Buttplug sex toy control library

chore: Get main file loading to DCM working

+109 -20
+4 -2
crates/buttplug_server_device_config/src/device_config_file/device.rs
··· 45 45 if let Some(gap) = self.message_gap_ms { 46 46 builder.message_gap_ms(gap); 47 47 } 48 - for feature in self.features { 49 - builder.add_feature(feature.into()); 48 + if let Some(features) = self.features { 49 + for feature in features { 50 + builder.add_feature(&feature.into()); 51 + } 50 52 } 51 53 builder.finish() 52 54 }
+71 -5
crates/buttplug_server_device_config/src/device_config_file/feature.rs
··· 4 4 use getset::{CopyGetters, Getters, MutGetters, Setters}; 5 5 use serde::{Deserialize, Serialize}; 6 6 use uuid::Uuid; 7 - use crate::{ServerDeviceFeature, ServerDeviceFeatureOutput, ServerDeviceFeatureOutputPositionWithDurationProperties, ServerDeviceFeatureOutputValueProperties}; 7 + use crate::{ServerDeviceFeature, ServerDeviceFeatureInput, ServerDeviceFeatureInputProperties, ServerDeviceFeatureOutput, ServerDeviceFeatureOutputPositionWithDurationProperties, ServerDeviceFeatureOutputValueProperties}; 8 8 9 9 use super::range_sequence_serialize; 10 10 ··· 54 54 #[serde(skip_serializing_if="Option::is_none")] 55 55 spray: Option<BaseDeviceFeatureOutputValueProperties>, 56 56 } 57 - /* 57 + 58 58 impl Into<ServerDeviceFeatureOutput> for BaseDeviceFeatureOutput { 59 59 fn into(self) -> ServerDeviceFeatureOutput { 60 + let mut output = ServerDeviceFeatureOutput::default(); 60 61 if let Some(vibrate) = self.vibrate { 62 + output.set_vibrate(Some(vibrate.into())); 61 63 } 64 + if let Some(rotate) = self.rotate { 65 + output.set_rotate(Some(rotate.into())); 66 + } 67 + if let Some(rotate_with_direction) = self.rotate_with_direction { 68 + output.set_rotate_with_direction(Some(rotate_with_direction.into())); 69 + } 70 + if let Some(oscillate) = self.oscillate { 71 + output.set_oscillate(Some(oscillate.into())); 72 + } 73 + if let Some(constrict) = self.constrict { 74 + output.set_constrict(Some(constrict.into())); 75 + } 76 + if let Some(heater) = self.heater { 77 + output.set_heater(Some(heater.into())); 78 + } 79 + if let Some(led) = self.led { 80 + output.set_led(Some(led.into())); 81 + } 82 + if let Some(position) = self.position { 83 + output.set_position(Some(position.into())); 84 + } 85 + if let Some(position_with_duration) = self.position_with_duration { 86 + output.set_position_with_duration(Some(position_with_duration.into())); 87 + } 88 + if let Some(spray) = self.spray { 89 + output.set_spray(Some(spray.into())); 90 + } 91 + 92 + output 62 93 } 63 94 } 64 - */ 65 95 66 96 #[derive(Serialize, Deserialize, Clone, Debug)] 67 97 struct UserDeviceFeatureOutputValueProperties { ··· 143 173 } 144 174 } 145 175 176 + impl Into<ServerDeviceFeatureInputProperties> for DeviceFeatureInputProperties { 177 + fn into(self) -> ServerDeviceFeatureInputProperties { 178 + ServerDeviceFeatureInputProperties::new(&self.value_range, &self.input_commands) 179 + } 180 + } 181 + 146 182 #[derive( 147 183 Clone, Debug, Default, Getters, Serialize, Deserialize, 148 184 )] ··· 154 190 button: Option<DeviceFeatureInputProperties> 155 191 } 156 192 193 + impl Into<ServerDeviceFeatureInput> for DeviceFeatureInput { 194 + fn into(self) -> ServerDeviceFeatureInput { 195 + let mut input = ServerDeviceFeatureInput::default(); 196 + if let Some(battery) = self.battery { 197 + input.set_battery(Some(battery.into())); 198 + } 199 + if let Some(rssi) = self.rssi { 200 + input.set_rssi(Some(rssi.into())); 201 + } 202 + if let Some(pressure) = self.pressure { 203 + input.set_pressure(Some(pressure.into())); 204 + } 205 + if let Some(button) = self.button { 206 + input.set_button(Some(button.into())); 207 + } 208 + input 209 + } 210 + } 211 + 157 212 #[derive( 158 213 Clone, Debug, Default, Getters, Serialize, Deserialize, CopyGetters, 159 214 )] ··· 179 234 180 235 impl Into<ServerDeviceFeature> for ConfigBaseDeviceFeature { 181 236 fn into(self) -> ServerDeviceFeature { 237 + // This isn't resolving correctly using .and_then, so having to do it the long way? 238 + let output: Option<ServerDeviceFeatureOutput> = if let Some(o) = self.output { 239 + Some(o.into()) 240 + } else { 241 + None 242 + }; 243 + let input: Option<ServerDeviceFeatureInput> = if let Some(i) = self.input { 244 + Some(i.into()) 245 + } else { 246 + None 247 + }; 182 248 ServerDeviceFeature::new( 183 249 &self.description, 184 250 self.id, 185 251 None, 186 252 self.feature_settings.alt_protocol_index, 187 - self.output.into(), 188 - self.input.into() 253 + &output, 254 + &input 189 255 ) 190 256 } 191 257 }
+29 -8
crates/buttplug_server_device_config/src/device_config_file/mod.rs
··· 147 147 dcm_builder.communication_specifier(&protocol_name, &specifiers); 148 148 } 149 149 150 + let mut default = None; 150 151 if let Some(features) = protocol_def.defaults() { 151 - dcm_builder.protocol_features(&BaseDeviceIdentifier::new_default(&protocol_name), features); 152 + default = Some(features.clone()); 153 + dcm_builder.protocol_features(&BaseDeviceIdentifier::new_default(&protocol_name), &features.clone().into()); 152 154 } 153 155 154 - for (config_ident, config) in protocol_def.configurations() { 155 - let ident = BaseDeviceIdentifier::new(&protocol_name, config_ident); 156 - dcm_builder.protocol_features(ident, config.clone()); 156 + for config in protocol_def.configurations() { 157 + if let Some(idents) = config.identifier() { 158 + for config_ident in idents { 159 + let ident = BaseDeviceIdentifier::new(&protocol_name, config_ident); 160 + if let Some(d) = &default { 161 + dcm_builder.protocol_features(&ident, &d.update_with_configuration(config.clone()).into()); 162 + } else { 163 + dcm_builder.protocol_features(&ident, &config.clone().into()); 164 + } 165 + } 166 + } 157 167 } 158 168 } 159 169 ··· 188 198 dcm_builder.protocol_features(&BaseDeviceIdentifier::new_default(&protocol_name), features); 189 199 } 190 200 191 - for (config_ident, config) in protocol_def.configurations() { 192 - let ident = BaseDeviceIdentifier::new(&protocol_name, config_ident); 193 - dcm_builder.protocol_features(ident, config.clone()); 201 + for config in protocol_def.configurations() { 202 + if let Some(idents) = config.identifier() { 203 + for config_ident in idents { 204 + let ident = BaseDeviceIdentifier::new(&protocol_name, config_ident); 205 + dcm_builder.protocol_features(ident, config.clone()); 206 + } 207 + } 194 208 } 195 209 } 196 210 ··· 258 272 259 273 #[cfg(test)] 260 274 mod test { 261 - use super::{load_protocol_config_from_json, DEVICE_CONFIGURATION_JSON, base::BaseConfigFile}; 275 + use crate::device_config_file::load_main_config; 276 + 277 + use super::{load_protocol_config_from_json, DEVICE_CONFIGURATION_JSON, base::BaseConfigFile}; 262 278 263 279 #[test] 264 280 fn test_config_file_parsing() { ··· 266 282 &DEVICE_CONFIGURATION_JSON.to_owned(), 267 283 true 268 284 ).unwrap(); 285 + } 286 + 287 + #[test] 288 + fn test_main_file_parsing() { 289 + load_main_config(&None, false).unwrap(); 269 290 } 270 291 }
+5 -4
crates/buttplug_server_device_config/src/device_feature.rs
··· 14 14 InputCommandType, 15 15 }, 16 16 }; 17 - use getset::{CopyGetters, Getters}; 17 + use getset::{CopyGetters, Getters, Setters}; 18 18 use serde::{ 19 19 Deserialize, 20 20 Serialize, ··· 157 157 } 158 158 } 159 159 160 - #[derive(Clone, Debug)] 160 + #[derive(Clone, Debug, Getters, Setters, Default)] 161 + #[getset(get = "pub", set = "pub(crate)")] 161 162 pub struct ServerDeviceFeatureOutput { 162 163 vibrate: Option<ServerDeviceFeatureOutputValueProperties>, 163 164 rotate: Option<ServerDeviceFeatureOutputValueProperties>, ··· 190 191 } 191 192 } 192 193 193 - #[derive(Clone, Debug, Getters)] 194 - #[getset(get = "pub")] 194 + #[derive(Clone, Debug, Getters, Setters, Default)] 195 + #[getset(get = "pub", set = "pub(crate)")] 195 196 pub struct ServerDeviceFeatureInput { 196 197 battery: Option<ServerDeviceFeatureInputProperties>, 197 198 rssi: Option<ServerDeviceFeatureInputProperties>,
-1
crates/buttplug_server_device_config/src/lib.rs
··· 157 157 158 158 159 159 use std::ops::RangeInclusive; 160 - use serde::Serializer; 161 160 use thiserror::Error; 162 161 163 162 #[derive(Error, Debug)]