Skip to content

Commit

Permalink
fixed ir raw reading, esp32-s3-devkitc-1 build, added support for ir …
Browse files Browse the repository at this point in the history
…signals with state (pr3y#216)
  • Loading branch information
eadmaster committed Sep 24, 2024
1 parent 35dea5e commit 7e56bca
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 32 deletions.
3 changes: 3 additions & 0 deletions src/core/VectorDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,9 @@ class SerialDisplayClass : public VectorDisplayClass {
VectorDisplayClass::begin(width, height);
}

bool getSwapBytes(void) { return false; } // stub
void setSwapBytes(bool swap) { return; } // stub

virtual void begin(int width=VECTOR_DISPLAY_DEFAULT_WIDTH, int height=VECTOR_DISPLAY_DEFAULT_HEIGHT) override {
begin(115200, width, height);
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/passwords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "globals.h"
#include "sd_functions.h"
#include "mykeyboard.h"

#include "modules/rf/rf.h" //for hexCharToDecimal


String xorEncryptDecryptMD5(const String &input, const String &password, const int MD5_PASSES) {
Expand Down Expand Up @@ -73,8 +73,6 @@ String readDecryptedFileOLD(FS &fs, String filepath) {
return plaintext;
}
*/

#include "modules/rf/rf.h" //for hexCharToDecimal

String readDecryptedFile(FS &fs, String filepath) {

Expand Down
40 changes: 31 additions & 9 deletions src/modules/ir/TV-B-Gone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Distributed under Creative Commons 2.5 -- Attribution & Share Alike
#include "core/settings.h"
#include "WORLD_IR_CODES.h"
#include "TV-B-Gone.h"
#include "modules/rf/rf.h" //for hexCharToDecimal
#include <IRutils.h>

char16_t FGCOLOR;
Expand Down Expand Up @@ -292,6 +293,7 @@ bool txIrFile(FS *fs, String filepath) {
String address = "";
String command = "";
String value = "";
String state = "";
String bits = "32";

databaseFile.seek(0); // comes back to first position
Expand Down Expand Up @@ -357,8 +359,8 @@ bool txIrFile(FS *fs, String filepath) {
command = line.substring(8);
command.trim();
Serial.println("Command: "+command);
} else if (line.startsWith("value:")) {
value = line.substring(strlen("value:"));
} else if (line.startsWith("value:") || line.startsWith("state:")) {
value = line.substring(6);
value.trim();
Serial.println("Value: "+value);
} else if (line.startsWith("bits:")) {
Expand Down Expand Up @@ -386,6 +388,7 @@ bool txIrFile(FS *fs, String filepath) {
command = "";
protocol = "";
value = "";
state = "";
type = "";
line = "";
break;
Expand Down Expand Up @@ -508,7 +511,7 @@ void otherIRcodes() {
if(line.startsWith("frequency:")) codes[total_codes].frequency = txt.toInt();
//if(line.startsWith("duty_cycle:")) codes[total_codes].duty_cycle = txt.toFloat();
if(line.startsWith("command:")) { codes[total_codes].command = txt; total_codes++; }
if(line.startsWith("data:") || line.startsWith("value:")) { codes[total_codes].data = txt; total_codes++; }
if(line.startsWith("data:") || line.startsWith("value:") || line.startsWith("state:")) { codes[total_codes].data = txt; total_codes++; }
}
options = { };
bool exit = false;
Expand Down Expand Up @@ -636,15 +639,34 @@ bool sendDecodedCommand(String protocol, String value, String bits) {

decode_type_t type = strToDecodeType(protocol.c_str());
if(type == decode_type_t::UNKNOWN) return false;
value.replace(" ", "");
uint64_t value_int = strtoull(value.c_str(), nullptr, 16);
uint16_t nbit_int = bits.toInt();

displayRedStripe("Sending..",TFT_WHITE,FGCOLOR);

IRsend irsend(IrTx); // Set the GPIO to be used to sending the message.
irsend.begin();
bool success = irsend.send(type, value_int, nbit_int); // bool send(const decode_type_t type, const uint64_t data, const uint16_t nbits, const uint16_t repeat = kNoRepeat);
bool success = false;
displayRedStripe("Sending..",TFT_WHITE,FGCOLOR);

if(hasACState(type)) {
// need to send the state (passed from value)
uint8_t state[nbit_int / 8] = {0};
uint16_t state_pos = 0;
for (uint16_t i = 0; i < value.length(); i += 3) {
// parse value -> state
uint8_t highNibble = hexCharToDecimal(value[i]);
uint8_t lowNibble = hexCharToDecimal(value[i + 1]);
state[state_pos] = (highNibble << 4) | lowNibble;
state_pos++;
}
//success = irsend.send(type, state, nbit_int / 8);
success = irsend.send(type, state, state_pos); // safer

} else {

value.replace(" ", "");
uint64_t value_int = strtoull(value.c_str(), nullptr, 16);

success = irsend.send(type, value_int, nbit_int); // bool send(const decode_type_t type, const uint64_t data, const uint16_t nbits, const uint16_t repeat = kNoRepeat);
}

delay(20);
Serial.println("Sent Decoded Command");
Expand All @@ -667,7 +689,7 @@ void sendRawCommand(uint16_t frequency, String rawData) {
}
String dataChunk = rawData.substring(0, delimiterIndex);
rawData.remove(0, delimiterIndex + 1);
dataBuffer[count++] = (dataChunk.toInt())/2;
dataBuffer[count++] = (dataChunk.toInt());
}

Serial.println("Parsing raw data complete.");
Expand Down
62 changes: 43 additions & 19 deletions src/modules/ir/ir_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ String uint32ToString(uint32_t value) {
return String(buffer);
}

String uint32ToStringInverted(uint32_t value) {
char buffer[12] = {0}; // 8 hex digits + 3 spaces + 1 null terminator
snprintf(buffer, sizeof(buffer), "%02X %02X %02X %02X",
(value >> 24) & 0xFF,
(value >> 16) & 0xFF,
(value >> 8) & 0xFF,
value & 0xFF);
return String(buffer);
}



IrRead::IrRead(bool headless_mode, bool raw_mode) {
headless = headless_mode;
Expand Down Expand Up @@ -158,33 +169,36 @@ void IrRead::save_signal() {
}


String IrRead::parse_state_signal() {
String r = "";
uint16_t state_len = (results.bits) / 8;
for (uint16_t i = 0; i < state_len; i++) {
//r += uint64ToString(results.state[i], 16) + " ";
r += ((results.state[i] < 0x10) ? "0" : ""); // adds 0 padding if necessary
r += String(results.state[i], HEX) + " ";
}
r.toUpperCase();
return r;
}

String IrRead::parse_raw_signal() {
//rawcode = new uint16_t[MAX_RAWBUF_SIZE];
//memset(rawcode, 0, MAX_RAWBUF_SIZE * sizeof(uint16_t));
//raw_data_len = results.rawlen;

// https://github.com/crankyoldgit/IRremoteESP8266/blob/master/examples/SmartIRRepeater/SmartIRRepeater.ino
rawcode = resultToRawArray(&results);
// Find out how many elements are in the array.
raw_data_len = getCorrectedRawLength(&results);

String signal_code = "";
//String signal_code2 = "";

// I HAVE NO FUCKING IDEA WHY WE NEED TO MULTIPLY BY 2, BUT WE DO.
for (uint16_t i = 1; i < raw_data_len; i++) {
//signal_code2 += String(results.rawbuf[i] * 2) + " ";
//rawcode[i - 1] = results.rawbuf[i] * 2;
//Serial.println(results.rawbuf[i]);
//Serial.println(rawcode[i]);
signal_code += String(rawcode[i] * 2) + " ";

for (uint16_t i = 0; i < raw_data_len; i++) {
signal_code += String(rawcode[i]) + " ";
}
delete[] rawcode;
rawcode = nullptr;
signal_code.trim();

//Serial.println(raw_data_len);
//Serial.println("data2 " + signal_code2);
return signal_code;
}

Expand Down Expand Up @@ -254,19 +268,20 @@ void IrRead::append_to_file_str(String btn_name) {
break;
}
}
//

strDeviceContent += "address: " + uint32ToString(results.address) + "\n";
strDeviceContent += "command: " + uint32ToString(results.command) + "\n";

// extra fields not supported on flipper
if(results.bits>32)
strDeviceContent += "value: " + uint32ToString(results.value >> 32) + " " + uint32ToString(results.value) + "\n"; // MEMO: from uint64_t
else
strDeviceContent += "value: " + uint32ToString(results.value) + "\n";
strDeviceContent += "bits: " + String(results.bits) + "\n";

if(hasACState(results.decode_type))
strDeviceContent += "state: " + parse_state_signal() + "\n";
else if(results.bits>32)
strDeviceContent += "value: " + uint32ToString(results.value) + " " + uint32ToString(results.value>> 32) + "\n"; // MEMO: from uint64_t
else
strDeviceContent += "value: " + uint32ToStringInverted(results.value) + "\n";

/*
Serial.println("IR results:");
Serial.println(results.bits);
Serial.println(results.address);
Serial.println(results.command);
Expand All @@ -275,6 +290,15 @@ void IrRead::append_to_file_str(String btn_name) {
Serial.println("value:");
serialPrintUint64(results.address, HEX);
serialPrintUint64(results.command, HEX);
*
Serial.print("resultToHexidecimal: ");
Serial.println(resultToHexidecimal(&results)); // 0x20DFC03F
Serial.println(results.value);
Serial.println();
String value = uint32ToString(results.value ) + " " + uint32ToString(results.value>> 32);
value.replace(" ", "");
uint64_t value_int = strtoull(value.c_str(), nullptr, 16);
Serial.println(value_int);
*/
}
strDeviceContent += "#\n";
Expand Down
3 changes: 2 additions & 1 deletion src/modules/ir/ir_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class IrRead {
public:
//IRrecv irrecv = IRrecv(IrRx);
IRrecv irrecv = IRrecv(IrRx, SAFE_STACK_BUFFER_SIZE, 50);
IRrecv irrecv = IRrecv(IrRx, SAFE_STACK_BUFFER_SIZE/2, 50);


/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -57,4 +57,5 @@ class IrRead {
void append_to_file_str(String btn_name);
bool write_file(String filename, FS* fs);
String parse_raw_signal();
String parse_state_signal();
};

0 comments on commit 7e56bca

Please sign in to comment.