IRremoteESP8266

ir_Corona.h
Go to the documentation of this file.
1 // Corona A/C
2 //
3 // Copyright 2020 Christian Nilsson
4
5 // Supports:
6 // Brand: Corona, Model: CSH-N2211 A/C
7 // Brand: Corona, Model: CSH-N2511 A/C
8 // Brand: Corona, Model: CSH-N2811 A/C
9 // Brand: Corona, Model: CSH-N4011 A/C
10 // Brand: Corona, Model: AR-01 remote
11 //
12 // Ref: https://docs.google.com/spreadsheets/d/1zzDEUQ52y7MZ7_xCU3pdjdqbRXOwZLsbTGvKWcicqCI/
13 // Ref: https://www.corona.co.jp/box/download.php?id=145060636229
14
15 #ifndef IR_CORONA_H_
16 #define IR_CORONA_H_
17
18 #define __STDC_LIMIT_MACROS
19 #include <stdint.h>
20 #ifndef UNIT_TEST
21 #include <Arduino.h>
22 #endif
23 #include "IRremoteESP8266.h"
24 #include "IRsend.h"
25 #ifdef UNIT_TEST
26 #include "IRsend_test.h"
27 #endif
28
30 struct CoronaSection {
31 uint8_t Header0;
32 uint8_t Header1;
33 uint8_t Label;
34 uint8_t Data0;
35 uint8_t Data0Inv;
36 uint8_t Data1;
37 uint8_t Data1Inv;
38 };
39
40 const uint8_t kCoronaAcSections = 3;
41
43 union CoronaProtocol {
44 uint8_t raw[kCoronaAcStateLength];
45 CoronaSection sections[kCoronaAcSections];
46 struct {
47 // Byte 0
48 uint8_t :8;
49 // Byte 1
50 uint8_t :8;
51 // Byte 2
52 uint8_t :8;
53 // Byte 3
54 uint8_t Fan :2;
55 uint8_t :1;
56 uint8_t Econo :1;
57 uint8_t :1; // always on
58 uint8_t :1;
59 uint8_t SwingVToggle :1;
60 uint8_t :1;
61 // Byte 4
62 uint8_t :8;
63 // Byte 5
64 uint8_t Temp :4;
65 uint8_t Power :1;
66 uint8_t PowerButton :1;
67 uint8_t Mode :2;
68 };
69 };
70
71 // Constants
72
73 // CORONA_AC
74 const uint8_t kCoronaAcSectionBytes = 7; // kCoronaAcStateLengthShort
75 const uint8_t kCoronaAcSectionHeader0 = 0x28;
76 const uint8_t kCoronaAcSectionHeader1 = 0x61;
77 const uint8_t kCoronaAcSectionLabelBase = 0x0D; // 0b1101
78 const uint8_t kCoronaAcSectionData0Base = 0x10; // D0 Pos 4 always on
79
80 const uint8_t kCoronaAcFanAuto = 0b00; // 0
81 const uint8_t kCoronaAcFanLow = 0b01; // 1
82 const uint8_t kCoronaAcFanMedium = 0b10; // 2
83 const uint8_t kCoronaAcFanHigh = 0b11; // 3
84
85 /* full auto mode not supported by this code yet
86 const uint8_t kCoronaAcAutoD0 = 0b00010100; // only combined with power save
87 const uint8_t kCoronaAcAutoD1 = 0b10000011; // only combined with power
88 */
89 const uint8_t kCoronaAcMinTemp = 17; // Celsius = 0b0001
90 const uint8_t kCoronaAcMaxTemp = 30; // Celsius = 0b1110
91 const uint8_t kCoronaAcModeHeat = 0b00; // 0
92 const uint8_t kCoronaAcModeDry = 0b01; // 1
93 const uint8_t kCoronaAcModeCool = 0b10; // 2
94 const uint8_t kCoronaAcModeFan = 0b11; // 3
95
96 const uint8_t kCoronaAcSettingsSection = 0;
97 const uint8_t kCoronaAcOnTimerSection = 1;
98 const uint8_t kCoronaAcOffTimerSection = 2;
99 const uint16_t kCoronaAcTimerMax = 12 * 60; // 12H in Minutes
100 // Min value on remote is 1 hour, actual sent value can be 2 secs
101 const uint16_t kCoronaAcTimerOff = 0xffff;
102 const uint16_t kCoronaAcTimerUnitsPerMin = 30; // 30 units = 1 minute
103
104 // Classes
105
107 class IRCoronaAc {
108 public:
109 explicit IRCoronaAc(const uint16_t pin, const bool inverted = false,
110 const bool use_modulation = true);
111
112 void stateReset();
113 #if SEND_CORONA_AC
114 void send(const uint16_t repeat = kNoRepeat);
119 int8_t calibrate(void) { return _irsend.calibrate(); }
120 #endif // SEND_CORONA_AC
121 void begin();
122 static bool validSection(const uint8_t state[], const uint16_t pos,
123 const uint8_t section);
124 void setPower(const bool on);
125 bool getPower(void) const;
126 bool getPowerButton(void) const;
127 void on(void);
128 void off(void);
129 void setTemp(const uint8_t temp);
130 uint8_t getTemp(void) const;
131 void setSwingVToggle(const bool on);
132 bool getSwingVToggle(void) const;
133 void setFan(const uint8_t speed);
134 uint8_t getFan(void) const;
135 void setMode(const uint8_t mode);
136 uint8_t getMode(void) const;
137 void setEcono(const bool on);
138 bool getEcono(void) const;
139 void setOnTimer(const uint16_t nr_of_mins);
140 uint16_t getOnTimer(void) const;
141 void setOffTimer(const uint16_t nr_of_mins);
142 uint16_t getOffTimer(void) const;
143 uint8_t* getRaw();
144 void setRaw(const uint8_t new_code[],
145 const uint16_t length = kCoronaAcStateLength);
146 static uint8_t convertMode(const stdAc::opmode_t mode);
147 static uint8_t convertFan(const stdAc::fanspeed_t speed);
148 static stdAc::opmode_t toCommonMode(const uint8_t mode);
149 static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
150 stdAc::state_t toCommon(void) const;
151 String toString(void) const;
152 #ifndef UNIT_TEST
153
154 private:
155 IRsend _irsend;
156 #else
157 IRsendTest _irsend;
159 #endif
161 CoronaProtocol _;
162 static uint8_t getSectionByte(const uint8_t section);
163 static void checksum(uint8_t* data);
164 void setPowerButton(const bool on);
165 void _setTimer(const uint8_t section, const uint16_t nr_of_mins);
166 uint16_t _getTimer(const uint8_t section) const;
167 };
168 #endif // IR_CORONA_H_
CoronaSection::Header1
uint8_t Header1
Definition: ir_Corona.h:32
kCoronaAcSectionBytes
const uint8_t kCoronaAcSectionBytes
Definition: ir_Corona.h:74
IRCoronaAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Corona.cpp:346
IRCoronaAc::setFan
void setFan(const uint8_t speed)
Set the operating speed of the A/C Fan.
Definition: ir_Corona.cpp:398
IRCoronaAc::setEcono
void setEcono(const bool on)
Change the powersave setting.
Definition: ir_Corona.cpp:407
IRCoronaAc::setRaw
void setRaw(const uint8_t new_code[], const uint16_t length=kCoronaAcStateLength)
Set the internal state from a valid code for this protocol.
Definition: ir_Corona.cpp:282
kCoronaAcSectionLabelBase
const uint8_t kCoronaAcSectionLabelBase
Definition: ir_Corona.h:77
kCoronaAcModeFan
const uint8_t kCoronaAcModeFan
Definition: ir_Corona.h:94
CoronaSection::Data1Inv
uint8_t Data1Inv
Definition: ir_Corona.h:37
IRCoronaAc::setPowerButton
void setPowerButton(const bool on)
Change the power button setting.
Definition: ir_Corona.cpp:328
IRCoronaAc
Class for handling detailed Corona A/C messages.
Definition: ir_Corona.h:107
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:61
kCoronaAcModeDry
const uint8_t kCoronaAcModeDry
Definition: ir_Corona.h:92
kCoronaAcSectionData0Base
const uint8_t kCoronaAcSectionData0Base
Definition: ir_Corona.h:78
CoronaProtocol::Power
uint8_t Power
Definition: ir_Corona.h:65
IRCoronaAc::getOffTimer
uint16_t getOffTimer(void) const
Get the current Off Timer time.
Definition: ir_Corona.cpp:511
IRCoronaAc::setPower
void setPower(const bool on)
Change the power setting. (in practice Standby, remote power)
Definition: ir_Corona.cpp:304
IRCoronaAc::stateReset
void stateReset()
Reset the internal state to a fixed known good state.
Definition: ir_Corona.cpp:154
IRCoronaAc::getFan
uint8_t getFan(void) const
Get the operating speed of the A/C Fan.
Definition: ir_Corona.cpp:392
IRCoronaAc::toCommon
stdAc::state_t toCommon(void) const
Convert the A/C state to it's common stdAc::state_t equivalent.
Definition: ir_Corona.cpp:552
IRCoronaAc::begin
void begin()
Set up hardware to be able to send a message.
Definition: ir_Corona.cpp:252
kCoronaAcFanMedium
const uint8_t kCoronaAcFanMedium
Definition: ir_Corona.h:82
kCoronaAcTimerUnitsPerMin
const uint16_t kCoronaAcTimerUnitsPerMin
Definition: ir_Corona.h:102
IRCoronaAc::setOffTimer
void setOffTimer(const uint16_t nr_of_mins)
Set the Off Timer time.
Definition: ir_Corona.cpp:518
kCoronaAcFanLow
const uint8_t kCoronaAcFanLow
Definition: ir_Corona.h:81
CoronaProtocol
Native representation of a Corona A/C message.
Definition: ir_Corona.h:43
CoronaSection::Header0
uint8_t Header0
Definition: ir_Corona.h:31
IRsend.h
IRCoronaAc::setTemp
void setTemp(const uint8_t temp)
Set the temp in deg C.
Definition: ir_Corona.cpp:288
IRCoronaAc::toString
String toString(void) const
Convert the internal state into a human readable string.
Definition: ir_Corona.cpp:527
kCoronaAcSectionHeader0
const uint8_t kCoronaAcSectionHeader0
Definition: ir_Corona.h:75
IRCoronaAc::setOnTimer
void setOnTimer(const uint16_t nr_of_mins)
Set the On Timer time.
Definition: ir_Corona.cpp:502
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:237
IRCoronaAc::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a standard A/C Fan speed into its native fan speed.
Definition: ir_Corona.cpp:420
IRCoronaAc::_
CoronaProtocol _
Definition: ir_Corona.h:161
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
CoronaProtocol::Econo
uint8_t Econo
Definition: ir_Corona.h:56
String
std::string String
Definition: IRremoteESP8266.h:1521
kCoronaAcOffTimerSection
const uint8_t kCoronaAcOffTimerSection
Definition: ir_Corona.h:98
kCoronaAcTimerMax
const uint16_t kCoronaAcTimerMax
Definition: ir_Corona.h:99
IRCoronaAc::validSection
static bool validSection(const uint8_t state[], const uint16_t pos, const uint8_t section)
Check that a CoronaAc Section part is valid with section byte and inverted.
Definition: ir_Corona.cpp:187
IRCoronaAc::getOnTimer
uint16_t getOnTimer(void) const
Get the current On Timer time.
Definition: ir_Corona.cpp:495
IRCoronaAc::getPower
bool getPower(void) const
Get the current power setting. (in practice Standby, remote power)
Definition: ir_Corona.cpp:315
kCoronaAcSectionHeader1
const uint8_t kCoronaAcSectionHeader1
Definition: ir_Corona.h:76
IRremoteESP8266.h
IRCoronaAc::send
void send(const uint16_t repeat=kNoRepeat)
Send the current internal state as an IR message.
Definition: ir_Corona.cpp:257
kCoronaAcSections
const uint8_t kCoronaAcSections
Definition: ir_Corona.h:40
IRCoronaAc::_getTimer
uint16_t _getTimer(const uint8_t section) const
Get the current Timer time.
Definition: ir_Corona.cpp:482
kNoRepeat
const uint16_t kNoRepeat
Definition: IRremoteESP8266.h:1145
kCoronaAcFanHigh
const uint8_t kCoronaAcFanHigh
Definition: ir_Corona.h:83
kCoronaAcStateLength
const uint16_t kCoronaAcStateLength
Definition: IRremoteESP8266.h:1186
IRCoronaAc::checksum
static void checksum(uint8_t *data)
Calculate and set the check values for the internal state.
Definition: ir_Corona.cpp:240
IRCoronaAc::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a standard A/C mode into its native mode.
Definition: ir_Corona.cpp:369
CoronaSection::Data0
uint8_t Data0
Definition: ir_Corona.h:34
CoronaProtocol::PowerButton
uint8_t PowerButton
Definition: ir_Corona.h:66
IRCoronaAc::getPowerButton
bool getPowerButton(void) const
Get the value of the current power button setting.
Definition: ir_Corona.cpp:334
IRCoronaAc::off
void off(void)
Change the power setting to Off.
Definition: ir_Corona.cpp:342
IRCoronaAc::_setTimer
void _setTimer(const uint8_t section, const uint16_t nr_of_mins)
Set the Timer time.
Definition: ir_Corona.cpp:462
kCoronaAcModeCool
const uint8_t kCoronaAcModeCool
Definition: ir_Corona.h:93
kCoronaAcMinTemp
const uint8_t kCoronaAcMinTemp
Definition: ir_Corona.h:89
CoronaSection::Data1
uint8_t Data1
Definition: ir_Corona.h:36
CoronaProtocol::Temp
uint8_t Temp
Definition: ir_Corona.h:64
IRCoronaAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode to it's common stdAc::opmode_t equivalent.
Definition: ir_Corona.cpp:381
IRCoronaAc::getTemp
uint8_t getTemp(void) const
Get the current temperature from the internal state.
Definition: ir_Corona.cpp:296
IRCoronaAc::getSwingVToggle
bool getSwingVToggle(void) const
Get the Vertical Swing toggle setting.
Definition: ir_Corona.cpp:453
IRCoronaAc::IRCoronaAc
IRCoronaAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor for handling detailed Corona A/C messages.
Definition: ir_Corona.cpp:148
CoronaSection::Data0Inv
uint8_t Data0Inv
Definition: ir_Corona.h:35
IRCoronaAc::getRaw
uint8_t * getRaw()
Get a copy of the internal state as a valid code for this protocol.
Definition: ir_Corona.cpp:274
IRCoronaAc::on
void on(void)
Change the power setting to On.
Definition: ir_Corona.cpp:339
kCoronaAcSettingsSection
const uint8_t kCoronaAcSettingsSection
Definition: ir_Corona.h:96
CoronaProtocol::SwingVToggle
uint8_t SwingVToggle
Definition: ir_Corona.h:59
CoronaProtocol::raw
uint8_t raw[kCoronaAcStateLength]
The state of the IR remote.
Definition: ir_Corona.h:44
CoronaProtocol::sections
CoronaSection sections[kCoronaAcSections]
Definition: ir_Corona.h:45
kCoronaAcModeHeat
const uint8_t kCoronaAcModeHeat
Definition: ir_Corona.h:91
CoronaSection::Label
uint8_t Label
Definition: ir_Corona.h:33
IRCoronaAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Corona.h:155
IRCoronaAc::setSwingVToggle
void setSwingVToggle(const bool on)
Set the Vertical Swing toggle setting.
Definition: ir_Corona.cpp:447
IRCoronaAc::getSectionByte
static uint8_t getSectionByte(const uint8_t section)
Get the byte that identifies the section.
Definition: ir_Corona.cpp:171
IRCoronaAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Corona.cpp:352
CoronaSection
Native representation of a section of a Corona A/C message.
Definition: ir_Corona.h:30
IRCoronaAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed to it's common equivalent.
Definition: ir_Corona.cpp:434
IRCoronaAc::getEcono
bool getEcono(void) const
Get the value of the current powersave setting.
Definition: ir_Corona.cpp:413
IRCoronaAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Corona.h:119
kCoronaAcTimerOff
const uint16_t kCoronaAcTimerOff
Definition: ir_Corona.h:101
CoronaProtocol::Mode
uint8_t Mode
Definition: ir_Corona.h:67
kCoronaAcOnTimerSection
const uint8_t kCoronaAcOnTimerSection
Definition: ir_Corona.h:97
CoronaProtocol::Fan
uint8_t Fan
Definition: ir_Corona.h:54
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:114
kCoronaAcMaxTemp
const uint8_t kCoronaAcMaxTemp
Definition: ir_Corona.h:90
kCoronaAcFanAuto
const uint8_t kCoronaAcFanAuto
Definition: ir_Corona.h:80
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:49