From 4a47558ef632650762bf4914184699475e6986e1 Mon Sep 17 00:00:00 2001 From: Mitchell Marino Date: Sat, 12 Jul 2025 18:53:52 -0500 Subject: [PATCH] some header work --- main/drivers/CMakeLists.txt | 1 + main/drivers/char_lcd.cpp | 16 ++++------------ main/drivers/game_info.cpp | 20 ++++++++++++++++++++ main/drivers/game_info.h | 17 +++++++++++++++++ main/drivers/power.cpp | 16 ++++++++++++++++ main/drivers/power.h | 3 +++ main/drivers/star_code.cpp | 13 +++++++++++++ main/drivers/star_code.h | 3 +++ 8 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 main/drivers/game_info.cpp create mode 100644 main/drivers/game_info.h diff --git a/main/drivers/CMakeLists.txt b/main/drivers/CMakeLists.txt index 557d252..4bdebb9 100644 --- a/main/drivers/CMakeLists.txt +++ b/main/drivers/CMakeLists.txt @@ -6,6 +6,7 @@ set(SOURCES "esp_lcd_ili9488/esp_lcd_ili9488.c" "bottom_half.cpp" "char_lcd.cpp" + "game_info.cpp" "game_timer.cpp" "i2c_lcd_pcf8574.c" "i2c.cpp" diff --git a/main/drivers/char_lcd.cpp b/main/drivers/char_lcd.cpp index 288a668..4a2a313 100644 --- a/main/drivers/char_lcd.cpp +++ b/main/drivers/char_lcd.cpp @@ -4,6 +4,7 @@ #include #include "state_tracking.h" #include +#include "power.h" i2c_lcd_pcf8574_handle_t lcd; @@ -223,6 +224,7 @@ void lcd_create_char(uint8_t location, uint8_t* charmap) { } } +// TODO: switch to row, col void lcd_print(uint8_t col, uint8_t row, const char* str) { lcd_set_cursor_pos(col, row); lcd_print(&lcd, str); @@ -236,7 +238,7 @@ void lcd_print(uint8_t col, uint8_t row, const char* str) { void set_lcd_header_enabled(bool enable) { if (!header_enabled && enable) { // enabling header - // TODO: enable header + lcd_print_header(); } else if (header_enabled && !enable) { // disabling header lcd_print(1, 1, EMPTY_ROW); @@ -254,14 +256,4 @@ void lcd_print_header() { lcd_print_header_bat(); } -void lcd_print_header_star_code() { - -} - -void lcd_print_header_step() { - -} - -void lcd_print_header_bat() { - -} +// TODO: add task to continoususly print the header. diff --git a/main/drivers/game_info.cpp b/main/drivers/game_info.cpp new file mode 100644 index 0000000..8be4798 --- /dev/null +++ b/main/drivers/game_info.cpp @@ -0,0 +1,20 @@ +#include "game_info.h" +#include +#include "char_lcd.h" + +static char game_state[GAME_STATE_MAX_LEN+1] = " "; + +void set_game_state(char* new_state) { + snprintf(game_state, sizeof(game_state), "%-5s", new_state); +} + +void reset_game_state() { + for (int i = 0; i < GAME_STATE_MAX_LEN; i++) { + game_state[i] = '\0'; + } + game_state[GAME_STATE_MAX_LEN] = '\0'; +} + +void lcd_print_header_step() { + lcd_print(11, 1, game_state); +} diff --git a/main/drivers/game_info.h b/main/drivers/game_info.h new file mode 100644 index 0000000..bf135be --- /dev/null +++ b/main/drivers/game_info.h @@ -0,0 +1,17 @@ +#ifndef GAME_INFO_H +#define GAME_INFO_H + +#define GAME_STATE_MAX_LEN 5 + +/// @brief Sets the game state, used for the header. +/// +/// Must be <= 5 characters +void set_game_state(char* new_state); + +/// @brief Resets the game state to be blank. +void reset_game_state(); + +/// @brief Prints the game state section of the header to the char_lcd. (row 1, columns 11-15) +void lcd_print_header_step(); + +#endif /* GAME_INFO_H */ \ No newline at end of file diff --git a/main/drivers/power.cpp b/main/drivers/power.cpp index cf7feb4..ee939a4 100644 --- a/main/drivers/power.cpp +++ b/main/drivers/power.cpp @@ -53,3 +53,19 @@ void init_power_board() { uint16_t get_bat_voltage() { return lipo.voltage(); } + +void lcd_print_header_bat() { + uint8_t soc = lipo.soc(); + char buf[5]; + if (soc < 5) { + sprintf(buf, "LOW "); + } else { + snprintf(buf, sizeof(buf), "%3d%%", soc); + } + + if (lipo.chgFlag()) { + buf[4] = '+'; + } + + lcd_print(17, 1, buf); +} diff --git a/main/drivers/power.h b/main/drivers/power.h index a74ac21..2ec8174 100644 --- a/main/drivers/power.h +++ b/main/drivers/power.h @@ -14,4 +14,7 @@ void init_power_board(); /// @return battery voltage in mV. uint16_t get_bat_voltage(); +/// @brief Prints the battery section of the header to the char_lcd. (row 1, columns 17-20) +void lcd_print_header_bat(); + #endif /* POWER_H */ diff --git a/main/drivers/star_code.cpp b/main/drivers/star_code.cpp index d40bfa7..56d0001 100644 --- a/main/drivers/star_code.cpp +++ b/main/drivers/star_code.cpp @@ -5,6 +5,7 @@ #include #include #include "drivers/bottom_half.h" +#include "char_lcd.h" static const char* TAG = "star_code"; @@ -14,6 +15,8 @@ static volatile bool system_initialized = false; static volatile SemaphoreHandle_t star_codes_sem; static std::vector star_codes; +static const char EMPTY_STAR_CODE_HEADER[] = " "; + static volatile bool doing_starcode = false; static uint16_t starcode_waiting_on_release; static char current[STARCODE_MAX_LEN + 1]; @@ -185,3 +188,13 @@ void pause_star_code_system() { void resume_star_code_system() { handling_new_starcodes = system_initialized; } + +void lcd_print_header_star_code() { + if (doing_starcode) { + char buf[STARCODE_MAX_LEN + 2]; + sprintf(buf, "*%-8s", current); + lcd_print(1, 1, buf); + } else { + lcd_print(1, 1, EMPTY_STAR_CODE_HEADER); + } +} diff --git a/main/drivers/star_code.h b/main/drivers/star_code.h index 4c6219d..e6528c2 100644 --- a/main/drivers/star_code.h +++ b/main/drivers/star_code.h @@ -81,4 +81,7 @@ void set_star_code_sys_enabled(bool enable); /// @return `true` if the star code system is handling star codes. bool star_code_sys_enabled(); +/// @brief Prints the star code section of the header to the char_lcd. (row 1, columns 1-10) +void lcd_print_header_star_code(); + #endif /* STAR_CODE_H */ \ No newline at end of file