From edfdbac7e61069604c8950d23a392c7e184b8e0f Mon Sep 17 00:00:00 2001 From: eadmaster <925171+eadmaster@users.noreply.github.com> Date: Fri, 12 Jul 2024 08:51:09 +0200 Subject: [PATCH] added serialcmds (#64) --- src/main.cpp | 10 ++++++++++ src/serialcmds.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/serialcmds.h | 3 +++ 3 files changed, 59 insertions(+) create mode 100644 src/serialcmds.cpp create mode 100644 src/serialcmds.h diff --git a/src/main.cpp b/src/main.cpp index 71e5f825..b3829b10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,6 +61,7 @@ TFT_eSprite draw = TFT_eSprite(&tft); #include "wifi_atks.h" #include "ble_spam.h" #include "openhaystack.h" +#include "serialcmds.h" #ifdef CARDPUTER @@ -145,6 +146,11 @@ void setup() { if((millis()-i>3400) && (millis()-i)<3600) tft.fillScreen(TFT_BLACK); if((millis()-i>3600)) tft.drawXBitmap(1,1,bits, bits_width, bits_height,TFT_BLACK,FGCOLOR); + //reinit needed? + Serial.begin(115200); + Serial.println("setup: serial init1"); + log_d("setup: serial init2"); + #if defined (CARDPUTER) // If any key is pressed, it'll jump the boot screen Keyboard.update(); if(Keyboard.isPressed()) @@ -173,7 +179,11 @@ void loop() { int index = 0; int opt = 6; // there are 3 options> 1 list SD files, 2 OTA and 3 Config tft.fillRect(0,0,WIDTH,HEIGHT,BGCOLOR); + log_d("loop"); while(1){ + handleSerialCommands(); + log_d("loop while"); + if(returnToMenu) { returnToMenu = false; tft.fillScreen(BGCOLOR); //fix any problem with the mainMenu screen when coming back from submenus or functions diff --git a/src/serialcmds.cpp b/src/serialcmds.cpp new file mode 100644 index 00000000..55773b24 --- /dev/null +++ b/src/serialcmds.cpp @@ -0,0 +1,46 @@ + +#include "serialcmds.h" +#include "globals.h" +#include +#include +#include "TV-B-Gone.h" + + +void handleSerialCommands() { + String cmd_str; + const int MIN_CMD_LEN = 1; + + if (Serial.available() >= MIN_CMD_LEN) { + cmd_str = Serial.readStringUntil('\n'); + } else { + // try again on next iteration + return; + } + + log_printf("received: %s\n", cmd_str.c_str()); + + // https://docs.flipper.net/development/cli#0Z9fs + cmd_str = cmd_str.toLowerCase(); + + if(cmd_str.startsWith("ir tx ")){ // ir tx
+ // : NEC, NECext, NEC42, NEC42ext, Samsung32, RC6, RC5, RC5X, SIRC, SIRC15, SIRC20, Kaseikyo, RCA + //
and must be in hex format + // e.g. ir tx NEC 04000000 08000000 + + if(cmd_str.startsWith("ir tx nec ")){ + String address = cmd_str.substring(10, 8); + String command = cmd_str.substring(19, 8); + // check if valid address, command + sendNECCommand(address, command); + log_printf("address: %x\tcommand=%x\n", address, command); + + } + + } + + //if(cmd_str.startsWith("ir tx raw")){ + + + +} + diff --git a/src/serialcmds.h b/src/serialcmds.h new file mode 100644 index 00000000..8ffcac56 --- /dev/null +++ b/src/serialcmds.h @@ -0,0 +1,3 @@ + + +void handleSerialCommands(); \ No newline at end of file