[display] SDL2 display driver for host platform (#6825)

This commit is contained in:
Clyde Stubbs
2024-06-12 11:42:01 +10:00
committed by GitHub
parent e2c1af199c
commit bc408ad08c
10 changed files with 286 additions and 1 deletions
@@ -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