Add more options to IRsend raw

Add more options to IRsend raw
This commit is contained in:
Theo Arends 2019-04-10 18:28:46 +02:00
parent a454ab71de
commit 90223a8eaa
1 changed files with 46 additions and 19 deletions

View File

@ -542,51 +542,78 @@ bool IrSendCommand(void)
if (strstr(XdrvMailbox.data, "{") == nullptr) { // If no JSON it must be rawdata if (strstr(XdrvMailbox.data, "{") == nullptr) { // If no JSON it must be rawdata
// IRSend frequency, rawdata, rawdata ... // IRSend frequency, rawdata, rawdata ...
// or IRSend raw,<freq>,<header mark>,<header space>,<bit mark>,<zero space>,<one space>,<bit stream> // or
// IRsend raw,<freq>,<any space>,<bit stream>
// IRsend raw,<freq>,<zero space>,<one space>,<bit stream>
// IRSend raw,<freq>,<header mark>,<header space>,<bit mark>,<zero space>,<one space>,<bit stream>
char *p; char *p;
char *str = strtok_r(XdrvMailbox.data, ", ", &p); char *str = strtok_r(XdrvMailbox.data, ", ", &p);
if (p == nullptr) { if (p == nullptr) {
error = IE_INVALID_RAWDATA; error = IE_INVALID_RAWDATA;
} else { } else {
uint16_t freq = atoi(str); uint16_t freq = atoi(str);
if (!freq && (*str != '0')) { // First parameter is a string if (!freq && (*str != '0')) { // First parameter is any string
uint16_t count = 0; uint16_t count = 0;
char *q = p; char *q = p;
for (; *q; count += (*q++ == ',')); for (; *q; count += (*q++ == ','));
if (count != 6) { // Parameters must be exactly 6 if (count < 2) { // Parameters must be at least 3
error = IE_INVALID_RAWDATA; error = IE_INVALID_RAWDATA;
} else { } else {
uint16_t parm[6]; uint16_t parm[count];
for (uint8_t i = 0; i < 6; i++) { for (uint8_t i = 0; i < count; i++) {
str = strtok_r(nullptr, ", ", &p); str = strtok_r(nullptr, ", ", &p);
parm[i] = atoi(str); parm[i] = atoi(str);
if (!parm[i]) { if (!parm[i]) {
if (!i) { if (!i) {
parm[0] = 38000; // Frequency default to 38kHz parm[0] = 38000; // Frequency default to 38kHz
} else { } else {
error = IE_INVALID_RAWDATA; error = IE_INVALID_RAWDATA; // Other parameters may not be 0
break; break;
} }
} }
} }
if (IE_NO_ERROR == error) { if (IE_NO_ERROR == error) {
uint16_t raw_array[strlen(p)*2+3]; // Header + bits + end uint16_t raw_array[strlen(p)*2+3]; // Header + bits + end (Largest needed)
uint16_t i = 0; uint16_t i = 0;
raw_array[i++] = parm[1]; // Header mark if (count < 4) { // Protocol where 0 = t, 1 = 2t (RC5)
raw_array[i++] = parm[2]; // Header space // IRSend raw,0,889,0000100000000000000100000
for (; *p; *p++) { uint16_t mark = parm[1] *2;
if (*p == '0') { if (3 == count) { // Protocol where 0 = t1, 1 = t2 (Could be RC5)
raw_array[i++] = parm[3]; // Bit mark // IRSend raw,0,889,1778,0000100000000000000100000
raw_array[i++] = parm[4]; // Zero space mark = parm[2];
} }
else if (*p == '1') { for (; *p; *p++) {
raw_array[i++] = parm[3]; // Bit mark if (*p == '0') {
raw_array[i++] = parm[5]; // One space raw_array[i++] = parm[1]; // Space
}
else if (*p == '1') {
raw_array[i++] = mark; // Mark
}
} }
} }
raw_array[i++] = parm[3]; // Trailing mark else if (6 == count) { // NEC Protocol
irsend_active = true; // IRSend raw,0,8620,4260,544,411,1496,010101101000111011001110000000001100110000000001100000000000000010001100
irsend->sendRaw(raw_array, i, parm[0]); raw_array[i++] = parm[1]; // Header mark
raw_array[i++] = parm[2]; // Header space
for (; *p; *p++) {
if (*p == '0') {
raw_array[i++] = parm[3]; // Bit mark
raw_array[i++] = parm[4]; // Zero space
}
else if (*p == '1') {
raw_array[i++] = parm[3]; // Bit mark
raw_array[i++] = parm[5]; // One space
}
}
raw_array[i++] = parm[3]; // Trailing mark
}
else {
error = IE_INVALID_RAWDATA; // Invalid number of parameters
}
if (IE_NO_ERROR == error) {
irsend_active = true;
irsend->sendRaw(raw_array, i, parm[0]);
}
} }
} }
} else { } else {