IRremoteESP8266: src/ir_Electra.h Source File

IRremoteESP8266

ir_Electra.h
Go to the documentation of this file.
1 // Copyright 2019 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
12 #ifndef IR_ELECTRA_H_
13 #define IR_ELECTRA_H_
14
15 #define __STDC_LIMIT_MACROS
16 #include <stdint.h>
17 #ifndef UNIT_TEST
18 #include <Arduino.h>
19 #endif
20 #include "IRremoteESP8266.h"
21 #include "IRsend.h"
22 #ifdef UNIT_TEST
23 #include "IRsend_test.h"
24 #endif
25
27 union ElectraProtocol {
28 uint8_t raw[kElectraAcStateLength];
29 struct {
30 // Byte 0
31 uint8_t :8;
32 // Byte 1
33 uint8_t SwingV :3;
34 uint8_t Temp :5;
35 // Byte 2
36 uint8_t :5;
37 uint8_t SwingH :3;
38 // Byte 3
39 uint8_t :8;
40 // Byte 4
41 uint8_t :5;
42 uint8_t Fan :3;
43 // Byte 5
44 uint8_t :6;
45 uint8_t Turbo :1;
46 uint8_t :1;
47 // Byte 6
48 uint8_t :5;
49 uint8_t Mode :3;
50 // Byte 7
51 uint8_t :8;
52 // Byte 8
53 uint8_t :8;
54 // Byte 9
55 uint8_t :2;
56 uint8_t Clean :1;
57 uint8_t :2;
58 uint8_t Power :1;
59 uint8_t :2;
60 // Byte 10
61 uint8_t :8;
62 // Byte 11
63 uint8_t LightToggle :8;
64 // Byte 12
65 uint8_t Sum :8;
66 };
67 };
68
69 // Constants
70 const uint8_t kElectraAcMinTemp = 16; // 16C
71 const uint8_t kElectraAcMaxTemp = 32; // 32C
72 const uint8_t kElectraAcTempDelta = 8;
73 const uint8_t kElectraAcSwingOn = 0b000;
74 const uint8_t kElectraAcSwingOff = 0b111;
75
76 const uint8_t kElectraAcFanAuto = 0b101;
77 const uint8_t kElectraAcFanLow = 0b011;
78 const uint8_t kElectraAcFanMed = 0b010;
79 const uint8_t kElectraAcFanHigh = 0b001;
80
81 const uint8_t kElectraAcAuto = 0b000;
82 const uint8_t kElectraAcCool = 0b001;
83 const uint8_t kElectraAcDry = 0b010;
84 const uint8_t kElectraAcHeat = 0b100;
85 const uint8_t kElectraAcFan = 0b110;
86
87 const uint8_t kElectraAcLightToggleOn = 0x15;
88 // Light has known ON values of 0x15 (0b00010101) or 0x19 (0b00011001)
89 // Thus common bits ON are: 0b00010001 (0x11)
90 // We will use this for the getLightToggle() test.
91 const uint8_t kElectraAcLightToggleMask = 0x11;
92 // and known OFF values of 0x08 (0b00001000) & 0x05 (0x00000101)
93 const uint8_t kElectraAcLightToggleOff = 0x08;
94
95
96 // Classes
98 class IRElectraAc {
99 public:
100 explicit IRElectraAc(const uint16_t pin, const bool inverted = false,
101 const bool use_modulation = true);
102 void stateReset(void);
103 #if SEND_ELECTRA_AC
104 void send(const uint16_t repeat = kElectraAcMinRepeat);
109 int8_t calibrate(void) { return _irsend.calibrate(); }
110 #endif // SEND_ELECTRA_AC
111 void begin(void);
112 void on(void);
113 void off(void);
114 void setPower(const bool on);
115 bool getPower(void) const;
116 void setMode(const uint8_t mode);
117 uint8_t getMode(void) const;
118 void setTemp(const uint8_t temp);
119 uint8_t getTemp(void) const;
120 void setFan(const uint8_t speed);
121 uint8_t getFan(void) const;
122 void setSwingV(const bool on);
123 bool getSwingV(void) const;
124 void setSwingH(const bool on);
125 bool getSwingH(void) const;
126 void setClean(const bool on);
127 bool getClean(void) const;
128 void setLightToggle(const bool on);
129 bool getLightToggle(void) const;
130 void setTurbo(const bool on);
131 bool getTurbo(void) const;
132 uint8_t* getRaw(void);
133 void setRaw(const uint8_t new_code[],
134 const uint16_t length = kElectraAcStateLength);
135 static bool validChecksum(const uint8_t state[],
136 const uint16_t length = kElectraAcStateLength);
137 static uint8_t calcChecksum(const uint8_t state[],
138 const uint16_t length = kElectraAcStateLength);
139 String toString(void) const;
140 static uint8_t convertMode(const stdAc::opmode_t mode);
141 static uint8_t convertFan(const stdAc::fanspeed_t speed);
142 static stdAc::opmode_t toCommonMode(const uint8_t mode);
143 static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
144 stdAc::state_t toCommon(void) const;
145 #ifndef UNIT_TEST
146
147 private:
148 IRsend _irsend;
149 #else
150 IRsendTest _irsend;
152 #endif
154 ElectraProtocol _;
155 void checksum(const uint16_t length = kElectraAcStateLength);
156 };
157 #endif // IR_ELECTRA_H_
ElectraProtocol::Temp
uint8_t Temp
Definition: ir_Electra.h:34
IRElectraAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Electra.cpp:158
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:165
IRElectraAc::checksum
void checksum(const uint16_t length=kElectraAcStateLength)
Calculate and set the checksum values for the internal state.
Definition: ir_Electra.cpp:94
IRElectraAc::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Electra.cpp:109
kElectraAcMinTemp
const uint8_t kElectraAcMinTemp
Definition: ir_Electra.h:70
IRElectraAc::getSwingV
bool getSwingV(void) const
Get the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:259
ElectraProtocol::Power
uint8_t Power
Definition: ir_Electra.h:58
kElectraAcMaxTemp
const uint8_t kElectraAcMaxTemp
Definition: ir_Electra.h:71
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
IRElectraAc::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Electra.cpp:135
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:86
IRElectraAc::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Electra.cpp:314
kElectraAcFanAuto
const uint8_t kElectraAcFanAuto
Definition: ir_Electra.h:76
IRElectraAc::on
void on(void)
Change the power setting to On.
Definition: ir_Electra.cpp:122
ElectraProtocol::Fan
uint8_t Fan
Definition: ir_Electra.h:42
IRElectraAc::setClean
void setClean(const bool on)
Set the Clean mode of the A/C.
Definition: ir_Electra.cpp:290
IRsend.h
kElectraAcMinRepeat
const uint16_t kElectraAcMinRepeat
Definition: IRremoteESP8266.h:958
IRElectraAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Electra.cpp:198
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:187
IRElectraAc::IRElectraAc
IRElectraAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Electra.cpp:55
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
kElectraAcHeat
const uint8_t kElectraAcHeat
Definition: ir_Electra.h:84
IRElectraAc::_
ElectraProtocol _
Definition: ir_Electra.h:154
String
std::string String
Definition: IRremoteESP8266.h:1199
kElectraAcCool
const uint8_t kElectraAcCool
Definition: ir_Electra.h:82
IRElectraAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Electra.cpp:205
ElectraProtocol::Sum
uint8_t Sum
Definition: ir_Electra.h:65
IRElectraAc
Class for handling detailed Electra A/C messages.
Definition: ir_Electra.h:98
kElectraAcAuto
const uint8_t kElectraAcAuto
Definition: ir_Electra.h:81
IRremoteESP8266.h
IRElectraAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Electra.cpp:178
kElectraAcDry
const uint8_t kElectraAcDry
Definition: ir_Electra.h:83
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:117
IRElectraAc::getLightToggle
bool getLightToggle(void) const
Get the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:283
IRElectraAc::getClean
bool getClean(void) const
Get the Clean mode of the A/C.
Definition: ir_Electra.cpp:296
IRElectraAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Electra.cpp:129
kElectraAcTempDelta
const uint8_t kElectraAcTempDelta
Definition: ir_Electra.h:72
ElectraProtocol
Native representation of a Electra A/C message.
Definition: ir_Electra.h:27
IRElectraAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Electra.h:109
kElectraAcLightToggleOff
const uint8_t kElectraAcLightToggleOff
Definition: ir_Electra.h:93
IRElectraAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Electra.cpp:242
ElectraProtocol::Clean
uint8_t Clean
Definition: ir_Electra.h:56
IRElectraAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Electra.cpp:190
kElectraAcLightToggleOn
const uint8_t kElectraAcLightToggleOn
Definition: ir_Electra.h:87
IRElectraAc::setLightToggle
void setLightToggle(const bool on)
Set the Light (LED) Toggle mode of the A/C.
Definition: ir_Electra.cpp:277
ElectraProtocol::Mode
uint8_t Mode
Definition: ir_Electra.h:49
kElectraAcFanLow
const uint8_t kElectraAcFanLow
Definition: ir_Electra.h:77
IRElectraAc::setSwingH
void setSwingH(const bool on)
Set the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:265
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:76
ElectraProtocol::SwingV
uint8_t SwingV
Definition: ir_Electra.h:33
IRElectraAc::off
void off(void)
Change the power setting to Off.
Definition: ir_Electra.cpp:125
IRElectraAc::send
void send(const uint16_t repeat=kElectraAcMinRepeat)
Send the current internal state as an IR message.
Definition: ir_Electra.cpp:102
IRElectraAc::_irsend
IRsend _irsend
instance of the IR send class
Definition: ir_Electra.h:148
kElectraAcSwingOn
const uint8_t kElectraAcSwingOn
Definition: ir_Electra.h:73
IRElectraAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Electra.cpp:221
kElectraAcFanMed
const uint8_t kElectraAcFanMed
Definition: ir_Electra.h:78
IRElectraAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Electra.cpp:342
kElectraAcFanHigh
const uint8_t kElectraAcFanHigh
Definition: ir_Electra.h:79
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:228
IRElectraAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Electra.cpp:70
IRElectraAc::setTurbo
void setTurbo(const bool on)
Set the Turbo mode of the A/C.
Definition: ir_Electra.cpp:302
ElectraProtocol::Turbo
uint8_t Turbo
Definition: ir_Electra.h:45
IRElectraAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Electra.cpp:141
IRElectraAc::getTurbo
bool getTurbo(void) const
Get the Turbo mode of the A/C.
Definition: ir_Electra.cpp:308
IRElectraAc::getSwingH
bool getSwingH(void) const
Get the Horizontal Swing mode of the A/C.
Definition: ir_Electra.cpp:271
ElectraProtocol::LightToggle
uint8_t LightToggle
Definition: ir_Electra.h:63
kElectraAcFan
const uint8_t kElectraAcFan
Definition: ir_Electra.h:85
kElectraAcLightToggleMask
const uint8_t kElectraAcLightToggleMask
Definition: ir_Electra.h:91
kElectraAcSwingOff
const uint8_t kElectraAcSwingOff
Definition: ir_Electra.h:74
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRElectraAc::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Electra.cpp:62
ElectraProtocol::raw
uint8_t raw[kElectraAcStateLength]
The state of the IR remote.
Definition: ir_Electra.h:28
ElectraProtocol::SwingH
uint8_t SwingH
Definition: ir_Electra.h:37
IRElectraAc::setSwingV
void setSwingV(const bool on)
Set the Vertical Swing mode of the A/C.
Definition: ir_Electra.cpp:253
kElectraAcStateLength
const uint16_t kElectraAcStateLength
Definition: IRremoteESP8266.h:956
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46