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:
tracestep 2023-03-26 18:59:57 -03:00 committed by Jesse Hills
parent 74fe135c9c
commit 358c59bd8d
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
2 changed files with 6 additions and 0 deletions

View File

@ -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);

View File

@ -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);