#ifndef __THER_INFRARED_HPP__ #define __THER_INFRARED_HPP__ #include #include #include #include #include namespace ther { template class Infrared { public: static auto Init() -> zpp::error { static sensor_trigger tri{.type = SENSOR_TRIG_DATA_READY, .chan = SENSOR_CHAN_AMBIENT_TEMP}; if (auto r = sensor_trigger_set( kDev, &tri, [](const device *dev, const sensor_trigger *trig) { s_is_data_ready = true; }); r != 0) { return -ENODEV; }; } static auto GetSensorValue() -> zpp::result> { if (!s_is_data_ready) { return zpp::error_code::k_nodata; } if (0 != sensor_sample_fetch(kDev)) { return zpp::error_code::k_io; } zpp::value val; if (0 != sensor_channel_get(kDev, SENSOR_CHAN_AMBIENT_TEMP, &val)) { return zpp::error_code::k_io; } s_is_data_ready = false; return val; } private: inline static bool s_is_data_ready{false}; }; } // namespace ther #endif