Skip to content

Commit

Permalink
added serialcmds (pr3y#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmaster committed Jul 12, 2024
1 parent 66a8e82 commit edfdbac
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions src/serialcmds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include "serialcmds.h"
#include "globals.h"
#include <IRsend.h>
#include <string>
#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 <protocol> <address> <command>
// <protocol>: NEC, NECext, NEC42, NEC42ext, Samsung32, RC6, RC5, RC5X, SIRC, SIRC15, SIRC20, Kaseikyo, RCA
// <address> and <command> 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")){



}

3 changes: 3 additions & 0 deletions src/serialcmds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


void handleSerialCommands();

0 comments on commit edfdbac

Please sign in to comment.