Skip to content

Commit

Permalink
Add Memory Timeout Callback
Browse files Browse the repository at this point in the history
  • Loading branch information
AzonInc committed Sep 23, 2024
1 parent 0bdc3d9 commit f59617f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion components/tc_bus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)

ReadMemoryCompleteTrigger = tc_bus_ns.class_("ReadMemoryCompleteTrigger", automation.Trigger.template())
ReadMemoryTimeoutTrigger = tc_bus_ns.class_("ReadMemoryTimeoutTrigger", automation.Trigger.template())

ReceivedCommandTrigger = tc_bus_ns.class_("ReceivedCommandTrigger", automation.Trigger.template())
CommandData = tc_bus_ns.struct(f"CommandData")
Expand Down Expand Up @@ -77,7 +78,8 @@
CONF_DOOR_READINESS = "door_readiness"

CONF_ON_COMMAND = "on_command_action"
CONF_ON_MEMORY = "on_memory_action"
CONF_ON_MEMORY = "on_read_memory_complete_action"
CONF_ON_MEMORY_TIMEOUT = "on_read_memory_timeout_action"
CONF_PROGRAMMING_MODE = "programming_mode"

MULTI_CONF = False
Expand Down Expand Up @@ -116,6 +118,11 @@ def validate_config(config):
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ReadMemoryCompleteTrigger),
}
),
cv.Optional(CONF_ON_MEMORY_TIMEOUT): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ReadMemoryTimeoutTrigger),
}
),
}
)
.extend(cv.COMPONENT_SCHEMA),
Expand Down Expand Up @@ -164,6 +171,9 @@ async def to_code(config):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [(cg.std_vector.template(cg.uint8), "x")], conf)

for conf in config.get(CONF_ON_MEMORY_TIMEOUT, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)



Expand Down
7 changes: 7 additions & 0 deletions components/tc_bus/automation.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,12 @@ namespace esphome
parent->add_read_memory_complete_callback([this](const std::vector<uint8_t> &value) { this->trigger(value); });
}
};

class ReadMemoryTimeoutTrigger : public Trigger<> {
public:
explicit ReadMemoryTimeoutTrigger(TCBusComponent *parent) {
parent->add_read_memory_timeout_callback([this]() { this->trigger(); });
}
};
} // namespace tc_bus
} // namespace esphome
6 changes: 6 additions & 0 deletions components/tc_bus/tc_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ namespace esphome
reading_memory_timer_ = 0;

ESP_LOGE(TAG, "Reading memory timed out!");
this->read_memory_timeout_callback_.call();
}
}

Expand Down Expand Up @@ -572,6 +573,11 @@ namespace esphome
this->read_memory_complete_callback_.add(std::move(callback));
}

void TCBusComponent::add_read_memory_timeout_callback(std::function<void()> &&callback)
{
this->read_memory_timeout_callback_.add(std::move(callback));
}

void TCBusComponent::set_programming_mode(bool enabled)
{
send_command(COMMAND_TYPE_PROGRAMMING_MODE, 0, enabled ? 1 : 0);
Expand Down
3 changes: 3 additions & 0 deletions components/tc_bus/tc_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ namespace esphome
void add_read_memory_complete_callback(std::function<void(std::vector<uint8_t>)> &&callback);
CallbackManager<void(std::vector<uint8_t>)> read_memory_complete_callback_{};

void add_read_memory_timeout_callback(std::function<void()> &&callback);
CallbackManager<void()> read_memory_timeout_callback_{};

bool sending;

protected:
Expand Down

0 comments on commit f59617f

Please sign in to comment.