GPIO changes + remote-config
This commit is contained in:
parent
e984ffa46b
commit
38f469eea9
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define BEEPER_GPIO 22
|
#define BEEPER_GPIO 33
|
||||||
#define BEEPER_INVERT true
|
#define BEEPER_INVERT true
|
||||||
|
|
||||||
unsigned long beeperDuration = 0;
|
unsigned long beeperDuration = 0;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define BUZZER_GPIO 23
|
#define BUZZER_GPIO 32
|
||||||
#define BUZZER_INVERT true
|
#define BUZZER_INVERT true
|
||||||
|
|
||||||
void buzzerSetup() {
|
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 <LittleFS.h>
|
||||||
|
|
||||||
#include "countdown.h"
|
#include "countdown.h"
|
||||||
#include "beeper.h"
|
#include "beeper.h"
|
||||||
#include "buzzer.h"
|
#include "buzzer.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
#include "remote.h"
|
||||||
|
|
||||||
#define COUNTDOWN_END_SEQUENCE_STEPS 5
|
#define COUNTDOWN_END_SEQUENCE_STEPS 5
|
||||||
#define COUNTDOWN_END_SEQUENCE_REPEAT 3
|
#define COUNTDOWN_END_SEQUENCE_REPEAT 3
|
||||||
|
|
||||||
#define HALF_BEEP_DURATION 1000
|
#define HALF_BEEP_DURATION 500
|
||||||
#define LAST_10_BEEP_DURATION 100
|
#define LAST_10_BEEP_DURATION 100
|
||||||
|
|
||||||
enum CountdownState {
|
enum CountdownState {
|
||||||
@ -35,13 +40,57 @@ bool countdownHalfTimeBeep = false;
|
|||||||
|
|
||||||
long countdownBeepSeconds = -1;
|
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) {
|
void setState(const CountdownState newState) {
|
||||||
if (countdownState == newState) {
|
if (countdownState == newState) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
countdownState = newState;
|
countdownState = newState;
|
||||||
const char* name;
|
const char *name;
|
||||||
bool buzzer = false;
|
bool buzzer = false;
|
||||||
switch (countdownState) {
|
switch (countdownState) {
|
||||||
case CONFIG:
|
case CONFIG:
|
||||||
@ -49,6 +98,9 @@ void setState(const CountdownState newState) {
|
|||||||
name = "CONFIG";
|
name = "CONFIG";
|
||||||
break;
|
break;
|
||||||
case READY:
|
case READY:
|
||||||
|
if (countdownConfigDirty) {
|
||||||
|
countdownConfigWrite();
|
||||||
|
}
|
||||||
countdownRest = countdownMillis;
|
countdownRest = countdownMillis;
|
||||||
countdownHalfTimeBeep = false;
|
countdownHalfTimeBeep = false;
|
||||||
countdownBeepSeconds = -1;
|
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() {
|
void countdownSetup() {
|
||||||
countdownConfigLoad();
|
countdownConfigLoad();
|
||||||
setState(READY);
|
setState(READY);
|
||||||
@ -236,9 +246,6 @@ void buttonShortPressed() {
|
|||||||
void buttonLongPressed() {
|
void buttonLongPressed() {
|
||||||
switch (countdownState) {
|
switch (countdownState) {
|
||||||
case CONFIG:
|
case CONFIG:
|
||||||
if (countdownConfigDirty) {
|
|
||||||
countdownConfigWrite();
|
|
||||||
}
|
|
||||||
setState(READY);
|
setState(READY);
|
||||||
break;
|
break;
|
||||||
case RUNNING:
|
case RUNNING:
|
||||||
@ -247,7 +254,7 @@ void buttonLongPressed() {
|
|||||||
case READY:
|
case READY:
|
||||||
setState(CONFIG);
|
setState(CONFIG);
|
||||||
break;
|
break;
|
||||||
case PAUSED: // NOLINT(*-branch-clone)
|
case PAUSED:
|
||||||
setState(READY);
|
setState(READY);
|
||||||
break;
|
break;
|
||||||
case END:
|
case END:
|
||||||
@ -255,3 +262,54 @@ void buttonLongPressed() {
|
|||||||
break;
|
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>
|
#include <IRremote.hpp>
|
||||||
|
|
||||||
|
unsigned long remoteLast = 0;
|
||||||
|
|
||||||
void remoteSetup() {
|
void remoteSetup() {
|
||||||
IrReceiver.begin(21);
|
IrReceiver.begin(27);
|
||||||
}
|
}
|
||||||
|
|
||||||
void remoteLoop() {
|
void remoteLoop() {
|
||||||
if (IrReceiver.decode()) {
|
if (IrReceiver.decode()) {
|
||||||
Serial.println("--------------------------------------------------------------");
|
if (IrReceiver.lastDecodedProtocol == NEC && IrReceiver.lastDecodedAddress == 0 && IrReceiver.repeatCount == 0) {
|
||||||
IrReceiver.printIRResultShort(&Serial);
|
const auto now = max(1UL, millis());
|
||||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
|
if (remoteLast == 0 || now - remoteLast >= 200) {
|
||||||
Serial.println("OVERFLOW");
|
remoteCmd(IrReceiver.lastDecodedCommand);
|
||||||
} else {
|
}
|
||||||
Serial.println(getProtocolString(IrReceiver.decodedIRData.protocol));
|
remoteLast = now;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
IrReceiver.resume();
|
IrReceiver.resume();
|
||||||
Serial.println("--------------------------------------------------------------");
|
|
||||||
Serial.println();
|
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/remote.h
23
src/remote.h
@ -1,8 +1,31 @@
|
|||||||
#ifndef REMOTE_H
|
#ifndef REMOTE_H
|
||||||
#define 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 remoteSetup();
|
||||||
|
|
||||||
void remoteLoop();
|
void remoteLoop();
|
||||||
|
|
||||||
|
void remoteCmd(uint16_t cmd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user