ESPHome 2025.5.0
Loading...
Searching...
No Matches
lg_protocol.cpp
Go to the documentation of this file.
1#include "lg_protocol.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace remote_base {
6
7static const char *const TAG = "remote.lg";
8
9static const uint32_t HEADER_HIGH_US = 8000;
10static const uint32_t HEADER_LOW_US = 4000;
11static const uint32_t BIT_HIGH_US = 600;
12static const uint32_t BIT_ONE_LOW_US = 1600;
13static const uint32_t BIT_ZERO_LOW_US = 550;
14
16 dst->set_carrier_frequency(38000);
17 dst->reserve(2 + data.nbits * 2u);
18
19 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
20
21 for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) {
22 if (data.data & 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 dst->mark(BIT_HIGH_US);
30}
32 LGData out{
33 .data = 0,
34 .nbits = 0,
35 };
36 if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
37 return {};
38
39 for (out.nbits = 0; out.nbits < 32; out.nbits++) {
40 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
41 out.data = (out.data << 1) | 1;
42 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
43 out.data = (out.data << 1) | 0;
44 } else if (out.nbits == 28) {
45 return out;
46 } else {
47 return {};
48 }
49 }
50
51 return out;
52}
53void LGProtocol::dump(const LGData &data) {
54 ESP_LOGI(TAG, "Received LG: data=0x%08" PRIX32 ", nbits=%d", data.data, data.nbits);
55}
56
57} // namespace remote_base
58} // namespace esphome
void encode(RemoteTransmitData *dst, const LGData &data) override
void dump(const LGData &data) override
optional< LGData > 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