IRremoteESP8266

ir_Electra.h
Go to the documentation of this file.
1 // Copyright 2019-2021 David Conran
5
6 // Supports:
7 // Brand: AUX, Model: KFR-35GW/BpNFW=3 A/C
8 // Brand: AUX, Model: YKR-T/011 remote
9 // Brand: Electra, Model: Classic INV 17 / AXW12DCS A/C
10 // Brand: Electra, Model: YKR-M/003E remote
11 // Brand: Frigidaire, Model: FGPC102AB1 A/C
12 // Brand: Subtropic, Model: SUB-07HN1_18Y A/C
13 // Brand: Subtropic, Model: YKR-H/102E remote
14 // Brand: Centek, Model: SCT-65Q09 A/C
15 // Brand: Centek, Model: YKR-P/002E remote
16 // Brand: AEG, Model: Chillflex Pro AXP26U338CW A/C
17 // Brand: Electrolux, Model: YKR-H/531E A/C
18
19 #ifndef IR_ELECTRA_H_
20 #define IR_ELECTRA_H_
21
22 #define __STDC_LIMIT_MACROS
23 #include <stdint.h>
24 #ifndef UNIT_TEST
25 #include <Arduino.h>
26 #endif
27 #include "IRremoteESP8266.h"
28 #include "IRsend.h"
29 #ifdef UNIT_TEST
30 #include "IRsend_test.h"
31 #endif
32
34 union ElectraProtocol {
35 uint8_t raw[kElectraAcStateLength];
36 struct {
37 // Byte 0
38 uint8_t :8;
39 // Byte 1
40 uint8_t SwingV :3;
41 uint8_t Temp :5;
42 // Byte 2
43 uint8_t :5;
44 uint8_t SwingH :3;
45 // Byte 3
46 uint8_t :6;
47 uint8_t SensorUpdate :1;
48 uint8_t :1;
49 // Byte 4
50 uint8_t :5;
51 uint8_t Fan :3;
52 // Byte 5
53 uint8_t :6;
54 uint8_t Turbo :1;
55 uint8_t :1;
56 // Byte 6
57 uint8_t :3;
58 uint8_t IFeel :1;
59 uint8_t :1;
60 uint8_t Mode :3;
61 // Byte 7
62 uint8_t SensorTemp :8;
63 // Byte 8
64 uint8_t :8;
65 // Byte 9
66 uint8_t :2;
67 uint8_t Clean :1;
68 uint8_t :2;
69 uint8_t Power :1;
70 uint8_t :2;
71 // Byte 10
72 uint8_t :8;
73 // Byte 11
74 uint8_t LightToggle :8;
75 // Byte 12
76 uint8_t Sum :8;
77 };
78 };
79
80 // Constants
81 const uint8_t kElectraAcMinTemp = 16; // 16C
82 const uint8_t kElectraAcMaxTemp = 32; // 32C
83 const uint8_t kElectraAcTempDelta = 8;
84 const uint8_t kElectraAcSwingOn = 0b000;
85 const uint8_t kElectraAcSwingOff = 0b111;
86
87 const uint8_t kElectraAcFanAuto = 0b101;
88 const uint8_t kElectraAcFanLow = 0b011;
89 const uint8_t kElectraAcFanMed = 0b010;
90 const uint8_t kElectraAcFanHigh = 0b001;
91
92 const uint8_t kElectraAcAuto = 0b000;
93 const uint8_t kElectraAcCool = 0b001;
94 const uint8_t kElectraAcDry = 0b010;
95 const uint8_t kElectraAcHeat = 0b100;
96 const uint8_t kElectraAcFan = 0b110;
97
98 const uint8_t kElectraAcLightToggleOn = 0x15;
99 // Light has known ON values of 0x15 (0b00010101) or 0x19 (0b00011001)
100 // Thus common bits ON are: 0b00010001 (0x11)
101 // We will use this for the getLightToggle() test.
102 const uint8_t kElectraAcLightToggleMask = 0x11;
103 // and known OFF values of 0x08 (0b00001000) & 0x05 (0x00000101)
104 const uint8_t kElectraAcLightToggleOff = 0x08;
105
106 // Re: Byte[7]. Or Delta == 0xA and Temperature are stored in last 6 bits,
107 // and bit 7 stores Unknown flag
108 const uint8_t kElectraAcSensorTempDelta = 0x4A;
109 const uint8_t kElectraAcSensorMinTemp = 0; // 0C
110 const uint8_t kElectraAcSensorMaxTemp = 50; // 50C
111
112 // Classes
114 class IRElectraAc {
115 public:
116 explicit IRElectraAc(const uint16_t pin, const bool inverted = false,
117 const bool use_modulation = true);
118 void stateReset(void);
119 #if SEND_ELECTRA_AC
120 void send(const uint16_t repeat = kElectraAcMinRepeat);
125 int8_t calibrate(void) { return _irsend.calibrate(); }
126 #endif // SEND_ELECTRA_AC
127 void begin(void);
128 void on(void);
129 void off(void);
130 void setPower(const bool on);
131 bool getPower(void) const;
132 void setMode(const uint8_t mode);
133 uint8_t getMode(void) const;
134 void setTemp(const uint8_t temp);
135 uint8_t getTemp(void) const;
136 void setFan(const uint8_t speed);
137 uint8_t getFan(void) const;
138 void setSwingV(const bool on);
139 bool getSwingV(void) const;
140 void setSwingH(const bool on);
141 bool getSwingH(void) const;
142 void setClean(const bool on);
143 bool getClean(void) const;
144 void setLightToggle(const bool on);
145 bool getLightToggle(void) const;
146 void setTurbo(const bool on);
147 bool getTurbo(void) const;
148 void setIFeel(const bool on);
149 bool getIFeel(void) const;
150 void setSensorUpdate(const bool on);
151 bool getSensorUpdate(void) const;
152 void setSensorTemp(const uint8_t temp);
153 uint8_t getSensorTemp(void) const;
154 uint8_t* getRaw(void);
155 void setRaw(const uint8_t new_code[],
156 const uint16_t length = kElectraAcStateLength);
157 static bool validChecksum(const uint8_t state[],
158 const uint16_t length = kElectraAcStateLength);
159 static uint8_t calcChecksum(const uint8_t state[],
160 const uint16_t length = kElectraAcStateLength);
161 String toString(void) const;
162 static uint8_t convertMode(const stdAc::opmode_t mode);
163 static uint8_t convertFan(const stdAc::fanspeed_t speed);
164 static stdAc::opmode_t toCommonMode(const uint8_t mode);
165 static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
166 stdAc::state_t toCommon(void) const;
167 #ifndef UNIT_TEST
168
169 private:
170 IRsend _irsend;
171 #else
172 IRsendTest _irsend;
174 #endif
176 ElectraProtocol _;
177 void checksum(const uint16_t length = kElectraAcStateLength);
178 };
179 #endif // IR_ELECTRA_H_
ElectraProtocol::Temp
uint8_t Temp
Definition: ir_Electra.h:41
IRElectraAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Electra.cpp:159
IRElectraAc::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Electra.cpp:166
IRElectraAc::checksum
void checksum(const uint16_t length=kElectraAcStateLength)
Calculate and set the checksum values for the internal state.
Definition: ir_Electra.cpp:95
IRElectraAc::setSensorUpdate
void setSensorUpdate(const bool on)
Set the silent Sensor Update setting of the message. i.e. Is this just a sensor temp update message f...
Definition: ir_Electra.cpp:342
IRElectraAc::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Electra.cpp:110
kElectraAcMinTemp
const uint8_t kElectraAcMinTemp
Definition: ir_Electra.h:81
IRElectraAc::getSwingV
bool getSwingV(void) const
Get the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:260
ElectraProtocol::Power
uint8_t Power
Definition: ir_Electra.h:69
IRElectraAc::getSensorUpdate
bool getSensorUpdate(void) const
Get the silent Sensor Update setting of the message. i.e. Is this just a sensor temp update message f...
Definition: ir_Electra.cpp:334
kElectraAcMaxTemp
const uint8_t kElectraAcMaxTemp
Definition: ir_Electra.h:82
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:61
IRElectraAc::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Electra.cpp:136
IRElectraAc::validChecksum
static bool validChecksum(const uint8_t state[], const uint16_t length=kElectraAcStateLength)
Verify the checksum is valid for a given state.
Definition: ir_Electra.cpp:87
IRElectraAc::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Electra.cpp:361
kElectraAcFanAuto
const uint8_t kElectraAcFanAuto
Definition: ir_Electra.h:87
IRElectraAc::on
void on(void)
Change the power setting to On.
Definition: ir_Electra.cpp:123
ElectraProtocol::Fan
uint8_t Fan
Definition: ir_Electra.h:51
IRElectraAc::setClean
void setClean(const bool on)
Set the Clean mode of the A/C.
Definition: ir_Electra.cpp:291
IRsend.h
kElectraAcMinRepeat
const uint16_t kElectraAcMinRepeat
Definition: IRremoteESP8266.h:1236
ElectraProtocol::SensorUpdate
uint8_t SensorUpdate
Definition: ir_Electra.h:47
IRElectraAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Electra.cpp:199
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:237
IRElectraAc::IRElectraAc
IRElectraAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Electra.cpp:56
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRElectraAc::setSensorTemp
void setSensorTemp(const uint8_t temp)
Set the Sensor temperature for the IFeel mode.
Definition: ir_Electra.cpp:346
kElectraAcHeat
const uint8_t kElectraAcHeat
Definition: ir_Electra.h:95
IRElectraAc::_
ElectraProtocol _
Definition: ir_Electra.h:176
IRElectraAc::setIFeel
void setIFeel(const bool on)
Set the IFeel mode of the A/C.
Definition: ir_Electra.cpp:319
String
std::string String
Definition: IRremoteESP8266.h:1521
kElectraAcCool
const uint8_t kElectraAcCool
Definition: ir_Electra.h:93
IRElectraAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Electra.cpp:206
ElectraProtocol::Sum
uint8_t Sum
Definition: ir_Electra.h:76
ElectraProtocol::SensorTemp
uint8_t SensorTemp
Definition: ir_Electra.h:62
IRElectraAc
Class for handling detailed Electra A/C messages.
Definition: ir_Electra.h:114
kElectraAcAuto
const uint8_t kElectraAcAuto
Definition: ir_Electra.h:92
IRremoteESP8266.h
IRElectraAc::getSensorTemp
uint8_t getSensorTemp(void) const
Get the current sensor temperature setting for the IFeel mode.
Definition: ir_Electra.cpp:354
IRElectraAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Electra.cpp:179
kElectraAcDry
const uint8_t kElectraAcDry
Definition: ir_Electra.h:94
ElectraProtocol::IFeel
uint8_t IFeel
Definition: ir_Electra.h:58
kElectraAcSensorMinTemp
const uint8_t kElectraAcSensorMinTemp
Definition: ir_Electra.h:109
IRElectraAc::setRaw
void setRaw(const uint8_t new_code[], const uint16_t length=kElectraAcStateLength)
Set the internal state from a valid code for this protocol.
Definition: ir_Electra.cpp:118
IRElectraAc::getLightToggle
bool getLightToggle(void) const
Get the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:284
IRElectraAc::getClean
bool getClean(void) const
Get the Clean mode of the A/C.
Definition: ir_Electra.cpp:297
IRElectraAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Electra.cpp:130
kElectraAcTempDelta
const uint8_t kElectraAcTempDelta
Definition: ir_Electra.h:83
ElectraProtocol
Native representation of a Electra A/C message.
Definition: ir_Electra.h:34
IRElectraAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Electra.h:125
kElectraAcSensorMaxTemp
const uint8_t kElectraAcSensorMaxTemp
Definition: ir_Electra.h:110
kElectraAcLightToggleOff
const uint8_t kElectraAcLightToggleOff
Definition: ir_Electra.h:104
IRElectraAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Electra.cpp:243
ElectraProtocol::Clean
uint8_t Clean
Definition: ir_Electra.h:67
IRElectraAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Electra.cpp:191
kElectraAcLightToggleOn
const uint8_t kElectraAcLightToggleOn
Definition: ir_Electra.h:98
IRElectraAc::setLightToggle
void setLightToggle(const bool on)
Set the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:278
ElectraProtocol::Mode
uint8_t Mode
Definition: ir_Electra.h:60
kElectraAcFanLow
const uint8_t kElectraAcFanLow
Definition: ir_Electra.h:88
IRElectraAc::setSwingH
void setSwingH(const bool on)
Set the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:266
kElectraAcSensorTempDelta
const uint8_t kElectraAcSensorTempDelta
Definition: ir_Electra.h:108
IRElectraAc::calcChecksum
static uint8_t calcChecksum(const uint8_t state[], const uint16_t length=kElectraAcStateLength)
Calculate the checksum for a given state.
Definition: ir_Electra.cpp:77
ElectraProtocol::SwingV
uint8_t SwingV
Definition: ir_Electra.h:40
IRElectraAc::off
void off(void)
Change the power setting to Off.
Definition: ir_Electra.cpp:126
IRElectraAc::send
void send(const uint16_t repeat=kElectraAcMinRepeat)
Send the current internal state as an IR message.
Definition: ir_Electra.cpp:103
IRElectraAc::_irsend
IRsend _irsend
instance of the IR send class
Definition: ir_Electra.h:170
kElectraAcSwingOn
const uint8_t kElectraAcSwingOn
Definition: ir_Electra.h:84
IRElectraAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Electra.cpp:222
kElectraAcFanMed
const uint8_t kElectraAcFanMed
Definition: ir_Electra.h:89
IRElectraAc::getIFeel
bool getIFeel(void) const
Get the IFeel mode of the A/C.
Definition: ir_Electra.cpp:315
IRElectraAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Electra.cpp:391
kElectraAcFanHigh
const uint8_t kElectraAcFanHigh
Definition: ir_Electra.h:90
IRElectraAc::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Electra.cpp:229
IRElectraAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Electra.cpp:71
IRElectraAc::setTurbo
void setTurbo(const bool on)
Set the Turbo mode of the A/C.
Definition: ir_Electra.cpp:303
ElectraProtocol::Turbo
uint8_t Turbo
Definition: ir_Electra.h:54
IRElectraAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Electra.cpp:142
IRElectraAc::getTurbo
bool getTurbo(void) const
Get the Turbo mode of the A/C.
Definition: ir_Electra.cpp:309
IRElectraAc::getSwingH
bool getSwingH(void) const
Get the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:272
ElectraProtocol::LightToggle
uint8_t LightToggle
Definition: ir_Electra.h:74
kElectraAcFan
const uint8_t kElectraAcFan
Definition: ir_Electra.h:96
kElectraAcLightToggleMask
const uint8_t kElectraAcLightToggleMask
Definition: ir_Electra.h:102
kElectraAcSwingOff
const uint8_t kElectraAcSwingOff
Definition: ir_Electra.h:85
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:114
IRElectraAc::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Electra.cpp:63
ElectraProtocol::raw
uint8_t raw[kElectraAcStateLength]
The state of the IR remote.
Definition: ir_Electra.h:35
ElectraProtocol::SwingH
uint8_t SwingH
Definition: ir_Electra.h:44
IRElectraAc::setSwingV
void setSwingV(const bool on)
Set the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:254
kElectraAcStateLength
const uint16_t kElectraAcStateLength
Definition: IRremoteESP8266.h:1234
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:49