forked from EmbeddedTeam/app_photomagnetic
- Add CONFIG_SAMPLE_NTC to CMakeLists.txt and Kconfig - Implement PI temperature controller with PWM output in heating.hpp - Convert NtcGroup from template to non-template class - Add LED helper class with flash support - Implement COM protocol handlers for device ID and running state - Add SPI, sensor, and PWM configuration to prj.conf - Remove indicator overlay and update main.cpp with temperature monitoring - Add test script for serial protocol communication
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#ifndef THER_NTC_HPP
|
|
#define THER_NTC_HPP
|
|
#include <cmath>
|
|
#include <zephyr/device.h>
|
|
#include <zephyr/drivers/sensor.h>
|
|
#include <zpp/result.hpp>
|
|
|
|
namespace ther {
|
|
|
|
class NtcGroup {
|
|
public:
|
|
/// Read all NTC sensors, return the maximum temperature value.
|
|
/// Returns error if every sensor read fails.
|
|
static auto GetSensorValue() -> zpp::result<sensor_value> {
|
|
bool found = false;
|
|
sensor_value max_val{};
|
|
|
|
for (const auto *dev : s_devices) {
|
|
if (0 != sensor_sample_fetch(dev)) {
|
|
continue;
|
|
}
|
|
|
|
sensor_value val{};
|
|
if (0 != sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &val)) {
|
|
continue;
|
|
}
|
|
|
|
if (!found || val.val1 > max_val.val1 ||
|
|
(val.val1 == max_val.val1 && val.val2 > max_val.val2)) {
|
|
max_val = val;
|
|
found = true;
|
|
}
|
|
}
|
|
|
|
if (found) {
|
|
return max_val;
|
|
}
|
|
|
|
return zpp::error_code::k_io;
|
|
}
|
|
|
|
private:
|
|
inline static const device *s_devices[] = {
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc1)),
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc2)),
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc3)),
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc4)),
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc5)),
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc6)),
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc7)),
|
|
DEVICE_DT_GET(DT_NODELABEL(pole_ntc8)),
|
|
};
|
|
};
|
|
|
|
} // namespace ther
|
|
|
|
#endif // THER_NTC_HPP
|