From aadd924bd00abe719825d3c3c2a15e588dc777f6 Mon Sep 17 00:00:00 2001 From: Mitchell Marino Date: Fri, 22 Aug 2025 11:44:22 -0500 Subject: [PATCH] switch to row, column --- main/drivers/char_lcd.cpp | 23 +++++++++++------------ main/drivers/char_lcd.h | 6 +++--- main/drivers/game_info.cpp | 2 +- main/drivers/power.cpp | 8 ++++---- main/drivers/sd.cpp | 8 ++++---- main/drivers/wires.cpp | 2 +- main/steps/setup_wires.cpp | 4 ++-- main/steps/step0.cpp | 16 ++++++++-------- main/steps/step1.cpp | 2 +- main/steps/step5.cpp | 12 ++++++------ 10 files changed, 41 insertions(+), 42 deletions(-) diff --git a/main/drivers/char_lcd.cpp b/main/drivers/char_lcd.cpp index 32bb85b..393cdd9 100644 --- a/main/drivers/char_lcd.cpp +++ b/main/drivers/char_lcd.cpp @@ -73,14 +73,14 @@ static bool replay_handler(const char* event, char* arg) { } else if (strcmp(event, "LCD_PRINT") == 0) { char* str = strtok(arg, ","); - uint8_t col = atoi(str); - str = strtok(NULL, ","); uint8_t row = atoi(str); + str = strtok(NULL, ","); + uint8_t col = atoi(str); // get remaining part of string. str = strtok(NULL, ""); // TODO: handle \r and \n - lcd_print(col, row, str); + lcd_print(row, col, str); } else { return false; } @@ -117,9 +117,9 @@ void lcd_clear(bool no_lock) { } } else { if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY); - lcd_print(0, 1, EMPTY_ROW, true); - lcd_print(0, 2, EMPTY_ROW, true); - lcd_print(0, 3, EMPTY_ROW, true); + lcd_print(1, 0, EMPTY_ROW, true); + lcd_print(2, 0, EMPTY_ROW, true); + lcd_print(3, 0, EMPTY_ROW, true); if (!no_lock) xSemaphoreGive(lcd_mutex); } } @@ -237,7 +237,7 @@ void lcd_create_char(uint8_t location, const uint8_t charmap[], bool no_lock) { if (!no_lock) xSemaphoreGive(lcd_mutex); if (is_state_tracking()) { - snprintf(buf, 65, + snprintf(buf, sizeof(buf), "%d,%d,%d,%d,%d,%d,%d,%d,%d", location, charmap[0], charmap[1], charmap[2], charmap[3], charmap[4], charmap[5], charmap[6], charmap[7] ); @@ -245,8 +245,7 @@ void lcd_create_char(uint8_t location, const uint8_t charmap[], bool no_lock) { } } -// TODO: switch to row, col -void lcd_print(uint8_t col, uint8_t row, const char* str, bool no_lock) { +void lcd_print(uint8_t row, uint8_t col, const char* str, bool no_lock) { if (!no_lock) xSemaphoreTake(lcd_mutex, portMAX_DELAY); lcd_set_cursor(&lcd, col, row); lcd_print(&lcd, str); @@ -254,7 +253,7 @@ void lcd_print(uint8_t col, uint8_t row, const char* str, bool no_lock) { if (is_state_tracking()) { // TODO: handle \r and \n and others - snprintf(buf, sizeof(buf), "%d,%d,%s", col, row, str); + snprintf(buf, sizeof(buf), "%d,%d,%s", row, col, str); event_occured("LCD_PRINT", buf); } } @@ -300,8 +299,8 @@ void lcd_do_splash() { lcd_create_char(5, custom_char[4], true); lcd_create_char(6, custom_char[5], true); - lcd_print(6, 1, "\x01\x02Marino", true); - lcd_print(5, 2, "\x03\x04\x05\x06""DEV", true); + lcd_print(1, 6, "\x01\x02Marino", true); + lcd_print(2, 5, "\x03\x04\x05\x06""DEV", true); xSemaphoreGive(lcd_mutex); } diff --git a/main/drivers/char_lcd.h b/main/drivers/char_lcd.h index 884f0e9..bfc5347 100644 --- a/main/drivers/char_lcd.h +++ b/main/drivers/char_lcd.h @@ -6,8 +6,8 @@ #define CHAR_LCD_I2C_NUM I2C_NUM_0 #define LCD_ADDR 0x27 -#define LCD_COLS 20 #define LCD_ROWS 4 +#define LCD_COLS 20 /// @brief Initializes the 2004 Character LCD void init_lcd(); @@ -49,10 +49,10 @@ void lcd_set_backlight(bool backlight, bool no_lock = false); void lcd_create_char(uint8_t location, const uint8_t charmap[], bool no_lock = false); /// @brief Print a string to the LCD at a given pos. -/// @param col the column to print the string at. /// @param row the row the print the string at. +/// @param col the column to print the string at. /// @param str the string to print. -void lcd_print(uint8_t col, uint8_t row, const char* str, bool no_lock = false); +void lcd_print(uint8_t row, uint8_t col, const char* str, bool no_lock = false); /// @brief Enables or disables the header on the LCD. /// @param enable `true` to enable the header, `false` to disable. diff --git a/main/drivers/game_info.cpp b/main/drivers/game_info.cpp index 26b8ded..de2d854 100644 --- a/main/drivers/game_info.cpp +++ b/main/drivers/game_info.cpp @@ -17,5 +17,5 @@ void lcd_print_header_step() { if (!lcd_header_enabled()) return; if (lcd_starcode_displaying_result()) return; - lcd_print(10, 0, game_state); + lcd_print(0, 10, game_state); } diff --git a/main/drivers/power.cpp b/main/drivers/power.cpp index 6931f89..abfac17 100644 --- a/main/drivers/power.cpp +++ b/main/drivers/power.cpp @@ -12,7 +12,7 @@ void bat_monitor_task(void* arg) { sprintf(str_buf, "%d.%03dV", voltage / 1000, voltage % 1000); lcd_clear(); - lcd_print(1, 0, str_buf); + lcd_print(0, 1, str_buf); int16_t current = lipo.current(current_measure::AVG); sprintf(str_buf, "%dmA", current); @@ -23,12 +23,12 @@ void bat_monitor_task(void* arg) { int16_t total_cap = lipo.capacity(capacity_measure::FULL); sprintf(str_buf, "%dmAh", total_cap); - lcd_print(1, 2, str_buf); + lcd_print(2, 1, str_buf); int16_t soc = lipo.soc(soc_measure::FILTERED); sprintf(str_buf, "%d%%", soc); - lcd_print(1, 3, str_buf); + lcd_print(3, 1, str_buf); vTaskDelay(pdMS_TO_TICKS(250)); @@ -74,5 +74,5 @@ void lcd_print_header_bat() { } } - lcd_print(16, 0, buf); + lcd_print(0, 16, buf); } diff --git a/main/drivers/sd.cpp b/main/drivers/sd.cpp index 0cd3697..ab4c018 100644 --- a/main/drivers/sd.cpp +++ b/main/drivers/sd.cpp @@ -51,10 +51,10 @@ bool init_sd() { ESP_LOGE(TAG, "Failed to mount sd card: %s.", esp_err_to_name(ret)); lcd_print(0, 0, "SD: "); - lcd_print(4, 0, esp_err_to_name(ret)); - lcd_print(0, 1, "Press Green to retry"); - lcd_print(0, 2, "Press Yellow to skip"); - lcd_print(0, 3, "Press Red to format"); + lcd_print(0, 4, esp_err_to_name(ret)); + lcd_print(1, 0, "Press Green to retry"); + lcd_print(2, 0, "Press Yellow to skip"); + lcd_print(3, 0, "Press Red to format"); ButtonKey button; while (!( get_button_pressed(&button) && (button == ButtonKey::button_green || button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10)); diff --git a/main/drivers/wires.cpp b/main/drivers/wires.cpp index 185508d..bc257d3 100644 --- a/main/drivers/wires.cpp +++ b/main/drivers/wires.cpp @@ -85,7 +85,7 @@ void clear_wires_pressed_released_cut(void) { void strike(const char* reason) { ESP_LOGW("strike!", "%s", reason); - lcd_print(0, 3, reason); + lcd_print(3, 0, reason); time_penalty(STRIKE_TIME_PENALTY); if (current_step > 0 && current_step <= N_STEPS) { total_strikes += 1; diff --git a/main/steps/setup_wires.cpp b/main/steps/setup_wires.cpp index 99f9bcb..e1c3eb4 100644 --- a/main/steps/setup_wires.cpp +++ b/main/steps/setup_wires.cpp @@ -11,7 +11,7 @@ void print_wires(WireColor* wires, int editing_idx) { lcd_print(1, 1, string_buf); cut_to_string(cut, string_buf); - lcd_print(1, 2, string_buf); + lcd_print(2, 1, string_buf); wires_state = get_wires(); for (int i = 0; i < NUM_WIRES; i++) { @@ -21,7 +21,7 @@ void print_wires(WireColor* wires, int editing_idx) { string_buf[i] = '!'; } } - lcd_print(1, 3, string_buf); + lcd_print(3, 1, string_buf); // TODO: find a way to indicate without a cursor. // lcd_set_cursor_pos(editing_idx+1, 1); diff --git a/main/steps/step0.cpp b/main/steps/step0.cpp index 7205db1..17c438f 100644 --- a/main/steps/step0.cpp +++ b/main/steps/step0.cpp @@ -336,32 +336,32 @@ static void debug_switches() { while (1) { if (get_button_pressed(&button)) { sprintf(buf, "Button Pressed: %d ", button); - lcd_print(0, 3, buf); + lcd_print(3, 0, buf); ESP_LOGI(TAG, "%s", buf); } if (get_button_released(&button)) { sprintf(buf, "Button Released: %d", button); - lcd_print(0, 3, buf); + lcd_print(3, 0, buf); ESP_LOGI(TAG, "%s", buf); } if (get_switch_flipped_down(&switch_)) { sprintf(buf, "Switch Down: %d ", switch_); - lcd_print(0, 3, buf); + lcd_print(3, 0, buf); ESP_LOGI(TAG, "%s", buf); } if (get_switch_flipped_up(&switch_)) { sprintf(buf, "Switch Up: %d ", switch_); - lcd_print(0, 3, buf); + lcd_print(3, 0, buf); ESP_LOGI(TAG, "%s", buf); } if (get_switch_touch_pressed(&switch_)) { sprintf(buf, "Switch Touch: %d ", switch_); - lcd_print(0, 3, buf); + lcd_print(3, 0, buf); ESP_LOGI(TAG, "%s", buf); } if (get_switch_touch_released(&switch_)) { sprintf(buf, "Switch Un-touch: %d", switch_); - lcd_print(0, 3, buf); + lcd_print(3, 0, buf); ESP_LOGI(TAG, "%s", buf); } @@ -370,7 +370,7 @@ static void debug_switches() { switch_touch_state = new_switch_touch_state; print_4bin_rev(bin_buf, switch_touch_state); sprintf(buf, "t: %s", bin_buf); - lcd_print(1, 0, buf); + lcd_print(0, 1, buf); ESP_LOGI(TAG, "%s", buf); } @@ -388,7 +388,7 @@ static void debug_switches() { button_state = new_button_state; print_4bin_rev(bin_buf, button_state); sprintf(buf, "b: %s", bin_buf); - lcd_print(1, 2, buf); + lcd_print(2, 1, buf); ESP_LOGI(TAG, "%s", buf); } diff --git a/main/steps/step1.cpp b/main/steps/step1.cpp index 99a600b..a82fa72 100644 --- a/main/steps/step1.cpp +++ b/main/steps/step1.cpp @@ -199,7 +199,7 @@ static int generate_part(void) { static void update_lcd_count(int times) { char buf[16] = {0}; sprintf(buf, "%d/15", times); - lcd_print(14, 1, buf); + lcd_print(1, 14, buf); } static bool play_part(uint32_t time) { diff --git a/main/steps/step5.cpp b/main/steps/step5.cpp index 873e7ed..9c26af3 100644 --- a/main/steps/step5.cpp +++ b/main/steps/step5.cpp @@ -729,7 +729,7 @@ void step5(void) { } // display expression - lcd_print(1, 2, display_expression.c_str()); + lcd_print(2, 1, display_expression.c_str()); // set LEDs const uint32_t COLORS[] = { @@ -790,8 +790,8 @@ void step5(void) { lcd_clear(); lcd_print(1, 1, "What"); - lcd_print(1, 2, display_expression.c_str()); - lcd_print(1, 3, entered_string.c_str()); + lcd_print(2, 1, display_expression.c_str()); + lcd_print(3, 1, entered_string.c_str()); } if (get_module_time() <= 0) { strike("Ran out of time!"); @@ -849,7 +849,7 @@ void step5(void) { // ESP_LOGI(TAG, "color string: %s", color_string.c_str()); - lcd_print(1, 2, color_string.c_str()); + lcd_print(2, 1, color_string.c_str()); std::string entered_string; @@ -880,8 +880,8 @@ void step5(void) { lcd_clear(); lcd_print(1, 1, "Plink"); - lcd_print(1, 2, color_string.c_str()); - lcd_print(1, 3, entered_string.c_str()); + lcd_print(2, 1, color_string.c_str()); + lcd_print(3, 1, entered_string.c_str()); } if (get_module_time() <= 0) { strike("Ran out of time!");