# IRremoteESP8266: src/ir_Goodweather.h Source File

ir_Goodweather.h
Go to the documentation of this file.
// Copyright 2019 ribeirodanielf
// Copyright 2019 David Conran
// Supports:
// Brand: Goodweather, Model: ZH/JT-03 remote
#ifndef IR_GOODWEATHER_H_
#define IR_GOODWEATHER_H_
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include "IRremoteESP8266.h"
#include "IRsend.h"
#ifdef UNIT_TEST
#include "IRsend_test.h"
#endif
union GoodweatherProtocol {
uint64_t raw;
struct {
// Byte 0
uint8_t :8;
// Byte 1
uint8_t Light :1;
uint8_t :2;
uint8_t Turbo :1;
uint8_t :0;
// Byte 2
uint8_t Command :4;
uint8_t :0;
// Byte 3
uint8_t Sleep :1;
uint8_t Power :1;
uint8_t Swing :2;
uint8_t AirFlow :1;
uint8_t Fan :2;
uint8_t :0;
// Byte 4
uint8_t Temp :4;
uint8_t :1;
uint8_t Mode :3;
uint8_t :0;
};
};
// Constants
// Timing
const uint16_t kGoodweatherBitMark = 580;
const uint16_t kGoodweatherOneSpace = 580;
const uint16_t kGoodweatherZeroSpace = 1860;
const uint16_t kGoodweatherHdrMark = 6820;
const uint16_t kGoodweatherHdrSpace = 6820;
const uint8_t kGoodweatherExtraTolerance = 12; // +12% extra
// Modes
const uint8_t kGoodweatherAuto = 0b000;
const uint8_t kGoodweatherCool = 0b001;
const uint8_t kGoodweatherDry = 0b010;
const uint8_t kGoodweatherFan = 0b011;
const uint8_t kGoodweatherHeat = 0b100;
// Swing
const uint8_t kGoodweatherSwingFast = 0b00;
const uint8_t kGoodweatherSwingSlow = 0b01;
const uint8_t kGoodweatherSwingOff = 0b10;
// Fan Control
const uint8_t kGoodweatherFanAuto = 0b00;
const uint8_t kGoodweatherFanHigh = 0b01;
const uint8_t kGoodweatherFanMed = 0b10;
const uint8_t kGoodweatherFanLow = 0b11;
// Temperature
const uint8_t kGoodweatherTempMin = 16; // Celsius
const uint8_t kGoodweatherTempMax = 31; // Celsius
// Commands
const uint8_t kGoodweatherCmdPower = 0x00;
const uint8_t kGoodweatherCmdMode = 0x01;
const uint8_t kGoodweatherCmdUpTemp = 0x02;
const uint8_t kGoodweatherCmdDownTemp = 0x03;
const uint8_t kGoodweatherCmdSwing = 0x04;
const uint8_t kGoodweatherCmdFan = 0x05;
const uint8_t kGoodweatherCmdTimer = 0x06;
const uint8_t kGoodweatherCmdAirFlow = 0x07;
const uint8_t kGoodweatherCmdHold = 0x08;
const uint8_t kGoodweatherCmdSleep = 0x09;
const uint8_t kGoodweatherCmdTurbo = 0x0A;
const uint8_t kGoodweatherCmdLight = 0x0B;
// PAD EOF
const uint64_t kGoodweatherStateInit = 0xD50000000000;
// Classes
class IRGoodweatherAc {
public:
explicit IRGoodweatherAc(const uint16_t pin, const bool inverted = false,
const bool use_modulation = true);
void stateReset(void);
#if SEND_GOODWEATHER
void send(const uint16_t repeat = kGoodweatherMinRepeat);
int8_t calibrate(void) { return _irsend.calibrate(); }
#endif // SEND_GOODWEATHER
void begin(void);
void on(void);
void off(void);
void setPower(const bool on);
bool getPower(void) const;
void setTemp(const uint8_t temp);
uint8_t getTemp(void) const;
void setFan(const uint8_t speed);
uint8_t getFan(void) const;
void setMode(const uint8_t mode);
uint8_t getMode(void) const;
void setSwing(const uint8_t speed);
uint8_t getSwing(void) const;
void setSleep(const bool toggle);
bool getSleep(void) const;
void setTurbo(const bool toggle);
bool getTurbo(void) const;
void setLight(const bool toggle);
bool getLight(void) const;
void setCommand(const uint8_t cmd);
uint8_t getCommand(void) const;
uint64_t getRaw(void);
void setRaw(const uint64_t state);
static uint8_t convertMode(const stdAc::opmode_t mode);
static uint8_t convertFan(const stdAc::fanspeed_t speed);
static uint8_t convertSwingV(const stdAc::swingv_t swingv);
static stdAc::opmode_t toCommonMode(const uint8_t mode);
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
stdAc::state_t toCommon(void) const;
String toString(void) const;
#ifndef UNIT_TEST
private:
IRsend _irsend;
#else // UNIT_TEST
IRsendTest _irsend;
#endif // UNIT_TEST
GoodweatherProtocol _;
};
#endif // IR_GOODWEATHER_H_
kGoodweatherCmdLight
const uint8_t kGoodweatherCmdLight
Definition: ir_Goodweather.h:93
GoodweatherProtocol::Power
uint8_t Power
Definition: ir_Goodweather.h:41
kGoodweatherCmdDownTemp
const uint8_t kGoodweatherCmdDownTemp
Definition: ir_Goodweather.h:85
IRGoodweatherAc::off
void off(void)
Change the power setting to Off.
Definition: ir_Goodweather.cpp:94
IRGoodweatherAc::on
void on(void)
Change the power setting to On.
Definition: ir_Goodweather.cpp:91
kGoodweatherOneSpace
const uint16_t kGoodweatherOneSpace
Definition: ir_Goodweather.h:57
IRGoodweatherAc::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Goodweather.cpp:69
GoodweatherProtocol::Sleep
uint8_t Sleep
Definition: ir_Goodweather.h:40
kGoodweatherTempMin
const uint8_t kGoodweatherTempMin
Definition: ir_Goodweather.h:79
IRGoodweatherAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Goodweather.h:146
kGoodweatherCmdPower
const uint8_t kGoodweatherCmdPower
Definition: ir_Goodweather.h:82
stdAc::swingv_t
swingv_t
Common A/C settings for Vertical Swing.
Definition: IRsend.h:70
kGoodweatherCmdAirFlow
const uint8_t kGoodweatherCmdAirFlow
Definition: ir_Goodweather.h:89
IRGoodweatherAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Goodweather.cpp:143
GoodweatherProtocol
Native representation of a Goodweather A/C message.
Definition: ir_Goodweather.h:26
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRGoodweatherAc::getLight
bool getLight(void) const
Get the Light (LED) Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:179
IRGoodweatherAc::setTurbo
void setTurbo(const bool toggle)
Set the Turbo Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:198
IRGoodweatherAc::setLight
void setLight(const bool toggle)
Set the Light (LED) Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:172
IRGoodweatherAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Goodweather.cpp:121
IRsend.h
kGoodweatherCmdSwing
const uint8_t kGoodweatherCmdSwing
Definition: ir_Goodweather.h:86
kGoodweatherFanMed
const uint8_t kGoodweatherFanMed
Definition: ir_Goodweather.h:76
IRGoodweatherAc::convertSwingV
static uint8_t convertSwingV(const stdAc::swingv_t swingv)
Convert a stdAc::swingv_t enum into it's native setting.
Definition: ir_Goodweather.cpp:273
kGoodweatherCmdUpTemp
const uint8_t kGoodweatherCmdUpTemp
Definition: ir_Goodweather.h:84
kGoodweatherHdrSpace
const uint16_t kGoodweatherHdrSpace
Definition: ir_Goodweather.h:60
IRGoodweatherAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Goodweather.h:111
GoodweatherProtocol::Turbo
uint8_t Turbo
Definition: ir_Goodweather.h:34
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:182
kGoodweatherFanAuto
const uint8_t kGoodweatherFanAuto
Definition: ir_Goodweather.h:74
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRGoodweatherAc::IRGoodweatherAc
IRGoodweatherAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Goodweather.cpp:64
kGoodweatherZeroSpace
const uint16_t kGoodweatherZeroSpace
Definition: ir_Goodweather.h:58
IRGoodweatherAc::setRaw
void setRaw(const uint64_t state)
Set the internal state from a valid code for this protocol.
Definition: ir_Goodweather.cpp:88
IRGoodweatherAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Goodweather.cpp:166
GoodweatherProtocol::Swing
uint8_t Swing
Definition: ir_Goodweather.h:42
kGoodweatherAuto
const uint8_t kGoodweatherAuto
Definition: ir_Goodweather.h:64
String
std::string String
Definition: IRremoteESP8266.h:1178
IRGoodweatherAc::send
void send(const uint16_t repeat=kGoodweatherMinRepeat)
Send the current internal state as an IR message.
Definition: ir_Goodweather.cpp:77
IRGoodweatherAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Goodweather.cpp:288
kGoodweatherExtraTolerance
const uint8_t kGoodweatherExtraTolerance
Definition: ir_Goodweather.h:61
IRGoodweatherAc::getCommand
uint8_t getCommand(void) const
Get the Command type/button pressed from the current settings.
Definition: ir_Goodweather.cpp:239
kGoodweatherSwingSlow
const uint8_t kGoodweatherSwingSlow
Definition: ir_Goodweather.h:71
IRremoteESP8266.h
kGoodweatherSwingOff
const uint8_t kGoodweatherSwingOff
Definition: ir_Goodweather.h:72
kGoodweatherDry
const uint8_t kGoodweatherDry
Definition: ir_Goodweather.h:66
IRGoodweatherAc::getSwing
uint8_t getSwing(void) const
Get the Vertical Swing speed of the A/C.
Definition: ir_Goodweather.cpp:226
kGoodweatherSwingFast
const uint8_t kGoodweatherSwingFast
Definition: ir_Goodweather.h:70
kGoodweatherCmdSleep
const uint8_t kGoodweatherCmdSleep
Definition: ir_Goodweather.h:91
IRGoodweatherAc::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Goodweather.cpp:312
kGoodweatherCool
const uint8_t kGoodweatherCool
Definition: ir_Goodweather.h:65
IRGoodweatherAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Goodweather.cpp:111
IRGoodweatherAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Goodweather.cpp:72
kGoodweatherCmdFan
const uint8_t kGoodweatherCmdFan
Definition: ir_Goodweather.h:87
IRGoodweatherAc::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Goodweather.cpp:105
kGoodweatherCmdHold
const uint8_t kGoodweatherCmdHold
Definition: ir_Goodweather.h:90
GoodweatherProtocol::Mode
uint8_t Mode
Definition: ir_Goodweather.h:49
IRGoodweatherAc::setSwing
void setSwing(const uint8_t speed)
Set the Vertical Swing speed of the A/C.
Definition: ir_Goodweather.cpp:211
kGoodweatherFan
const uint8_t kGoodweatherFan
Definition: ir_Goodweather.h:67
kGoodweatherCmdTurbo
const uint8_t kGoodweatherCmdTurbo
Definition: ir_Goodweather.h:92
IRGoodweatherAc::setCommand
void setCommand(const uint8_t cmd)
Set the remote Command type/button pressed.
Definition: ir_Goodweather.cpp:232
GoodweatherProtocol::Light
uint8_t Light
Definition: ir_Goodweather.h:32
GoodweatherProtocol::Command
uint8_t Command
Definition: ir_Goodweather.h:37
kGoodweatherStateInit
const uint64_t kGoodweatherStateInit
Definition: ir_Goodweather.h:95
kGoodweatherCmdTimer
const uint8_t kGoodweatherCmdTimer
Definition: ir_Goodweather.h:88
GoodweatherProtocol::Temp
uint8_t Temp
Definition: ir_Goodweather.h:47
IRGoodweatherAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Goodweather.cpp:149
IRGoodweatherAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Goodweather.cpp:339
IRGoodweatherAc::getTurbo
bool getTurbo(void) const
Get the Turbo Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:205
kGoodweatherTempMax
const uint8_t kGoodweatherTempMax
Definition: ir_Goodweather.h:80
IRGoodweatherAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Goodweather.cpp:301
kGoodweatherFanLow
const uint8_t kGoodweatherFanLow
Definition: ir_Goodweather.h:77
IRGoodweatherAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Goodweather.cpp:127
kGoodweatherHeat
const uint8_t kGoodweatherHeat
Definition: ir_Goodweather.h:68
kGoodweatherBitMark
const uint16_t kGoodweatherBitMark
Definition: ir_Goodweather.h:56
IRGoodweatherAc::getSleep
bool getSleep(void) const
Get the Sleep Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:192
kGoodweatherFanHigh
const uint8_t kGoodweatherFanHigh
Definition: ir_Goodweather.h:75
IRGoodweatherAc::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Goodweather.cpp:259
IRGoodweatherAc::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Goodweather.cpp:246
GoodweatherProtocol::raw
uint64_t raw
The state of the IR remote in IR code form.
Definition: ir_Goodweather.h:27
kGoodweatherHdrMark
const uint16_t kGoodweatherHdrMark
Definition: ir_Goodweather.h:59
GoodweatherProtocol::AirFlow
uint8_t AirFlow
Definition: ir_Goodweather.h:43
IRGoodweatherAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Goodweather.cpp:98
IRGoodweatherAc::setSleep
void setSleep(const bool toggle)
Set the Sleep Toggle setting of the A/C.
Definition: ir_Goodweather.cpp:185
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRGoodweatherAc
Class for handling detailed Goodweather A/C messages.
Definition: ir_Goodweather.h:100
IRGoodweatherAc::_
GoodweatherProtocol _
Definition: ir_Goodweather.h:152
GoodweatherProtocol::Fan
uint8_t Fan
Definition: ir_Goodweather.h:44
IRGoodweatherAc::getRaw
uint64_t getRaw(void)
Get a copy of the internal state as a valid code for this protocol.
Definition: ir_Goodweather.cpp:84
kGoodweatherMinRepeat
const uint16_t kGoodweatherMinRepeat
Definition: IRremoteESP8266.h:951
kGoodweatherCmdMode
const uint8_t kGoodweatherCmdMode
Definition: ir_Goodweather.h:83
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46