From 8bddceca66cc7ab43d4d0c119045d1f63942ded3 Mon Sep 17 00:00:00 2001 From: Mitchell Marino Date: Thu, 21 Aug 2025 20:03:16 -0500 Subject: [PATCH] update starcodes --- main/drivers/game_info.cpp | 2 ++ main/drivers/power.cpp | 4 +++- main/drivers/star_code.cpp | 26 ++++++++++++++++---------- main/drivers/star_code.h | 9 ++++++--- main/steps/step0.cpp | 8 ++++---- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/main/drivers/game_info.cpp b/main/drivers/game_info.cpp index 27069c8..f98ac9e 100644 --- a/main/drivers/game_info.cpp +++ b/main/drivers/game_info.cpp @@ -1,4 +1,5 @@ #include "game_info.h" +#include "star_code.h" #include #include "char_lcd.h" @@ -17,6 +18,7 @@ void reset_game_state() { void lcd_print_header_step() { if (!lcd_header_enabled()) return; + if (lcd_starcode_displaying_result()) return; lcd_print(11, 0, game_state); } diff --git a/main/drivers/power.cpp b/main/drivers/power.cpp index dbb6be5..5a8bab5 100644 --- a/main/drivers/power.cpp +++ b/main/drivers/power.cpp @@ -1,5 +1,6 @@ #include "power.h" #include "char_lcd.h" +#include "star_code.h" #include static const char* TAG = "power"; @@ -56,10 +57,11 @@ uint16_t get_bat_voltage() { void lcd_print_header_bat() { if (!lcd_header_enabled()) return; + if (lcd_starcode_displaying_result()) return; uint8_t soc = lipo.soc(); uint8_t current = lipo.current(); - char buf[4]; + char buf[5]; if (soc < 5 && current <= 0) { snprintf(buf, sizeof(buf), "LOW"); } else if (soc == 100) { diff --git a/main/drivers/star_code.cpp b/main/drivers/star_code.cpp index c5cd39f..423b81b 100644 --- a/main/drivers/star_code.cpp +++ b/main/drivers/star_code.cpp @@ -20,8 +20,10 @@ static std::vector star_codes; static const char EMPTY_STAR_CODE_HEADER[] = " "; esp_timer_handle_t starcode_delay_timer; -static volatile bool processing_starcode; +/// @brief `true` if we are delaying for a starcode +static volatile bool delaying_for_starcode; static volatile StarCodeEntry* current_starcode = nullptr; +/// @brief `true` when we are handling user input for a starcode static volatile bool doing_starcode = false; static uint16_t starcode_waiting_on_release; static char current[STARCODE_MAX_LEN + 1]; @@ -30,7 +32,7 @@ static size_t current_idx; static void starcode_trigger_cb(void* arg) { (void) arg; - processing_starcode = false; + delaying_for_starcode = false; if (current_starcode != nullptr) { if (current_starcode->triggered_sem != nullptr) @@ -42,12 +44,12 @@ static void starcode_trigger_cb(void* arg) { } // TODO: rename star code everywhere to starcode - lcd_print_header_star_code(); + lcd_print_header(); } void star_code_handle_keypad(uint16_t* just_pressed, uint16_t* just_released) { - if ((!processing_starcode) && handling_new_starcodes && (*just_pressed & (1 << KeypadKey::star))) { + if ((!delaying_for_starcode) && handling_new_starcodes && (*just_pressed & (1 << KeypadKey::star))) { current_idx = 0; current[current_idx] = '\0'; doing_starcode = true; @@ -130,7 +132,7 @@ bool add_star_code(StarCodeEntry code) { ESP_LOGW(TAG, "invalid code"); return false; } - if (code.display_text != nullptr && strlen(code.display_text) > STARCODE_MAX_LEN + 1) { + if (code.display_text != nullptr && strlen(code.display_text) > STARCODE_DISPLAY_TEXT_MAX_LEN) { ESP_LOGW(TAG, "invalid display_text"); return false; } @@ -206,7 +208,7 @@ bool trigger_star_code(const char* code) { }); uint64_t delay_us = 2'000'000; - processing_starcode = true; + delaying_for_starcode = true; if (it != star_codes.end()) { current_starcode = &*it; delay_us = current_starcode->delay_us; @@ -230,12 +232,12 @@ void lcd_print_header_star_code() { if (!lcd_header_enabled()) return; // TODO: consider upping the display text size to be able to overwrite the game_state area. - if (processing_starcode) { + if (delaying_for_starcode) { if (current_starcode == nullptr) { - lcd_print(0, 0, "Invalid "); + lcd_print(0, 0, "Invalid starcode "); } else if (current_starcode->display_text != nullptr) { - char buf[STARCODE_MAX_LEN + 2]; - snprintf(buf, sizeof(buf), "%-10s", current_starcode->display_text); + char buf[21]; + snprintf(buf, sizeof(buf), "%-20s", current_starcode->display_text); lcd_print(0, 0, buf); } else { lcd_print(0, 0, EMPTY_STAR_CODE_HEADER); @@ -248,3 +250,7 @@ void lcd_print_header_star_code() { lcd_print(0, 0, EMPTY_STAR_CODE_HEADER); } } + +bool lcd_starcode_displaying_result() { + return delaying_for_starcode; +} diff --git a/main/drivers/star_code.h b/main/drivers/star_code.h index caf4803..d60cefb 100644 --- a/main/drivers/star_code.h +++ b/main/drivers/star_code.h @@ -7,6 +7,7 @@ /// The max length of a starcode (not counting the star) #define STARCODE_MAX_LEN 9 +#define STARCODE_DISPLAY_TEXT_MAX_LEN 20 /// @brief A handler for a specific star code struct StarCodeEntry { @@ -18,7 +19,7 @@ struct StarCodeEntry { const char* code; /// @brief The text to display when the star code is entered (or null). /// - /// This must be <= 10 characters. + /// This must be <= 20 characters. const char* display_text; /// @brief The number of microseconds to delay when the star code is entered before calling the handler. uint64_t delay_us; @@ -77,11 +78,13 @@ bool trigger_star_code(const char* code); /// If one is being handled currently, it is canceled. void set_star_code_sys_enabled(bool enable); -/// @brief Gets weather or not the star code system is handling new star codes. -/// @return `true` if the star code system is handling star codes. +/// @return `true` iff 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 0, columns 0-9) void lcd_print_header_star_code(); +/// @return `true` iff the starcode system is using the full header. +bool lcd_starcode_displaying_result(); + #endif /* STAR_CODE_H */ \ No newline at end of file diff --git a/main/steps/step0.cpp b/main/steps/step0.cpp index 0308885..44d4bb9 100644 --- a/main/steps/step0.cpp +++ b/main/steps/step0.cpp @@ -59,28 +59,28 @@ void step0() { StarCodeEntry star_codes[] = { { .code = "9819", - .display_text = "Diffuse", + .display_text = "Diffusal Initiated", .delay_us = 2'000'000, .callback = nullptr, .triggered_sem = continue_sem, }, { .code = "59861", - .display_text = "Set Wires", + .display_text = "Setup Wires", .delay_us = 10'000'000, .callback = setup_wires, .triggered_sem = nullptr, }, { .code = "59862", - .display_text = "Set Time", + .display_text = "Set Game Time", .delay_us = 2'000'000, .callback = set_game_time, .triggered_sem = nullptr, }, { .code = "59863", - .display_text = "DBG switch", + .display_text = "Debug switches", .delay_us = 2'000'000, .callback = debug_switches, .triggered_sem = nullptr,