mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
SX1509 minimum loop period (fixes esphome/issues#4325) (#4613)
* Minimum loop period (fixes esphome/issues#4325) * clang-tidy suggestions * More clang-tidy suggestions
This commit is contained in:
parent
74fe135c9c
commit
358c59bd8d
2 changed files with 6 additions and 0 deletions
|
@ -42,6 +42,9 @@ void SX1509Component::dump_config() {
|
|||
|
||||
void SX1509Component::loop() {
|
||||
if (this->has_keypad_) {
|
||||
if (millis() - this->last_loop_timestamp_ < min_loop_period_)
|
||||
return;
|
||||
this->last_loop_timestamp_ = millis();
|
||||
uint16_t key_data = this->read_key_data();
|
||||
for (auto *binary_sensor : this->keypad_binary_sensors_)
|
||||
binary_sensor->process(key_data);
|
||||
|
|
|
@ -69,6 +69,9 @@ class SX1509Component : public Component, public i2c::I2CDevice {
|
|||
uint8_t debounce_time_ = 1;
|
||||
std::vector<SX1509Processor *> keypad_binary_sensors_;
|
||||
|
||||
uint32_t last_loop_timestamp_ = 0;
|
||||
const uint32_t min_loop_period_ = 15; // ms
|
||||
|
||||
void setup_keypad_();
|
||||
void set_debounce_config_(uint8_t config_value);
|
||||
void set_debounce_time_(uint8_t time);
|
||||
|
|
Loading…
Reference in a new issue