ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
samsung_protocol.cpp
Go to the documentation of this file.
1#include "samsung_protocol.h"
2#include "esphome/core/log.h"
3#include <cinttypes>
4
5namespace esphome::remote_base {
6
7ESPHOME_LOG_TAG(TAG, "remote.samsung");
8
9static constexpr uint32_t HEADER_HIGH_US = 4500;
10static constexpr uint32_t HEADER_LOW_US = 4500;
11static constexpr uint32_t BIT_HIGH_US = 560;
12static constexpr uint32_t BIT_ONE_LOW_US = 1690;
13static constexpr uint32_t BIT_ZERO_LOW_US = 560;
14static constexpr uint32_t FOOTER_HIGH_US = 560;
15static constexpr uint32_t FOOTER_LOW_US = 560;
16
18 dst->set_carrier_frequency(38000);
19 dst->reserve(4 + data.nbits * 2u);
20
21 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
22
23 for (uint8_t bit = data.nbits; bit > 0; bit--) {
24 if ((data.data >> (bit - 1)) & 1) {
25 dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
26 } else {
27 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
28 }
29 }
30
31 dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
32}
35 .data = 0,
36 .nbits = 0,
37 };
38 if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
39 return {};
40
41 for (out.nbits = 0; out.nbits < 64; out.nbits++) {
42 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
43 out.data = (out.data << 1) | 1;
44 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
45 out.data = (out.data << 1) | 0;
46 } else if (out.nbits >= 31) {
47 if (!src.expect_mark(FOOTER_HIGH_US))
48 return {};
49 return out;
50 } else {
51 return {};
52 }
53 }
54
55 if (!src.expect_mark(FOOTER_HIGH_US))
56 return {};
57 return out;
58}
60 ESP_LOGI(TAG, "Received Samsung: data=0x%" PRIX64 ", nbits=%d", data.data, data.nbits);
61}
62
63} // namespace esphome::remote_base
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 encode(RemoteTransmitData *dst, const SamsungData &data)
optional< SamsungData > decode(RemoteReceiveData src)
void dump(const SamsungData &data)
std::vector< uint8_t > & out
Definition gif.cpp:49
ESPHOME_LOG_TAG(TAG, "remote.abbwelcome")
const void * src
Definition hal.h:68
static void uint32_t