1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-22 21:22:22 +01:00

Mpr121 added debounce and thresholds config (#558)

* fixed code issues from previous PR

* travis line to long

* travis

* more travis

* Update esphome/components/mpr121/mpr121.h

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* fixed issues

* fixed issues

* fixes remove duplicate line
remove threshold settings

* fixed touch release thresholds mixup
This commit is contained in:
Michiel van Turnhout
2019-05-28 20:39:20 +02:00
committed by Otto Winter
parent df0d33c3cd
commit 5893506528
4 changed files with 56 additions and 6 deletions

View File

@@ -18,9 +18,11 @@ void MPR121Component::setup() {
}
// set touch sensitivity for all 12 channels
for (uint8_t i = 0; i < 12; i++) {
this->write_byte(MPR121_TOUCHTH_0 + 2 * i, 12);
this->write_byte(MPR121_RELEASETH_0 + 2 * i, 6);
for (auto *channel : this->channels_) {
this->write_byte(MPR121_TOUCHTH_0 + 2 * channel->channel_,
channel->touch_threshold_.value_or(this->touch_threshold_));
this->write_byte(MPR121_RELEASETH_0 + 2 * channel->channel_,
channel->release_threshold_.value_or(this->release_threshold_));
}
this->write_byte(MPR121_MHDR, 0x01);
this->write_byte(MPR121_NHDR, 0x01);
@@ -44,6 +46,19 @@ void MPR121Component::setup() {
// start with first 5 bits of baseline tracking
this->write_byte(MPR121_ECR, 0x8F);
}
void MPR121Component::set_touch_debounce(uint8_t debounce) {
uint8_t mask = debounce << 4;
this->debounce_ &= 0x0f;
this->debounce_ |= mask;
}
void MPR121Component::set_release_debounce(uint8_t debounce) {
uint8_t mask = debounce & 0x0f;
this->debounce_ &= 0xf0;
this->debounce_ |= mask;
};
void MPR121Component::dump_config() {
ESP_LOGCONFIG(TAG, "MPR121:");
LOG_I2C_DEVICE(this);