11static constexpr uint32_t CARRIER_FREQUENCY = 38000;
13static constexpr uint32_t HEADER_US = 19 * T_US / 2;
16static constexpr uint32_t GAP_MIN_US = HEADER_US - T_US / 4;
17static constexpr uint8_t MIN_HALF_DEGREES =
static_cast<uint8_t
>(IRA211_MIN_TEMPERATURE * 2);
18static constexpr uint8_t MAX_HALF_DEGREES =
static_cast<uint8_t
>(IRA211_MAX_TEMPERATURE * 2);
20static constexpr uint8_t DEVICE_ID = 0x66;
21static constexpr uint8_t BITS_PER_PACKET = 10;
22static constexpr uint8_t MIN_PACKETS = 4;
23static constexpr uint8_t MAX_PACKETS = 7;
24static constexpr uint8_t MAX_BITS = MAX_PACKETS * BITS_PER_PACKET;
28static constexpr uint8_t FIELD_TEMPERATURE = 1 << 0;
29static constexpr uint8_t FIELD_MODE = 1 << 1;
30static constexpr uint8_t FIELD_FAN = 1 << 2;
37static const CommandLayout LAYOUTS[] PROGMEM = {
46static optional<CommandLayout> find_layout(
IRA211Command command) {
47 for (
const auto &slot : LAYOUTS) {
50 if (layout.command == command)
57static uint8_t packet_count(
const CommandLayout &layout) {
58 return 3 + ((layout.fields & FIELD_TEMPERATURE) ? 2 : 0) + ((layout.fields & FIELD_MODE) ? 1 : 0) +
59 ((layout.fields & FIELD_FAN) ? 1 : 0);
65static bool is_known_mode(uint8_t
value) {
76static bool is_known_fan(uint8_t
value) {
90 for (uint8_t i = 0; i <
count; i++)
96 if (this->command != rhs.
command)
98 const optional<CommandLayout> layout = find_layout(this->command);
99 if (!layout.has_value())
101 if ((layout->fields & FIELD_TEMPERATURE) && this->half_degrees != rhs.
half_degrees)
103 if ((layout->fields & FIELD_MODE) && this->mode != rhs.
mode)
105 return !(layout->fields & FIELD_FAN) || this->
fan == rhs.
fan;
109 const optional<CommandLayout> layout = find_layout(data.command);
110 if (!layout.has_value())
113 uint8_t bytes[MAX_PACKETS];
115 bytes[
count++] = DEVICE_ID;
116 bytes[
count++] = wire_xform(
static_cast<uint8_t
>(data.command));
117 if (layout->fields & FIELD_TEMPERATURE) {
118 bytes[
count++] = wire_xform(data.half_degrees / 2);
119 bytes[
count++] = wire_xform((data.half_degrees & 1) ? 5 : 0);
121 if (layout->fields & FIELD_MODE)
122 bytes[
count++] = wire_xform(
static_cast<uint8_t
>(data.mode));
123 if (layout->fields & FIELD_FAN)
124 bytes[
count++] = wire_xform(
static_cast<uint8_t
>(data.fan));
131 dst->
item(HEADER_US, T_US);
132 dst->
item(T_US, HEADER_US);
137 for (uint8_t p = 0; p <
count; p++) {
138 const uint16_t packet = (1 << 9) | (bytes[p] << 1);
139 for (int8_t i = BITS_PER_PACKET - 1; i >= 0; i--) {
140 const bool bit = (packet >> i) & 1;
141 if (bit != level && run != 0) {
143 dst->
mark(run * T_US);
145 dst->
space(run * T_US);
154 dst->
space(run * T_US);
156 dst->
space(HEADER_US);
160 if (!
src.expect_item(HEADER_US, T_US) || !
src.expect_item(T_US, HEADER_US))
164 uint8_t bytes[MAX_PACKETS]{};
166 while (
src.is_valid()) {
167 const int32_t
raw =
src.peek();
168 const bool is_mark =
raw > 0;
171 if (is_mark && (!
src.is_valid(1) ||
src.peek(1) <= -
static_cast<int32_t
>(GAP_MIN_US)))
173 if (!is_mark &&
duration >= GAP_MIN_US)
176 if (run == 0 || bits + run > MAX_BITS)
178 for (
uint32_t i = 0; i < run; i++, bits++) {
179 const uint8_t
pos = bits % BITS_PER_PACKET;
180 if ((
pos == 0 && !is_mark) || (
pos == BITS_PER_PACKET - 1 && is_mark))
182 if (
pos != 0 &&
pos != BITS_PER_PACKET - 1) {
183 uint8_t &
byte = bytes[bits / BITS_PER_PACKET];
184 byte = (
byte << 1) | (is_mark ? 1 : 0);
190 const uint8_t
count = bits / BITS_PER_PACKET;
191 if (bits % BITS_PER_PACKET != 0 ||
count < MIN_PACKETS || bytes[0] != DEVICE_ID)
195 const optional<CommandLayout> layout = find_layout(
out.command);
197 ESP_LOGV(TAG,
"Invalid frame (%u bits)", bits);
203 if (layout->fields & FIELD_TEMPERATURE) {
204 const uint8_t whole = wire_xform(bytes[index++]);
205 const uint8_t tenths = wire_xform(bytes[index++]);
206 const uint16_t half_degrees = whole * 2 + (tenths >= 5 ? 1 : 0);
207 if (half_degrees < MIN_HALF_DEGREES || half_degrees > MAX_HALF_DEGREES)
209 out.half_degrees =
static_cast<uint8_t
>(half_degrees);
211 if (layout->fields & FIELD_MODE) {
212 const uint8_t
mode = wire_xform(bytes[index++]);
213 if (!is_known_mode(
mode))
217 if (layout->fields & FIELD_FAN) {
218 const uint8_t fan = wire_xform(bytes[index++]);
219 if (!is_known_fan(fan))
227PROGMEM_STRING_TABLE(IRA211CommandStrings,
"UNKNOWN",
"TEMP_UP",
"TEMP_DOWN",
"UNKNOWN",
"MODE",
"FAN",
"POWER",
233 return LOG_STR(
"Protection");
235 return LOG_STR(
"Timer");
237 return LOG_STR(
"Comfort");
239 return LOG_STR(
"Unknown");
243static const LogString *fan_to_string(
IRA211Fan fan) {
246 return LOG_STR(
"Auto");
248 return LOG_STR(
"1/3");
250 return LOG_STR(
"2/3");
252 return LOG_STR(
"3/3");
254 return LOG_STR(
"Unknown");
259 const optional<CommandLayout> layout = find_layout(data.command);
260 const uint8_t fields = layout.has_value() ? layout->fields : 0;
261 const unsigned whole = data.half_degrees / 2;
262 const unsigned tenths = (data.half_degrees & 1) ? 5 : 0;
263 const auto *command = LOG_STR_ARG(IRA211CommandStrings::get_log_str(data.command, 0));
264 if (fields == (FIELD_TEMPERATURE | FIELD_MODE | FIELD_FAN)) {
265 ESP_LOGI(TAG,
"Received IRA211: command=%s, temperature=%u.%uC, mode=%s, fan=%s", command, whole, tenths,
266 LOG_STR_ARG(mode_to_string(data.mode)), LOG_STR_ARG(fan_to_string(data.fan)));
267 }
else if (fields == FIELD_TEMPERATURE) {
268 ESP_LOGI(TAG,
"Received IRA211: command=%s, temperature=%u.%uC", command, whole, tenths);
269 }
else if (fields == FIELD_MODE) {
270 ESP_LOGI(TAG,
"Received IRA211: command=%s, mode=%s", command, LOG_STR_ARG(mode_to_string(data.mode)));
271 }
else if (fields == FIELD_FAN) {
272 ESP_LOGI(TAG,
"Received IRA211: command=%s, fan=%s", command, LOG_STR_ARG(fan_to_string(data.fan)));
274 ESP_LOGI(TAG,
"Received IRA211: command=%s", command);
BedjetMode mode
BedJet operating mode.
optional< IRA211Data > decode(RemoteReceiveData src)
void encode(RemoteTransmitData *dst, const IRA211Data &data)
void dump(const IRA211Data &data)
void space(uint32_t length)
void set_carrier_frequency(uint32_t carrier_frequency)
void mark(uint32_t length)
void item(uint32_t mark, uint32_t space)
void reserve(uint32_t len)
std::vector< uint8_t > & out
ESPHOME_LOG_TAG(TAG, "remote.abbwelcome")
@ IRA211_COMMAND_TEMP_DOWN
PROGMEM_STRING_TABLE(Hob2HoodCommandNames, "light_off", "light_on", "fan_off", "fan_low", "fan_medium", "fan_high", "fan_max", "unknown")
void progmem_memcpy(void *dst, const void *src, size_t len)
uint8_t reverse_bits(uint8_t x)
Reverse the order of 8 bits.
bool operator==(const IRA211Data &rhs) const
Compares the command and only the fields that command carries.