5 namespace remote_base {
7 static const char *
const TAG =
"remote.drayton";
9 static const uint32_t BIT_TIME_US = 500;
10 static const uint8_t CARRIER_KHZ = 2;
11 static const uint8_t NBITS_PREAMBLE = 12;
12 static const uint8_t NBITS_SYNC = 4;
13 static const uint8_t NBITS_ADDRESS = 16;
14 static const uint8_t NBITS_CHANNEL = 5;
15 static const uint8_t NBITS_COMMAND = 7;
16 static const uint8_t NDATABITS = NBITS_ADDRESS + NBITS_CHANNEL + NBITS_COMMAND;
17 static const uint8_t MIN_RX_SRC = (NDATABITS + NBITS_SYNC / 2);
19 static const uint8_t CMD_ON = 0x41;
20 static const uint8_t CMD_OFF = 0x02;
87 uint16_t khz = CARRIER_KHZ;
91 uint32_t out_data = 0x0AAA;
92 for (uint32_t mask = 1UL << (NBITS_PREAMBLE - 1); mask != 0; mask >>= 1) {
93 if (out_data & mask) {
94 dst->
mark(BIT_TIME_US);
96 dst->
space(BIT_TIME_US);
102 for (uint32_t mask = 1UL << (NBITS_SYNC - 1); mask != 0; mask >>= 1) {
103 if (out_data & mask) {
104 dst->
mark(BIT_TIME_US);
106 dst->
space(BIT_TIME_US);
110 ESP_LOGD(TAG,
"Send Drayton: address=%04x channel=%03x cmd=%02x", data.
address, data.
channel, data.
command);
113 out_data <<= NBITS_COMMAND;
115 out_data <<= NBITS_CHANNEL;
118 ESP_LOGV(TAG,
"Send Drayton: out_data %08" PRIx32, out_data);
120 for (uint32_t mask = 1UL << (NDATABITS - 1); mask != 0; mask >>= 1) {
121 if (out_data & mask) {
122 dst->
mark(BIT_TIME_US);
123 dst->
space(BIT_TIME_US);
125 dst->
space(BIT_TIME_US);
126 dst->
mark(BIT_TIME_US);
140 "Decode Drayton: %" PRId32
", %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
141 " %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
142 " %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
"",
154 ESP_LOGVV(TAG,
"Decode Drayton: sync search %d, %" PRId32
" %" PRId32, src.
size() - src.
get_index(), src.
peek(),
159 ESP_LOGVV(TAG,
"Decode Drayton: Found SYNC, - %d", src.
get_index());
168 ESP_LOGV(TAG,
"Decode Drayton: Fail 1, - %" PRIu32, src.
get_index());
175 uint32_t out_data = 0;
176 uint8_t bit = NDATABITS - 1;
177 ESP_LOGVV(TAG,
"Decode Drayton: first bit %d %" PRId32
", %" PRId32, src.
peek(0), src.
peek(1), src.
peek(2));
179 out_data |= 0 << bit;
182 out_data |= 1 << bit;
184 ESP_LOGV(TAG,
"Decode Drayton: Fail 2, - %d %d %d", src.
peek(-1), src.
peek(0), src.
peek(1));
192 ESP_LOGVV(TAG,
"Decode Drayton: Data, %2d %08" PRIx32, bit, out_data);
195 out_data |= 0 << bit;
198 out_data |= 1 << bit;
205 ESP_LOGVV(TAG,
"Decode Drayton: Fail 3, %d %" PRId32
" %" PRId32, src.
peek(-1), src.
peek(0), src.
peek(1));
217 ESP_LOGV(TAG,
"Decode Drayton: Data, %2d %08x", bit, out_data);
219 out.channel = (uint8_t) (out_data & 0x1F);
220 out_data >>= NBITS_CHANNEL;
221 out.command = (uint8_t) (out_data & 0x7F);
222 out_data >>= NBITS_COMMAND;
223 out.address = (uint16_t) (out_data & 0xFFFF);
230 ESP_LOGI(TAG,
"Received Drayton: address=0x%04X (0x%04x), channel=0x%03x command=0x%03X", data.
address,
void set_carrier_frequency(uint32_t carrier_frequency)
bool peek_space(uint32_t length, uint32_t offset=0) const
void encode(RemoteTransmitData *dst, const DraytonData &data) override
bool expect_space(uint32_t length)
bool expect_mark(uint32_t length)
bool peek_mark(uint32_t length, uint32_t offset=0) const
void mark(uint32_t length)
int32_t peek(uint32_t offset=0) const
uint32_t get_index() const
optional< DraytonData > decode(RemoteReceiveData src) override
void dump(const DraytonData &data) override
void space(uint32_t length)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
void advance(uint32_t amount=1)
bool peek_space_at_least(uint32_t length, uint32_t offset=0) const