Fix several features of M1 and M2 (i know what the 7 is now ...) (#6507)

* Fix several features of M1 and M2 (i know what the 7 is now ...)

* 'THe' should be 'The'.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* remove floating definition

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
Thomas Göttgens
2025-04-07 12:46:22 +02:00
committed by GitHub
parent 860e8eca5a
commit 606abfc116
12 changed files with 221 additions and 124 deletions

View File

@@ -212,6 +212,60 @@ const char *getDeviceName()
return name;
}
#if defined(ELECROW_ThinkNode_M1) || defined(ELECROW_ThinkNode_M2)
static int32_t ledBlinkCount = 0;
static int32_t elecrowLedBlinker()
{
// are we in alert buzzer mode?
if (buttonThread->isBuzzing()) {
// blink LED three times for 3 seconds, then 3 times for a second, with one second pause
if (ledBlinkCount % 2) { // odd means LED OFF
ledBlink.set(false);
ledBlinkCount++;
if (ledBlinkCount >= 12)
ledBlinkCount = 0;
noTone(PIN_BUZZER);
return 1000;
} else {
if (ledBlinkCount < 6) {
ledBlink.set(true);
tone(PIN_BUZZER, 4000, 3000);
ledBlinkCount++;
return 3000;
} else {
ledBlink.set(true);
tone(PIN_BUZZER, 4000, 1000);
ledBlinkCount++;
return 1000;
}
}
} else {
ledBlinkCount = 0;
if (config.device.led_heartbeat_disabled)
return 1000;
static bool ledOn;
// when fully charged, remain on!
if (powerStatus->getIsCharging() && powerStatus->getBatteryChargePercent() >= 100) {
ledOn = true;
} else {
ledOn ^= 1;
}
ledBlink.set(ledOn);
// when charging, blink 0.5Hz square wave rate to indicate that
if (powerStatus->getIsCharging()) {
return 500;
}
// When almost empty, blink rapidly
if (!powerStatus->getIsCharging() && powerStatus->getBatteryChargePercent() < 10) {
return 250;
}
}
return 1000;
}
#else
static int32_t ledBlinker()
{
// Still set up the blinking (heartbeat) interval but skip code path below, so LED will blink if
@@ -227,6 +281,7 @@ static int32_t ledBlinker()
// have a very sparse duty cycle of LED being on, unless charging, then blink 0.5Hz square wave rate to indicate that
return powerStatus->getIsCharging() ? 1000 : (ledOn ? 1 : 1000);
}
#endif
uint32_t timeLastPowered = 0;
@@ -263,11 +318,6 @@ void printInfo()
void setup()
{
#ifdef POWER_CHRG
pinMode(POWER_CHRG, OUTPUT);
digitalWrite(POWER_CHRG, HIGH);
#endif
#if defined(PIN_POWER_EN)
pinMode(PIN_POWER_EN, OUTPUT);
digitalWrite(PIN_POWER_EN, HIGH);
@@ -278,11 +328,6 @@ void setup()
digitalWrite(LED_POWER, HIGH);
#endif
#ifdef POWER_LED
pinMode(POWER_LED, OUTPUT);
digitalWrite(POWER_LED, HIGH);
#endif
#ifdef USER_LED
pinMode(USER_LED, OUTPUT);
digitalWrite(USER_LED, LOW);
@@ -414,7 +459,12 @@ void setup()
OSThread::setup();
#if defined(ELECROW_ThinkNode_M1) || defined(ELECROW_ThinkNode_M2)
// The ThinkNodes have their own blink logic
ledPeriodic = new Periodic("Blink", elecrowLedBlinker);
#else
ledPeriodic = new Periodic("Blink", ledBlinker);
#endif
fsInit();