From 0b816aca68e03d71ea820d0ffee700f0b6cdb4fe Mon Sep 17 00:00:00 2001 From: Mitchell M Date: Wed, 28 Aug 2024 17:50:26 -0500 Subject: [PATCH] fix warnings --- main/drivers/game_timer.cpp | 10 +++++--- main/drivers/game_timer.h | 4 ++-- main/drivers/wires.cpp | 2 +- main/drivers/wires.h | 2 +- main/helper.cpp | 36 ++++++++++++++++++++++++++++ main/helper.h | 6 +++-- main/main.cpp | 34 ++------------------------- main/steps/step0.cpp | 47 +++++++++++++++++++++++++++++++++++++ main/steps/step2.cpp | 8 +++---- main/steps/step5.cpp | 2 -- 10 files changed, 103 insertions(+), 48 deletions(-) diff --git a/main/drivers/game_timer.cpp b/main/drivers/game_timer.cpp index c5a7fc8..f80b5f0 100644 --- a/main/drivers/game_timer.cpp +++ b/main/drivers/game_timer.cpp @@ -51,7 +51,7 @@ void stop_module_timer(void) { is_module_playing = false; } -void set_game_time(uint32_t new_time) { +void set_game_time(int32_t new_time) { if (new_time > 0) { game_time_count_up = false; game_time_left = new_time; @@ -62,8 +62,12 @@ void set_game_time(uint32_t new_time) { write_game_time(game_time_left); } -uint32_t get_game_time() { - return game_time_left; +int32_t get_game_time() { + if (game_time_count_up) { + return -((int32_t) game_time_left); + } else { + return ((int32_t) game_time_left); + } } void set_module_time(uint32_t new_time) { diff --git a/main/drivers/game_timer.h b/main/drivers/game_timer.h index c0913d7..86a7b2b 100644 --- a/main/drivers/game_timer.h +++ b/main/drivers/game_timer.h @@ -18,9 +18,9 @@ void start_module_timer(void); void stop_module_timer(void); /// Sets the game time in ms -void set_game_time(uint32_t new_time); +void set_game_time(int32_t new_time); /// Gets the current game time in ms -uint32_t get_game_time(); +int32_t get_game_time(); /// Gets the current game time in ms void time_penalty(uint32_t penalty); diff --git a/main/drivers/wires.cpp b/main/drivers/wires.cpp index 9c9da69..d292791 100644 --- a/main/drivers/wires.cpp +++ b/main/drivers/wires.cpp @@ -79,7 +79,7 @@ void clear_wires_pressed_released_cut(void) { button_released = false; } -void strike(char* reason) { +void strike(const char* reason) { ESP_LOGW("strike!", "%s", reason); lcd_set_cursor(&lcd, 0, 3); lcd_print(&lcd, reason); diff --git a/main/drivers/wires.h b/main/drivers/wires.h index 03474f0..77aa1ab 100644 --- a/main/drivers/wires.h +++ b/main/drivers/wires.h @@ -29,6 +29,6 @@ void clear_wires_pressed_released_cut(void); void set_leds(uint8_t led_states); -void strike(char* reason); +void strike(const char* reason); #endif /* WIRES_HPP */ \ No newline at end of file diff --git a/main/helper.cpp b/main/helper.cpp index 4160911..0030796 100644 --- a/main/helper.cpp +++ b/main/helper.cpp @@ -102,3 +102,39 @@ void do_star_codes(StarCodeHandler* star_codes, int star_codes_len) { vTaskDelay(pdMS_TO_TICKS(10)); } } + +static lv_style_t game_results_style; +static lv_obj_t* game_results_label; + +static char str_buf[10] = {0}; +static char* write_time(uint32_t game_time) { + uint8_t hours = (game_time / (1000*60*60)) % 10; + uint8_t minutes = (game_time / (1000*60)) % 60; + uint8_t seconds = (game_time / (1000)) % 60; + + sprintf(str_buf, "%d:%d:%d", hours, minutes, seconds); + return str_buf; +} + +void display_game_results(void) { + if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) { + lv_style_init(&game_results_style); + lv_style_set_text_color(&game_results_style, lv_color_white()); + lv_style_set_bg_color(&game_results_style, lv_color_black()); + lv_style_set_bg_opa(&game_results_style, LV_OPA_100); + lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_CENTER); + + game_results_label = lv_label_create(lv_scr_act()); + lv_obj_add_flag(game_results_label, LV_OBJ_FLAG_HIDDEN); + lv_obj_align(game_results_label, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_style(game_results_label, &game_results_style, LV_STATE_DEFAULT); + + char buf[100] = {0}; + char* time = write_time(get_game_time()); + sprintf(buf, "Finished!\nTotal Time (w/ penalties): %s\nTotal Strikes: %ld", time, total_strikes); + + lv_label_set_text(game_results_label, buf); + + xSemaphoreGive(xGuiSemaphore); + } +} diff --git a/main/helper.h b/main/helper.h index aa28ba3..98697d9 100644 --- a/main/helper.h +++ b/main/helper.h @@ -8,10 +8,11 @@ #include "drivers/char_lcd.h" #include "drivers/leds.h" #include "drivers/speaker.h" +#include "drivers/tft.h" struct StarCodeHandler { - char* code; - char* display_text; + const char* code; + const char* display_text; bool should_exit; void (*callback)(void); }; @@ -23,5 +24,6 @@ struct StarCodeHandler { void clean_bomb(void); void poster_child_task(void* arg); void do_star_codes(StarCodeHandler* star_codes, int star_codes_len); +void display_game_results(); #endif /* HELPER_H */ diff --git a/main/main.cpp b/main/main.cpp index 76ddc32..c340010 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -28,38 +28,6 @@ static const char *TAG = "main"; uint32_t initial_game_time = 60*60*1000; uint32_t skip_to_step = 0; -static void print_bin(char* out_str, uint8_t n) { - out_str[0] = ((n & 0b1000) ? '1' : '0'); - out_str[1] = ((n & 0b0100) ? '1' : '0'); - out_str[2] = ((n & 0b0010) ? '1' : '0'); - out_str[3] = ((n & 0b0001) ? '1' : '0'); -} - -static void debug_switches() { - uint8_t switch_state = 0; - uint8_t button_state = 0; - - char buff[5] = {0}; - - while (1) { - uint8_t new_button_state = get_button_state(); - if (new_button_state != button_state) { - button_state = new_button_state; - print_bin(buff, button_state); - ESP_LOGI("main", "b: 0b%s", buff); - } - - uint8_t new_switch_state = get_switch_state(); - if (new_switch_state != switch_state) { - switch_state = new_switch_state; - print_bin(buff, switch_state); - ESP_LOGI("main", "s: 0b%s", buff); - } - - vTaskDelay(pdMS_TO_TICKS(10)); - } -} - extern "C" void app_main(void) { printf("app_main\n"); @@ -95,5 +63,7 @@ extern "C" void app_main(void) { stop_game_timer(); ESP_LOGI(TAG, "Bomb has been diffused. Counter-Terrorists win."); ESP_ERROR_CHECK_WITHOUT_ABORT(play_raw("/sdcard/diffused.pcm")); + + display_game_results(); } diff --git a/main/steps/step0.cpp b/main/steps/step0.cpp index 9a9f33c..dd91295 100644 --- a/main/steps/step0.cpp +++ b/main/steps/step0.cpp @@ -19,6 +19,7 @@ static void try_step4(void) { clean_bomb(); step4(); } static void try_step5(void) { clean_bomb(); step5(); } static void try_step6(void) { clean_bomb(); step6(); } static void issue_strike(void) { strike("Strike Issued"); } +static void debug_switches(void); /// Wait for "*9819" void step0(void) { @@ -43,6 +44,12 @@ void step0(void) { .should_exit = false, .callback = set_game_time, }, + { + .code = "*598623", + .display_text = "Debug Switches", + .should_exit = false, + .callback = debug_switches, + }, { .code = "*59871", .display_text = "Try Step 1", @@ -232,3 +239,43 @@ static void set_game_time(void) { vTaskDelay(pdMS_TO_TICKS(10)); } } + + +static void print_bin(char* out_str, uint8_t n) { + out_str[0] = ((n & 0b1000) ? '1' : '0'); + out_str[1] = ((n & 0b0100) ? '1' : '0'); + out_str[2] = ((n & 0b0010) ? '1' : '0'); + out_str[3] = ((n & 0b0001) ? '1' : '0'); +} + +static void debug_switches(void) { + clean_bomb(); + uint8_t switch_state = 0; + uint8_t button_state = 0; + + char buff[5] = {0}; + + KeypadKey key; + while (1) { + uint8_t new_button_state = get_button_state(); + if (new_button_state != button_state) { + button_state = new_button_state; + print_bin(buff, button_state); + ESP_LOGI("main", "b: 0b%s", buff); + } + + uint8_t new_switch_state = get_switch_state(); + if (new_switch_state != switch_state) { + switch_state = new_switch_state; + print_bin(buff, switch_state); + ESP_LOGI("main", "s: 0b%s", buff); + } + + if (get_pressed_keypad(&key) && key == KeypadKey::pound) { + return; + } + + vTaskDelay(pdMS_TO_TICKS(10)); + } +} + diff --git a/main/steps/step2.cpp b/main/steps/step2.cpp index 2709837..536313e 100644 --- a/main/steps/step2.cpp +++ b/main/steps/step2.cpp @@ -90,8 +90,7 @@ void step2(void) { int solved_times = 0; new_puzzle(); - int strike_time = xTaskGetTickCount(); - bool striked = false; + int strike_time = 0; while(solved_times < NUM_SOLVES) { // for every bit in the answer- set_module_sseg_raw(display_map); @@ -111,13 +110,12 @@ void step2(void) { } } else { strike_time = xTaskGetTickCount(); - striked = true; strike("Incorrect Character!"); } } - if (xTaskGetTickCount() - strike_time > pdMS_TO_TICKS(5000)) { - striked = false; + if (strike_time != 0 && xTaskGetTickCount() - strike_time > pdMS_TO_TICKS(5000)) { + strike_time = 0; lcd_clear(&lcd); } vTaskDelay(pdMS_TO_TICKS(10)); diff --git a/main/steps/step5.cpp b/main/steps/step5.cpp index 932ae34..49a602a 100644 --- a/main/steps/step5.cpp +++ b/main/steps/step5.cpp @@ -386,8 +386,6 @@ void step5(void) { int buttons_pressed = 0; ButtonKey button; - KeypadKey key; - while (1) { if (get_pressed_button(&button)) { buttons_pressed++;