1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-14 14:48:18 +00:00

fixed issues

This commit is contained in:
Michiel van Turnhout 2019-05-27 12:43:15 +02:00
parent db13dd10fa
commit b15fbae7f2
4 changed files with 15 additions and 18 deletions

View File

@ -27,13 +27,9 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
if CONF_TOUCH_DEBOUNCE in 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]))
cg.add(var.set_touch_debounce(config[CONF_TOUCH_DEBOUNCE]))
cg.add(var.set_release_debounce(config[CONF_RELEASE_DEBOUNCE]))
cg.add(var.set_touch_threshold(config[CONF_TOUCH_THRESHOLD]))
cg.add(var.set_release_threshold(config[CONF_RELEASE_THRESHOLD]))
yield cg.register_component(var, config)
yield i2c.register_i2c_device(var, config)

View File

@ -12,8 +12,8 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(MPR121Channel),
cv.GenerateID(CONF_MPR121_ID): cv.use_id(MPR121Component),
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_RELEASE_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.int_range(min=0x05, max=0x30),
})

View File

@ -19,8 +19,10 @@ void MPR121Component::setup() {
// set touch sensitivity for all 12 channels
for (auto *channel : this->channels_) {
this->write_byte(MPR121_TOUCHTH_0 + 2 * channel->get_channel(), channel->get_touch_threshold());
this->write_byte(MPR121_RELEASETH_0 + 2 * channel->get_channel(), channel->get_release_threshold());
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);

View File

@ -46,19 +46,18 @@ 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_))); }
int get_channel() { return 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; };
uint8_t get_touch_threshold() { return this->touch_threshold_; };
uint8_t get_release_threshold() { return this->release_threshold_; };
protected:
uint8_t channel_{0};
optional<uint8_t> touch_threshold_{};
uint8_t release_threshold_{DEFAULT_RELEASE_THRESHOLD};
optional<uint8_t> release_threshold_{};
};
class MPR121Component : public Component, public i2c::I2CDevice {
@ -78,8 +77,8 @@ class MPR121Component : public Component, public i2c::I2CDevice {
protected:
std::vector<MPR121Channel *> channels_{};
uint8_t debounce_{0};
uint8_t touch_threshold_{12};
uint8_t release_threshold_{6};
uint8_t touch_threshold_{};
uint8_t release_threshold_{};
enum ErrorCode {
NONE = 0,
COMMUNICATION_FAILED,