ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
dooya_protocol.cpp
Go to the documentation of this file.
1#include "dooya_protocol.h"
2#include "esphome/core/log.h"
3
4namespace esphome::remote_base {
5
6ESPHOME_LOG_TAG(TAG, "remote.dooya");
7
8static constexpr uint32_t HEADER_HIGH_US = 5000;
9static constexpr uint32_t HEADER_LOW_US = 1500;
10static constexpr uint32_t SHORT_US = 350;
11static constexpr uint32_t LONG_US = 750;
12static constexpr BitTimings BIT_TIMINGS{.one_space = SHORT_US,
13 .zero_space = LONG_US,
15 .one_mark = LONG_US,
16 .zero_mark = SHORT_US};
17
20 dst->reserve(2 + 40 * 2u);
21
22 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
23 // 24 bit id, 8 bit channel, 4 bit button, 4 bit check
24 const uint8_t bytes[5] = {static_cast<uint8_t>(data.id >> 16), static_cast<uint8_t>(data.id >> 8),
25 static_cast<uint8_t>(data.id), data.channel,
26 static_cast<uint8_t>((data.button & 0x0F) << 4 | (data.check & 0x0F))};
27 dst->item_bytes<BIT_TIMINGS>(bytes, sizeof(bytes));
28}
30 uint8_t bytes[5];
31 if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US) || !src.expect_bytes_last_mark<BIT_TIMINGS>(bytes, sizeof(bytes)))
32 return {};
33 return DooyaData{
34 .id = encode_uint24(bytes[0], bytes[1], bytes[2]),
35 .channel = bytes[3],
36 .button = static_cast<uint8_t>(bytes[4] >> 4),
37 .check = static_cast<uint8_t>(bytes[4] & 0x0F),
38 };
39}
40void DooyaProtocol::dump(const DooyaData &data) {
41 ESP_LOGI(TAG, "Received Dooya: id=0x%08" PRIX32 ", channel=%d, button=%d, check=%d", data.id, data.channel,
42 data.button, data.check);
43}
44
45} // namespace esphome::remote_base
optional< DooyaData > decode(RemoteReceiveData src)
void encode(RemoteTransmitData *dst, const DooyaData &data)
void dump(const DooyaData &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
void item_bytes(const uint8_t *bytes, size_t len)
One item per bit of each byte.
Definition remote_base.h:49
ESPHOME_LOG_TAG(TAG, "remote.abbwelcome")
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
Definition helpers.h:1047
const void * src
Definition hal.h:68
static void uint32_t
A bit is a mark (one_mark or zero_mark, both bit_mark unless set) and a space (one_space or zero_spac...
Definition remote_base.h:29