1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-06 03:43:49 +01:00

Add support for matrix keypads (#4241)

Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
Samuel Sieb
2023-01-09 19:06:54 -08:00
committed by GitHub
parent 657fd9d0d5
commit fe55f3a43d
9 changed files with 365 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
import esphome.codegen as cg
CODEOWNERS = ["@ssieb"]
key_provider_ns = cg.esphome_ns.namespace("key_provider")
KeyProvider = key_provider_ns.class_("KeyProvider")

View File

@@ -0,0 +1,13 @@
#include "key_provider.h"
namespace esphome {
namespace key_provider {
void KeyProvider::add_on_key_callback(std::function<void(uint8_t)> &&callback) {
this->key_callback_.add(std::move(callback));
}
void KeyProvider::send_key_(uint8_t key) { this->key_callback_.call(key); }
} // namespace key_provider
} // namespace esphome

View File

@@ -0,0 +1,21 @@
#pragma once
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
namespace esphome {
namespace key_provider {
/// interface for components that provide keypresses
class KeyProvider {
public:
void add_on_key_callback(std::function<void(uint8_t)> &&callback);
protected:
void send_key_(uint8_t key);
CallbackManager<void(uint8_t)> key_callback_{};
};
} // namespace key_provider
} // namespace esphome