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