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