diff --git a/sounds/README.md b/sounds/README.md new file mode 100644 index 0000000..33b5575 --- /dev/null +++ b/sounds/README.md @@ -0,0 +1,10 @@ +### How to upload +This is to upload sounds to the device. In order to speak correctly. +Below is the command to push the files to the M5Core2 once is connected to the device via WiFi. + +for i in $(ls *.mp3); do echo "Pushing [$i]...."; ./upload.py http://192.168.1.1/webupload $i; done + + +### How to delete +To delete it is easy: +curl -s http://192.168.1.1/erase?filename=the_filename diff --git a/sounds/bluetooth.mp3 b/sounds/bluetooth.mp3 new file mode 100644 index 0000000..959f54f Binary files /dev/null and b/sounds/bluetooth.mp3 differ diff --git a/sounds/bluetooth.raw b/sounds/bluetooth.raw new file mode 100644 index 0000000..71d2165 Binary files /dev/null and b/sounds/bluetooth.raw differ diff --git a/sounds/poweroff.mp3 b/sounds/poweroff.mp3 new file mode 100644 index 0000000..8f17c2f Binary files /dev/null and b/sounds/poweroff.mp3 differ diff --git a/sounds/poweroff.raw b/sounds/poweroff.raw new file mode 100644 index 0000000..7e499bd Binary files /dev/null and b/sounds/poweroff.raw differ diff --git a/sounds/rccontroller.mp3 b/sounds/rccontroller.mp3 new file mode 100644 index 0000000..b17f568 Binary files /dev/null and b/sounds/rccontroller.mp3 differ diff --git a/sounds/rccontroller.raw b/sounds/rccontroller.raw new file mode 100644 index 0000000..8dc7372 Binary files /dev/null and b/sounds/rccontroller.raw differ diff --git a/sounds/reboot.mp3 b/sounds/reboot.mp3 new file mode 100644 index 0000000..3bdec7e Binary files /dev/null and b/sounds/reboot.mp3 differ diff --git a/sounds/reboot.raw b/sounds/reboot.raw new file mode 100644 index 0000000..ca23633 Binary files /dev/null and b/sounds/reboot.raw differ diff --git a/sounds/reset.mp3 b/sounds/reset.mp3 new file mode 100644 index 0000000..45bd772 Binary files /dev/null and b/sounds/reset.mp3 differ diff --git a/sounds/reset.raw b/sounds/reset.raw new file mode 100644 index 0000000..181518f Binary files /dev/null and b/sounds/reset.raw differ diff --git a/sounds/rfscanners.mp3 b/sounds/rfscanners.mp3 new file mode 100644 index 0000000..fff4368 Binary files /dev/null and b/sounds/rfscanners.mp3 differ diff --git a/sounds/rfscanners.raw b/sounds/rfscanners.raw new file mode 100644 index 0000000..dc78be2 Binary files /dev/null and b/sounds/rfscanners.raw differ diff --git a/sounds/rfsettings.mp3 b/sounds/rfsettings.mp3 new file mode 100644 index 0000000..d2ae21e Binary files /dev/null and b/sounds/rfsettings.mp3 differ diff --git a/sounds/rfsettings.raw b/sounds/rfsettings.raw new file mode 100644 index 0000000..8bf09ee Binary files /dev/null and b/sounds/rfsettings.raw differ diff --git a/sounds/rxbinding.mp3 b/sounds/rxbinding.mp3 new file mode 100644 index 0000000..47c89f6 Binary files /dev/null and b/sounds/rxbinding.mp3 differ diff --git a/sounds/rxbinding.raw b/sounds/rxbinding.raw new file mode 100644 index 0000000..779d621 Binary files /dev/null and b/sounds/rxbinding.raw differ diff --git a/sounds/savesettings.mp3 b/sounds/savesettings.mp3 new file mode 100644 index 0000000..ce545f1 Binary files /dev/null and b/sounds/savesettings.mp3 differ diff --git a/sounds/savesettings.raw b/sounds/savesettings.raw new file mode 100644 index 0000000..b55c8a9 Binary files /dev/null and b/sounds/savesettings.raw differ diff --git a/sounds/stickcalibration.mp3 b/sounds/stickcalibration.mp3 new file mode 100644 index 0000000..e48072d Binary files /dev/null and b/sounds/stickcalibration.mp3 differ diff --git a/sounds/stickcalibration.raw b/sounds/stickcalibration.raw new file mode 100644 index 0000000..9f0dfd7 Binary files /dev/null and b/sounds/stickcalibration.raw differ diff --git a/sounds/stickpositions.mp3 b/sounds/stickpositions.mp3 new file mode 100644 index 0000000..0d4f2ae Binary files /dev/null and b/sounds/stickpositions.mp3 differ diff --git a/sounds/stickpositions.raw b/sounds/stickpositions.raw new file mode 100644 index 0000000..aa9626e Binary files /dev/null and b/sounds/stickpositions.raw differ diff --git a/sounds/systemshuttingdown.mp3 b/sounds/systemshuttingdown.mp3 new file mode 100644 index 0000000..7d6b790 Binary files /dev/null and b/sounds/systemshuttingdown.mp3 differ diff --git a/sounds/systemshuttingdown.raw b/sounds/systemshuttingdown.raw new file mode 100644 index 0000000..8fd8534 Binary files /dev/null and b/sounds/systemshuttingdown.raw differ diff --git a/sounds/trims.mp3 b/sounds/trims.mp3 new file mode 100644 index 0000000..5dee66b Binary files /dev/null and b/sounds/trims.mp3 differ diff --git a/sounds/trims.raw b/sounds/trims.raw new file mode 100644 index 0000000..0dcf7d1 Binary files /dev/null and b/sounds/trims.raw differ diff --git a/sounds/upload.py b/sounds/upload.py new file mode 100755 index 0000000..56578d3 --- /dev/null +++ b/sounds/upload.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 +import requests +import sys + +### print (sys.argv) +### print(len(sys.argv)) +if len(sys.argv) < 3: + print("Invalid parameters\n") + exit + +filename = sys.argv[2] +url = sys.argv[1] + +files = {'file': open(filename, 'rb')} +final_resp = requests.post(url, files=files) diff --git a/sounds/welcome.mp3 b/sounds/welcome.mp3 new file mode 100644 index 0000000..9940507 Binary files /dev/null and b/sounds/welcome.mp3 differ diff --git a/sounds/welcome.raw b/sounds/welcome.raw new file mode 100644 index 0000000..4ebe06b Binary files /dev/null and b/sounds/welcome.raw differ diff --git a/sounds/wifi.mp3 b/sounds/wifi.mp3 new file mode 100644 index 0000000..5f1eaa9 Binary files /dev/null and b/sounds/wifi.mp3 differ diff --git a/sounds/wifi.raw b/sounds/wifi.raw new file mode 100644 index 0000000..a4e5e5a Binary files /dev/null and b/sounds/wifi.raw differ diff --git a/src/Screen.cpp b/src/Screen.cpp index 432493b..2dc3a0d 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -37,6 +37,7 @@ void Screen::update(void) { } else if(current_screen == SCREEN_MENU_POWEROFF) { menu_poweroff(); } + last_screen_update = millis(); } @@ -54,6 +55,10 @@ void Screen::update(void) { } +void Screen::menu_bluetooth(void) { +} + + void Screen::intro(void) { // M5.Lcd.drawRect(100, 100, 50, 50, BLUE); // @@ -102,6 +107,11 @@ void Screen::menu(void) { for(uint8_t y = menu_start_position; y < menu_max_position * MENU_HEIGHT; y+=MENU_HEIGHT) { if((current_menu - menu_start_position) == menu_count) { mainscreen_buffer.setTextColor(BLACK, YELLOW); + + // Trigger voice + speak.speak_words = current_menu; + speak.speak_now = true; + } else { mainscreen_buffer.setTextColor(WHITE, BLACK); } @@ -130,10 +140,6 @@ void Screen::menu(void) { if(current_menu == menu_total) current_menu--; - // char debug[256]; - // sprintf(debug, "current_menu: %i menu_start_position: %i menu_max_position: %i menu_total: %i", current_menu, menu_start_position, menu_max_position, menu_total); - // Serial.println(debug); - if(current_menu >= menu_max_position) { if(menu_start_position + MENU_MAX_ITEMS < menu_total) { menu_start_position++; @@ -157,11 +163,14 @@ void Screen::menu(void) { updated = true; } + // Handling Button B if(M5.BtnB.wasPressed()) { if(current_menu == MENU_REBOOT) { current_screen = SCREEN_MENU_REBOOT; } else if(current_menu == MENU_POWER_OFF) { current_screen = SCREEN_MENU_POWEROFF; + } else if(current_menu == MENU_BLUETOOTH) { + current_screen = SCREEN_MENU_BLUETOOTH; } updated = true; } @@ -250,6 +259,12 @@ void Screen::menu_poweroff(void) { if(M5.BtnB.wasPressed()) { if(current_menu_poweroff_selection == SELECTION_YES) { + // Trigger voice + speak.speak_miscs = PHRASE000; + speak.speak_now_other = true; + + vTaskDelay(1200); + M5.shutdown(); } else if(current_menu_poweroff_selection == SELECTION_NO) { // Return back to main menu diff --git a/src/Screen.h b/src/Screen.h index 7d31bd4..20ec59b 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -3,6 +3,7 @@ #include #include +#include "Speak.h" #define REFRESH_TIME 1 #define INTRO_TIME 100 @@ -17,7 +18,8 @@ enum screen_names { SCREEN_INTRO, SCREEN_MENU, SCREEN_MENU_REBOOT, - SCREEN_MENU_POWEROFF + SCREEN_MENU_POWEROFF, + SCREEN_MENU_BLUETOOTH }; enum menu_items { @@ -50,6 +52,7 @@ class Screen { void menu(void); void menu_reboot(void); void menu_poweroff(void); + void menu_bluetooth(void); void update(void); private: diff --git a/src/Speak.cpp b/src/Speak.cpp index 22578f7..983b3e7 100644 --- a/src/Speak.cpp +++ b/src/Speak.cpp @@ -11,6 +11,7 @@ void Speak::begin(void) { // Enable speaker M5.Axp.SetSpkEnable(true); + i2s_driver_uninstall(SPEAK_I2S_NUMBER); i2s_config_t i2s_config = { .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. 设置I2S工作模式 @@ -25,7 +26,7 @@ void Speak::begin(void) { i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); i2s_config.use_apll = false; // I2S clock setup. I2S时钟设置 i2s_config.tx_desc_auto_clear = true; // Enables auto-cleanup descriptors for understreams. 开启欠流自动清除描述符 - // i2s_config.fixed_mclk = 0; + i2s_config.fixed_mclk = 0; // Install and drive I2S. 安装并驱动I2S i2s_driver_install(SPEAK_I2S_NUMBER, &i2s_config, 0, NULL); @@ -41,30 +42,83 @@ void Speak::begin(void) { } -void Speak::welcome(void) { +void Speak::speak_menu(uint8_t menu_selected) { + if(menu_selected == MENU_RC_CONTROLLER) { + speak("rccalibration.raw"); + } else if(menu_selected == MENU_BLUETOOTH) { + speak("bluetooth.raw"); + } else if(menu_selected == MENU_STICK_CALIBRATION) { + speak("stickcalibration.raw"); + } else if(menu_selected == MENU_STICK_POSITIONS) { + speak("stickpositions.raw"); + } else if(menu_selected == MENU_TRIMS) { + speak("trims.raw"); + } else if(menu_selected == MENU_WIFI) { + speak("wifi.raw"); + } else if(menu_selected == MENU_RX_BINDING) { + speak("rxbinding.raw"); + } else if(menu_selected == MENU_RF_SETTINGS) { + speak("rfsettings.raw"); + } else if(menu_selected == MENU_RF_SCANNERS) { + speak("rfscanners.raw"); + } else if(menu_selected == MENU_SAVE_SETTINGS) { + speak("savesettings.raw"); + } else if(menu_selected == MENU_RESET) { + speak("reset.raw"); + } else if(menu_selected == MENU_REBOOT) { + speak("reboot.raw"); + } else if(menu_selected == MENU_POWER_OFF) { + speak("poweroff.raw"); + } +} + + +void Speak::speak_misc(uint8_t phrase) { + if(phrase == PHRASE000) { + speak("systemshuttingdown.raw"); + } +} + + +void Speak::speak(String filename) { size_t bytes_written = 0; + filename = "/" + filename; + // Loading file from LittleFS to memory - File soundfile = LITTLEFS.open("/welcome.raw", FILE_READ); + File soundfile = LITTLEFS.open(filename, FILE_READ); uint16_t samples_read = 0; uint32_t soundfile_size = soundfile.size(); uint32_t file_position = 0; // WAVFileReader *reader = new WAVFileReader(); Serial.println("Reading...."); - uint8_t *samples = (uint8_t *)malloc(1024 * sizeof(uint8_t) * 2); - uint8_t *original; + int16_t *samples = (int16_t *)malloc(1024 * sizeof(int16_t) * 2); + int16_t *original; original = samples; + int16_t data_high, data_low, data; + while(true) { samples_read = 0; - for(uint16_t samples_count = 0; samples_count < 1024 ; samples_count++) { + for(uint32_t samples_count = 0; samples_count < 1024 ; samples_count++) { if(!soundfile.available()) { break; } // *samples++ = soundfile.read(); // Serial.println(samples[samples_read]) - uint8_t data = soundfile.read(); + // int16_t data = soundfile.read() | soundfile.read() << 8; + data_low = soundfile.read(); + if(soundfile.available()) { + data_high = soundfile.read(); + } else { + data_high = 0; + } + + data = data_low | data_high << 8; + + // Lower sound ?? + data = data * 2.5; samples[samples_count * 2] = data; samples[samples_count * 2 + 1] = data; samples_read++; @@ -76,10 +130,10 @@ void Speak::welcome(void) { // Serial.println("Loop break..."); break; } - // Serial.println("After line 67"); + // Serial.println("After line 67") // Serial.println(file_position); - i2s_write(SPEAK_I2S_NUMBER, samples, samples_read * sizeof(uint8_t) * 2, &bytes_written, portMAX_DELAY); + i2s_write(SPEAK_I2S_NUMBER, samples, samples_read * sizeof(int16_t) * 2, &bytes_written, portMAX_DELAY); // Serial.println("After sound..."); samples = original; @@ -93,16 +147,11 @@ void Speak::welcome(void) { // Stops soundfile.close(); +} - /*** - while(soundfile.available()) { - soundfileR[file_position] = soundfile.read(); - file_position++; - } - ***/ - Serial.println("DONE"); - // i2s_write(SPEAK_I2S_NUMBER, soundfile, soundfile_size, &bytes_written, portMAX_DELAY); +void Speak::welcome(void) { + speak("welcome.raw"); } void Speak::dingdong(void) { diff --git a/src/Speak.h b/src/Speak.h index 390b5d3..a99d234 100644 --- a/src/Speak.h +++ b/src/Speak.h @@ -5,6 +5,7 @@ #include #include #include +#include "Screen.h" #define NUM_FRAMES_TO_SEND 256 #define MODE_SPEAKER 1 @@ -17,14 +18,27 @@ #define OUTPUT_GAIN 10 + +enum phrase { + PHRASE000 +}; + + class Speak { public: Speak(void); void begin(void); void dingdong(void); void welcome(void); + void speak_menu(uint8_t); + void speak_misc(uint8_t); + void speak(String filename); virtual int16_t process_sample(int16_t sample) { return sample; } // virtual int8_t process_sample(int8_t sample) { return sample; } + bool speak_now = false; + bool speak_now_other = false; + int16_t speak_words = -1; + int16_t speak_miscs = -1; private: }; diff --git a/src/main.cpp b/src/main.cpp index ea9a06c..919ecfa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,6 @@ void setup() { CPU_0 ); - /*** xTaskCreatePinnedToCore( taskSpeak, "TaskSpeak", // Name of the process @@ -56,7 +55,6 @@ void setup() { NULL, CPU_0 ); - ***/ speak.welcome(); } @@ -81,7 +79,15 @@ void taskSpeak(void *pvParameters) { (void) pvParameters; for(;;) { - + if(speak.speak_now == true) { + speak.speak_menu(speak.speak_words); + speak.speak_now = false; + } + + if(speak.speak_now_other == true) { + speak.speak_misc(speak.speak_miscs); + speak.speak_now_other = false; + } vTaskDelay(100); } } diff --git a/src/main.h b/src/main.h index 0c4001a..03f6483 100644 --- a/src/main.h +++ b/src/main.h @@ -6,8 +6,8 @@ #define CPU_0 0 #include -#include "Screen.h" #include "Speak.h" +#include "Screen.h" #include "Storage.h" #include "CustomWiFi.h" #include "Web.h"