ESPHome 2025.5.0
Loading...
Searching...
No Matches
esp32_hall.cpp
Go to the documentation of this file.
1#ifdef USE_ESP32
2#include "esp32_hall.h"
3#include "esphome/core/log.h"
4#include "esphome/core/hal.h"
5#include <driver/adc.h>
6
7namespace esphome {
8namespace esp32_hall {
9
10static const char *const TAG = "esp32_hall";
11
13 adc1_config_width(ADC_WIDTH_BIT_12);
14 int value_int = hall_sensor_read();
15 float value = (value_int / 4095.0f) * 10000.0f;
16 ESP_LOGD(TAG, "'%s': Got reading %.0f µT", this->name_.c_str(), value);
17 this->publish_state(value);
18}
19std::string ESP32HallSensor::unique_id() { return get_mac_address() + "-hall"; }
20void ESP32HallSensor::dump_config() { LOG_SENSOR("", "ESP32 Hall Sensor", this); }
21
22} // namespace esp32_hall
23} // namespace esphome
24
25#endif
constexpr const char * c_str() const
Definition string_ref.h:68
std::string unique_id() override
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:39
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string get_mac_address()
Get the device MAC address as a string, in lowercase hex notation.
Definition helpers.cpp:726