#include "chip_temperature_sensor.h" #include "chip_temperature.h" namespace kvida { void ChipTemperatureSensor::begin() { drivers::chip_temperature_init(); } bool ChipTemperatureSensor::fetch() { float celsius = drivers::chip_temperature_read_celsius(); // Convert to the fixed-point convention (val1 + val2 * 1e-6) once, at // the boundary where the underlying driver hands us a float -- // ESP32-C6 has no hardware FPU, see sensor.h. auto val1 = static_cast(celsius); auto val2 = static_cast((celsius - static_cast(val1)) * 1000000.0f); last_ = SensorValue{val1, val2, "C", 0}; fetched_ = true; return true; } bool ChipTemperatureSensor::get(SensorChannel channel, SensorValue &out) { if (!fetched_ || channel != SensorChannel::ChipTemperature) { return false; } out = last_; return true; } } // namespace kvida