cadmus_core/frontlight/
standard.rs1use super::{Frontlight, LightLevels};
2use anyhow::Error;
3use nix::ioctl_write_int_bad;
4use std::fs::File;
5use std::fs::OpenOptions;
6use std::os::unix::io::AsRawFd;
7
8ioctl_write_int_bad!(write_frontlight_intensity, 241);
9const FRONTLIGHT_INTERFACE: &str = "/dev/ntx_io";
10
11pub struct StandardFrontlight {
12 value: f32,
13 interface: File,
14}
15
16impl StandardFrontlight {
17 pub fn new(value: f32) -> Result<StandardFrontlight, Error> {
18 let interface = OpenOptions::new().write(true).open(FRONTLIGHT_INTERFACE)?;
19 Ok(StandardFrontlight { value, interface })
20 }
21}
22
23impl Frontlight for StandardFrontlight {
24 fn set_intensity(&mut self, value: f32) {
25 let ret =
26 unsafe { write_frontlight_intensity(self.interface.as_raw_fd(), value as libc::c_int) };
27 if ret.is_ok() {
28 self.value = value;
29 }
30 }
31
32 fn set_warmth(&mut self, _value: f32) {}
33
34 fn levels(&self) -> LightLevels {
35 LightLevels {
36 intensity: self.value,
37 warmth: 0.0,
38 }
39 }
40}