14static constexpr uint8_t NBITS = 25;
15static constexpr uint32_t BIT_TIME_US = 700;
16static constexpr int32_t MARK_ADJUST_US = 300;
17static constexpr int32_t SPACE_ADJUST_US = -200;
19static constexpr uint8_t MAX_RUNS = 18;
21static constexpr std::array<Hob2HoodCommand, 7> COMMANDS = {
26PROGMEM_STRING_TABLE(Hob2HoodCommandNames,
"light_off",
"light_on",
"fan_off",
"fan_low",
"fan_medium",
"fan_high",
27 "fan_max",
"unknown");
30template<
typename F>
static bool walk_runs(
Hob2HoodCommand command, F &&emit) {
35 for (uint8_t i = 0; i < NBITS; i++, bits <<= 1) {
36 const bool bit = (bits & 0x80000000) != 0;
38 const bool last = i == NBITS - 1;
39 if (last || (((bits << 1) & 0x80000000) != 0) != bit) {
40 const uint32_t length = BIT_TIME_US * std::abs(run) + (run < 0 ? MARK_ADJUST_US : SPACE_ADJUST_US);
41 if (!emit(run < 0,
length, last))
52 walk_runs(data.command, [dst](
bool is_mark,
uint32_t length,
bool) {
63 for (
auto command : COMMANDS) {
66 const bool matched = walk_runs(command, [&
src](
bool is_mark,
uint32_t length,
bool last) {
77 while (index < COMMANDS.size() && COMMANDS[index] != data.command)
79 ESP_LOGI(TAG,
"Received Hob2Hood: %s",
80 LOG_STR_ARG(Hob2HoodCommandNames::get_log_str(index, Hob2HoodCommandNames::LAST_INDEX)));
void encode(RemoteTransmitData *dst, const Hob2HoodData &data)
void set_carrier_frequency(uint32_t carrier_frequency)
void reserve(uint32_t len)
@ HOB2HOOD_COMMAND_FAN_HIGH
@ HOB2HOOD_COMMAND_FAN_MEDIUM
@ HOB2HOOD_COMMAND_LIGHT_OFF
@ HOB2HOOD_COMMAND_FAN_MAX
@ HOB2HOOD_COMMAND_FAN_OFF
@ HOB2HOOD_COMMAND_LIGHT_ON
@ HOB2HOOD_COMMAND_FAN_LOW
ESPHOME_LOG_TAG(TAG, "remote.abbwelcome")
PROGMEM_STRING_TABLE(Hob2HoodCommandNames, "light_off", "light_on", "fan_off", "fan_low", "fan_medium", "fan_high", "fan_max", "unknown")