mirror of
https://github.com/esphome/esphome.git
synced 2024-11-09 16:57:47 +01:00
[sdl] Allow the display to act as a KeyProvider
This commit is contained in:
parent
17204baac0
commit
dfb98b523f
3 changed files with 12 additions and 5 deletions
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue