Skip to content

Commit c8269dd

Browse files
committed
feat(sec-touch): add intertask delay of 30ms
1 parent 0e8f751 commit c8269dd

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

components/sec_touch/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515

1616

1717
CONF_SEC_TOUCH_ID = "sec_touch_id"
18+
CONF_INTER_TASK_DELAY = "inter_task_delay_ms"
1819
# The total of fan pairs that the SEC-Touch shows in the screen
1920

2021
CONFIG_SCHEMA = cv.Schema(
2122
{
2223
cv.GenerateID(): cv.declare_id(SECTouchComponent),
24+
cv.Optional(CONF_INTER_TASK_DELAY, default=30): cv.positive_int,
2325
}
2426
)
2527

@@ -44,3 +46,4 @@ async def to_code(config):
4446
var = cg.new_Pvariable(config[CONF_ID])
4547
await cg.register_component(var, config)
4648
await uart.register_uart_device(var, config)
49+
cg.add(var.set_inter_task_delay(config[CONF_INTER_TASK_DELAY]))

components/sec_touch/sec_touch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ void SECTouchComponent::loop() {
9090
return;
9191
}
9292

93+
if (millis() < this->task_ready_at_ms_) {
94+
return;
95+
}
9396
ESP_LOGD(TAG, "[loop] No Data available, processing task queue");
9497
this->process_task_queue();
9598
return;
@@ -448,6 +451,7 @@ void SECTouchComponent::cleanup_after_task_complete(bool failed, bool is_timeout
448451
this->current_running_task_type = TaskType::NONE;
449452
this->task_start_time_ = 0;
450453
this->last_scan_task_timed_out_ = is_timeout && this->scan_mode_active_;
454+
this->task_ready_at_ms_ = millis() + this->inter_task_delay_ms_;
451455
}
452456
} // namespace sec_touch
453457
} // namespace esphome

components/sec_touch/sec_touch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class SECTouchComponent : public PollingComponent, public uart::UARTDevice {
4747
this->manual_update_listeners.count(property_id) > 0;
4848
}
4949

50+
void set_inter_task_delay(uint32_t ms) { inter_task_delay_ms_ = ms; }
51+
5052
void add_set_task(std::unique_ptr<SetDataTask> task);
5153
void add_recursive_tasks_to_get_queue();
5254
void add_manual_tasks_to_queue();
@@ -87,6 +89,8 @@ class SECTouchComponent : public PollingComponent, public uart::UARTDevice {
8789
void send_ack_message();
8890

8991
unsigned long task_start_time_ = 0;
92+
unsigned long task_ready_at_ms_ = 0;
93+
uint32_t inter_task_delay_ms_ = 30;
9094
int current_running_task_property_id_ = -1;
9195
bool last_scan_task_timed_out_ = false;
9296
void process_data_of_current_incoming_message();

0 commit comments

Comments
 (0)