mirror of
https://github.com/clockworkpi/PicoCalc.git
synced 2025-12-12 10:18:54 +01:00
Update multi booter
add battery percentage displaying
This commit is contained in:
parent
e403bc04d8
commit
cb0b1fbb63
@ -17,4 +17,8 @@ void init_i2c_kbd();
|
||||
int read_i2c_kbd();
|
||||
int read_battery();
|
||||
|
||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bitClear(value, bit) ((value) &= ~(1 << (bit)))
|
||||
#define bitSet(value, bit) ((value) |= (1 << (bit)))
|
||||
|
||||
#endif
|
||||
@ -141,3 +141,11 @@ int keypad_get_key(void)
|
||||
return act_key;
|
||||
}
|
||||
|
||||
int keypad_get_battery() {
|
||||
int bat_pcnt = read_battery();
|
||||
bat_pcnt = bat_pcnt >> 8;
|
||||
//int bat_charging = bitRead(bat_pcnt, 7);
|
||||
bitClear(bat_pcnt, 7);
|
||||
return bat_pcnt;
|
||||
|
||||
}
|
||||
@ -17,5 +17,5 @@ typedef enum {
|
||||
|
||||
void keypad_init(void);
|
||||
int keypad_get_key(void);
|
||||
|
||||
int keypad_get_battery(void);
|
||||
#endif // KEY_EVENT_H
|
||||
|
||||
@ -285,7 +285,7 @@ void final_selection_callback(const char *path)
|
||||
|
||||
int main()
|
||||
{
|
||||
char buf[64];
|
||||
uint32_t cur_time,last_time=0;
|
||||
stdio_init_all();
|
||||
|
||||
uart_init(uart0, 115200);
|
||||
@ -302,6 +302,8 @@ int main()
|
||||
lcd_clear();
|
||||
text_directory_ui_pre_init();
|
||||
|
||||
cur_time = time_us_64() / 1000;
|
||||
last_time = cur_time;
|
||||
// Check for SD card presence
|
||||
DEBUG_PRINT("Checking for SD card...\n");
|
||||
if (!sd_card_inserted())
|
||||
@ -314,11 +316,16 @@ int main()
|
||||
text_directory_ui_set_final_callback(final_selection_callback);
|
||||
while (!sd_card_inserted())
|
||||
{
|
||||
cur_time = time_us_64() / 1000;
|
||||
int key = keypad_get_key();
|
||||
if (key != 0)
|
||||
process_key_event(key);
|
||||
|
||||
sleep_ms(20);
|
||||
if(cur_time - last_time > 60000) {
|
||||
text_directory_ui_update_header(1);
|
||||
last_time = cur_time;
|
||||
}
|
||||
}
|
||||
|
||||
// Card detected, wait for it to stabilize
|
||||
|
||||
@ -426,6 +426,15 @@ static void ui_draw_status_bar(void)
|
||||
|
||||
}
|
||||
|
||||
static void ui_draw_battery_status(){
|
||||
char buf[8];
|
||||
int pcnt = keypad_get_battery();
|
||||
|
||||
sprintf(buf,"%d%%",pcnt);
|
||||
int y = UI_Y + HEADER_TITLE_HEIGHT;
|
||||
//draw_rect_spi(UI_X, y, UI_X + UI_WIDTH - 1, y + PATH_HEADER_HEIGHT - 1, COLOR_BG);
|
||||
draw_text(UI_X + 240, y + 2, buf, COLOR_FG, COLOR_BG);
|
||||
}
|
||||
// Refresh the entire UI
|
||||
static void ui_refresh(void)
|
||||
{
|
||||
@ -436,7 +445,7 @@ static void ui_refresh(void)
|
||||
if(entry_count == 0) {
|
||||
ui_draw_empty_tip();
|
||||
}
|
||||
|
||||
ui_draw_battery_status();
|
||||
}
|
||||
|
||||
// Handle key events for navigation and selection
|
||||
@ -565,6 +574,7 @@ void text_directory_ui_set_status(const char *msg)
|
||||
|
||||
void text_directory_ui_update_header(uint8_t nosd) {
|
||||
ui_draw_path_header(nosd);
|
||||
ui_draw_battery_status();
|
||||
}
|
||||
|
||||
void text_directory_ui_draw_default_app() {
|
||||
@ -578,16 +588,14 @@ void text_directory_ui_draw_default_app() {
|
||||
void text_directory_ui_run(void)
|
||||
{
|
||||
uint32_t last_scroll_update = 0;
|
||||
const uint32_t SCROLL_UPDATE_MS = 500; // Update scrolling text every 100ms
|
||||
|
||||
uint32_t last_bat_update = 0;
|
||||
while (true)
|
||||
{
|
||||
uint32_t current_time = time_us_64() / 1000;
|
||||
int key = keypad_get_key();
|
||||
if (key != 0)
|
||||
process_key_event(key);
|
||||
|
||||
uint32_t current_time = time_us_64() / 1000;
|
||||
|
||||
// Update scrolling text periodically
|
||||
if (current_time - last_scroll_update > SCROLL_UPDATE_MS)
|
||||
{
|
||||
@ -599,21 +607,29 @@ void text_directory_ui_run(void)
|
||||
}
|
||||
last_scroll_update = current_time;
|
||||
}
|
||||
|
||||
if(current_time - last_bat_update > BAT_UPDATE_MS){
|
||||
text_directory_ui_update_header(!status_flag);
|
||||
last_bat_update = current_time;
|
||||
}
|
||||
// Check for SD card removal during runtime
|
||||
if (!sd_card_inserted()) {
|
||||
text_directory_ui_set_status("SD card removed. Please reinsert.");
|
||||
ui_draw_path_header(1);
|
||||
text_directory_ui_update_header(!status_flag);
|
||||
ui_clear_directory_list();
|
||||
update_required = 1;
|
||||
ui_draw_directory_list();
|
||||
// Wait until the SD card is reinserted
|
||||
while (!sd_card_inserted()) {
|
||||
current_time = time_us_64() / 1000;
|
||||
key = keypad_get_key();
|
||||
if (key != 0)
|
||||
process_key_event(key);
|
||||
|
||||
sleep_ms(20);
|
||||
if(current_time - last_bat_update > BAT_UPDATE_MS){
|
||||
text_directory_ui_update_header(!status_flag);
|
||||
last_bat_update = current_time;
|
||||
}
|
||||
}
|
||||
|
||||
// Once reinserted, update the UI and reinitialize filesystem
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
#define ITEMS_PER_PAGE 16
|
||||
#define FONT_HEIGHT 12
|
||||
#define ENTRY_PADDING 2
|
||||
#define BAT_UPDATE_MS 60000
|
||||
#define SCROLL_UPDATE_MS 500
|
||||
// Callback type: invoked when the user makes a final selection. The selected path is passed as an argument.
|
||||
typedef void (*final_selection_callback_t)(const char *selected_path);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user