diff --git a/README.md b/README.md index d5e49a0..db584cb 100755 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ ESP-IDF version `v5.3.2` Firmware for the BLK_BOX Top control board for the puzzle `PDE001`. -Convert audio files to 44100Hz mono signed 16 uncompressed .wav files with the following command: +## Resources + +All the files in the `resources/` folder should be loaded onto a micro SD card placed in the BLK_BOX. + +Developer Note: You can convert mp3 files to 44100Hz mono signed 16 uncompressed .wav files with the following command: ```ffmpeg -i input.mp3 -ac 1 -ar 44100 -sample_fmt s16 output.wav``` +File names must be no longer than `8` characters not including the extention +File extentions must be no longer than `3` characters. + + diff --git a/main/drivers/bottom_half.cpp b/main/drivers/bottom_half.cpp index 841fdf3..b88e3cc 100644 --- a/main/drivers/bottom_half.cpp +++ b/main/drivers/bottom_half.cpp @@ -286,8 +286,8 @@ bool get_switch_flipped(SwitchKey* switch_) { *switch_ = (SwitchKey) i; } // clear bit - button_pressed &= ~bit_selector; - button_released &= ~bit_selector; + switch_flipped_up &= ~bit_selector; + switch_flipped_down &= ~bit_selector; return true; } } diff --git a/main/drivers/speaker.h b/main/drivers/speaker.h index f27b45f..16d190f 100644 --- a/main/drivers/speaker.h +++ b/main/drivers/speaker.h @@ -20,7 +20,7 @@ #define SPEAKER_PIN_DOUT GPIO_NUM_3 #define SAMPLE_RATE 44100 // The maximum number of clips that can be queued at one time. -#define CLIP_QUEUE_SIZE 8 +#define CLIP_QUEUE_SIZE 64 extern i2s_chan_handle_t tx_chan; diff --git a/main/drivers/sseg.cpp b/main/drivers/sseg.cpp index 5d2f890..e7319e9 100644 --- a/main/drivers/sseg.cpp +++ b/main/drivers/sseg.cpp @@ -13,18 +13,31 @@ void init_sseg() { ESP_LOGI(TAG, "Sseg initialized!"); } -void set_game_sseg_raw(const uint8_t* digits) { - sseg->setSegments(digits[0], 0); - sseg->setSegments(digits[1], 1); - sseg->setSegments(digits[2], 2); - sseg->setSegments(digits[3], 3); +void set_game_sseg_raw(const uint8_t* segments) { + sseg->setSegments(segments[0], 0); + sseg->setSegments(segments[1], 1); + sseg->setSegments(segments[2], 2); + sseg->setSegments(segments[3], 3); +} +void clear_game_sseg() { + sseg->setSegments(0, 0); + sseg->setSegments(0, 1); + sseg->setSegments(0, 2); + sseg->setSegments(0, 3); } -void set_module_sseg_raw(const uint8_t* digits) { - sseg->setSegments(digits[0], 4); - sseg->setSegments(digits[1], 5); - sseg->setSegments(digits[2], 6); - sseg->setSegments(digits[3], 7); +void set_module_sseg_raw(const uint8_t* segments) { + sseg->setSegments(segments[0], 4); + sseg->setSegments(segments[1], 5); + sseg->setSegments(segments[2], 6); + sseg->setSegments(segments[3], 7); +} + +void clear_module_sseg() { + sseg->setSegments(0, 4); + sseg->setSegments(0, 5); + sseg->setSegments(0, 6); + sseg->setSegments(0, 7); } void set_game_sseg_num(uint32_t value, uint8_t dot_pos) { diff --git a/main/drivers/sseg.h b/main/drivers/sseg.h index 5e6a76e..ab5c20d 100644 --- a/main/drivers/sseg.h +++ b/main/drivers/sseg.h @@ -12,19 +12,25 @@ extern TM1640* sseg; /// Initializes the seven segment driver void init_sseg(); -/// sets the game seven segment to the value of the digits +/// @brief Sets the game seven segment to the value of `segments`. /// /// the bits 0-6 map to segments A-G, and bit 7 is DP. /// /// `digits` must have len >= 4. -void set_game_sseg_raw(const uint8_t* digits); +void set_game_sseg_raw(const uint8_t* segments); -/// sets the module seven segment to the value of the digits +/// @brief Clears the game seven segment display. +void clear_game_sseg(); + +/// @brief Sets the module seven segment to the value of the `segments`. /// /// the bits 0-6 map to segments A-G, and bit 7 is DP. /// /// `digits` must have len >= 4. -void set_module_sseg_raw(const uint8_t* digits); +void set_module_sseg_raw(const uint8_t* segments); + +/// @brief Clears the game seven segment display. +void clear_module_sseg(); /// sets the game timer to the given number, with the dot at position `dot_pos` from the right (0 => right-most digit). void set_game_sseg_num(uint32_t value, uint8_t dot_pos); diff --git a/main/main.cpp b/main/main.cpp index 55779ba..b2239a8 100755 --- a/main/main.cpp +++ b/main/main.cpp @@ -49,7 +49,7 @@ extern "C" void app_main(void) { stop_game_timer(); ESP_LOGI(TAG, "Bomb has been diffused. Counter-Terrorists win."); - play_clip_wav(MOUNT_POINT "/diffused.wav", true, false, 3, 0); + play_clip_wav(MOUNT_POINT "/diffuse.wav", true, false, 3, 0); display_game_results(); } diff --git a/main/steps/step1.cpp b/main/steps/step1.cpp index 05106f8..f71f4a7 100644 --- a/main/steps/step1.cpp +++ b/main/steps/step1.cpp @@ -263,8 +263,12 @@ static bool play_part(uint32_t time) { lv_label_set_text(text, ""); xSemaphoreGive(xGuiSemaphore); } - vTaskDelay(pdMS_TO_TICKS(80)); - play_clip_wav(MOUNT_POINT "/correct.wav", true, false, 3, 0); + if (part == 2) { + play_clip_wav(MOUNT_POINT "/stepdone.wav", true, false, 0, 0); + vTaskDelay(pdMS_TO_TICKS(2000)); + } else { + play_clip_wav(MOUNT_POINT "/partdone.wav", true, false, 1, 0); + } return true; } diff --git a/main/steps/step2.cpp b/main/steps/step2.cpp index cf7fa11..5c04d11 100644 --- a/main/steps/step2.cpp +++ b/main/steps/step2.cpp @@ -100,14 +100,14 @@ void step2(void) { char c = char_of_keypad_key(key); // ESP_LOGI(TAG, "Pressed: %c", c); if (c == answer_char) { - play_clip_wav(MOUNT_POINT "/correct.wav", true, false, 3, 0); solved_times++; if (solved_times < NUM_SOLVES) { + play_clip_wav(MOUNT_POINT "/stepdone.wav", true, false, 0, 0); clean_bomb(); new_puzzle(); } else { - uint8_t display_tmp[4] = {0b00000000, 0b00000000, 0b00000000, 0b00000000}; - set_module_sseg_raw(display_tmp); + play_clip_wav(MOUNT_POINT "/partdone.wav", true, false, 0, 0); + clear_module_sseg(); } } else { strike_time = xTaskGetTickCount(); diff --git a/main/steps/step3.cpp b/main/steps/step3.cpp index 438969c..08b476b 100644 --- a/main/steps/step3.cpp +++ b/main/steps/step3.cpp @@ -80,7 +80,7 @@ void step3(void) { // tone = 2; while (get_button_pressed(nullptr)) vTaskDelay(pdMS_TO_TICKS(10)); - play_clip_wav(MOUNT_POINT "/correct.wav", true, false, 3, 0); + play_clip_wav(MOUNT_POINT "/ready.wav", true, false, 3, 0); play_clip_wav(TONE_FILES[tone], false, false, 3, 0); bool correct = false; @@ -98,7 +98,11 @@ void step3(void) { if (correct) { times++; clean_bomb(); - play_clip_wav(MOUNT_POINT "/correct.wav", true, false, 3, 0); + if (times < TIMES_TO_COMPLETE) { + play_clip_wav(MOUNT_POINT "/part-done.wav", true, false, 3, 0); + } else { + play_clip_wav(MOUNT_POINT "/step-done.wav", true, false, 3, 0); + } } else { vTaskDelay(pdMS_TO_TICKS(1500)); } diff --git a/main/steps/step4.cpp b/main/steps/step4.cpp index e96401b..a0c8740 100644 --- a/main/steps/step4.cpp +++ b/main/steps/step4.cpp @@ -23,8 +23,7 @@ static const void* BACKGROUND_SRC = (void*)"A:" MOUNT_POINT "/bg.bin"; // LV_IMG_DECLARE(background); // static const void* BACKGROUND_SRC = (void*)&background; -static QueueHandle_t stop_music; -static bool playing_music = true; +#define MUSIC_FILE MOUNT_POINT "/piano.wav" static const char* PIECE_IMG_SRC[] = { NULL, @@ -162,16 +161,15 @@ static void init_screen() { xSemaphoreGive(xGuiSemaphore); - play_clip_wav(MOUNT_POINT "/tetris.wav", true, false, 3, 0); + play_clip_wav(MUSIC_FILE, true, true, 4, 0); } static void deinit_screen() { while (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdFALSE) vTaskDelay(pdMS_TO_TICKS(10)); - lv_obj_clean(lv_scr_act()); xSemaphoreGive(xGuiSemaphore); - if (!stop_clip(MOUNT_POINT "/tetris.wav", pdMS_TO_TICKS(1000))) { + if (!stop_clip(MUSIC_FILE, pdMS_TO_TICKS(1000))) { ESP_LOGW(TAG, "Can't stop, addicted to the shindig."); } } diff --git a/resources/high-1.wav b/resources/high-1.wav new file mode 100644 index 0000000..19ce59a Binary files /dev/null and b/resources/high-1.wav differ diff --git a/resources/high-3.wav b/resources/high-3.wav new file mode 100644 index 0000000..dc0d5a9 Binary files /dev/null and b/resources/high-3.wav differ diff --git a/resources/high-6.wav b/resources/high-6.wav new file mode 100644 index 0000000..625bd82 Binary files /dev/null and b/resources/high-6.wav differ diff --git a/resources/low-1.wav b/resources/low-1.wav new file mode 100644 index 0000000..aaeb7c9 Binary files /dev/null and b/resources/low-1.wav differ diff --git a/resources/low-3.wav b/resources/low-3.wav new file mode 100644 index 0000000..e3095eb Binary files /dev/null and b/resources/low-3.wav differ diff --git a/resources/low-6.wav b/resources/low-6.wav new file mode 100644 index 0000000..4e13e31 Binary files /dev/null and b/resources/low-6.wav differ diff --git a/resources/piano.wav b/resources/piano.wav new file mode 100644 index 0000000..929c875 Binary files /dev/null and b/resources/piano.wav differ