Skip to content

Commit

Permalink
Merge pull request #602 from Lamnxzp/fix
Browse files Browse the repository at this point in the history
Bug Fixes: NEC Extended Encoding Issue (custom_ir.cpp) and Last Captured Signal appearing after the Device Save (ir_read.cpp)
  • Loading branch information
bmorcelli authored Dec 24, 2024
2 parents bfcc813 + f868908 commit a8b4144
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/modules/ir/custom_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ void otherIRcodes() {
else if(codes[i].protocol.startsWith("RC6")) options.push_back({ codes[i].name.c_str(), [=](){ sendRC6Command(codes[i].address, codes[i].command); addToRecentCodes(codes[i]); }});
else if(codes[i].protocol.startsWith("Samsung")) options.push_back({ codes[i].name.c_str(), [=](){ sendSamsungCommand(codes[i].address, codes[i].command); addToRecentCodes(codes[i]); }});
else if(codes[i].protocol=="SIRC") options.push_back({ codes[i].name.c_str(), [=](){ sendSonyCommand(codes[i].address, codes[i].command); addToRecentCodes(codes[i]); }});
else if(codes[i].protocol!="" && codes[i].data!="") options.push_back({ codes[i].name.c_str(), [=](){ sendDecodedCommand(codes[i].protocol, codes[i].data); addToRecentCodes(codes[i]); }});
else if(codes[i].protocol=="Panasonic") options.push_back({ codes[i].name.c_str(), [=](){ sendPanasonicCommand(codes[i].address, codes[i].command); addToRecentCodes(codes[i]); }});
else if(codes[i].protocol!="" && codes[i].data!="") options.push_back({ codes[i].name.c_str(), [=](){ sendDecodedCommand(codes[i].protocol, codes[i].data); addToRecentCodes(codes[i]); }});
}
options.push_back({ "Main Menu" , [&](){ exit=true; }});
databaseFile.close();
Expand All @@ -355,6 +355,10 @@ void sendNECCommand(String address, String command) {
if(first_zero_byte_pos!=-1) address = address.substring(0, first_zero_byte_pos);
first_zero_byte_pos = command.indexOf("00", 2);
if(first_zero_byte_pos!=-1) command = command.substring(0, first_zero_byte_pos);

address.replace(" ", "");
command.replace(" ", "");

uint16_t addressValue = strtoul(address.c_str(), nullptr, 16);
uint16_t commandValue = strtoul(command.c_str(), nullptr, 16);
uint64_t data = irsend.encodeNEC(addressValue, commandValue);
Expand All @@ -363,7 +367,6 @@ void sendNECCommand(String address, String command) {
digitalWrite(bruceConfig.irTx, LED_OFF);
}


void sendRC5Command(String address, String command) {
IRsend irsend(bruceConfig.irTx,true); // Set the GPIO to be used to sending the message.
irsend.begin();
Expand Down Expand Up @@ -447,8 +450,8 @@ void sendPanasonicCommand(String address, String command) {

bool sendDecodedCommand(String protocol, String value, String bits) {
// https://github.com/crankyoldgit/IRremoteESP8266/blob/master/examples/SmartIRRepeater/SmartIRRepeater.ino

decode_type_t type = strToDecodeType(protocol.c_str());
decode_type_t type = strToDecodeType(protocol.c_str());
if(type == decode_type_t::UNKNOWN) return false;
uint16_t nbit_int = bits.toInt();

Expand All @@ -472,7 +475,6 @@ bool sendDecodedCommand(String protocol, String value, String bits) {
success = irsend.send(type, state, state_pos); // safer

} else {

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

Expand Down
23 changes: 10 additions & 13 deletions src/modules/ir/ir_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ String IrRead::parse_raw_signal() {
return signal_code;
}


void IrRead::append_to_file_str(String btn_name) {
strDeviceContent += "name: " + btn_name + "\n";

Expand Down Expand Up @@ -312,34 +311,32 @@ void IrRead::save_device() {

FS* fs = nullptr;

bool sdCardAvaible = setupSdCard();
bool littleFsAvaible = checkLittleFsSize();
bool sdCardAvailable = setupSdCard();
bool littleFsAvailable = checkLittleFsSize();

if (sdCardAvaible && littleFsAvaible) {
if (sdCardAvailable && littleFsAvailable) {
// ask to choose one
options = {
{"SD Card", [&]() { fs=&SD; }},
{"SD Card", [&]() { fs=&SD; }},
{"LittleFS", [&]() { fs=&LittleFS; }},
};
delay(200);
loopOptions(options);
} else if (sdCardAvaible) {
} else if (sdCardAvailable) {
fs=&SD;
} else if (littleFsAvaible) {
} else if (littleFsAvailable) {
fs=&LittleFS;
};

if (fs != nullptr && write_file(filename, fs)) {
if (fs && write_file(filename, fs)) {
displaySuccess("File saved to " + String((fs == &SD) ? "SD Card" : "LittleFS") + ".", true);
signals_read = 0;
strDeviceContent = "";
} else {
if (fs == nullptr) {
displayError("No storage available.", true);
} else displayError("Error writing file.", true);
}
} else displayError(fs ? "Error writing file." : "No storage available.", true);

delay(1000);

irrecv.resume();
begin();
}

Expand Down

0 comments on commit a8b4144

Please sign in to comment.