1
0
mirror of https://github.com/esphome/esphome.git synced 2025-05-31 05:26:17 +01:00
2023-09-01 13:31:27 +12:00

25 lines
626 B
C++

#ifdef USE_ESP32
#include "esp32_hall.h"
#include <driver/adc.h>
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
namespace esphome {
namespace esp32_hall {
static const char *const TAG = "esp32_hall";
void ESP32HallSensor::update() {
adc1_config_width(ADC_WIDTH_BIT_12);
int value_int = hall_sensor_read();
float value = (value_int / 4095.0f) * 10000.0f;
ESP_LOGD(TAG, "'%s': Got reading %.0f µT", this->name_.c_str(), value);
this->publish_state(value);
}
void ESP32HallSensor::dump_config() { LOG_SENSOR("", "ESP32 Hall Sensor", this); }
} // namespace esp32_hall
} // namespace esphome
#endif