Skip to content

Commit

Permalink
feat: add status led control
Browse files Browse the repository at this point in the history
  • Loading branch information
DriftKingTW committed Feb 4, 2024
1 parent 043a20e commit 9a4184a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9a4184a

Please sign in to comment.