ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
matrix_keypad.h
Go to the documentation of this file.
1#pragma once
2
6#include "esphome/core/hal.h"
8#include <cstdlib>
9#include <utility>
10
11namespace esphome::matrix_keypad {
12
14 public:
15 virtual void button_pressed(int row, int col) {};
16 virtual void button_released(int row, int col) {};
17 virtual void key_pressed(uint8_t key) {};
18 virtual void key_released(uint8_t key) {};
19};
20
21class MatrixKeyTrigger final : public Trigger<uint8_t> {};
22
23class MatrixKeypad final : public key_provider::KeyProvider, public Component {
24 public:
25 void setup() override;
26 void loop() override;
27 void dump_config() override;
28 void set_columns(std::vector<GPIOPin *> pins) { columns_ = std::move(pins); };
29 void set_rows(std::vector<GPIOPin *> pins) { rows_ = std::move(pins); };
31 void set_keys(const uint8_t *keys) { this->keys_ = keys; }
32 void set_debounce_time(uint32_t debounce_time) { debounce_time_ = debounce_time; };
33 void set_has_diodes(bool has_diodes) { has_diodes_ = has_diodes; };
34 void set_has_pulldowns(bool has_pulldowns) { has_pulldowns_ = has_pulldowns; };
35
38
39 protected:
40 std::vector<GPIOPin *> rows_;
41 std::vector<GPIOPin *> columns_;
42 const uint8_t *keys_{nullptr};
44 bool has_diodes_{false};
45 bool has_pulldowns_{false};
46 int pressed_key_ = -1;
48 int active_key_{-1};
49
50 std::vector<MatrixKeypadListener *> listeners_{};
51 std::vector<MatrixKeyTrigger *> key_triggers_;
52};
53
54} // namespace esphome::matrix_keypad
interface for components that provide keypresses
Definition key_provider.h:9
void set_has_diodes(bool has_diodes)
std::vector< MatrixKeypadListener * > listeners_
void set_keys(const uint8_t *keys)
keys is a codegen PROGMEM table with one key code per button.
void set_columns(std::vector< GPIOPin * > pins)
void set_rows(std::vector< GPIOPin * > pins)
void register_key_trigger(MatrixKeyTrigger *trig)
std::vector< GPIOPin * > columns_
std::vector< MatrixKeyTrigger * > key_triggers_
std::vector< GPIOPin * > rows_
void set_debounce_time(uint32_t debounce_time)
void set_has_pulldowns(bool has_pulldowns)
void register_listener(MatrixKeypadListener *listener)
virtual void button_pressed(int row, int col)
virtual void button_released(int row, int col)
const char * key
static void uint32_t