mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-21 05:23:27 +02:00
Create GT911 Touchscreen component (#4027)
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_INDEX
|
||||
|
||||
from .. import gt911_ns
|
||||
from ..touchscreen import GT911Touchscreen, GT911ButtonListener
|
||||
|
||||
CONF_GT911_ID = "gt911_id"
|
||||
|
||||
GT911Button = gt911_ns.class_(
|
||||
"GT911Button",
|
||||
binary_sensor.BinarySensor,
|
||||
cg.Component,
|
||||
GT911ButtonListener,
|
||||
cg.Parented.template(GT911Touchscreen),
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(GT911Button).extend(
|
||||
{
|
||||
cv.GenerateID(CONF_GT911_ID): cv.use_id(GT911Touchscreen),
|
||||
cv.Optional(CONF_INDEX, default=0): cv.int_range(min=0, max=3),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = await binary_sensor.new_binary_sensor(config)
|
||||
await cg.register_component(var, config)
|
||||
await cg.register_parented(var, config[CONF_GT911_ID])
|
||||
cg.add(var.set_index(config[CONF_INDEX]))
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "gt911_button.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace gt911 {
|
||||
|
||||
static const char *const TAG = "GT911.binary_sensor";
|
||||
|
||||
void GT911Button::setup() {
|
||||
this->parent_->register_button_listener(this);
|
||||
this->publish_initial_state(false);
|
||||
}
|
||||
|
||||
void GT911Button::dump_config() {
|
||||
LOG_BINARY_SENSOR("", "GT911 Button", this);
|
||||
ESP_LOGCONFIG(TAG, " Index: %u", this->index_);
|
||||
}
|
||||
|
||||
void GT911Button::update_button(uint8_t index, bool state) {
|
||||
if (index != this->index_)
|
||||
return;
|
||||
|
||||
this->publish_state(state);
|
||||
}
|
||||
|
||||
} // namespace gt911
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/components/gt911/touchscreen/gt911_touchscreen.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace gt911 {
|
||||
|
||||
class GT911Button : public binary_sensor::BinarySensor,
|
||||
public Component,
|
||||
public GT911ButtonListener,
|
||||
public Parented<GT911Touchscreen> {
|
||||
public:
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
void set_index(uint8_t index) { this->index_ = index; }
|
||||
|
||||
void update_button(uint8_t index, bool state) override;
|
||||
|
||||
protected:
|
||||
uint8_t index_;
|
||||
};
|
||||
|
||||
} // namespace gt911
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user