ESPHome  2024.11.0
magiquest_protocol.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "remote_base.h"
4 
5 #include <cinttypes>
6 
7 /* Based on protocol analysis from
8  * https://arduino-irremote.github.io/Arduino-IRremote/ir__MagiQuest_8cpp_source.html
9  */
10 
11 namespace esphome {
12 namespace remote_base {
13 
14 struct MagiQuestData {
15  uint16_t magnitude;
16  uint32_t wand_id;
17 
18  bool operator==(const MagiQuestData &rhs) const {
19  // Treat 0xffff as a special, wildcard magnitude
20  // In testing, the wand never produces this value, and this allows us to match
21  // on just the wand_id if wanted.
22  if (rhs.wand_id != this->wand_id) {
23  return false;
24  }
25  return (this->wand_id == 0xffff || rhs.wand_id == 0xffff || this->wand_id == rhs.wand_id);
26  }
27 };
28 
29 class MagiQuestProtocol : public RemoteProtocol<MagiQuestData> {
30  public:
31  void encode(RemoteTransmitData *dst, const MagiQuestData &data) override;
32  optional<MagiQuestData> decode(RemoteReceiveData src) override;
33  void dump(const MagiQuestData &data) override;
34 };
35 
37 
38 template<typename... Ts> class MagiQuestAction : public RemoteTransmitterActionBase<Ts...> {
39  public:
40  TEMPLATABLE_VALUE(uint16_t, magnitude)
41  TEMPLATABLE_VALUE(uint32_t, wand_id)
42 
43  void encode(RemoteTransmitData *dst, Ts... x) override {
44  MagiQuestData data{};
45  data.magnitude = this->magnitude_.value(x...);
46  data.wand_id = this->wand_id_.value(x...);
47  MagiQuestProtocol().encode(dst, data);
48  }
49 };
50 
51 } // namespace remote_base
52 } // namespace esphome
bool operator==(const MagiQuestData &rhs) const
DECLARE_REMOTE_PROTOCOL(AEHA) template< typename... Ts > class AEHAAction
Definition: aeha_protocol.h:27
uint16_t x
Definition: tt21100.cpp:17
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void encode(RemoteTransmitData *dst, const MagiQuestData &data) override