ESPHome
2026.3.0
Loading...
Searching...
No Matches
esphome
components
mpr121
binary_sensor
mpr121_binary_sensor.cpp
Go to the documentation of this file.
1
#include "
mpr121_binary_sensor.h
"
2
3
namespace
esphome
{
4
namespace
mpr121 {
5
6
void
MPR121BinarySensor::setup
() {
7
uint8_t touch_threshold = this->
touch_threshold_
.value_or(this->
parent_
->get_touch_threshold());
8
this->
parent_
->write_byte(
MPR121_TOUCHTH_0
+ 2 * this->
channel_
, touch_threshold);
9
10
uint8_t release_threshold = this->
release_threshold_
.value_or(this->
parent_
->get_release_threshold());
11
this->
parent_
->write_byte(
MPR121_RELEASETH_0
+ 2 * this->
channel_
, release_threshold);
12
}
13
14
void
MPR121BinarySensor::process
(uint16_t data) {
15
bool
new_state = data & (1 << this->
channel_
);
16
this->
publish_state
(new_state);
17
}
18
19
}
// namespace mpr121
20
}
// namespace esphome
esphome::Parented< MPR121Component >::parent_
MPR121Component * parent_
Definition
helpers.h:1726
esphome::binary_sensor::BinarySensor::publish_state
void publish_state(bool new_state)
Publish a new state to the front-end.
Definition
binary_sensor.cpp:20
esphome::mpr121::MPR121BinarySensor::channel_
uint8_t channel_
Definition
mpr121_binary_sensor.h:20
esphome::mpr121::MPR121BinarySensor::release_threshold_
optional< uint8_t > release_threshold_
Definition
mpr121_binary_sensor.h:22
esphome::mpr121::MPR121BinarySensor::touch_threshold_
optional< uint8_t > touch_threshold_
Definition
mpr121_binary_sensor.h:21
esphome::mpr121::MPR121BinarySensor::process
void process(uint16_t data) override
Definition
mpr121_binary_sensor.cpp:14
esphome::mpr121::MPR121BinarySensor::setup
void setup() override
Definition
mpr121_binary_sensor.cpp:6
mpr121_binary_sensor.h
esphome::mpr121::MPR121_TOUCHTH_0
@ MPR121_TOUCHTH_0
Definition
mpr121.h:31
esphome::mpr121::MPR121_RELEASETH_0
@ MPR121_RELEASETH_0
Definition
mpr121.h:32
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
Generated by
1.12.0