Skip to content

Commit b728503

Browse files
authored
Merge pull request #85 from eadmaster/serialcmds
added power serial cmds, wakeup cardputer by pressing any key (#64)
2 parents 8acf3da + 51a2e5e commit b728503

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed

src/core/serialcmds.cpp

+74-16
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
#include "cJSON.h"
88
#include <inttypes.h> // for PRIu64
99

10-
#include <ESP8266Audio.h>
11-
#include <ESP8266SAM.h>
10+
#ifndef STICK_C_PLUS
11+
#include <ESP8266Audio.h>
12+
#include <ESP8266SAM.h>
13+
#endif
14+
1215
#include "sd_functions.h"
1316
#include "settings.h"
1417
#include "display.h"
18+
#include "powerSave.h"
1519
#include "modules/rf/rf.h"
1620

1721

@@ -54,6 +58,10 @@ void handleSerialCommands() {
5458

5559
// TODO: more commands https://docs.flipper.net/development/cli#0Z9fs
5660

61+
if(cmd_str == "" ) { // empty
62+
return;
63+
}
64+
5765
if(cmd_str.startsWith("ir") ) {
5866

5967
// ir tx <protocol> <address> <command>
@@ -194,11 +202,12 @@ void handleSerialCommands() {
194202
}
195203
} // endof rf
196204

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" ) ) {
198207
// TODO: move in audio.cpp module
199208
AudioOutputI2S *audioout = new AudioOutputI2S(); // https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L32
200209
#ifdef CARDPUTER
201-
audioout->SetPinout(41, 43, 42);
210+
audioout->SetPinout(41, 43, 42); // bclk, wclk, dout
202211
// TODO: other pinouts
203212
#endif
204213
AudioGenerator* generator = NULL;
@@ -235,8 +244,8 @@ void handleSerialCommands() {
235244
if(song.endsWith(".mid")) {
236245
// need to load a soundfont
237246
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
240249
if(sf2) {
241250
// a soundfount was found
242251
AudioGeneratorMIDI* midi = new AudioGeneratorMIDI();
@@ -281,30 +290,79 @@ void handleSerialCommands() {
281290
return;
282291
}
283292
} // end of music_player
293+
#endif
284294

285295
// WIP: record | mic
286296
// https://github.com/earlephilhower/ESP8266Audio/issues/70
287297
// https://github.com/earlephilhower/ESP8266Audio/pull/118
288298

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;
298319
}
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
299328
return;
300329
}
301-
*/
302330

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+
303356
if(cmd_str == "clock" ) {
304357
//esp_timer_stop(screensaver_timer); // disable screensaver while the clock is running
305358
runClockLoop();
306359
return;
307360
}
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+
308366

309367
Serial.println("unsupported serial command: " + cmd_str);
310368

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)