diff --git a/HeatpumpIRFactory.cpp b/HeatpumpIRFactory.cpp index 80c10dc..eaed55e 100644 --- a/HeatpumpIRFactory.cpp +++ b/HeatpumpIRFactory.cpp @@ -79,6 +79,8 @@ HeatpumpIR* HeatpumpIRFactory::create(const char *modelName) { return new ToshibaDaiseikaiHeatpumpIR(); } else if (strcmp_P(modelName, PSTR("toshiba")) == 0) { return new ToshibaHeatpumpIR(); + } else if (strcmp_P(modelName, PSTR("ZHJG01")) == 0) { + return new ZHJG01HeatpumpIR(); } else if (strcmp_P(modelName, PSTR("ZHLT01")) == 0) { return new ZHLT01HeatpumpIR(); } diff --git a/HeatpumpIRFactory.h b/HeatpumpIRFactory.h index 147b70a..b96e187 100644 --- a/HeatpumpIRFactory.h +++ b/HeatpumpIRFactory.h @@ -27,6 +27,7 @@ #include #include #include +#include #include class HeatpumpIRFactory diff --git a/ZHJG01HeatpumpIR.cpp b/ZHJG01HeatpumpIR.cpp new file mode 100644 index 0000000..1a37066 --- /dev/null +++ b/ZHJG01HeatpumpIR.cpp @@ -0,0 +1,160 @@ +#include + +ZHJG01HeatpumpIR::ZHJG01HeatpumpIR() : HeatpumpIR() +{ + static const char model[] PROGMEM = "ZHJG01"; + static const char info[] PROGMEM = "{\"mdl\":\"ZHJG01\",\"dn\":\"ZHJG01\",\"mT\":18,\"xT\":32,\"fs\":3,\"maint\":[10]}}"; + + _model = model; + _info = info; +} + +void ZHJG01HeatpumpIR::send(IRSender& IR, + uint8_t powerModeCmd, + uint8_t operatingModeCmd, + uint8_t fanSpeedCmd, + uint8_t temperatureCmd, + uint8_t swingVCmd, + uint8_t swingHCmd) +{ + + uint8_t operatingMode = ZHJG01_MODE_AUTO; + uint8_t fanSpeed = ZHJG01_FAN_AUTO; + uint8_t temperature = 25; + uint8_t swingV = ZHJG01_VDIR_FIXED; + + uint8_t powerMode = powerModeCmd == 0 ? ZHJG01_POWER_OFF : ZHJG01_POWER_ON; + + switch (operatingModeCmd) + { + case MODE_COOL: + operatingMode = ZHJG01_MODE_COOL; + break; + case MODE_FAN: + operatingMode = ZHJG01_MODE_FAN; + break; + case MODE_DRY: + operatingMode = ZHJG01_MODE_DRY; + temperatureCmd = 25; + break; + case MODE_HEAT: + operatingMode = ZHJG01_MODE_HEAT; + break; + default: + operatingMode = ZHJG01_MODE_AUTO; + temperatureCmd = 25; + } + + switch (fanSpeedCmd) + { + case FAN_AUTO: + fanSpeed = ZHJG01_FAN_AUTO; + break; + case FAN_1: + fanSpeed = ZHJG01_FAN1; + break; + case FAN_2: + fanSpeed = ZHJG01_FAN2; + break; + case FAN_3: + fanSpeed = ZHJG01_FAN3; + break; + case FAN_4: + case FAN_5: + fanSpeed = ZHJG01_FAN_TURBO; + break; + case FAN_SILENT: + fanSpeed = ZHJG01_FAN_ECO; + break; + } + + switch (swingVCmd) + { + case VDIR_AUTO: + swingV = ZHJG01_VDIR_WIND; + break; + case VDIR_SWING: + swingV = ZHJG01_VDIR_SWING; + break; + default: + swingV = ZHJG01_VDIR_FIXED; + } + + // temperature must be between 17 and 32 degrees + if (temperatureCmd < 16) + { + temperature = 16; + } + else if (temperatureCmd > 32) + { + temperature = 32; + } else + { + temperature = temperatureCmd; + } + + sendZHJG01(IR, powerMode, operatingMode, fanSpeed, temperature, swingV); +} + +void ZHJG01HeatpumpIR::sendZHJG01(IRSender& IR, + uint8_t powerMode, + uint8_t operatingMode, + uint8_t fanSpeed, + uint8_t temperature, + uint8_t swingV) +{ + uint8_t ZHJG01Template[] = { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF }; + // Bytenumbers: 0 1 2 3 4 5 + +/******************************************************************************** + * Byte[0]: Turbo, Eco, Fan, Vertical Swing + * TURBO ON: B0x1xxxxx + * ECO ON: B0x0xxxxx + * TURBO/ECO OFF: B1xxxxxxx + * FAN1: Bx00xxxxx + * FAN2: Bx01xxxxx + * FAN3: Bx10xxxxx + * FAN AUTO: Bx11xxxxx + * VERTICAL FIXED: Bxxx01xxx + * VERTICAL SWING: Bxxx10xxx + * VERTICAL WIND: Bxxx11xxx + *******************************************************************************/ + ZHJG01Template[1] = fanSpeed | swingV; + ZHJG01Template[0] = ~ ZHJG01Template[1]; + +/******************************************************************************** + * Byte[2]: Temp, Power, Mode + * TEMP: Bttttxxxx + * POWER ON: Bxxxx0xxx + * POWER OFF: Bxxxx1xxx + * MODE HEAT: Bxxxxx011 + * MODE VENT: Bxxxxx100 + * MODE DRY: Bxxxxx101 + * MODE COOL: Bxxxxx110 + * MODE AUTO: Bxxxxx111 + *******************************************************************************/ + + uint8_t tempBits = ((temperature - 17) << 4) & 0b11110000; + ZHJG01Template[3] = tempBits | powerMode | operatingMode; + ZHJG01Template[2] = ~ ZHJG01Template[3]; + + + ZHJG01Template[5] = 0b11010101; // Undecoded (timer?) + ZHJG01Template[4] = ~ ZHJG01Template[5]; + + // 38 kHz PWM frequency + IR.setFrequency(38); + + // Header + IR.mark(ZHJG01_HDR_MARK); + IR.space(ZHJG01_HDR_SPACE); + + // Data + for (unsigned int i=0; i + +/******************************************************************************** + * TIMINGS + * Space: Not used + * Header Mark: 6550 us + * Header Space: 7755 us + * Bit Mark: 560 us + * Zero Space: 1530 us + * One Space: 3750 us + *******************************************************************************/ +#define ZHJG01_HDR_MARK 6550 +#define ZHJG01_HDR_SPACE 7755 +#define ZHJG01_BIT_MARK 560 +#define ZHJG01_ZERO_SPACE 1530 +#define ZHJG01_ONE_SPACE 3750 + +/******************************************************************************** + * + * ZHJG01 codes + * + *******************************************************************************/ + +// Power +#define ZHJG01_POWER_OFF 0x00 +#define ZHJG01_POWER_ON 0x08 + +// Operating Modes +#define ZHJG01_MODE_AUTO 0x00 +#define ZHJG01_MODE_COOL 0x01 +#define ZHJG01_MODE_DRY 0x02 +#define ZHJG01_MODE_FAN 0x03 +#define ZHJG01_MODE_HEAT 0x04 + +//Fan control +#define ZHJG01_FAN_AUTO 0x00 +#define ZHJG01_FAN1 0x60 +#define ZHJG01_FAN2 0x40 +#define ZHJG01_FAN3 0x20 +#define ZHJG01_FAN_TURBO 0x80 +#define ZHJG01_FAN_ECO 0xA0 +// FAN_4 and FAN_5 are not supported, but are implemented as button "TURBO" +// This only works for HEAT and COOL. Otherwise FAN_3 is used. +// FAN_SILENT is not supported, but is implmented as button "ECO". + +// Vertical Swing +#define ZHJG01_VDIR_WIND 0x00 // "Natural Wind", implemented on VDIR_AUTO +#define ZHJG01_VDIR_SWING 0x08 // Swing +#define ZHJG01_VDIR_FIXED 0x10 // All others are not supported + // and implemented as Fixed + +class ZHJG01HeatpumpIR : public HeatpumpIR +{ + public: + ZHJG01HeatpumpIR(); + void send(IRSender& IR, uint8_t powerModeCmd, + uint8_t operatingModeCmd, + uint8_t fanSpeedCmd, + uint8_t temperatureCmd, + uint8_t swingVCmd, + uint8_t swingHCmd); + + protected: + void sendZHJG01(IRSender& IR, uint8_t powerMode, + uint8_t operatingMode, + uint8_t fanSpeed, + uint8_t temperature, + uint8_t swingV); +}; + +#endif