IRremoteESP8266: src/ir_Carrier.h Source File

IRremoteESP8266

ir_Carrier.h
Go to the documentation of this file.
1 // Copyright 2020 David Conran
6
7 // Supports:
8 // Brand: Carrier/Surrey, Model: 42QG5A55970 remote
9 // Brand: Carrier/Surrey, Model: 619EGX0090E0 A/C
10 // Brand: Carrier/Surrey, Model: 619EGX0120E0 A/C
11 // Brand: Carrier/Surrey, Model: 619EGX0180E0 A/C
12 // Brand: Carrier/Surrey, Model: 619EGX0220E0 A/C
13 // Brand: Carrier/Surrey, Model: 53NGK009/012 Inverter
14
15 #ifndef IR_CARRIER_H_
16 #define IR_CARRIER_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 union CarrierProtocol {
31 uint64_t raw;
32 struct {
33 // Byte 0
34 uint8_t :8;
35 // Byte 1
36 uint8_t :8;
37 // Byte 2
38 uint8_t Sum:4;
39 uint8_t Mode:2;
40 uint8_t Fan:2;
41 // Byte 3
42 uint8_t Temp:4;
43 uint8_t :1;
44 uint8_t SwingV:1;
45 uint8_t :2;
46 // Byte 4
47 uint8_t :4;
48 uint8_t Power:1;
49 uint8_t OffTimerEnable:1;
50 uint8_t OnTimerEnable:1;
51 uint8_t Sleep:1;
52 // Byte 5
53 uint8_t :8;
54 // Byte 6
55 uint8_t :4;
56 uint8_t OnTimer:4;
57 // Byte 7
58 uint8_t :4;
59 uint8_t OffTimer:4;
60 };
61 };
62
63 // Constants
64
65 // CARRIER_AC64
66 const uint8_t kCarrierAc64ChecksumOffset = 16;
67 const uint8_t kCarrierAc64ChecksumSize = 4;
68 const uint8_t kCarrierAc64Heat = 0b01; // 1
69 const uint8_t kCarrierAc64Cool = 0b10; // 2
70 const uint8_t kCarrierAc64Fan = 0b11; // 3
71 const uint8_t kCarrierAc64FanAuto = 0b00; // 0
72 const uint8_t kCarrierAc64FanLow = 0b01; // 1
73 const uint8_t kCarrierAc64FanMedium = 0b10; // 2
74 const uint8_t kCarrierAc64FanHigh = 0b11; // 3
75 const uint8_t kCarrierAc64MinTemp = 16; // Celsius
76 const uint8_t kCarrierAc64MaxTemp = 30; // Celsius
77 const uint8_t kCarrierAc64TimerMax = 9; // Hours.
78 const uint8_t kCarrierAc64TimerMin = 1; // Hours.
79
80
81 // Classes
82
84 class IRCarrierAc64 {
85 public:
86 explicit IRCarrierAc64(const uint16_t pin, const bool inverted = false,
87 const bool use_modulation = true);
88
89 void stateReset();
90 #if SEND_CARRIER_AC64
91 void send(const uint16_t repeat = kCarrierAc64MinRepeat);
96 int8_t calibrate(void) { return _irsend.calibrate(); }
97 #endif // SEND_CARRIER_AC64
98 void begin();
99 static uint8_t calcChecksum(const uint64_t state);
100 static bool validChecksum(const uint64_t state);
101 void setPower(const bool on);
102 bool getPower(void) const;
103 void on(void);
104 void off(void);
105 void setTemp(const uint8_t temp);
106 uint8_t getTemp(void) const;
107 void setSwingV(const bool on);
108 bool getSwingV(void) const;
109 void setSleep(const bool on);
110 bool getSleep(void) const;
111 void setFan(const uint8_t speed);
112 uint8_t getFan(void) const;
113 void setMode(const uint8_t mode);
114 uint8_t getMode(void) const;
115 void setOnTimer(const uint16_t nr_of_mins);
116 uint16_t getOnTimer(void) const;
117 void setOffTimer(const uint16_t nr_of_mins);
118 uint16_t getOffTimer(void) const;
119 uint64_t getRaw(void);
120 void setRaw(const uint64_t state);
121 static uint8_t convertMode(const stdAc::opmode_t mode);
122 static uint8_t convertFan(const stdAc::fanspeed_t speed);
123 static stdAc::opmode_t toCommonMode(const uint8_t mode);
124 static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
125 stdAc::state_t toCommon(void) const;
126 String toString(void) const;
127 #ifndef UNIT_TEST
128
129 private:
130 IRsend _irsend;
131 #else
132 IRsendTest _irsend;
134 #endif
136 CarrierProtocol _;
137 void checksum(void);
138 void _cancelOnTimer(void);
139 void _cancelOffTimer(void);
140 };
141 #endif // IR_CARRIER_H_
kCarrierAc64MinTemp
const uint8_t kCarrierAc64MinTemp
Definition: ir_Carrier.h:75
kCarrierAc64TimerMin
const uint8_t kCarrierAc64TimerMin
Definition: ir_Carrier.h:78
IRCarrierAc64::on
void on(void)
Change the power setting to On.
Definition: ir_Carrier.cpp:310
IRCarrierAc64::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Carrier.cpp:299
CarrierProtocol::Sleep
uint8_t Sleep
Definition: ir_Carrier.h:51
IRCarrierAc64::getTemp
uint8_t getTemp(void) const
Get the current temperature from the internal state.
Definition: ir_Carrier.cpp:293
IRCarrierAc64::checksum
void checksum(void)
Calculate and set the checksum values for the internal state.
Definition: ir_Carrier.cpp:257
IRCarrierAc64::toCommon
stdAc::state_t toCommon(void) const
Convert the A/C state to it's common stdAc::state_t equivalent.
Definition: ir_Carrier.cpp:513
IRCarrierAc64::IRCarrierAc64
IRCarrierAc64(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Carrier.cpp:226
CarrierProtocol::Fan
uint8_t Fan
Definition: ir_Carrier.h:40
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
CarrierProtocol::OnTimer
uint8_t OnTimer
Definition: ir_Carrier.h:56
CarrierProtocol::OffTimerEnable
uint8_t OffTimerEnable
Definition: ir_Carrier.h:49
kCarrierAc64Heat
const uint8_t kCarrierAc64Heat
Definition: ir_Carrier.h:68
IRsend.h
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:187
IRCarrierAc64::_cancelOnTimer
void _cancelOnTimer(void)
Clear the On Timer enable bit.
Definition: ir_Carrier.cpp:430
IRCarrierAc64::begin
void begin()
Set up hardware to be able to send a message.
Definition: ir_Carrier.cpp:262
kCarrierAc64Cool
const uint8_t kCarrierAc64Cool
Definition: ir_Carrier.h:69
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRCarrierAc64::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode to it's common stdAc::opmode_t equivalent.
Definition: ir_Carrier.cpp:349
String
std::string String
Definition: IRremoteESP8266.h:1199
IRCarrierAc64::getOffTimer
uint16_t getOffTimer(void) const
Get the current Off Timer time.
Definition: ir_Carrier.cpp:466
IRCarrierAc64::setTemp
void setTemp(const uint8_t temp)
Set the temp in deg C.
Definition: ir_Carrier.cpp:285
IRCarrierAc64::send
void send(const uint16_t repeat=kCarrierAc64MinRepeat)
Send the current internal state as an IR message.
Definition: ir_Carrier.cpp:267
IRCarrierAc64::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Carrier.cpp:375
IRCarrierAc64::setOffTimer
void setOffTimer(const uint16_t nr_of_mins)
Set the Off Timer time.
Definition: ir_Carrier.cpp:477
kCarrierAc64TimerMax
const uint8_t kCarrierAc64TimerMax
Definition: ir_Carrier.h:77
kCarrierAc64FanHigh
const uint8_t kCarrierAc64FanHigh
Definition: ir_Carrier.h:74
IRremoteESP8266.h
CarrierProtocol
Native representation of a Carrier A/C message.
Definition: ir_Carrier.h:30
IRCarrierAc64::_
CarrierProtocol _
Definition: ir_Carrier.h:136
IRCarrierAc64::validChecksum
static bool validChecksum(const uint64_t state)
Verify the checksum is valid for a given state.
Definition: ir_Carrier.cpp:250
CarrierProtocol::Mode
uint8_t Mode
Definition: ir_Carrier.h:39
kCarrierAc64FanMedium
const uint8_t kCarrierAc64FanMedium
Definition: ir_Carrier.h:73
kCarrierAc64MaxTemp
const uint8_t kCarrierAc64MaxTemp
Definition: ir_Carrier.h:76
IRCarrierAc64
Class for handling detailed Carrier 64 bit A/C messages.
Definition: ir_Carrier.h:84
IRCarrierAc64::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Carrier.cpp:317
IRCarrierAc64::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Carrier.h:130
IRCarrierAc64::stateReset
void stateReset()
Reset the internal state to a fixed known good state.
Definition: ir_Carrier.cpp:232
IRCarrierAc64::off
void off(void)
Change the power setting to Off.
Definition: ir_Carrier.cpp:313
CarrierProtocol::OffTimer
uint8_t OffTimer
Definition: ir_Carrier.h:59
IRCarrierAc64::calcChecksum
static uint8_t calcChecksum(const uint64_t state)
Calculate the checksum for a given state.
Definition: ir_Carrier.cpp:237
IRCarrierAc64::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Carrier.h:96
CarrierProtocol::Sum
uint8_t Sum
Definition: ir_Carrier.h:38
IRCarrierAc64::setRaw
void setRaw(const uint64_t state)
Set the internal state from a valid code for this protocol.
Definition: ir_Carrier.cpp:281
CarrierProtocol::Power
uint8_t Power
Definition: ir_Carrier.h:48
IRCarrierAc64::getSwingV
bool getSwingV(void) const
Get the Vertical Swing mode of the A/C.
Definition: ir_Carrier.cpp:406
IRCarrierAc64::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Carrier.cpp:305
kCarrierAc64Fan
const uint8_t kCarrierAc64Fan
Definition: ir_Carrier.h:70
kCarrierAc64ChecksumSize
const uint8_t kCarrierAc64ChecksumSize
Definition: ir_Carrier.h:67
CarrierProtocol::SwingV
uint8_t SwingV
Definition: ir_Carrier.h:44
IRCarrierAc64::setOnTimer
void setOnTimer(const uint16_t nr_of_mins)
Set the On Timer time.
Definition: ir_Carrier.cpp:448
IRCarrierAc64::getRaw
uint64_t getRaw(void)
Get a copy of the internal state as a valid code for this protocol.
Definition: ir_Carrier.cpp:274
IRCarrierAc64::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a standard A/C mode into its native mode.
Definition: ir_Carrier.cpp:338
kCarrierAc64MinRepeat
const uint16_t kCarrierAc64MinRepeat
Definition: IRremoteESP8266.h:912
kCarrierAc64FanLow
const uint8_t kCarrierAc64FanLow
Definition: ir_Carrier.h:72
kCarrierAc64FanAuto
const uint8_t kCarrierAc64FanAuto
Definition: ir_Carrier.h:71
IRCarrierAc64::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Carrier.cpp:389
CarrierProtocol::raw
uint64_t raw
The state of the IR remote.
Definition: ir_Carrier.h:31
IRCarrierAc64::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Carrier.cpp:365
IRCarrierAc64::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Carrier.cpp:323
IRCarrierAc64::setSwingV
void setSwingV(const bool on)
Set the Vertical Swing mode of the A/C.
Definition: ir_Carrier.cpp:400
IRCarrierAc64::setSleep
void setSleep(const bool on)
Set the Sleep mode of the A/C.
Definition: ir_Carrier.cpp:412
IRCarrierAc64::_cancelOffTimer
void _cancelOffTimer(void)
Clear the Off Timer enable bit.
Definition: ir_Carrier.cpp:459
IRCarrierAc64::toString
String toString(void) const
Convert the internal state into a human readable string.
Definition: ir_Carrier.cpp:490
IRCarrierAc64::getSleep
bool getSleep(void) const
Get the Sleep mode of the A/C.
Definition: ir_Carrier.cpp:425
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
CarrierProtocol::Temp
uint8_t Temp
Definition: ir_Carrier.h:42
CarrierProtocol::OnTimerEnable
uint8_t OnTimerEnable
Definition: ir_Carrier.h:50
IRCarrierAc64::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Carrier.cpp:359
IRCarrierAc64::getOnTimer
uint16_t getOnTimer(void) const
Get the current On Timer time.
Definition: ir_Carrier.cpp:437
kCarrierAc64ChecksumOffset
const uint8_t kCarrierAc64ChecksumOffset
Definition: ir_Carrier.h:66
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46