blk_box_tc/main/steps/step0.cpp
2024-08-12 22:40:37 -05:00

220 lines
6.3 KiB
C++

#include "step0.h"
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(); }
static void issue_strike(void) { strike("Strike Issued"); }
/// Wait for "*9819"
void step0(void) {
StarCodeHandler star_codes[] = {
{
.code = "*9819",
.display_text = "Diffusal Initiated",
.should_exit = true,
.callback = nullptr,
},
{
.code = "*59861",
.display_text = "Set Up Wires",
.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,
},
{
.code = "*1111",
.display_text = "Issue Strike",
.should_exit = false,
.callback = issue_strike,
},
};
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));
}
}