update strike reasons. Add star codes

This commit is contained in:
Mitchell Marino 2024-08-11 17:44:47 -05:00
parent 68b8f980df
commit 9a48eb63e1
5 changed files with 208 additions and 12 deletions

View File

@ -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();

View File

@ -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));
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}