|
12 | 12 | #include "sd_functions.h"
|
13 | 13 | #include "settings.h"
|
14 | 14 | #include "display.h"
|
| 15 | +#include "powerSave.h" |
15 | 16 | #include "modules/rf/rf.h"
|
16 | 17 |
|
17 | 18 |
|
@@ -54,6 +55,10 @@ void handleSerialCommands() {
|
54 | 55 |
|
55 | 56 | // TODO: more commands https://docs.flipper.net/development/cli#0Z9fs
|
56 | 57 |
|
| 58 | + if(cmd_str == "" ) { // empty |
| 59 | + return; |
| 60 | + } |
| 61 | + |
57 | 62 | if(cmd_str.startsWith("ir") ) {
|
58 | 63 |
|
59 | 64 | // ir tx <protocol> <address> <command>
|
@@ -194,11 +199,11 @@ void handleSerialCommands() {
|
194 | 199 | }
|
195 | 200 | } // endof rf
|
196 | 201 |
|
197 |
| - if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("ttf" ) ) { |
| 202 | + if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("tts" ) || cmd_str.startsWith("say" ) ) { |
198 | 203 | // TODO: move in audio.cpp module
|
199 | 204 | AudioOutputI2S *audioout = new AudioOutputI2S(); // https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L32
|
200 | 205 | #ifdef CARDPUTER
|
201 |
| - audioout->SetPinout(41, 43, 42); |
| 206 | + audioout->SetPinout(41, 43, 42); // bclk, wclk, dout |
202 | 207 | // TODO: other pinouts
|
203 | 208 | #endif
|
204 | 209 | AudioGenerator* generator = NULL;
|
@@ -235,8 +240,8 @@ void handleSerialCommands() {
|
235 | 240 | if(song.endsWith(".mid")) {
|
236 | 241 | // need to load a soundfont
|
237 | 242 | AudioFileSource* sf2 = NULL;
|
238 |
| - if(setupSdCard()) sf2 = new AudioFileSourceSD("audio/1mgm.sf2"); // TODO: make configurable |
239 |
| - if(!sf2) sf2 = new AudioFileSourceLittleFS("audio/1mgm.sf2"); // TODO: make configurable |
| 243 | + if(setupSdCard()) sf2 = new AudioFileSourceSD("1mgm.sf2"); // TODO: make configurable |
| 244 | + if(!sf2) sf2 = new AudioFileSourceLittleFS("1mgm.sf2"); // TODO: make configurable |
240 | 245 | if(sf2) {
|
241 | 246 | // a soundfount was found
|
242 | 247 | AudioGeneratorMIDI* midi = new AudioGeneratorMIDI();
|
@@ -286,25 +291,68 @@ void handleSerialCommands() {
|
286 | 291 | // https://github.com/earlephilhower/ESP8266Audio/issues/70
|
287 | 292 | // https://github.com/earlephilhower/ESP8266Audio/pull/118
|
288 | 293 |
|
289 |
| -/* TODO: rewrite using the new screen dimmer feat. |
290 |
| - if(cmd_str.startsWith("lcd " ) || cmd_str.startsWith("tft" ) ) { |
291 |
| - String new_status = cmd_str.substring(strlen("lcd "), cmd_str.length()); |
292 |
| - if(new_status=="off") { |
293 |
| - analogWrite(BACKLIGHT, 0); |
294 |
| - esp_timer_stop(screensaver_timer); |
295 |
| - } else if(new_status=="on") { |
296 |
| - getBrightness(); // reinit brightness |
297 |
| - reset_screensaver_timer(); |
| 294 | + // backlight brightness adjust (range 0-255) https://docs.flipper.net/development/cli/#XQQAI |
| 295 | + // e.g. "led br 127" |
| 296 | + if(cmd_str.startsWith("led br ")) { |
| 297 | + const char* valueStr = cmd_str.c_str() + strlen("led br "); |
| 298 | + int value = (atoi(valueStr) * 100) / 255; // convert to 0-100 range |
| 299 | + //Serial.print("value: "); |
| 300 | + //Serial.println(value); |
| 301 | + if(value<=0) value=1; |
| 302 | + if(value>100) value=100; |
| 303 | + setBrightness(value, false); // false -> do not save |
| 304 | + return; |
| 305 | + } |
| 306 | + else if(cmd_str.startsWith("led ")) { |
| 307 | + // change UI color |
| 308 | + // e.g. "led 255 255 255" |
| 309 | + const char* rgbString = cmd_str.c_str() + 4; |
| 310 | + int r, g, b; |
| 311 | + if (sscanf(rgbString, "%d %d %d", &r, &g, &b) != 3) { |
| 312 | + Serial.println("invalid color: " + String(rgbString)); |
| 313 | + return; |
| 314 | + } |
| 315 | + if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { |
| 316 | + Serial.println("invalid color: " + String(rgbString)); |
| 317 | + return; |
298 | 318 | }
|
| 319 | + uint16_t hexColor = tft.color565(r, g, b); // Use the TFT_eSPI function to convert RGB to 16-bit color |
| 320 | + //Serial.print("converted color:"); |
| 321 | + //SerialPrintHexString(hexColor); |
| 322 | + FGCOLOR = hexColor; // change global var, dont save in settings |
299 | 323 | return;
|
300 | 324 | }
|
301 |
| -*/ |
302 | 325 |
|
| 326 | + // power cmds: off, reboot |
| 327 | + if(cmd_str == "power off" ) { |
| 328 | + // closest thing https://github.com/esp8266/Arduino/issues/929 |
| 329 | + //ESP.deepSleep(0); |
| 330 | + esp_deep_sleep_start(); // only wake up via hardware reset |
| 331 | + return; |
| 332 | + } |
| 333 | + if(cmd_str == "power reboot" ) { |
| 334 | + ESP.restart(); |
| 335 | + return; |
| 336 | + } |
| 337 | + if(cmd_str == "power sleep" ) { |
| 338 | + // cmd not supported on flipper0 |
| 339 | + // TODO: proper sleep mode with esp_deep_sleep_start(); |
| 340 | + setSleepMode(); |
| 341 | + //turnOffDisplay(); |
| 342 | + //esp_timer_stop(screensaver_timer); |
| 343 | + return; |
| 344 | + } |
| 345 | + |
303 | 346 | if(cmd_str == "clock" ) {
|
304 | 347 | //esp_timer_stop(screensaver_timer); // disable screensaver while the clock is running
|
305 | 348 | runClockLoop();
|
306 | 349 | return;
|
307 | 350 | }
|
| 351 | + |
| 352 | + // TODO: "storage" cmd to manage files https://docs.flipper.net/development/cli/#Xgais |
| 353 | + |
| 354 | + // TODO: "gpio" cmds https://docs.flipper.net/development/cli/#aqA4b |
| 355 | + |
308 | 356 |
|
309 | 357 | Serial.println("unsupported serial command: " + cmd_str);
|
310 | 358 |
|
|
0 commit comments