43 template<auto Context, u8 Index, u32 Offset, u32 MaxValue>
56 DACChannel::s_device = open((
"/sys/bus/iio/devices/iio:device" + std::to_string(Context) +
"/out_voltage" + std::to_string(Index) +
"_raw").c_str(), O_RDWR);
57 return DACChannel::s_device != -1;
66 close(DACChannel::s_device);
76 u32 rawValue = std::max<float>(value * MaxValue - Offset, 0.0F);
78 std::string data = std::to_string(rawValue);
79 lseek(DACChannel::s_device, 0, 0);
80 if (write(DACChannel::s_device, data.data(), data.size()) <= 0)
82 lseek(DACChannel::s_device, 0, 0);
90 operator float() const noexcept {
91 std::string data(0xFF, 0x00);
93 if (read(DACChannel::s_device, data.data(), data.size()) < 0)
95 lseek(DACChannel::s_device, 0, 0);
97 return float(std::max<float>(std::stof(data) + Offset, 0)) / MaxValue;
106 template<auto,
template<auto, u8, u32, u32>
typename>
109 static inline int s_device = -1;