Refactor char_lcd functions

This commit is contained in:
2025-03-25 17:16:54 -05:00
parent 7e00a6d950
commit af93abb8cb
20 changed files with 260 additions and 108 deletions
+7 -10
View File
@@ -6,16 +6,13 @@ void print_wires(WireColor* wires, int editing_idx) {
bool cut[NUM_WIRES];
solve_wires(wires, cut);
lcd_set_cursor(&lcd, 1, 1);
char string_buf[NUM_WIRES+1] = {0};
wires_to_string(wires, string_buf);
lcd_print(&lcd, string_buf);
lcd_print(1, 1, string_buf);
lcd_set_cursor(&lcd, 1, 2);
cut_to_string(cut, string_buf);
lcd_print(&lcd, string_buf);
lcd_print(1, 2, string_buf);
lcd_set_cursor(&lcd, 1, 3);
wires_state = get_wires();
for (int i = 0; i < NUM_WIRES; i++) {
if (wires_state & (1<<i)) {
@@ -24,16 +21,16 @@ void print_wires(WireColor* wires, int editing_idx) {
string_buf[i] = '!';
}
}
lcd_print(&lcd, string_buf);
lcd_print(1, 3, string_buf);
lcd_set_cursor(&lcd, editing_idx+1, 1);
lcd_set_cursor_pos(editing_idx+1, 1);
}
void setup_wires(void) {
clear_all_pressed_released();
get_cut_wires();
lcd_clear(&lcd);
lcd_cursor(&lcd);
lcd_clear();
lcd_set_cursor_vis(false);
WireColor wires[NUM_WIRES];
load_wires_from_sd_card(wires);
@@ -51,7 +48,7 @@ void setup_wires(void) {
save_wires_to_sd_card(wires);
print_wires(wires, editing_idx);
} else if (key == KeypadKey::pound) {
lcd_no_cursor(&lcd);
lcd_set_cursor_vis(false);
return;
}
}
+4 -5
View File
@@ -156,12 +156,11 @@ static const int CURSOR_POS_MAP[5] = {1, 3, 4, 6, 7};
static char str_buf[18] = {0};
static void _update_display(uint8_t* digits, uint8_t cursor_pos) {
sprintf(str_buf, "%d:%d%d:%d%d", digits[0], digits[1], digits[2], digits[3], digits[4]);
lcd_clear(&lcd);
lcd_set_cursor(&lcd, 1, 1);
lcd_print(&lcd, str_buf);
lcd_clear();
lcd_print(1, 1, str_buf);
cursor_pos = MAX(0, MIN(4, cursor_pos));
int mapped_cursor_pos = CURSOR_POS_MAP[cursor_pos];
lcd_set_cursor(&lcd, mapped_cursor_pos, 1);
lcd_set_cursor_pos(mapped_cursor_pos, 1);
}
static void set_game_time(void) {
@@ -170,7 +169,7 @@ static void set_game_time(void) {
uint8_t seconds = (initial_game_time / (1000)) % 60;
uint8_t digits[5] = {hours, (uint8_t)(minutes / 10), (uint8_t)(minutes % 10), (uint8_t)(seconds / 10), (uint8_t)(seconds % 10)};
uint8_t cursor_pos = 0;
lcd_cursor(&lcd);
lcd_set_cursor_vis(true);
_update_display(digits, cursor_pos);
+6 -7
View File
@@ -196,27 +196,26 @@ static int generate_part(void) {
static void update_lcd_count(int times) {
char buf[16] = {0};
sprintf(buf, "%d/15", times);
lcd_set_cursor(&lcd, 14, 1);
lcd_print(&lcd, buf);
lcd_print(14, 1, buf);
}
static bool play_part(uint32_t time) {
stop_module_timer();
set_module_time(time);
lcd_clear(&lcd);
lcd_set_cursor(&lcd, 1, 1);
lcd_clear();
lcd_set_cursor_pos(1, 1);
switch (part) {
case 0:
lcd_print(&lcd, "COLOR");
lcd_print("COLOR");
led_strip_set_pixel(leds, Led::char_lcd, 20, 0, 20);
break;
case 1:
lcd_print(&lcd, "NUMBER");
lcd_print("NUMBER");
led_strip_set_pixel(leds, Led::char_lcd, 0, 0, 30);
break;
case 2:
lcd_print(&lcd, "SWITCH");
lcd_print("SWITCH");
led_strip_set_pixel(leds, Led::char_lcd, 20, 20, 0);
break;
}
+2 -2
View File
@@ -96,7 +96,7 @@ void step2(void) {
// for every bit in the answer-
set_module_sseg_raw(display_map);
if (get_pressed_keypad(&key)) {
lcd_clear(&lcd);
lcd_clear();
char c = char_of_keypad_key(key);
// ESP_LOGI(TAG, "Pressed: %c", c);
if (c == answer_char) {
@@ -117,7 +117,7 @@ void step2(void) {
if (strike_time != 0 && xTaskGetTickCount() - strike_time > pdMS_TO_TICKS(5000)) {
strike_time = 0;
lcd_clear(&lcd);
lcd_clear();
}
vTaskDelay(pdMS_TO_TICKS(10));
}
+4 -7
View File
@@ -211,9 +211,8 @@ static bool one_second() {
int lcd_string_idx = lcd_string_dist(gen);
bool was_high = (tone / 3) == 1;
write_leds();
lcd_clear(&lcd);
lcd_set_cursor(&lcd, 1, 1);
lcd_print(&lcd, LCD_STRINGS[lcd_string_idx]);
lcd_clear();
lcd_print(1, 1, LCD_STRINGS[lcd_string_idx]);
int red_led_count = 0;
int blue_led_count = 0;
@@ -268,8 +267,7 @@ static bool three_second() {
int lcd_number = lcd_number_dist(gen);
char lcd_number_string[9] = {0};
sprintf(lcd_number_string, "%d", lcd_number);
lcd_set_cursor(&lcd, 1, 1);
lcd_print(&lcd, lcd_number_string);
lcd_print(1, 1, lcd_number_string);
bool was_high = (tone / 3) == 1;
@@ -331,8 +329,7 @@ static bool six_second() {
generate_random_lcd_text();
vTaskDelay(pdMS_TO_TICKS(10));
lcd_set_cursor(&lcd, 0, 0);
lcd_print(&lcd, random_lcd_text);
lcd_print(0, 0, random_lcd_text);
int vowels = 0;
for (int i = 0; i < 20; i++) {
+2 -3
View File
@@ -657,9 +657,8 @@ static void check_line_clears(void) {
static void update_score(void) {
char buff[16] = {};
sprintf(buff, "%d/%d", score, target_score);
lcd_clear(&lcd);
lcd_set_cursor(&lcd, 1, 1);
lcd_print(&lcd, buff);
lcd_clear();
lcd_print(1, 1, buff);
}
static void line_clear(int hi) {
+19 -27
View File
@@ -217,7 +217,7 @@ void step5(void) {
clean_bomb();
int solved_puzzles = 0;
while (solved_puzzles < TIMES_TO_SOLVE) {
lcd_set_cursor(&lcd, 1, 1);
lcd_set_cursor_pos(1, 1);
bool solved_correctly = false;
int puzzle = puzzle_dist(gen);
@@ -225,7 +225,7 @@ void step5(void) {
switch (puzzle) {
case 0: {
lcd_print(&lcd, "Clear");
lcd_print("Clear");
set_module_time(TIME_CLEAR);
start_module_timer();
@@ -258,7 +258,7 @@ void step5(void) {
break;
}
case 1: {
lcd_print(&lcd, "Blank");
lcd_print("Blank");
set_module_time(TIME_BLANK);
start_module_timer();
@@ -375,7 +375,7 @@ void step5(void) {
break;
}
case 3: {
lcd_print(&lcd, "Nothing");
lcd_print("Nothing");
set_module_time(TIME_NOTHING);
start_module_timer();
@@ -431,7 +431,7 @@ void step5(void) {
break;
}
case 4: {
lcd_print(&lcd, "Blink");
lcd_print("Blink");
set_module_time(TIME_BLINK);
start_module_timer();
@@ -490,7 +490,7 @@ void step5(void) {
break;
}
case 5: {
lcd_print(&lcd, "Ummm");
lcd_print("Ummm");
set_module_time(TIME_UMMM);
start_module_timer();
@@ -543,7 +543,7 @@ void step5(void) {
break;
}
case 6: {
lcd_print(&lcd, "Plank");
lcd_print("Plank");
set_module_time(TIME_PLANK);
start_module_timer();
@@ -632,7 +632,7 @@ void step5(void) {
break;
}
case 7: {
lcd_print(&lcd, "What");
lcd_print("What");
set_module_time(TIME_WHAT);
start_module_timer();
@@ -705,8 +705,7 @@ void step5(void) {
}
// display expression
lcd_set_cursor(&lcd, 1, 2);
lcd_print(&lcd, display_expression.c_str());
lcd_print(1, 2, display_expression.c_str());
// set LEDs
@@ -764,13 +763,10 @@ void step5(void) {
entered_string += char_of_keypad_key(key);
}
lcd_clear(&lcd);
lcd_set_cursor(&lcd, 1, 1);
lcd_print(&lcd, "What");
lcd_set_cursor(&lcd, 1, 2);
lcd_print(&lcd, display_expression.c_str());
lcd_set_cursor(&lcd, 1, 3);
lcd_print(&lcd, entered_string.c_str());
lcd_clear();
lcd_print(1, 1, "What");
lcd_print(1, 2, display_expression.c_str());
lcd_print(1, 3, entered_string.c_str());
}
if (get_module_time() <= 0) {
strike("Ran out of time!");
@@ -783,7 +779,7 @@ void step5(void) {
break;
}
case 8: {
lcd_print(&lcd, "Plink");
lcd_print("Plink");
set_module_time(TIME_PLINK);
start_module_timer();
@@ -826,8 +822,7 @@ void step5(void) {
// ESP_LOGI(TAG, "color string: %s", color_string.c_str());
lcd_set_cursor(&lcd, 1, 2);
lcd_print(&lcd, color_string.c_str());
lcd_print(1, 2, color_string.c_str());
std::string entered_string;
@@ -856,13 +851,10 @@ void step5(void) {
break;
}
lcd_clear(&lcd);
lcd_set_cursor(&lcd, 1, 1);
lcd_print(&lcd, "Plink");
lcd_set_cursor(&lcd, 1, 2);
lcd_print(&lcd, color_string.c_str());
lcd_set_cursor(&lcd, 1, 3);
lcd_print(&lcd, entered_string.c_str());
lcd_clear();
lcd_print(1, 1, "Plink");
lcd_print(1, 2, color_string.c_str());
lcd_print(1, 3, entered_string.c_str());
}
if (get_module_time() <= 0) {
strike("Ran out of time!");