mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +00:00
fixed issues
This commit is contained in:
parent
db13dd10fa
commit
b15fbae7f2
@ -27,13 +27,9 @@ CONFIG_SCHEMA = cv.Schema({
|
|||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
if CONF_TOUCH_DEBOUNCE in config:
|
|
||||||
cg.add(var.set_touch_debounce(config[CONF_TOUCH_DEBOUNCE]))
|
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]))
|
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]))
|
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]))
|
cg.add(var.set_release_threshold(config[CONF_RELEASE_THRESHOLD]))
|
||||||
yield cg.register_component(var, config)
|
yield cg.register_component(var, config)
|
||||||
yield i2c.register_i2c_device(var, config)
|
yield i2c.register_i2c_device(var, config)
|
||||||
|
@ -12,8 +12,8 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
|||||||
cv.GenerateID(): cv.declare_id(MPR121Channel),
|
cv.GenerateID(): cv.declare_id(MPR121Channel),
|
||||||
cv.GenerateID(CONF_MPR121_ID): cv.use_id(MPR121Component),
|
cv.GenerateID(CONF_MPR121_ID): cv.use_id(MPR121Component),
|
||||||
cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=11),
|
cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=11),
|
||||||
cv.Optional(CONF_TOUCH_THRESHOLD): cv.All(cv.Coerce(int), cv.Range(min=0x05, max=0x30)),
|
cv.Optional(CONF_TOUCH_THRESHOLD): cv.int_range(min=0x05, max=0x30),
|
||||||
cv.Optional(CONF_RELEASE_THRESHOLD): cv.All(cv.Coerce(int), cv.Range(min=0x05, max=0x30)),
|
cv.Optional(CONF_RELEASE_THRESHOLD): cv.int_range(min=0x05, max=0x30),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,8 +19,10 @@ void MPR121Component::setup() {
|
|||||||
|
|
||||||
// set touch sensitivity for all 12 channels
|
// set touch sensitivity for all 12 channels
|
||||||
for (auto *channel : this->channels_) {
|
for (auto *channel : this->channels_) {
|
||||||
this->write_byte(MPR121_TOUCHTH_0 + 2 * channel->get_channel(), channel->get_touch_threshold());
|
this->write_byte(MPR121_TOUCHTH_0 + 2 * channel->channel_,
|
||||||
this->write_byte(MPR121_RELEASETH_0 + 2 * channel->get_channel(), channel->get_release_threshold());
|
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_MHDR, 0x01);
|
||||||
this->write_byte(MPR121_NHDR, 0x01);
|
this->write_byte(MPR121_NHDR, 0x01);
|
||||||
|
@ -46,19 +46,18 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class MPR121Channel : public binary_sensor::BinarySensor {
|
class MPR121Channel : public binary_sensor::BinarySensor {
|
||||||
|
friend class MPR121Component;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_channel(uint8_t channel) { channel_ = channel; }
|
void set_channel(uint8_t channel) { channel_ = channel; }
|
||||||
void process(uint16_t data) { this->publish_state(static_cast<bool>(data & (1 << this->channel_))); }
|
void process(uint16_t data) { this->publish_state(static_cast<bool>(data & (1 << this->channel_))); }
|
||||||
int get_channel() { return this->channel_; };
|
|
||||||
void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
|
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; };
|
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_; };
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t channel_{0};
|
uint8_t channel_{0};
|
||||||
optional<uint8_t> touch_threshold_{};
|
optional<uint8_t> touch_threshold_{};
|
||||||
uint8_t release_threshold_{DEFAULT_RELEASE_THRESHOLD};
|
optional<uint8_t> release_threshold_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class MPR121Component : public Component, public i2c::I2CDevice {
|
class MPR121Component : public Component, public i2c::I2CDevice {
|
||||||
@ -78,8 +77,8 @@ class MPR121Component : public Component, public i2c::I2CDevice {
|
|||||||
protected:
|
protected:
|
||||||
std::vector<MPR121Channel *> channels_{};
|
std::vector<MPR121Channel *> channels_{};
|
||||||
uint8_t debounce_{0};
|
uint8_t debounce_{0};
|
||||||
uint8_t touch_threshold_{12};
|
uint8_t touch_threshold_{};
|
||||||
uint8_t release_threshold_{6};
|
uint8_t release_threshold_{};
|
||||||
enum ErrorCode {
|
enum ErrorCode {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
COMMUNICATION_FAILED,
|
COMMUNICATION_FAILED,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user