MCPcopy Create free account
hub / github.com/RizeCrime/linuxblaster_control / set_feature

Method set_feature

src/lib.rs:123–164  ·  view source on GitHub ↗

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>,
    )

Source from the content-addressed store, hash-verified

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

Callers 5

apply_profileMethod · 0.80
nav_paneFunction · 0.80
eq_featuresFunction · 0.80
sbx_featuresFunction · 0.80
autoeq_paneFunction · 0.80

Calls 7

featureMethod · 0.80
valueMethod · 0.80
dependenciesMethod · 0.80
write_to_deviceMethod · 0.80
read_from_deviceMethod · 0.80
dependentsMethod · 0.80

Tested by

no test coverage detected