From dfb98b523fcd26a764c7b2787e75c64b1267c6c5 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:37:54 +1200 Subject: [PATCH] [sdl] Allow the display to act as a KeyProvider --- esphome/components/sdl/display.py | 6 ++++-- esphome/components/sdl/sdl_esphome.cpp | 4 ++++ esphome/components/sdl/sdl_esphome.h | 7 ++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/esphome/components/sdl/display.py b/esphome/components/sdl/display.py index 18dc570f88..e32b7f5e2f 100644 --- a/esphome/components/sdl/display.py +++ b/esphome/components/sdl/display.py @@ -2,7 +2,7 @@ import subprocess import esphome.codegen as cg import esphome.config_validation as cv -from esphome.components import display +from esphome.components import display, key_provider from esphome.const import ( CONF_ID, CONF_DIMENSIONS, @@ -12,8 +12,10 @@ from esphome.const import ( PLATFORM_HOST, ) +AUTO_LOAD = ["key_provider"] + sdl_ns = cg.esphome_ns.namespace("sdl") -Sdl = sdl_ns.class_("Sdl", display.Display, cg.Component) +Sdl = sdl_ns.class_("Sdl", display.Display, key_provider.KeyProvider) CONF_SDL_OPTIONS = "sdl_options" diff --git a/esphome/components/sdl/sdl_esphome.cpp b/esphome/components/sdl/sdl_esphome.cpp index 5e17ca5650..667bd9eda8 100644 --- a/esphome/components/sdl/sdl_esphome.cpp +++ b/esphome/components/sdl/sdl_esphome.cpp @@ -84,6 +84,10 @@ void Sdl::loop() { } break; + case SDL_KEYUP: + this->send_key_(e.key.keysym.sym); + break; + default: ESP_LOGV(TAG, "Event %d", e.type); break; diff --git a/esphome/components/sdl/sdl_esphome.h b/esphome/components/sdl/sdl_esphome.h index e4b2d9dd9f..c750c436c8 100644 --- a/esphome/components/sdl/sdl_esphome.h +++ b/esphome/components/sdl/sdl_esphome.h @@ -1,10 +1,11 @@ #pragma once #ifdef USE_HOST +#include "esphome/components/display/display.h" +#include "esphome/components/key_provider/key_provider.h" +#include "esphome/core/application.h" #include "esphome/core/component.h" #include "esphome/core/log.h" -#include "esphome/core/application.h" -#include "esphome/components/display/display.h" #define SDL_MAIN_HANDLED #include "SDL.h" @@ -13,7 +14,7 @@ namespace sdl { constexpr static const char *const TAG = "sdl"; -class Sdl : public display::Display { +class Sdl : public display::Display, public key_provider::KeyProvider { public: display::DisplayType get_display_type() override { return display::DISPLAY_TYPE_COLOR; } void update() override;