v1.2: Settings toggles, flight logbook, local time, WiFi auto-reconnect, metric units
This commit is contained in:
@@ -6,37 +6,58 @@ namespace {
|
||||
constexpr uint8_t PIN_RED = 4;
|
||||
constexpr uint8_t PIN_GREEN = 16;
|
||||
constexpr uint8_t PIN_BLUE = 17;
|
||||
constexpr uint32_t BLINK_INTERVAL_MS = 400;
|
||||
|
||||
constexpr uint32_t GREEN_BLINK_INTERVAL_MS = 400;
|
||||
constexpr uint32_t RED_BLINK_INTERVAL_MS = 150;
|
||||
|
||||
bool initialized = false;
|
||||
bool blinkState = false;
|
||||
uint32_t lastToggleMs = 0;
|
||||
Mode lastMode = Mode::Off;
|
||||
|
||||
void setAllOff() {
|
||||
digitalWrite(PIN_RED, HIGH);
|
||||
digitalWrite(PIN_GREEN, HIGH);
|
||||
digitalWrite(PIN_BLUE, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void begin() {
|
||||
pinMode(PIN_RED, OUTPUT);
|
||||
pinMode(PIN_GREEN, OUTPUT);
|
||||
pinMode(PIN_BLUE, OUTPUT);
|
||||
digitalWrite(PIN_RED, HIGH); // aus (LED ist active-low)
|
||||
digitalWrite(PIN_GREEN, HIGH); // aus
|
||||
digitalWrite(PIN_BLUE, HIGH); // aus
|
||||
setAllOff();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
bool update(bool active, uint32_t nowMs) {
|
||||
bool update(Mode mode, uint32_t nowMs) {
|
||||
if (!initialized) begin();
|
||||
|
||||
if (!active) {
|
||||
digitalWrite(PIN_GREEN, HIGH); // aus
|
||||
if (mode == Mode::Off) {
|
||||
setAllOff();
|
||||
blinkState = false;
|
||||
lastMode = mode;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nowMs - lastToggleMs >= BLINK_INTERVAL_MS) {
|
||||
if (mode != lastMode) {
|
||||
lastToggleMs = nowMs;
|
||||
blinkState = true;
|
||||
lastMode = mode;
|
||||
}
|
||||
|
||||
uint32_t interval = (mode == Mode::EmergencyRed) ? RED_BLINK_INTERVAL_MS : GREEN_BLINK_INTERVAL_MS;
|
||||
uint8_t pin = (mode == Mode::EmergencyRed) ? PIN_RED : PIN_GREEN;
|
||||
|
||||
if (nowMs - lastToggleMs >= interval) {
|
||||
lastToggleMs = nowMs;
|
||||
blinkState = !blinkState;
|
||||
digitalWrite(PIN_GREEN, blinkState ? LOW : HIGH); // LOW = an, volle Helligkeit (kein PWM noetig)
|
||||
}
|
||||
|
||||
digitalWrite(pin, blinkState ? LOW : HIGH);
|
||||
digitalWrite(mode == Mode::EmergencyRed ? PIN_GREEN : PIN_RED, HIGH);
|
||||
digitalWrite(PIN_BLUE, HIGH);
|
||||
|
||||
return blinkState;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user