Browse Source
Merge pull request #225 from alesgenova/short-led
companion_radio: greatly reduce the status LED usage
pull/229/head
ripplebiz
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
13 additions and
8 deletions
-
examples/companion_radio/UITask.cpp
|
|
|
@ -4,6 +4,12 @@ |
|
|
|
|
|
|
|
#define AUTO_OFF_MILLIS 15000 // 15 seconds
|
|
|
|
|
|
|
|
#ifdef PIN_STATUS_LED |
|
|
|
#define LED_ON_MILLIS 20 |
|
|
|
#define LED_ON_MSG_MILLIS 200 |
|
|
|
#define LED_CYCLE_MILLIS 4000 |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifndef USER_BTN_PRESSED |
|
|
|
#define USER_BTN_PRESSED LOW |
|
|
|
#endif |
|
|
|
@ -135,22 +141,21 @@ void UITask::userLedHandler() { |
|
|
|
#ifdef PIN_STATUS_LED |
|
|
|
static int state = 0; |
|
|
|
static int next_change = 0; |
|
|
|
static int last_increment = 0; |
|
|
|
|
|
|
|
int cur_time = millis(); |
|
|
|
if (cur_time > next_change) { |
|
|
|
if (state == 0) { |
|
|
|
state = 1; // led on, short = unread msg
|
|
|
|
state = 1; |
|
|
|
if (_msgcount > 0) { |
|
|
|
next_change = cur_time + 500; |
|
|
|
last_increment = LED_ON_MSG_MILLIS; |
|
|
|
} else { |
|
|
|
next_change = cur_time + 2000; |
|
|
|
last_increment = LED_ON_MILLIS; |
|
|
|
} |
|
|
|
next_change = cur_time + last_increment; |
|
|
|
} else { |
|
|
|
state = 0; |
|
|
|
if (_board->getBattMilliVolts() > 3800) { |
|
|
|
next_change = cur_time + 2000; |
|
|
|
} else { |
|
|
|
next_change = cur_time + 4000; // 4s blank if bat level low
|
|
|
|
} |
|
|
|
next_change = cur_time + LED_CYCLE_MILLIS - last_increment; |
|
|
|
} |
|
|
|
digitalWrite(PIN_STATUS_LED, state); |
|
|
|
} |
|
|
|
|