mirror of
https://github.com/clockworkpi/PicoCalc.git
synced 2025-12-12 18:28:53 +01:00
Compare commits
3 Commits
e403bc04d8
...
4449860332
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4449860332 | ||
|
|
bdbac6751e | ||
|
|
cb0b1fbb63 |
@ -17,4 +17,8 @@ void init_i2c_kbd();
|
|||||||
int read_i2c_kbd();
|
int read_i2c_kbd();
|
||||||
int read_battery();
|
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
|
#endif
|
||||||
@ -141,3 +141,11 @@ int keypad_get_key(void)
|
|||||||
return act_key;
|
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);
|
void keypad_init(void);
|
||||||
int keypad_get_key(void);
|
int keypad_get_key(void);
|
||||||
|
int keypad_get_battery(void);
|
||||||
#endif // KEY_EVENT_H
|
#endif // KEY_EVENT_H
|
||||||
|
|||||||
@ -344,6 +344,22 @@ void draw_rect_spi(int x1, int y1, int x2, int y2, int c) {
|
|||||||
lcd_spi_raise_cs();
|
lcd_spi_raise_cs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//16x6
|
||||||
|
void draw_battery_icon(int x0, int y0, int level) {
|
||||||
|
draw_rect_spi(x0, y0, x0+14, y0+6, WHITE);
|
||||||
|
draw_rect_spi(x0 + 1, y0 + 1, x0+12, y0+5, BLACK);
|
||||||
|
|
||||||
|
// (2x2)
|
||||||
|
draw_rect_spi(x0 + 14, y0 + 2, x0+14+2, y0+2+2, WHITE);
|
||||||
|
|
||||||
|
for (int i = 0; i <= 13; i++) {
|
||||||
|
if (i < level) {
|
||||||
|
draw_rect_spi(x0 + 1 + i * 1, y0 + 1, x0 + 1 + i*1+1, y0+1+4, WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
Print a char on the LCD display
|
Print a char on the LCD display
|
||||||
Any characters not in the font will print as a space.
|
Any characters not in the font will print as a space.
|
||||||
|
|||||||
@ -123,7 +123,7 @@ void draw_rect_spi(int x1, int y1, int x2, int y2, int c);
|
|||||||
void define_region_spi(int xstart, int ystart, int xend, int yend, int rw);
|
void define_region_spi(int xstart, int ystart, int xend, int yend, int rw);
|
||||||
void draw_line_spi(int x1, int y1, int x2, int y2, int color);
|
void draw_line_spi(int x1, int y1, int x2, int y2, int color);
|
||||||
void lcd_print_string_color(char *s, int fg, int bg);
|
void lcd_print_string_color(char *s, int fg, int bg);
|
||||||
|
void draw_battery_icon(int x0, int y0, int level);
|
||||||
//Print the bitmap of a char on the video output
|
//Print the bitmap of a char on the video output
|
||||||
// x, y - the top left of the char
|
// x, y - the top left of the char
|
||||||
// width, height - size of the char's bitmap
|
// width, height - size of the char's bitmap
|
||||||
|
|||||||
@ -285,7 +285,7 @@ void final_selection_callback(const char *path)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
char buf[64];
|
uint32_t cur_time,last_time=0;
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
uart_init(uart0, 115200);
|
uart_init(uart0, 115200);
|
||||||
@ -301,7 +301,9 @@ int main()
|
|||||||
lcd_init();
|
lcd_init();
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
text_directory_ui_pre_init();
|
text_directory_ui_pre_init();
|
||||||
|
|
||||||
|
cur_time = time_us_64() / 1000;
|
||||||
|
last_time = cur_time;
|
||||||
// Check for SD card presence
|
// Check for SD card presence
|
||||||
DEBUG_PRINT("Checking for SD card...\n");
|
DEBUG_PRINT("Checking for SD card...\n");
|
||||||
if (!sd_card_inserted())
|
if (!sd_card_inserted())
|
||||||
@ -314,11 +316,16 @@ int main()
|
|||||||
text_directory_ui_set_final_callback(final_selection_callback);
|
text_directory_ui_set_final_callback(final_selection_callback);
|
||||||
while (!sd_card_inserted())
|
while (!sd_card_inserted())
|
||||||
{
|
{
|
||||||
|
cur_time = time_us_64() / 1000;
|
||||||
int key = keypad_get_key();
|
int key = keypad_get_key();
|
||||||
if (key != 0)
|
if (key != 0)
|
||||||
process_key_event(key);
|
process_key_event(key);
|
||||||
|
|
||||||
sleep_ms(20);
|
sleep_ms(20);
|
||||||
|
if(cur_time - last_time > BAT_UPDATE_MS) {
|
||||||
|
text_directory_ui_update_header(1);
|
||||||
|
last_time = cur_time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Card detected, wait for it to stabilize
|
// Card detected, wait for it to stabilize
|
||||||
|
|||||||
@ -426,6 +426,20 @@ static void ui_draw_status_bar(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ui_draw_battery_status(){
|
||||||
|
char buf[8];
|
||||||
|
int pcnt = keypad_get_battery();
|
||||||
|
int level = pcnt * 13 / 100;
|
||||||
|
int pad = 0;
|
||||||
|
sprintf(buf,"%d%%",pcnt);
|
||||||
|
int y = UI_Y + HEADER_TITLE_HEIGHT;
|
||||||
|
if(pcnt < 10) { pad = 8;}
|
||||||
|
else if( pcnt >= 10 && pcnt < 100){pad = 0;}
|
||||||
|
else if(pcnt == 100){pad = -8;}
|
||||||
|
//draw_rect_spi(UI_X, y, UI_X + UI_WIDTH - 1, y + PATH_HEADER_HEIGHT - 1, COLOR_BG);
|
||||||
|
draw_text(UI_X + UI_WIDTH-16-20-5+pad, y + 2, buf, COLOR_FG, COLOR_BG);
|
||||||
|
draw_battery_icon(UI_X+UI_WIDTH-16,y+4,level);
|
||||||
|
}
|
||||||
// Refresh the entire UI
|
// Refresh the entire UI
|
||||||
static void ui_refresh(void)
|
static void ui_refresh(void)
|
||||||
{
|
{
|
||||||
@ -436,7 +450,7 @@ static void ui_refresh(void)
|
|||||||
if(entry_count == 0) {
|
if(entry_count == 0) {
|
||||||
ui_draw_empty_tip();
|
ui_draw_empty_tip();
|
||||||
}
|
}
|
||||||
|
ui_draw_battery_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle key events for navigation and selection
|
// Handle key events for navigation and selection
|
||||||
@ -563,8 +577,10 @@ void text_directory_ui_set_status(const char *msg)
|
|||||||
ui_draw_status_bar();
|
ui_draw_status_bar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void text_directory_ui_update_header(uint8_t nosd) {
|
void text_directory_ui_update_header(uint8_t nosd) {
|
||||||
ui_draw_path_header(nosd);
|
ui_draw_path_header(nosd);
|
||||||
|
ui_draw_battery_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_directory_ui_draw_default_app() {
|
void text_directory_ui_draw_default_app() {
|
||||||
@ -578,16 +594,14 @@ void text_directory_ui_draw_default_app() {
|
|||||||
void text_directory_ui_run(void)
|
void text_directory_ui_run(void)
|
||||||
{
|
{
|
||||||
uint32_t last_scroll_update = 0;
|
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)
|
while (true)
|
||||||
{
|
{
|
||||||
|
uint32_t current_time = time_us_64() / 1000;
|
||||||
int key = keypad_get_key();
|
int key = keypad_get_key();
|
||||||
if (key != 0)
|
if (key != 0)
|
||||||
process_key_event(key);
|
process_key_event(key);
|
||||||
|
|
||||||
uint32_t current_time = time_us_64() / 1000;
|
|
||||||
|
|
||||||
// Update scrolling text periodically
|
// Update scrolling text periodically
|
||||||
if (current_time - last_scroll_update > SCROLL_UPDATE_MS)
|
if (current_time - last_scroll_update > SCROLL_UPDATE_MS)
|
||||||
{
|
{
|
||||||
@ -599,21 +613,29 @@ void text_directory_ui_run(void)
|
|||||||
}
|
}
|
||||||
last_scroll_update = current_time;
|
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
|
// Check for SD card removal during runtime
|
||||||
if (!sd_card_inserted()) {
|
if (!sd_card_inserted()) {
|
||||||
text_directory_ui_set_status("SD card removed. Please reinsert.");
|
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();
|
ui_clear_directory_list();
|
||||||
update_required = 1;
|
update_required = 1;
|
||||||
ui_draw_directory_list();
|
ui_draw_directory_list();
|
||||||
// Wait until the SD card is reinserted
|
// Wait until the SD card is reinserted
|
||||||
while (!sd_card_inserted()) {
|
while (!sd_card_inserted()) {
|
||||||
|
current_time = time_us_64() / 1000;
|
||||||
key = keypad_get_key();
|
key = keypad_get_key();
|
||||||
if (key != 0)
|
if (key != 0)
|
||||||
process_key_event(key);
|
process_key_event(key);
|
||||||
|
|
||||||
sleep_ms(20);
|
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
|
// Once reinserted, update the UI and reinitialize filesystem
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
#define ITEMS_PER_PAGE 16
|
#define ITEMS_PER_PAGE 16
|
||||||
#define FONT_HEIGHT 12
|
#define FONT_HEIGHT 12
|
||||||
#define ENTRY_PADDING 2
|
#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.
|
// 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);
|
typedef void (*final_selection_callback_t)(const char *selected_path);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user