1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-14 17:22:20 +01:00

touch ups

This commit is contained in:
J. Nick Koston
2025-06-12 13:16:48 -05:00
parent 8517420356
commit aecf080211
3 changed files with 18 additions and 16 deletions

View File

@@ -19,16 +19,6 @@ static const uint32_t SETUP_MODE_LOG_INTERVAL_MS = 250;
class ESP32TouchBinarySensor;
struct TouchPadEvent {
touch_pad_t pad;
uint32_t value;
bool is_touched; // Whether this pad is currently touched
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
uint32_t intr_mask; // Interrupt mask for S2/S3
uint32_t pad_status; // Pad status bitmap for S2/S3
#endif
};
class ESP32TouchComponent : public Component {
public:
void register_touch_pad(ESP32TouchBinarySensor *pad) { this->children_.push_back(pad); }

View File

@@ -18,6 +18,12 @@ namespace esp32_touch {
static const char *const TAG = "esp32_touch";
struct TouchPadEventV1 {
touch_pad_t pad;
uint32_t value;
bool is_touched;
};
void ESP32TouchComponent::setup() {
ESP_LOGCONFIG(TAG, "Running setup for ESP32");
@@ -29,7 +35,7 @@ void ESP32TouchComponent::setup() {
if (queue_size < 8)
queue_size = 8;
this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEvent));
this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEventV1));
if (this->touch_queue_ == nullptr) {
ESP_LOGE(TAG, "Failed to create touch event queue of size %d", queue_size);
this->mark_failed();
@@ -106,7 +112,7 @@ void ESP32TouchComponent::loop() {
}
// Process any queued touch events from interrupts
TouchPadEvent event;
TouchPadEventV1 event;
while (xQueueReceive(this->touch_queue_, &event, 0) == pdTRUE) {
// Find the corresponding sensor
for (auto *child : this->children_) {
@@ -228,7 +234,7 @@ void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {
bool is_touched = value < child->get_threshold();
// Always send the current state - the main loop will filter for changes
TouchPadEvent event;
TouchPadEventV1 event;
event.pad = pad;
event.value = value;
event.is_touched = is_touched;

View File

@@ -20,6 +20,12 @@ namespace esp32_touch {
static const char *const TAG = "esp32_touch";
struct TouchPadEventV2 {
touch_pad_t pad;
uint32_t intr_mask;
uint32_t pad_status;
};
void ESP32TouchComponent::setup() {
// Add a delay to allow serial connection, but feed the watchdog
ESP_LOGCONFIG(TAG, "Waiting 5 seconds before touch sensor setup...");
@@ -36,7 +42,7 @@ void ESP32TouchComponent::setup() {
if (queue_size < 8)
queue_size = 8;
this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEvent));
this->touch_queue_ = xQueueCreate(queue_size, sizeof(TouchPadEventV2));
if (this->touch_queue_ == nullptr) {
ESP_LOGE(TAG, "Failed to create touch event queue of size %d", queue_size);
this->mark_failed();
@@ -257,7 +263,7 @@ void ESP32TouchComponent::loop() {
const uint32_t now = App.get_loop_component_start_time();
// Process any queued touch events from interrupts
TouchPadEvent event;
TouchPadEventV2 event;
while (xQueueReceive(this->touch_queue_, &event, 0) == pdTRUE) {
// Handle timeout events
if (event.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) {
@@ -350,7 +356,7 @@ void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
// Read interrupt status and pad status
TouchPadEvent event;
TouchPadEventV2 event;
event.intr_mask = touch_pad_read_intr_status_mask();
event.pad_status = touch_pad_get_status();
event.pad = touch_pad_get_current_meas_channel();