From 0df4a888d5bfc56e020cbc7a6c08e1089d1eaf8a Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Mon, 15 Jul 2019 09:22:07 +0200 Subject: [PATCH] Support IRSend long press ('repeat' feature from IRRemoteESP8266) (#6074) --- sonoff/_changelog.ino | 1 + sonoff/i18n.h | 1 + sonoff/xdrv_05_irremote.ino | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 64ddee9df..59831ab66 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -3,6 +3,7 @@ * Add support for Sonoff iFan03 as module 71 (#5988) * Add support for a buzzer * Add command SetOption67 0/1 to disable or enable a buzzer as used in iFan03 + * Add support IRSend long press ('repeat' feature from IRRemoteESP8266) (#6074) * * 6.6.0.1 20190708 * Fix Domoticz battery level set to 100 if define USE_ADC_VCC is not used (#6033) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index b049966f6..f72b2036b 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -374,6 +374,7 @@ #define D_JSON_IR_BITS "Bits" #define D_JSON_IR_DATA "Data" #define D_JSON_IR_RAWDATA "RawData" + #define D_JSON_IR_REPEAT "Repeat" #define D_CMND_IRHVAC "IRHVAC" #define D_JSON_IRHVAC_VENDOR "VENDOR" #define D_JSON_IRHVAC_POWER "POWER" diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 93bc3d6b3..5beb696a8 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -683,38 +683,39 @@ bool IrSendCommand(void) error = IE_INVALID_JSON; } else { // IRsend { "protocol": "SAMSUNG", "bits": 32, "data": 551502015 } + // IRsend { "protocol": "NEC", "bits": 32, "data":"0x02FDFE80", "repeat": 2 } char parm_uc[10]; const char *protocol = root[UpperCase_P(parm_uc, PSTR(D_JSON_IR_PROTOCOL))]; 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))]; if (protocol && bits) { char protocol_text[20]; int protocol_code = GetCommandCode(protocol_text, sizeof(protocol_text), protocol, kIrRemoteProtocols); char dvalue[64]; char hvalue[64]; - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("IRS: protocol_text %s, protocol %s, bits %d, data %s (%s), protocol_code %d"), - protocol_text, protocol, bits, ulltoa(data, dvalue, 10), IrUint64toHex(data, hvalue, bits), protocol_code); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("IRS: protocol_text %s, protocol %s, bits %d, data %s (%s), repeat %d, protocol_code %d"), + protocol_text, protocol, bits, ulltoa(data, dvalue, 10), IrUint64toHex(data, hvalue, bits), repeat, protocol_code); irsend_active = true; switch (protocol_code) { case NEC: - irsend->sendNEC(data, (bits > NEC_BITS) ? NEC_BITS : bits); break; + irsend->sendNEC(data, (bits > NEC_BITS) ? NEC_BITS : bits, repeat); break; case SONY: - irsend->sendSony(data, (bits > SONY_20_BITS) ? SONY_20_BITS : bits, 2); break; + irsend->sendSony(data, (bits > SONY_20_BITS) ? SONY_20_BITS : bits, repeat > kSonyMinRepeat ? repeat : kSonyMinRepeat); break; case RC5: - irsend->sendRC5(data, bits); break; + irsend->sendRC5(data, bits, repeat); break; case RC6: - irsend->sendRC6(data, bits); break; + irsend->sendRC6(data, bits, repeat); break; case DISH: - irsend->sendDISH(data, (bits > DISH_BITS) ? DISH_BITS : bits); break; + irsend->sendDISH(data, (bits > DISH_BITS) ? DISH_BITS : bits, repeat > kDishMinRepeat ? repeat : kDishMinRepeat); break; case JVC: - irsend->sendJVC(data, (bits > JVC_BITS) ? JVC_BITS : bits, 1); break; + irsend->sendJVC(data, (bits > JVC_BITS) ? JVC_BITS : bits, repeat > 1 ? repeat : 1); break; case SAMSUNG: - irsend->sendSAMSUNG(data, (bits > SAMSUNG_BITS) ? SAMSUNG_BITS : bits); break; + irsend->sendSAMSUNG(data, (bits > SAMSUNG_BITS) ? SAMSUNG_BITS : bits, repeat); break; case PANASONIC: -// irsend->sendPanasonic(bits, data); break; - irsend->sendPanasonic64(data, bits); break; + irsend->sendPanasonic64(data, bits, repeat); break; default: irsend_active = false; Response_P(S_JSON_COMMAND_SVALUE, command, D_JSON_PROTOCOL_NOT_SUPPORTED);