Skip to content

Commit

Permalink
Added button action to show battery level
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Oct 4, 2023
1 parent 0d2c3fa commit 702dba0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions firmware/application/src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions firmware/application/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions software/script/chameleon_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ class ButtonPressFunction(enum.IntEnum):
SettingsButtonCycleSlot = 1
SettingsButtonCycleSlotDec = 2
SettingsButtonCloneIcUid = 3
SettingsButtonShowBattery = 4

@staticmethod
def list():
Expand All @@ -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
Expand All @@ -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"


Expand Down

0 comments on commit 702dba0

Please sign in to comment.