1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-09 05:13:48 +01:00

[mpr121] cleaner setup (#11013)

This commit is contained in:
mrtoy-me
2025-10-04 22:54:31 +10:00
committed by GitHub
parent 2eea674c04
commit 874db20b7d
2 changed files with 2 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ namespace mpr121 {
static const char *const TAG = "mpr121"; static const char *const TAG = "mpr121";
void MPR121Component::setup() { void MPR121Component::setup() {
this->disable_loop();
// soft reset device // soft reset device
this->write_byte(MPR121_SOFTRESET, 0x63); this->write_byte(MPR121_SOFTRESET, 0x63);
this->set_timeout(100, [this]() { this->set_timeout(100, [this]() {
@@ -51,7 +52,7 @@ void MPR121Component::setup() {
this->write_byte(MPR121_ECR, 0x80 | (this->max_touch_channel_ + 1)); this->write_byte(MPR121_ECR, 0x80 | (this->max_touch_channel_ + 1));
this->flush_gpio_(); this->flush_gpio_();
this->setup_complete_ = true; this->enable_loop();
}); });
} }
@@ -80,9 +81,6 @@ void MPR121Component::dump_config() {
} }
} }
void MPR121Component::loop() { void MPR121Component::loop() {
if (!this->setup_complete_)
return;
uint16_t val = 0; uint16_t val = 0;
this->read_byte_16(MPR121_TOUCHSTATUS_L, &val); this->read_byte_16(MPR121_TOUCHSTATUS_L, &val);

View File

@@ -80,7 +80,6 @@ class MPR121Component : public Component, public i2c::I2CDevice {
void pin_mode(uint8_t ionum, gpio::Flags flags); void pin_mode(uint8_t ionum, gpio::Flags flags);
protected: protected:
bool setup_complete_{false};
std::vector<MPR121Channel *> channels_{}; std::vector<MPR121Channel *> channels_{};
uint8_t debounce_{0}; uint8_t debounce_{0};
uint8_t touch_threshold_{}; uint8_t touch_threshold_{};