ESPHome  2024.11.0
keeloq_protocol.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "remote_base.h"
5 
6 namespace esphome {
7 namespace remote_base {
8 
9 struct KeeloqData {
10  uint32_t encrypted; // 32 bit encrypted field
11  uint32_t address; // 28 bit serial number
12  uint8_t command; // Button Status S2-S1-S0-S3
13  bool repeat; // Repeated command bit
14  bool vlow; // Battery status bit
15 
16  bool operator==(const KeeloqData &rhs) const {
17  // Treat 0x10 as a special, wildcard button press
18  // This allows us to match on just the address if wanted.
19  if (address != rhs.address) {
20  return false;
21  }
22  return (rhs.command == 0x10 || command == rhs.command);
23  }
24 };
25 
26 class KeeloqProtocol : public RemoteProtocol<KeeloqData> {
27  public:
28  void encode(RemoteTransmitData *dst, const KeeloqData &data) override;
29  optional<KeeloqData> decode(RemoteReceiveData src) override;
30  void dump(const KeeloqData &data) override;
31 };
32 
34 
35 template<typename... Ts> class KeeloqAction : public RemoteTransmitterActionBase<Ts...> {
36  public:
37  TEMPLATABLE_VALUE(uint32_t, address)
38  TEMPLATABLE_VALUE(uint32_t, encrypted)
39  TEMPLATABLE_VALUE(uint8_t, command)
40  TEMPLATABLE_VALUE(bool, vlow)
41 
42  void encode(RemoteTransmitData *dst, Ts... x) override {
43  KeeloqData data{};
44  data.address = this->address_.value(x...);
45  data.encrypted = this->encrypted_.value(x...);
46  data.command = this->command_.value(x...);
47  data.vlow = this->vlow_.value(x...);
48  KeeloqProtocol().encode(dst, data);
49  }
50 };
51 
52 } // namespace remote_base
53 } // namespace esphome
DECLARE_REMOTE_PROTOCOL(AEHA) template< typename... Ts > class AEHAAction
Definition: aeha_protocol.h:27
uint16_t x
Definition: tt21100.cpp:17
bool operator==(const KeeloqData &rhs) const
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void encode(RemoteTransmitData *dst, const KeeloqData &data) override