mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-07 13:24:56 +02: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:
committed by
Otto Winter
parent
2570f2d6f2
commit
9e56318498
@@ -46,17 +46,29 @@ enum {
|
||||
};
|
||||
|
||||
class MPR121Channel : public binary_sensor::BinarySensor {
|
||||
friend class MPR121Component;
|
||||
|
||||
public:
|
||||
void set_channel(uint8_t channel) { channel_ = channel; }
|
||||
void process(uint16_t data) { this->publish_state(static_cast<bool>(data & (1 << this->channel_))); }
|
||||
void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
|
||||
void set_release_threshold(uint8_t release_threshold) { this->release_threshold_ = release_threshold; };
|
||||
|
||||
protected:
|
||||
uint8_t channel_{0};
|
||||
optional<uint8_t> touch_threshold_{};
|
||||
optional<uint8_t> release_threshold_{};
|
||||
};
|
||||
|
||||
class MPR121Component : public Component, public i2c::I2CDevice {
|
||||
public:
|
||||
void register_channel(MPR121Channel *channel) { this->channels_.push_back(channel); }
|
||||
void set_touch_debounce(uint8_t debounce);
|
||||
void set_release_debounce(uint8_t debounce);
|
||||
void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
|
||||
void set_release_threshold(uint8_t release_threshold) { this->release_threshold_ = release_threshold; };
|
||||
uint8_t get_touch_threshold() { return this->touch_threshold_; };
|
||||
uint8_t get_release_threshold() { return this->release_threshold_; };
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||
@@ -64,6 +76,9 @@ class MPR121Component : public Component, public i2c::I2CDevice {
|
||||
|
||||
protected:
|
||||
std::vector<MPR121Channel *> channels_{};
|
||||
uint8_t debounce_{0};
|
||||
uint8_t touch_threshold_{};
|
||||
uint8_t release_threshold_{};
|
||||
enum ErrorCode {
|
||||
NONE = 0,
|
||||
COMMUNICATION_FAILED,
|
||||
|
||||
Reference in New Issue
Block a user