From 702dba0d9310a0d6686377f926eb3c262f7beb7a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Oct 2023 19:36:33 +0200 Subject: [PATCH] Added button action to show battery level --- CHANGELOG.md | 1 + firmware/application/src/app_main.c | 32 +++++++++++++++++++++++++++++ firmware/application/src/settings.h | 1 + software/script/chameleon_cmd.py | 5 +++++ 4 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e7d707d..da1c57e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index a6eeab14..16723d34 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -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; diff --git a/firmware/application/src/settings.h b/firmware/application/src/settings.h index adfd3cd1..4231733e 100644 --- a/firmware/application/src/settings.h +++ b/firmware/application/src/settings.h @@ -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 { diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index 1ab67b76..d20d7192 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -377,6 +377,7 @@ class ButtonPressFunction(enum.IntEnum): SettingsButtonCycleSlot = 1 SettingsButtonCycleSlotDec = 2 SettingsButtonCloneIcUid = 3 + SettingsButtonShowBattery = 4 @staticmethod def list(): @@ -391,6 +392,8 @@ def __str__(self): 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 @@ def usage(self): 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"