mirror of
https://github.com/esphome/esphome.git
synced 2025-10-07 12:23:47 +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() {
|
void MPR121Component::setup() {
|
||||||
// soft reset device
|
// soft reset device
|
||||||
this->write_byte(MPR121_SOFTRESET, 0x63);
|
this->write_byte(MPR121_SOFTRESET, 0x63);
|
||||||
delay(100); // NOLINT
|
this->set_timeout(100, [this]() {
|
||||||
if (!this->write_byte(MPR121_ECR, 0x0)) {
|
if (!this->write_byte(MPR121_ECR, 0x0)) {
|
||||||
this->error_code_ = COMMUNICATION_FAILED;
|
this->error_code_ = COMMUNICATION_FAILED;
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set touch sensitivity for all 12 channels
|
// set touch sensitivity for all 12 channels
|
||||||
for (auto *channel : this->channels_) {
|
for (auto *channel : this->channels_) {
|
||||||
channel->setup();
|
channel->setup();
|
||||||
@@ -52,6 +51,8 @@ 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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPR121Component::set_touch_debounce(uint8_t debounce) {
|
void MPR121Component::set_touch_debounce(uint8_t debounce) {
|
||||||
@@ -73,15 +74,15 @@ void MPR121Component::dump_config() {
|
|||||||
case COMMUNICATION_FAILED:
|
case COMMUNICATION_FAILED:
|
||||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||||
break;
|
break;
|
||||||
case WRONG_CHIP_STATE:
|
|
||||||
ESP_LOGE(TAG, "MPR121 has wrong default value for CONFIG2?");
|
|
||||||
break;
|
|
||||||
case NONE:
|
case NONE:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
||||||
|
@@ -80,6 +80,7 @@ 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_{};
|
||||||
@@ -88,7 +89,6 @@ class MPR121Component : public Component, public i2c::I2CDevice {
|
|||||||
enum ErrorCode {
|
enum ErrorCode {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
COMMUNICATION_FAILED,
|
COMMUNICATION_FAILED,
|
||||||
WRONG_CHIP_STATE,
|
|
||||||
} error_code_{NONE};
|
} error_code_{NONE};
|
||||||
|
|
||||||
bool flush_gpio_();
|
bool flush_gpio_();
|
||||||
|
Reference in New Issue
Block a user