IRremoteIDF
Infrared send & receive for ESP-IDF
Loading...
Searching...
No Matches
ir_Sharp.h
Go to the documentation of this file.
1// Copyright 2019 crankyoldgit
2
14
15// Supports:
16// Brand: Sharp, Model: LC-52D62U TV
17// Brand: Sharp, Model: AY-ZP40KR A/C (A907)
18// Brand: Sharp, Model: AH-AxSAY A/C (A907)
19// Brand: Sharp, Model: CRMC-A907 JBEZ remote (A907)
20// Brand: Sharp, Model: CRMC-A950 JBEZ (A907)
21// Brand: Sharp, Model: AH-PR13-GL A/C (A903)
22// Brand: Sharp, Model: CRMC-A903JBEZ remote (A903)
23// Brand: Sharp, Model: AH-XP10NRY A/C (A903)
24// Brand: Sharp, Model: CRMC-820 JBEZ remote (A903)
25// Brand: Sharp, Model: CRMC-A705 JBEZ remote (A705)
26// Brand: Sharp, Model: AH-A12REVP-1 A/C (A903)
27// Brand: Sharp, Model: CRMC-A863 JBEZ remote (A903)
28
29#ifndef IR_SHARP_H_
30#define IR_SHARP_H_
31
32#include "IRplatform.h"
33#include "IRrecv.h"
34#include "IRremoteESP8266.h"
35#include "IRsend.h"
36#ifdef UNIT_TEST
37#include "IRsend_test.h"
38#endif
39#include "IRutils.h"
40
44 struct {
45 // Byte 0~3
46 uint8_t pad[4];
47 // Byte 4
48 uint8_t Temp :4;
49 uint8_t Model :1;
50 uint8_t :3;
51 // Byte 5
52 uint8_t :4;
53 uint8_t PowerSpecial :4;
54 // Byte 6
55 uint8_t Mode :2;
56 uint8_t :1;
57 uint8_t Clean :1;
58 uint8_t Fan :3;
59 uint8_t :1;
60 // Byte 7
61 uint8_t TimerHours :4;
62 uint8_t :2;
63 uint8_t TimerType :1;
64 uint8_t TimerEnabled:1;
65 // Byte 8
66 uint8_t Swing :3;
67 uint8_t :5;
68 // Byte 9
69 uint8_t :8;
70 // Byte 10
71 uint8_t Special :8;
72 // Byte 11
73 uint8_t :2;
74 uint8_t Ion :1;
75 uint8_t :1;
76 uint8_t Model2 :1;
77 uint8_t :3;
78 // Byte 12
79 uint8_t :4;
80 uint8_t Sum :4;
81 };
82};
83
84// Constants
85const uint16_t kSharpAcHdrMark = 3800;
86const uint16_t kSharpAcHdrSpace = 1900;
87const uint16_t kSharpAcBitMark = 470;
88const uint16_t kSharpAcZeroSpace = 500;
89const uint16_t kSharpAcOneSpace = 1400;
91
92const uint8_t kSharpAcByteTemp = 4;
93const uint8_t kSharpAcMinTemp = 15; // Celsius
94const uint8_t kSharpAcMaxTemp = 30; // Celsius
95
96const uint8_t kSharpAcPowerUnknown = 0; // 0b0000
97const uint8_t kSharpAcPowerOnFromOff = 1; // 0b0001
98const uint8_t kSharpAcPowerOff = 2; // 0b0010
99const uint8_t kSharpAcPowerOn = 3; // 0b0011 (Normal)
100const uint8_t kSharpAcPowerSetSpecialOn = 6; // 0b0110
101const uint8_t kSharpAcPowerSetSpecialOff = 7; // 0b0111
102const uint8_t kSharpAcPowerTimerSetting = 8; // 0b1000
103
104const uint8_t kSharpAcAuto = 0b00; // A907 only
105const uint8_t kSharpAcFan = 0b00; // A705 only
106const uint8_t kSharpAcDry = 0b11;
107const uint8_t kSharpAcCool = 0b10;
108const uint8_t kSharpAcHeat = 0b01; // A907 only
109const uint8_t kSharpAcFanAuto = 0b010; // 2
110const uint8_t kSharpAcFanMin = 0b100; // 4 (FAN1)
111const uint8_t kSharpAcFanMed = 0b011; // 3 (FAN2)
112const uint8_t kSharpAcFanA705Low = 0b011; // 3 (A903 too)
113const uint8_t kSharpAcFanHigh = 0b101; // 5 (FAN3)
114const uint8_t kSharpAcFanA705Med = 0b101; // 5 (A903 too)
115const uint8_t kSharpAcFanMax = 0b111; // 7 (FAN4)
116
117const uint8_t kSharpAcTimerIncrement = 30; // Mins
118const uint8_t kSharpAcTimerHoursOff = 0b0000;
119const uint8_t kSharpAcTimerHoursMax = 0b1100; // 12
120const uint8_t kSharpAcOffTimerType = 0b0;
121const uint8_t kSharpAcOnTimerType = 0b1;
122
123// Ref: https://github.com/crankyoldgit/IRremoteESP8266/discussions/1590#discussioncomment-1260213
124const uint8_t kSharpAcSwingVIgnore = 0b000; // Don't change the swing setting.
125const uint8_t kSharpAcSwingVHigh = 0b001; // 0° down. Similar to Cool Coanda.
126const uint8_t kSharpAcSwingVOff = 0b010; // Stop & Go to last fixed pos.
127const uint8_t kSharpAcSwingVMid = 0b011; // 30° down
128const uint8_t kSharpAcSwingVLow = 0b100; // 45° down
129const uint8_t kSharpAcSwingVLast = 0b101; // Same as kSharpAcSwingVOff.
130// Toggles between last fixed pos & either 75° down (Heat) or 0° down (Cool)
131// i.e. alternate between last pos <-> 75° down if in Heat mode, AND
132// alternate between last pos <-> 0° down if in Cool mode.
133// Note: `setSwingV(kSharpAcSwingVLowest)` will only allow the Lowest setting in
134// Heat mode, it will default to `kSharpAcSwingVLow` otherwise.
135// If you want to set this value in other modes e.g. Cool, you must
136// use `setSwingV`s optional `force` parameter.
137const uint8_t kSharpAcSwingVLowest = 0b110;
139const uint8_t kSharpAcSwingVToggle = 0b111; // Toggle Constant swinging on/off.
140
141const uint8_t kSharpAcSpecialPower = 0x00;
142const uint8_t kSharpAcSpecialTurbo = 0x01;
143const uint8_t kSharpAcSpecialTempEcono = 0x04;
144const uint8_t kSharpAcSpecialFan = 0x05;
145const uint8_t kSharpAcSpecialSwing = 0x06;
146const uint8_t kSharpAcSpecialTimer = 0xC0;
147const uint8_t kSharpAcSpecialTimerHalfHour = 0xDE;
148
149// Classes
152 public:
153 explicit IRSharpAc(const uint16_t pin, const bool inverted = false,
154 const bool use_modulation = true);
155#if SEND_SHARP_AC
156 void send(const uint16_t repeat = kSharpAcDefaultRepeat);
161 int8_t calibrate(void) { return _irsend.calibrate(); }
162#endif // SEND_SHARP_AC
163 void begin(void);
164 void setModel(const sharp_ac_remote_model_t model);
165 sharp_ac_remote_model_t getModel(const bool raw = false) const;
166 void on(void);
167 void off(void);
168 void setPower(const bool on, const bool prev_on = true);
169 bool getPower(void) const;
170 bool isPowerSpecial(void) const;
171 void setTemp(const uint8_t temp, const bool save = true);
172 uint8_t getTemp(void) const;
173 void setFan(const uint8_t fan, const bool save = true);
174 uint8_t getFan(void) const;
175 void setMode(const uint8_t mode, const bool save = true);
176 uint8_t getMode(void) const;
177 void setSpecial(const uint8_t mode);
178 uint8_t getSpecial(void) const;
179 bool getTurbo(void) const;
180 void setTurbo(const bool on);
181 bool getSwingToggle(void) const;
182 void setSwingToggle(const bool on);
183 uint8_t getSwingV(void) const;
184 void setSwingV(const uint8_t position, const bool force = false);
185 bool getIon(void) const;
186 void setIon(const bool on);
187 bool getEconoToggle(void) const;
188 void setEconoToggle(const bool on);
189 bool getLightToggle(void) const;
190 void setLightToggle(const bool on);
191 uint16_t getTimerTime(void) const;
192 bool getTimerEnabled(void) const;
193 bool getTimerType(void) const;
194 void setTimer(bool enable, bool timer_type, uint16_t mins);
195 bool getClean(void) const;
196 void setClean(const bool on);
197 uint8_t* getRaw(void);
198 void setRaw(const uint8_t new_code[],
199 const uint16_t length = kSharpAcStateLength);
200 static bool validChecksum(uint8_t state[],
201 const uint16_t length = kSharpAcStateLength);
202 static uint8_t convertMode(const stdAc::opmode_t mode);
203 static uint8_t convertFan(const stdAc::fanspeed_t speed,
204 const sharp_ac_remote_model_t model =
206 static uint8_t convertSwingV(const stdAc::swingv_t position);
207 stdAc::opmode_t toCommonMode(const uint8_t mode) const;
208 stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed) const;
210 const uint8_t pos,
211 const stdAc::opmode_t mode = stdAc::opmode_t::kHeat) const;
212 stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const;
213 String toString(void) const;
214#ifndef UNIT_TEST
215
216 private:
218#else // UNIT_TEST
220 IRsendTest _irsend;
222#endif // UNIT_TEST
224 uint8_t _temp;
225 uint8_t _mode;
226 uint8_t _fan;
228 void stateReset(void);
229 void checksum(void);
230 static uint8_t calcChecksum(uint8_t state[],
231 const uint16_t length = kSharpAcStateLength);
232 void setPowerSpecial(const uint8_t value);
233 uint8_t getPowerSpecial(void) const;
234 void clearPowerSpecial(void);
235 bool _getEconoToggle(void) const;
236 void _setEconoToggle(const bool on);
237};
238
239#endif // IR_SHARP_H_
std::string String
The protocol code builds human readable output with String. On ESP-IDF that is just std::string.
Definition IRplatform.h:21
const uint16_t kSharpAcStateLength
Definition IRremoteESP8266.h:1406
const uint16_t kSharpAcDefaultRepeat
Definition IRremoteESP8266.h:1408
sharp_ac_remote_model_t
Sharp A/C model numbers.
Definition IRsend.h:198
@ A907
Definition IRsend.h:199
const uint32_t kDefaultMessageGap
Definition IRsend.h:42
Class for handling detailed Sharp A/C messages.
Definition ir_Sharp.h:151
bool getLightToggle(void) const
Get the Light toggle setting of the A/C.
Definition ir_Sharp.cpp:670
void setSwingToggle(const bool on)
Set the (vertical) Swing Toggle setting of the A/C.
Definition ir_Sharp.cpp:610
IRsend _irsend
Instance of the IR send class.
Definition ir_Sharp.h:217
void setTemp(const uint8_t temp, const bool save=true)
Set the temperature.
Definition ir_Sharp.cpp:430
uint8_t _mode
Saved copy of the desired mode.
Definition ir_Sharp.h:225
void off(void)
Set the requested power state of the A/C to off.
Definition ir_Sharp.cpp:382
uint16_t getTimerTime(void) const
Get how long the timer is set for, in minutes.
Definition ir_Sharp.cpp:676
uint8_t _temp
Saved copy of the desired temp.
Definition ir_Sharp.h:224
bool getClean(void) const
Get the Clean setting of the A/C.
Definition ir_Sharp.cpp:714
sharp_ac_remote_model_t getModel(const bool raw=false) const
Get/Detect the model of the A/C.
Definition ir_Sharp.cpp:335
void setSwingV(const uint8_t position, const bool force=false)
Set the Vertical Swing setting of the A/C.
Definition ir_Sharp.cpp:563
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition ir_Sharp.cpp:738
void setModel(const sharp_ac_remote_model_t model)
Set the model of the A/C to emulate.
Definition ir_Sharp.cpp:316
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition ir_Sharp.cpp:462
bool getEconoToggle(void) const
Get the Economical mode toggle setting of the A/C.
Definition ir_Sharp.cpp:655
void clearPowerSpecial(void)
Clear the "special"/non-normal bits in the power section. e.g. for normal/common command modes.
Definition ir_Sharp.cpp:363
uint8_t getSpecial(void) const
Get the value of the Special (button/command?) setting.
Definition ir_Sharp.cpp:425
stdAc::opmode_t toCommonMode(const uint8_t mode) const
Convert a native mode into its stdAc equivalent.
Definition ir_Sharp.cpp:779
stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed) const
Convert a native fan speed into its stdAc equivalent.
Definition ir_Sharp.cpp:797
SharpProtocol _
Definition ir_Sharp.h:223
bool _getEconoToggle(void) const
Get the Economical mode toggle setting of the A/C.
Definition ir_Sharp.cpp:630
void setFan(const uint8_t fan, const bool save=true)
Set the speed of the fan.
Definition ir_Sharp.cpp:509
void on(void)
Set the requested power state of the A/C to on.
Definition ir_Sharp.cpp:379
stdAc::state_t toCommon(const stdAc::state_t *prev=NULL) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition ir_Sharp.cpp:841
bool getPower(void) const
Get the value of the current power setting.
Definition ir_Sharp.cpp:397
bool getIon(void) const
Get the Ion (Filter) setting of the A/C.
Definition ir_Sharp.cpp:617
bool getTurbo(void) const
Get the Turbo setting of the A/C.
Definition ir_Sharp.cpp:535
void setPower(const bool on, const bool prev_on=true)
Change the power setting, including the previous power state.
Definition ir_Sharp.cpp:387
static uint8_t convertFan(const stdAc::fanspeed_t speed, const sharp_ac_remote_model_t model=sharp_ac_remote_model_t::A907)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition ir_Sharp.cpp:752
void setLightToggle(const bool on)
Set the Light mode toggle setting of the A/C.
Definition ir_Sharp.cpp:663
void send(const uint16_t repeat=kSharpAcDefaultRepeat)
Send the current internal state as an IR message.
Definition ir_Sharp.cpp:257
void setTimer(bool enable, bool timer_type, uint16_t mins)
Set or cancel the timer function.
Definition ir_Sharp.cpp:695
void setRaw(const uint8_t new_code[], const uint16_t length=kSharpAcStateLength)
Set the internal state from a valid code for this protocol.
Definition ir_Sharp.cpp:309
void setTurbo(const bool on)
Set the Turbo setting of the A/C.
Definition ir_Sharp.cpp:545
uint8_t getSwingV(void) const
Get the Vertical Swing setting of the A/C.
Definition ir_Sharp.cpp:553
sharp_ac_remote_model_t _model
Saved copy of the model.
Definition ir_Sharp.h:227
void _setEconoToggle(const bool on)
Set the Economical mode toggle setting of the A/C.
Definition ir_Sharp.cpp:639
String toString(void) const
Convert the current internal state into a human readable string.
Definition ir_Sharp.cpp:870
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition ir_Sharp.cpp:301
void stateReset(void)
Reset the state of the remote to a known good state/sequence.
Definition ir_Sharp.cpp:288
void setMode(const uint8_t mode, const bool save=true)
Set the operating mode of the A/C.
Definition ir_Sharp.cpp:469
stdAc::swingv_t toCommonSwingV(const uint8_t pos, const stdAc::opmode_t mode=stdAc::opmode_t::kHeat) const
Convert a native vertical swing postion to it's common equivalent.
Definition ir_Sharp.cpp:821
void begin(void)
Set up hardware to be able to send a message.
Definition ir_Sharp.cpp:252
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition ir_Sharp.h:161
static bool validChecksum(uint8_t state[], const uint16_t length=kSharpAcStateLength)
Verify the checksum is valid for a given state.
Definition ir_Sharp.cpp:277
void setClean(const bool on)
Set the Economical mode toggle setting of the A/C.
Definition ir_Sharp.cpp:721
uint8_t _fan
Saved copy of the desired fan speed.
Definition ir_Sharp.h:226
static uint8_t convertSwingV(const stdAc::swingv_t position)
Convert a standard A/C vertical swing into its native setting.
Definition ir_Sharp.cpp:589
void setSpecial(const uint8_t mode)
Set the value of the Special (button/command?) setting.
Definition ir_Sharp.cpp:407
void checksum(void)
Calculate and set the checksum values for the internal state.
Definition ir_Sharp.cpp:283
uint8_t getFan(void) const
Get the current fan speed setting.
Definition ir_Sharp.cpp:529
bool isPowerSpecial(void) const
Is one of the special power states in use?
Definition ir_Sharp.cpp:369
void setEconoToggle(const bool on)
Set the Economical mode toggle setting of the A/C.
Definition ir_Sharp.cpp:648
bool getTimerEnabled(void) const
Is the Timer enabled?
Definition ir_Sharp.cpp:684
bool getTimerType(void) const
Get the current timer type.
Definition ir_Sharp.cpp:688
bool getSwingToggle(void) const
Get the (vertical) Swing Toggle setting of the A/C.
Definition ir_Sharp.cpp:604
static uint8_t calcChecksum(uint8_t state[], const uint16_t length=kSharpAcStateLength)
Calculate the checksum for a given state.
Definition ir_Sharp.cpp:266
void setIon(const bool on)
Set the Ion (Filter) setting of the A/C.
Definition ir_Sharp.cpp:621
void setPowerSpecial(const uint8_t value)
Set the value of the Power Special setting without any checks.
Definition ir_Sharp.cpp:351
uint8_t getTemp(void) const
Get the current temperature setting.
Definition ir_Sharp.cpp:456
uint8_t getPowerSpecial(void) const
Get the value of the Power Special setting.
Definition ir_Sharp.cpp:357
Class for sending all basic IR protocols.
Definition IRsend.h:256
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition IRsend.cpp:286
const uint8_t kSharpAcSwingVHigh
Definition ir_Sharp.h:125
const uint16_t kSharpAcHdrSpace
Definition ir_Sharp.h:86
const uint8_t kSharpAcByteTemp
Definition ir_Sharp.h:92
const uint8_t kSharpAcSpecialTimerHalfHour
Definition ir_Sharp.h:147
const uint8_t kSharpAcPowerTimerSetting
Definition ir_Sharp.h:102
const uint16_t kSharpAcOneSpace
Definition ir_Sharp.h:89
const uint8_t kSharpAcFanMin
Definition ir_Sharp.h:110
const uint8_t kSharpAcSpecialTurbo
Definition ir_Sharp.h:142
const uint8_t kSharpAcFanAuto
Definition ir_Sharp.h:109
const uint8_t kSharpAcSpecialSwing
Definition ir_Sharp.h:145
const uint8_t kSharpAcSwingVIgnore
Definition ir_Sharp.h:124
const uint8_t kSharpAcTimerHoursOff
Definition ir_Sharp.h:118
const uint8_t kSharpAcFanA705Low
Definition ir_Sharp.h:112
const uint8_t kSharpAcFan
Definition ir_Sharp.h:105
const uint8_t kSharpAcSwingVToggle
Definition ir_Sharp.h:139
const uint8_t kSharpAcDry
Definition ir_Sharp.h:106
const uint16_t kSharpAcZeroSpace
Definition ir_Sharp.h:88
const uint8_t kSharpAcSpecialTimer
Definition ir_Sharp.h:146
const uint8_t kSharpAcPowerOff
Definition ir_Sharp.h:98
const uint8_t kSharpAcTimerHoursMax
Definition ir_Sharp.h:119
const uint8_t kSharpAcPowerSetSpecialOn
Definition ir_Sharp.h:100
const uint8_t kSharpAcSpecialFan
Definition ir_Sharp.h:144
const uint8_t kSharpAcMaxTemp
Definition ir_Sharp.h:94
const uint8_t kSharpAcSwingVMid
Definition ir_Sharp.h:127
const uint8_t kSharpAcFanMed
Definition ir_Sharp.h:111
const uint32_t kSharpAcGap
Definition ir_Sharp.h:90
const uint8_t kSharpAcSwingVLow
Definition ir_Sharp.h:128
const uint8_t kSharpAcFanA705Med
Definition ir_Sharp.h:114
const uint8_t kSharpAcSpecialPower
Definition ir_Sharp.h:141
const uint8_t kSharpAcFanMax
Definition ir_Sharp.h:115
const uint8_t kSharpAcPowerSetSpecialOff
Definition ir_Sharp.h:101
const uint8_t kSharpAcSwingVCoanda
Definition ir_Sharp.h:138
const uint8_t kSharpAcSwingVLast
Definition ir_Sharp.h:129
const uint8_t kSharpAcSwingVOff
Definition ir_Sharp.h:126
const uint8_t kSharpAcPowerUnknown
Definition ir_Sharp.h:96
const uint8_t kSharpAcHeat
Definition ir_Sharp.h:108
const uint8_t kSharpAcAuto
Definition ir_Sharp.h:104
const uint8_t kSharpAcSwingVLowest
Definition ir_Sharp.h:137
const uint8_t kSharpAcMinTemp
Definition ir_Sharp.h:93
const uint8_t kSharpAcOffTimerType
Definition ir_Sharp.h:120
const uint8_t kSharpAcOnTimerType
Definition ir_Sharp.h:121
const uint8_t kSharpAcPowerOnFromOff
Definition ir_Sharp.h:97
const uint16_t kSharpAcBitMark
Definition ir_Sharp.h:87
const uint8_t kSharpAcCool
Definition ir_Sharp.h:107
const uint8_t kSharpAcFanHigh
Definition ir_Sharp.h:113
const uint8_t kSharpAcSpecialTempEcono
Definition ir_Sharp.h:143
const uint8_t kSharpAcTimerIncrement
Definition ir_Sharp.h:117
const uint8_t kSharpAcPowerOn
Definition ir_Sharp.h:99
const uint16_t kSharpAcHdrMark
Definition ir_Sharp.h:85
fanspeed_t
Common A/C settings for Fan Speeds.
Definition IRsend.h:67
opmode_t
Common A/C settings for A/C operating modes.
Definition IRsend.h:55
swingv_t
Common A/C settings for Vertical Swing.
Definition IRsend.h:80
Structure to hold a common A/C state.
Definition IRsend.h:120
Native representation of a Sharp A/C message.
Definition ir_Sharp.h:42
uint8_t raw[kSharpAcStateLength]
State of the remote in IR code form.
Definition ir_Sharp.h:43
uint8_t pad[4]
Definition ir_Sharp.h:46
uint8_t Mode
Definition ir_Sharp.h:55
uint8_t Temp
Definition ir_Sharp.h:48
uint8_t Sum
Definition ir_Sharp.h:80
uint8_t Model2
Definition ir_Sharp.h:76
uint8_t Special
Definition ir_Sharp.h:71
uint8_t TimerHours
Definition ir_Sharp.h:61
uint8_t PowerSpecial
Definition ir_Sharp.h:53
uint8_t Swing
Definition ir_Sharp.h:66
uint8_t TimerEnabled
Definition ir_Sharp.h:64
uint8_t Fan
Definition ir_Sharp.h:58
uint8_t Model
Definition ir_Sharp.h:49
uint8_t Clean
Definition ir_Sharp.h:57
uint8_t Ion
Definition ir_Sharp.h:74
uint8_t TimerType
Definition ir_Sharp.h:63