diff --git a/drivers/drmem-drv-elgato/src/lib.rs b/drivers/drmem-drv-elgato/src/lib.rs index 0982947..b74111c 100644 --- a/drivers/drmem-drv-elgato/src/lib.rs +++ b/drivers/drmem-drv-elgato/src/lib.rs @@ -43,6 +43,7 @@ struct LightState { pub struct Instance { state: DriverState, addr: Ipv4Addr, + poll_interval: Duration, d_on: driver::ReportReading, s_on: driver::SettingStream, d_brightness: driver::ReportReading, @@ -62,8 +63,7 @@ impl Instance { format!("http://{}:9123/elgato/lights", address) } - // Attempts to pull the hostname/port for the remote process. - + // Attempts to pull the hostname for the light. fn get_cfg_address(cfg: &DriverConfig) -> Result { match cfg.get("addr") { Some(toml::value::Value::String(addr)) => { @@ -80,6 +80,19 @@ impl Instance { Err(Error::BadConfig) } + // Attempts to pull the poll interval for the light. + fn get_cfg_poll_interval(cfg: &DriverConfig) -> Result { + match cfg.get("poll_interval") { + Some(toml::value::Value::Integer(interval)) => { + return Ok(Duration::from_millis(*interval as u64)); + } + Some(_) => error!("'poll_interval' config parameter should be an integer"), + None => return Ok(Duration::from_millis(3000)), + } + + Err(Error::BadConfig) + } + async fn get_light_status(&mut self) -> Result { // Get the current status of the light // this allows us to fill the struct with the current values @@ -111,9 +124,11 @@ impl driver::API for Instance { Box> + Send + 'static>, > { let addr = Instance::get_cfg_address(cfg); + let poll_interval = Instance::get_cfg_poll_interval(cfg); let fut = async move { let addr = addr?; + let poll_interval = poll_interval?; // Define the devices managed by this driver. let (d_on, s_on, _) = core @@ -137,6 +152,7 @@ impl driver::API for Instance { Ok(Box::new(Instance { state: DriverState::Unknown, addr, + poll_interval, d_on, s_on, d_brightness, @@ -154,6 +170,7 @@ impl driver::API for Instance { ) -> Pin + Send + 'a>> { let fut = async { let mut timer = + interval_at(Instant::now(), self.poll_interval); let mut on: Option = None; let mut brightness: Option = None; let mut temperature: Option = None;