mirror of
https://github.com/esphome/esphome.git
synced 2025-08-01 16:07:47 +00:00
[touchscreen] Disable loop until interrupt triggered
This commit is contained in:
parent
0968338064
commit
817ee70db0
@ -7,13 +7,24 @@ namespace touchscreen {
|
|||||||
|
|
||||||
static const char *const TAG = "touchscreen";
|
static const char *const TAG = "touchscreen";
|
||||||
|
|
||||||
void TouchscreenInterrupt::gpio_intr(TouchscreenInterrupt *store) { store->touched = true; }
|
void TouchscreenInterrupt::gpio_intr(TouchscreenInterrupt *store) {
|
||||||
|
bool new_state = store->isr_pin_.digital_read();
|
||||||
|
if (new_state != store->inverted) {
|
||||||
|
store->touched = true;
|
||||||
|
if (store->component_ != nullptr) {
|
||||||
|
store->component_->enable_loop_soon_any_context();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Touchscreen::attach_interrupt_(InternalGPIOPin *irq_pin, esphome::gpio::InterruptType type) {
|
void Touchscreen::attach_interrupt_(InternalGPIOPin *irq_pin, esphome::gpio::InterruptType type) {
|
||||||
|
this->store_.isr_pin_ = irq_pin->to_isr();
|
||||||
|
this->store_.component_ = this;
|
||||||
|
this->store_.inverted = irq_pin->is_inverted();
|
||||||
irq_pin->attach_interrupt(TouchscreenInterrupt::gpio_intr, &this->store_, type);
|
irq_pin->attach_interrupt(TouchscreenInterrupt::gpio_intr, &this->store_, type);
|
||||||
this->store_.init = true;
|
this->store_.init = true;
|
||||||
this->store_.touched = false;
|
this->store_.touched = false;
|
||||||
ESP_LOGD(TAG, "Attach Touch Interupt");
|
ESP_LOGD(TAG, "Attach Touch Interrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Touchscreen::call_setup() {
|
void Touchscreen::call_setup() {
|
||||||
@ -71,6 +82,8 @@ void Touchscreen::loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this->store_.init)
|
||||||
|
this->disable_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Touchscreen::add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw) {
|
void Touchscreen::add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw) {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/core/defines.h"
|
|
||||||
#include "esphome/components/display/display.h"
|
#include "esphome/components/display/display.h"
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace touchscreen {
|
namespace touchscreen {
|
||||||
@ -30,9 +30,12 @@ struct TouchPoint {
|
|||||||
using TouchPoints_t = std::vector<TouchPoint>;
|
using TouchPoints_t = std::vector<TouchPoint>;
|
||||||
|
|
||||||
struct TouchscreenInterrupt {
|
struct TouchscreenInterrupt {
|
||||||
|
ISRInternalGPIOPin isr_pin_;
|
||||||
volatile bool touched{true};
|
volatile bool touched{true};
|
||||||
bool init{false};
|
bool init{false};
|
||||||
|
bool inverted{false};
|
||||||
static void gpio_intr(TouchscreenInterrupt *store);
|
static void gpio_intr(TouchscreenInterrupt *store);
|
||||||
|
Component *component_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
class TouchListener {
|
class TouchListener {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user