Added button action to show battery level

This commit is contained in:
Philippe Teuwen
2023-10-04 19:36:33 +02:00
parent 0d2c3fae89
commit 702dba0d93
4 changed files with 39 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Added button action to show battery level (@doegox)
- Added GUI Page docs (@GameTec-live)
- Changed CLI threads polling into blocking reads, to reduce CPU usage (@doegox)
- Added support for timestamped comments in CLI via `rem`, `;`, `%` or `#` (@doegox)
+32
View File
@@ -532,6 +532,35 @@ static void cycle_slot(bool dec) {
set_slot_light_color(color_new);
}
static void show_battery(void) {
uint32_t *led_pins = hw_get_led_array();
// if still in the first 4s after boot, blink red while waiting for battery info
while (percentage_batt_lvl == 0) {
for (int i = 0; i < RGB_LIST_NUM; i++) {
nrf_gpio_pin_clear(led_pins[i]);
}
bsp_delay_ms(100);
set_slot_light_color(RGB_RED);
for (int i = 0; i < RGB_LIST_NUM; i++) {
nrf_gpio_pin_set(led_pins[i]);
}
bsp_delay_ms(100);
}
// ok we have data, show level with cyan LEDs
for (int i = 0; i < RGB_LIST_NUM; i++) {
nrf_gpio_pin_clear(led_pins[i]);
}
set_slot_light_color(RGB_CYAN);
uint8_t nleds = (percentage_batt_lvl * 2) / 25; // 0->7 (8 for 100% but this is ignored)
for (int i = 0; i < RGB_LIST_NUM; i++) {
if (i <= nleds) {
nrf_gpio_pin_set(led_pins[i]);
bsp_delay_ms(50);
}
}
// nothing special to finish, we wait for sleep or slot change
}
#if defined(PROJECT_CHAMELEON_ULTRA)
static void offline_status_blink_color(uint8_t blink_color) {
@@ -689,6 +718,9 @@ static void run_button_function_by_settings(settings_button_function_t sbf) {
break;
#endif
case SettingsButtonShowBattery:
show_battery();
default:
NRF_LOG_ERROR("Unsupported button function")
break;
+1
View File
@@ -25,6 +25,7 @@ typedef enum {
SettingsButtonCycleSlotDec = 2U,
// Read the UID card number immediately after pressing, continue searching, and simulate immediately after reading the card
SettingsButtonCloneIcUid = 3U,
SettingsButtonShowBattery = 4U,
} settings_button_function_t;
typedef struct ALIGN_U32 {
+5
View File
@@ -377,6 +377,7 @@ class ButtonPressFunction(enum.IntEnum):
SettingsButtonCycleSlot = 1
SettingsButtonCycleSlotDec = 2
SettingsButtonCloneIcUid = 3
SettingsButtonShowBattery = 4
@staticmethod
def list():
@@ -391,6 +392,8 @@ class ButtonPressFunction(enum.IntEnum):
return "Cycle Slot Dec"
elif self == ButtonPressFunction.SettingsButtonCloneIcUid:
return "Quickly Copy Ic Uid"
elif self == ButtonPressFunction.SettingsButtonShowBattery:
return "Show Battery Level"
return "None"
@staticmethod
@@ -408,6 +411,8 @@ class ButtonPressFunction(enum.IntEnum):
elif self == ButtonPressFunction.SettingsButtonCloneIcUid:
return ("Read the UID card number immediately after pressing, continue searching," +
"and simulate immediately after reading the card")
elif self == ButtonPressFunction.SettingsButtonShowBattery:
return ("Lights up slot LEDs according to battery level")
return "Unknown"