tweaks to all steps
This commit is contained in:
parent
159b8201fe
commit
99a5402e76
@ -1,6 +1,6 @@
|
|||||||
#include "speaker.h"
|
#include "speaker.h"
|
||||||
|
|
||||||
static i2s_chan_handle_t tx_chan;
|
i2s_chan_handle_t tx_chan;
|
||||||
|
|
||||||
static const char *TAG = "speaker_driver";
|
static const char *TAG = "speaker_driver";
|
||||||
|
|
||||||
@ -18,7 +18,11 @@ esp_err_t play_raw(const char *fp) {
|
|||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
size_t bytes_written = 0;
|
size_t bytes_written = 0;
|
||||||
|
|
||||||
ESP_ERROR_CHECK(i2s_channel_enable(tx_chan));
|
esp_err_t channel_enable_result = i2s_channel_enable(tx_chan);
|
||||||
|
ESP_ERROR_CHECK_WITHOUT_ABORT(channel_enable_result);
|
||||||
|
if (channel_enable_result != ESP_OK) {
|
||||||
|
return channel_enable_result;
|
||||||
|
}
|
||||||
|
|
||||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||||
for (int i = 0; i < bytes_read; i++) {
|
for (int i = 0; i < bytes_read; i++) {
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
#define SAMPLE_RATE 44100
|
#define SAMPLE_RATE 44100
|
||||||
#define AUDIO_BUFFER 2048
|
#define AUDIO_BUFFER 2048
|
||||||
|
|
||||||
|
extern i2s_chan_handle_t tx_chan;
|
||||||
|
|
||||||
esp_err_t play_raw(const char *fp);
|
esp_err_t play_raw(const char *fp);
|
||||||
void init_speaker(void);
|
void init_speaker(void);
|
||||||
void play_example();
|
void play_example();
|
||||||
|
|||||||
@ -18,6 +18,7 @@ static void try_step3(void) { clean_bomb(); step3(); }
|
|||||||
static void try_step4(void) { clean_bomb(); step4(); }
|
static void try_step4(void) { clean_bomb(); step4(); }
|
||||||
static void try_step5(void) { clean_bomb(); step5(); }
|
static void try_step5(void) { clean_bomb(); step5(); }
|
||||||
static void try_step6(void) { clean_bomb(); step6(); }
|
static void try_step6(void) { clean_bomb(); step6(); }
|
||||||
|
static void issue_strike(void) { strike("Strike Issued"); }
|
||||||
|
|
||||||
/// Wait for "*9819"
|
/// Wait for "*9819"
|
||||||
void step0(void) {
|
void step0(void) {
|
||||||
@ -112,6 +113,12 @@ void step0(void) {
|
|||||||
.should_exit = true,
|
.should_exit = true,
|
||||||
.callback = skip_to_step6,
|
.callback = skip_to_step6,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.code = "*1111",
|
||||||
|
.display_text = "Issue Strike",
|
||||||
|
.should_exit = false,
|
||||||
|
.callback = issue_strike,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
int len = sizeof(star_codes)/sizeof(StarCodeHandler);
|
int len = sizeof(star_codes)/sizeof(StarCodeHandler);
|
||||||
do_star_codes(star_codes, len);
|
do_star_codes(star_codes, len);
|
||||||
|
|||||||
@ -38,6 +38,8 @@ static lv_style_t red_text;
|
|||||||
static lv_style_t yellow_text;
|
static lv_style_t yellow_text;
|
||||||
static lv_style_t blue_text;
|
static lv_style_t blue_text;
|
||||||
|
|
||||||
|
static lv_style_t* last_style = nullptr;
|
||||||
|
|
||||||
static int switch_leds[] = {0, 0, 0, 0};
|
static int switch_leds[] = {0, 0, 0, 0};
|
||||||
|
|
||||||
static lv_style_t* color_styles[] = {
|
static lv_style_t* color_styles[] = {
|
||||||
@ -110,8 +112,6 @@ static void generate_switch_leds(void) {
|
|||||||
|
|
||||||
switch_leds[3] = colors[0];
|
switch_leds[3] = colors[0];
|
||||||
|
|
||||||
ESP_LOGI(TAG, "%d, %d, %d, %d", switch_leds[0], switch_leds[1], switch_leds[2], switch_leds[3]);
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
uint8_t* rgb = NEOPIXEL_COLORS[switch_leds[i]];
|
uint8_t* rgb = NEOPIXEL_COLORS[switch_leds[i]];
|
||||||
led_strip_set_pixel(leds, Led::switch1 - i, rgb[0], rgb[1], rgb[2]);
|
led_strip_set_pixel(leds, Led::switch1 - i, rgb[0], rgb[1], rgb[2]);
|
||||||
@ -119,19 +119,33 @@ static void generate_switch_leds(void) {
|
|||||||
led_strip_refresh(leds);
|
led_strip_refresh(leds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_text_and_color(char* text_str, int color) {
|
||||||
|
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||||
|
ESP_LOGI(TAG, "set_text_and_color: setting text: %s", text_str);
|
||||||
|
lv_label_set_text(text, text_str);
|
||||||
|
ESP_LOGI(TAG, "set_text_and_color: set text");
|
||||||
|
lv_obj_center(text);
|
||||||
|
ESP_LOGI(TAG, "set_text_and_color: setting %d", color);
|
||||||
|
if (last_style != nullptr) {
|
||||||
|
ESP_LOGI(TAG, "set_text_and_color: removing %d", color);
|
||||||
|
lv_obj_remove_style(text, last_style, LV_STATE_DEFAULT);
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "set_text_and_color: adding %d", color);
|
||||||
|
lv_obj_add_style(text, color_styles[color], LV_STATE_DEFAULT);
|
||||||
|
last_style = color_styles[color];
|
||||||
|
ESP_LOGI(TAG, "set_text_and_color: style");
|
||||||
|
xSemaphoreGive(xGuiSemaphore);
|
||||||
|
ESP_LOGI(TAG, "set_text_and_color: give");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int generate_part_a(void) {
|
static int generate_part_a(void) {
|
||||||
int text_color = zero_to_three(my_gen);
|
int text_color = zero_to_three(my_gen);
|
||||||
int text_idx = zero_to_three(my_gen);
|
int text_idx = zero_to_three(my_gen);
|
||||||
|
|
||||||
char* text_string = COLOR_NAMES[text_idx];
|
char* text_string = COLOR_NAMES[text_idx];
|
||||||
|
|
||||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
set_text_and_color(text_string, text_color);
|
||||||
lv_label_set_text(text, text_string);
|
|
||||||
lv_obj_center(text);
|
|
||||||
lv_obj_add_style(text, color_styles[text_color], LV_STATE_DEFAULT);
|
|
||||||
xSemaphoreGive(xGuiSemaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
generate_switch_leds();
|
generate_switch_leds();
|
||||||
|
|
||||||
// the correct answer is the text color
|
// the correct answer is the text color
|
||||||
@ -149,13 +163,7 @@ static int generate_part_b(void) {
|
|||||||
|
|
||||||
char* text_string = NUM_NAMES[text_number];
|
char* text_string = NUM_NAMES[text_number];
|
||||||
|
|
||||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
set_text_and_color(text_string, text_color);
|
||||||
lv_label_set_text(text, text_string);
|
|
||||||
lv_obj_center(text);
|
|
||||||
lv_obj_add_style(text, color_styles[text_color], LV_STATE_DEFAULT);
|
|
||||||
xSemaphoreGive(xGuiSemaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
generate_switch_leds();
|
generate_switch_leds();
|
||||||
|
|
||||||
// the correct answer is the number
|
// the correct answer is the number
|
||||||
@ -171,12 +179,7 @@ static int generate_part_c(void) {
|
|||||||
int text_color = zero_to_three(my_gen);
|
int text_color = zero_to_three(my_gen);
|
||||||
char* text_string = "switch";
|
char* text_string = "switch";
|
||||||
|
|
||||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
set_text_and_color(text_string, text_color);
|
||||||
lv_label_set_text(text, text_string);
|
|
||||||
lv_obj_center(text);
|
|
||||||
lv_obj_add_style(text, color_styles[text_color], LV_STATE_DEFAULT);
|
|
||||||
xSemaphoreGive(xGuiSemaphore);
|
|
||||||
}
|
|
||||||
generate_switch_leds();
|
generate_switch_leds();
|
||||||
|
|
||||||
// the correct answer is the switch
|
// the correct answer is the switch
|
||||||
@ -196,6 +199,13 @@ static int generate_part(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void update_lcd_count(int times) {
|
||||||
|
char buf[6] = {0};
|
||||||
|
sprintf(buf, "%d/15", times);
|
||||||
|
lcd_set_cursor(&lcd, 14, 1);
|
||||||
|
lcd_print(&lcd, buf);
|
||||||
|
}
|
||||||
|
|
||||||
static bool play_part(uint32_t time) {
|
static bool play_part(uint32_t time) {
|
||||||
stop_module_timer();
|
stop_module_timer();
|
||||||
set_module_time(time);
|
set_module_time(time);
|
||||||
@ -220,6 +230,7 @@ static bool play_part(uint32_t time) {
|
|||||||
|
|
||||||
int times = 0;
|
int times = 0;
|
||||||
int correct = generate_part();
|
int correct = generate_part();
|
||||||
|
update_lcd_count(times);
|
||||||
|
|
||||||
ButtonKey button;
|
ButtonKey button;
|
||||||
SwitchKey switch_;
|
SwitchKey switch_;
|
||||||
@ -231,6 +242,7 @@ static bool play_part(uint32_t time) {
|
|||||||
times++;
|
times++;
|
||||||
if (times >= 15) break;
|
if (times >= 15) break;
|
||||||
correct = generate_part();
|
correct = generate_part();
|
||||||
|
update_lcd_count(times);
|
||||||
} else {
|
} else {
|
||||||
strike("Incorrect action");
|
strike("Incorrect action");
|
||||||
}
|
}
|
||||||
@ -241,6 +253,7 @@ static bool play_part(uint32_t time) {
|
|||||||
times++;
|
times++;
|
||||||
if (times >= 15) break;
|
if (times >= 15) break;
|
||||||
correct = generate_part();
|
correct = generate_part();
|
||||||
|
update_lcd_count(times);
|
||||||
} else {
|
} else {
|
||||||
strike("Incorrect action");
|
strike("Incorrect action");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -193,6 +193,7 @@ bool play_game(int time, int required_score) {
|
|||||||
clear_board();
|
clear_board();
|
||||||
|
|
||||||
generate_block();
|
generate_block();
|
||||||
|
show_board();
|
||||||
|
|
||||||
ButtonKey button;
|
ButtonKey button;
|
||||||
while (get_pressed_button(&button));
|
while (get_pressed_button(&button));
|
||||||
@ -376,7 +377,7 @@ static void generate_block(void) {
|
|||||||
piece = new_piece;
|
piece = new_piece;
|
||||||
piece_rotation = 0;
|
piece_rotation = 0;
|
||||||
|
|
||||||
piece_location[0] = 20;
|
piece_location[0] = 18;
|
||||||
piece_location[1] = 4;
|
piece_location[1] = 4;
|
||||||
|
|
||||||
get_node_locations();
|
get_node_locations();
|
||||||
|
|||||||
@ -41,13 +41,16 @@ std::vector<int> unique_values(std::vector<int>& input_options, int num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void step3(void) {
|
void step3(void) {
|
||||||
set_module_time(20000);
|
StarCodeHandler star_codes[] = {
|
||||||
start_module_timer();
|
{
|
||||||
|
.code = "*2648",
|
||||||
// wait
|
.display_text = "Starting...",
|
||||||
while (get_module_time() > 0) {
|
.should_exit = true,
|
||||||
vTaskDelay(10);
|
.callback = nullptr,
|
||||||
}
|
},
|
||||||
|
};
|
||||||
|
int len = sizeof(star_codes)/sizeof(StarCodeHandler);
|
||||||
|
do_star_codes(star_codes, len);
|
||||||
|
|
||||||
std::vector<int> all_leds;
|
std::vector<int> all_leds;
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#define ONE_SECOND_TIME 90'000
|
#define ONE_SECOND_TIME 90'000
|
||||||
#define THREE_SECOND_TIME 90'000
|
#define THREE_SECOND_TIME 90'000
|
||||||
#define SIX_SECOND_TIME 90'000
|
#define SIX_SECOND_TIME 75'000
|
||||||
|
|
||||||
static const char *TAG = "step4";
|
static const char *TAG = "step4";
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ static const char* LCD_STRINGS[] = {
|
|||||||
"nothing",
|
"nothing",
|
||||||
"",
|
"",
|
||||||
"a word",
|
"a word",
|
||||||
"not something",
|
"somethink",
|
||||||
"what?",
|
"what?",
|
||||||
"LCD",
|
"LCD",
|
||||||
"display",
|
"display",
|
||||||
@ -61,17 +61,23 @@ static bool three_second();
|
|||||||
static bool six_second();
|
static bool six_second();
|
||||||
|
|
||||||
void step4(void) {
|
void step4(void) {
|
||||||
// start counting down module timer immediatly
|
StarCodeHandler star_codes[] = {
|
||||||
set_module_time(30'000);
|
{
|
||||||
start_module_timer();
|
.code = "*1642",
|
||||||
|
.display_text = "Starting...",
|
||||||
while (get_module_time() > 0) vTaskDelay(pdMS_TO_TICKS(100));
|
.should_exit = true,
|
||||||
|
.callback = nullptr,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
int len = sizeof(star_codes)/sizeof(StarCodeHandler);
|
||||||
|
do_star_codes(star_codes, len);
|
||||||
|
|
||||||
while (times < 4) {
|
while (times < 4) {
|
||||||
tone = tone_dist(gen);
|
tone = tone_dist(gen);
|
||||||
// tone = 2;
|
// tone = 2;
|
||||||
while (get_pressed_button(nullptr)) vTaskDelay(pdMS_TO_TICKS(10));
|
while (get_pressed_button(nullptr)) vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
|
||||||
|
play_raw(MOUNT_POINT "/que.pcm");
|
||||||
play_raw(TONE_FILES[tone]);
|
play_raw(TONE_FILES[tone]);
|
||||||
|
|
||||||
bool correct = false;
|
bool correct = false;
|
||||||
@ -90,6 +96,8 @@ void step4(void) {
|
|||||||
times++;
|
times++;
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
play_raw(MOUNT_POINT "/correct.pcm");
|
play_raw(MOUNT_POINT "/correct.pcm");
|
||||||
|
} else {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1500));
|
||||||
}
|
}
|
||||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||||
}
|
}
|
||||||
@ -179,6 +187,17 @@ static void debug_actual_values(uint8_t buttons, uint8_t switch_) {
|
|||||||
ESP_LOGI(TAG, "");
|
ESP_LOGI(TAG, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wait_for_timer(void) {
|
||||||
|
KeypadKey key;
|
||||||
|
while (get_module_time() > 0) {
|
||||||
|
if (get_pressed_keypad(&key) && key == KeypadKey::kd) {
|
||||||
|
set_module_time(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool one_second() {
|
static bool one_second() {
|
||||||
clean_bomb();
|
clean_bomb();
|
||||||
set_module_time(ONE_SECOND_TIME);
|
set_module_time(ONE_SECOND_TIME);
|
||||||
@ -220,10 +239,7 @@ static bool one_second() {
|
|||||||
|
|
||||||
debug_correct_values(correct_buttons, correct_button_mask, correct_switches);
|
debug_correct_values(correct_buttons, correct_button_mask, correct_switches);
|
||||||
|
|
||||||
// wait for timer
|
wait_for_timer();
|
||||||
while (get_module_time() > 0) {
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_actual_values(get_button_state(), get_switch_state());
|
debug_actual_values(get_button_state(), get_switch_state());
|
||||||
|
|
||||||
@ -254,8 +270,6 @@ static bool three_second() {
|
|||||||
|
|
||||||
bool was_high = (tone / 3) == 1;
|
bool was_high = (tone / 3) == 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rng_leds();
|
rng_leds();
|
||||||
write_leds();
|
write_leds();
|
||||||
int red_led_count = 0;
|
int red_led_count = 0;
|
||||||
@ -289,10 +303,7 @@ static bool three_second() {
|
|||||||
|
|
||||||
debug_correct_values(correct_buttons, correct_button_mask, correct_switches);
|
debug_correct_values(correct_buttons, correct_button_mask, correct_switches);
|
||||||
|
|
||||||
// wait for timer
|
wait_for_timer();
|
||||||
while (get_module_time() > 0) {
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_actual_values(get_button_state(), get_switch_state());
|
debug_actual_values(get_button_state(), get_switch_state());
|
||||||
|
|
||||||
@ -370,10 +381,7 @@ static bool six_second() {
|
|||||||
|
|
||||||
debug_correct_values(correct_buttons, correct_button_mask, correct_switches);
|
debug_correct_values(correct_buttons, correct_button_mask, correct_switches);
|
||||||
|
|
||||||
// wait for timer
|
wait_for_timer();
|
||||||
while (get_module_time() > 0) {
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_actual_values(get_button_state(), get_switch_state());
|
debug_actual_values(get_button_state(), get_switch_state());
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,7 @@ void step5(void) {
|
|||||||
new_puzzle();
|
new_puzzle();
|
||||||
int strike_time = xTaskGetTickCount();
|
int strike_time = xTaskGetTickCount();
|
||||||
bool striked = false;
|
bool striked = false;
|
||||||
while(solved_times < 3) {
|
while(solved_times < 4) {
|
||||||
// for every bit in the answer-
|
// for every bit in the answer-
|
||||||
set_module_sseg_raw(display_map);
|
set_module_sseg_raw(display_map);
|
||||||
if (get_pressed_keypad(&key)) {
|
if (get_pressed_keypad(&key)) {
|
||||||
|
|||||||
@ -1212,7 +1212,7 @@ CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1
|
|||||||
# Port
|
# Port
|
||||||
#
|
#
|
||||||
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
|
CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y
|
||||||
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
|
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
|
||||||
CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS=y
|
CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS=y
|
||||||
# CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK is not set
|
# CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK is not set
|
||||||
# CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set
|
# CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user