code clean

This commit is contained in:
Patrick Haßel 2025-08-07 11:04:23 +02:00
parent f2bd3bab46
commit 67a676c320
2 changed files with 26 additions and 12 deletions

View File

@ -3,12 +3,14 @@
#include <Arduino.h> #include <Arduino.h>
#define BEEP_PIN 2
inline void beepSet(const bool state) { inline void beepSet(const bool state) {
digitalWrite(2, state ? HIGH : LOW); digitalWrite(BEEP_PIN, state ? HIGH : LOW);
} }
inline void beepSetup() { inline void beepSetup() {
pinMode(2,OUTPUT); pinMode(BEEP_PIN,OUTPUT);
beepSet(false); beepSet(false);
} }

View File

@ -3,19 +3,16 @@
#include "mode/Mode.h" #include "mode/Mode.h"
#include "mode/ModeTimer.h" #include "mode/ModeTimer.h"
void stepMode();
void readConsole();
void buttonCallback(ButtonEvent event);
Display display; Display display;
ModeTimer mode; ModeTimer mode;
void buttonCallback(const ButtonEvent event) {
if (event == BUTTON_PRESSED) {
mode.buttonOK();
}
if (BUTTON_PRESSED_LONG) {
mode.buttonESC();
}
}
Button button(23, buttonCallback); Button button(23, buttonCallback);
void setup() { void setup() {
@ -29,14 +26,20 @@ void setup() {
} }
void loop() { void loop() {
stepMode();
readConsole();
}
void stepMode() {
const uint64_t now = millis(); const uint64_t now = millis();
static uint64_t lastMillis = 0; static uint64_t lastMillis = 0;
const uint64_t deltaMillis = now - lastMillis; const uint64_t deltaMillis = now - lastMillis;
lastMillis = now; lastMillis = now;
mode.step(deltaMillis); mode.step(deltaMillis);
mode.draw(display); mode.draw(display);
}
void readConsole() {
const auto code = Serial.read(); const auto code = Serial.read();
if (code == ' ') { if (code == ' ') {
mode.buttonOK(); mode.buttonOK();
@ -45,3 +48,12 @@ void loop() {
mode.buttonESC(); mode.buttonESC();
} }
} }
void buttonCallback(const ButtonEvent event) {
if (event == BUTTON_PRESSED) {
mode.buttonOK();
}
if (BUTTON_PRESSED_LONG) {
mode.buttonESC();
}
}