Merge pull request #225 from alesgenova/short-led
companion_radio: greatly reduce the status LED usage
This commit is contained in:
@@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
#define AUTO_OFF_MILLIS 15000 // 15 seconds
|
#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
|
#ifndef USER_BTN_PRESSED
|
||||||
#define USER_BTN_PRESSED LOW
|
#define USER_BTN_PRESSED LOW
|
||||||
#endif
|
#endif
|
||||||
@@ -135,22 +141,21 @@ void UITask::userLedHandler() {
|
|||||||
#ifdef PIN_STATUS_LED
|
#ifdef PIN_STATUS_LED
|
||||||
static int state = 0;
|
static int state = 0;
|
||||||
static int next_change = 0;
|
static int next_change = 0;
|
||||||
|
static int last_increment = 0;
|
||||||
|
|
||||||
int cur_time = millis();
|
int cur_time = millis();
|
||||||
if (cur_time > next_change) {
|
if (cur_time > next_change) {
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
state = 1; // led on, short = unread msg
|
state = 1;
|
||||||
if (_msgcount > 0) {
|
if (_msgcount > 0) {
|
||||||
next_change = cur_time + 500;
|
last_increment = LED_ON_MSG_MILLIS;
|
||||||
} else {
|
} else {
|
||||||
next_change = cur_time + 2000;
|
last_increment = LED_ON_MILLIS;
|
||||||
}
|
}
|
||||||
|
next_change = cur_time + last_increment;
|
||||||
} else {
|
} else {
|
||||||
state = 0;
|
state = 0;
|
||||||
if (_board->getBattMilliVolts() > 3800) {
|
next_change = cur_time + LED_CYCLE_MILLIS - last_increment;
|
||||||
next_change = cur_time + 2000;
|
|
||||||
} else {
|
|
||||||
next_change = cur_time + 4000; // 4s blank if bat level low
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
digitalWrite(PIN_STATUS_LED, state);
|
digitalWrite(PIN_STATUS_LED, state);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user