mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 02:28:28 +02:00
[display] SDL2 display driver for host platform (#6825)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
from esphome.components import touchscreen
|
||||
from ..display import Sdl, sdl_ns, CONF_SDL_ID
|
||||
|
||||
SdlTouchscreen = sdl_ns.class_("SdlTouchscreen", touchscreen.Touchscreen)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = touchscreen.TOUCHSCREEN_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(SdlTouchscreen),
|
||||
cv.GenerateID(CONF_SDL_ID): cv.use_id(Sdl),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_parented(var, config[CONF_SDL_ID])
|
||||
await touchscreen.register_touchscreen(var, config)
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef USE_HOST
|
||||
#include "../sdl_esphome.h"
|
||||
#include "esphome/components/touchscreen/touchscreen.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace sdl {
|
||||
|
||||
class SdlTouchscreen : public touchscreen::Touchscreen, public Parented<Sdl> {
|
||||
public:
|
||||
void setup() override {
|
||||
this->x_raw_max_ = this->display_->get_width();
|
||||
this->y_raw_max_ = this->display_->get_height();
|
||||
}
|
||||
|
||||
void update_touches() override {
|
||||
if (this->parent_->mouse_down) {
|
||||
add_raw_touch_position_(0, this->parent_->mouse_x, this->parent_->mouse_y);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace sdl
|
||||
} // namespace esphome
|
||||
#endif
|
||||
Reference in New Issue
Block a user