step 3 fixes
This commit is contained in:
parent
25116bca87
commit
159b8201fe
@ -62,12 +62,14 @@ void step3(void) {
|
|||||||
|
|
||||||
int last_cycle_tick = xTaskGetTickCount();
|
int last_cycle_tick = xTaskGetTickCount();
|
||||||
int scrambled_times = 0;
|
int scrambled_times = 0;
|
||||||
std::vector<int> led_options = all_leds;
|
|
||||||
while (scrambled_times < 5) {
|
while (scrambled_times < 5) {
|
||||||
if (xTaskGetTickCount() - last_cycle_tick > 50) {
|
if ((xTaskGetTickCount() - last_cycle_tick) > pdMS_TO_TICKS(100)) {
|
||||||
|
clean_bomb();
|
||||||
|
std::vector<int> led_options = all_leds;
|
||||||
set_unique_leds_random_color(led_options, led_number_dist(gen), INDICATOR_RED, INDICATOR_GREEN, INDICATOR_BLUE);
|
set_unique_leds_random_color(led_options, led_number_dist(gen), INDICATOR_RED, INDICATOR_GREEN, INDICATOR_BLUE);
|
||||||
led_strip_refresh(leds);
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
last_cycle_tick = xTaskGetTickCount();
|
last_cycle_tick = xTaskGetTickCount();
|
||||||
|
scrambled_times++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +140,8 @@ void step3(void) {
|
|||||||
const int INDICATOR_BLUE[6] = {0, 10, 0, 0, 5, 5};
|
const int INDICATOR_BLUE[6] = {0, 10, 0, 0, 5, 5};
|
||||||
|
|
||||||
set_unique_leds_random_color(indicator_options, indicators_num, INDICATOR_RED, INDICATOR_BLUE, INDICATOR_GREEN);
|
set_unique_leds_random_color(indicator_options, indicators_num, INDICATOR_RED, INDICATOR_BLUE, INDICATOR_GREEN);
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
// ESP_LOGI(TAG, "puzzle 1 LEDs set (%i leds)", indicators_num);
|
// ESP_LOGI(TAG, "puzzle 1 LEDs set (%i leds)", indicators_num);
|
||||||
|
|
||||||
if (indicators_num < 18) {
|
if (indicators_num < 18) {
|
||||||
@ -312,11 +316,11 @@ void step3(void) {
|
|||||||
set_module_time(20000);
|
set_module_time(20000);
|
||||||
start_module_timer();
|
start_module_timer();
|
||||||
|
|
||||||
const int COLOR_RED[4] = {0, 20, 10, 0};
|
const int COLOR_RED[5] = {0, 20, 10, 0, 0};
|
||||||
const int COLOR_GREEN[4] = {20, 0, 10, 0};
|
const int COLOR_GREEN[5] = {20, 0, 10, 0, 0};
|
||||||
const int COLOR_BLUE[4] = {0, 0, 0, 20};
|
const int COLOR_BLUE[5] = {0, 0, 0, 20, 0};
|
||||||
|
|
||||||
static std::uniform_int_distribution<> color_dist(0, 3);
|
static std::uniform_int_distribution<> color_dist(0, 4);
|
||||||
|
|
||||||
int tft_color = color_dist(gen);
|
int tft_color = color_dist(gen);
|
||||||
int speaker_color = color_dist(gen);
|
int speaker_color = color_dist(gen);
|
||||||
@ -380,16 +384,11 @@ void step3(void) {
|
|||||||
const int BUTTON_COLOR_BLUE[4] = {0, 0, 0, 10};
|
const int BUTTON_COLOR_BLUE[4] = {0, 0, 0, 10};
|
||||||
|
|
||||||
static std::uniform_int_distribution<> button_color_dist(0, 3);
|
static std::uniform_int_distribution<> button_color_dist(0, 3);
|
||||||
|
int button_colors[4] = {button_color_dist(gen), button_color_dist(gen), button_color_dist(gen), button_color_dist(gen)};
|
||||||
|
|
||||||
int b1_color = button_color_dist(gen);
|
for (int i = 0; i < 4; i++) {
|
||||||
int b2_color = button_color_dist(gen);
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, (20 - i), BUTTON_COLOR_RED[button_colors[i]], BUTTON_COLOR_GREEN[button_colors[i]], BUTTON_COLOR_BLUE[button_colors[i]]));
|
||||||
int b3_color = button_color_dist(gen);
|
}
|
||||||
int b4_color = button_color_dist(gen);
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 20, BUTTON_COLOR_RED[b1_color], BUTTON_COLOR_GREEN[b1_color], BUTTON_COLOR_BLUE[b1_color]));
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 19, BUTTON_COLOR_RED[b2_color], BUTTON_COLOR_GREEN[b2_color], BUTTON_COLOR_BLUE[b2_color]));
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 18, BUTTON_COLOR_RED[b3_color], BUTTON_COLOR_GREEN[b3_color], BUTTON_COLOR_BLUE[b3_color]));
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 17, BUTTON_COLOR_RED[b4_color], BUTTON_COLOR_GREEN[b4_color], BUTTON_COLOR_BLUE[b4_color]));
|
|
||||||
|
|
||||||
// switches
|
// switches
|
||||||
const int SWITCH_COLOR_RED[3] = {20, 0, 10};
|
const int SWITCH_COLOR_RED[3] = {20, 0, 10};
|
||||||
@ -406,47 +405,81 @@ void step3(void) {
|
|||||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
|
|
||||||
ButtonKey button;
|
ButtonKey button;
|
||||||
|
SwitchKey switch_key;
|
||||||
uint8_t starting_switch_state = get_switch_state();
|
uint8_t starting_switch_state = get_switch_state();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (get_pressed_button(&button)) {
|
if (get_pressed_button(&button)) {
|
||||||
uint8_t button_state = get_button_state();
|
uint8_t button_state = get_button_state();
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (((button_state >> i) & 0b1) == 0b1) {
|
||||||
|
button_colors[i]++;
|
||||||
|
if (button_colors[i] > 3) {
|
||||||
|
button_colors[i] = 0;
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, (20 - i), BUTTON_COLOR_RED[button_colors[i]], BUTTON_COLOR_GREEN[button_colors[i]], BUTTON_COLOR_BLUE[button_colors[i]]));
|
||||||
|
}
|
||||||
|
|
||||||
// change button colors
|
|
||||||
if ((button_state & 0b1) == 0b1) {
|
|
||||||
b1_color++;
|
|
||||||
if (b1_color > 3) {
|
|
||||||
b1_color = 0;
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 20, BUTTON_COLOR_RED[b1_color], BUTTON_COLOR_GREEN[b1_color], BUTTON_COLOR_BLUE[b1_color]));
|
|
||||||
}
|
|
||||||
if ((button_state & 0b10) == 0b10) {
|
|
||||||
b2_color++;
|
|
||||||
if (b2_color > 3) {
|
|
||||||
b2_color = 0;
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 19, BUTTON_COLOR_RED[b2_color], BUTTON_COLOR_GREEN[b2_color], BUTTON_COLOR_BLUE[b2_color]));
|
|
||||||
}
|
|
||||||
if ((button_state & 0b100) == 0b100) {
|
|
||||||
b3_color++;
|
|
||||||
if (b3_color > 3) {
|
|
||||||
b3_color = 0;
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 18, BUTTON_COLOR_RED[b3_color], BUTTON_COLOR_GREEN[b3_color], BUTTON_COLOR_BLUE[b3_color]));
|
|
||||||
}
|
|
||||||
if ((button_state & 0b1000) == 0b1000) {
|
|
||||||
b4_color++;
|
|
||||||
if (b4_color > 3) {
|
|
||||||
b4_color = 0;
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, 17, BUTTON_COLOR_RED[b4_color], BUTTON_COLOR_GREEN[b4_color], BUTTON_COLOR_BLUE[b4_color]));
|
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
|
|
||||||
|
if (button_colors[0] == 0 && button_colors[1] == 1 && button_colors[2] == 2 && button_colors[3] == 3) {
|
||||||
|
// check switch state
|
||||||
|
uint8_t switch_state = get_switch_state();
|
||||||
|
bool correct = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (switch_colors[i] == 2) {
|
||||||
|
if ((((switch_state ^ starting_switch_state) >> i) & 0b1) != 1) {
|
||||||
|
correct = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (((switch_state >> i) & 0b1) != (switch_colors[i] & 0b1)) {
|
||||||
|
correct = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (correct) {
|
||||||
|
solved_puzzles++;
|
||||||
|
solved_correctly = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (get_flipped_switch(&switch_key)) {
|
||||||
|
if (button_colors[0] == 0 && button_colors[1] == 1 && button_colors[2] == 2 && button_colors[3] == 3) {
|
||||||
|
// check switch state
|
||||||
|
uint8_t switch_state = get_switch_state();
|
||||||
|
bool correct = true;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (switch_colors[i] == 2) {
|
||||||
|
if ((((switch_state ^ starting_switch_state) >> i) & 0b1) != 1) {
|
||||||
|
correct = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (((switch_state >> i) & 0b1) != (switch_colors[i] & 0b1)) {
|
||||||
|
correct = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (correct) {
|
||||||
|
solved_puzzles++;
|
||||||
|
solved_correctly = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (get_module_time() <= 0) {
|
if (get_module_time() <= 0) {
|
||||||
// check button state
|
// check button state
|
||||||
if (b1_color == 0 && b2_color == 1 && b3_color == 2 && b4_color == 3) {
|
if (button_colors[0] == 0 && button_colors[1] == 1 && button_colors[2] == 2 && button_colors[3] == 3) {
|
||||||
// check switch state
|
// check switch state
|
||||||
uint8_t switch_state = get_switch_state();
|
uint8_t switch_state = get_switch_state();
|
||||||
bool correct = true;
|
bool correct = true;
|
||||||
@ -680,9 +713,9 @@ void step3(void) {
|
|||||||
int expression_answer = -1;
|
int expression_answer = -1;
|
||||||
std::string display_expression;
|
std::string display_expression;
|
||||||
|
|
||||||
std::vector<int> possible_math_operations = {0, 1, 2, 3};
|
|
||||||
while (expression_answer < 0) {
|
while (expression_answer < 0) {
|
||||||
math_numbers = {static_cast<float>(math_number_dist(gen)), static_cast<float>(math_number_dist(gen)), static_cast<float>(math_number_dist(gen)), static_cast<float>(math_number_dist(gen))};
|
math_numbers = {static_cast<float>(math_number_dist(gen)), static_cast<float>(math_number_dist(gen)), static_cast<float>(math_number_dist(gen)), static_cast<float>(math_number_dist(gen))};
|
||||||
|
std::vector<int> possible_math_operations = {0, 1, 2, 3};
|
||||||
math_operations = unique_values(possible_math_operations, 3);
|
math_operations = unique_values(possible_math_operations, 3);
|
||||||
|
|
||||||
display_expression = std::to_string(static_cast<int>(math_numbers[0]));
|
display_expression = std::to_string(static_cast<int>(math_numbers[0]));
|
||||||
@ -910,6 +943,7 @@ void step3(void) {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
stop_module_timer();
|
||||||
if (solved_correctly) {
|
if (solved_correctly) {
|
||||||
play_raw(MOUNT_POINT "/correct.pcm");
|
play_raw(MOUNT_POINT "/correct.pcm");
|
||||||
vTaskDelay(pdMS_TO_TICKS(500));
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user