2017-02-14 13:27:08 +00:00
|
|
|
/*
|
2017-11-15 22:07:45 +00:00
|
|
|
xdrv_irremote.ino - infra red support for Sonoff-Tasmota
|
2017-02-14 13:27:08 +00:00
|
|
|
|
2017-12-22 13:55:24 +00:00
|
|
|
Copyright (C) 2018 Heiko Krupp, Lazar Obradovic and Theo Arends
|
2017-02-14 13:27:08 +00:00
|
|
|
|
2017-05-13 12:02:10 +01:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2017-02-14 13:27:08 +00:00
|
|
|
|
2017-05-13 12:02:10 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-02-14 13:27:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_IR_REMOTE
|
|
|
|
/*********************************************************************************************\
|
2017-10-06 16:28:00 +01:00
|
|
|
* IR Remote send and receive using IRremoteESP8266 library
|
2017-02-14 13:27:08 +00:00
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
#include <IRremoteESP8266.h>
|
2017-11-19 17:02:03 +00:00
|
|
|
|
|
|
|
// Based on IRremoteESP8266.h enum decode_type_t
|
|
|
|
const char kIrRemoteProtocols[] PROGMEM =
|
|
|
|
"UNKNOWN|RC5|RC6|NEC|SONY|PANASONIC|JVC|SAMSUNG|WHYNTER|AIWA_RC_T501|LG|SANYO|MITSUBISHI|DISH|SHARP";
|
|
|
|
|
|
|
|
#ifdef USE_IR_HVAC
|
|
|
|
|
|
|
|
#include <ir_Mitsubishi.h>
|
2017-10-08 15:51:05 +01:00
|
|
|
|
|
|
|
// HVAC TOSHIBA_
|
|
|
|
#define HVAC_TOSHIBA_HDR_MARK 4400
|
|
|
|
#define HVAC_TOSHIBA_HDR_SPACE 4300
|
|
|
|
#define HVAC_TOSHIBA_BIT_MARK 543
|
|
|
|
#define HVAC_TOSHIBA_ONE_SPACE 1623
|
|
|
|
#define HVAC_MISTUBISHI_ZERO_SPACE 472
|
|
|
|
#define HVAC_TOSHIBA_RPT_MARK 440
|
|
|
|
#define HVAC_TOSHIBA_RPT_SPACE 7048 // Above original iremote limit
|
|
|
|
#define HVAC_TOSHIBA_DATALEN 9
|
|
|
|
|
|
|
|
IRMitsubishiAC *mitsubir = NULL;
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
const char kFanSpeedOptions[] = "A12345S";
|
|
|
|
const char kHvacModeOptions[] = "HDCA";
|
2017-03-29 17:42:05 +01:00
|
|
|
#endif
|
2017-02-14 13:27:08 +00:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* IR Send
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2017-11-19 17:02:03 +00:00
|
|
|
#include <IRsend.h>
|
|
|
|
|
2017-02-14 13:27:08 +00:00
|
|
|
IRsend *irsend = NULL;
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
void IrSendInit(void)
|
2017-02-14 13:27:08 +00:00
|
|
|
{
|
2017-10-08 15:51:05 +01:00
|
|
|
irsend = new IRsend(pin[GPIO_IRSEND]); // an IR led is at GPIO_IRSEND
|
2017-02-14 13:27:08 +00:00
|
|
|
irsend->begin();
|
2017-03-29 17:42:05 +01:00
|
|
|
|
|
|
|
#ifdef USE_IR_HVAC
|
|
|
|
mitsubir = new IRMitsubishiAC(pin[GPIO_IRSEND]);
|
|
|
|
#endif //USE_IR_HVAC
|
2017-02-14 13:27:08 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 16:28:00 +01:00
|
|
|
#ifdef USE_IR_RECEIVE
|
2017-10-08 15:51:05 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* IR Receive
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2017-11-19 17:02:03 +00:00
|
|
|
#include <IRrecv.h>
|
2017-10-06 16:28:00 +01:00
|
|
|
|
2017-11-19 17:02:03 +00:00
|
|
|
#define IR_TIME_AVOID_DUPLICATE 500 // Milliseconds
|
2017-10-25 13:27:30 +01:00
|
|
|
|
2017-10-06 16:28:00 +01:00
|
|
|
IRrecv *irrecv = NULL;
|
|
|
|
unsigned long ir_lasttime = 0;
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
void IrReceiveInit(void)
|
2017-10-06 16:28:00 +01:00
|
|
|
{
|
2017-10-08 15:51:05 +01:00
|
|
|
irrecv = new IRrecv(pin[GPIO_IRRECV]); // an IR led is at GPIO_IRRECV
|
|
|
|
irrecv->enableIRIn(); // Start the receiver
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("IrReceive initialized"));
|
2017-10-06 16:28:00 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
void IrReceiveCheck()
|
2017-10-08 15:51:05 +01:00
|
|
|
{
|
2017-10-29 17:18:46 +00:00
|
|
|
char sirtype[14]; // Max is AIWA_RC_T501
|
2017-10-08 15:51:05 +01:00
|
|
|
int8_t iridx = 0;
|
2017-02-14 13:27:08 +00:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
decode_results results;
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
if (irrecv->decode(&results)) {
|
2017-02-17 16:18:41 +00:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_IRR "RawLen %d, Bits %d, Value %08X, Decode %d"),
|
|
|
|
results.rawlen, results.bits, results.value, results.decode_type);
|
2017-10-18 17:22:34 +01:00
|
|
|
AddLog(LOG_LEVEL_DEBUG);
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
unsigned long now = millis();
|
|
|
|
if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) {
|
|
|
|
ir_lasttime = now;
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
iridx = results.decode_type;
|
|
|
|
if ((iridx < 0) || (iridx > 14)) {
|
|
|
|
iridx = 0;
|
2017-02-14 13:27:08 +00:00
|
|
|
}
|
2017-11-11 11:33:30 +00:00
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_IRRECEIVED "\":{\"" D_IR_PROTOCOL "\":\"%s\",\"" D_IR_BITS "\":%d,\"" D_IR_DATA "\":\"%X\"}}"),
|
2017-10-29 17:18:46 +00:00
|
|
|
GetTextIndexed(sirtype, sizeof(sirtype), iridx, kIrRemoteProtocols), results.bits, results.value);
|
2017-10-18 17:22:34 +01:00
|
|
|
MqttPublishPrefixTopic_P(6, PSTR(D_IRRECEIVED));
|
2017-10-08 15:51:05 +01:00
|
|
|
#ifdef USE_DOMOTICZ
|
2017-10-25 13:27:30 +01:00
|
|
|
unsigned long value = results.value | (iridx << 28); // [Protocol:4, Data:28]
|
|
|
|
DomoticzSensor(DZ_COUNT, value); // Send data as Domoticz Counter value
|
2017-10-10 14:40:02 +01:00
|
|
|
#endif // USE_DOMOTICZ
|
2017-04-25 17:24:42 +01:00
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
|
|
|
|
irrecv->resume();
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
2017-02-14 13:27:08 +00:00
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
#endif // USE_IR_RECEIVE
|
2017-03-29 17:42:05 +01:00
|
|
|
|
|
|
|
#ifdef USE_IR_HVAC
|
2017-10-08 15:51:05 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
|
2017-03-29 17:42:05 +01:00
|
|
|
{
|
2017-11-19 17:02:03 +00:00
|
|
|
uint16_t rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2];
|
2017-10-08 15:51:05 +01:00
|
|
|
byte data[HVAC_TOSHIBA_DATALEN] = {0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00};
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-04-25 17:24:42 +01:00
|
|
|
char *p;
|
|
|
|
char *token;
|
2017-04-03 15:38:15 +01:00
|
|
|
uint8_t mode;
|
|
|
|
|
|
|
|
if (HVAC_Mode == NULL) {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = (char *)kHvacModeOptions; // default HVAC_HOT
|
2017-10-08 15:51:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0]));
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
2017-04-25 17:24:42 +01:00
|
|
|
if (!p) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
data[6] = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-04-25 17:24:42 +01:00
|
|
|
if (!HVAC_Power) {
|
2017-10-08 15:51:05 +01:00
|
|
|
data[6] = (byte)0x07; // Turn OFF HVAC
|
2017-04-25 17:24:42 +01:00
|
|
|
}
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-04-03 15:38:15 +01:00
|
|
|
if (HVAC_FanMode == NULL) {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO
|
2017-10-08 15:51:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0]));
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
2017-04-25 17:24:42 +01:00
|
|
|
if (!p) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
mode = p - kFanSpeedOptions + 1;
|
2017-04-25 17:24:42 +01:00
|
|
|
if ((1 == mode) || (7 == mode)) {
|
|
|
|
mode = 0;
|
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
mode = mode << 5; // AUTO = 0x00, SPEED = 0x40, 0x60, 0x80, 0xA0, 0xC0, SILENT = 0x00
|
2017-04-03 15:38:15 +01:00
|
|
|
data[6] = data[6] | mode;
|
2017-03-29 17:42:05 +01:00
|
|
|
|
|
|
|
byte Temp;
|
|
|
|
if (HVAC_Temp > 30) {
|
|
|
|
Temp = 30;
|
|
|
|
}
|
|
|
|
else if (HVAC_Temp < 17) {
|
|
|
|
Temp = 17;
|
|
|
|
}
|
2017-04-25 17:24:42 +01:00
|
|
|
else {
|
|
|
|
Temp = HVAC_Temp;
|
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
data[5] = (byte)Temp - 17 << 4;
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
data[HVAC_TOSHIBA_DATALEN - 1] = 0;
|
2017-03-29 17:42:05 +01:00
|
|
|
for (int x = 0; x < HVAC_TOSHIBA_DATALEN - 1; x++) {
|
2017-10-08 15:51:05 +01:00
|
|
|
data[HVAC_TOSHIBA_DATALEN - 1] = (byte)data[x] ^ data[HVAC_TOSHIBA_DATALEN - 1]; // CRC is a simple bits addition
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
byte mask = 1;
|
|
|
|
|
|
|
|
//header
|
|
|
|
rawdata[i++] = HVAC_TOSHIBA_HDR_MARK;
|
|
|
|
rawdata[i++] = HVAC_TOSHIBA_HDR_SPACE;
|
|
|
|
|
|
|
|
//data
|
|
|
|
for (int b = 0; b < HVAC_TOSHIBA_DATALEN; b++) {
|
|
|
|
for (mask = B10000000; mask > 0; mask >>= 1) { //iterate through bit mask
|
|
|
|
if (data[b] & mask) { // Bit ONE
|
|
|
|
rawdata[i++] = HVAC_TOSHIBA_BIT_MARK;
|
|
|
|
rawdata[i++] = HVAC_TOSHIBA_ONE_SPACE;
|
|
|
|
}
|
|
|
|
else { // Bit ZERO
|
|
|
|
rawdata[i++] = HVAC_TOSHIBA_BIT_MARK;
|
|
|
|
rawdata[i++] = HVAC_MISTUBISHI_ZERO_SPACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//trailer
|
|
|
|
rawdata[i++] = HVAC_TOSHIBA_RPT_MARK;
|
|
|
|
rawdata[i++] = HVAC_TOSHIBA_RPT_SPACE;
|
|
|
|
|
|
|
|
noInterrupts();
|
2017-10-08 15:51:05 +01:00
|
|
|
irsend->sendRaw(rawdata, i, 38);
|
|
|
|
irsend->sendRaw(rawdata, i, 38);
|
2017-03-29 17:42:05 +01:00
|
|
|
interrupts();
|
|
|
|
|
2017-04-03 15:38:15 +01:00
|
|
|
return false;
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
|
2017-03-29 17:42:05 +01:00
|
|
|
{
|
2017-04-25 17:24:42 +01:00
|
|
|
char *p;
|
|
|
|
char *token;
|
2017-04-03 15:38:15 +01:00
|
|
|
uint8_t mode;
|
2017-09-02 13:37:02 +01:00
|
|
|
|
2017-03-29 17:42:05 +01:00
|
|
|
mitsubir->stateReset();
|
2017-04-03 15:38:15 +01:00
|
|
|
|
|
|
|
if (HVAC_Mode == NULL) {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = (char *)kHvacModeOptions; // default HVAC_HOT
|
2017-10-08 15:51:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0]));
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
2017-04-25 17:24:42 +01:00
|
|
|
if (!p) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
mode = (p - kHvacModeOptions + 1) << 3; // HOT = 0x08, DRY = 0x10, COOL = 0x18, AUTO = 0x20
|
2017-04-03 15:38:15 +01:00
|
|
|
mitsubir->setMode(mode);
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-08-16 16:05:36 +01:00
|
|
|
mitsubir->setPower(HVAC_Power);
|
2017-03-29 17:42:05 +01:00
|
|
|
|
2017-04-03 15:38:15 +01:00
|
|
|
if (HVAC_FanMode == NULL) {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO
|
2017-10-08 15:51:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-10-18 17:22:34 +01:00
|
|
|
p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0]));
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
2017-04-25 17:24:42 +01:00
|
|
|
if (!p) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
mode = p - kFanSpeedOptions; // AUTO = 0, SPEED = 1 .. 5, SILENT = 6
|
2017-04-03 15:38:15 +01:00
|
|
|
mitsubir->setFan(mode);
|
2017-03-29 17:42:05 +01:00
|
|
|
|
|
|
|
mitsubir->setTemp(HVAC_Temp);
|
|
|
|
mitsubir->setVane(MITSUBISHI_AC_VANE_AUTO);
|
|
|
|
mitsubir->send();
|
2017-09-02 13:37:02 +01:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: Mitsubishi Power %d, Mode %d, FanSpeed %d, Temp %d, VaneMode %d"),
|
|
|
|
// mitsubir->getPower(), mitsubir->getMode(), mitsubir->getFan(), mitsubir->getTemp(), mitsubir->getVane());
|
2017-10-18 17:22:34 +01:00
|
|
|
// AddLog(LOG_LEVEL_DEBUG);
|
2017-09-02 13:37:02 +01:00
|
|
|
|
2017-04-03 15:38:15 +01:00
|
|
|
return false;
|
2017-03-29 17:42:05 +01:00
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
#endif // USE_IR_HVAC
|
2017-10-06 16:28:00 +01:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Commands
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(3) + 40 = 96
|
|
|
|
IRsend:
|
|
|
|
{ "protocol": "SAMSUNG", "bits": 32, "data": 551502015 }
|
|
|
|
|
|
|
|
IRhvac:
|
|
|
|
{ "Vendor": "<Toshiba|Mitsubishi>", "Power": <0|1>, "Mode": "<Hot|Cold|Dry|Auto>", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> }
|
|
|
|
*/
|
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
boolean IrSendCommand(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
2017-10-06 16:28:00 +01:00
|
|
|
{
|
2017-10-08 15:51:05 +01:00
|
|
|
boolean serviced = true;
|
|
|
|
boolean error = false;
|
|
|
|
char dataBufUc[data_len];
|
2017-10-29 17:18:46 +00:00
|
|
|
char protocol_text[20];
|
2017-10-08 15:51:05 +01:00
|
|
|
const char *protocol;
|
2017-10-26 15:33:33 +01:00
|
|
|
uint32_t bits = 0;
|
2017-10-08 15:51:05 +01:00
|
|
|
uint32_t data = 0;
|
2017-10-06 16:28:00 +01:00
|
|
|
|
2017-10-08 15:51:05 +01:00
|
|
|
const char *HVAC_Mode;
|
|
|
|
const char *HVAC_FanMode;
|
|
|
|
const char *HVAC_Vendor;
|
|
|
|
int HVAC_Temp = 21;
|
|
|
|
boolean HVAC_Power = true;
|
|
|
|
|
|
|
|
for (uint16_t i = 0; i <= sizeof(dataBufUc); i++) {
|
|
|
|
dataBufUc[i] = toupper(dataBuf[i]);
|
|
|
|
}
|
|
|
|
if (!strcasecmp_P(type, PSTR(D_CMND_IRSEND))) {
|
|
|
|
if (data_len) {
|
|
|
|
StaticJsonBuffer<128> jsonBuf;
|
|
|
|
JsonObject &ir_json = jsonBuf.parseObject(dataBufUc);
|
|
|
|
if (!ir_json.success()) {
|
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
|
2017-10-06 16:28:00 +01:00
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
else {
|
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_DONE "\"}"));
|
|
|
|
protocol = ir_json[D_IR_PROTOCOL];
|
|
|
|
bits = ir_json[D_IR_BITS];
|
|
|
|
data = ir_json[D_IR_DATA];
|
|
|
|
if (protocol && bits && data) {
|
2017-10-29 17:18:46 +00:00
|
|
|
int protocol_code = GetCommandCode(protocol_text, sizeof(protocol_text), protocol, kIrRemoteProtocols);
|
|
|
|
switch (protocol_code) {
|
|
|
|
case NEC:
|
|
|
|
irsend->sendNEC(data, bits); break;
|
|
|
|
case SONY:
|
|
|
|
irsend->sendSony(data, bits); break;
|
|
|
|
case RC5:
|
|
|
|
irsend->sendRC5(data, bits); break;
|
|
|
|
case RC6:
|
|
|
|
irsend->sendRC6(data, bits); break;
|
|
|
|
case DISH:
|
|
|
|
irsend->sendDISH(data, bits); break;
|
|
|
|
case JVC:
|
|
|
|
irsend->sendJVC(data, bits, 1); break;
|
|
|
|
case SAMSUNG:
|
|
|
|
irsend->sendSAMSUNG(data, bits); break;
|
|
|
|
case PANASONIC:
|
|
|
|
irsend->sendPanasonic(bits, data); break;
|
|
|
|
default:
|
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_PROTOCOL_NOT_SUPPORTED "\"}"));
|
2017-10-08 15:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
error = true;
|
|
|
|
}
|
2017-10-06 16:28:00 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRSEND "\":\"" D_NO " " D_IR_PROTOCOL ", " D_IR_BITS " " D_OR " " D_IR_DATA "\"}"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef USE_IR_HVAC
|
|
|
|
else if (!strcasecmp_P(type, PSTR(D_CMND_IRHVAC))) {
|
|
|
|
if (data_len) {
|
|
|
|
StaticJsonBuffer<164> jsonBufer;
|
|
|
|
JsonObject &root = jsonBufer.parseObject(dataBufUc);
|
|
|
|
if (!root.success()) {
|
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_INVALID_JSON "\"}")); // JSON decode failed
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_DONE "\"}"));
|
|
|
|
HVAC_Vendor = root[D_IRHVAC_VENDOR];
|
|
|
|
HVAC_Power = root[D_IRHVAC_POWER];
|
|
|
|
HVAC_Mode = root[D_IRHVAC_MODE];
|
|
|
|
HVAC_FanMode = root[D_IRHVAC_FANSPEED];
|
|
|
|
HVAC_Temp = root[D_IRHVAC_TEMP];
|
|
|
|
|
|
|
|
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: Received Vendor %s, Power %d, Mode %s, FanSpeed %s, Temp %d"),
|
|
|
|
// HVAC_Vendor, HVAC_Power, HVAC_Mode, HVAC_FanMode, HVAC_Temp);
|
2017-10-18 17:22:34 +01:00
|
|
|
// AddLog(LOG_LEVEL_DEBUG);
|
2017-10-08 15:51:05 +01:00
|
|
|
|
|
|
|
if (HVAC_Vendor == NULL || !strcasecmp_P(HVAC_Vendor, PSTR("TOSHIBA"))) {
|
2017-10-18 17:22:34 +01:00
|
|
|
error = IrHvacToshiba(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
|
2017-10-08 15:51:05 +01:00
|
|
|
}
|
|
|
|
else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) {
|
2017-10-18 17:22:34 +01:00
|
|
|
error = IrHvacMitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
|
2017-10-08 15:51:05 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_IRHVAC "\":\"" D_WRONG " " D_IRHVAC_VENDOR ", " D_IRHVAC_MODE " " D_OR " " D_IRHVAC_FANSPEED "\"}"));
|
|
|
|
}
|
2017-10-06 16:28:00 +01:00
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
#endif // USE_IR_HVAC
|
|
|
|
else {
|
|
|
|
serviced = false; // Unknown command
|
|
|
|
}
|
|
|
|
return serviced;
|
2017-10-06 16:28:00 +01:00
|
|
|
}
|
2017-10-08 15:51:05 +01:00
|
|
|
#endif // USE_IR_REMOTE
|