From 9a48eb63e18855fc9e712eda11b6896639e7472e Mon Sep 17 00:00:00 2001 From: Mitchell M Date: Sun, 11 Aug 2024 17:44:47 -0500 Subject: [PATCH] update strike reasons. Add star codes --- main/main.cpp | 14 ++-- main/steps/step0.cpp | 189 +++++++++++++++++++++++++++++++++++++++++++ main/steps/step0.h | 7 +- main/steps/step1.cpp | 4 +- main/steps/step3.cpp | 6 +- 5 files changed, 208 insertions(+), 12 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 3eb56c2..d3a4a42 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -25,6 +25,8 @@ #include "steps/step6.h" static const char *TAG = "main"; +uint32_t initial_game_time = 60*60*1000; +uint32_t skip_to_step = 0; extern "C" void app_main(void) { printf("app_main\n"); @@ -45,17 +47,17 @@ extern "C" void app_main(void) { set_game_time(60*60*1000 + 1000); start_game_timer(); clean_bomb(); - step1(); + if (skip_to_step <= 1) step1(); clean_bomb(); - step2(); + if (skip_to_step <= 2) step2(); clean_bomb(); - step3(); + if (skip_to_step <= 3) step3(); clean_bomb(); - step4(); + if (skip_to_step <= 4) step4(); clean_bomb(); - step5(); + if (skip_to_step <= 5) step5(); clean_bomb(); - step6(); + if (skip_to_step <= 6) step6(); clean_bomb(); stop_game_timer(); diff --git a/main/steps/step0.cpp b/main/steps/step0.cpp index 4e3fcf8..c6da0ec 100644 --- a/main/steps/step0.cpp +++ b/main/steps/step0.cpp @@ -2,6 +2,23 @@ static const char* TAG = "step0"; +extern uint32_t initial_game_time; +extern uint32_t skip_to_step; + +static void set_game_time(void); +static void skip_to_step1(void) { skip_to_step = 1; } +static void skip_to_step2(void) { skip_to_step = 2; } +static void skip_to_step3(void) { skip_to_step = 3; } +static void skip_to_step4(void) { skip_to_step = 4; } +static void skip_to_step5(void) { skip_to_step = 5; } +static void skip_to_step6(void) { skip_to_step = 6; } +static void try_step1(void) { clean_bomb(); step1(); } +static void try_step2(void) { clean_bomb(); step2(); } +static void try_step3(void) { clean_bomb(); step3(); } +static void try_step4(void) { clean_bomb(); step4(); } +static void try_step5(void) { clean_bomb(); step5(); } +static void try_step6(void) { clean_bomb(); step6(); } + /// Wait for "*9819" void step0(void) { StarCodeHandler star_codes[] = { @@ -17,7 +34,179 @@ void step0(void) { .should_exit = false, .callback = setup_wires, }, + { + .code = "*59862", + .display_text = "Set Game Time", + .should_exit = false, + .callback = set_game_time, + }, + { + .code = "*59871", + .display_text = "Try Step 1", + .should_exit = false, + .callback = try_step1, + }, + { + .code = "*59872", + .display_text = "Try Step 2", + .should_exit = false, + .callback = try_step2, + }, + { + .code = "*59873", + .display_text = "Try Step 3", + .should_exit = false, + .callback = try_step3, + }, + { + .code = "*59874", + .display_text = "Try Step 4", + .should_exit = false, + .callback = try_step4, + }, + { + .code = "*59875", + .display_text = "Try Step 5", + .should_exit = false, + .callback = try_step5, + }, + { + .code = "*59876", + .display_text = "Try Step 6", + .should_exit = false, + .callback = try_step6, + }, + { + .code = "*59881", + .display_text = "Skip To Step 1", + .should_exit = true, + .callback = skip_to_step1, + }, + { + .code = "*59882", + .display_text = "Skip To Step 2", + .should_exit = true, + .callback = skip_to_step2, + }, + { + .code = "*59883", + .display_text = "Skip To Step 3", + .should_exit = true, + .callback = skip_to_step3, + }, + { + .code = "*59884", + .display_text = "Skip To Step 4", + .should_exit = true, + .callback = skip_to_step4, + }, + { + .code = "*59885", + .display_text = "Skip To Step 5", + .should_exit = true, + .callback = skip_to_step5, + }, + { + .code = "*59886", + .display_text = "Skip To Step 6", + .should_exit = true, + .callback = skip_to_step6, + }, }; int len = sizeof(star_codes)/sizeof(StarCodeHandler); do_star_codes(star_codes, len); } + +static const char* SECONDS_OR_MINUTES[] = { + "Minutes", + "Seconds", +}; + +static const int STRING_MAX_LEN = 8; +static void set_game_time(void) { + KeypadKey key; + bool seconds = true; + + int current = initial_game_time / 1000; + char str_buf[21] = {0}; + + lcd_clear(&lcd); + lcd_set_cursor(&lcd, 1, 1); + sprintf(str_buf, "%d", current); + lcd_print(&lcd, str_buf); + lcd_set_cursor(&lcd, 1, 2); + lcd_print(&lcd, SECONDS_OR_MINUTES[seconds]); + + while (1) { + while (get_pressed_keypad(&key)) { + if (key == KeypadKey::star) { + current = 0; + } else if (key == KeypadKey::pound) { + // submit + if (current == 0) { + clean_bomb(); + return; + } + + if (seconds) { + initial_game_time = current * 1000; + } else { + initial_game_time = current * 60*1000; + } + clean_bomb(); + return; + } else if (key == KeypadKey::ka) { + if (seconds) { + current = current / 60; + } else { + current = current * 60; + } + seconds = !seconds; + } else { + int just_pressed = 0; + switch (key) { + case KeypadKey::k1: + just_pressed = 1; + break; + case KeypadKey::k2: + just_pressed = 2; + break; + case KeypadKey::k3: + just_pressed = 3; + break; + case KeypadKey::k4: + just_pressed = 4; + break; + case KeypadKey::k5: + just_pressed = 5; + break; + case KeypadKey::k6: + just_pressed = 6; + break; + case KeypadKey::k7: + just_pressed = 7; + break; + case KeypadKey::k8: + just_pressed = 8; + break; + case KeypadKey::k9: + just_pressed = 9; + break; + default: + break; + } + + current = (current * 10) + just_pressed; + } + + lcd_clear(&lcd); + lcd_set_cursor(&lcd, 1, 1); + sprintf(str_buf, "%d", current); + lcd_print(&lcd, str_buf); + lcd_set_cursor(&lcd, 1, 2); + lcd_print(&lcd, SECONDS_OR_MINUTES[seconds]); + } + + vTaskDelay(pdMS_TO_TICKS(10)); + } +} diff --git a/main/steps/step0.h b/main/steps/step0.h index 892964a..9fe35f0 100644 --- a/main/steps/step0.h +++ b/main/steps/step0.h @@ -7,7 +7,12 @@ #include "setup_wires.h" #include "../helper.h" -#define STRING_MAX_LEN 8 +#include "step1.h" +#include "step2.h" +#include "step3.h" +#include "step4.h" +#include "step5.h" +#include "step6.h" /// Wait for "*9819" void step0(void); diff --git a/main/steps/step1.cpp b/main/steps/step1.cpp index c4b5ae6..e03d7dd 100644 --- a/main/steps/step1.cpp +++ b/main/steps/step1.cpp @@ -232,7 +232,7 @@ static bool play_part(uint32_t time) { if (times >= 15) break; correct = generate_part(); } else { - strike("Incorrect color action"); + strike("Incorrect action"); } } while (get_flipped_switch(&switch_)) { @@ -242,7 +242,7 @@ static bool play_part(uint32_t time) { if (times >= 15) break; correct = generate_part(); } else { - strike("Incorrect color action"); + strike("Incorrect action"); } } if (get_module_time() <= 0) { diff --git a/main/steps/step3.cpp b/main/steps/step3.cpp index da1e916..8ed9011 100644 --- a/main/steps/step3.cpp +++ b/main/steps/step3.cpp @@ -95,7 +95,7 @@ void step3(void) { if (flipped_state == green_indicators) { solved_puzzles++; } else { - strike("Incorrect switch combination! (step 3, puzzle 0)"); + strike("Incorrect Switches"); } break; } @@ -127,7 +127,7 @@ void step3(void) { solved_puzzles++; // ESP_LOGI(TAG, "puzzle 1 solved (switches)!"); } else { - strike("Switch state was changed! (step 3, puzzle 1)"); + strike("Switch State Changed"); } break; } @@ -150,7 +150,7 @@ void step3(void) { // ESP_LOGI(TAG, "puzzle 1 solved (keypad)!"); } } else { - strike("Switch state was changed! (step 3, puzzle 1)"); + strike("Switch State Changed"); } break; }