mirror of
https://github.com/esphome/esphome.git
synced 2025-09-15 09:42:19 +01:00
debug
This commit is contained in:
@@ -21,7 +21,15 @@ namespace esp32_touch {
|
|||||||
static const char *const TAG = "esp32_touch";
|
static const char *const TAG = "esp32_touch";
|
||||||
|
|
||||||
void ESP32TouchComponent::setup() {
|
void ESP32TouchComponent::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Running setup for ESP32-S2/S3");
|
// Add a delay to allow serial connection, but feed the watchdog
|
||||||
|
ESP_LOGCONFIG(TAG, "Waiting 5 seconds before touch sensor setup...");
|
||||||
|
for (int i = 0; i < 50; i++) {
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
App.feed_wdt();
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGCONFIG(TAG, "=== ESP32 Touch Sensor v2 Setup Starting ===");
|
||||||
|
ESP_LOGCONFIG(TAG, "Configuring %d touch pads", this->children_.size());
|
||||||
|
|
||||||
// Create queue for touch events first
|
// Create queue for touch events first
|
||||||
size_t queue_size = this->children_.size() * 4;
|
size_t queue_size = this->children_.size() * 4;
|
||||||
@@ -36,9 +44,16 @@ void ESP32TouchComponent::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize touch pad peripheral
|
// Initialize touch pad peripheral
|
||||||
touch_pad_init();
|
ESP_LOGD(TAG, "Initializing touch pad peripheral...");
|
||||||
|
esp_err_t init_err = touch_pad_init();
|
||||||
|
if (init_err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to initialize touch pad: %s", esp_err_to_name(init_err));
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Configure each touch pad first
|
// Configure each touch pad first
|
||||||
|
ESP_LOGD(TAG, "Configuring individual touch pads...");
|
||||||
for (auto *child : this->children_) {
|
for (auto *child : this->children_) {
|
||||||
esp_err_t config_err = touch_pad_config(child->get_touch_pad());
|
esp_err_t config_err = touch_pad_config(child->get_touch_pad());
|
||||||
if (config_err != ESP_OK) {
|
if (config_err != ESP_OK) {
|
||||||
@@ -108,11 +123,20 @@ void ESP32TouchComponent::setup() {
|
|||||||
// Start FSM
|
// Start FSM
|
||||||
touch_pad_fsm_start();
|
touch_pad_fsm_start();
|
||||||
|
|
||||||
// Read initial benchmark values and set thresholds if not explicitly configured
|
// Wait for initial measurements
|
||||||
|
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
// Read initial values and set thresholds
|
||||||
for (auto *child : this->children_) {
|
for (auto *child : this->children_) {
|
||||||
if (child->get_threshold() != 0) {
|
if (child->get_threshold() != 0) {
|
||||||
touch_pad_set_thresh(child->get_touch_pad(), child->get_threshold());
|
touch_pad_set_thresh(child->get_touch_pad(), child->get_threshold());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to read initial values for debugging
|
||||||
|
uint32_t raw = 0, benchmark = 0;
|
||||||
|
touch_pad_read_raw_data(child->get_touch_pad(), &raw);
|
||||||
|
touch_pad_read_benchmark(child->get_touch_pad(), &benchmark);
|
||||||
|
ESP_LOGD(TAG, "Initial pad %d: raw=%d, benchmark=%d", child->get_touch_pad(), raw, benchmark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,17 +317,19 @@ void ESP32TouchComponent::loop() {
|
|||||||
if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > 1000) {
|
if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > 1000) {
|
||||||
ESP_LOGD(TAG, "=== Touch Pad Status ===");
|
ESP_LOGD(TAG, "=== Touch Pad Status ===");
|
||||||
for (auto *child : this->children_) {
|
for (auto *child : this->children_) {
|
||||||
|
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_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: benchmark=%d, smooth=%d, threshold=%d", child->get_touch_pad(), benchmark, smooth,
|
ESP_LOGD(TAG, " Pad T%d: raw=%d, benchmark=%d, smooth=%d, threshold=%d", child->get_touch_pad(), raw,
|
||||||
child->get_threshold());
|
benchmark, smooth, child->get_threshold());
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, " Pad T%d: benchmark=%d, threshold=%d", child->get_touch_pad(), 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,6 +373,11 @@ void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {
|
|||||||
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
|
||||||
|
// 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);
|
||||||
|
//}
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user