ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
ir_transmitter.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ARDUINO
4#ifdef USE_REMOTE_TRANSMITTER
6
7namespace esphome::midea {
8
9using remote_base::RemoteTransmitterBase;
11
12class IrFollowMeData : public IrData {
13 public:
14 // Default constructor (temp: 30C, beeper: off)
15 IrFollowMeData() : IrData({MIDEA_TYPE_FOLLOW_ME, 0x82, 0x48, 0x7F, 0x1F}) {}
16 // Copy from Base
18 // Direct from temperature in celsius and beeper values
19 IrFollowMeData(uint8_t temp, bool beeper = false) : IrFollowMeData() {
20 this->set_temp(temp, false);
21 this->set_beeper(beeper);
22 }
23 // Direct from temperature, fahrenheit and beeper values
25 this->set_temp(temp, fahrenheit);
26 this->set_beeper(beeper);
27 }
28
29 /* TEMPERATURE */
30 uint8_t temp() const {
31 if (this->fahrenheit()) {
32 return this->get_value_(4) + 31;
33 }
34 return this->get_value_(4) - 1;
35 }
36 void set_temp(uint8_t val, bool fahrenheit = false) {
38 if (this->fahrenheit()) {
39 // see https://github.com/esphome/feature-requests/issues/1627#issuecomment-1365639966
40 val = esphome::clamp<uint8_t>(val, MIN_TEMP_F, MAX_TEMP_F) - 31;
41 } else {
42 val = esphome::clamp<uint8_t>(val, MIN_TEMP_C, MAX_TEMP_C) + 1;
43 }
44 this->set_value_(4, val);
45 }
46
47 /* BEEPER */
48 bool beeper() const { return this->get_value_(3, 128); }
49 void set_beeper(bool val) { this->set_mask_(3, val, 128); }
50
51 /* FAHRENHEIT */
52 bool fahrenheit() const { return this->get_value_(2, 32); }
53 void set_fahrenheit(bool val) { this->set_mask_(2, val, 32); }
54
55 protected:
56 inline static constexpr uint8_t MIN_TEMP_C = 0;
57 inline static constexpr uint8_t MAX_TEMP_C = 37;
58
59 // see
60 // https://github.com/crankyoldgit/IRremoteESP8266/blob/9bdf8abcb465268c5409db99dc83a26df64c7445/src/ir_Midea.h#L116
61 inline static constexpr uint8_t MIN_TEMP_F = 32;
62 // see
63 // https://github.com/crankyoldgit/IRremoteESP8266/blob/9bdf8abcb465268c5409db99dc83a26df64c7445/src/ir_Midea.h#L117
64 inline static constexpr uint8_t MAX_TEMP_F = 99;
65};
66
67class IrSpecialData : public IrData {
68 public:
69 IrSpecialData(uint8_t code) : IrData({MIDEA_TYPE_SPECIAL, code, 0xFF, 0xFF, 0xFF}) {}
70};
71
73 public:
74 void set_transmitter(RemoteTransmitterBase *transmitter) { this->transmitter_ = transmitter; }
75 void transmit(IrData &data) {
76 data.finalize();
77 auto transmit = this->transmitter_->transmit();
78 remote_base::MideaProtocol().encode(transmit.get_data(), data);
79 transmit.perform();
80 }
81
82 protected:
84};
85
86} // namespace esphome::midea
87
88#endif
89#endif // USE_ARDUINO
static constexpr uint8_t MAX_TEMP_F
IrFollowMeData(uint8_t temp, bool beeper=false)
static constexpr uint8_t MIN_TEMP_C
IrFollowMeData(const IrData &data)
IrFollowMeData(uint8_t temp, bool fahrenheit, bool beeper)
static constexpr uint8_t MIN_TEMP_F
void set_temp(uint8_t val, bool fahrenheit=false)
static constexpr uint8_t MAX_TEMP_C
void set_transmitter(RemoteTransmitterBase *transmitter)
RemoteTransmitterBase * transmitter_
void set_value_(uint8_t idx, uint8_t value, uint8_t mask=255, uint8_t shift=0)
uint8_t get_value_(uint8_t idx, uint8_t mask=255, uint8_t shift=0) const
void set_mask_(uint8_t idx, bool state, uint8_t mask=255)
void encode(RemoteTransmitData *dst, const MideaData &src) override
mopeka_std_values val[3]