ESPHome 2025.5.0
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 {
6namespace remote_base {
7
8static const char *const TAG = "remote.samsung";
9
10static const uint32_t HEADER_HIGH_US = 4500;
11static const uint32_t HEADER_LOW_US = 4500;
12static const uint32_t BIT_HIGH_US = 560;
13static const uint32_t BIT_ONE_LOW_US = 1690;
14static const uint32_t BIT_ZERO_LOW_US = 560;
15static const uint32_t FOOTER_HIGH_US = 560;
16static const uint32_t FOOTER_LOW_US = 560;
17
19 dst->set_carrier_frequency(38000);
20 dst->reserve(4 + data.nbits * 2u);
21
22 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
23
24 for (uint8_t bit = data.nbits; bit > 0; bit--) {
25 if ((data.data >> (bit - 1)) & 1) {
26 dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
27 } else {
28 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
29 }
30 }
31
32 dst->item(FOOTER_HIGH_US, FOOTER_LOW_US);
33}
35 SamsungData out{
36 .data = 0,
37 .nbits = 0,
38 };
39 if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
40 return {};
41
42 for (out.nbits = 0; out.nbits < 64; out.nbits++) {
43 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
44 out.data = (out.data << 1) | 1;
45 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
46 out.data = (out.data << 1) | 0;
47 } else if (out.nbits >= 31) {
48 if (!src.expect_mark(FOOTER_HIGH_US))
49 return {};
50 return out;
51 } else {
52 return {};
53 }
54 }
55
56 if (!src.expect_mark(FOOTER_HIGH_US))
57 return {};
58 return out;
59}
61 ESP_LOGI(TAG, "Received Samsung: data=0x%" PRIX64 ", nbits=%d", data.data, data.nbits);
62}
63
64} // namespace remote_base
65} // namespace esphome
bool expect_item(uint32_t mark, uint32_t space)
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:34
void item(uint32_t mark, uint32_t space)
Definition remote_base.h:29
optional< SamsungData > decode(RemoteReceiveData src) override
void encode(RemoteTransmitData *dst, const SamsungData &data) override
void dump(const SamsungData &data) override
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7