mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 17:22:20 +01:00
cleanup
This commit is contained in:
@@ -309,78 +309,77 @@ void ESP32TouchComponent::loop() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// In setup mode, periodically log all pad values
|
// In setup mode, periodically log all pad values
|
||||||
if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > SETUP_MODE_LOG_INTERVAL_MS) {
|
if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > SETUP_MODE_LOG_INTERVAL_MS) {
|
||||||
for (auto *child : this->children_) {
|
for (auto *child : this->children_) {
|
||||||
uint32_t raw = 0;
|
uint32_t raw = 0;
|
||||||
uint32_t benchmark = 0;
|
uint32_t benchmark = 0;
|
||||||
uint32_t smooth = 0;
|
uint32_t smooth = 0;
|
||||||
|
|
||||||
touch_pad_read_raw_data(child->get_touch_pad(), &raw);
|
touch_pad_read_raw_data(child->get_touch_pad(), &raw);
|
||||||
touch_pad_read_benchmark(child->get_touch_pad(), &benchmark);
|
touch_pad_read_benchmark(child->get_touch_pad(), &benchmark);
|
||||||
|
|
||||||
if (this->filter_configured_()) {
|
if (this->filter_configured_()) {
|
||||||
touch_pad_filter_read_smooth(child->get_touch_pad(), &smooth);
|
touch_pad_filter_read_smooth(child->get_touch_pad(), &smooth);
|
||||||
ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, smooth=%d, threshold=%d", child->get_touch_pad(), raw, benchmark,
|
ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, smooth=%d, threshold=%d", child->get_touch_pad(), raw,
|
||||||
smooth, child->get_threshold());
|
benchmark, smooth, child->get_threshold());
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, threshold=%d", child->get_touch_pad(), raw, benchmark,
|
ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, threshold=%d", child->get_touch_pad(), raw, benchmark,
|
||||||
child->get_threshold());
|
child->get_threshold());
|
||||||
}
|
|
||||||
}
|
|
||||||
this->setup_mode_last_log_print_ = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ESP32TouchComponent::on_shutdown() {
|
|
||||||
// Disable interrupts
|
|
||||||
touch_pad_intr_disable(static_cast<touch_pad_intr_mask_t>(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE |
|
|
||||||
TOUCH_PAD_INTR_MASK_TIMEOUT));
|
|
||||||
touch_pad_isr_deregister(touch_isr_handler, this);
|
|
||||||
if (this->touch_queue_) {
|
|
||||||
vQueueDelete(this->touch_queue_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if any pad is configured for wakeup
|
|
||||||
bool is_wakeup_source = false;
|
|
||||||
for (auto *child : this->children_) {
|
|
||||||
if (child->get_wakeup_threshold() != 0) {
|
|
||||||
if (!is_wakeup_source) {
|
|
||||||
is_wakeup_source = true;
|
|
||||||
// Touch sensor FSM mode must be 'TOUCH_FSM_MODE_TIMER' to use it to wake-up.
|
|
||||||
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->setup_mode_last_log_print_ = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_wakeup_source) {
|
void ESP32TouchComponent::on_shutdown() {
|
||||||
touch_pad_deinit();
|
// Disable interrupts
|
||||||
|
touch_pad_intr_disable(static_cast<touch_pad_intr_mask_t>(
|
||||||
|
TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE | TOUCH_PAD_INTR_MASK_TIMEOUT));
|
||||||
|
touch_pad_isr_deregister(touch_isr_handler, this);
|
||||||
|
if (this->touch_queue_) {
|
||||||
|
vQueueDelete(this->touch_queue_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any pad is configured for wakeup
|
||||||
|
bool is_wakeup_source = false;
|
||||||
|
for (auto *child : this->children_) {
|
||||||
|
if (child->get_wakeup_threshold() != 0) {
|
||||||
|
if (!is_wakeup_source) {
|
||||||
|
is_wakeup_source = true;
|
||||||
|
// Touch sensor FSM mode must be 'TOUCH_FSM_MODE_TIMER' to use it to wake-up.
|
||||||
|
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_wakeup_source) {
|
||||||
|
touch_pad_deinit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {
|
void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {
|
||||||
ESP32TouchComponent *component = static_cast<ESP32TouchComponent *>(arg);
|
ESP32TouchComponent *component = static_cast<ESP32TouchComponent *>(arg);
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
|
|
||||||
// Read interrupt status and pad status
|
// Read interrupt status and pad status
|
||||||
TouchPadEventV2 event;
|
TouchPadEventV2 event;
|
||||||
event.intr_mask = touch_pad_read_intr_status_mask();
|
event.intr_mask = touch_pad_read_intr_status_mask();
|
||||||
event.pad_status = touch_pad_get_status();
|
event.pad_status = touch_pad_get_status();
|
||||||
event.pad = touch_pad_get_current_meas_channel();
|
event.pad = touch_pad_get_current_meas_channel();
|
||||||
|
|
||||||
// Debug logging from ISR (using ROM functions for ISR safety) - only log non-timeout events for now
|
// Debug logging from ISR (using ROM functions for ISR safety) - only log non-timeout events for now
|
||||||
// if (event.intr_mask != 0x10 || event.pad_status != 0) {
|
// if (event.intr_mask != 0x10 || event.pad_status != 0) {
|
||||||
// ets_printf("ISR: intr=0x%x, status=0x%x, pad=%d\n", event.intr_mask, event.pad_status, event.pad);
|
// ets_printf("ISR: intr=0x%x, status=0x%x, pad=%d\n", event.intr_mask, event.pad_status, event.pad);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Send event to queue for processing in main loop
|
// Send event to queue for processing in main loop
|
||||||
xQueueSendFromISR(component->touch_queue_, &event, &xHigherPriorityTaskWoken);
|
xQueueSendFromISR(component->touch_queue_, &event, &xHigherPriorityTaskWoken);
|
||||||
|
|
||||||
if (xHigherPriorityTaskWoken) {
|
if (xHigherPriorityTaskWoken) {
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace esp32_touch
|
} // namespace esp32_touch
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
Reference in New Issue
Block a user