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