mirror of
https://github.com/esphome/esphome.git
synced 2025-03-14 14:48:18 +00:00
Added thresholds for mpr121 component
to be valid for all channels
This commit is contained in:
parent
96b5c979ca
commit
f2da32ed70
@ -1,7 +1,7 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c
|
||||
from esphome.const import CONF_ID, CONF_RELEASE_DEBOUNCE, CONF_TOUCH_DEBOUNCE
|
||||
from esphome.const import CONF_ID, CONF_RELEASE_DEBOUNCE, CONF_TOUCH_DEBOUNCE, CONF_TOUCH_THRESHOLD, CONF_RELEASE_THRESHOLD
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
AUTO_LOAD = ['binary_sensor']
|
||||
@ -14,7 +14,9 @@ MULTI_CONF = True
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_id(MPR121Component),
|
||||
cv.Optional(CONF_RELEASE_DEBOUNCE): cv.All(cv.Coerce(int), cv.Range(min=0, max=7)),
|
||||
cv.Optional(CONF_TOUCH_DEBOUNCE): cv.All(cv.Coerce(int), cv.Range(min=0, max=7))
|
||||
cv.Optional(CONF_TOUCH_DEBOUNCE): cv.All(cv.Coerce(int), cv.Range(min=0, max=7)),
|
||||
cv.Optional(CONF_TOUCH_THRESHOLD): cv.All(cv.Coerce(int), cv.Range(min=0x05, max=0x30)),
|
||||
cv.Optional(CONF_RELEASE_THRESHOLD): cv.All(cv.Coerce(int), cv.Range(min=0x05, max=0x30)),
|
||||
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x5A))
|
||||
|
||||
|
||||
@ -24,5 +26,9 @@ def to_code(config):
|
||||
cg.add(var.set_touch_debounce(config[CONF_TOUCH_DEBOUNCE]))
|
||||
if CONF_RELEASE_DEBOUNCE in config:
|
||||
cg.add(var.set_release_debounce(config[CONF_RELEASE_DEBOUNCE]))
|
||||
if CONF_TOUCH_THRESHOLD in config:
|
||||
cg.add(var.set_touch_threshold(config[CONF_TOUCH_THRESHOLD]))
|
||||
if CONF_RELEASE_THRESHOLD in config:
|
||||
cg.add(var.set_release_threshold(config[CONF_RELEASE_THRESHOLD]))
|
||||
yield cg.register_component(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
|
@ -19,11 +19,15 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield binary_sensor.register_binary_sensor(var, config)
|
||||
hub = yield cg.get_variable(config[CONF_MPR121_ID])
|
||||
|
||||
cg.add(var.set_channel(config[CONF_CHANNEL]))
|
||||
if CONF_TOUCH_THRESHOLD in config:
|
||||
cg.add(var.set_touch_threshold(config[CONF_TOUCH_THRESHOLD]))
|
||||
else:
|
||||
cg.add(var.set_touch_threshold(hub.get_touch_threshold()))
|
||||
if CONF_RELEASE_THRESHOLD in config:
|
||||
cg.add(var.set_release_threshold(config[CONF_RELEASE_THRESHOLD]))
|
||||
hub = yield cg.get_variable(config[CONF_MPR121_ID])
|
||||
else:
|
||||
cg.add(var.set_release_threshold(hub.get_release_threshold()))
|
||||
cg.add(hub.register_channel(var))
|
||||
|
@ -66,6 +66,10 @@ class MPR121Component : public Component, public i2c::I2CDevice {
|
||||
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; }
|
||||
@ -75,6 +79,8 @@ class MPR121Component : public Component, public i2c::I2CDevice {
|
||||
std::vector<MPR121Channel *> channels_{};
|
||||
uint16_t currtouched_{0};
|
||||
uint8_t debounce_{0};
|
||||
uint8_t touch_threshold_{12};
|
||||
uint8_t release_threshold{6};
|
||||
enum ErrorCode {
|
||||
NONE = 0,
|
||||
COMMUNICATION_FAILED,
|
||||
|
Loading…
x
Reference in New Issue
Block a user