IRremoteESP8266
ir_Samsung.h
Go to the documentation of this file.
1 // Copyright 2018 David Conran
10 
11 // Supports:
12 // Brand: Samsung, Model: UA55H6300 TV (SAMSUNG)
13 // Brand: Samsung, Model: BN59-01178B TV remote (SAMSUNG)
14 // Brand: Samsung, Model: DB63-03556X003 remote
15 // Brand: Samsung, Model: DB93-16761C remote
16 // Brand: Samsung, Model: IEC-R03 remote
17 // Brand: Samsung, Model: AK59-00167A Bluray remote (SAMSUNG36)
18 // Brand: Samsung, Model: AH59-02692E Soundbar remote (SAMSUNG36)
19 // Brand: Samsung, Model: HW-J551 Soundbar (SAMSUNG36)
20 // Brand: Samsung, Model: AR09FSSDAWKNFA A/C (SAMSUNG_AC)
21 // Brand: Samsung, Model: AR12KSFPEWQNET A/C (SAMSUNG_AC)
22 // Brand: Samsung, Model: AR12HSSDBWKNEU A/C (SAMSUNG_AC)
23 // Brand: Samsung, Model: AR12NXCXAWKXEU A/C (SAMSUNG_AC)
24 // Brand: Samsung, Model: AR09HSFSBWKN A/C (SAMSUNG_AC)
25 // Brand: Samsung, Model: DB93-14195A remote (SAMSUNG_AC)
26 
27 #ifndef IR_SAMSUNG_H_
28 #define IR_SAMSUNG_H_
29 
30 #define __STDC_LIMIT_MACROS
31 #include <stdint.h>
32 #ifndef UNIT_TEST
33 #include <Arduino.h>
34 #endif
35 #include "IRremoteESP8266.h"
36 #include "IRsend.h"
37 #ifdef UNIT_TEST
38 #include "IRsend_test.h"
39 #endif
40 
44  struct {
45  // Byte 0
46  uint8_t :8;
47  // Byte 1
48  uint8_t :4;
49  uint8_t Quiet1 :1;
50  uint8_t Power1 :1;
51  uint8_t :2;
52  // Byte 2~4
53  uint8_t pad0[3];
54  // Byte 5
55  uint8_t :5;
56  uint8_t Quiet5 :1;
57  uint8_t :2;
58  // Byte 6
59  uint8_t :4;
60  uint8_t Power6 :2;
61  uint8_t :2;
62  // Byte 7
63  uint8_t :8;
64  // Byte 8
65  uint8_t Powerful8 :8;
66  // Byte 9
67  uint8_t :4;
68  uint8_t Swing :3;
69  uint8_t :1;
70  // Byte 10
71  uint8_t :1;
72  uint8_t Powerful10 :3;
73  uint8_t Display :1;
74  uint8_t :2;
75  uint8_t Clean10 :1;
76  // Byte 11
77  uint8_t Ion :1;
78  uint8_t Clean11 :1;
79  uint8_t :2;
80  uint8_t Temp :4;
81  // Byte 12
82  uint8_t :1;
83  uint8_t Fan :3;
84  uint8_t Mode :3;
85  uint8_t :1;
86  // Byte 13
87  uint8_t :1;
88  uint8_t Beep :1;
89  uint8_t :6;
90  };
91  struct {
92  // 1st Section
93  // Byte 0
94  uint8_t :8;
95  // Byte 1
96  uint8_t :4;
97  uint8_t Sum1Lower :4;
98  // Byte 2
99  uint8_t Sum1Upper :4;
100  uint8_t :4;
101  // Byte 3
102  uint8_t :8;
103  // Byte 4
104  uint8_t :8;
105  // Byte 5
106  uint8_t :8;
107  // Byte 6
108  uint8_t :8;
109  // 2nd Section
110  // Byte 7
111  uint8_t :8;
112  // Byte 8
113  uint8_t :4;
114  uint8_t Sum2Lower :4;
115  // Byte 9
116  uint8_t Sum2Upper :4;
117  uint8_t :4;
118  // Byte 10
119  uint8_t :1;
120  uint8_t Breeze :3; // WindFree
121  uint8_t :4;
122  // Byte 11
123  uint8_t :8;
124  // Byte 12
125  uint8_t :8;
126  // Byte 13
127  uint8_t :8;
128  // 3rd Section
129  // Byte 14
130  uint8_t :8;
131  // Byte 15
132  uint8_t :4;
133  uint8_t Sum3Lower :4;
134  // Byte 16
135  uint8_t Sum3Upper :4;
136  uint8_t :4;
137  // Byte 17
138  uint8_t :8;
139  // Byte 18
140  uint8_t :8;
141  // Byte 19
142  uint8_t :8;
143  // Byte 20
144  uint8_t :8;
145  };
146 };
147 
148 // Constants
149 const uint8_t kSamsungAcPowerfulMask8 = 0b01010000;
150 const uint8_t kSamsungAcSwingMove = 0b010;
151 const uint8_t kSamsungAcSwingStop = 0b111;
152 const uint8_t kSamsungAcPowerful10On = 0b011;
153 const uint8_t kSamsungAcBreezeOn = 0b101;
154 const uint8_t kSamsungAcMinTemp = 16; // C Mask 0b11110000
155 const uint8_t kSamsungAcMaxTemp = 30; // C Mask 0b11110000
156 const uint8_t kSamsungAcAutoTemp = 25; // C Mask 0b11110000
157 const uint8_t kSamsungAcAuto = 0;
158 const uint8_t kSamsungAcCool = 1;
159 const uint8_t kSamsungAcDry = 2;
160 const uint8_t kSamsungAcFan = 3;
161 const uint8_t kSamsungAcHeat = 4;
162 const uint8_t kSamsungAcFanAuto = 0;
163 const uint8_t kSamsungAcFanLow = 2;
164 const uint8_t kSamsungAcFanMed = 4;
165 const uint8_t kSamsungAcFanHigh = 5;
166 const uint8_t kSamsungAcFanAuto2 = 6;
167 const uint8_t kSamsungAcFanTurbo = 7;
168 const uint16_t kSamsungAcSectionLength = 7;
169 const uint64_t kSamsungAcPowerSection = 0x1D20F00000000;
170 
171 // Classes
173 class IRSamsungAc {
174  public:
175  explicit IRSamsungAc(const uint16_t pin, const bool inverted = false,
176  const bool use_modulation = true);
177  void stateReset(const bool forcepower = true, const bool initialPower = true);
178 #if SEND_SAMSUNG_AC
179  void send(const uint16_t repeat = kSamsungAcDefaultRepeat,
180  const bool calcchecksum = true);
181  void sendExtended(const uint16_t repeat = kSamsungAcDefaultRepeat,
182  const bool calcchecksum = true);
183  void sendOn(const uint16_t repeat = kSamsungAcDefaultRepeat);
184  void sendOff(const uint16_t repeat = kSamsungAcDefaultRepeat);
189  int8_t calibrate(void) { return _irsend.calibrate(); }
190 #endif // SEND_SAMSUNG_AC
191  void begin(void);
192  void on(void);
193  void off(void);
194  void setPower(const bool on);
195  bool getPower(void) const;
196  void setTemp(const uint8_t temp);
197  uint8_t getTemp(void) const;
198  void setFan(const uint8_t speed);
199  uint8_t getFan(void) const;
200  void setMode(const uint8_t mode);
201  uint8_t getMode(void) const;
202  void setSwing(const bool on);
203  bool getSwing(void) const;
204  void setBeep(const bool on);
205  bool getBeep(void) const;
206  void setClean(const bool on);
207  bool getClean(void) const;
208  void setQuiet(const bool on);
209  bool getQuiet(void) const;
210  void setPowerful(const bool on);
211  bool getPowerful(void) const;
212  void setBreeze(const bool on);
213  bool getBreeze(void) const;
214  void setDisplay(const bool on);
215  bool getDisplay(void) const;
216  void setIon(const bool on);
217  bool getIon(void) const;
218  uint8_t* getRaw(void);
219  void setRaw(const uint8_t new_code[],
220  const uint16_t length = kSamsungAcStateLength);
221  static uint8_t calcSectionChecksum(const uint8_t *section);
222  static uint8_t getSectionChecksum(const uint8_t *section);
223  static bool validChecksum(const uint8_t state[],
224  const uint16_t length = kSamsungAcStateLength);
225  static uint8_t convertMode(const stdAc::opmode_t mode);
226  static uint8_t convertFan(const stdAc::fanspeed_t speed);
227  static stdAc::opmode_t toCommonMode(const uint8_t mode);
228  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
229  stdAc::state_t toCommon(void) const;
230  String toString(void) const;
231 #ifndef UNIT_TEST
232 
233  private:
235 #else // UNIT_TEST
236  IRsendTest _irsend;
238 #endif // UNIT_TEST
241  bool _forcepower;
243  void checksum(void);
244 };
245 
246 #endif // IR_SAMSUNG_H_
IRSamsungAc::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Samsung.cpp:708
kSamsungAcDry
const uint8_t kSamsungAcDry
Definition: ir_Samsung.h:159
IRSamsungAc
Class for handling detailed Samsung A/C messages.
Definition: ir_Samsung.h:173
IRSamsungAc::_forcepower
bool _forcepower
Hack to know when we need to send a special power mesg.
Definition: ir_Samsung.h:241
kSamsungAcCool
const uint8_t kSamsungAcCool
Definition: ir_Samsung.h:158
SamsungProtocol::Sum2Upper
uint8_t Sum2Upper
Definition: ir_Samsung.h:116
SamsungProtocol
Native representation of a Samsung A/C message.
Definition: ir_Samsung.h:42
IRSamsungAc::getIon
bool getIon(void) const
Get the Ion (Filter) setting of the A/C.
Definition: ir_Samsung.cpp:643
IRSamsungAc::setQuiet
void setQuiet(const bool on)
Set the Quiet setting of the A/C.
Definition: ir_Samsung.cpp:574
kSamsungAcFanMed
const uint8_t kSamsungAcFanMed
Definition: ir_Samsung.h:164
IRSamsungAc::send
void send(const uint16_t repeat=kSamsungAcDefaultRepeat, const bool calcchecksum=true)
Send the current internal state as an IR message.
Definition: ir_Samsung.cpp:357
kSamsungAcFanAuto2
const uint8_t kSamsungAcFanAuto2
Definition: ir_Samsung.h:166
kSamsungAcAuto
const uint8_t kSamsungAcAuto
Definition: ir_Samsung.h:157
IRSamsungAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Samsung.h:234
IRSamsungAc::checksum
void checksum(void)
Update the checksum for the internal state.
Definition: ir_Samsung.cpp:339
IRSamsungAc::IRSamsungAc
IRSamsungAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Samsung.cpp:271
IRSamsungAc::getPowerful
bool getPowerful(void) const
Get the Powerful (Turbo) setting of the A/C.
Definition: ir_Samsung.cpp:586
kSamsungAcFanHigh
const uint8_t kSamsungAcFanHigh
Definition: ir_Samsung.h:165
IRSamsungAc::getClean
bool getClean(void) const
Get the Clean setting of the A/C.
Definition: ir_Samsung.cpp:555
SamsungProtocol::Temp
uint8_t Temp
Definition: ir_Samsung.h:80
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:58
kSamsungAcFan
const uint8_t kSamsungAcFan
Definition: ir_Samsung.h:160
IRSamsungAc::setBreeze
void setBreeze(const bool on)
Closes the vanes over the fan outlet, to stop direct wind. Aka. WindFree.
Definition: ir_Samsung.cpp:620
SamsungProtocol::Swing
uint8_t Swing
Definition: ir_Samsung.h:68
SamsungProtocol::Ion
uint8_t Ion
Definition: ir_Samsung.h:77
kSamsungAcSwingStop
const uint8_t kSamsungAcSwingStop
Definition: ir_Samsung.h:151
kSamsungAcDefaultRepeat
const uint16_t kSamsungAcDefaultRepeat
Definition: IRremoteESP8266.h:1138
IRSamsungAc::getDisplay
bool getDisplay(void) const
Get the Display (Light/LED) setting of the A/C.
Definition: ir_Samsung.cpp:631
IRSamsungAc::_
SamsungProtocol _
Definition: ir_Samsung.h:240
kSamsungAcPowerful10On
const uint8_t kSamsungAcPowerful10On
Definition: ir_Samsung.h:152
IRsend.h
IRSamsungAc::setSwing
void setSwing(const bool on)
Set the vertical swing setting of the A/C.
Definition: ir_Samsung.cpp:537
IRSamsungAc::getQuiet
bool getQuiet(void) const
Get the Quiet setting of the A/C.
Definition: ir_Samsung.cpp:568
SamsungProtocol::Sum3Upper
uint8_t Sum3Upper
Definition: ir_Samsung.h:135
kSamsungAcSectionLength
const uint16_t kSamsungAcSectionLength
Definition: ir_Samsung.h:168
IRSamsungAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Samsung.cpp:292
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:190
IRSamsungAc::setIon
void setIon(const bool on)
Set the Ion (Filter) setting of the A/C.
Definition: ir_Samsung.cpp:649
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
IRSamsungAc::getTemp
uint8_t getTemp(void) const
Get the current temperature setting.
Definition: ir_Samsung.cpp:471
IRSamsungAc::setRaw
void setRaw(const uint8_t new_code[], const uint16_t length=kSamsungAcStateLength)
Set the internal state from a valid code for this protocol.
Definition: ir_Samsung.cpp:432
SamsungProtocol::Sum1Lower
uint8_t Sum1Lower
Definition: ir_Samsung.h:97
String
std::string String
Definition: IRremoteESP8266.h:1279
IRSamsungAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Samsung.cpp:735
IRSamsungAc::sendOff
void sendOff(const uint16_t repeat=kSamsungAcDefaultRepeat)
Send the special extended "Off" message as the library can't seem to reproduce this message automatic...
Definition: ir_Samsung.cpp:412
IRSamsungAc::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Samsung.cpp:443
IRSamsungAc::convertFan
static uint8_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Samsung.cpp:669
SamsungProtocol::Quiet1
uint8_t Quiet1
Definition: ir_Samsung.h:49
SamsungProtocol::Beep
uint8_t Beep
Definition: ir_Samsung.h:88
kSamsungAcPowerfulMask8
const uint8_t kSamsungAcPowerfulMask8
Definition: ir_Samsung.h:149
kSamsungAcStateLength
const uint16_t kSamsungAcStateLength
Definition: IRremoteESP8266.h:1134
IRSamsungAc::validChecksum
static bool validChecksum(const uint8_t state[], const uint16_t length=kSamsungAcStateLength)
Verify the checksum is valid for a given state.
Definition: ir_Samsung.cpp:325
IRSamsungAc::getBeep
bool getBeep(void) const
Get the Beep setting of the A/C.
Definition: ir_Samsung.cpp:543
IRremoteESP8266.h
SamsungProtocol::Sum3Lower
uint8_t Sum3Lower
Definition: ir_Samsung.h:133
IRSamsungAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Samsung.cpp:463
kSamsungAcPowerSection
const uint64_t kSamsungAcPowerSection
Definition: ir_Samsung.h:169
IRSamsungAc::setPowerful
void setPowerful(const bool on)
Set the Powerful (Turbo) setting of the A/C.
Definition: ir_Samsung.cpp:594
SamsungProtocol::Sum2Lower
uint8_t Sum2Lower
Definition: ir_Samsung.h:114
kSamsungAcExtendedStateLength
const uint16_t kSamsungAcExtendedStateLength
Definition: IRremoteESP8266.h:1136
SamsungProtocol::Mode
uint8_t Mode
Definition: ir_Samsung.h:84
IRSamsungAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Samsung.cpp:450
SamsungProtocol::Sum1Upper
uint8_t Sum1Upper
Definition: ir_Samsung.h:99
SamsungProtocol::Display
uint8_t Display
Definition: ir_Samsung.h:73
IRSamsungAc::setDisplay
void setDisplay(const bool on)
Set the Display (Light/LED) setting of the A/C.
Definition: ir_Samsung.cpp:637
SamsungProtocol::Clean11
uint8_t Clean11
Definition: ir_Samsung.h:78
kSamsungAcBreezeOn
const uint8_t kSamsungAcBreezeOn
Definition: ir_Samsung.h:153
IRSamsungAc::stateReset
void stateReset(const bool forcepower=true, const bool initialPower=true)
Reset the internal state of the emulation.
Definition: ir_Samsung.cpp:281
IRSamsungAc::_lastsentpowerstate
bool _lastsentpowerstate
Definition: ir_Samsung.h:242
kSamsungAcAutoTemp
const uint8_t kSamsungAcAutoTemp
Definition: ir_Samsung.h:156
kSamsungAcSwingMove
const uint8_t kSamsungAcSwingMove
Definition: ir_Samsung.h:150
IRSamsungAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Samsung.cpp:477
kSamsungAcFanLow
const uint8_t kSamsungAcFanLow
Definition: ir_Samsung.h:163
IRSamsungAc::setClean
void setClean(const bool on)
Set the Clean setting of the A/C.
Definition: ir_Samsung.cpp:561
SamsungProtocol::Breeze
uint8_t Breeze
Definition: ir_Samsung.h:120
kSamsungAcHeat
const uint8_t kSamsungAcHeat
Definition: ir_Samsung.h:161
IRSamsungAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Samsung.cpp:683
IRSamsungAc::sendOn
void sendOn(const uint16_t repeat=kSamsungAcDefaultRepeat)
Send the special extended "On" message as the library can't seem to reproduce this message automatica...
Definition: ir_Samsung.cpp:399
kSamsungAcFanAuto
const uint8_t kSamsungAcFanAuto
Definition: ir_Samsung.h:162
IRSamsungAc::setBeep
void setBeep(const bool on)
Set the Beep setting of the A/C.
Definition: ir_Samsung.cpp:549
SamsungProtocol::Power1
uint8_t Power1
Definition: ir_Samsung.h:50
IRSamsungAc::getSectionChecksum
static uint8_t getSectionChecksum(const uint8_t *section)
Get the existing checksum for a given state section.
Definition: ir_Samsung.cpp:298
IRSamsungAc::getSwing
bool getSwing(void) const
Get the vertical swing setting of the A/C.
Definition: ir_Samsung.cpp:529
SamsungProtocol::Powerful8
uint8_t Powerful8
Definition: ir_Samsung.h:65
SamsungProtocol::Powerful10
uint8_t Powerful10
Definition: ir_Samsung.h:72
IRSamsungAc::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Samsung.cpp:656
IRSamsungAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Samsung.h:189
SamsungProtocol::Fan
uint8_t Fan
Definition: ir_Samsung.h:83
IRSamsungAc::sendExtended
void sendExtended(const uint16_t repeat=kSamsungAcDefaultRepeat, const bool calcchecksum=true)
Send the extended current internal state as an IR message.
Definition: ir_Samsung.cpp:374
IRSamsungAc::calcSectionChecksum
static uint8_t calcSectionChecksum(const uint8_t *section)
Calculate the checksum for a given state section.
Definition: ir_Samsung.cpp:307
IRSamsungAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Samsung.cpp:501
kSamsungAcMaxTemp
const uint8_t kSamsungAcMaxTemp
Definition: ir_Samsung.h:155
SamsungProtocol::Clean10
uint8_t Clean10
Definition: ir_Samsung.h:75
IRSamsungAc::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Samsung.cpp:446
IRSamsungAc::getBreeze
bool getBreeze(void) const
Are the vanes closed over the fan outlet, to stop direct wind? Aka. WindFree.
Definition: ir_Samsung.cpp:612
IRSamsungAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Samsung.cpp:696
SamsungProtocol::pad0
uint8_t pad0[3]
Definition: ir_Samsung.h:53
IRSamsungAc::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Samsung.cpp:457
IRSamsungAc::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Samsung.cpp:424
kSamsungAcFanTurbo
const uint8_t kSamsungAcFanTurbo
Definition: ir_Samsung.h:167
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:97
IRSamsungAc::getFan
uint8_t getFan(void) const
Get the current fan speed setting.
Definition: ir_Samsung.cpp:521
SamsungProtocol::raw
uint8_t raw[kSamsungAcExtendedStateLength]
State in code form.
Definition: ir_Samsung.h:43
kSamsungAcMinTemp
const uint8_t kSamsungAcMinTemp
Definition: ir_Samsung.h:154
SamsungProtocol::Power6
uint8_t Power6
Definition: ir_Samsung.h:60
SamsungProtocol::Quiet5
uint8_t Quiet5
Definition: ir_Samsung.h:56
IRSamsungAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Samsung.cpp:495
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46