From 9a4184a25ce5ee0a8cfe76d1423ec4bca2d89353 Mon Sep 17 00:00:00 2001 From: DriftKingTW Date: Sun, 4 Feb 2024 19:47:25 +0800 Subject: [PATCH] feat: add status led control --- src/main.cpp | 27 +++++++++++++++++++++++++-- src/main.hpp | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index aa91e1f..45eb470 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -190,6 +190,7 @@ void setup() { Serial.println("Configuring Configuration Buttons..."); + pinMode(CFG_BTN_PIN_0, INPUT_PULLUP); pinMode(CFG_BTN_PIN_1, INPUT_PULLUP); pinMode(CFG_BTN_PIN_2, INPUT_PULLUP); @@ -495,6 +496,13 @@ void ledTask(void *pvParameters) { while (true) { currentMillis = millis(); + if (isGoingToSleep) { + vTaskDelay(100 / portTICK_PERIOD_MS); + leds[0] = CRGB::Black; + FastLED.show(); + continue; + } + // Low battery LED blink if (isLowBattery) { if (currentMillis - ledPreviousMillis > 1000 && @@ -909,6 +917,21 @@ void loop() { longPressCounter++; } isUsbMode = !isUsbMode; + usbKeyboard.releaseAll(); + bleKeyboard.releaseAll(); + } else if (digitalRead(CFG_BTN_PIN_0) == ACTIVE) { + resetIdle(); + int longPressCounter = 0; + while (digitalRead(CFG_BTN_PIN_0) == ACTIVE) { + delay(10); + if (longPressCounter > 100) { + switchBootMode(); + } + longPressCounter++; + } + isUsbMode = !isUsbMode; + usbKeyboard.releaseAll(); + bleKeyboard.releaseAll(); } } @@ -1380,7 +1403,7 @@ void renderScreen() { * */ int getBatteryPercentage() { - const float minVoltage = 2.8, fullVolatge = 3.8; + const float minVoltage = 3, fullVolatge = 3.8; int raw = analogRead(6); float batteryVoltage = raw * V_REF / 4096.0 * VOLTAGE_DIVIDER_RATIO; @@ -1465,7 +1488,7 @@ void switchBootMode() { void checkIdle() { if (!isCaffeinated && currentMillis - sleepPreviousMillis > SLEEP_INTERVAL && - getUSBPowerState()) { + !getUSBPowerState()) { goSleeping(); } else if (!isCaffeinated && currentMillis - sleepPreviousMillis > SCREEN_SLEEP_INTERVAL) { diff --git a/src/main.hpp b/src/main.hpp index f15506f..bf68687 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -62,6 +62,7 @@ using namespace std; #define LED_PIN_DIN 38 #define NUM_LEDS 1 +#define CFG_BTN_PIN_0 0 #define CFG_BTN_PIN_1 2 #define CFG_BTN_PIN_2 1