From 00ca86ed5d89032f640177e2a43bd08d05bd9993 Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Fri, 26 Jul 2024 05:43:37 +0200 Subject: [PATCH 1/2] added power serial cmds, wakeup cardputer by pressing any key (#64) --- src/core/serialcmds.cpp | 76 +++++++++++++++++++++++++++++++++-------- src/core/settings.cpp | 2 +- 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 205cf7ea..ace23839 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -12,6 +12,7 @@ #include "sd_functions.h" #include "settings.h" #include "display.h" +#include "powerSave.h" #include "modules/rf/rf.h" @@ -54,6 +55,10 @@ void handleSerialCommands() { // TODO: more commands https://docs.flipper.net/development/cli#0Z9fs + if(cmd_str == "" ) { // empty + return; + } + if(cmd_str.startsWith("ir") ) { // ir tx
@@ -194,11 +199,11 @@ void handleSerialCommands() { } } // endof rf - if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("ttf" ) ) { + if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("tts" ) || cmd_str.startsWith("say" ) ) { // TODO: move in audio.cpp module AudioOutputI2S *audioout = new AudioOutputI2S(); // https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L32 #ifdef CARDPUTER - audioout->SetPinout(41, 43, 42); + audioout->SetPinout(41, 43, 42); // bclk, wclk, dout // TODO: other pinouts #endif AudioGenerator* generator = NULL; @@ -235,8 +240,8 @@ void handleSerialCommands() { if(song.endsWith(".mid")) { // need to load a soundfont AudioFileSource* sf2 = NULL; - if(setupSdCard()) sf2 = new AudioFileSourceSD("audio/1mgm.sf2"); // TODO: make configurable - if(!sf2) sf2 = new AudioFileSourceLittleFS("audio/1mgm.sf2"); // TODO: make configurable + if(setupSdCard()) sf2 = new AudioFileSourceSD("1mgm.sf2"); // TODO: make configurable + if(!sf2) sf2 = new AudioFileSourceLittleFS("1mgm.sf2"); // TODO: make configurable if(sf2) { // a soundfount was found AudioGeneratorMIDI* midi = new AudioGeneratorMIDI(); @@ -286,25 +291,68 @@ void handleSerialCommands() { // https://github.com/earlephilhower/ESP8266Audio/issues/70 // https://github.com/earlephilhower/ESP8266Audio/pull/118 -/* TODO: rewrite using the new screen dimmer feat. - if(cmd_str.startsWith("lcd " ) || cmd_str.startsWith("tft" ) ) { - String new_status = cmd_str.substring(strlen("lcd "), cmd_str.length()); - if(new_status=="off") { - analogWrite(BACKLIGHT, 0); - esp_timer_stop(screensaver_timer); - } else if(new_status=="on") { - getBrightness(); // reinit brightness - reset_screensaver_timer(); + // backlight brightness adjust (range 0-255) https://docs.flipper.net/development/cli/#XQQAI + // e.g. "led br 127" + if(cmd_str.startsWith("led br ")) { + const char* valueStr = cmd_str.c_str() + strlen("led br "); + int value = (atoi(valueStr) * 100) / 255; // convert to 0-100 range + //Serial.print("value: "); + //Serial.println(value); + if(value<=0) value=1; + if(value>100) value=100; + setBrightness(value, false); // false -> do not save + return; + } + else if(cmd_str.startsWith("led ")) { + // change UI color + // e.g. "led 255 255 255" + const char* rgbString = cmd_str.c_str() + 4; + int r, g, b; + if (sscanf(rgbString, "%d %d %d", &r, &g, &b) != 3) { + Serial.println("invalid color: " + String(rgbString)); + return; + } + if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { + Serial.println("invalid color: " + String(rgbString)); + return; } + uint16_t hexColor = tft.color565(r, g, b); // Use the TFT_eSPI function to convert RGB to 16-bit color + //Serial.print("converted color:"); + //SerialPrintHexString(hexColor); + FGCOLOR = hexColor; // change global var, dont save in settings return; } -*/ + // power cmds: off, reboot + if(cmd_str == "power off" ) { + // closest thing https://github.com/esp8266/Arduino/issues/929 + //ESP.deepSleep(0); + esp_deep_sleep_start(); // only wake up via hardware reset + return; + } + if(cmd_str == "power reboot" ) { + ESP.restart(); + return; + } + if(cmd_str == "power sleep" ) { + // cmd not supported on flipper0 + // TODO: proper sleep mode with esp_deep_sleep_start(); + setSleepMode(); + //turnOffDisplay(); + //esp_timer_stop(screensaver_timer); + return; + } + if(cmd_str == "clock" ) { //esp_timer_stop(screensaver_timer); // disable screensaver while the clock is running runClockLoop(); return; } + + // TODO: "storage" cmd to manage files https://docs.flipper.net/development/cli/#Xgais + + // TODO: "gpio" cmds https://docs.flipper.net/development/cli/#aqA4b + Serial.println("unsupported serial command: " + cmd_str); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 2ea0e291..9f6911ab 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -165,7 +165,7 @@ void setSleepMode() { sleepModeOn(); while (1) { #if defined(CARDPUTER) - if (checkEscPress() || checkSelPress()) + if (checkAnyKeyPress()) #else if (checkSelPress()) #endif From 51a2e5e1fc0908fbb18b73c26b8ad322652270ca Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:08:27 +0200 Subject: [PATCH 2/2] disabled music player for STICK_C_PLUS, fixed power off command on non-cardputer targets (#64) --- src/core/serialcmds.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index ace23839..441c78bb 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -7,8 +7,11 @@ #include "cJSON.h" #include // for PRIu64 -#include -#include +#ifndef STICK_C_PLUS + #include + #include +#endif + #include "sd_functions.h" #include "settings.h" #include "display.h" @@ -199,6 +202,7 @@ void handleSerialCommands() { } } // endof rf + #ifndef STICK_C_PLUS if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("tts" ) || cmd_str.startsWith("say" ) ) { // TODO: move in audio.cpp module AudioOutputI2S *audioout = new AudioOutputI2S(); // https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L32 @@ -286,6 +290,7 @@ void handleSerialCommands() { return; } } // end of music_player + #endif // WIP: record | mic // https://github.com/earlephilhower/ESP8266Audio/issues/70 @@ -323,11 +328,17 @@ void handleSerialCommands() { return; } - // power cmds: off, reboot + // power cmds: off, reboot, sleep if(cmd_str == "power off" ) { // closest thing https://github.com/esp8266/Arduino/issues/929 - //ESP.deepSleep(0); - esp_deep_sleep_start(); // only wake up via hardware reset + #if defined(STICK_C_PLUS) + axp192.PowerOff(); + #elif defined(STICK_C_PLUS2) + digitalWrite(4,LOW); + #else + //ESP.deepSleep(0); + esp_deep_sleep_start(); // only wake up via hardware reset + #endif return; } if(cmd_str == "power reboot" ) { @@ -335,8 +346,7 @@ void handleSerialCommands() { return; } if(cmd_str == "power sleep" ) { - // cmd not supported on flipper0 - // TODO: proper sleep mode with esp_deep_sleep_start(); + // NOTE: cmd not supported on flipper0 setSleepMode(); //turnOffDisplay(); //esp_timer_stop(screensaver_timer);