ESPHome  2022.12.8
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 name_
Definition: entity_base.h:54
std::string get_mac_address()
Get the device MAC address as a string, in lowercase hex notation.
Definition: helpers.cpp:442
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:72
Definition: a4988.cpp:4