Skip to content

Commit

Permalink
new device air conditioner
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed Sep 28, 2024
1 parent e8694b8 commit 823381b
Show file tree
Hide file tree
Showing 6 changed files with 641 additions and 66 deletions.
101 changes: 35 additions & 66 deletions Platformio/hardware/ESP32/infrared_sender_hal_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,38 @@ enum IRprotocols {
IR_PROTOCOL_SAMSUNG36 = 6
};
void sendIRcode_HAL(int protocol, std::list<std::string> commandPayloads, std::string additionalPayload) {

// first determine if data was provided by commandPayload or by additionalPayload. Only one of these will be used.
std::string::size_type sz = 0; // alias of size_t
std::string dataStr;
uint64_t data;
if (commandPayloads.empty() && (additionalPayload == "")) {
Serial.printf("execute: cannot send IR command, because both data and payload are empty\r\n");
return;
} else {
if (additionalPayload != "") {
dataStr = additionalPayload;
} else {
auto current = commandPayloads.begin();
dataStr = *current;
}
}

switch (protocol) {
case IR_PROTOCOL_GC: {
auto current = commandPayloads.begin();
std::string arrayStr = *current;
// first create array of needed size
std::string::difference_type size = std::count(arrayStr.begin(), arrayStr.end(), ',');
std::string::difference_type size = std::count(dataStr.begin(), dataStr.end(), ',');
size += 1;
uint16_t *buf = new uint16_t[size];
// now get comma separated values and fill array
int pos = 0;
std::stringstream ss(arrayStr);
std::stringstream ss(dataStr);
while(ss.good()) {
std::string dataStr;
std::getline(ss, dataStr, ',');
std::string valueStr;
std::getline(ss, valueStr, ',');
// https://cplusplus.com/reference/string/stoull/
std::string::size_type sz = 0; // alias of size_t
const uint64_t data = std::stoull(dataStr, &sz, 0);
// Serial.printf(" next string value %s (%" PRIu64 ")\r\n", dataStr.c_str(), data);
data = std::stoull(valueStr, &sz, 0);
// Serial.printf(" next string value %s (%" PRIu64 ")\r\n", valueStr.c_str(), data);
buf[pos] = data;
pos += 1;
}
Expand All @@ -56,87 +70,42 @@ void sendIRcode_HAL(int protocol, std::list<std::string> commandPayloads, std::s
}

case IR_PROTOCOL_NEC: {
auto current = commandPayloads.begin();
std::string dataStr = *current;
// https://cplusplus.com/reference/string/stoull/
std::string::size_type sz = 0; // alias of size_t
const uint64_t data = std::stoull(dataStr, &sz, 0);
data = std::stoull(dataStr, &sz, 0);
Serial.printf("execute: will send IR NEC, data %s (%" PRIu64 ")\r\n", dataStr.c_str(), data);
IrSender.sendNEC(data);
break;
}

case IR_PROTOCOL_SAMSUNG: {
auto current = commandPayloads.begin();
std::string dataStr = *current;
// https://cplusplus.com/reference/string/stoull/
std::string::size_type sz = 0; // alias of size_t
const uint64_t data = std::stoull(dataStr, &sz, 0);
data = std::stoull(dataStr, &sz, 0);
Serial.printf("execute: will send IR SAMSUNG, data %s (%" PRIu64 ")\r\n", dataStr.c_str(), data);
IrSender.sendSAMSUNG(data);
break;
}

case IR_PROTOCOL_SONY: {
std::string::size_type sz = 0; // alias of size_t
uint64_t data;
if (commandPayloads.empty() && (additionalPayload == "")) {
Serial.printf("execute: cannot send IR SONY, because both data and payload are empty\r\n");
} else {
if (additionalPayload != "") {
data = std::stoull(additionalPayload, &sz, 0);
} else {
auto current = commandPayloads.begin();
data = std::stoull(*current, &sz, 0);
}
Serial.printf("execute: will send IR SONY 15 bit, data (%" PRIu64 ")\r\n", data);
IrSender.sendSony(data, 15);
}
data = std::stoull(dataStr, &sz, 0);
Serial.printf("execute: will send IR SONY 15 bit, data %s (%" PRIu64 ")\r\n", dataStr.c_str(), data);
IrSender.sendSony(data, 15);
break;
}

case IR_PROTOCOL_RC5: {
std::string::size_type sz = 0; // alias of size_t
uint64_t data;
if (commandPayloads.empty() && (additionalPayload == "")) {
Serial.printf("execute: cannot send IR RC5, because both data and payload are empty\r\n");
} else {
if (additionalPayload != "") {
data = std::stoull(additionalPayload, &sz, 0);
} else {
auto current = commandPayloads.begin();
data = std::stoull(*current, &sz, 0);
}
Serial.printf("execute: will send IR RC5, data (%" PRIu64 ")\r\n", data);
IrSender.sendRC5(IrSender.encodeRC5X(0x00, data));
}
data = std::stoull(dataStr, &sz, 0);
Serial.printf("execute: will send IR RC5, data %s (%" PRIu64 ")\r\n", dataStr.c_str(), data);
IrSender.sendRC5(IrSender.encodeRC5X(0x00, data));
break;
}

case IR_PROTOCOL_DENON: {
std::string::size_type sz = 0; // alias of size_t
uint64_t data;
if (commandPayloads.empty() && (additionalPayload == "")) {
Serial.printf("execute: cannot send IR DENON 48 bit, because both data and payload are empty\r\n");
} else {
if (additionalPayload != "") {
data = std::stoull(additionalPayload, &sz, 0);
} else {
auto current = commandPayloads.begin();
data = std::stoull(*current, &sz, 0);
}
Serial.printf("execute: will send IR DENON 48 bit, data (%" PRIu64 ")\r\n", data);
IrSender.sendDenon(data, 48);
}
data = std::stoull(dataStr, &sz, 0);
Serial.printf("execute: will send IR DENON 48 bit, data %s (%" PRIu64 ")\r\n", dataStr.c_str(), data);
IrSender.sendDenon(data, 48);
break;
}

case IR_PROTOCOL_SAMSUNG36: {
auto current = commandPayloads.begin();
std::string dataStr = *current;
// https://cplusplus.com/reference/string/stoull/
std::string::size_type sz = 0; // alias of size_t
const uint64_t data = std::stoull(dataStr, &sz, 0);
data = std::stoull(dataStr, &sz, 0);
Serial.printf("execute: will send IR SAMSUNG36, data %s (%" PRIu64 ")\r\n", dataStr.c_str(), data);
IrSender.sendSamsung36(data);
break;
Expand Down
Loading

0 comments on commit 823381b

Please sign in to comment.