[sdl] Allow the display to act as a KeyProvider

This commit is contained in:
Jesse Hills 2024-06-24 16:37:54 +12:00
parent 17204baac0
commit dfb98b523f
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A
3 changed files with 12 additions and 5 deletions

View file

@ -2,7 +2,7 @@ import subprocess
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import display from esphome.components import display, key_provider
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
CONF_DIMENSIONS, CONF_DIMENSIONS,
@ -12,8 +12,10 @@ from esphome.const import (
PLATFORM_HOST, PLATFORM_HOST,
) )
AUTO_LOAD = ["key_provider"]
sdl_ns = cg.esphome_ns.namespace("sdl") 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" CONF_SDL_OPTIONS = "sdl_options"

View file

@ -84,6 +84,10 @@ void Sdl::loop() {
} }
break; break;
case SDL_KEYUP:
this->send_key_(e.key.keysym.sym);
break;
default: default:
ESP_LOGV(TAG, "Event %d", e.type); ESP_LOGV(TAG, "Event %d", e.type);
break; break;

View file

@ -1,10 +1,11 @@
#pragma once #pragma once
#ifdef USE_HOST #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/component.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/application.h"
#include "esphome/components/display/display.h"
#define SDL_MAIN_HANDLED #define SDL_MAIN_HANDLED
#include "SDL.h" #include "SDL.h"
@ -13,7 +14,7 @@ namespace sdl {
constexpr static const char *const TAG = "sdl"; constexpr static const char *const TAG = "sdl";
class Sdl : public display::Display { class Sdl : public display::Display, public key_provider::KeyProvider {
public: public:
display::DisplayType get_display_type() override { return display::DISPLAY_TYPE_COLOR; } display::DisplayType get_display_type() override { return display::DISPLAY_TYPE_COLOR; }
void update() override; void update() override;