Browse Source

Menu Assistance.

master
Englebert 3 years ago
parent
commit
047dcf5938
  1. 10
      sounds/README.md
  2. BIN
      sounds/bluetooth.mp3
  3. BIN
      sounds/bluetooth.raw
  4. BIN
      sounds/poweroff.mp3
  5. BIN
      sounds/poweroff.raw
  6. BIN
      sounds/rccontroller.mp3
  7. BIN
      sounds/rccontroller.raw
  8. BIN
      sounds/reboot.mp3
  9. BIN
      sounds/reboot.raw
  10. BIN
      sounds/reset.mp3
  11. BIN
      sounds/reset.raw
  12. BIN
      sounds/rfscanners.mp3
  13. BIN
      sounds/rfscanners.raw
  14. BIN
      sounds/rfsettings.mp3
  15. BIN
      sounds/rfsettings.raw
  16. BIN
      sounds/rxbinding.mp3
  17. BIN
      sounds/rxbinding.raw
  18. BIN
      sounds/savesettings.mp3
  19. BIN
      sounds/savesettings.raw
  20. BIN
      sounds/stickcalibration.mp3
  21. BIN
      sounds/stickcalibration.raw
  22. BIN
      sounds/stickpositions.mp3
  23. BIN
      sounds/stickpositions.raw
  24. BIN
      sounds/systemshuttingdown.mp3
  25. BIN
      sounds/systemshuttingdown.raw
  26. BIN
      sounds/trims.mp3
  27. BIN
      sounds/trims.raw
  28. 15
      sounds/upload.py
  29. BIN
      sounds/welcome.mp3
  30. BIN
      sounds/welcome.raw
  31. BIN
      sounds/wifi.mp3
  32. BIN
      sounds/wifi.raw
  33. 23
      src/Screen.cpp
  34. 5
      src/Screen.h
  35. 83
      src/Speak.cpp
  36. 14
      src/Speak.h
  37. 12
      src/main.cpp
  38. 2
      src/main.h

10
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

BIN
sounds/bluetooth.mp3

BIN
sounds/bluetooth.raw

BIN
sounds/poweroff.mp3

BIN
sounds/poweroff.raw

BIN
sounds/rccontroller.mp3

BIN
sounds/rccontroller.raw

BIN
sounds/reboot.mp3

BIN
sounds/reboot.raw

BIN
sounds/reset.mp3

BIN
sounds/reset.raw

BIN
sounds/rfscanners.mp3

BIN
sounds/rfscanners.raw

BIN
sounds/rfsettings.mp3

BIN
sounds/rfsettings.raw

BIN
sounds/rxbinding.mp3

BIN
sounds/rxbinding.raw

BIN
sounds/savesettings.mp3

BIN
sounds/savesettings.raw

BIN
sounds/stickcalibration.mp3

BIN
sounds/stickcalibration.raw

BIN
sounds/stickpositions.mp3

BIN
sounds/stickpositions.raw

BIN
sounds/systemshuttingdown.mp3

BIN
sounds/systemshuttingdown.raw

BIN
sounds/trims.mp3

BIN
sounds/trims.raw

15
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)

BIN
sounds/welcome.mp3

BIN
sounds/welcome.raw

BIN
sounds/wifi.mp3

BIN
sounds/wifi.raw

23
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

5
src/Screen.h

@ -3,6 +3,7 @@
#include <Arduino.h>
#include <M5Core2.h>
#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:

83
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) {

14
src/Speak.h

@ -5,6 +5,7 @@
#include <M5Core2.h>
#include <driver/i2s.h>
#include <LITTLEFS.h>
#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:
};

12
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);
}
}

2
src/main.h

@ -6,8 +6,8 @@
#define CPU_0 0
#include <M5Core2.h>
#include "Screen.h"
#include "Speak.h"
#include "Screen.h"
#include "Storage.h"
#include "CustomWiFi.h"
#include "Web.h"

Loading…
Cancel
Save