ESPHome 2025.5.0
Loading...
Searching...
No Matches
panasonic_protocol.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace remote_base {
6
7static const char *const TAG = "remote.panasonic";
8
9static const uint32_t HEADER_HIGH_US = 3502;
10static const uint32_t HEADER_LOW_US = 1750;
11static const uint32_t BIT_HIGH_US = 502;
12static const uint32_t BIT_ZERO_LOW_US = 400;
13static const uint32_t BIT_ONE_LOW_US = 1244;
14
16 dst->reserve(100);
17 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
18 dst->set_carrier_frequency(35000);
19
20 uint32_t mask;
21 for (mask = 1UL << 15; mask != 0; mask >>= 1) {
22 if (data.address & mask) {
23 dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
24 } else {
25 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
26 }
27 }
28
29 for (mask = 1UL << 31; mask != 0; mask >>= 1) {
30 if (data.command & mask) {
31 dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
32 } else {
33 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
34 }
35 }
36 dst->mark(BIT_HIGH_US);
37}
39 PanasonicData out{
40 .address = 0,
41 .command = 0,
42 };
43 if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
44 return {};
45
46 uint32_t mask;
47 for (mask = 1UL << 15; mask != 0; mask >>= 1) {
48 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
49 out.address |= mask;
50 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
51 out.address &= ~mask;
52 } else {
53 return {};
54 }
55 }
56
57 for (mask = 1UL << 31; mask != 0; mask >>= 1) {
58 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
59 out.command |= mask;
60 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
61 out.command &= ~mask;
62 } else {
63 return {};
64 }
65 }
66
67 return out;
68}
70 ESP_LOGI(TAG, "Received Panasonic: address=0x%04X, command=0x%08" PRIX32, data.address, data.command);
71}
72
73} // namespace remote_base
74} // namespace esphome
void dump(const PanasonicData &data) override
void encode(RemoteTransmitData *dst, const PanasonicData &data) override
optional< PanasonicData > decode(RemoteReceiveData src) override
bool expect_item(uint32_t mark, uint32_t space)
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:34
void item(uint32_t mark, uint32_t space)
Definition remote_base.h:29
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7