IRremoteESP8266
ir_Bosch.h
Go to the documentation of this file.
1 // Copyright 2022 Nico Thien
5 
6 // Supports:
7 // Brand: Bosch, Model: CL3000i-Set 26 E A/C
8 // Brand: Bosch, Model: RG10A(G2S)BGEF remote
9 
10 
11 #ifndef IR_BOSCH_H_
12 #define IR_BOSCH_H_
13 
14 #define __STDC_LIMIT_MACROS
15 #include <stdint.h>
16 #include <algorithm>
17 #include <cstring>
18 #include "IRremoteESP8266.h"
19 #include "IRsend.h"
20 #include "IRrecv.h"
21 #include "IRtext.h"
22 #include "IRutils.h"
23 #ifndef UNIT_TEST
24 #include <Arduino.h>
25 #endif
26 #ifdef UNIT_TEST
27 #include "IRsend_test.h"
28 #endif
29 
30 // Constants
31 const uint16_t kBoschHdrMark = 4366;
32 const uint16_t kBoschBitMark = 502;
33 const uint16_t kBoschHdrSpace = 4415;
34 const uint16_t kBoschOneSpace = 1645;
35 const uint16_t kBoschZeroSpace = 571;
36 const uint16_t kBoschFooterSpace = 5235;
37 const uint16_t kBoschFreq = 38000; // Hz. (Guessing the most common frequency.)
38 const uint16_t kBosch144NrOfSections = 3;
39 const uint16_t kBosch144BytesPerSection = 6;
40 
45 using std::min;
46 using std::max;
47 using std::memcpy;
48 using std::memcmp;
49 
50 // Modes Bit[0] to Section 3 Bit[1-2] to Section 1
51 // ModeS3 ModeS1
52 const uint8_t kBosch144Cool = 0b000;
53 const uint8_t kBosch144Dry = 0b011;
54 const uint8_t kBosch144Auto = 0b101;
55 const uint8_t kBosch144Heat = 0b110;
56 const uint8_t kBosch144Fan = 0b010;
57 
58 // Fan Control Bit[0-5] to Section 3 Bit[6-8] to Section 1
59 // FanS3 FanS1
60 const uint16_t kBosch144Fan20 = 0b111001010;
61 const uint16_t kBosch144Fan40 = 0b100010100;
62 const uint16_t kBosch144Fan60 = 0b010011110;
63 const uint16_t kBosch144Fan80 = 0b001101000;
64 const uint16_t kBosch144Fan100 = 0b001110010;
65 const uint16_t kBosch144FanAuto = 0b101110011;
66 const uint16_t kBosch144FanAuto0 = 0b000110011;
67 
68 // Temperature
69 const uint8_t kBosch144TempMin = 16; // Celsius
70 const uint8_t kBosch144TempMax = 30; // Celsius
73  0b00001, // 16C // Bit[0] to Section 3 Bit[1-4] to Section 1
74  0b00000, // 17C // TempS3 TempS1
75  0b00010, // 18c
76  0b00110, // 19C
77  0b00100, // 20C
78  0b01100, // 21C
79  0b01110, // 22C
80  0b01010, // 23C
81  0b01000, // 24C
82  0b11000, // 25C
83  0b11010, // 26C
84  0b10010, // 27C
85  0b10000, // 28C
86  0b10100, // 29C
87  0b10110 // 30C
88 };
89 
90 // "OFF" is a 96bit-message the same as Coolix protocol
91 const uint8_t kBosch144Off[] = {0xB2, 0x4D, 0x7B, 0x84, 0xE0, 0x1F,
92  0xB2, 0x4D, 0x7B, 0x84, 0xE0, 0x1F};
93 
94 // On, 25C, Mode: Auto
96  0xB2, 0x4D, 0x1F, 0xE0, 0xC8, 0x37,
97  0xB2, 0x4D, 0x1F, 0xE0, 0xC8, 0x37,
98  0xD5, 0x65, 0x00, 0x00, 0x00, 0x3A};
99 
102  struct {
103  uint8_t :8; // Fixed value 0b10110010 / 0xB2. ############
104  uint8_t InnvertS1_1:8; // Invert byte 0b01001101 / 0x4D #
105  uint8_t :5; // not used (without timer use) #
106  uint8_t FanS1 :3; // Fan speed bits in Section 1 #
107  uint8_t InnvertS1_2:8; // Invert byte # Section 1 =
108  uint8_t :2; // not used (without timer use) # Sektion 2
109  uint8_t ModeS1 :2; // Operation mode bits S1 #
110  uint8_t TempS1 :4; // Desired temperature (Celsius) S2 #
111  uint8_t InnvertS1_3:8; // Invert byte (without timer use) ############
112 
113  uint8_t :8; // Fixed value 0b10110010 / 0xB2. ############
114  uint8_t InnvertS2_1:8; // Invert byte 0b01001101 / 0x4D #
115  uint8_t :5; // not used (without timer use) #
116  uint8_t FanS2 :3; // Fan speed bits in Section 2 #
117  uint8_t InnvertS2_2:8; // Invert byte # Section 2 =
118  uint8_t :2; // not used (without timer use) # Sektion 1
119  uint8_t ModeS2 :2; // Operation mode bits S2 #
120  uint8_t TempS2 :4; // Desired temperature (Celsius) S2 #
121  uint8_t InnvertS2_3:8; // Invert byte (without timer use) ###########
122 
123  uint8_t :8; // Fixed value 0b11010101 / 0xD5 ###########
124  uint8_t ModeS3 :1; // ModeBit in Section 3 #
125  uint8_t FanS3 :6; // Fan speed bits in Section 3 #
126  uint8_t :1; // Unknown #
127  uint8_t :7; // Unknown #
128  uint8_t Quiet :1; // Silent-Mode # Section 3
129  uint8_t :4; // Unknown #
130  uint8_t TempS3 :1; // Desired temp. Bit in Section3 #
131  uint8_t :3; // Unknown #
132  uint8_t :8; // Unknown #
133  uint8_t ChecksumS3 :8; // Checksum from byte 13-17 ###########
134  };
135 };
136 
137 // Classes
138 
141  public:
142  explicit IRBosch144AC(const uint16_t pin, const bool inverted = false,
143  const bool use_modulation = true);
144  void stateReset(void);
145 #if SEND_BOSCH144
146  void send(const uint16_t repeat = 0);
151  int8_t calibrate(void) { return _irsend.calibrate(); }
152 #endif // SEND_BOSCH144
153  void begin();
154  void setPower(const bool state);
155  bool getPower(void) const;
156  void setTemp(const uint8_t temp);
157  uint8_t getTemp(void) const;
158  void setFan(const uint16_t speed);
159  uint16_t getFan(void) const;
160  void setMode(const uint8_t mode);
161  uint8_t getMode(void) const;
162  void setQuiet(const bool on);
163  bool getQuiet(void) const;
164  uint8_t* getRaw(void);
165  void setRaw(const uint8_t new_code[],
166  const uint16_t length = kBosch144StateLength);
167  static uint8_t convertMode(const stdAc::opmode_t mode);
168  static uint16_t convertFan(const stdAc::fanspeed_t speed);
169  static stdAc::opmode_t toCommonMode(const uint8_t mode);
170  static stdAc::fanspeed_t toCommonFanSpeed(const uint16_t speed);
171  stdAc::state_t toCommon(void) const;
172  String toString(void) const;
173 #ifndef UNIT_TEST
174 
175  private:
177 #else
178  IRsendTest _irsend;
180 #endif
183 
184  // Internal State settings
185  bool powerFlag;
186 
187  void setInvertBytes();
188  void setCheckSumS3();
189  void setTempRaw(const uint8_t code);
190  uint8_t getTempRaw(void) const;
191 };
192 
193 #endif // IR_BOSCH_H_
IRBosch144AC::_
Bosch144Protocol _
The state of the IR remote in IR code form.
Definition: ir_Bosch.h:182
IRBosch144AC::calibrate
int8_t calibrate(void)
Run the calibration to calculate uSec timing offsets for this platform.
Definition: ir_Bosch.h:151
IRBosch144AC::toCommonFanSpeed
static stdAc::fanspeed_t toCommonFanSpeed(const uint16_t speed)
Convert a native fan speed into its stdAc equivalent.
Definition: ir_Bosch.cpp:211
IRBosch144AC::getFan
uint16_t getFan(void) const
Definition: ir_Bosch.cpp:127
kBoschHdrSpace
const uint16_t kBoschHdrSpace
Definition: ir_Bosch.h:33
Bosch144Protocol::ChecksumS3
uint8_t ChecksumS3
Definition: ir_Bosch.h:133
Bosch144Protocol::ModeS1
uint8_t ModeS1
Definition: ir_Bosch.h:109
kBosch144StateLength
const uint16_t kBosch144StateLength
Definition: IRremoteESP8266.h:1168
IRBosch144AC::getTempRaw
uint8_t getTempRaw(void) const
kBoschFooterSpace
const uint16_t kBoschFooterSpace
Definition: ir_Bosch.h:36
kBosch144FanAuto0
const uint16_t kBosch144FanAuto0
Definition: ir_Bosch.h:66
Bosch144Protocol::Quiet
uint8_t Quiet
Definition: ir_Bosch.h:128
stdAc::fanspeed_t
fanspeed_t
Common A/C settings for Fan Speeds.
Definition: IRsend.h:61
kBosch144TempMin
const uint8_t kBosch144TempMin
Definition: ir_Bosch.h:69
Bosch144Protocol::InnvertS2_3
uint8_t InnvertS2_3
Definition: ir_Bosch.h:121
IRBosch144AC::setTemp
void setTemp(const uint8_t temp)
Set the temperature.
Definition: ir_Bosch.cpp:103
Bosch144Protocol::TempS3
uint8_t TempS3
Definition: ir_Bosch.h:130
IRBosch144AC::setCheckSumS3
void setCheckSumS3()
Definition: ir_Bosch.cpp:274
IRBosch144AC::getRaw
uint8_t * getRaw(void)
Get a copy of the internal state as a valid code for this protocol.
Definition: ir_Bosch.cpp:68
kBosch144NrOfSections
const uint16_t kBosch144NrOfSections
Definition: ir_Bosch.h:38
IRBosch144AC::toCommonMode
static stdAc::opmode_t toCommonMode(const uint8_t mode)
Convert a native mode into its stdAc equivalent.
Definition: ir_Bosch.cpp:198
IRBosch144AC::getPower
bool getPower(void) const
Definition: ir_Bosch.cpp:92
IRsend.h
kBosch144FanAuto
const uint16_t kBosch144FanAuto
Definition: ir_Bosch.h:65
IRBosch144AC::send
void send(const uint16_t repeat=0)
Send the current internal state as an IR message.
Definition: ir_Bosch.cpp:57
kBosch144Fan40
const uint16_t kBosch144Fan40
Definition: ir_Bosch.h:61
irutils::addModeToString
String addModeToString(const uint8_t mode, const uint8_t automatic, const uint8_t cool, const uint8_t heat, const uint8_t dry, const uint8_t fan)
Create a String of human output for the given operating mode. e.g. "Mode: 1 (Cool)".
Definition: IRutils.cpp:770
IRsend
Class for sending all basic IR protocols.
Definition: IRsend.h:237
kBosch144Off
const uint8_t kBosch144Off[]
Definition: ir_Bosch.h:91
Bosch144Protocol::ModeS3
uint8_t ModeS3
Definition: ir_Bosch.h:124
IRsend::calibrate
int8_t calibrate(uint16_t hz=38000U)
Calculate & set any offsets to account for execution times during sending.
Definition: IRsend.cpp:207
kBosch144TempMax
const uint8_t kBosch144TempMax
Definition: ir_Bosch.h:70
Bosch144Protocol::TempS2
uint8_t TempS2
Definition: ir_Bosch.h:120
String
std::string String
Definition: IRremoteESP8266.h:1521
IRBosch144AC::setQuiet
void setQuiet(const bool on)
Set the Quiet mode of the A/C.
Definition: ir_Bosch.cpp:148
kBosch144Fan100
const uint16_t kBosch144Fan100
Definition: ir_Bosch.h:64
kBosch144BytesPerSection
const uint16_t kBosch144BytesPerSection
Definition: ir_Bosch.h:39
kBoschHdrMark
const uint16_t kBoschHdrMark
Definition: ir_Bosch.h:31
IRBosch144AC::begin
void begin()
Set up hardware to be able to send a message.
Definition: ir_Bosch.cpp:52
IRBosch144AC::IRBosch144AC
IRBosch144AC(const uint16_t pin, const bool inverted=false, const bool use_modulation=true)
Class constructor.
Definition: ir_Bosch.cpp:41
IRBosch144AC::getQuiet
bool getQuiet(void) const
Get the Quiet mode of the A/C.
Definition: ir_Bosch.cpp:155
IRremoteESP8266.h
IRBosch144AC::setRaw
void setRaw(const uint8_t new_code[], const uint16_t length=kBosch144StateLength)
Set the internal state from a valid code for this protocol.
Definition: ir_Bosch.cpp:77
Bosch144Protocol::FanS3
uint8_t FanS3
Definition: ir_Bosch.h:125
kBosch144Fan80
const uint16_t kBosch144Fan80
Definition: ir_Bosch.h:63
irutils::addTempToString
String addTempToString(const uint16_t degrees, const bool celsius, const bool precomma, const bool isSensorTemp)
Create a String of human output for a given temperature. e.g. "Temp: 25C".
Definition: IRutils.cpp:733
kBosch144DefaultState
const uint8_t kBosch144DefaultState[kBosch144StateLength]
Definition: ir_Bosch.h:95
IRBosch144AC::getTemp
uint8_t getTemp(void) const
Definition: ir_Bosch.cpp:109
kBoschOneSpace
const uint16_t kBoschOneSpace
Definition: ir_Bosch.h:34
Bosch144Protocol::InnvertS1_2
uint8_t InnvertS1_2
Definition: ir_Bosch.h:107
kBosch144Auto
const uint8_t kBosch144Auto
Definition: ir_Bosch.h:54
kBosch144Fan
const uint8_t kBosch144Fan
Definition: ir_Bosch.h:56
kBoschBitMark
const uint16_t kBoschBitMark
Definition: ir_Bosch.h:32
Bosch144Protocol::ModeS2
uint8_t ModeS2
Definition: ir_Bosch.h:119
IRrecv.h
Bosch144Protocol::InnvertS1_1
uint8_t InnvertS1_1
Definition: ir_Bosch.h:104
IRutils.h
Bosch144Protocol::FanS1
uint8_t FanS1
Definition: ir_Bosch.h:106
IRBosch144AC::toCommon
stdAc::state_t toCommon(void) const
Convert the current internal state into its stdAc::state_t equivalent.
Definition: ir_Bosch.cpp:224
IRBosch144AC::stateReset
void stateReset(void)
Reset the internal state to a fixed known good state.
Definition: ir_Bosch.cpp:46
IRBosch144AC::_irsend
IRsend _irsend
Instance of the IR send class.
Definition: ir_Bosch.h:176
IRBosch144AC::setMode
void setMode(const uint8_t mode)
Set the desired operation mode.
Definition: ir_Bosch.cpp:133
IRtext.h
kBosch144Fan20
const uint16_t kBosch144Fan20
Definition: ir_Bosch.h:60
IRBosch144AC::setFan
void setFan(const uint16_t speed)
Set the speed of the fan.
Definition: ir_Bosch.cpp:122
kBosch144TempMap
const uint8_t kBosch144TempMap[kBosch144TempRange]
Definition: ir_Bosch.h:72
kBosch144Dry
const uint8_t kBosch144Dry
Definition: ir_Bosch.h:53
IRBosch144AC::powerFlag
bool powerFlag
Definition: ir_Bosch.h:185
Bosch144Protocol::InnvertS1_3
uint8_t InnvertS1_3
Definition: ir_Bosch.h:111
irutils::addBoolToString
String addBoolToString(const bool value, const String label, const bool precomma)
Create a String with a colon separated flag suitable for Humans. e.g. "Power: On".
Definition: IRutils.cpp:553
IRBosch144AC::convertFan
static uint16_t convertFan(const stdAc::fanspeed_t speed)
Convert a stdAc::fanspeed_t enum into it's native speed.
Definition: ir_Bosch.cpp:178
irutils::addFanToString
String addFanToString(const uint8_t speed, const uint8_t high, const uint8_t low, const uint8_t automatic, const uint8_t quiet, const uint8_t medium, const uint8_t maximum, const uint8_t medium_high)
Create a String of human output for the given fan speed. e.g. "Fan: 0 (Auto)".
Definition: IRutils.cpp:837
IRBosch144AC::convertMode
static uint8_t convertMode(const stdAc::opmode_t mode)
Convert a stdAc::opmode_t enum into its native mode.
Definition: ir_Bosch.cpp:160
IRBosch144AC::getMode
uint8_t getMode(void) const
Definition: ir_Bosch.cpp:142
Bosch144Protocol::raw
uint8_t raw[kBosch144StateLength]
The state in IR code form.
Definition: ir_Bosch.h:101
kBosch144Fan60
const uint16_t kBosch144Fan60
Definition: ir_Bosch.h:62
Bosch144Protocol::InnvertS2_2
uint8_t InnvertS2_2
Definition: ir_Bosch.h:117
kBosch144TempRange
const uint8_t kBosch144TempRange
Definition: ir_Bosch.h:71
IRBosch144AC::toString
String toString(void) const
Convert the current internal state into a human readable string.
Definition: ir_Bosch.cpp:250
kBosch144Cool
const uint8_t kBosch144Cool
Definition: ir_Bosch.h:52
IRBosch144AC::setInvertBytes
void setInvertBytes()
Definition: ir_Bosch.cpp:268
Bosch144Protocol::TempS1
uint8_t TempS1
Definition: ir_Bosch.h:110
IRBosch144AC::setTempRaw
void setTempRaw(const uint8_t code)
Definition: ir_Bosch.cpp:96
kBoschZeroSpace
const uint16_t kBoschZeroSpace
Definition: ir_Bosch.h:35
kBoschFreq
const uint16_t kBoschFreq
Definition: ir_Bosch.h:37
Bosch144Protocol::FanS2
uint8_t FanS2
Definition: ir_Bosch.h:116
Bosch144Protocol::InnvertS2_1
uint8_t InnvertS2_1
Definition: ir_Bosch.h:114
stdAc::state_t
Structure to hold a common A/C state.
Definition: IRsend.h:114
Bosch144Protocol
Definition: ir_Bosch.h:100
kBosch144Heat
const uint8_t kBosch144Heat
Definition: ir_Bosch.h:55
IRBosch144AC::setPower
void setPower(const bool state)
Definition: ir_Bosch.cpp:88
IRBosch144AC
Class for handling detailed Bosch144 A/C messages.
Definition: ir_Bosch.h:140
stdAc::opmode_t
opmode_t
Common A/C settings for A/C operating modes.
Definition: IRsend.h:49