Managed Write: enable dependencies, write, confirm, re-query dependents. Automatically calls `read_state_from_device()` after switching the Output. Pass `None` for value to toggle (flip between 0.0 and 1.0).
(
&self,
id: FeatureId,
value: Option<f32>,
)
| 121 | /// |
| 122 | /// Pass `None` for value to toggle (flip between 0.0 and 1.0). |
| 123 | pub fn set_feature( |
| 124 | &self, |
| 125 | id: FeatureId, |
| 126 | value: Option<f32>, |
| 127 | ) -> Result<(), Box<dyn Error>> { |
| 128 | let feature = self.feature(id); |
| 129 | |
| 130 | let actual_value = match value { |
| 131 | Some(value) => value, |
| 132 | None => { |
| 133 | if feature.value() == 0.0 { |
| 134 | 1.0 |
| 135 | } else { |
| 136 | 0.0 |
| 137 | } |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | debug!("set_feature: {} = {}", id, actual_value); |
| 142 | |
| 143 | for &dependency_id in id.dependencies() { |
| 144 | let dependency = self.feature(dependency_id); |
| 145 | if dependency.value() != 1.0 { |
| 146 | debug!("Enabling dependency: {} for {}", dependency_id, id); |
| 147 | self.set_feature(dependency_id, Some(1.0))?; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | feature.write_to_device(actual_value); |
| 152 | feature.read_from_device(); |
| 153 | |
| 154 | for &dependent_id in id.dependents() { |
| 155 | self.feature(dependent_id).read_from_device(); |
| 156 | } |
| 157 | |
| 158 | // changing the output changes the internal settings profile |
| 159 | if feature.id == FeatureId::Output { |
| 160 | self.read_state_from_device(); |
| 161 | } |
| 162 | |
| 163 | Ok(()) |
| 164 | } |
| 165 | |
| 166 | pub fn find_device(api: &HidApi) -> Result<DeviceInfo, Box<dyn Error>> { |
| 167 | let device = api |
no test coverage detected