ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
roomba_protocol.cpp
Go to the documentation of this file.
1#include "roomba_protocol.h"
2#include "esphome/core/log.h"
3
4namespace esphome::remote_base {
5
6static const char *const TAG = "remote.roomba";
7
8static constexpr uint8_t NBITS = 8;
9static constexpr uint32_t BIT_ONE_HIGH_US = 3000;
10static constexpr uint32_t BIT_ONE_LOW_US = 1000;
11static constexpr uint32_t BIT_ZERO_HIGH_US = BIT_ONE_LOW_US;
12static constexpr uint32_t BIT_ZERO_LOW_US = BIT_ONE_HIGH_US;
13
15 dst->set_carrier_frequency(38000);
16 dst->reserve(NBITS * 2u);
17
18 for (uint32_t mask = 1UL << (NBITS - 1); mask != 0; mask >>= 1) {
19 if (data.data & mask) {
20 dst->item(BIT_ONE_HIGH_US, BIT_ONE_LOW_US);
21 } else {
22 dst->item(BIT_ZERO_HIGH_US, BIT_ZERO_LOW_US);
23 }
24 }
25}
27 RoombaData out{.data = 0};
28
29 for (uint8_t i = 0; i < (NBITS - 1); i++) {
30 out.data <<= 1UL;
31 if (src.expect_item(BIT_ONE_HIGH_US, BIT_ONE_LOW_US)) {
32 out.data |= 1UL;
33 } else if (src.expect_item(BIT_ZERO_HIGH_US, BIT_ZERO_LOW_US)) {
34 out.data |= 0UL;
35 } else {
36 return {};
37 }
38 }
39
40 // not possible to measure space on last bit, check only mark
41 out.data <<= 1UL;
42 if (src.expect_mark(BIT_ONE_HIGH_US)) {
43 out.data |= 1UL;
44 } else if (src.expect_mark(BIT_ZERO_HIGH_US)) {
45 out.data |= 0UL;
46 } else {
47 return {};
48 }
49
50 return out;
51}
52void RoombaProtocol::dump(const RoombaData &data) { ESP_LOGD(TAG, "Received Roomba: data=0x%02X", data.data); }
53
54} // namespace esphome::remote_base
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:29
void item(uint32_t mark, uint32_t space)
Definition remote_base.h:24
void encode(RemoteTransmitData *dst, const RoombaData &data) override
void dump(const RoombaData &data) override
optional< RoombaData > decode(RemoteReceiveData src) override
const void * src
Definition hal.h:64
static void uint32_t