ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
receiver_mitsubishi_heavy.cpp
Go to the documentation of this file.
2#include "heatpumpir.h"
3
4#if defined(USE_ARDUINO) || defined(USE_ESP32)
5
6#include <HeatpumpIRFactory.h>
7
8namespace esphome::heatpumpir {
9
10static constexpr uint8_t FRAME_PREFIX[5] = {0x52, 0xAE, 0xC3, 0x26, 0xD9};
11static constexpr uint8_t XOR_CHECKSUM_EXPECTED = 0xFF;
12static constexpr uint8_t PREFIX_LENGTH = 5;
13static constexpr uint8_t MODE_TEMP_BYTE = 9;
14static constexpr uint8_t MODE_MASK = 0x07;
15static constexpr uint8_t TEMP_MASK = 0x0F;
16static constexpr uint8_t TEMPERATURE_BASE = 17;
17static constexpr uint8_t TEMPERATURE_SHIFT = 4;
18static constexpr remote_base::BitTimings MITSUBISHI_HEAVY_BIT_TIMINGS{.bit_mark = MITSUBISHI_HEAVY_BIT_MARK,
19 .one_space = MITSUBISHI_HEAVY_ONE_SPACE,
20 .zero_space = MITSUBISHI_HEAVY_ZERO_SPACE};
21
22static bool read_raw_bytes(remote_base::RemoteReceiveData &data, uint8_t frame[MITSUBISHI_HEAVY_FRAME_LENGTH]) {
23 if (!data.expect_item(MITSUBISHI_HEAVY_HDR_MARK, MITSUBISHI_HEAVY_HDR_SPACE))
24 return false;
25
26 return data.expect_bytes<MITSUBISHI_HEAVY_BIT_TIMINGS>(frame, MITSUBISHI_HEAVY_FRAME_LENGTH);
27}
28
29static bool validate_prefix(const uint8_t frame[MITSUBISHI_HEAVY_FRAME_LENGTH]) {
30 for (uint8_t i = 0; i < PREFIX_LENGTH; i++) {
31 if (frame[i] != FRAME_PREFIX[i])
32 return false;
33 }
34 return true;
35}
36
37static bool validate_checksums(const uint8_t frame[MITSUBISHI_HEAVY_FRAME_LENGTH]) {
38 for (uint8_t i = PREFIX_LENGTH; i < MITSUBISHI_HEAVY_FRAME_LENGTH; i += 2) {
39 if ((uint8_t) (frame[i] ^ frame[i + 1]) != XOR_CHECKSUM_EXPECTED)
40 return false;
41 }
42 return true;
43}
44
45static bool decode_mode_field(const uint8_t frame[MITSUBISHI_HEAVY_FRAME_LENGTH], climate::ClimateMode &mode) {
46 if (frame[MODE_TEMP_BYTE] & MITSUBISHI_HEAVY_MODE_OFF) {
48 return true;
49 }
50 switch (frame[MODE_TEMP_BYTE] & MODE_MASK) {
51 case MITSUBISHI_HEAVY_MODE_AUTO:
53 return true;
54 case MITSUBISHI_HEAVY_MODE_HEAT:
56 return true;
57 case MITSUBISHI_HEAVY_MODE_COOL:
59 return true;
60 case MITSUBISHI_HEAVY_MODE_DRY:
62 return true;
63 case MITSUBISHI_HEAVY_MODE_FAN:
65 return true;
66 default:
67 return false;
68 }
69}
70
71static float decode_temperature_field(const uint8_t frame[MITSUBISHI_HEAVY_FRAME_LENGTH]) {
72 uint8_t temp_nibble = frame[MODE_TEMP_BYTE] >> TEMPERATURE_SHIFT;
73 uint8_t inverted_nibble = ~temp_nibble;
74 uint8_t temp_offset = inverted_nibble & TEMP_MASK;
75 return TEMPERATURE_BASE + temp_offset;
76}
77
78static bool apply_climate_state(const uint8_t frame[MITSUBISHI_HEAVY_FRAME_LENGTH], HeatpumpIRClimate &climate) {
80 if (!decode_mode_field(frame, mode))
81 return false;
82 climate.mode = mode;
83 climate.target_temperature = decode_temperature_field(frame);
84 return true;
85}
86
88 HeatpumpIRClimate &climate) {
89 if (!read_raw_bytes(data, frame))
90 return false;
91 if (!validate_prefix(frame))
92 return false;
93 if (!validate_checksums(frame))
94 return false;
95 return apply_climate_state(frame, climate);
96}
97
98} // namespace esphome::heatpumpir
99
100#endif
BedjetMode mode
BedJet operating mode.
ClimateMode
Enum for all modes a climate device can be in.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
bool decode_mitsubishi_heavy_frame(remote_base::RemoteReceiveData &data, uint8_t frame[MITSUBISHI_HEAVY_FRAME_LENGTH], HeatpumpIRClimate &climate)
Read a Mitsubishi Heavy frame into frame, check its prefix and inverted byte pairs,...
constexpr uint8_t MITSUBISHI_HEAVY_FRAME_LENGTH
Bytes in a Mitsubishi Heavy IR frame, prefix included.
std::span< const uint8_t > data