5 namespace remote_base {
7 static const char *
const TAG =
"remote.nec";
9 static const uint32_t HEADER_HIGH_US = 9000;
10 static const uint32_t HEADER_LOW_US = 4500;
11 static const uint32_t BIT_HIGH_US = 560;
12 static const uint32_t BIT_ONE_LOW_US = 1690;
13 static const uint32_t BIT_ZERO_LOW_US = 560;
16 ESP_LOGD(TAG,
"Sending NEC: address=0x%04X, command=0x%04X command_repeats=%d", data.
address, data.
command,
22 dst->
item(HEADER_HIGH_US, HEADER_LOW_US);
24 for (uint16_t mask = 1; mask; mask <<= 1) {
26 dst->
item(BIT_HIGH_US, BIT_ONE_LOW_US);
28 dst->
item(BIT_HIGH_US, BIT_ZERO_LOW_US);
33 for (uint16_t mask = 1; mask; mask <<= 1) {
35 dst->
item(BIT_HIGH_US, BIT_ONE_LOW_US);
37 dst->
item(BIT_HIGH_US, BIT_ZERO_LOW_US);
42 dst->
mark(BIT_HIGH_US);
50 if (!src.
expect_item(HEADER_HIGH_US, HEADER_LOW_US))
53 for (uint16_t mask = 1; mask; mask <<= 1) {
56 }
else if (src.
expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
57 data.address &= ~mask;
63 for (uint16_t mask = 1; mask; mask <<= 1) {
66 }
else if (src.
expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
67 data.command &= ~mask;
73 while (src.
peek_item(BIT_HIGH_US, BIT_ONE_LOW_US) || src.
peek_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
75 for (uint16_t mask = 1; mask; mask <<= 1) {
78 }
else if (src.
expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
86 if (command != data.command) {
90 data.command_repeats += 1;
97 ESP_LOGI(TAG,
"Received NEC: address=0x%04X, command=0x%04X command_repeats=%d", data.
address, data.
command,
optional< NECData > decode(RemoteReceiveData src) override
void set_carrier_frequency(uint32_t carrier_frequency)
void item(uint32_t mark, uint32_t space)
bool expect_mark(uint32_t length)
void dump(const NECData &data) override
void mark(uint32_t length)
bool peek_item(uint32_t mark, uint32_t space, uint32_t offset=0) const
Implementation of SPI Controller mode.
void reserve(uint32_t len)
void encode(RemoteTransmitData *dst, const NECData &data) override
bool expect_item(uint32_t mark, uint32_t space)