From c10b2368314247899a024dc47533c8df4c2d6ce8 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 4 Aug 2019 12:37:01 +0200 Subject: [PATCH 1/2] Add allow repeat/longpress for IRSend raw, introduced IRSend option (#6074) --- sonoff/_changelog.ino | 1 + sonoff/xdrv_05_irremote.ino | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 61ddb795b..c45665e78 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -7,6 +7,7 @@ * Add MqttCount metric to STATE (#6155) * Add define USE_ENERGY_MARGIN_DETECTION to disable Energy Margin and Power Limit detection * Add define USE_ENERGY_POWER_LIMIT to disable Energy Power Limit detection while Energy Margin detection is active + * Add allow repeat/longpress for IRSend raw, introduced IRSend option (#6074) * * 6.6.0.2 20190714 * Change commands Var and Mem to show all parameters when no index is given (#6107) diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 1017cba7e..400020922 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -754,6 +754,9 @@ uint32_t IrRemoteCmndIrSendRaw(void) return IE_INVALID_RAWDATA; } + // repeat + uint16_t repeat = XdrvMailbox.index - 1; + uint16_t freq = atoi(str); if (!freq && (*str != '0')) { // First parameter is any string uint16_t count = 0; @@ -798,7 +801,9 @@ uint32_t IrRemoteCmndIrSendRaw(void) } } irsend_active = true; - irsend->sendRaw(raw_array, i, parm[0]); + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, i, parm[0]); + } } else if (6 == count) { // NEC Protocol // IRsend raw,0,8620,4260,544,411,1496,010101101000111011001110000000001100110000000001100000000000000010001100 @@ -817,7 +822,9 @@ uint32_t IrRemoteCmndIrSendRaw(void) } raw_array[i++] = parm[3]; // Trailing mark irsend_active = true; - irsend->sendRaw(raw_array, i, parm[0]); + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, i, parm[0]); + } } else { return IE_INVALID_RAWDATA; // Invalid number of parameters @@ -842,7 +849,9 @@ uint32_t IrRemoteCmndIrSendRaw(void) // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: stack count %d"), count); irsend_active = true; - irsend->sendRaw(raw_array, count, freq); + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, count, freq); + } } else { uint16_t *raw_array = reinterpret_cast(malloc(count * sizeof(uint16_t))); if (raw_array == nullptr) { @@ -856,7 +865,9 @@ uint32_t IrRemoteCmndIrSendRaw(void) // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: heap count %d"), count); irsend_active = true; - irsend->sendRaw(raw_array, count, freq); + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, count, freq); + } free(raw_array); } } @@ -890,6 +901,10 @@ uint32_t IrRemoteCmndIrSendJson(void) uint16_t bits = root[UpperCase_P(parm_uc, PSTR(D_JSON_IR_BITS))]; uint64_t data = strtoull(root[UpperCase_P(parm_uc, PSTR(D_JSON_IR_DATA))], nullptr, 0); uint16_t repeat = root[UpperCase_P(parm_uc, PSTR(D_JSON_IR_REPEAT))]; + // check if the IRSend is great than repeat + if (XdrvMailbox.index > repeat + 1) { + repeat = XdrvMailbox.index - 1; + } if (!(protocol && bits)) { return IE_SYNTAX_IRSEND; } From b56f0a6aa12616d83e6d0ff42a9e4cadd6ae873c Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 4 Aug 2019 12:45:17 +0200 Subject: [PATCH 2/2] IRSend handle index=0 --- sonoff/xdrv_05_irremote.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 400020922..a75efcbd4 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -755,7 +755,7 @@ uint32_t IrRemoteCmndIrSendRaw(void) } // repeat - uint16_t repeat = XdrvMailbox.index - 1; + uint16_t repeat = XdrvMailbox.index > 0 ? XdrvMailbox.index - 1 : 0; uint16_t freq = atoi(str); if (!freq && (*str != '0')) { // First parameter is any string