7 namespace remote_base {
9 static const char *
const TAG =
"remote.drayton";
11 static const uint32_t BIT_TIME_US = 500;
12 static const uint8_t CARRIER_KHZ = 2;
13 static const uint8_t NBITS_PREAMBLE = 12;
14 static const uint8_t NBITS_SYNC = 4;
15 static const uint8_t NBITS_ADDRESS = 16;
16 static const uint8_t NBITS_CHANNEL = 5;
17 static const uint8_t NBITS_COMMAND = 7;
18 static const uint8_t NDATABITS = NBITS_ADDRESS + NBITS_CHANNEL + NBITS_COMMAND;
19 static const uint8_t MIN_RX_SRC = (NDATABITS + NBITS_SYNC / 2);
21 static const uint8_t CMD_ON = 0x41;
22 static const uint8_t CMD_OFF = 0x02;
89 uint16_t khz = CARRIER_KHZ;
93 uint32_t out_data = 0x0AAA;
94 for (uint32_t mask = 1UL << (NBITS_PREAMBLE - 1); mask != 0; mask >>= 1) {
95 if (out_data & mask) {
96 dst->
mark(BIT_TIME_US);
98 dst->
space(BIT_TIME_US);
104 for (uint32_t mask = 1UL << (NBITS_SYNC - 1); mask != 0; mask >>= 1) {
105 if (out_data & mask) {
106 dst->
mark(BIT_TIME_US);
108 dst->
space(BIT_TIME_US);
112 ESP_LOGD(TAG,
"Send Drayton: address=%04x channel=%03x cmd=%02x", data.
address, data.
channel, data.
command);
115 out_data <<= NBITS_COMMAND;
117 out_data <<= NBITS_CHANNEL;
120 ESP_LOGV(TAG,
"Send Drayton: out_data %08" PRIx32, out_data);
122 for (uint32_t mask = 1UL << (NDATABITS - 1); mask != 0; mask >>= 1) {
123 if (out_data & mask) {
124 dst->
mark(BIT_TIME_US);
125 dst->
space(BIT_TIME_US);
127 dst->
space(BIT_TIME_US);
128 dst->
mark(BIT_TIME_US);
142 "Decode Drayton: %" PRId32
", %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
143 " %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
144 " %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
" %" PRId32
"",
156 ESP_LOGVV(TAG,
"Decode Drayton: sync search %" PRIu32
", %" PRId32
" %" PRId32, src.
size() - src.
get_index(),
161 ESP_LOGVV(TAG,
"Decode Drayton: Found SYNC, - %" PRIu32, src.
get_index());
170 ESP_LOGV(TAG,
"Decode Drayton: Fail 1, - %" PRIu32, src.
get_index());
177 uint32_t out_data = 0;
178 uint8_t bit = NDATABITS - 1;
179 ESP_LOGVV(TAG,
"Decode Drayton: first bit %" PRId32
" %" PRId32
", %" PRId32, src.
peek(0), src.
peek(1),
182 out_data |= 0 << bit;
185 out_data |= 1 << bit;
187 ESP_LOGV(TAG,
"Decode Drayton: Fail 2, - %" PRId32
" %" PRId32
" %" PRId32, src.
peek(-1), src.
peek(0),
196 ESP_LOGVV(TAG,
"Decode Drayton: Data, %2d %08" PRIx32, bit, out_data);
199 out_data |= 0 << bit;
202 out_data |= 1 << bit;
209 ESP_LOGVV(TAG,
"Decode Drayton: Fail 3, %" PRId32
" %" PRId32
" %" PRId32, src.
peek(-1), src.
peek(0),
222 ESP_LOGV(TAG,
"Decode Drayton: Data, %2d %08" PRIx32, bit, out_data);
224 out.channel = (uint8_t) (out_data & 0x1F);
225 out_data >>= NBITS_CHANNEL;
226 out.command = (uint8_t) (out_data & 0x7F);
227 out_data >>= NBITS_COMMAND;
228 out.address = (uint16_t) (out_data & 0xFFFF);
235 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)
Implementation of SPI Controller mode.
void advance(uint32_t amount=1)
bool peek_space_at_least(uint32_t length, uint32_t offset=0) const