Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Code to parse through and send Flipper Zero Codes. #135

Closed
wants to merge 12 commits into from
171 changes: 171 additions & 0 deletions IRextra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#include <FS.h>
#include <SD.h>
#include <SPI.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>

#define IR_DATA_BUFFER_SIZE 2000

File databaseFile;


void sendRawCommand(int frequency, String rawData);
void sendNECextCommand(String address, String command);
void sendNECCommand(String address, String command);
void sendRC5Command(String address, String command);
void sendSamsungCommand(String address, String command);
void sendSonyCommand(String address, String command);
void otherIRcodes();

//Setup
void otherIRcodes() {
//Serial.begin(115200);

databaseFile = SD.open("/Power_off.txt");
if (!databaseFile) {
Serial.println("Failed to open database file.");
return;
}
Serial.println("Opened database file.");
String line;
while (databaseFile.available()) {
line = databaseFile.readStringUntil('\n');
if (line.startsWith("type:")) {
String type = line.substring(5);
type.trim();
//Serial.println(type);
//Serial.println("type1");
if (type == "raw") {
//Serial.println("RAW");
int frequency = 0;
String rawData = "";
while (databaseFile.available()) {
line = databaseFile.readStringUntil('\n');
if (line.startsWith("frequency:")) {
String frequencyString = line.substring(10);
frequencyString.trim();
frequency = frequencyString.toInt();
} else if (line.startsWith("data:")) {
rawData = line.substring(5);
rawData.trim();
} else if (line.indexOf("#") != -1) {
//Serial.println(frequency);
//Serial.println(rawData);
sendRawCommand(frequency, rawData);
rawData = "";
frequency = 0;
type = "";
line = "";
break;
}
}
} else if (type == "parsed") {
String protocol = "";
String address = "";
String command = "";
//Serial.println("PARSED");
while (databaseFile.available()) {
line = databaseFile.readStringUntil('\n');
if (line.startsWith("protocol:")) {
protocol = line.substring(9);
protocol.trim();
//Serial.println(protocol);
} else if (line.startsWith("address:")) {
address = line.substring(8);
address.trim();
//Serial.println(address);
} else if (line.startsWith("command:")) {
command = line.substring(8);
command.trim();
//Serial.println(command);
} else if (line.indexOf("#") != -1) {
if (protocol == "NECext") {
sendNECextCommand(address, command);
} else if (protocol == "NEC") {
sendNECCommand(address, command);
} else if (protocol == "RC5") {
sendRC5Command(address, command);
} else if (protocol == "Samsung") {
sendSamsungCommand(address, command);
} else if (protocol.startsWith("SIRC")) {
sendSonyCommand(address, command);
}
protocol = "";
address = "";
command = "";
type = "";
line = "";
break;
}
}
}
}
//else{
//Serial.println("closed1");
//}

}
databaseFile.close();
//Serial.println("closed");
//Serial.println("closed");
//change to finished extra
//Serial.println("EXTRA finished");
}

//IR commands
void sendNECCommand(String address, String command) {
uint32_t addressValue = strtoul(address.c_str(), nullptr, 16);
uint32_t commandValue = strtoul(command.c_str(), nullptr, 16);
irsend.sendNEC(addressValue, commandValue, 32);
//Serial.println("Sent1");
}

void sendNECextCommand(String address, String command) {
uint32_t addressValue = strtoul(address.c_str(), nullptr, 16);
uint32_t commandValue = strtoul(command.c_str(), nullptr, 16);
irsend.sendNEC(addressValue, commandValue, 32);
//Serial.println("Sent2");
}

void sendRC5Command(String address, String command) {
uint32_t addressValue = strtoul(address.c_str(), nullptr, 16);
uint32_t commandValue = strtoul(command.c_str(), nullptr, 16);
irsend.sendRC5(addressValue, commandValue, 12);
//Serial.println("Sent3");
}

void sendSamsungCommand(String address, String command) {
uint64_t data = ((uint64_t)strtoul(address.c_str(), nullptr, 16) << 32) | strtoul(command.c_str(), nullptr, 16);
irsend.sendSamsung36(data, 36);
//Serial.println("Sent4");
}

void sendSonyCommand(String address, String command) {
uint16_t data = (uint16_t)strtoul(command.c_str(), nullptr, 16);
uint16_t addressValue = (uint16_t)strtoul(address.c_str(), nullptr, 16);
irsend.sendSony(addressValue, data);
//Serial.println("Sent5");
}

void sendRawCommand(int frequency, String rawData) {
uint16_t dataBuffer[IR_DATA_BUFFER_SIZE];
int count = 0;

// Parse raw data string
while (rawData.length() > 0 && count < IR_DATA_BUFFER_SIZE) {
int delimiterIndex = rawData.indexOf(' ');
if (delimiterIndex == -1) {
delimiterIndex = rawData.length();
}
String dataChunk = rawData.substring(0, delimiterIndex);
rawData.remove(0, delimiterIndex + 1);
dataBuffer[count++] = dataChunk.toInt();
}

//Serial.println("Parsing raw data complete.");

// Send raw command
irsend.sendRaw(dataBuffer, count, frequency);

//Serial.println("Sent6");
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NEMO is named after the small, clever and stubborn fish in Finding Nemo. This pr

## My Changelog
* Adjusted .github/workflow/compile.yml to compile with the DEAUTH function.
* Added suport to SONG on StickC Plus and Plus2
* Added support to SONG on StickC Plus and Plus2
* Added an "Attack Menu" when seeing details of an Access Point
- Clone Portal (Creates an Evil portal with the same SSID of the target)
- Deauth attack (broadcasts deauthentication frames to devices connected to this Access Point)
Expand Down Expand Up @@ -117,7 +117,7 @@ arduino-cli compile --fqbn m5stack:esp32:m5stack_cardputer -e --build-property b

```

- This will create multiple binaries based on partition sketch, you can merge a single binary using `esptool``
- This will create multiple binaries based on partition sketch, you can merge a single binary using `esptool`
- Install esptool - `pip install -U esptool`

```bash
Expand Down Expand Up @@ -151,7 +151,7 @@ ls ./build

# This will flash the build output from the build step, it reuses the container image from the previous step.
# By default this will compile for the M5Cardputer in en-us locale, ./config/.env.M5Cardputer
./scipts/flash.sh --device=/dev/ttyusb0
./scripts/flash.sh --device=/dev/ttyusb0

# If you passed a different build config make sure to pass it along to the flash script
./scipts/flash.sh --device=/dev/ttyusb0 --build-config=./config/.env.M5Cardputer
Expand All @@ -178,7 +178,7 @@ Please report bugs via GitHub Issues. These are easier to track than comments on

## Contributing
Contributions are welcome.
* Pliease look at the GitHub Issues for the project. There are feature suggestions and bugs reported there, and I'd appreciate PRs that address those.
* Please look at the GitHub Issues for the project. There are feature suggestions and bugs reported there, and I'd appreciate PRs that address those.
* When submitting a Pull Request, please target the develop branch. The easiest way to do this is to fork ALL branches, or to simply create a "develop" branch in your own fork, then use GitHub to Sync your develop branch.
* Take note of how certain hardware (like the LED and RTC) are defined and gated in the code and try to stick to those patterns. Also, use the definitions for FGCOLOR, BGCOLOR, TEXT_SIZE* and the DISP alias when outputting things to the built-in display.
* Feel free to add your github to the contributors array as part of your pull request.
Expand Down
14 changes: 11 additions & 3 deletions m5stick-nemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ MENU tvbgmenu[] = {
{ TXT_MN_AMERICA, 0},
{ TXT_MN_EMEA, 1},
{ TXT_MN_CUSTOM, 2}
{ TXT_MN_CUSTOM,"2", 4}
};
int tvbgmenu_size = sizeof(tvbgmenu) / sizeof (MENU);

Expand Down Expand Up @@ -1164,8 +1165,7 @@ void tvbgmenu_loop() {
isSwitching = true;
rstOverride = false;
return;
}

}
#if defined(USE_EEPROM)
EEPROM.write(3, region);
EEPROM.commit();
Expand All @@ -1182,9 +1182,17 @@ void sendAllCodes() {
num_codes = num_NAcodes;
} else if (region == EU) {
num_codes = num_EUcodes;
} else {
} else if {
num_codes = num_CUSTOMcodes;
}
else {
#if defined(SD_CARD)
DISP.fillScreen(BGCOLOR);
DISP.println(TXT_TRIG_TV);
DISP.println(TXT_RG_CUSTOM,"2");
otherIRcodes();
#endif
}
for (i = 0 ; i < num_codes; i++)
{
if (region == NA) {
Expand Down