ESPHome  2024.11.1
jvc_protocol.cpp
Go to the documentation of this file.
1 #include "jvc_protocol.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace remote_base {
6 
7 static const char *const TAG = "remote.jvc";
8 
9 static const uint8_t NBITS = 16;
10 static const uint32_t HEADER_HIGH_US = 8400;
11 static const uint32_t HEADER_LOW_US = 4200;
12 static const uint32_t BIT_ONE_LOW_US = 1725;
13 static const uint32_t BIT_ZERO_LOW_US = 525;
14 static const uint32_t BIT_HIGH_US = 525;
15 
17  dst->set_carrier_frequency(38000);
18  dst->reserve(2 + NBITS * 2u);
19 
20  dst->item(HEADER_HIGH_US, HEADER_LOW_US);
21 
22  for (uint32_t mask = 1UL << (NBITS - 1); mask != 0; mask >>= 1) {
23  if (data.data & mask) {
24  dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
25  } else {
26  dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
27  }
28  }
29 
30  dst->mark(BIT_HIGH_US);
31 }
33  JVCData out{.data = 0};
34  if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
35  return {};
36 
37  for (uint8_t i = 0; i < NBITS; i++) {
38  out.data <<= 1UL;
39  if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
40  out.data |= 1UL;
41  } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
42  out.data |= 0UL;
43  } else {
44  return {};
45  }
46  }
47  return out;
48 }
49 void JVCProtocol::dump(const JVCData &data) { ESP_LOGI(TAG, "Received JVC: data=0x%04" PRIX32, data.data); }
50 
51 } // namespace remote_base
52 } // namespace esphome
void set_carrier_frequency(uint32_t carrier_frequency)
Definition: remote_base.h:34
optional< JVCData > decode(RemoteReceiveData src) override
void item(uint32_t mark, uint32_t space)
Definition: remote_base.h:29
void encode(RemoteTransmitData *dst, const JVCData &data) override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void dump(const JVCData &data) override
bool expect_item(uint32_t mark, uint32_t space)
Definition: remote_base.cpp:74