ESPHome 2026.11.0-dev
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::remote_base {
5
6ESPHOME_LOG_TAG(TAG, "remote.lg");
7
8static constexpr uint32_t HEADER_HIGH_US = 8000;
9static constexpr uint32_t HEADER_LOW_US = 4000;
10static constexpr uint32_t BIT_HIGH_US = 600;
11static constexpr uint32_t BIT_ONE_LOW_US = 1600;
12static constexpr uint32_t BIT_ZERO_LOW_US = 550;
13
15 dst->set_carrier_frequency(38000);
16 dst->reserve(2 + data.nbits * 2u);
17
18 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
19
20 for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) {
21 if (data.data & mask) {
22 dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
23 } else {
24 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
25 }
26 }
27
28 dst->mark(BIT_HIGH_US);
29}
31 LGData out{
32 .data = 0,
33 .nbits = 0,
34 };
35 if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
36 return {};
37
38 for (out.nbits = 0; out.nbits < 32; out.nbits++) {
39 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
40 out.data = (out.data << 1) | 1;
41 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
42 out.data = (out.data << 1) | 0;
43 } else if (out.nbits == 28) {
44 return out;
45 } else {
46 return {};
47 }
48 }
49
50 return out;
51}
52void LGProtocol::dump(const LGData &data) {
53 ESP_LOGI(TAG, "Received LG: data=0x%08" PRIX32 ", nbits=%d", data.data, data.nbits);
54}
55
56} // namespace esphome::remote_base
void encode(RemoteTransmitData *dst, const LGData &data)
optional< LGData > decode(RemoteReceiveData src)
void dump(const LGData &data)
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:64
void item(uint32_t mark, uint32_t space)
Definition remote_base.h:43
std::vector< uint8_t > & out
Definition gif.cpp:49
ESPHOME_LOG_TAG(TAG, "remote.abbwelcome")
const void * src
Definition hal.h:68
static void uint32_t