mirror of
https://github.com/esphome/esphome.git
synced 2025-10-06 20:03:46 +01:00
[mpr121] remove delay (#10963)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
@@ -13,13 +13,12 @@ static const char *const TAG = "mpr121";
|
||||
void MPR121Component::setup() {
|
||||
// soft reset device
|
||||
this->write_byte(MPR121_SOFTRESET, 0x63);
|
||||
delay(100); // NOLINT
|
||||
this->set_timeout(100, [this]() {
|
||||
if (!this->write_byte(MPR121_ECR, 0x0)) {
|
||||
this->error_code_ = COMMUNICATION_FAILED;
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
// set touch sensitivity for all 12 channels
|
||||
for (auto *channel : this->channels_) {
|
||||
channel->setup();
|
||||
@@ -52,6 +51,8 @@ void MPR121Component::setup() {
|
||||
this->write_byte(MPR121_ECR, 0x80 | (this->max_touch_channel_ + 1));
|
||||
|
||||
this->flush_gpio_();
|
||||
this->setup_complete_ = true;
|
||||
});
|
||||
}
|
||||
|
||||
void MPR121Component::set_touch_debounce(uint8_t debounce) {
|
||||
@@ -73,15 +74,15 @@ void MPR121Component::dump_config() {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case WRONG_CHIP_STATE:
|
||||
ESP_LOGE(TAG, "MPR121 has wrong default value for CONFIG2?");
|
||||
break;
|
||||
case NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void MPR121Component::loop() {
|
||||
if (!this->setup_complete_)
|
||||
return;
|
||||
|
||||
uint16_t val = 0;
|
||||
this->read_byte_16(MPR121_TOUCHSTATUS_L, &val);
|
||||
|
||||
|
@@ -80,6 +80,7 @@ class MPR121Component : public Component, public i2c::I2CDevice {
|
||||
void pin_mode(uint8_t ionum, gpio::Flags flags);
|
||||
|
||||
protected:
|
||||
bool setup_complete_{false};
|
||||
std::vector<MPR121Channel *> channels_{};
|
||||
uint8_t debounce_{0};
|
||||
uint8_t touch_threshold_{};
|
||||
@@ -88,7 +89,6 @@ class MPR121Component : public Component, public i2c::I2CDevice {
|
||||
enum ErrorCode {
|
||||
NONE = 0,
|
||||
COMMUNICATION_FAILED,
|
||||
WRONG_CHIP_STATE,
|
||||
} error_code_{NONE};
|
||||
|
||||
bool flush_gpio_();
|
||||
|
Reference in New Issue
Block a user