Skip to content

Commit 00ca86e

Browse files
committed
added power serial cmds, wakeup cardputer by pressing any key (pr3y#64)
1 parent 4744c31 commit 00ca86e

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

src/core/serialcmds.cpp

+62-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "sd_functions.h"
1313
#include "settings.h"
1414
#include "display.h"
15+
#include "powerSave.h"
1516
#include "modules/rf/rf.h"
1617

1718

@@ -54,6 +55,10 @@ void handleSerialCommands() {
5455

5556
// TODO: more commands https://docs.flipper.net/development/cli#0Z9fs
5657

58+
if(cmd_str == "" ) { // empty
59+
return;
60+
}
61+
5762
if(cmd_str.startsWith("ir") ) {
5863

5964
// ir tx <protocol> <address> <command>
@@ -194,11 +199,11 @@ void handleSerialCommands() {
194199
}
195200
} // endof rf
196201

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" ) ) {
198203
// TODO: move in audio.cpp module
199204
AudioOutputI2S *audioout = new AudioOutputI2S(); // https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L32
200205
#ifdef CARDPUTER
201-
audioout->SetPinout(41, 43, 42);
206+
audioout->SetPinout(41, 43, 42); // bclk, wclk, dout
202207
// TODO: other pinouts
203208
#endif
204209
AudioGenerator* generator = NULL;
@@ -235,8 +240,8 @@ void handleSerialCommands() {
235240
if(song.endsWith(".mid")) {
236241
// need to load a soundfont
237242
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
240245
if(sf2) {
241246
// a soundfount was found
242247
AudioGeneratorMIDI* midi = new AudioGeneratorMIDI();
@@ -286,25 +291,68 @@ void handleSerialCommands() {
286291
// https://github.com/earlephilhower/ESP8266Audio/issues/70
287292
// https://github.com/earlephilhower/ESP8266Audio/pull/118
288293

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;
298318
}
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
299323
return;
300324
}
301-
*/
302325

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+
303346
if(cmd_str == "clock" ) {
304347
//esp_timer_stop(screensaver_timer); // disable screensaver while the clock is running
305348
runClockLoop();
306349
return;
307350
}
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+
308356

309357
Serial.println("unsupported serial command: " + cmd_str);
310358

src/core/settings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void setSleepMode() {
165165
sleepModeOn();
166166
while (1) {
167167
#if defined(CARDPUTER)
168-
if (checkEscPress() || checkSelPress())
168+
if (checkAnyKeyPress())
169169
#else
170170
if (checkSelPress())
171171
#endif

0 commit comments

Comments
 (0)