Step 2 & 5 fixes
This commit is contained in:
parent
23b7ffa7f7
commit
2333776f4e
@ -14,7 +14,7 @@ static const uint8_t SSEG_MAPS[5][4] = {
|
||||
};
|
||||
|
||||
static const int INDICATOR_RED[5] = {15, 0, 0, 10, 5};
|
||||
static const int INDICATOR_GREEN[5] = {0, 0, 10, 5, 5};
|
||||
static const int INDICATOR_GREEN[5] = {0, 0, 10, 5, 7};
|
||||
static const int INDICATOR_BLUE[5] = {0, 10, 0, 0, 5};
|
||||
|
||||
// random number generators
|
||||
|
||||
@ -90,10 +90,15 @@ bool submit_2(bool* lit_leds, int green_pressed, int blue_pressed, int fingerpri
|
||||
uint8_t switch_state = get_switch_state() & 0b11;
|
||||
|
||||
bool rfid_correct = (lit_leds[0] && (green_pressed == 1)) || (!lit_leds[0] && (green_pressed == 0));
|
||||
ESP_LOGI(TAG, "rfid_correct: %i", rfid_correct);
|
||||
bool lcd_correct = (lit_leds[1] && (blue_pressed == 1)) || (!lit_leds[1] && (blue_pressed == 0));
|
||||
ESP_LOGI(TAG, "lcd_correct: %i", lcd_correct);
|
||||
bool speaker_correct = (lit_leds[2] && (fingerprint_pressed == 2)) || (!lit_leds[2] && (fingerprint_pressed == 0));
|
||||
ESP_LOGI(TAG, "speaker_correct: %i", speaker_correct);
|
||||
bool keypad_correct = (lit_leds[3] && (keypad_string == "12")) || (!lit_leds[3] && (keypad_string == ""));
|
||||
ESP_LOGI(TAG, "keypad_correct: %i", keypad_correct);
|
||||
bool tft_correct = (lit_leds[4] && (switch_state == 0b11)) || !lit_leds[4];
|
||||
ESP_LOGI(TAG, "tft_correct: %i", tft_correct);
|
||||
|
||||
if (rfid_correct && lcd_correct && speaker_correct && keypad_correct && tft_correct) {
|
||||
return true;
|
||||
@ -134,15 +139,15 @@ bool submit_4(int* button_colors, int* switch_colors, uint8_t initial_switch_sta
|
||||
}
|
||||
|
||||
bool submit_5(std::array<int, 4> indicator_numbers, std::array<int, 4> buttons_pressed) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (buttons_pressed == indicator_numbers) {
|
||||
if (buttons_pressed != indicator_numbers) {
|
||||
ESP_LOGI(TAG, "Button State: %i, %i, %i, %i, Indicator Numbers: %i, %i, %i, %i", buttons_pressed[0], buttons_pressed[1], buttons_pressed[2], buttons_pressed[3], indicator_numbers[0], indicator_numbers[1], indicator_numbers[2], indicator_numbers[3]);
|
||||
strike("Wrong button state!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t switch_state = get_switch_state();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ESP_LOGI(TAG, "Switch State: %i, Indicator Number: %i", ((switch_state >> i) & 0b1), indicator_numbers[i]);
|
||||
if (((switch_state >> i) & 0b1) == (indicator_numbers[i] & 0b1)) {
|
||||
strike("Wrong switch state!");
|
||||
return false;
|
||||
@ -163,16 +168,16 @@ bool submit_6(bool* buttons_cycling, bool button_turned_on, int led_off) {
|
||||
}
|
||||
|
||||
void step5(void) {
|
||||
StarCodeHandler star_codes[] = {
|
||||
{
|
||||
.code = "*2648",
|
||||
.display_text = "Starting...",
|
||||
.should_exit = true,
|
||||
.callback = nullptr,
|
||||
},
|
||||
};
|
||||
int len = sizeof(star_codes)/sizeof(StarCodeHandler);
|
||||
do_star_codes(star_codes, len);
|
||||
// StarCodeHandler star_codes[] = {
|
||||
// {
|
||||
// .code = "*2648",
|
||||
// .display_text = "Starting...",
|
||||
// .should_exit = true,
|
||||
// .callback = nullptr,
|
||||
// },
|
||||
// };
|
||||
// int len = sizeof(star_codes)/sizeof(StarCodeHandler);
|
||||
// do_star_codes(star_codes, len);
|
||||
|
||||
std::vector<int> all_leds;
|
||||
|
||||
@ -204,8 +209,8 @@ void step5(void) {
|
||||
lcd_set_cursor(&lcd, 1, 1);
|
||||
bool solved_correctly = false;
|
||||
|
||||
int puzzle = puzzle_dist(gen);
|
||||
// int puzzle = 6;
|
||||
// int puzzle = puzzle_dist(gen);
|
||||
int puzzle = 2;
|
||||
|
||||
switch (puzzle) {
|
||||
case 0: {
|
||||
@ -221,24 +226,18 @@ void step5(void) {
|
||||
set_unique_leds(indicator_options, green_indicators, 0, 10, 0);
|
||||
|
||||
// set non-green
|
||||
const int NON_GREEN_INDICATOR_RED[3] = {30, 0, 15};
|
||||
const int NON_GREEN_INDICATOR_RED[3] = {20, 0, 10};
|
||||
const int NON_GREEN_INDICATOR_GREEN[3] = {0, 0, 0};
|
||||
const int NON_GREEN_INDICATOR_BLUE[3] = {0, 30, 15};
|
||||
const int NON_GREEN_INDICATOR_BLUE[3] = {0, 10, 5};
|
||||
std::uniform_int_distribution<> non_green_indicators_dist(0, (20 - green_indicators));
|
||||
set_unique_leds_random_color(indicator_options, non_green_indicators_dist(gen), NON_GREEN_INDICATOR_RED, NON_GREEN_INDICATOR_GREEN, NON_GREEN_INDICATOR_BLUE);
|
||||
|
||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||
|
||||
// wait for time
|
||||
// wait for submit
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (char_of_keypad_key(key) == '#') {
|
||||
solved_correctly = submit_0(green_indicators);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (get_module_time() <= 0) {
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_0(green_indicators);
|
||||
break;
|
||||
}
|
||||
@ -286,7 +285,7 @@ void step5(void) {
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
set_module_time(25000);
|
||||
set_module_time(40000);
|
||||
start_module_timer();
|
||||
|
||||
std::map<int, int> idx_to_led_map = {
|
||||
@ -319,7 +318,6 @@ void step5(void) {
|
||||
ButtonKey button;
|
||||
|
||||
while (1) {
|
||||
// add if strike when wrong instead of at the end
|
||||
if (get_pressed_button(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
@ -340,6 +338,7 @@ void step5(void) {
|
||||
}
|
||||
if (get_touch_pressed()) {
|
||||
fingerprint_sensor_pressed++;
|
||||
// ESP_LOGI(TAG, "touch sensor pressed");
|
||||
if ((fingerprint_sensor_pressed > 2) || !lit_leds[2]) {
|
||||
strike("Too many times!");
|
||||
break;
|
||||
@ -351,6 +350,7 @@ void step5(void) {
|
||||
solved_correctly = submit_2(lit_leds, green_button_pressed, blue_button_pressed, fingerprint_sensor_pressed, keypad_string);
|
||||
break;
|
||||
} else {
|
||||
// ESP_LOGI(TAG, "pressed %c", char_of_keypad_key(key));
|
||||
keypad_string += char_of_keypad_key(key);
|
||||
}
|
||||
}
|
||||
@ -368,11 +368,11 @@ void step5(void) {
|
||||
set_module_time(25000);
|
||||
start_module_timer();
|
||||
|
||||
const int COLOR_RED[5] = {0, 20, 10, 0, 0};
|
||||
const int COLOR_GREEN[5] = {20, 0, 10, 0, 0};
|
||||
const int COLOR_BLUE[5] = {0, 0, 0, 20, 0};
|
||||
const int COLOR_RED[5] = {0, 20, 10, 0};
|
||||
const int COLOR_GREEN[5] = {20, 0, 10, 0};
|
||||
const int COLOR_BLUE[5] = {0, 0, 0, 20};
|
||||
|
||||
static std::uniform_int_distribution<> color_dist(0, 4);
|
||||
static std::uniform_int_distribution<> color_dist(0, 3);
|
||||
|
||||
int tft_color = color_dist(gen);
|
||||
int speaker_color = color_dist(gen);
|
||||
@ -386,6 +386,7 @@ void step5(void) {
|
||||
int buttons_pressed = 0;
|
||||
|
||||
ButtonKey button;
|
||||
KeypadKey key;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
@ -407,9 +408,9 @@ void step5(void) {
|
||||
strike("Wrong button!");
|
||||
} else {
|
||||
solved_correctly = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (get_module_time() <= 0) {
|
||||
@ -471,8 +472,7 @@ void step5(void) {
|
||||
}
|
||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||
}
|
||||
get_pressed_keypad(&key);
|
||||
if (get_module_time() <= 0 || char_of_keypad_key(key) == '#') {
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_4(button_colors, switch_colors, starting_switch_state);
|
||||
break;
|
||||
}
|
||||
@ -507,27 +507,30 @@ void step5(void) {
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
bool failed = false;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (((button_state >> i) & 0b1) == 0b1) {
|
||||
buttons_pressed[i]++;
|
||||
if (buttons_pressed[i] > indicator_numbers[i]) {
|
||||
strike("Too many times!");
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
break;
|
||||
}
|
||||
get_pressed_keypad(&key);
|
||||
if (get_module_time() <= 0 || char_of_keypad_key(key) == '#') {
|
||||
}
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
ESP_LOGI(TAG, "Keypad Char: %c, time: %lu", char_of_keypad_key(key), get_module_time());
|
||||
solved_correctly = submit_5(indicator_numbers, buttons_pressed);
|
||||
break;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
@ -570,12 +573,14 @@ void step5(void) {
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
bool failed = false;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (((button_state >> i) & 0b1) == 0b1) {
|
||||
if (button_colors[i] == -1) {
|
||||
if (button_turned_on) {
|
||||
strike("Pressed after on!");
|
||||
failed = true;
|
||||
break;
|
||||
} else if (led_turn_on_dist(gen) == 0) {
|
||||
button_turned_on = true;
|
||||
@ -584,12 +589,16 @@ void step5(void) {
|
||||
}
|
||||
} else if (button_colors[i] != CORRECT_COLORS[i]) {
|
||||
strike("Wrong time!");
|
||||
failed = true;
|
||||
break;
|
||||
} else {
|
||||
buttons_cycling[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((xTaskGetTickCount() - lastCycleTime) >= pdMS_TO_TICKS(500)) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@ -606,7 +615,7 @@ void step5(void) {
|
||||
lastCycleTime = xTaskGetTickCount();
|
||||
}
|
||||
get_pressed_keypad(&key);
|
||||
if (get_module_time() <= 0 || char_of_keypad_key(key) == '#') {
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_6(buttons_cycling, button_turned_on, led_off);
|
||||
break;
|
||||
}
|
||||
@ -616,7 +625,7 @@ void step5(void) {
|
||||
}
|
||||
case 7: {
|
||||
lcd_print(&lcd, "What");
|
||||
set_module_time(50000);
|
||||
set_module_time(55000);
|
||||
start_module_timer();
|
||||
|
||||
std::uniform_int_distribution<> math_number_dist(1, 9);
|
||||
@ -703,7 +712,8 @@ void step5(void) {
|
||||
|
||||
int modifier_indicators[4] = {add_sub_indicator_dist(gen), add_sub_indicator_dist(gen), mult_div_indicator_dist(gen), mult_div_indicator_dist(gen)};
|
||||
|
||||
while ((((expression_answer + (modifier_indicators[0] * 3) - modifier_indicators[1]) * (3 ^ modifier_indicators[2])) / (2 ^ modifier_indicators[3])) < 0) {
|
||||
|
||||
while ((((expression_answer + (modifier_indicators[0] * 3) - modifier_indicators[1]) * std::pow(3, modifier_indicators[2])) / std::pow(2, modifier_indicators[3])) < 0) {
|
||||
modifier_indicators[0] = add_sub_indicator_dist(gen);
|
||||
modifier_indicators[1] = add_sub_indicator_dist(gen);
|
||||
modifier_indicators[2] = mult_div_indicator_dist(gen);
|
||||
@ -712,8 +722,8 @@ void step5(void) {
|
||||
|
||||
expression_answer += modifier_indicators[0] * 3;
|
||||
expression_answer -= modifier_indicators[1];
|
||||
expression_answer *= 3 ^ modifier_indicators[2];
|
||||
expression_answer /= 2 ^ modifier_indicators[3];
|
||||
expression_answer *= std::pow(3, modifier_indicators[2]);
|
||||
expression_answer /= std::pow(2, modifier_indicators[3]);
|
||||
|
||||
std::vector<int> led_options = all_leds;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@ -723,9 +733,9 @@ void step5(void) {
|
||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||
|
||||
std::string answer_string = std::to_string(expression_answer);
|
||||
std::string entered_string;
|
||||
std::string entered_string = "";
|
||||
|
||||
// ESP_LOGI(TAG, "Solved full answer: %s", answer_string.c_str());
|
||||
ESP_LOGI(TAG, "Solved full answer: %s", answer_string.c_str());
|
||||
|
||||
KeypadKey key;
|
||||
|
||||
@ -738,8 +748,8 @@ void step5(void) {
|
||||
// submit
|
||||
if (entered_string != answer_string) {
|
||||
strike("Incorrect answer!");
|
||||
break;
|
||||
} else {
|
||||
solved_puzzles++;
|
||||
solved_correctly = true;
|
||||
}
|
||||
break;
|
||||
@ -818,6 +828,8 @@ void step5(void) {
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
bool failed = false;
|
||||
|
||||
if (key == KeypadKey::star) {
|
||||
// clear
|
||||
entered_string = "";
|
||||
@ -825,14 +837,19 @@ void step5(void) {
|
||||
// submit
|
||||
if (entered_string != answer_num) {
|
||||
strike("Incorrect answer!");
|
||||
failed = true;
|
||||
} else {
|
||||
solved_times++;
|
||||
solved_correctly = true;;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
entered_string += char_of_keypad_key(key);
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
break;
|
||||
}
|
||||
|
||||
lcd_clear(&lcd);
|
||||
lcd_set_cursor(&lcd, 1, 1);
|
||||
lcd_print(&lcd, "Plink");
|
||||
@ -869,6 +886,7 @@ void step5(void) {
|
||||
} else {
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
}
|
||||
clear_all_pressed_released();
|
||||
clean_bomb();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user