GPIO changes + remote-config
This commit is contained in:
parent
e984ffa46b
commit
38f469eea9
@ -2,7 +2,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define BEEPER_GPIO 22
|
||||
#define BEEPER_GPIO 33
|
||||
#define BEEPER_INVERT true
|
||||
|
||||
unsigned long beeperDuration = 0;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define BUZZER_GPIO 23
|
||||
#define BUZZER_GPIO 32
|
||||
#define BUZZER_INVERT true
|
||||
|
||||
void buzzerSetup() {
|
||||
|
||||
@ -1,14 +1,19 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "hicpp-multiway-paths-covered"
|
||||
#pragma ide diagnostic ignored "bugprone-branch-clone"
|
||||
|
||||
#include <LittleFS.h>
|
||||
|
||||
#include "countdown.h"
|
||||
#include "beeper.h"
|
||||
#include "buzzer.h"
|
||||
#include "display.h"
|
||||
#include "remote.h"
|
||||
|
||||
#define COUNTDOWN_END_SEQUENCE_STEPS 5
|
||||
#define COUNTDOWN_END_SEQUENCE_REPEAT 3
|
||||
|
||||
#define HALF_BEEP_DURATION 1000
|
||||
#define HALF_BEEP_DURATION 500
|
||||
#define LAST_10_BEEP_DURATION 100
|
||||
|
||||
enum CountdownState {
|
||||
@ -35,13 +40,57 @@ bool countdownHalfTimeBeep = false;
|
||||
|
||||
long countdownBeepSeconds = -1;
|
||||
|
||||
void countdownConfigLoad() {
|
||||
if (LittleFS.begin(true)) {
|
||||
Serial.println("Filesystem mounted.");
|
||||
if (LittleFS.exists("/countdownMillis")) {
|
||||
File file = LittleFS.open("/countdownMillis");
|
||||
if (file) {
|
||||
const String content = file.readString();
|
||||
if (content) {
|
||||
countdownMillis = content.toInt();
|
||||
Serial.printf("Read countdownMillis from file: countdownMillis=%lu, file=%s\n", countdownMillis, file.path());
|
||||
} else {
|
||||
Serial.printf("WARN: Cannot parse content of: %s\n", file.path());
|
||||
}
|
||||
file.close();
|
||||
} else {
|
||||
Serial.printf("WARN: Cannot open file for READ: %s\n", file.path());
|
||||
}
|
||||
}
|
||||
LittleFS.end();
|
||||
Serial.println("Filesystem unmounted.");
|
||||
} else {
|
||||
Serial.println("ERROR: Failed to mount filesystem.");
|
||||
}
|
||||
}
|
||||
|
||||
void countdownConfigWrite() {
|
||||
if (LittleFS.begin(true)) {
|
||||
Serial.println("Filesystem mounted.");
|
||||
File file = LittleFS.open("/countdownMillis", "w", true);
|
||||
if (file) {
|
||||
file.printf("%lu", countdownMillis);
|
||||
Serial.printf("Wrote countdownMillis to file: countdownMillis=%lu, file=%s\n", countdownMillis, file.path());
|
||||
file.close();
|
||||
countdownConfigDirty = false;
|
||||
} else {
|
||||
Serial.printf("WARN: Cannot open file for WRITE: %s\n", file.path());
|
||||
}
|
||||
LittleFS.end();
|
||||
Serial.println("Filesystem unmounted.");
|
||||
} else {
|
||||
Serial.println("ERROR: failed to mount filesystem");
|
||||
}
|
||||
}
|
||||
|
||||
void setState(const CountdownState newState) {
|
||||
if (countdownState == newState) {
|
||||
return;
|
||||
}
|
||||
|
||||
countdownState = newState;
|
||||
const char* name;
|
||||
const char *name;
|
||||
bool buzzer = false;
|
||||
switch (countdownState) {
|
||||
case CONFIG:
|
||||
@ -49,6 +98,9 @@ void setState(const CountdownState newState) {
|
||||
name = "CONFIG";
|
||||
break;
|
||||
case READY:
|
||||
if (countdownConfigDirty) {
|
||||
countdownConfigWrite();
|
||||
}
|
||||
countdownRest = countdownMillis;
|
||||
countdownHalfTimeBeep = false;
|
||||
countdownBeepSeconds = -1;
|
||||
@ -125,48 +177,6 @@ void countdownDraw() {
|
||||
}
|
||||
}
|
||||
|
||||
void countdownConfigLoad() {
|
||||
if (LittleFS.begin(true)) {
|
||||
Serial.println("Filesystem mounted.");
|
||||
File file = LittleFS.open("/countdownMillis");
|
||||
if (file) {
|
||||
const String content = file.readString();
|
||||
if (content) {
|
||||
countdownMillis = content.toInt();
|
||||
Serial.printf("Read countdownMillis from file: countdownMillis=%lu, file=%s", countdownMillis, file.path());
|
||||
} else {
|
||||
Serial.printf("WARN: Cannot parse content of: %s\n", file.path());
|
||||
}
|
||||
file.close();
|
||||
} else {
|
||||
Serial.printf("WARN: Cannot open file for READ: %s\n", file.path());
|
||||
}
|
||||
LittleFS.end();
|
||||
Serial.println("Filesystem unmounted.");
|
||||
} else {
|
||||
Serial.println("ERROR: Failed to mount filesystem.");
|
||||
}
|
||||
}
|
||||
|
||||
void countdownConfigWrite() {
|
||||
if (LittleFS.begin(true)) {
|
||||
Serial.println("Filesystem mounted.");
|
||||
File file = LittleFS.open("/countdownMillis", "w", true);
|
||||
if (file) {
|
||||
file.printf("%lu", countdownMillis);
|
||||
Serial.printf("Wrote countdownMillis to file: countdownMillis=%lu, file=%s", countdownMillis, file.path());
|
||||
file.close();
|
||||
countdownConfigDirty = false;
|
||||
} else {
|
||||
Serial.printf("WARN: Cannot open file for WRITE: %s\n", file.path());
|
||||
}
|
||||
LittleFS.end();
|
||||
Serial.println("Filesystem unmounted.");
|
||||
} else {
|
||||
Serial.println("ERROR: failed to mount filesystem");
|
||||
}
|
||||
}
|
||||
|
||||
void countdownSetup() {
|
||||
countdownConfigLoad();
|
||||
setState(READY);
|
||||
@ -236,9 +246,6 @@ void buttonShortPressed() {
|
||||
void buttonLongPressed() {
|
||||
switch (countdownState) {
|
||||
case CONFIG:
|
||||
if (countdownConfigDirty) {
|
||||
countdownConfigWrite();
|
||||
}
|
||||
setState(READY);
|
||||
break;
|
||||
case RUNNING:
|
||||
@ -247,7 +254,7 @@ void buttonLongPressed() {
|
||||
case READY:
|
||||
setState(CONFIG);
|
||||
break;
|
||||
case PAUSED: // NOLINT(*-branch-clone)
|
||||
case PAUSED:
|
||||
setState(READY);
|
||||
break;
|
||||
case END:
|
||||
@ -255,3 +262,54 @@ void buttonLongPressed() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void remoteCmd(uint16_t cmd) {
|
||||
switch (countdownState) {
|
||||
case CONFIG:
|
||||
switch (cmd) {
|
||||
case IR_CMD_UP:
|
||||
countdownMillis = min(15 * 60000L, countdownMillis + 60000);
|
||||
countdownRest = countdownMillis;
|
||||
countdownConfigDirty = true;
|
||||
break;
|
||||
case IR_CMD_DOWN:
|
||||
countdownMillis = max(0L, countdownMillis - 60000);
|
||||
countdownRest = countdownMillis;
|
||||
countdownConfigDirty = true;
|
||||
break;
|
||||
case IR_CMD_RIGHT:
|
||||
countdownMillis = min(15 * 60000L, countdownMillis + 1000);
|
||||
countdownRest = countdownMillis;
|
||||
countdownConfigDirty = true;
|
||||
break;
|
||||
case IR_CMD_LEFT:
|
||||
countdownMillis = max(0L, countdownMillis - 1000);
|
||||
countdownRest = countdownMillis;
|
||||
countdownConfigDirty = true;
|
||||
break;
|
||||
case IR_CMD_C:
|
||||
case IR_CMD_X:
|
||||
setState(READY);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case READY:
|
||||
if (cmd == IR_CMD_A) {
|
||||
setState(CONFIG);
|
||||
}
|
||||
case RUNNING:
|
||||
case PAUSED:
|
||||
case END:
|
||||
switch (cmd) {
|
||||
case IR_CMD_X:
|
||||
setState(countdownState == RUNNING ? PAUSED : RUNNING);
|
||||
break;
|
||||
case IR_CMD_C:
|
||||
setState(READY);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
@ -2,29 +2,21 @@
|
||||
|
||||
#include <IRremote.hpp>
|
||||
|
||||
unsigned long remoteLast = 0;
|
||||
|
||||
void remoteSetup() {
|
||||
IrReceiver.begin(21);
|
||||
IrReceiver.begin(27);
|
||||
}
|
||||
|
||||
void remoteLoop() {
|
||||
if (IrReceiver.decode()) {
|
||||
Serial.println("--------------------------------------------------------------");
|
||||
IrReceiver.printIRResultShort(&Serial);
|
||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
|
||||
Serial.println("OVERFLOW");
|
||||
} else {
|
||||
Serial.println(getProtocolString(IrReceiver.decodedIRData.protocol));
|
||||
IrReceiver.printIRSendUsage(&Serial);
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, false);
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, true);
|
||||
IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false);
|
||||
IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, true);
|
||||
IrReceiver.printIRResultAsCVariables(&Serial);
|
||||
IrReceiver.compensateAndPrintIRResultAsPronto(&Serial);
|
||||
if (IrReceiver.lastDecodedProtocol == NEC && IrReceiver.lastDecodedAddress == 0 && IrReceiver.repeatCount == 0) {
|
||||
const auto now = max(1UL, millis());
|
||||
if (remoteLast == 0 || now - remoteLast >= 200) {
|
||||
remoteCmd(IrReceiver.lastDecodedCommand);
|
||||
}
|
||||
remoteLast = now;
|
||||
}
|
||||
IrReceiver.resume();
|
||||
Serial.println("--------------------------------------------------------------");
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
23
src/remote.h
23
src/remote.h
@ -1,8 +1,31 @@
|
||||
#ifndef REMOTE_H
|
||||
#define REMOTE_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define IR_CMD_A 0x45
|
||||
#define IR_CMD_UP 0x46
|
||||
#define IR_CMD_B 0x47
|
||||
#define IR_CMD_LEFT 0x44
|
||||
#define IR_CMD_X 0x40
|
||||
#define IR_CMD_RIGHT 0x43
|
||||
#define IR_CMD_0 0x7
|
||||
#define IR_CMD_DOWN 0x15
|
||||
#define IR_CMD_C 0x9
|
||||
#define IR_CMD_1 0x16
|
||||
#define IR_CMD_2 0x19
|
||||
#define IR_CMD_3 0xD
|
||||
#define IR_CMD_4 0xC
|
||||
#define IR_CMD_5 0x18
|
||||
#define IR_CMD_6 0x5E
|
||||
#define IR_CMD_7 0x8
|
||||
#define IR_CMD_8 0x1C
|
||||
#define IR_CMD_9 0x5A
|
||||
|
||||
void remoteSetup();
|
||||
|
||||
void remoteLoop();
|
||||
|
||||
void remoteCmd(uint16_t cmd);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user