ESPHome  2024.10.2
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 
7 namespace esphome {
8 namespace esp32_hall {
9 
10 static 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 }
19 std::string ESP32HallSensor::unique_id() { return get_mac_address() + "-hall"; }
20 void ESP32HallSensor::dump_config() { LOG_SENSOR("", "ESP32 Hall Sensor", this); }
21 
22 } // namespace esp32_hall
23 } // namespace esphome
24 
25 #endif
std::string unique_id() override
Definition: esp32_hall.cpp:19
std::string get_mac_address()
Get the device MAC address as a string, in lowercase hex notation.
Definition: helpers.cpp:691
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
constexpr const char * c_str() const
Definition: string_ref.h:68
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7