ESPHome
2026.8.0-dev
Loading...
Searching...
No Matches
esphome
components
waveshare_io_ch32v003
sensor
waveshare_io_ch32v003_sensor.cpp
Go to the documentation of this file.
1
#include "
waveshare_io_ch32v003_sensor.h
"
2
3
#include "
esphome/core/log.h
"
4
5
namespace
esphome::waveshare_io_ch32v003
{
6
7
static
const
char
*
const
TAG
=
"waveshare_io_ch32v003.sensor"
;
8
9
float
WaveshareIOCH32V003Sensor::get_setup_priority
()
const
{
return
setup_priority::DATA
; }
10
11
void
WaveshareIOCH32V003Sensor::dump_config
() {
12
ESP_LOGCONFIG(TAG,
13
"WaveshareIOCH32V003Sensor:\n"
14
" Reference Voltage: %.2fV"
,
15
this->
reference_voltage_
);
16
}
17
18
float
WaveshareIOCH32V003Sensor::sample
() {
19
uint16_t adc_value = this->
parent_
->get_adc_value();
20
// Convert the ADC value to voltage. 10-bit ADC
21
float
voltage = adc_value * this->
reference_voltage_
/ 1023.0f;
22
return
voltage;
23
}
24
25
void
WaveshareIOCH32V003Sensor::update
() { this->
publish_state
(this->
sample
()); }
26
27
}
// namespace esphome::waveshare_io_ch32v003
esphome::Parented< WaveshareIOCH32V003Component >::parent_
WaveshareIOCH32V003Component * parent_
Definition
helpers.h:1886
esphome::sensor::Sensor::publish_state
void publish_state(float state)
Publish a new state to the front-end.
Definition
sensor.cpp:68
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::sample
float sample() override
Definition
waveshare_io_ch32v003_sensor.cpp:18
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::get_setup_priority
float get_setup_priority() const override
Definition
waveshare_io_ch32v003_sensor.cpp:9
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::dump_config
void dump_config() override
Definition
waveshare_io_ch32v003_sensor.cpp:11
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::reference_voltage_
float reference_voltage_
Definition
waveshare_io_ch32v003_sensor.h:26
esphome::waveshare_io_ch32v003::WaveshareIOCH32V003Sensor::update
void update() override
Definition
waveshare_io_ch32v003_sensor.cpp:25
log.h
esphome::setup_priority::DATA
constexpr float DATA
For components that import data from directly connected sensors like DHT.
Definition
component.h:45
esphome::spi::TAG
const char *const TAG
Definition
spi.cpp:7
esphome::waveshare_io_ch32v003
Definition
waveshare_io_ch32v003_output.cpp:5
waveshare_io_ch32v003_sensor.h
Generated by
1.12.0