IRremoteESP8266
ir_Samsung.h
Go to the documentation of this file.
1 // Copyright 2018 David Conran
9 
10 // Supports:
11 // Brand: Samsung, Model: UA55H6300 TV (SAMSUNG)
12 // Brand: Samsung, Model: BN59-01178B TV remote (SAMSUNG)
13 // Brand: Samsung, Model: DB63-03556X003 remote
14 // Brand: Samsung, Model: DB93-16761C remote
15 // Brand: Samsung, Model: IEC-R03 remote
16 // Brand: Samsung, Model: AK59-00167A Bluray remote (SAMSUNG36)
17 // Brand: Samsung, Model: AH59-02692E Soundbar remote (SAMSUNG36)
18 // Brand: Samsung, Model: HW-J551 Soundbar (SAMSUNG36)
19 // Brand: Samsung, Model: AR09FSSDAWKNFA A/C (SAMSUNG_AC)
20 // Brand: Samsung, Model: AR12KSFPEWQNET A/C (SAMSUNG_AC)
21 // Brand: Samsung, Model: AR12HSSDBWKNEU A/C (SAMSUNG_AC)
22 // Brand: Samsung, Model: AR12NXCXAWKXEU A/C (SAMSUNG_AC)
23 
24 #ifndef IR_SAMSUNG_H_
25 #define IR_SAMSUNG_H_
26 
27 #define __STDC_LIMIT_MACROS
28 #include <stdint.h>
29 #ifndef UNIT_TEST
30 #include <Arduino.h>
31 #endif
32 #include "IRremoteESP8266.h"
33 #include "IRsend.h"
34 #ifdef UNIT_TEST
35 #include "IRsend_test.h"
36 #endif
37 
41  struct {
42  // Byte 0
43  uint8_t :8;
44  // Byte 1
45  uint8_t :4;
46  uint8_t Quiet1 :1;
47  uint8_t Power1 :1;
48  uint8_t :2;
49  // Byte 2~4
50  uint8_t pad0[3];
51  // Byte 5
52  uint8_t :5;
53  uint8_t Quiet5 :1;
54  uint8_t :2;
55  // Byte 6
56  uint8_t :4;
57  uint8_t Power6 :2;
58  uint8_t :2;
59  // Byte 7
60  uint8_t :8;
61  // Byte 8
62  uint8_t Powerful8 :8;
63  // Byte 9
64  uint8_t :4;
65  uint8_t Swing :3;
66  uint8_t :1;
67  // Byte 10
68  uint8_t :1;
69  uint8_t Powerful10 :3;
70  uint8_t Display :1;
71  uint8_t :2;
72  uint8_t Clean10 :1;
73  // Byte 11
74  uint8_t Ion :1;
75  uint8_t Clean11 :1;
76  uint8_t :2;
77  uint8_t Temp :4;
78  // Byte 12
79  uint8_t :1;
80  uint8_t Fan :3;
81  uint8_t Mode :3;
82  uint8_t :1;
83  // Byte 13
84  uint8_t :1;
85  uint8_t Beep :1;
86  uint8_t :6;
87  };
88  struct {
89  uint8_t :8;
90  // Byte 1
91  uint8_t :4;
92  uint8_t Sum1 :4;
93  uint8_t pad1[6];
94  // Byte 8
95  uint8_t :4;
96  uint8_t Sum2 :4;
97  uint8_t :8;
98  // Byte 10
99  uint8_t :1;
100  uint8_t Breeze :3; // WindFree
101  uint8_t :4;
102  };
103 };
104 
105 // Constants
106 const uint8_t kSamsungAcPowerfulMask8 = 0b01010000;
107 const uint8_t kSamsungAcSwingMove = 0b010;
108 const uint8_t kSamsungAcSwingStop = 0b111;
109 const uint8_t kSamsungAcPowerful10On = 0b011;
110 const uint8_t kSamsungAcBreezeOn = 0b101;
111 const uint8_t kSamsungAcMinTemp = 16; // C Mask 0b11110000
112 const uint8_t kSamsungAcMaxTemp = 30; // C Mask 0b11110000
113 const uint8_t kSamsungAcAutoTemp = 25; // C Mask 0b11110000
114 const uint8_t kSamsungAcAuto = 0;
115 const uint8_t kSamsungAcCool = 1;
116 const uint8_t kSamsungAcDry = 2;
117 const uint8_t kSamsungAcFan = 3;
118 const uint8_t kSamsungAcHeat = 4;
119 const uint8_t kSamsungAcFanAuto = 0;
120 const uint8_t kSamsungAcFanLow = 2;
121 const uint8_t kSamsungAcFanMed = 4;
122 const uint8_t kSamsungAcFanHigh = 5;
123 const uint8_t kSamsungAcFanAuto2 = 6;
124 const uint8_t kSamsungAcFanTurbo = 7;
125 const uint16_t kSamsungAcSectionLength = 7;
126 const uint64_t kSamsungAcPowerSection = 0x1D20F00000000;
127 
128 // Classes
130 class IRSamsungAc {
131  public:
132  explicit IRSamsungAc(const uint16_t pin, const bool inverted = false,
133  const bool use_modulation = true);
134  void stateReset(const bool forcepower = true, const bool initialPower = true);
135 #if SEND_SAMSUNG_AC
136  void send(const uint16_t repeat = kSamsungAcDefaultRepeat,
137  const bool calcchecksum = true);
138  void sendExtended(const uint16_t repeat = kSamsungAcDefaultRepeat,
139  const bool calcchecksum = true);
140  void sendOn(const uint16_t repeat = kSamsungAcDefaultRepeat);
141  void sendOff(const uint16_t repeat = kSamsungAcDefaultRepeat);
146  int8_t calibrate(void) { return _irsend.calibrate(); }
147 #endif // SEND_SAMSUNG_AC
148  void begin(void);
149  void on(void);
150  void off(void);
151  void setPower(const bool on);
152  bool getPower(void) const;
153  void setTemp(const uint8_t temp);
154  uint8_t getTemp(void) const;
155  void setFan(const uint8_t speed);
156  uint8_t getFan(void) const;
157  void setMode(const uint8_t mode);
158  uint8_t getMode(void) const;
159  void setSwing(const bool on);
160  bool getSwing(void) const;
161  void setBeep(const bool on);
162  bool getBeep(void) const;
163  void setClean(const bool on);
164  bool getClean(void) const;
165  void setQuiet(const bool on);
166  bool getQuiet(void) const;
167  void setPowerful(const bool on);
168  bool getPowerful(void) const;
169  void setBreeze(const bool on);
170  bool getBreeze(void) const;
171  void setDisplay(const bool on);
172  bool getDisplay(void) const;
173  void setIon(const bool on);
174  bool getIon(void) const;
175  uint8_t* getRaw(void);
176  void setRaw(const uint8_t new_code[],
177  const uint16_t length = kSamsungAcStateLength);
178  static bool validChecksum(const uint8_t state[],
179  const uint16_t length = kSamsungAcStateLength);
180  static uint8_t calcChecksum(const uint8_t state[],
181  const uint16_t length = kSamsungAcStateLength);
182  static uint8_t convertMode(const stdAc::opmode_t mode);
183  static uint8_t convertFan(const stdAc::fanspeed_t speed);
184  static stdAc::opmode_t toCommonMode(const uint8_t mode);
185  static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
186  stdAc::state_t toCommon(void) const;
187  String toString(void) const;
188 #ifndef UNIT_TEST
189 
190  private:
192 #else // UNIT_TEST
193  IRsendTest _irsend;
195 #endif // UNIT_TEST
198  bool _forcepower;
200  void checksum(const uint16_t length = kSamsungAcStateLength);
201 };
202 
203 #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:692
kSamsungAcDry
const uint8_t kSamsungAcDry
Definition: ir_Samsung.h:116
IRSamsungAc
Class for handling detailed Samsung A/C messages.
Definition: ir_Samsung.h:130
IRSamsungAc::_forcepower
bool _forcepower
Hack to know when we need to send a special power mesg.
Definition: ir_Samsung.h:198
kSamsungAcCool
const uint8_t kSamsungAcCool
Definition: ir_Samsung.h:115
SamsungProtocol
Native representation of a Samsung A/C message.
Definition: ir_Samsung.h:39
IRSamsungAc::getIon
bool getIon(void) const
Get the Ion (Filter) setting of the A/C.
Definition: ir_Samsung.cpp:627
IRSamsungAc::setQuiet
void setQuiet(const bool on)
Set the Quiet setting of the A/C.
Definition: ir_Samsung.cpp:558
kSamsungAcFanMed
const uint8_t kSamsungAcFanMed
Definition: ir_Samsung.h:121
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:341
kSamsungAcFanAuto2
const uint8_t kSamsungAcFanAuto2
Definition: ir_Samsung.h:123
kSamsungAcAuto
const uint8_t kSamsungAcAuto
Definition: ir_Samsung.h:114
IRSamsungAc::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Samsung.h:191
IRSamsungAc::IRSamsungAc
IRSamsungAc(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Samsung.cpp:270
IRSamsungAc::getPowerful
bool getPowerful(void) const
Get the Powerful (Turbo) setting of the A/C.
Definition: ir_Samsung.cpp:570
kSamsungAcFanHigh
const uint8_t kSamsungAcFanHigh
Definition: ir_Samsung.h:122
IRSamsungAc::getClean
bool getClean(void) const
Get the Clean setting of the A/C.
Definition: ir_Samsung.cpp:539
SamsungProtocol::Temp
uint8_t Temp
Definition: ir_Samsung.h:77
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:117
IRSamsungAc::setBreeze
void setBreeze(const bool on)
Closes the vanes over the fan outlet, to stop direct wind. Aka. WindFree.
Definition: ir_Samsung.cpp:604
SamsungProtocol::Swing
uint8_t Swing
Definition: ir_Samsung.h:65
SamsungProtocol::Ion
uint8_t Ion
Definition: ir_Samsung.h:74
kSamsungAcSwingStop
const uint8_t kSamsungAcSwingStop
Definition: ir_Samsung.h:108
kSamsungAcDefaultRepeat
const uint16_t kSamsungAcDefaultRepeat
Definition: IRremoteESP8266.h:1048
IRSamsungAc::getDisplay
bool getDisplay(void) const
Get the Display (Light/LED) setting of the A/C.
Definition: ir_Samsung.cpp:615
IRSamsungAc::_
SamsungProtocol _
Definition: ir_Samsung.h:197
kSamsungAcPowerful10On
const uint8_t kSamsungAcPowerful10On
Definition: ir_Samsung.h:109
IRsend.h
IRSamsungAc::setSwing
void setSwing(const bool on)
Set the vertical swing setting of the A/C.
Definition: ir_Samsung.cpp:521
IRSamsungAc::getQuiet
bool getQuiet(void) const
Get the Quiet setting of the A/C.
Definition: ir_Samsung.cpp:552
kSamsungAcSectionLength
const uint16_t kSamsungAcSectionLength
Definition: ir_Samsung.h:125
IRSamsungAc::begin
void begin(void)
Set up hardware to be able to send a message.
Definition: ir_Samsung.cpp:291
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:182
IRSamsungAc::setIon
void setIon(const bool on)
Set the Ion (Filter) setting of the A/C.
Definition: ir_Samsung.cpp:633
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:455
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:416
String
std::string String
Definition: IRremoteESP8266.h:1178
IRSamsungAc::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Samsung.cpp:719
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:396
IRSamsungAc::on
void on(void)
Set the requested power state of the A/C to on.
Definition: ir_Samsung.cpp:427
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:653
SamsungProtocol::Quiet1
uint8_t Quiet1
Definition: ir_Samsung.h:46
SamsungProtocol::Beep
uint8_t Beep
Definition: ir_Samsung.h:85
kSamsungAcPowerfulMask8
const uint8_t kSamsungAcPowerfulMask8
Definition: ir_Samsung.h:106
kSamsungAcStateLength
const uint16_t kSamsungAcStateLength
Definition: IRremoteESP8266.h:1044
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:316
IRSamsungAc::getBeep
bool getBeep(void) const
Get the Beep setting of the A/C.
Definition: ir_Samsung.cpp:527
IRremoteESP8266.h
IRSamsungAc::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Samsung.cpp:447
kSamsungAcPowerSection
const uint64_t kSamsungAcPowerSection
Definition: ir_Samsung.h:126
IRSamsungAc::setPowerful
void setPowerful(const bool on)
Set the Powerful (Turbo) setting of the A/C.
Definition: ir_Samsung.cpp:578
kSamsungAcExtendedStateLength
const uint16_t kSamsungAcExtendedStateLength
Definition: IRremoteESP8266.h:1046
SamsungProtocol::Mode
uint8_t Mode
Definition: ir_Samsung.h:81
IRSamsungAc::setPower
void setPower(const bool on)
Change the power setting.
Definition: ir_Samsung.cpp:434
SamsungProtocol::pad1
uint8_t pad1[6]
Definition: ir_Samsung.h:93
SamsungProtocol::Display
uint8_t Display
Definition: ir_Samsung.h:70
IRSamsungAc::setDisplay
void setDisplay(const bool on)
Set the Display (Light/LED) setting of the A/C.
Definition: ir_Samsung.cpp:621
SamsungProtocol::Clean11
uint8_t Clean11
Definition: ir_Samsung.h:75
kSamsungAcBreezeOn
const uint8_t kSamsungAcBreezeOn
Definition: ir_Samsung.h:110
IRSamsungAc::stateReset
void stateReset(const bool forcepower=true, const bool initialPower=true)
Reset the internal state of the emulation.
Definition: ir_Samsung.cpp:280
IRSamsungAc::calcChecksum
static uint8_t calcChecksum(const uint8_t state[], const uint16_t length=kSamsungAcStateLength)
Calculate the checksum for a given state.
Definition: ir_Samsung.cpp:297
IRSamsungAc::_lastsentpowerstate
bool _lastsentpowerstate
Definition: ir_Samsung.h:199
kSamsungAcAutoTemp
const uint8_t kSamsungAcAutoTemp
Definition: ir_Samsung.h:113
kSamsungAcSwingMove
const uint8_t kSamsungAcSwingMove
Definition: ir_Samsung.h:107
IRSamsungAc::setMode
void setMode(const uint8_t mode)
Set the operating mode of the A/C.
Definition: ir_Samsung.cpp:461
kSamsungAcFanLow
const uint8_t kSamsungAcFanLow
Definition: ir_Samsung.h:120
IRSamsungAc::setClean
void setClean(const bool on)
Set the Clean setting of the A/C.
Definition: ir_Samsung.cpp:545
SamsungProtocol::Breeze
uint8_t Breeze
Definition: ir_Samsung.h:100
kSamsungAcHeat
const uint8_t kSamsungAcHeat
Definition: ir_Samsung.h:118
IRSamsungAc::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Samsung.cpp:667
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:383
kSamsungAcFanAuto
const uint8_t kSamsungAcFanAuto
Definition: ir_Samsung.h:119
IRSamsungAc::checksum
void checksum(const uint16_t length=kSamsungAcStateLength)
Update the checksum for the internal state.
Definition: ir_Samsung.cpp:329
IRSamsungAc::setBeep
void setBeep(const bool on)
Set the Beep setting of the A/C.
Definition: ir_Samsung.cpp:533
SamsungProtocol::Power1
uint8_t Power1
Definition: ir_Samsung.h:47
SamsungProtocol::Sum1
uint8_t Sum1
Definition: ir_Samsung.h:92
IRSamsungAc::getSwing
bool getSwing(void) const
Get the vertical swing setting of the A/C.
Definition: ir_Samsung.cpp:513
SamsungProtocol::Powerful8
uint8_t Powerful8
Definition: ir_Samsung.h:62
SamsungProtocol::Powerful10
uint8_t Powerful10
Definition: ir_Samsung.h:69
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:640
IRSamsungAc::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Samsung.h:146
SamsungProtocol::Fan
uint8_t Fan
Definition: ir_Samsung.h:80
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:362
IRSamsungAc::setFan
void setFan(const uint8_t speed)
Set the speed of the fan.
Definition: ir_Samsung.cpp:485
kSamsungAcMaxTemp
const uint8_t kSamsungAcMaxTemp
Definition: ir_Samsung.h:112
SamsungProtocol::Clean10
uint8_t Clean10
Definition: ir_Samsung.h:72
SamsungProtocol::Sum2
uint8_t Sum2
Definition: ir_Samsung.h:96
IRSamsungAc::off
void off(void)
Set the requested power state of the A/C to off.
Definition: ir_Samsung.cpp:430
IRSamsungAc::getBreeze
bool getBreeze(void) const
Are the vanes closed over the fan outlet, to stop direct wind? Aka. WindFree.
Definition: ir_Samsung.cpp:596
IRSamsungAc::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Samsung.cpp:680
SamsungProtocol::pad0
uint8_t pad0[3]
Definition: ir_Samsung.h:50
IRSamsungAc::getPower
bool getPower(void) const
Get the value of the current power setting.
Definition: ir_Samsung.cpp:441
IRSamsungAc::getRaw
uint8_t * getRaw(void)
Get a PTR to the internal state/code for this protocol.
Definition: ir_Samsung.cpp:408
kSamsungAcFanTurbo
const uint8_t kSamsungAcFanTurbo
Definition: ir_Samsung.h:124
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:505
SamsungProtocol::raw
uint8_t raw[kSamsungAcExtendedStateLength]
State in code form.
Definition: ir_Samsung.h:40
kSamsungAcMinTemp
const uint8_t kSamsungAcMinTemp
Definition: ir_Samsung.h:111
SamsungProtocol::Power6
uint8_t Power6
Definition: ir_Samsung.h:57
SamsungProtocol::Quiet5
uint8_t Quiet5
Definition: ir_Samsung.h:53
IRSamsungAc::getMode
uint8_t getMode(void) const
Get the operating mode setting of the A/C.
Definition: ir_Samsung.cpp:479
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:46