Buttplug sex toy control library

chore: Run rustfmt

+3542 -3040
+10 -8
crates/buttplug_client/src/client_event_loop.rs
··· 8 8 //! Implementation of internal Buttplug Client event loop. 9 9 10 10 use super::{ 11 - client_message_sorter::ClientMessageSorter, 12 - device::{ButtplugClientDevice, ButtplugClientDeviceEvent}, 13 11 ButtplugClientEvent, 14 12 ButtplugClientMessageFuturePair, 15 13 ButtplugClientMessageSender, 14 + client_message_sorter::ClientMessageSorter, 15 + device::{ButtplugClientDevice, ButtplugClientDeviceEvent}, 16 16 }; 17 17 use buttplug_core::{ 18 18 connector::{ButtplugConnector, ButtplugConnectorStateShared}, ··· 29 29 use dashmap::DashMap; 30 30 use log::*; 31 31 use std::sync::{ 32 - atomic::{AtomicBool, Ordering}, 33 32 Arc, 33 + atomic::{AtomicBool, Ordering}, 34 34 }; 35 35 use tokio::{ 36 36 select, ··· 151 151 // If it doesn't, insert it. 152 152 None => { 153 153 debug!("Device does not exist, creating new entry."); 154 - let device = ButtplugClientDevice::new_from_device_info( 155 - info, 156 - &self.from_client_sender, 157 - ); 154 + let device = ButtplugClientDevice::new_from_device_info(info, &self.from_client_sender); 158 155 self.device_map.insert(info.device_index(), device.clone()); 159 156 device 160 157 } ··· 226 223 self.send_client_event(ButtplugClientEvent::DeviceAdded(device)); 227 224 } 228 225 let new_indexes: Vec<u32> = list.devices().iter().map(|x| x.1.device_index()).collect(); 229 - let disconnected_indexes: Vec<u32> = self.device_map.iter().filter(|x| !new_indexes.contains(x.key())).map(|x| *x.key()).collect(); 226 + let disconnected_indexes: Vec<u32> = self 227 + .device_map 228 + .iter() 229 + .filter(|x| !new_indexes.contains(x.key())) 230 + .map(|x| *x.key()) 231 + .collect(); 230 232 for index in disconnected_indexes { 231 233 trace!("Device removed, updating map and sending to client"); 232 234 self.disconnect_device(index);
+1 -1
crates/buttplug_client/src/client_message_sorter.rs
··· 16 16 use dashmap::DashMap; 17 17 use log::*; 18 18 use std::sync::{ 19 - atomic::{AtomicU32, Ordering}, 20 19 Arc, 20 + atomic::{AtomicU32, Ordering}, 21 21 }; 22 22 23 23 /// Message sorting and pairing for remote client connectors.
+30 -10
crates/buttplug_client/src/device/command.rs
··· 45 45 impl Into<OutputType> for &ClientDeviceOutputCommand { 46 46 fn into(self) -> OutputType { 47 47 match self { 48 - ClientDeviceOutputCommand::Vibrate(_) | ClientDeviceOutputCommand::VibrateFloat(_) => OutputType::Vibrate, 49 - ClientDeviceOutputCommand::Oscillate(_) | ClientDeviceOutputCommand::OscillateFloat(_) => OutputType::Oscillate, 50 - ClientDeviceOutputCommand::Rotate(_) | ClientDeviceOutputCommand::RotateFloat(_) => OutputType::Rotate, 51 - ClientDeviceOutputCommand::Constrict(_) | ClientDeviceOutputCommand::ConstrictFloat(_) => OutputType::Constrict, 52 - ClientDeviceOutputCommand::Heater(_) | ClientDeviceOutputCommand::HeaterFloat(_) => OutputType::Heater, 48 + ClientDeviceOutputCommand::Vibrate(_) | ClientDeviceOutputCommand::VibrateFloat(_) => { 49 + OutputType::Vibrate 50 + } 51 + ClientDeviceOutputCommand::Oscillate(_) | ClientDeviceOutputCommand::OscillateFloat(_) => { 52 + OutputType::Oscillate 53 + } 54 + ClientDeviceOutputCommand::Rotate(_) | ClientDeviceOutputCommand::RotateFloat(_) => { 55 + OutputType::Rotate 56 + } 57 + ClientDeviceOutputCommand::Constrict(_) | ClientDeviceOutputCommand::ConstrictFloat(_) => { 58 + OutputType::Constrict 59 + } 60 + ClientDeviceOutputCommand::Heater(_) | ClientDeviceOutputCommand::HeaterFloat(_) => { 61 + OutputType::Heater 62 + } 53 63 ClientDeviceOutputCommand::Led(_) | ClientDeviceOutputCommand::LedFloat(_) => OutputType::Led, 54 - ClientDeviceOutputCommand::Spray(_) | ClientDeviceOutputCommand::SprayFloat(_) => OutputType::Spray, 55 - ClientDeviceOutputCommand::Position(_) | ClientDeviceOutputCommand::PositionFloat(_) => OutputType::Position, 56 - ClientDeviceOutputCommand::PositionWithDuration(_, _) | ClientDeviceOutputCommand::PositionWithDurationFloat(_, _) => OutputType::PositionWithDuration, 57 - ClientDeviceOutputCommand::RotateWithDirection(_, _) | ClientDeviceOutputCommand::RotateWithDirectionFloat(_, _) => OutputType::RotateWithDirection, 64 + ClientDeviceOutputCommand::Spray(_) | ClientDeviceOutputCommand::SprayFloat(_) => { 65 + OutputType::Spray 66 + } 67 + ClientDeviceOutputCommand::Position(_) | ClientDeviceOutputCommand::PositionFloat(_) => { 68 + OutputType::Position 69 + } 70 + ClientDeviceOutputCommand::PositionWithDuration(_, _) 71 + | ClientDeviceOutputCommand::PositionWithDurationFloat(_, _) => { 72 + OutputType::PositionWithDuration 73 + } 74 + ClientDeviceOutputCommand::RotateWithDirection(_, _) 75 + | ClientDeviceOutputCommand::RotateWithDirectionFloat(_, _) => { 76 + OutputType::RotateWithDirection 77 + } 58 78 } 59 79 } 60 - } 80 + }
+59 -39
crates/buttplug_client/src/device/device.rs
··· 10 10 use crate::device::{ClientDeviceCommandValue, ClientDeviceOutputCommand}; 11 11 12 12 use crate::{ 13 - device::ClientDeviceFeature, 14 - create_boxed_future_client_error, 15 13 ButtplugClientMessageSender, 16 14 ButtplugClientResultFuture, 15 + create_boxed_future_client_error, 16 + device::ClientDeviceFeature, 17 17 }; 18 18 use buttplug_core::message::InputType; 19 19 use buttplug_core::{ 20 20 errors::ButtplugDeviceError, 21 21 message::{ 22 - ButtplugServerMessageV4, DeviceFeature, DeviceMessageInfoV4, OutputType, StopDeviceCmdV0 22 + ButtplugServerMessageV4, 23 + DeviceFeature, 24 + DeviceMessageInfoV4, 25 + OutputType, 26 + StopDeviceCmdV0, 23 27 }, 24 28 util::stream::convert_broadcast_receiver_to_stream, 25 29 }; 26 - use futures::{future, FutureExt, Stream}; 30 + use futures::{FutureExt, Stream, future}; 27 31 use getset::{CopyGetters, Getters}; 28 32 use log::*; 29 33 use std::collections::BTreeMap; 30 34 use std::{ 31 - fmt, sync::{ 35 + fmt, 36 + sync::{ 37 + Arc, 32 38 atomic::{AtomicBool, Ordering}, 33 - Arc, 34 - } 39 + }, 35 40 }; 36 41 use tokio::sync::broadcast; 37 42 ··· 120 125 name: name.to_owned(), 121 126 display_name: display_name.clone(), 122 127 index, 123 - device_features: device_features.iter().map(|(i, x)| (*i, ClientDeviceFeature::new(index, *i, &x, message_sender))).collect(), 128 + device_features: device_features 129 + .iter() 130 + .map(|(i, x)| (*i, ClientDeviceFeature::new(index, *i, &x, message_sender))) 131 + .collect(), 124 132 event_loop_sender: message_sender.clone(), 125 133 internal_event_sender: event_sender, 126 134 device_connected, ··· 156 164 .device_features 157 165 .iter() 158 166 .filter(|x| { 159 - if let Some(output) = x.1 160 - .feature() 161 - .output() { 167 + if let Some(output) = x.1.feature().output() { 162 168 output.contains(actuator_type) 163 - } else { 169 + } else { 164 170 false 165 171 } 166 172 }) ··· 169 175 .collect() 170 176 } 171 177 172 - fn set_client_value(&self, client_device_command: &ClientDeviceOutputCommand) -> ButtplugClientResultFuture { 178 + fn set_client_value( 179 + &self, 180 + client_device_command: &ClientDeviceOutputCommand, 181 + ) -> ButtplugClientResultFuture { 173 182 let features = self.filter_device_actuators(client_device_command.into()); 174 183 if features.is_empty() { 175 184 // TODO err 176 185 } 177 - let mut fut_vec: Vec<ButtplugClientResultFuture> = vec!(); 186 + let mut fut_vec: Vec<ButtplugClientResultFuture> = vec![]; 178 187 for x in features { 179 188 let val = x.convert_client_cmd_to_output_cmd(client_device_command); 180 189 match val { 181 - Ok(v) => fut_vec.push(self.event_loop_sender.send_message_expect_ok( 182 - v.into(), 183 - )), 184 - Err(e) => return future::ready(Err(e)).boxed() 185 - } 190 + Ok(v) => fut_vec.push(self.event_loop_sender.send_message_expect_ok(v.into())), 191 + Err(e) => return future::ready(Err(e)).boxed(), 192 + } 186 193 } 187 194 async move { 188 195 futures::future::try_join_all(fut_vec).await?; ··· 191 198 .boxed() 192 199 } 193 200 194 - pub fn send_command(&self, client_device_command: &ClientDeviceOutputCommand) -> ButtplugClientResultFuture { 201 + pub fn send_command( 202 + &self, 203 + client_device_command: &ClientDeviceOutputCommand, 204 + ) -> ButtplugClientResultFuture { 195 205 self.set_client_value(client_device_command) 196 206 } 197 207 ··· 204 214 let val = level.into(); 205 215 self.set_client_value(&match val { 206 216 ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::Vibrate(v), 207 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::VibrateFloat(f) 217 + ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::VibrateFloat(f), 208 218 }) 209 219 } 210 220 211 221 pub fn has_battery_level(&self) -> bool { 212 - self 213 - .device_features 214 - .iter() 215 - .any(|x| x.1.feature().input().as_ref().is_some_and(|x| x.contains(InputType::Battery))) 222 + self.device_features.iter().any(|x| { 223 + x.1 224 + .feature() 225 + .input() 226 + .as_ref() 227 + .is_some_and(|x| x.contains(InputType::Battery)) 228 + }) 216 229 } 217 230 218 231 pub fn battery_level(&self) -> ButtplugClientResultFuture<u32> { 219 - if let Some(battery) = self 220 - .device_features 221 - .iter() 222 - .find(|x| x.1.feature().input().as_ref().is_some_and(|x| x.contains(InputType::Battery))) 223 - { 232 + if let Some(battery) = self.device_features.iter().find(|x| { 233 + x.1 234 + .feature() 235 + .input() 236 + .as_ref() 237 + .is_some_and(|x| x.contains(InputType::Battery)) 238 + }) { 224 239 battery.1.battery_level() 225 240 } else { 226 241 create_boxed_future_client_error( ··· 233 248 } 234 249 235 250 pub fn has_rssi_level(&self) -> bool { 236 - self 237 - .device_features 238 - .iter() 239 - .any(|x| x.1.feature().input().as_ref().is_some_and(|x| x.contains(InputType::Rssi))) 251 + self.device_features.iter().any(|x| { 252 + x.1 253 + .feature() 254 + .input() 255 + .as_ref() 256 + .is_some_and(|x| x.contains(InputType::Rssi)) 257 + }) 240 258 } 241 259 242 260 pub fn rssi_level(&self) -> ButtplugClientResultFuture<i8> { 243 - if let Some(rssi) = self 244 - .device_features 245 - .iter() 246 - .find(|x| x.1.feature().input().as_ref().is_some_and(|x| x.contains(InputType::Rssi))) 247 - { 261 + if let Some(rssi) = self.device_features.iter().find(|x| { 262 + x.1 263 + .feature() 264 + .input() 265 + .as_ref() 266 + .is_some_and(|x| x.contains(InputType::Rssi)) 267 + }) { 248 268 rssi.1.rssi_level() 249 269 } else { 250 270 create_boxed_future_client_error(
+171 -52
crates/buttplug_client/src/device/feature.rs
··· 1 - use futures::{future, FutureExt}; 1 + use futures::{FutureExt, future}; 2 2 use getset::{CopyGetters, Getters}; 3 3 4 4 use buttplug_core::{ 5 5 errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError}, 6 6 message::{ 7 - ButtplugDeviceMessageNameV4, ButtplugServerMessageV4, DeviceFeature, DeviceFeatureOutputLimits, InputCmdV4, InputCommandType, InputType, InputTypeData, OutputCmdV4, OutputCommand, OutputPositionWithDuration, OutputRotateWithDirection, OutputType, OutputValue 7 + ButtplugDeviceMessageNameV4, 8 + ButtplugServerMessageV4, 9 + DeviceFeature, 10 + DeviceFeatureOutputLimits, 11 + InputCmdV4, 12 + InputCommandType, 13 + InputType, 14 + InputTypeData, 15 + OutputCmdV4, 16 + OutputCommand, 17 + OutputPositionWithDuration, 18 + OutputRotateWithDirection, 19 + OutputType, 20 + OutputValue, 8 21 }, 9 22 }; 10 23 11 24 use super::ClientDeviceOutputCommand; 12 25 13 26 use crate::{ 14 - create_boxed_future_client_error, device::ClientDeviceCommandValue, ButtplugClientError, ButtplugClientMessageSender, ButtplugClientResultFuture 27 + ButtplugClientError, 28 + ButtplugClientMessageSender, 29 + ButtplugClientResultFuture, 30 + create_boxed_future_client_error, 31 + device::ClientDeviceCommandValue, 15 32 }; 16 33 17 34 #[derive(Getters, CopyGetters, Clone)] ··· 44 61 } 45 62 } 46 63 47 - fn check_step_value(&self, feature_output: &dyn DeviceFeatureOutputLimits, steps: u32) -> Result<u32, ButtplugClientError> { 64 + fn check_step_value( 65 + &self, 66 + feature_output: &dyn DeviceFeatureOutputLimits, 67 + steps: u32, 68 + ) -> Result<u32, ButtplugClientError> { 48 69 if feature_output.step_limit().contains(&(steps as i32)) { 49 70 Ok(steps) 50 71 } else { 51 - Err(ButtplugClientError::ButtplugOutputCommandConversionError(format!("{} is larger than the maximum number of steps ({}).", steps, feature_output.step_count()))) 72 + Err(ButtplugClientError::ButtplugOutputCommandConversionError( 73 + format!( 74 + "{} is larger than the maximum number of steps ({}).", 75 + steps, 76 + feature_output.step_count() 77 + ), 78 + )) 52 79 } 53 80 } 54 81 55 - fn convert_float_value(&self, feature_output: &dyn DeviceFeatureOutputLimits, float_amt: f64) -> Result<u32, ButtplugClientError> { 82 + fn convert_float_value( 83 + &self, 84 + feature_output: &dyn DeviceFeatureOutputLimits, 85 + float_amt: f64, 86 + ) -> Result<u32, ButtplugClientError> { 56 87 if float_amt < 0.0f64 || float_amt > 1.0f64 { 57 - Err(ButtplugClientError::ButtplugOutputCommandConversionError("Float values must be between 0.0 and 1.0".to_owned())) 88 + Err(ButtplugClientError::ButtplugOutputCommandConversionError( 89 + "Float values must be between 0.0 and 1.0".to_owned(), 90 + )) 58 91 } else { 59 92 Ok((float_amt * feature_output.step_count() as f64).ceil() as u32) 60 93 } 61 94 } 62 95 63 - pub(super) fn convert_client_cmd_to_output_cmd(&self, client_cmd: &ClientDeviceOutputCommand) -> Result<OutputCmdV4, ButtplugClientError> { 64 - let output_type: OutputType = client_cmd.into(); 96 + pub(super) fn convert_client_cmd_to_output_cmd( 97 + &self, 98 + client_cmd: &ClientDeviceOutputCommand, 99 + ) -> Result<OutputCmdV4, ButtplugClientError> { 100 + let output_type: OutputType = client_cmd.into(); 65 101 // First off, make sure we support this output. 66 102 let output = self 67 103 .feature 68 104 .output() 69 105 .as_ref() 70 - .ok_or(ButtplugClientError::ButtplugOutputCommandConversionError(format!("Device feature does not support output type {}", output_type)))? 106 + .ok_or(ButtplugClientError::ButtplugOutputCommandConversionError( 107 + format!( 108 + "Device feature does not support output type {}", 109 + output_type 110 + ), 111 + ))? 71 112 .get(output_type) 72 - .ok_or(ButtplugClientError::ButtplugOutputCommandConversionError(format!("Device feature does not support output type {}", output_type)))?; 113 + .ok_or(ButtplugClientError::ButtplugOutputCommandConversionError( 114 + format!( 115 + "Device feature does not support output type {}", 116 + output_type 117 + ), 118 + ))?; 73 119 74 120 let output_cmd = match client_cmd { 75 - ClientDeviceOutputCommand::VibrateFloat(v) => OutputCommand::Vibrate(OutputValue::new(self.convert_float_value(output, *v)?)), 76 - ClientDeviceOutputCommand::OscillateFloat(v) => OutputCommand::Oscillate(OutputValue::new(self.convert_float_value(output, *v)?)), 77 - ClientDeviceOutputCommand::RotateFloat(v) => OutputCommand::Rotate(OutputValue::new(self.convert_float_value(output, *v)?)), 78 - ClientDeviceOutputCommand::ConstrictFloat(v) => OutputCommand::Constrict(OutputValue::new(self.convert_float_value(output, *v)?)), 79 - ClientDeviceOutputCommand::HeaterFloat(v) => OutputCommand::Heater(OutputValue::new(self.convert_float_value(output, *v)?)), 80 - ClientDeviceOutputCommand::LedFloat(v )=> OutputCommand::Led(OutputValue::new(self.convert_float_value(output, *v)?)), 81 - ClientDeviceOutputCommand::SprayFloat(v) => OutputCommand::Spray(OutputValue::new(self.convert_float_value(output, *v)?)), 82 - ClientDeviceOutputCommand::PositionFloat(v) => OutputCommand::Position(OutputValue::new(self.convert_float_value(output, *v)?)), 83 - ClientDeviceOutputCommand::PositionWithDurationFloat(v, d) => OutputCommand::PositionWithDuration(OutputPositionWithDuration::new(self.convert_float_value(output, *v)?, *d)), 84 - ClientDeviceOutputCommand::RotateWithDirectionFloat(v, d) => OutputCommand::RotateWithDirection(OutputRotateWithDirection::new(self.convert_float_value(output, *v)?, *d)), 85 - ClientDeviceOutputCommand::Vibrate(v) => OutputCommand::Vibrate(OutputValue::new(self.check_step_value(output, *v)?)), 86 - ClientDeviceOutputCommand::Oscillate(v) => OutputCommand::Oscillate(OutputValue::new(self.check_step_value(output, *v)?)), 87 - ClientDeviceOutputCommand::Rotate(v) => OutputCommand::Rotate(OutputValue::new(self.check_step_value(output, *v)?)), 88 - ClientDeviceOutputCommand::Constrict(v) => OutputCommand::Constrict(OutputValue::new(self.check_step_value(output, *v)?)), 89 - ClientDeviceOutputCommand::Heater(v) => OutputCommand::Heater(OutputValue::new(self.check_step_value(output, *v)?)), 90 - ClientDeviceOutputCommand::Led(v )=> OutputCommand::Led(OutputValue::new(self.check_step_value(output, *v)?)), 91 - ClientDeviceOutputCommand::Spray(v) => OutputCommand::Spray(OutputValue::new(self.check_step_value(output, *v)?)), 92 - ClientDeviceOutputCommand::Position(v) => OutputCommand::Position(OutputValue::new(self.check_step_value(output, *v)?)), 93 - ClientDeviceOutputCommand::PositionWithDuration(v, d) => OutputCommand::PositionWithDuration(OutputPositionWithDuration::new(self.check_step_value(output, *v)?, *d)), 94 - ClientDeviceOutputCommand::RotateWithDirection(v, d) => OutputCommand::RotateWithDirection(OutputRotateWithDirection::new(self.check_step_value(output, *v)?, *d)), 121 + ClientDeviceOutputCommand::VibrateFloat(v) => { 122 + OutputCommand::Vibrate(OutputValue::new(self.convert_float_value(output, *v)?)) 123 + } 124 + ClientDeviceOutputCommand::OscillateFloat(v) => { 125 + OutputCommand::Oscillate(OutputValue::new(self.convert_float_value(output, *v)?)) 126 + } 127 + ClientDeviceOutputCommand::RotateFloat(v) => { 128 + OutputCommand::Rotate(OutputValue::new(self.convert_float_value(output, *v)?)) 129 + } 130 + ClientDeviceOutputCommand::ConstrictFloat(v) => { 131 + OutputCommand::Constrict(OutputValue::new(self.convert_float_value(output, *v)?)) 132 + } 133 + ClientDeviceOutputCommand::HeaterFloat(v) => { 134 + OutputCommand::Heater(OutputValue::new(self.convert_float_value(output, *v)?)) 135 + } 136 + ClientDeviceOutputCommand::LedFloat(v) => { 137 + OutputCommand::Led(OutputValue::new(self.convert_float_value(output, *v)?)) 138 + } 139 + ClientDeviceOutputCommand::SprayFloat(v) => { 140 + OutputCommand::Spray(OutputValue::new(self.convert_float_value(output, *v)?)) 141 + } 142 + ClientDeviceOutputCommand::PositionFloat(v) => { 143 + OutputCommand::Position(OutputValue::new(self.convert_float_value(output, *v)?)) 144 + } 145 + ClientDeviceOutputCommand::PositionWithDurationFloat(v, d) => { 146 + OutputCommand::PositionWithDuration(OutputPositionWithDuration::new( 147 + self.convert_float_value(output, *v)?, 148 + *d, 149 + )) 150 + } 151 + ClientDeviceOutputCommand::RotateWithDirectionFloat(v, d) => { 152 + OutputCommand::RotateWithDirection(OutputRotateWithDirection::new( 153 + self.convert_float_value(output, *v)?, 154 + *d, 155 + )) 156 + } 157 + ClientDeviceOutputCommand::Vibrate(v) => { 158 + OutputCommand::Vibrate(OutputValue::new(self.check_step_value(output, *v)?)) 159 + } 160 + ClientDeviceOutputCommand::Oscillate(v) => { 161 + OutputCommand::Oscillate(OutputValue::new(self.check_step_value(output, *v)?)) 162 + } 163 + ClientDeviceOutputCommand::Rotate(v) => { 164 + OutputCommand::Rotate(OutputValue::new(self.check_step_value(output, *v)?)) 165 + } 166 + ClientDeviceOutputCommand::Constrict(v) => { 167 + OutputCommand::Constrict(OutputValue::new(self.check_step_value(output, *v)?)) 168 + } 169 + ClientDeviceOutputCommand::Heater(v) => { 170 + OutputCommand::Heater(OutputValue::new(self.check_step_value(output, *v)?)) 171 + } 172 + ClientDeviceOutputCommand::Led(v) => { 173 + OutputCommand::Led(OutputValue::new(self.check_step_value(output, *v)?)) 174 + } 175 + ClientDeviceOutputCommand::Spray(v) => { 176 + OutputCommand::Spray(OutputValue::new(self.check_step_value(output, *v)?)) 177 + } 178 + ClientDeviceOutputCommand::Position(v) => { 179 + OutputCommand::Position(OutputValue::new(self.check_step_value(output, *v)?)) 180 + } 181 + ClientDeviceOutputCommand::PositionWithDuration(v, d) => OutputCommand::PositionWithDuration( 182 + OutputPositionWithDuration::new(self.check_step_value(output, *v)?, *d), 183 + ), 184 + ClientDeviceOutputCommand::RotateWithDirection(v, d) => OutputCommand::RotateWithDirection( 185 + OutputRotateWithDirection::new(self.check_step_value(output, *v)?, *d), 186 + ), 95 187 }; 96 - Ok(OutputCmdV4::new(self.device_index, self.feature_index, output_cmd)) 188 + Ok(OutputCmdV4::new( 189 + self.device_index, 190 + self.feature_index, 191 + output_cmd, 192 + )) 97 193 } 98 194 99 - pub fn send_command(&self, client_device_command: &ClientDeviceOutputCommand) -> ButtplugClientResultFuture { 195 + pub fn send_command( 196 + &self, 197 + client_device_command: &ClientDeviceOutputCommand, 198 + ) -> ButtplugClientResultFuture { 100 199 match self.convert_client_cmd_to_output_cmd(&client_device_command) { 101 200 Ok(cmd) => self.event_loop_sender.send_message_expect_ok(cmd.into()), 102 - Err(e) => future::ready(Err(e)).boxed() 201 + Err(e) => future::ready(Err(e)).boxed(), 103 202 } 104 203 } 105 204 ··· 107 206 let val = level.into(); 108 207 self.send_command(&match val { 109 208 ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::Vibrate(v), 110 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::VibrateFloat(f) 209 + ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::VibrateFloat(f), 111 210 }) 112 211 } 113 212 114 - pub fn oscillate(&self, level: impl Into<ClientDeviceCommandValue>) -> ButtplugClientResultFuture { 213 + pub fn oscillate( 214 + &self, 215 + level: impl Into<ClientDeviceCommandValue>, 216 + ) -> ButtplugClientResultFuture { 115 217 let val = level.into(); 116 218 self.send_command(&match val { 117 219 ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::Oscillate(v), 118 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::OscillateFloat(f) 220 + ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::OscillateFloat(f), 119 221 }) 120 222 } 121 223 ··· 123 225 let val = level.into(); 124 226 self.send_command(&match val { 125 227 ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::Rotate(v), 126 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::RotateFloat(f) 228 + ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::RotateFloat(f), 127 229 }) 128 230 } 129 231 ··· 131 233 let val = level.into(); 132 234 self.send_command(&match val { 133 235 ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::Spray(v), 134 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::SprayFloat(f) 236 + ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::SprayFloat(f), 135 237 }) 136 238 } 137 239 138 - pub fn constrict(&self, level: impl Into<ClientDeviceCommandValue>) -> ButtplugClientResultFuture { 240 + pub fn constrict( 241 + &self, 242 + level: impl Into<ClientDeviceCommandValue>, 243 + ) -> ButtplugClientResultFuture { 139 244 let val = level.into(); 140 245 self.send_command(&match val { 141 246 ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::Constrict(v), 142 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::ConstrictFloat(f) 247 + ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::ConstrictFloat(f), 143 248 }) 144 249 } 145 250 ··· 147 252 let val = level.into(); 148 253 self.send_command(&match val { 149 254 ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::Position(v), 150 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::PositionFloat(f) 255 + ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::PositionFloat(f), 151 256 }) 152 257 } 153 258 ··· 158 263 ) -> ButtplugClientResultFuture { 159 264 let val = position.into(); 160 265 self.send_command(&match val { 161 - ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::PositionWithDuration(v, duration_in_ms), 162 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::PositionWithDurationFloat(f, duration_in_ms) 266 + ClientDeviceCommandValue::Int(v) => { 267 + ClientDeviceOutputCommand::PositionWithDuration(v, duration_in_ms) 268 + } 269 + ClientDeviceCommandValue::Float(f) => { 270 + ClientDeviceOutputCommand::PositionWithDurationFloat(f, duration_in_ms) 271 + } 163 272 }) 164 273 } 165 274 166 - pub fn rotate_with_direction(&self, level: impl Into<ClientDeviceCommandValue>, clockwise: bool) -> ButtplugClientResultFuture { 275 + pub fn rotate_with_direction( 276 + &self, 277 + level: impl Into<ClientDeviceCommandValue>, 278 + clockwise: bool, 279 + ) -> ButtplugClientResultFuture { 167 280 let val = level.into(); 168 281 self.send_command(&match val { 169 - ClientDeviceCommandValue::Int(v) => ClientDeviceOutputCommand::RotateWithDirection(v, clockwise), 170 - ClientDeviceCommandValue::Float(f) => ClientDeviceOutputCommand::RotateWithDirectionFloat(f, clockwise) 282 + ClientDeviceCommandValue::Int(v) => { 283 + ClientDeviceOutputCommand::RotateWithDirection(v, clockwise) 284 + } 285 + ClientDeviceCommandValue::Float(f) => { 286 + ClientDeviceOutputCommand::RotateWithDirectionFloat(f, clockwise) 287 + } 171 288 }) 172 289 } 173 290 ··· 236 353 if sensor_type == data.data().as_input_type() { 237 354 Ok(data.data()) 238 355 } else { 239 - Err(ButtplugError::ButtplugMessageError(ButtplugMessageError::UnexpectedMessageType( 240 - "InputReading".to_owned(), 241 - )) 242 - .into()) 356 + Err( 357 + ButtplugError::ButtplugMessageError(ButtplugMessageError::UnexpectedMessageType( 358 + "InputReading".to_owned(), 359 + )) 360 + .into(), 361 + ) 243 362 } 244 363 } else { 245 364 Err( 246 365 ButtplugError::ButtplugMessageError(ButtplugMessageError::UnexpectedMessageType( 247 366 "InputReading".to_owned(), 248 367 )) 249 - .into() 368 + .into(), 250 369 ) 251 370 } 252 371 }
+2 -2
crates/buttplug_client/src/device/mod.rs
··· 1 + mod command; 1 2 mod device; 2 3 mod feature; 3 - mod command; 4 4 5 + pub use command::*; 5 6 pub use device::*; 6 7 pub use feature::*; 7 - pub use command::*;
+14 -14
crates/buttplug_client/src/lib.rs
··· 16 16 connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorFuture}, 17 17 errors::{ButtplugError, ButtplugHandshakeError}, 18 18 message::{ 19 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 20 + BUTTPLUG_CURRENT_API_MINOR_VERSION, 19 21 ButtplugClientMessageV4, 20 22 ButtplugServerMessageV4, 21 23 PingV0, ··· 24 26 StartScanningV0, 25 27 StopAllDevicesV0, 26 28 StopScanningV0, 27 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 28 - BUTTPLUG_CURRENT_API_MINOR_VERSION, 29 29 }, 30 30 util::{ 31 31 async_manager, ··· 37 37 use dashmap::DashMap; 38 38 pub use device::{ButtplugClientDevice, ButtplugClientDeviceEvent}; 39 39 use futures::{ 40 - future::{self, BoxFuture, FutureExt}, 41 40 Stream, 41 + future::{self, BoxFuture, FutureExt}, 42 42 }; 43 43 use log::*; 44 + use std::{ 45 + collections::BTreeMap, 46 + sync::{ 47 + Arc, 48 + atomic::{AtomicBool, Ordering}, 49 + }, 50 + }; 44 51 use strum_macros::Display; 45 - use std::{collections::BTreeMap, sync::{ 46 - atomic::{AtomicBool, Ordering}, 47 - Arc, 48 - }}; 49 52 use thiserror::Error; 50 - use tokio::sync::{broadcast, mpsc, Mutex}; 53 + use tokio::sync::{Mutex, broadcast, mpsc}; 51 54 use tracing_futures::Instrument; 52 55 53 56 /// Result type used for public APIs. ··· 107 110 #[error(transparent)] 108 111 ButtplugError(#[from] ButtplugError), 109 112 /// Error converting output command: {} 110 - ButtplugOutputCommandConversionError(String) 113 + ButtplugOutputCommandConversionError(String), 111 114 } 112 115 113 116 /// Enum representing different events that can be emitted by a client. ··· 270 273 client_name: name.to_owned(), 271 274 server_name: Arc::new(Mutex::new(None)), 272 275 event_stream, 273 - message_sender: ButtplugClientMessageSender::new( 274 - &message_sender, 275 - &connected, 276 - ), 276 + message_sender: ButtplugClientMessageSender::new(&message_sender, &connected), 277 277 connected, 278 278 device_map: Arc::new(DashMap::new()), 279 279 } ··· 431 431 .send_message_expect_ok(StopAllDevicesV0::default().into()) 432 432 } 433 433 434 - pub fn event_stream(&self) -> impl Stream<Item = ButtplugClientEvent> + use<>{ 434 + pub fn event_stream(&self) -> impl Stream<Item = ButtplugClientEvent> + use<> { 435 435 let stream = convert_broadcast_receiver_to_stream(self.event_stream.subscribe()); 436 436 // We can either Box::pin here or force the user to pin_mut!() on their 437 437 // end. While this does end up with a dynamic dispatch on our end, it
+14 -12
crates/buttplug_client/src/serializer/mod.rs
··· 1 1 use buttplug_core::message::{ 2 + ButtplugClientMessageV4, 3 + ButtplugMessage, 4 + ButtplugMessageFinalizer, 5 + ButtplugServerMessageV4, 2 6 serializer::{ 3 - json_serializer::{create_message_validator, deserialize_to_message, vec_to_protocol_json}, 4 7 ButtplugMessageSerializer, 5 8 ButtplugSerializedMessage, 6 9 ButtplugSerializerError, 10 + json_serializer::{create_message_validator, deserialize_to_message, vec_to_protocol_json}, 7 11 }, 8 - ButtplugClientMessageV4, 9 - ButtplugMessage, 10 - ButtplugMessageFinalizer, 11 - ButtplugServerMessageV4, 12 12 }; 13 13 use jsonschema::Validator; 14 14 use serde::{Deserialize, Serialize}; ··· 74 74 mod test { 75 75 use super::*; 76 76 use buttplug_core::message::{ 77 - RequestServerInfoV4, 78 77 BUTTPLUG_CURRENT_API_MAJOR_VERSION, 79 78 BUTTPLUG_CURRENT_API_MINOR_VERSION, 79 + RequestServerInfoV4, 80 80 }; 81 81 82 82 #[test] ··· 102 102 "[{\"Ok\":{\"NotAField\":\"NotAValue\",\"Id\":1}}]", 103 103 ]; 104 104 let serializer = ButtplugClientJSONSerializer::default(); 105 - let _ = serializer.serialize(&vec![RequestServerInfoV4::new( 106 - "test client", 107 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 108 - BUTTPLUG_CURRENT_API_MINOR_VERSION, 109 - ) 110 - .into()]); 105 + let _ = serializer.serialize(&vec![ 106 + RequestServerInfoV4::new( 107 + "test client", 108 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 109 + BUTTPLUG_CURRENT_API_MINOR_VERSION, 110 + ) 111 + .into(), 112 + ]); 111 113 for msg in incorrect_incoming_messages { 112 114 let res = serializer.deserialize(&ButtplugSerializedMessage::Text(msg.to_owned())); 113 115 assert!(res.is_err(), "{} should be an error", msg);
+1 -1
crates/buttplug_client_in_process/src/in_process_client.rs
··· 7 7 8 8 use super::ButtplugInProcessClientConnectorBuilder; 9 9 use buttplug_client::ButtplugClient; 10 - use buttplug_server::{device::ServerDeviceManagerBuilder, ButtplugServerBuilder}; 10 + use buttplug_server::{ButtplugServerBuilder, device::ServerDeviceManagerBuilder}; 11 11 use buttplug_server_device_config::DeviceConfigurationManagerBuilder; 12 12 13 13 /// Convenience function for creating in-process connectors.
+4 -4
crates/buttplug_client_in_process/src/in_process_connector.rs
··· 14 14 util::async_manager, 15 15 }; 16 16 use buttplug_server::{ 17 - message::ButtplugServerMessageVariant, 18 17 ButtplugServer, 19 18 ButtplugServerBuilder, 19 + message::ButtplugServerMessageVariant, 20 20 }; 21 21 22 22 use futures::{ 23 - future::{self, BoxFuture, FutureExt}, 24 23 StreamExt, 24 + future::{self, BoxFuture, FutureExt}, 25 25 }; 26 26 use futures_util::pin_mut; 27 27 use std::sync::{ 28 - atomic::{AtomicBool, Ordering}, 29 28 Arc, 29 + atomic::{AtomicBool, Ordering}, 30 30 }; 31 - use tokio::sync::mpsc::{channel, Sender}; 31 + use tokio::sync::mpsc::{Sender, channel}; 32 32 use tracing_futures::Instrument; 33 33 34 34 #[derive(Default)]
+7 -4
crates/buttplug_core/build.rs
··· 2 2 use jsonschema::Validator; 3 3 4 4 fn main() { 5 - println!("cargo:rerun-if-changed={}", SCHEMA_DIR); 6 - let schema: serde_json::Value = 7 - serde_json::from_str(&std::fs::read_to_string(std::path::Path::new(SCHEMA_DIR).join("buttplug-schema.json")).unwrap()).expect("Built in schema better be valid json"); 5 + println!("cargo:rerun-if-changed={}", SCHEMA_DIR); 6 + let schema: serde_json::Value = serde_json::from_str( 7 + &std::fs::read_to_string(std::path::Path::new(SCHEMA_DIR).join("buttplug-schema.json")) 8 + .unwrap(), 9 + ) 10 + .expect("Built in schema better be valid json"); 8 11 let _ = Validator::new(&schema).expect("Built in schema better be a valid schema"); 9 - } 12 + }
+1 -1
crates/buttplug_core/src/connector/mod.rs
··· 67 67 pub mod transport; 68 68 69 69 use crate::{ 70 - message::{serializer::ButtplugSerializedMessage, ButtplugMessage}, 70 + message::{ButtplugMessage, serializer::ButtplugSerializedMessage}, 71 71 util::future::{ButtplugFuture, ButtplugFutureStateShared}, 72 72 }; 73 73 use displaydoc::Display;
+5 -6
crates/buttplug_core/src/connector/remote_connector.rs
··· 8 8 //! Generic remote transport handling methods and traits 9 9 10 10 use super::{ 11 - transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 12 11 ButtplugConnector, 13 12 ButtplugConnectorError, 14 13 ButtplugConnectorResultFuture, 14 + transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 15 15 }; 16 16 use crate::{ 17 17 message::{ 18 - serializer::{ButtplugMessageSerializer, ButtplugSerializedMessage}, 19 18 ButtplugMessage, 19 + serializer::{ButtplugMessageSerializer, ButtplugSerializedMessage}, 20 20 }, 21 21 util::async_manager, 22 22 }; 23 - use futures::{future::BoxFuture, select, FutureExt}; 23 + use futures::{FutureExt, future::BoxFuture, select}; 24 24 use log::*; 25 25 use std::marker::PhantomData; 26 - use tokio::sync::mpsc::{channel, Receiver, Sender}; 26 + use tokio::sync::mpsc::{Receiver, Sender, channel}; 27 27 28 28 enum ButtplugRemoteConnectorMessage<T> 29 29 where ··· 112 112 "{}", 113 113 format!( 114 114 "Got invalid messages from remote Buttplug connection - Message: {:?} - Error: {:?}", 115 - serialized_msg, 116 - e 115 + serialized_msg, e 117 116 ) 118 117 ); 119 118 }
+3 -3
crates/buttplug_core/src/connector/transport/stream.rs
··· 10 10 11 11 use crate::{ 12 12 connector::{ 13 - transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 14 13 ButtplugConnectorError, 15 14 ButtplugConnectorResultFuture, 15 + transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 16 16 }, 17 17 message::serializer::ButtplugSerializedMessage, 18 18 util::async_manager, 19 19 }; 20 20 use futures::{ 21 - future::{self, BoxFuture}, 22 21 FutureExt, 22 + future::{self, BoxFuture}, 23 23 }; 24 24 25 25 use std::sync::Arc; 26 26 use tokio::{ 27 27 select, 28 28 sync::{ 29 - mpsc::{Receiver, Sender}, 30 29 Mutex, 30 + mpsc::{Receiver, Sender}, 31 31 }, 32 32 }; 33 33
+1 -1
crates/buttplug_core/src/errors.rs
··· 9 9 10 10 use super::message::{ 11 11 self, 12 - serializer::ButtplugSerializerError, 13 12 ButtplugMessageSpecVersion, 14 13 ErrorCode, 15 14 InputType, 16 15 OutputType, 16 + serializer::ButtplugSerializerError, 17 17 }; 18 18 use futures::future::BoxFuture; 19 19 use serde::{Deserialize, Serialize};
+70 -38
crates/buttplug_core/src/message/device_feature.rs
··· 8 8 use crate::{message::InputCommandType, util::range_serialize::*}; 9 9 use derive_builder::Builder; 10 10 use getset::{CopyGetters, Getters, MutGetters, Setters}; 11 - use serde::{ser::SerializeSeq, Deserialize, Serialize, Serializer}; 12 - use std::{ 13 - collections::HashSet, hash::Hash, ops::RangeInclusive 14 - }; 11 + use serde::{Deserialize, Serialize, Serializer, ser::SerializeSeq}; 12 + use std::{collections::HashSet, hash::Hash, ops::RangeInclusive}; 15 13 16 14 #[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash, EnumIter)] 17 15 pub enum OutputType { ··· 72 70 #[derive( 73 71 Clone, Debug, Default, Getters, MutGetters, CopyGetters, Setters, Serialize, Deserialize, 74 72 )] 75 - #[serde(rename_all="PascalCase")] 73 + #[serde(rename_all = "PascalCase")] 76 74 pub struct DeviceFeature { 77 75 // Index of the feature on the device. This was originally implicit as the position in the feature 78 76 // array. We now make it explicit even though it's still just array position, because implicit ··· 127 125 } 128 126 129 127 #[derive(Serialize, Deserialize, Clone, Debug, Getters)] 130 - #[serde(rename_all="PascalCase")] 128 + #[serde(rename_all = "PascalCase")] 131 129 pub struct DeviceFeatureOutputValueProperties { 132 130 #[getset(get = "pub")] 133 131 #[serde(serialize_with = "range_serialize")] ··· 136 134 137 135 impl DeviceFeatureOutputValueProperties { 138 136 pub fn new(value: &RangeInclusive<i32>) -> Self { 139 - DeviceFeatureOutputValueProperties { value: value.clone() } 137 + DeviceFeatureOutputValueProperties { 138 + value: value.clone(), 139 + } 140 140 } 141 141 142 142 pub fn step_count(&self) -> u32 { ··· 154 154 } 155 155 156 156 #[derive(Serialize, Deserialize, Clone, Debug, Getters)] 157 - #[serde(rename_all="PascalCase")] 157 + #[serde(rename_all = "PascalCase")] 158 158 pub struct DeviceFeatureOutputPositionWithDurationProperties { 159 159 #[getset(get = "pub")] 160 160 #[serde(serialize_with = "range_serialize")] ··· 166 166 167 167 impl DeviceFeatureOutputPositionWithDurationProperties { 168 168 pub fn new(position: &RangeInclusive<i32>, duration: &RangeInclusive<i32>) -> Self { 169 - DeviceFeatureOutputPositionWithDurationProperties { position: position.clone(), duration: duration.clone() } 169 + DeviceFeatureOutputPositionWithDurationProperties { 170 + position: position.clone(), 171 + duration: duration.clone(), 172 + } 170 173 } 171 174 172 175 pub fn step_count(&self) -> u32 { ··· 186 189 #[derive(Clone, Debug, Getters, Setters, Default, Serialize, Deserialize, Builder)] 187 190 #[builder(setter(strip_option), default)] 188 191 #[getset(get = "pub")] 189 - #[serde(rename_all="PascalCase")] 192 + #[serde(rename_all = "PascalCase")] 190 193 pub struct DeviceFeatureOutput { 191 - #[serde(skip_serializing_if="Option::is_none")] 194 + #[serde(skip_serializing_if = "Option::is_none")] 192 195 vibrate: Option<DeviceFeatureOutputValueProperties>, 193 - #[serde(skip_serializing_if="Option::is_none")] 196 + #[serde(skip_serializing_if = "Option::is_none")] 194 197 rotate: Option<DeviceFeatureOutputValueProperties>, 195 - #[serde(skip_serializing_if="Option::is_none")] 198 + #[serde(skip_serializing_if = "Option::is_none")] 196 199 rotate_with_direction: Option<DeviceFeatureOutputValueProperties>, 197 - #[serde(skip_serializing_if="Option::is_none")] 200 + #[serde(skip_serializing_if = "Option::is_none")] 198 201 oscillate: Option<DeviceFeatureOutputValueProperties>, 199 - #[serde(skip_serializing_if="Option::is_none")] 202 + #[serde(skip_serializing_if = "Option::is_none")] 200 203 constrict: Option<DeviceFeatureOutputValueProperties>, 201 - #[serde(skip_serializing_if="Option::is_none")] 204 + #[serde(skip_serializing_if = "Option::is_none")] 202 205 heater: Option<DeviceFeatureOutputValueProperties>, 203 - #[serde(skip_serializing_if="Option::is_none")] 206 + #[serde(skip_serializing_if = "Option::is_none")] 204 207 led: Option<DeviceFeatureOutputValueProperties>, 205 - #[serde(skip_serializing_if="Option::is_none")] 208 + #[serde(skip_serializing_if = "Option::is_none")] 206 209 position: Option<DeviceFeatureOutputValueProperties>, 207 - #[serde(skip_serializing_if="Option::is_none")] 210 + #[serde(skip_serializing_if = "Option::is_none")] 208 211 position_with_duration: Option<DeviceFeatureOutputPositionWithDurationProperties>, 209 - #[serde(skip_serializing_if="Option::is_none")] 212 + #[serde(skip_serializing_if = "Option::is_none")] 210 213 spray: Option<DeviceFeatureOutputValueProperties>, 211 214 } 212 215 ··· 229 232 230 233 pub fn get(&self, output_type: OutputType) -> Option<&dyn DeviceFeatureOutputLimits> { 231 234 match output_type { 232 - OutputType::Constrict => self.constrict().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 233 - OutputType::Heater => self.heater().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 234 - OutputType::Led => self.led().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 235 - OutputType::Oscillate => self.oscillate().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 236 - OutputType::Position => self.position().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 237 - OutputType::PositionWithDuration => self.position_with_duration().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 238 - OutputType::Rotate => self.rotate().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 239 - OutputType::RotateWithDirection => self.rotate_with_direction().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 240 - OutputType::Spray => self.spray().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 235 + OutputType::Constrict => self 236 + .constrict() 237 + .as_ref() 238 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 239 + OutputType::Heater => self 240 + .heater() 241 + .as_ref() 242 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 243 + OutputType::Led => self 244 + .led() 245 + .as_ref() 246 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 247 + OutputType::Oscillate => self 248 + .oscillate() 249 + .as_ref() 250 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 251 + OutputType::Position => self 252 + .position() 253 + .as_ref() 254 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 255 + OutputType::PositionWithDuration => self 256 + .position_with_duration() 257 + .as_ref() 258 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 259 + OutputType::Rotate => self 260 + .rotate() 261 + .as_ref() 262 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 263 + OutputType::RotateWithDirection => self 264 + .rotate_with_direction() 265 + .as_ref() 266 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 267 + OutputType::Spray => self 268 + .spray() 269 + .as_ref() 270 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 241 271 OutputType::Unknown => None, 242 - OutputType::Vibrate => self.vibrate().as_ref().map(|x| x as &dyn DeviceFeatureOutputLimits), 272 + OutputType::Vibrate => self 273 + .vibrate() 274 + .as_ref() 275 + .map(|x| x as &dyn DeviceFeatureOutputLimits), 243 276 } 244 277 } 245 278 } ··· 247 280 #[derive( 248 281 Clone, Debug, Default, PartialEq, Eq, Getters, MutGetters, Setters, Serialize, Deserialize, 249 282 )] 250 - #[serde(rename_all="PascalCase")] 283 + #[serde(rename_all = "PascalCase")] 251 284 pub struct DeviceFeatureInputProperties { 252 285 #[getset(get = "pub", get_mut = "pub(super)")] 253 286 #[serde(serialize_with = "range_sequence_serialize")] ··· 268 301 } 269 302 } 270 303 271 - 272 304 #[derive(Clone, Debug, Getters, Setters, Default, Serialize, Deserialize, Builder)] 273 305 #[builder(setter(strip_option), default)] 274 306 #[getset(get = "pub")] 275 - #[serde(rename_all="PascalCase")] 307 + #[serde(rename_all = "PascalCase")] 276 308 pub struct DeviceFeatureInput { 277 - #[serde(skip_serializing_if="Option::is_none")] 309 + #[serde(skip_serializing_if = "Option::is_none")] 278 310 battery: Option<DeviceFeatureInputProperties>, 279 - #[serde(skip_serializing_if="Option::is_none")] 311 + #[serde(skip_serializing_if = "Option::is_none")] 280 312 rssi: Option<DeviceFeatureInputProperties>, 281 - #[serde(skip_serializing_if="Option::is_none")] 313 + #[serde(skip_serializing_if = "Option::is_none")] 282 314 pressure: Option<DeviceFeatureInputProperties>, 283 - #[serde(skip_serializing_if="Option::is_none")] 315 + #[serde(skip_serializing_if = "Option::is_none")] 284 316 button: Option<DeviceFeatureInputProperties>, 285 317 } 286 318 ··· 304 336 InputType::Unknown => &None, 305 337 } 306 338 } 307 - } 339 + }
+3 -4
crates/buttplug_core/src/message/serializer/json_serializer.rs
··· 12 12 use serde_json::{Deserializer, Value}; 13 13 use std::fmt::Debug; 14 14 15 - static MESSAGE_JSON_SCHEMA: &str = 16 - include_str!("../../../schema/buttplug-schema.json"); 15 + static MESSAGE_JSON_SCHEMA: &str = include_str!("../../../schema/buttplug-schema.json"); 17 16 18 17 /// Creates a [jsonschema::JSONSchema] validator using the built in buttplug message schema. 19 18 pub fn create_message_validator() -> Validator { ··· 74 73 Err(e) => { 75 74 return Err(ButtplugSerializerError::JsonSerializerError(format!( 76 75 "Message: {msg_str} - Error: {e:?}" 77 - ))) 76 + ))); 78 77 } 79 78 } 80 79 } 81 80 Err(e) => { 82 81 return Err(ButtplugSerializerError::JsonSerializerError(format!( 83 82 "Message: {msg_str} - Error: {e:?}" 84 - ))) 83 + ))); 85 84 } 86 85 } 87 86 }
+1 -1
crates/buttplug_core/src/message/v0/error.rs
··· 130 130 let js = serde_json::to_string(&error).expect("Infallible serialization."); 131 131 assert_eq!(ERROR_STR, js); 132 132 } 133 - /* 133 + /* 134 134 #[test] 135 135 fn test_error_deserialize() { 136 136 let union: ButtplugServerMessageCurrent =
+1 -1
crates/buttplug_core/src/message/v0/ok.rs
··· 54 54 let js = serde_json::to_string(&ok).expect("Infallible serialization"); 55 55 assert_eq!(OK_STR, js); 56 56 } 57 - /* 57 + /* 58 58 #[test] 59 59 fn test_ok_deserialize() { 60 60 let union: ButtplugServerMessageCurrent =
+8 -2
crates/buttplug_core/src/message/v4/device_list.rs
··· 29 29 30 30 impl DeviceListV4 { 31 31 pub fn new(devices: Vec<DeviceMessageInfoV4>) -> Self { 32 - let device_map = devices.iter().map(|x| (x.device_index(), x.clone())).collect(); 33 - Self { id: 1, devices: device_map } 32 + let device_map = devices 33 + .iter() 34 + .map(|x| (x.device_index(), x.clone())) 35 + .collect(); 36 + Self { 37 + id: 1, 38 + devices: device_map, 39 + } 34 40 } 35 41 } 36 42
+10 -8
crates/buttplug_core/src/message/v4/input_reading.rs
··· 17 17 18 18 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, CopyGetters)] 19 19 #[getset(get_copy = "pub")] 20 - pub struct InputData<T> where T: Copy + Clone { 20 + pub struct InputData<T> 21 + where 22 + T: Copy + Clone, 23 + { 21 24 #[serde(rename = "Data")] 22 25 data: T, 23 26 } 24 27 25 - impl<T> InputData<T> where T: Copy + Clone { 28 + impl<T> InputData<T> 29 + where 30 + T: Copy + Clone, 31 + { 26 32 pub fn new(data: T) -> Self { 27 33 Self { data } 28 34 } ··· 33 39 Battery(InputData<u8>), 34 40 Rssi(InputData<i8>), 35 41 Button(InputData<u8>), 36 - Pressure(InputData<u32>) 42 + Pressure(InputData<u32>), 37 43 } 38 44 39 45 impl InputTypeData { ··· 76 82 } 77 83 78 84 impl InputReadingV4 { 79 - pub fn new( 80 - device_index: u32, 81 - feature_index: u32, 82 - data: InputTypeData 83 - ) -> Self { 85 + pub fn new(device_index: u32, feature_index: u32, data: InputTypeData) -> Self { 84 86 Self { 85 87 id: 0, 86 88 device_index,
+1 -1
crates/buttplug_core/src/message/v4/mod.rs
··· 18 18 device_list::DeviceListV4, 19 19 device_message_info::DeviceMessageInfoV4, 20 20 input_cmd::{InputCmdV4, InputCommandType}, 21 - input_reading::{InputData, InputTypeData, InputReadingV4}, 21 + input_reading::{InputData, InputReadingV4, InputTypeData}, 22 22 output_cmd::{ 23 23 OutputCmdV4, 24 24 OutputCommand,
+1 -1
crates/buttplug_core/src/message/v4/spec_enums.rs
··· 6 6 // for full license information. 7 7 8 8 use crate::message::{ 9 - v4::input_cmd::InputCmdV4, 10 9 ButtplugMessage, 11 10 ButtplugMessageError, 12 11 ButtplugMessageFinalizer, ··· 23 22 StopAllDevicesV0, 24 23 StopDeviceCmdV0, 25 24 StopScanningV0, 25 + v4::input_cmd::InputCmdV4, 26 26 }; 27 27 use serde::{Deserialize, Serialize}; 28 28
+1 -1
crates/buttplug_core/src/util/mod.rs
··· 11 11 pub mod async_manager; 12 12 pub mod future; 13 13 pub mod json; 14 - pub mod stream; 15 14 pub mod range_serialize; 15 + pub mod stream; 16 16 17 17 #[cfg(not(feature = "wasm"))] 18 18 pub use tokio::time::sleep;
+1 -1
crates/buttplug_core/src/util/range_serialize.rs
··· 24 24 seq.serialize_element(&vec![*range.start(), *range.end()])?; 25 25 } 26 26 seq.end() 27 - } 27 + }
+1 -1
crates/buttplug_core/src/util/stream.rs
··· 6 6 // for full license information. 7 7 8 8 use async_stream::stream; 9 - use futures::{pin_mut, Stream}; 9 + use futures::{Stream, pin_mut}; 10 10 use tokio::sync::broadcast; 11 11 12 12 pub fn convert_broadcast_receiver_to_stream<T>(
+1 -1
crates/buttplug_server/src/device/hardware/communication.rs
··· 9 9 use async_trait::async_trait; 10 10 use buttplug_core::{ 11 11 util::{async_manager, sleep}, 12 - {errors::ButtplugDeviceError, ButtplugResultFuture}, 12 + {ButtplugResultFuture, errors::ButtplugDeviceError}, 13 13 }; 14 14 use futures::future::{self, FutureExt}; 15 15 use serde::{Deserialize, Serialize};
+2 -2
crates/buttplug_server/src/device/hardware/mod.rs
··· 3 3 4 4 use async_trait::async_trait; 5 5 use buttplug_core::errors::ButtplugDeviceError; 6 - use buttplug_server_device_config::{ProtocolCommunicationSpecifier, Endpoint}; 6 + use buttplug_server_device_config::{Endpoint, ProtocolCommunicationSpecifier}; 7 7 use futures::future::BoxFuture; 8 8 use futures_util::FutureExt; 9 9 use getset::{CopyGetters, Getters}; 10 10 use instant::Instant; 11 11 use serde::{Deserialize, Serialize}; 12 - use tokio::sync::{broadcast, RwLock}; 12 + use tokio::sync::{RwLock, broadcast}; 13 13 use uuid::Uuid; 14 14 15 15 /// Parameters for reading data from a [Hardware](crate::device::Hardware) endpoint
+10 -8
crates/buttplug_server/src/device/protocol.rs
··· 13 13 }; 14 14 use buttplug_server_device_config::{ 15 15 Endpoint, 16 - ServerDeviceDefinition, 17 16 ProtocolCommunicationSpecifier, 17 + ServerDeviceDefinition, 18 18 UserDeviceIdentifier, 19 19 }; 20 20 use dashmap::DashMap; 21 21 22 + use super::hardware::HardwareWriteCmd; 22 23 use crate::{ 23 - device::{hardware::{Hardware, HardwareCommand, HardwareReadCmd}, protocol_impl::get_default_protocol_map}, 24 + device::{ 25 + hardware::{Hardware, HardwareCommand, HardwareReadCmd}, 26 + protocol_impl::get_default_protocol_map, 27 + }, 24 28 message::{ 29 + ButtplugServerDeviceMessage, 25 30 checked_output_cmd::CheckedOutputCmdV4, 26 31 spec_enums::ButtplugDeviceCommandMessageUnionV4, 27 - ButtplugServerDeviceMessage, 28 32 }, 29 33 }; 30 34 use async_trait::async_trait; 31 35 use futures::{ 32 - future::{self, BoxFuture, FutureExt}, 33 36 StreamExt, 37 + future::{self, BoxFuture, FutureExt}, 34 38 }; 35 39 use std::{collections::HashMap, sync::Arc}; 36 40 use std::{pin::Pin, time::Duration}; 37 41 use uuid::Uuid; 38 - use super::hardware::HardwareWriteCmd; 39 42 40 43 /// Strategy for situations where hardware needs to get updates every so often in order to keep 41 44 /// things alive. Currently this applies to iOS backgrounding with bluetooth devices, as well as ··· 421 424 let battery_reading = InputReadingV4::new( 422 425 device_index, 423 426 feature_index, 424 - buttplug_core::message::InputTypeData::Battery(InputData::new(battery_level as u8)) 427 + buttplug_core::message::InputTypeData::Battery(InputData::new(battery_level as u8)), 425 428 ); 426 429 debug!("Got battery reading: {}", battery_level); 427 430 Ok(battery_reading) ··· 531 534 impl Default for ProtocolManager { 532 535 fn default() -> Self { 533 536 Self { 534 - protocol_map: get_default_protocol_map() 537 + protocol_map: get_default_protocol_map(), 535 538 } 536 539 } 537 540 } ··· 582 585 specializers 583 586 } 584 587 } 585 - 586 588 587 589 /* 588 590 #[cfg(test)]
+18 -16
crates/buttplug_server/src/device/protocol_impl/activejoy.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 25 25 feature_id: Uuid, 26 26 speed: u32, 27 27 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 28 - Ok(vec![HardwareWriteCmd::new( 29 - &[feature_id], 30 - Endpoint::Tx, 31 - [ 32 - 0xb0, // static header 33 - 0x01, // mode: 1=vibe, 5=shock, 6=thrust, 7=suction, 8=rotation, 16=swing, 34 - 0x00, // strong mode = 1 (thrust, suction, swing, rotate) 35 - feature_index as u8, // 0 unless vibe2 36 - if speed == 0 { 0x00 } else { 0x01 }, 37 - speed as u8, 38 - ] 39 - .to_vec(), 40 - false, 41 - ) 42 - .into()]) 28 + Ok(vec![ 29 + HardwareWriteCmd::new( 30 + &[feature_id], 31 + Endpoint::Tx, 32 + [ 33 + 0xb0, // static header 34 + 0x01, // mode: 1=vibe, 5=shock, 6=thrust, 7=suction, 8=rotation, 16=swing, 35 + 0x00, // strong mode = 1 (thrust, suction, swing, rotate) 36 + feature_index as u8, // 0 unless vibe2 37 + if speed == 0 { 0x00 } else { 0x01 }, 38 + speed as u8, 39 + ] 40 + .to_vec(), 41 + false, 42 + ) 43 + .into(), 44 + ]) 43 45 } 44 46 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/adrienlastic.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - format!("MotorValue:{speed:02};").as_bytes().to_vec(), 33 - true, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + format!("MotorValue:{speed:02};").as_bytes().to_vec(), 34 + true, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+17 -15
crates/buttplug_server/src/device/protocol_impl/amorelie_joy.rs
··· 12 12 use crate::device::{ 13 13 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 14 14 protocol::{ 15 - generic_protocol_initializer_setup, 16 15 ProtocolHandler, 17 16 ProtocolIdentifier, 18 17 ProtocolInitializer, 18 + generic_protocol_initializer_setup, 19 19 }, 20 20 }; 21 - use buttplug_server_device_config::ProtocolCommunicationSpecifier; 22 21 use async_trait::async_trait; 22 + use buttplug_server_device_config::ProtocolCommunicationSpecifier; 23 23 use std::sync::Arc; 24 - use uuid::{uuid, Uuid}; 24 + use uuid::{Uuid, uuid}; 25 25 26 26 const AMORELIE_JOY_PROTOCOL_UUID: Uuid = uuid!("0968017b-96f8-44ae-b113-39080dd7ed5f"); 27 27 ··· 59 59 feature_id: Uuid, 60 60 speed: u32, 61 61 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 62 - Ok(vec![HardwareWriteCmd::new( 63 - &[feature_id], 64 - Endpoint::Tx, 65 - [ 66 - 0x01, // static header 67 - 0x01, // pattern (1 = steady), 68 - speed as u8, // speed 0-100 69 - ] 70 - .to_vec(), 71 - false, 72 - ) 73 - .into()]) 62 + Ok(vec![ 63 + HardwareWriteCmd::new( 64 + &[feature_id], 65 + Endpoint::Tx, 66 + [ 67 + 0x01, // static header 68 + 0x01, // pattern (1 = steady), 69 + speed as u8, // speed 0-100 70 + ] 71 + .to_vec(), 72 + false, 73 + ) 74 + .into(), 75 + ]) 74 76 } 75 77 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/aneros.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xF1 + (feature_index as u8), speed as u8], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xF1 + (feature_index as u8), speed as u8], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+33 -31
crates/buttplug_server/src/device/protocol_impl/ankni.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareReadCmd, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::sync::Arc; 26 - use uuid::{uuid, Uuid}; 26 + use uuid::{Uuid, uuid}; 27 27 28 28 generic_protocol_initializer_setup!(Ankni, "ankni"); 29 29 ··· 88 88 feature_id: Uuid, 89 89 speed: u32, 90 90 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 91 - Ok(vec![HardwareWriteCmd::new( 92 - &[feature_id], 93 - Endpoint::Tx, 94 - vec![ 95 - 0x03, 96 - 0x12, 97 - speed as u8, 98 - 0x00, 99 - 0x00, 100 - 0x00, 101 - 0x00, 102 - 0x00, 103 - 0x00, 104 - 0x00, 105 - 0x00, 106 - 0x00, 107 - 0x00, 108 - 0x00, 109 - 0x00, 110 - 0x00, 111 - 0x00, 112 - 0x00, 113 - 0x00, 114 - 0x00, 115 - ], 116 - true, 117 - ) 118 - .into()]) 91 + Ok(vec![ 92 + HardwareWriteCmd::new( 93 + &[feature_id], 94 + Endpoint::Tx, 95 + vec![ 96 + 0x03, 97 + 0x12, 98 + speed as u8, 99 + 0x00, 100 + 0x00, 101 + 0x00, 102 + 0x00, 103 + 0x00, 104 + 0x00, 105 + 0x00, 106 + 0x00, 107 + 0x00, 108 + 0x00, 109 + 0x00, 110 + 0x00, 111 + 0x00, 112 + 0x00, 113 + 0x00, 114 + 0x00, 115 + 0x00, 116 + ], 117 + true, 118 + ) 119 + .into(), 120 + ]) 119 121 } 120 122 } 121 123
+17 -15
crates/buttplug_server/src/device/protocol_impl/bananasome.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 34 34 impl Bananasome { 35 35 fn hardware_command(&self, feature_index: u32, speed: u32) -> Vec<HardwareCommand> { 36 36 self.current_commands[feature_index as usize].store(speed as u8, Ordering::Relaxed); 37 - vec![HardwareWriteCmd::new( 38 - &[BANANASOME_PROTOCOL_UUID], 39 - Endpoint::Tx, 40 - vec![ 41 - 0xa0, 42 - 0x03, 43 - self.current_commands[0].load(Ordering::Relaxed), 44 - self.current_commands[1].load(Ordering::Relaxed), 45 - self.current_commands[2].load(Ordering::Relaxed), 46 - ], 47 - false, 48 - ) 49 - .into()] 37 + vec![ 38 + HardwareWriteCmd::new( 39 + &[BANANASOME_PROTOCOL_UUID], 40 + Endpoint::Tx, 41 + vec![ 42 + 0xa0, 43 + 0x03, 44 + self.current_commands[0].load(Ordering::Relaxed), 45 + self.current_commands[1].load(Ordering::Relaxed), 46 + self.current_commands[2].load(Ordering::Relaxed), 47 + ], 48 + false, 49 + ) 50 + .into(), 51 + ] 50 52 } 51 53 } 52 54
+15 -13
crates/buttplug_server/src/device/protocol_impl/cachito.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![ 33 - 2u8 + (feature_index as u8), 34 - 1u8 + feature_index as u8, 35 - speed as u8, 36 - 0u8, 37 - ], 38 - false, 39 - ) 40 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![ 34 + 2u8 + (feature_index as u8), 35 + 1u8 + feature_index as u8, 36 + speed as u8, 37 + 0u8, 38 + ], 39 + false, 40 + ) 41 + .into(), 42 + ]) 41 43 } 42 44 }
+16 -14
crates/buttplug_server/src/device/protocol_impl/cowgirl.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 33 33 34 34 impl Cowgirl { 35 35 fn hardware_commands(&self) -> Vec<HardwareCommand> { 36 - vec![HardwareWriteCmd::new( 37 - &[COWGIRL_PROTOCOL_UUID], 38 - Endpoint::Tx, 39 - vec![ 40 - 0x00, 41 - 0x01, 42 - self.speeds[0].load(Ordering::Relaxed), 43 - self.speeds[1].load(Ordering::Relaxed), 44 - ], 45 - true, 46 - ) 47 - .into()] 36 + vec![ 37 + HardwareWriteCmd::new( 38 + &[COWGIRL_PROTOCOL_UUID], 39 + Endpoint::Tx, 40 + vec![ 41 + 0x00, 42 + 0x01, 43 + self.speeds[0].load(Ordering::Relaxed), 44 + self.speeds[1].load(Ordering::Relaxed), 45 + ], 46 + true, 47 + ) 48 + .into(), 49 + ] 48 50 } 49 51 } 50 52
+13 -11
crates/buttplug_server/src/device/protocol_impl/cowgirl_cone.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::{errors::ButtplugDeviceError, util::sleep}; 19 19 use buttplug_server_device_config::{ 20 - ServerDeviceDefinition, 20 + Endpoint, 21 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 22 23 UserDeviceIdentifier, 23 - Endpoint, 24 24 }; 25 25 use std::{sync::Arc, time::Duration}; 26 - use uuid::{uuid, Uuid}; 26 + use uuid::{Uuid, uuid}; 27 27 28 28 generic_protocol_initializer_setup!(CowgirlCone, "cowgirl-cone"); 29 29 ··· 62 62 feature_id: Uuid, 63 63 speed: u32, 64 64 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 65 - Ok(vec![HardwareWriteCmd::new( 66 - &[feature_id], 67 - Endpoint::Tx, 68 - vec![0xf1, 0x01, speed as u8, 0x00], 69 - false, 70 - ) 71 - .into()]) 65 + Ok(vec![ 66 + HardwareWriteCmd::new( 67 + &[feature_id], 68 + Endpoint::Tx, 69 + vec![0xf1, 0x01, speed as u8, 0x00], 70 + false, 71 + ) 72 + .into(), 73 + ]) 72 74 } 73 75 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/cupido.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xb0, 0x03, 0, 0, 0, speed as u8, 0xaa], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xb0, 0x03, 0, 0, 0, speed as u8, 0xaa], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 38 40 /* -- expensive if we're not caching the battery
+10 -8
crates/buttplug_server/src/device/protocol_impl/deepsire.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0x55, 0x04, 0x01, 0x00, 0x00, speed as u8, 0xAA], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0x55, 0x04, 0x01, 0x00, 0x00, speed as u8, 0xAA], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+19 -17
crates/buttplug_server/src/device/protocol_impl/feelingso.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 34 34 35 35 impl FeelingSo { 36 36 fn hardware_command(&self) -> Vec<HardwareCommand> { 37 - vec![HardwareWriteCmd::new( 38 - &[FEELINGSO_PROTOCOL_UUID], 39 - Endpoint::Tx, 40 - vec![ 41 - 0xaa, 42 - 0x40, 43 - 0x03, 44 - self.speeds[0].load(Ordering::Relaxed), 45 - self.speeds[1].load(Ordering::Relaxed), 46 - 0x14, // Oscillate range: 1 to 4 47 - 0x19, // Checksum? 48 - ], 49 - false, 50 - ) 51 - .into()] 37 + vec![ 38 + HardwareWriteCmd::new( 39 + &[FEELINGSO_PROTOCOL_UUID], 40 + Endpoint::Tx, 41 + vec![ 42 + 0xaa, 43 + 0x40, 44 + 0x03, 45 + self.speeds[0].load(Ordering::Relaxed), 46 + self.speeds[1].load(Ordering::Relaxed), 47 + 0x14, // Oscillate range: 1 to 4 48 + 0x19, // Checksum? 49 + ], 50 + false, 51 + ) 52 + .into(), 53 + ] 52 54 } 53 55 } 54 56
+14 -12
crates/buttplug_server/src/device/protocol_impl/fleshy_thrust.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 27 27 position: u32, 28 28 duration: u32, 29 29 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 30 - Ok(vec![HardwareWriteCmd::new( 31 - &[feature_id], 32 - Endpoint::Tx, 33 - vec![ 34 - position as u8, 35 - ((duration & 0xff00) >> 8) as u8, 36 - (duration & 0xff) as u8, 37 - ], 38 - false, 39 - ) 40 - .into()]) 30 + Ok(vec![ 31 + HardwareWriteCmd::new( 32 + &[feature_id], 33 + Endpoint::Tx, 34 + vec![ 35 + position as u8, 36 + ((duration & 0xff00) >> 8) as u8, 37 + (duration & 0xff) as u8, 38 + ], 39 + false, 40 + ) 41 + .into(), 42 + ]) 41 43 } 42 44 }
+11 -9
crates/buttplug_server/src/device/protocol_impl/foreo.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::sync::Arc; ··· 63 63 feature_id: Uuid, 64 64 speed: u32, 65 65 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 66 - Ok(vec![HardwareWriteCmd::new( 67 - &[feature_id], 68 - Endpoint::Tx, 69 - vec![0x01, self.mode, speed as u8], 70 - true, 71 - ) 72 - .into()]) 66 + Ok(vec![ 67 + HardwareWriteCmd::new( 68 + &[feature_id], 69 + Endpoint::Tx, 70 + vec![0x01, self.mode, speed as u8], 71 + true, 72 + ) 73 + .into(), 74 + ]) 73 75 } 74 76 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/fox.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0x03, 0x01, 0x01, 0xfe, speed as u8], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0x03, 0x01, 0x01, 0xfe, speed as u8], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+7 -11
crates/buttplug_server/src/device/protocol_impl/fredorch.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareEvent, HardwareSubscribeCmd, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::{errors::ButtplugDeviceError, util::sleep}; 19 19 use buttplug_server_device_config::{ 20 20 Endpoint, 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use futures::FutureExt; 26 26 use std::{ 27 27 sync::{ 28 - atomic::{AtomicU8, Ordering}, 29 28 Arc, 29 + atomic::{AtomicU8, Ordering}, 30 30 }, 31 31 time::Duration, 32 32 }; 33 33 use tokio::select; 34 - use uuid::{uuid, Uuid}; 34 + use uuid::{Uuid, uuid}; 35 35 36 36 use super::fleshlight_launch_helper::calculate_speed; 37 37 ··· 217 217 data.push(crc[0]); 218 218 data.push(crc[1]); 219 219 self.previous_position.store(position, Ordering::Relaxed); 220 - Ok(vec![HardwareWriteCmd::new( 221 - &[FREDORCH_PROTOCOL_UUID], 222 - Endpoint::Tx, 223 - data, 224 - false, 225 - ) 226 - .into()]) 220 + Ok(vec![ 221 + HardwareWriteCmd::new(&[FREDORCH_PROTOCOL_UUID], Endpoint::Tx, data, false).into(), 222 + ]) 227 223 } 228 224 }
+13 -11
crates/buttplug_server/src/device/protocol_impl/fredorch_rotary.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareEvent, HardwareSubscribeCmd, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; ··· 21 21 }; 22 22 use buttplug_server_device_config::{ 23 23 Endpoint, 24 - ServerDeviceDefinition, 25 24 ProtocolCommunicationSpecifier, 25 + ServerDeviceDefinition, 26 26 UserDeviceIdentifier, 27 27 }; 28 28 use futures::FutureExt; 29 29 use std::{ 30 30 sync::{ 31 - atomic::{AtomicU8, Ordering}, 32 31 Arc, 32 + atomic::{AtomicU8, Ordering}, 33 33 }, 34 34 time::Duration, 35 35 }; 36 36 use tokio::select; 37 - use uuid::{uuid, Uuid}; 37 + use uuid::{Uuid, uuid}; 38 38 39 39 const FREDORCH_COMMAND_TIMEOUT_MS: u64 = 100; 40 40 const FREDORCH_ROTORY_PROTOCOL_UUID: Uuid = uuid!("0ec6598a-bfd1-4f47-9738-e8cd8ace6473"); ··· 216 216 self.target_speed.store(speed, Ordering::Relaxed); 217 217 if speed == 0 { 218 218 self.current_speed.store(speed, Ordering::Relaxed); 219 - Ok(vec![HardwareWriteCmd::new( 220 - &[FREDORCH_ROTORY_PROTOCOL_UUID], 221 - Endpoint::Tx, 222 - vec![0x55, 0x03, 0x24, 0x27, 0xaa], 223 - false, 224 - ) 225 - .into()]) 219 + Ok(vec![ 220 + HardwareWriteCmd::new( 221 + &[FREDORCH_ROTORY_PROTOCOL_UUID], 222 + Endpoint::Tx, 223 + vec![0x55, 0x03, 0x24, 0x27, 0xaa], 224 + false, 225 + ) 226 + .into(), 227 + ]) 226 228 } else { 227 229 Ok(vec![]) 228 230 }
+19 -21
crates/buttplug_server/src/device/protocol_impl/galaku.rs
··· 6 6 // for full license information. 7 7 8 8 use async_trait::async_trait; 9 - use std::sync::atomic::{AtomicU8, Ordering}; 10 9 use std::sync::Arc; 11 - use uuid::{uuid, Uuid}; 10 + use std::sync::atomic::{AtomicU8, Ordering}; 11 + use uuid::{Uuid, uuid}; 12 12 13 13 use futures_util::future::BoxFuture; 14 - use futures_util::{future, FutureExt}; 14 + use futures_util::{FutureExt, future}; 15 15 16 - use buttplug_core::message::{InputData, InputReadingV4, InputType, InputTypeData}; 17 16 use buttplug_core::errors::ButtplugDeviceError; 17 + use buttplug_core::message::{InputData, InputReadingV4, InputType, InputTypeData}; 18 18 use buttplug_server_device_config::Endpoint; 19 19 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 ··· 33 33 HardwareWriteCmd, 34 34 }, 35 35 protocol::{ 36 - generic_protocol_initializer_setup, 37 36 ProtocolHandler, 38 37 ProtocolIdentifier, 39 38 ProtocolInitializer, 39 + generic_protocol_initializer_setup, 40 40 }, 41 41 }; 42 42 ··· 158 158 0, 159 159 0, 160 160 ]; 161 - Ok(vec![HardwareWriteCmd::new( 162 - &[GALAKU_PROTOCOL_UUID], 163 - Endpoint::Tx, 164 - data, 165 - false, 166 - ) 167 - .into()]) 161 + Ok(vec![ 162 + HardwareWriteCmd::new(&[GALAKU_PROTOCOL_UUID], Endpoint::Tx, data, false).into(), 163 + ]) 168 164 } else { 169 165 self.speeds[feature_index as usize].store(speed as u8, Ordering::Relaxed); 170 166 let data: Vec<u32> = vec![ ··· 179 175 0, 180 176 0, 181 177 ]; 182 - Ok(vec![HardwareWriteCmd::new( 183 - &[GALAKU_PROTOCOL_UUID], 184 - Endpoint::Tx, 185 - send_bytes(data), 186 - false, 187 - ) 188 - .into()]) 178 + Ok(vec![ 179 + HardwareWriteCmd::new( 180 + &[GALAKU_PROTOCOL_UUID], 181 + Endpoint::Tx, 182 + send_bytes(data), 183 + false, 184 + ) 185 + .into(), 186 + ]) 189 187 } 190 188 } 191 189 ··· 277 275 let battery_reading = InputReadingV4::new( 278 276 device_index, 279 277 feature_index, 280 - InputTypeData::Battery(InputData::new(data[0])) 278 + InputTypeData::Battery(InputData::new(data[0])), 281 279 ); 282 280 Ok(battery_reading) 283 281 }
+2 -2
crates/buttplug_server/src/device/protocol_impl/galaku_pump.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use uuid::{uuid, Uuid}; 8 + use uuid::{Uuid, uuid}; 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint;
+4 -4
crates/buttplug_server/src/device/protocol_impl/hgod.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; ··· 21 21 }; 22 22 use buttplug_server_device_config::{ 23 23 Endpoint, 24 - ServerDeviceDefinition, 25 24 ProtocolCommunicationSpecifier, 25 + ServerDeviceDefinition, 26 26 UserDeviceIdentifier, 27 27 }; 28 28 use std::{ 29 29 sync::{ 30 - atomic::{AtomicU8, Ordering}, 31 30 Arc, 31 + atomic::{AtomicU8, Ordering}, 32 32 }, 33 33 time::Duration, 34 34 }; 35 - use uuid::{uuid, Uuid}; 35 + use uuid::{Uuid, uuid}; 36 36 37 37 // Time between Hgod update commands, in milliseconds. 38 38 const HGOD_COMMAND_DELAY_MS: u64 = 100;
+20 -16
crates/buttplug_server/src/device/protocol_impl/hismith.rs
··· 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; 16 16 use buttplug_server_device_config::{ 17 - ServerDeviceDefinition, 18 17 ProtocolCommunicationSpecifier, 18 + ServerDeviceDefinition, 19 19 UserDeviceIdentifier, 20 20 }; 21 21 use std::sync::Arc; 22 - use uuid::{uuid, Uuid}; 22 + use uuid::{Uuid, uuid}; 23 23 24 24 const HISMITH_PROTOCOL_UUID: Uuid = uuid!("e59f9c5d-bb4a-4a9c-ab57-0ceb43af1da7"); 25 25 ··· 109 109 let idx: u8 = 0x04; 110 110 let speed: u8 = speed as u8; 111 111 112 - Ok(vec![HardwareWriteCmd::new( 113 - &[feature_id], 114 - Endpoint::Tx, 115 - vec![0xAA, idx, speed, speed + idx], 116 - false, 117 - ) 118 - .into()]) 112 + Ok(vec![ 113 + HardwareWriteCmd::new( 114 + &[feature_id], 115 + Endpoint::Tx, 116 + vec![0xAA, idx, speed, speed + idx], 117 + false, 118 + ) 119 + .into(), 120 + ]) 119 121 } 120 122 121 123 fn handle_output_vibrate_cmd( ··· 133 135 speed as u8 134 136 }; 135 137 136 - Ok(vec![HardwareWriteCmd::new( 137 - &[feature_id], 138 - Endpoint::Tx, 139 - vec![0xAA, idx, speed, speed + idx], 140 - false, 141 - ) 142 - .into()]) 138 + Ok(vec![ 139 + HardwareWriteCmd::new( 140 + &[feature_id], 141 + Endpoint::Tx, 142 + vec![0xAA, idx, speed, speed + idx], 143 + false, 144 + ) 145 + .into(), 146 + ]) 143 147 } 144 148 }
+40 -28
crates/buttplug_server/src/device/protocol_impl/hismith_mini.rs
··· 10 10 protocol::{ProtocolHandler, ProtocolIdentifier, ProtocolInitializer}, 11 11 }; 12 12 use async_trait::async_trait; 13 - use buttplug_core::{ 14 - errors::ButtplugDeviceError, message::OutputType, 15 - }; 13 + use buttplug_core::{errors::ButtplugDeviceError, message::OutputType}; 16 14 use buttplug_server_device_config::{ 17 15 Endpoint, 18 - ServerDeviceDefinition, 19 16 ProtocolCommunicationSpecifier, 17 + ServerDeviceDefinition, 20 18 UserDeviceIdentifier, 21 19 }; 22 20 use std::sync::Arc; 23 - use uuid::{uuid, Uuid}; 21 + use uuid::{Uuid, uuid}; 24 22 25 23 const HISMITH_MINI_PROTOCOL_UUID: Uuid = uuid!("94befc1a-9859-4bf6-99ee-5678c89237a7"); 26 24 ··· 87 85 dual_vibe: device_definition 88 86 .features() 89 87 .iter() 90 - .filter(|x| x.output().as_ref().is_some_and(|x| x.contains(OutputType::Vibrate))) 88 + .filter(|x| { 89 + x.output() 90 + .as_ref() 91 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 92 + }) 91 93 .count() 92 94 >= 2, 93 95 second_constrict: device_definition 94 96 .features() 95 97 .iter() 96 - .position(|x| x.output().as_ref().is_some_and(|x| x.contains(OutputType::Constrict))) 98 + .position(|x| { 99 + x.output() 100 + .as_ref() 101 + .is_some_and(|x| x.contains(OutputType::Constrict)) 102 + }) 97 103 .unwrap_or(0) 98 104 == 1, 99 105 })) ··· 116 122 let idx: u8 = 0x03; 117 123 let speed: u8 = speed as u8; 118 124 119 - Ok(vec![HardwareWriteCmd::new( 120 - &[feature_id], 121 - Endpoint::Tx, 122 - vec![0xCC, idx, speed, speed + idx], 123 - false, 124 - ) 125 - .into()]) 125 + Ok(vec![ 126 + HardwareWriteCmd::new( 127 + &[feature_id], 128 + Endpoint::Tx, 129 + vec![0xCC, idx, speed, speed + idx], 130 + false, 131 + ) 132 + .into(), 133 + ]) 126 134 } 127 135 128 136 fn handle_output_vibrate_cmd( ··· 138 146 }; 139 147 let speed: u8 = speed as u8; 140 148 141 - Ok(vec![HardwareWriteCmd::new( 142 - &[feature_id], 143 - Endpoint::Tx, 144 - vec![0xCC, idx, speed, speed + idx], 145 - false, 146 - ) 147 - .into()]) 149 + Ok(vec![ 150 + HardwareWriteCmd::new( 151 + &[feature_id], 152 + Endpoint::Tx, 153 + vec![0xCC, idx, speed, speed + idx], 154 + false, 155 + ) 156 + .into(), 157 + ]) 148 158 } 149 159 150 160 fn handle_output_constrict_cmd( ··· 156 166 let idx: u8 = if self.second_constrict { 0x05 } else { 0x03 }; 157 167 let speed: u8 = level as u8; 158 168 159 - Ok(vec![HardwareWriteCmd::new( 160 - &[feature_id], 161 - Endpoint::Tx, 162 - vec![0xCC, idx, speed, speed + idx], 163 - false, 164 - ) 165 - .into()]) 169 + Ok(vec![ 170 + HardwareWriteCmd::new( 171 + &[feature_id], 172 + Endpoint::Tx, 173 + vec![0xCC, idx, speed, speed + idx], 174 + false, 175 + ) 176 + .into(), 177 + ]) 166 178 } 167 179 }
+5 -9
crates/buttplug_server/src/device/protocol_impl/htk_bm.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 50 50 } else if right != 0 { 51 51 data = 13 // right only 52 52 } 53 - Ok(vec![HardwareWriteCmd::new( 54 - &[HTK_BM_PROTOCOL_UUID], 55 - Endpoint::Tx, 56 - vec![data], 57 - false, 58 - ) 59 - .into()]) 53 + Ok(vec![ 54 + HardwareWriteCmd::new(&[HTK_BM_PROTOCOL_UUID], Endpoint::Tx, vec![data], false).into(), 55 + ]) 60 56 } 61 57 }
+33 -25
crates/buttplug_server/src/device/protocol_impl/itoys.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xa0, 0x01, 0x00, 0x00, speed as u8, 0xff], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xa0, 0x01, 0x00, 0x00, speed as u8, 0xff], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 38 - 39 - fn handle_output_oscillate_cmd(&self, _feature_index: u32, feature_id: Uuid, speed: u32) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 40 - Ok(vec![HardwareWriteCmd::new( 41 - &[feature_id], 42 - Endpoint::Tx, 43 - vec![ 44 - 0xa0, 45 - 0x06, 46 - if speed == 0 { 0x00 } else { 0x01 }, 47 - 0x00, 48 - if speed == 0 { 0x00 } else { 0x01 }, 49 - speed as u8, 50 - ], 51 - false, 52 - ) 53 - .into()]) 54 - } 40 + fn handle_output_oscillate_cmd( 41 + &self, 42 + _feature_index: u32, 43 + feature_id: Uuid, 44 + speed: u32, 45 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 46 + Ok(vec![ 47 + HardwareWriteCmd::new( 48 + &[feature_id], 49 + Endpoint::Tx, 50 + vec![ 51 + 0xa0, 52 + 0x06, 53 + if speed == 0 { 0x00 } else { 0x01 }, 54 + 0x00, 55 + if speed == 0 { 0x00 } else { 0x01 }, 56 + speed as u8, 57 + ], 58 + false, 59 + ) 60 + .into(), 61 + ]) 62 + } 55 63 }
+11 -9
crates/buttplug_server/src/device/protocol_impl/jejoue.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 63 63 pattern = 2; 64 64 } 65 65 66 - Ok(vec![HardwareWriteCmd::new( 67 - &[JEJOUE_PROTOCOL_UUID], 68 - Endpoint::Tx, 69 - vec![pattern, speed], 70 - false, 71 - ) 72 - .into()]) 66 + Ok(vec![ 67 + HardwareWriteCmd::new( 68 + &[JEJOUE_PROTOCOL_UUID], 69 + Endpoint::Tx, 70 + vec![pattern, speed], 71 + false, 72 + ) 73 + .into(), 74 + ]) 73 75 } 74 76 }
+62 -53
crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 22 22 23 23 #[derive(Default)] 24 24 pub struct JoyHub { 25 - last_cmds: [AtomicU8; 3] 25 + last_cmds: [AtomicU8; 3], 26 26 } 27 27 28 28 impl JoyHub { 29 - fn form_hardware_command(&self, index: u32, speed: u32) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 + fn form_hardware_command( 30 + &self, 31 + index: u32, 32 + speed: u32, 33 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 30 34 self.last_cmds[index as usize].store(speed as u8, Ordering::Relaxed); 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[JOYHUB_PROTOCOL_UUID], 33 - Endpoint::Tx, 34 - vec![ 35 - 0xa0, 36 - 0x03, 37 - self.last_cmds[0].load(Ordering::Relaxed), 38 - self.last_cmds[2].load(Ordering::Relaxed), 39 - self.last_cmds[1].load(Ordering::Relaxed), 40 - 0x00, 41 - 0xaa, 42 - ], 43 - false, 44 - ).into()]) 35 + Ok(vec![ 36 + HardwareWriteCmd::new( 37 + &[JOYHUB_PROTOCOL_UUID], 38 + Endpoint::Tx, 39 + vec![ 40 + 0xa0, 41 + 0x03, 42 + self.last_cmds[0].load(Ordering::Relaxed), 43 + self.last_cmds[2].load(Ordering::Relaxed), 44 + self.last_cmds[1].load(Ordering::Relaxed), 45 + 0x00, 46 + 0xaa, 47 + ], 48 + false, 49 + ) 50 + .into(), 51 + ]) 45 52 } 46 53 } 47 54 48 55 impl ProtocolHandler for JoyHub { 49 56 fn handle_output_vibrate_cmd( 50 - &self, 51 - feature_index: u32, 52 - _feature_id: Uuid, 53 - speed: u32, 54 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 57 + &self, 58 + feature_index: u32, 59 + _feature_id: Uuid, 60 + speed: u32, 61 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 55 62 self.form_hardware_command(feature_index, speed) 56 63 } 57 64 58 65 fn handle_output_rotate_cmd( 59 - &self, 60 - feature_index: u32, 61 - _feature_id: Uuid, 62 - speed: u32, 63 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 66 + &self, 67 + feature_index: u32, 68 + _feature_id: Uuid, 69 + speed: u32, 70 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 64 71 self.form_hardware_command(feature_index, speed) 65 72 } 66 73 67 74 fn handle_output_oscillate_cmd( 68 - &self, 69 - feature_index: u32, 70 - _feature_id: Uuid, 71 - speed: u32, 72 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 73 - self.form_hardware_command(feature_index, speed) 75 + &self, 76 + feature_index: u32, 77 + _feature_id: Uuid, 78 + speed: u32, 79 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 80 + self.form_hardware_command(feature_index, speed) 74 81 } 75 82 76 83 fn handle_output_constrict_cmd( 77 - &self, 78 - _feature_index: u32, 79 - feature_id: Uuid, 80 - level: u32, 81 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 82 - Ok(vec![HardwareWriteCmd::new( 83 - &[feature_id], 84 - Endpoint::Tx, 85 - vec![ 86 - 0xa0, 87 - 0x07, 88 - if level == 0 { 0x00 } else { 0x01 }, 89 - 0x00, 90 - level as u8, 91 - 0xff, 92 - ], 93 - false, 94 - ) 95 - .into()]) 84 + &self, 85 + _feature_index: u32, 86 + feature_id: Uuid, 87 + level: u32, 88 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 89 + Ok(vec![ 90 + HardwareWriteCmd::new( 91 + &[feature_id], 92 + Endpoint::Tx, 93 + vec![ 94 + 0xa0, 95 + 0x07, 96 + if level == 0 { 0x00 } else { 0x01 }, 97 + 0x00, 98 + level as u8, 99 + 0xff, 100 + ], 101 + false, 102 + ) 103 + .into(), 104 + ]) 96 105 } 97 106 }
+55 -54
crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v2.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - 9 8 use std::sync::atomic::{AtomicU8, Ordering}; 10 9 11 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 12 11 13 12 use crate::device::{ 14 13 hardware::{HardwareCommand, HardwareWriteCmd}, 15 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 16 15 }; 17 16 use buttplug_core::errors::ButtplugDeviceError; 18 17 use buttplug_server_device_config::Endpoint; ··· 22 21 23 22 #[derive(Default)] 24 23 pub struct JoyHubV2 { 25 - last_cmds: [AtomicU8; 3] 24 + last_cmds: [AtomicU8; 3], 26 25 } 27 26 28 27 impl JoyHubV2 { 29 - fn form_hardware_command(&self, index: u32, speed: u32) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 28 + fn form_hardware_command( 29 + &self, 30 + index: u32, 31 + speed: u32, 32 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 30 33 info!("GOT JOYHUB COMMAND"); 31 34 self.last_cmds[index as usize].store(speed as u8, Ordering::Relaxed); 32 - Ok(vec![HardwareWriteCmd::new( 33 - &[JOYHUB_V2_PROTOCOL_UUID], 34 - Endpoint::Tx, 35 - vec![ 36 - 0xa0, 37 - 0x03, 38 - self.last_cmds[0].load(Ordering::Relaxed), 39 - self.last_cmds[1].load(Ordering::Relaxed), 40 - self.last_cmds[2].load(Ordering::Relaxed), 41 - 0x00, 42 - 0xaa, 43 - ], 44 - false, 45 - ).into()]) 35 + Ok(vec![ 36 + HardwareWriteCmd::new( 37 + &[JOYHUB_V2_PROTOCOL_UUID], 38 + Endpoint::Tx, 39 + vec![ 40 + 0xa0, 41 + 0x03, 42 + self.last_cmds[0].load(Ordering::Relaxed), 43 + self.last_cmds[1].load(Ordering::Relaxed), 44 + self.last_cmds[2].load(Ordering::Relaxed), 45 + 0x00, 46 + 0xaa, 47 + ], 48 + false, 49 + ) 50 + .into(), 51 + ]) 46 52 } 47 53 } 48 54 49 55 impl ProtocolHandler for JoyHubV2 { 50 56 fn handle_output_vibrate_cmd( 51 - &self, 52 - feature_index: u32, 53 - _feature_id: Uuid, 54 - speed: u32, 55 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 57 + &self, 58 + feature_index: u32, 59 + _feature_id: Uuid, 60 + speed: u32, 61 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 56 62 self.form_hardware_command(feature_index, speed) 57 63 } 58 64 59 65 fn handle_output_rotate_cmd( 60 - &self, 61 - feature_index: u32, 62 - _feature_id: Uuid, 63 - speed: u32, 64 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 66 + &self, 67 + feature_index: u32, 68 + _feature_id: Uuid, 69 + speed: u32, 70 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 65 71 self.form_hardware_command(feature_index, speed) 66 72 } 67 73 68 74 fn handle_output_oscillate_cmd( 69 - &self, 70 - feature_index: u32, 71 - _feature_id: Uuid, 72 - speed: u32, 73 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 74 - self.form_hardware_command(feature_index, speed) 75 + &self, 76 + feature_index: u32, 77 + _feature_id: Uuid, 78 + speed: u32, 79 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 80 + self.form_hardware_command(feature_index, speed) 75 81 } 76 82 77 83 fn handle_output_constrict_cmd( 78 - &self, 79 - _feature_index: u32, 80 - feature_id: Uuid, 81 - level: u32, 82 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 83 - Ok(vec![HardwareWriteCmd::new( 84 - &[feature_id], 85 - Endpoint::Tx, 86 - vec![ 87 - 0xa0, 88 - 0x0d, 89 - 0x00, 90 - 0x00, 91 - level as u8, 92 - 0xff 93 - ], 94 - false, 95 - ) 96 - .into()]) 84 + &self, 85 + _feature_index: u32, 86 + feature_id: Uuid, 87 + level: u32, 88 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 89 + Ok(vec![ 90 + HardwareWriteCmd::new( 91 + &[feature_id], 92 + Endpoint::Tx, 93 + vec![0xa0, 0x0d, 0x00, 0x00, level as u8, 0xff], 94 + false, 95 + ) 96 + .into(), 97 + ]) 97 98 } 98 99 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v3.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xa0, 0x03, 0x00, 0x00, 0x00, speed as u8, 0xaa], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xa0, 0x03, 0x00, 0x00, 0x00, speed as u8, 0xaa], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+62 -54
crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v4.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - 9 8 use std::sync::atomic::{AtomicU8, Ordering}; 10 9 11 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 12 11 13 12 use crate::device::{ 14 13 hardware::{HardwareCommand, HardwareWriteCmd}, 15 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 16 15 }; 17 16 use buttplug_core::errors::ButtplugDeviceError; 18 17 use buttplug_server_device_config::Endpoint; ··· 22 21 23 22 #[derive(Default)] 24 23 pub struct JoyHubV4 { 25 - last_cmds: [AtomicU8; 3] 24 + last_cmds: [AtomicU8; 3], 26 25 } 27 26 28 27 impl JoyHubV4 { 29 - fn form_hardware_command(&self, index: u32, speed: u32) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 28 + fn form_hardware_command( 29 + &self, 30 + index: u32, 31 + speed: u32, 32 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 30 33 self.last_cmds[index as usize].store(speed as u8, Ordering::Relaxed); 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[JOYHUB_V4_PROTOCOL_UUID], 33 - Endpoint::Tx, 34 - vec![ 35 - 0xa0, 36 - 0x03, 37 - self.last_cmds[0].load(Ordering::Relaxed), 38 - 0x00, 39 - self.last_cmds[2].load(Ordering::Relaxed), 40 - self.last_cmds[1].load(Ordering::Relaxed), 41 - 0xaa, 42 - ], 43 - false, 44 - ).into()]) 34 + Ok(vec![ 35 + HardwareWriteCmd::new( 36 + &[JOYHUB_V4_PROTOCOL_UUID], 37 + Endpoint::Tx, 38 + vec![ 39 + 0xa0, 40 + 0x03, 41 + self.last_cmds[0].load(Ordering::Relaxed), 42 + 0x00, 43 + self.last_cmds[2].load(Ordering::Relaxed), 44 + self.last_cmds[1].load(Ordering::Relaxed), 45 + 0xaa, 46 + ], 47 + false, 48 + ) 49 + .into(), 50 + ]) 45 51 } 46 52 } 47 53 48 54 impl ProtocolHandler for JoyHubV4 { 49 55 fn handle_output_vibrate_cmd( 50 - &self, 51 - feature_index: u32, 52 - _feature_id: Uuid, 53 - speed: u32, 54 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 56 + &self, 57 + feature_index: u32, 58 + _feature_id: Uuid, 59 + speed: u32, 60 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 55 61 self.form_hardware_command(feature_index, speed) 56 62 } 57 63 58 64 fn handle_output_rotate_cmd( 59 - &self, 60 - feature_index: u32, 61 - _feature_id: Uuid, 62 - speed: u32, 63 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 65 + &self, 66 + feature_index: u32, 67 + _feature_id: Uuid, 68 + speed: u32, 69 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 64 70 self.form_hardware_command(feature_index, speed) 65 71 } 66 72 67 73 fn handle_output_oscillate_cmd( 68 - &self, 69 - feature_index: u32, 70 - _feature_id: Uuid, 71 - speed: u32, 72 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 73 - self.form_hardware_command(feature_index, speed) 74 + &self, 75 + feature_index: u32, 76 + _feature_id: Uuid, 77 + speed: u32, 78 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 79 + self.form_hardware_command(feature_index, speed) 74 80 } 75 81 76 82 fn handle_output_constrict_cmd( 77 - &self, 78 - _feature_index: u32, 79 - feature_id: Uuid, 80 - level: u32, 81 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 82 - Ok(vec![HardwareWriteCmd::new( 83 - &[feature_id], 84 - Endpoint::Tx, 85 - vec![ 86 - 0xa0, 87 - 0x07, 88 - if level == 0 { 0x00 } else { 0x01 }, 89 - 0x00, 90 - level as u8, 91 - 0xff, 92 - ], 93 - false, 94 - ) 95 - .into()]) 83 + &self, 84 + _feature_index: u32, 85 + feature_id: Uuid, 86 + level: u32, 87 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 88 + Ok(vec![ 89 + HardwareWriteCmd::new( 90 + &[feature_id], 91 + Endpoint::Tx, 92 + vec![ 93 + 0xa0, 94 + 0x07, 95 + if level == 0 { 0x00 } else { 0x01 }, 96 + 0x00, 97 + level as u8, 98 + 0xff, 99 + ], 100 + false, 101 + ) 102 + .into(), 103 + ]) 96 104 } 97 105 }
+62 -53
crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v5.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 21 21 22 22 #[derive(Default)] 23 23 pub struct JoyHubV5 { 24 - last_cmds: [AtomicU8; 3] 24 + last_cmds: [AtomicU8; 3], 25 25 } 26 26 27 27 impl JoyHubV5 { 28 - fn form_hardware_command(&self, index: u32, speed: u32) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 28 + fn form_hardware_command( 29 + &self, 30 + index: u32, 31 + speed: u32, 32 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 33 self.last_cmds[index as usize].store(speed as u8, Ordering::Relaxed); 30 - Ok(vec![HardwareWriteCmd::new( 31 - &[JOYHUB_V5_PROTOCOL_UUID], 32 - Endpoint::Tx, 33 - vec![ 34 - 0xa0, 35 - 0x03, 36 - self.last_cmds[1].load(Ordering::Relaxed), 37 - 0x00, 38 - self.last_cmds[0].load(Ordering::Relaxed), 39 - 0x00, 40 - 0xaa, 41 - ], 42 - false, 43 - ).into()]) 34 + Ok(vec![ 35 + HardwareWriteCmd::new( 36 + &[JOYHUB_V5_PROTOCOL_UUID], 37 + Endpoint::Tx, 38 + vec![ 39 + 0xa0, 40 + 0x03, 41 + self.last_cmds[1].load(Ordering::Relaxed), 42 + 0x00, 43 + self.last_cmds[0].load(Ordering::Relaxed), 44 + 0x00, 45 + 0xaa, 46 + ], 47 + false, 48 + ) 49 + .into(), 50 + ]) 44 51 } 45 52 } 46 53 47 54 impl ProtocolHandler for JoyHubV5 { 48 55 fn handle_output_vibrate_cmd( 49 - &self, 50 - feature_index: u32, 51 - _feature_id: Uuid, 52 - speed: u32, 53 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 56 + &self, 57 + feature_index: u32, 58 + _feature_id: Uuid, 59 + speed: u32, 60 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 54 61 self.form_hardware_command(feature_index, speed) 55 62 } 56 63 57 64 fn handle_output_rotate_cmd( 58 - &self, 59 - feature_index: u32, 60 - _feature_id: Uuid, 61 - speed: u32, 62 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 65 + &self, 66 + feature_index: u32, 67 + _feature_id: Uuid, 68 + speed: u32, 69 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 63 70 self.form_hardware_command(feature_index, speed) 64 71 } 65 72 66 73 fn handle_output_oscillate_cmd( 67 - &self, 68 - feature_index: u32, 69 - _feature_id: Uuid, 70 - speed: u32, 71 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 72 - self.form_hardware_command(feature_index, speed) 74 + &self, 75 + feature_index: u32, 76 + _feature_id: Uuid, 77 + speed: u32, 78 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 79 + self.form_hardware_command(feature_index, speed) 73 80 } 74 81 75 82 fn handle_output_constrict_cmd( 76 - &self, 77 - _feature_index: u32, 78 - feature_id: Uuid, 79 - level: u32, 80 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 81 - Ok(vec![HardwareWriteCmd::new( 82 - &[feature_id], 83 - Endpoint::Tx, 84 - vec![ 85 - 0xa0, 86 - 0x07, 87 - if level == 0 { 0x00 } else { 0x01 }, 88 - 0x00, 89 - level as u8, 90 - 0xff, 91 - ], 92 - false, 93 - ) 94 - .into()]) 83 + &self, 84 + _feature_index: u32, 85 + feature_id: Uuid, 86 + level: u32, 87 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 88 + Ok(vec![ 89 + HardwareWriteCmd::new( 90 + &[feature_id], 91 + Endpoint::Tx, 92 + vec![ 93 + 0xa0, 94 + 0x07, 95 + if level == 0 { 0x00 } else { 0x01 }, 96 + 0x00, 97 + level as u8, 98 + 0xff, 99 + ], 100 + false, 101 + ) 102 + .into(), 103 + ]) 95 104 } 96 105 }
+62 -53
crates/buttplug_server/src/device/protocol_impl/joyhub/joyhub_v6.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 21 21 22 22 #[derive(Default)] 23 23 pub struct JoyHubV6 { 24 - last_cmds: [AtomicU8; 3] 24 + last_cmds: [AtomicU8; 3], 25 25 } 26 26 27 27 impl JoyHubV6 { 28 - fn form_hardware_command(&self, index: u32, speed: u32) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 28 + fn form_hardware_command( 29 + &self, 30 + index: u32, 31 + speed: u32, 32 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 33 self.last_cmds[index as usize].store(speed as u8, Ordering::Relaxed); 30 - Ok(vec![HardwareWriteCmd::new( 31 - &[JOYHUB_V6_PROTOCOL_UUID], 32 - Endpoint::Tx, 33 - vec![ 34 - 0xa0, 35 - 0x03, 36 - self.last_cmds[1].load(Ordering::Relaxed), 37 - self.last_cmds[0].load(Ordering::Relaxed), 38 - self.last_cmds[2].load(Ordering::Relaxed), 39 - 0x00, 40 - 0xaa, 41 - ], 42 - false, 43 - ).into()]) 34 + Ok(vec![ 35 + HardwareWriteCmd::new( 36 + &[JOYHUB_V6_PROTOCOL_UUID], 37 + Endpoint::Tx, 38 + vec![ 39 + 0xa0, 40 + 0x03, 41 + self.last_cmds[1].load(Ordering::Relaxed), 42 + self.last_cmds[0].load(Ordering::Relaxed), 43 + self.last_cmds[2].load(Ordering::Relaxed), 44 + 0x00, 45 + 0xaa, 46 + ], 47 + false, 48 + ) 49 + .into(), 50 + ]) 44 51 } 45 52 } 46 53 47 54 impl ProtocolHandler for JoyHubV6 { 48 55 fn handle_output_vibrate_cmd( 49 - &self, 50 - feature_index: u32, 51 - _feature_id: Uuid, 52 - speed: u32, 53 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 56 + &self, 57 + feature_index: u32, 58 + _feature_id: Uuid, 59 + speed: u32, 60 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 54 61 self.form_hardware_command(feature_index, speed) 55 62 } 56 63 57 64 fn handle_output_rotate_cmd( 58 - &self, 59 - feature_index: u32, 60 - _feature_id: Uuid, 61 - speed: u32, 62 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 65 + &self, 66 + feature_index: u32, 67 + _feature_id: Uuid, 68 + speed: u32, 69 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 63 70 self.form_hardware_command(feature_index, speed) 64 71 } 65 72 66 73 fn handle_output_oscillate_cmd( 67 - &self, 68 - feature_index: u32, 69 - _feature_id: Uuid, 70 - speed: u32, 71 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 72 - self.form_hardware_command(feature_index, speed) 74 + &self, 75 + feature_index: u32, 76 + _feature_id: Uuid, 77 + speed: u32, 78 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 79 + self.form_hardware_command(feature_index, speed) 73 80 } 74 81 75 82 fn handle_output_constrict_cmd( 76 - &self, 77 - _feature_index: u32, 78 - feature_id: Uuid, 79 - level: u32, 80 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 81 - Ok(vec![HardwareWriteCmd::new( 82 - &[feature_id], 83 - Endpoint::Tx, 84 - vec![ 85 - 0xa0, 86 - 0x07, 87 - if level == 0 { 0x00 } else { 0x01 }, 88 - 0x00, 89 - level as u8, 90 - 0xff, 91 - ], 92 - false, 93 - ) 94 - .into()]) 83 + &self, 84 + _feature_index: u32, 85 + feature_id: Uuid, 86 + level: u32, 87 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 88 + Ok(vec![ 89 + HardwareWriteCmd::new( 90 + &[feature_id], 91 + Endpoint::Tx, 92 + vec![ 93 + 0xa0, 94 + 0x07, 95 + if level == 0 { 0x00 } else { 0x01 }, 96 + 0x00, 97 + level as u8, 98 + 0xff, 99 + ], 100 + false, 101 + ) 102 + .into(), 103 + ]) 95 104 } 96 105 }
+6 -4
crates/buttplug_server/src/device/protocol_impl/kgoal_boost.rs
··· 8 8 use crate::{ 9 9 device::{ 10 10 hardware::{Hardware, HardwareEvent, HardwareSubscribeCmd, HardwareUnsubscribeCmd}, 11 - protocol::{generic_protocol_setup, ProtocolHandler}, 11 + protocol::{ProtocolHandler, generic_protocol_setup}, 12 12 }, 13 13 message::ButtplugServerDeviceMessage, 14 14 }; ··· 20 20 use buttplug_server_device_config::Endpoint; 21 21 use dashmap::DashSet; 22 22 use futures::{ 23 - future::{self, BoxFuture}, 24 23 FutureExt, 25 24 StreamExt, 25 + future::{self, BoxFuture}, 26 26 }; 27 27 use std::{pin::Pin, sync::Arc}; 28 28 use tokio::sync::broadcast; ··· 104 104 InputReadingV4::new( 105 105 device_index, 106 106 feature_index, 107 - buttplug_core::message::InputTypeData::Pressure(InputData::new(normalized)) 107 + buttplug_core::message::InputTypeData::Pressure(InputData::new(normalized)), 108 108 ) 109 109 .into(), 110 110 ) ··· 121 121 InputReadingV4::new( 122 122 device_index, 123 123 feature_index, 124 - buttplug_core::message::InputTypeData::Pressure(InputData::new(unnormalized)) 124 + buttplug_core::message::InputTypeData::Pressure(InputData::new( 125 + unnormalized, 126 + )), 125 127 ) 126 128 .into(), 127 129 )
+19 -17
crates/buttplug_server/src/device/protocol_impl/kiiroo_prowand.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareReadCmd, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler}, 10 + protocol::{ProtocolHandler, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::{ 13 13 errors::ButtplugDeviceError, 14 14 message::{self, InputData, InputReadingV4, InputTypeData}, 15 15 }; 16 16 use buttplug_server_device_config::Endpoint; 17 - use futures::{future::BoxFuture, FutureExt}; 17 + use futures::{FutureExt, future::BoxFuture}; 18 18 use std::{default::Default, sync::Arc}; 19 19 use uuid::Uuid; 20 20 ··· 30 30 feature_id: Uuid, 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 - Ok(vec![HardwareWriteCmd::new( 34 - &[feature_id], 35 - Endpoint::Tx, 36 - vec![ 37 - 0x00, 38 - 0x00, 39 - 0x64, 40 - if speed == 0 { 0x00 } else { 0xff }, 41 - speed as u8, 42 - speed as u8, 43 - ], 44 - false, 45 - ) 46 - .into()]) 33 + Ok(vec![ 34 + HardwareWriteCmd::new( 35 + &[feature_id], 36 + Endpoint::Tx, 37 + vec![ 38 + 0x00, 39 + 0x00, 40 + 0x64, 41 + if speed == 0 { 0x00 } else { 0xff }, 42 + speed as u8, 43 + speed as u8, 44 + ], 45 + false, 46 + ) 47 + .into(), 48 + ]) 47 49 } 48 50 49 51 fn handle_battery_level_cmd( ··· 62 64 let battery_reading = message::InputReadingV4::new( 63 65 device_index, 64 66 feature_index, 65 - InputTypeData::Battery(InputData::new(data[0])) 67 + InputTypeData::Battery(InputData::new(data[0])), 66 68 ); 67 69 debug!("Got battery reading: {}", data[0]); 68 70 Ok(battery_reading)
+12 -10
crates/buttplug_server/src/device/protocol_impl/kiiroo_spot.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareReadCmd, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler}, 10 + protocol::{ProtocolHandler, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::{ 13 13 errors::ButtplugDeviceError, 14 14 message::{self, InputData, InputReadingV4, InputTypeData}, 15 15 }; 16 16 use buttplug_server_device_config::Endpoint; 17 - use futures::{future::BoxFuture, FutureExt}; 17 + use futures::{FutureExt, future::BoxFuture}; 18 18 use std::{default::Default, sync::Arc}; 19 19 use uuid::Uuid; 20 20 ··· 30 30 feature_id: Uuid, 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 - Ok(vec![HardwareWriteCmd::new( 34 - &[feature_id], 35 - Endpoint::Tx, 36 - vec![0x00, 0xff, 0x00, 0x00, 0x00, speed as u8], 37 - false, 38 - ) 39 - .into()]) 33 + Ok(vec![ 34 + HardwareWriteCmd::new( 35 + &[feature_id], 36 + Endpoint::Tx, 37 + vec![0x00, 0xff, 0x00, 0x00, 0x00, speed as u8], 38 + false, 39 + ) 40 + .into(), 41 + ]) 40 42 } 41 43 42 44 fn handle_battery_level_cmd( ··· 55 57 let battery_reading = message::InputReadingV4::new( 56 58 device_index, 57 59 feature_index, 58 - InputTypeData::Battery(InputData::new(data[0])) 60 + InputTypeData::Battery(InputData::new(data[0])), 59 61 ); 60 62 debug!("Got battery reading: {}", data[0]); 61 63 Ok(battery_reading)
+13 -11
crates/buttplug_server/src/device/protocol_impl/kiiroo_v2.rs
··· 9 9 use crate::device::{ 10 10 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 11 11 protocol::{ 12 - generic_protocol_initializer_setup, 13 12 ProtocolHandler, 14 13 ProtocolIdentifier, 15 14 ProtocolInitializer, 15 + generic_protocol_initializer_setup, 16 16 }, 17 17 }; 18 18 use async_trait::async_trait; 19 19 use buttplug_core::errors::ButtplugDeviceError; 20 20 use buttplug_server_device_config::Endpoint; 21 21 use buttplug_server_device_config::{ 22 - ServerDeviceDefinition, 23 22 ProtocolCommunicationSpecifier, 23 + ServerDeviceDefinition, 24 24 UserDeviceIdentifier, 25 25 }; 26 26 use std::sync::{ 27 - atomic::{AtomicU8, Ordering}, 28 27 Arc, 28 + atomic::{AtomicU8, Ordering}, 29 29 }; 30 - use uuid::{uuid, Uuid}; 30 + use uuid::{Uuid, uuid}; 31 31 32 32 const KIIROO_V2_PROTOCOL_UUID: Uuid = uuid!("05ab9d57-5e65-47b2-add4-5bad3e8663e5"); 33 33 generic_protocol_initializer_setup!(KiirooV2, "kiiroo-v2"); ··· 73 73 let position = position as u8; 74 74 let calculated_speed = (calculate_speed(distance, duration) * 99f64) as u8; 75 75 self.previous_position.store(position, Ordering::Relaxed); 76 - Ok(vec![HardwareWriteCmd::new( 77 - &[feature_id], 78 - Endpoint::Tx, 79 - [position, calculated_speed].to_vec(), 80 - false, 81 - ) 82 - .into()]) 76 + Ok(vec![ 77 + HardwareWriteCmd::new( 78 + &[feature_id], 79 + Endpoint::Tx, 80 + [position, calculated_speed].to_vec(), 81 + false, 82 + ) 83 + .into(), 84 + ]) 83 85 } 84 86 }
+18 -29
crates/buttplug_server/src/device/protocol_impl/kiiroo_v21.rs
··· 8 8 use super::fleshlight_launch_helper::calculate_speed; 9 9 use crate::{ 10 10 device::{ 11 - hardware::{ 12 - Hardware, 13 - HardwareCommand, 14 - HardwareReadCmd, 15 - HardwareWriteCmd, 16 - }, 17 - protocol::{generic_protocol_setup, ProtocolHandler}, 11 + hardware::{Hardware, HardwareCommand, HardwareReadCmd, HardwareWriteCmd}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 18 13 }, 19 14 message::ButtplugServerDeviceMessage, 20 15 }; 21 16 use buttplug_core::{ 22 17 errors::ButtplugDeviceError, 23 18 message::{InputData, InputReadingV4, InputTypeData}, 24 - util::{stream::convert_broadcast_receiver_to_stream}, 19 + util::stream::convert_broadcast_receiver_to_stream, 25 20 }; 26 21 use buttplug_server_device_config::Endpoint; 27 22 use dashmap::DashSet; 28 - use futures::{ 29 - future::BoxFuture, 30 - FutureExt, 31 - StreamExt, 32 - }; 23 + use futures::{FutureExt, StreamExt, future::BoxFuture}; 33 24 use std::{ 34 25 default::Default, 35 26 pin::Pin, 36 27 sync::{ 37 - atomic::{AtomicU8, Ordering::Relaxed}, 38 28 Arc, 29 + atomic::{AtomicU8, Ordering::Relaxed}, 39 30 }, 40 31 }; 41 32 use tokio::sync::broadcast; ··· 68 59 feature_id: Uuid, 69 60 speed: u32, 70 61 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 71 - Ok(vec![HardwareWriteCmd::new( 72 - &[feature_id], 73 - Endpoint::Tx, 74 - vec![0x01, speed as u8], 75 - false, 76 - ) 77 - .into()]) 62 + Ok(vec![ 63 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![0x01, speed as u8], false).into(), 64 + ]) 78 65 } 79 66 80 67 fn handle_position_with_duration_cmd( ··· 91 78 let position = position as u8; 92 79 let speed = (calculate_speed(distance, duration) * 99f64) as u8; 93 80 self.previous_position.store(position, Relaxed); 94 - Ok(vec![HardwareWriteCmd::new( 95 - &[feature_id], 96 - Endpoint::Tx, 97 - [0x03, 0x00, speed, position].to_vec(), 98 - false, 99 - ) 100 - .into()]) 81 + Ok(vec![ 82 + HardwareWriteCmd::new( 83 + &[feature_id], 84 + Endpoint::Tx, 85 + [0x03, 0x00, speed, position].to_vec(), 86 + false, 87 + ) 88 + .into(), 89 + ]) 101 90 } 102 91 103 92 fn handle_battery_level_cmd( ··· 125 114 let battery_reading = InputReadingV4::new( 126 115 device_index, 127 116 feature_index, 128 - InputTypeData::Battery(InputData::new(battery_level)) 117 + InputTypeData::Battery(InputData::new(battery_level)), 129 118 ); 130 119 debug!("Got battery reading: {}", battery_level); 131 120 Ok(battery_reading)
+16 -18
crates/buttplug_server/src/device/protocol_impl/kiiroo_v21_initialized.rs
··· 10 10 use crate::device::{ 11 11 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 12 12 protocol::{ 13 - generic_protocol_initializer_setup, 14 13 ProtocolHandler, 15 14 ProtocolIdentifier, 16 15 ProtocolInitializer, 16 + generic_protocol_initializer_setup, 17 17 }, 18 18 }; 19 19 use async_trait::async_trait; 20 20 use buttplug_core::errors::ButtplugDeviceError; 21 21 use buttplug_server_device_config::Endpoint; 22 22 use buttplug_server_device_config::{ 23 - ServerDeviceDefinition, 24 23 ProtocolCommunicationSpecifier, 24 + ServerDeviceDefinition, 25 25 UserDeviceIdentifier, 26 26 }; 27 27 use std::sync::{ 28 - atomic::{AtomicU8, Ordering}, 29 28 Arc, 29 + atomic::{AtomicU8, Ordering}, 30 30 }; 31 - use uuid::{uuid, Uuid}; 31 + use uuid::{Uuid, uuid}; 32 32 33 33 const KIIROO_V21_INITIALIZED_PROTOCOL_UUID: Uuid = uuid!("22329023-5464-41b6-a0de-673d7e993055"); 34 34 ··· 77 77 feature_id: Uuid, 78 78 speed: u32, 79 79 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 80 - Ok(vec![HardwareWriteCmd::new( 81 - &[feature_id], 82 - Endpoint::Tx, 83 - vec![0x01, speed as u8], 84 - false, 85 - ) 86 - .into()]) 80 + Ok(vec![ 81 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![0x01, speed as u8], false).into(), 82 + ]) 87 83 } 88 84 89 85 fn handle_position_with_duration_cmd( ··· 102 98 self 103 99 .previous_position 104 100 .store(position as u8, Ordering::Relaxed); 105 - Ok(vec![HardwareWriteCmd::new( 106 - &[feature_id], 107 - Endpoint::Tx, 108 - [0x03, 0x00, calculated_speed, position as u8].to_vec(), 109 - false, 110 - ) 111 - .into()]) 101 + Ok(vec![ 102 + HardwareWriteCmd::new( 103 + &[feature_id], 104 + Endpoint::Tx, 105 + [0x03, 0x00, calculated_speed, position as u8].to_vec(), 106 + false, 107 + ) 108 + .into(), 109 + ]) 112 110 } 113 111 }
+14 -12
crates/buttplug_server/src/device/protocol_impl/kiiroo_v2_vibrator.rs
··· 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 38 38 speed: u32, 39 39 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 40 40 self.speeds[feature_index as usize].store(speed as u8, Ordering::Relaxed); 41 - Ok(vec![HardwareWriteCmd::new( 42 - &[feature_id], 43 - Endpoint::Tx, 44 - self 45 - .speeds 46 - .iter() 47 - .map(|v| v.load(Ordering::Relaxed)) 48 - .collect(), 49 - false, 50 - ) 51 - .into()]) 41 + Ok(vec![ 42 + HardwareWriteCmd::new( 43 + &[feature_id], 44 + Endpoint::Tx, 45 + self 46 + .speeds 47 + .iter() 48 + .map(|v| v.load(Ordering::Relaxed)) 49 + .collect(), 50 + false, 51 + ) 52 + .into(), 53 + ]) 52 54 } 53 55 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/kizuna.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![48 + speed as u8, b'\r', b'\n'], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![48 + speed as u8, b'\r', b'\n'], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+23 -21
crates/buttplug_server/src/device/protocol_impl/lelo_harmony.rs
··· 15 15 HardwareWriteCmd, 16 16 }, 17 17 protocol::{ 18 - generic_protocol_initializer_setup, 19 18 ProtocolHandler, 20 19 ProtocolIdentifier, 21 20 ProtocolInitializer, 21 + generic_protocol_initializer_setup, 22 22 }, 23 23 }; 24 24 use async_trait::async_trait; 25 25 use buttplug_core::errors::ButtplugDeviceError; 26 26 use buttplug_server_device_config::Endpoint; 27 27 use buttplug_server_device_config::{ 28 - ServerDeviceDefinition, 29 28 ProtocolCommunicationSpecifier, 29 + ServerDeviceDefinition, 30 30 UserDeviceIdentifier, 31 31 }; 32 32 use std::sync::Arc; 33 - use uuid::{uuid, Uuid}; 33 + use uuid::{Uuid, uuid}; 34 34 35 35 const LELO_HARMONY_PROTOCOL_UUID: Uuid = uuid!("220e180a-e6d5-4fd1-963e-43a6f990b717"); 36 36 generic_protocol_initializer_setup!(LeloHarmony, "lelo-harmony"); ··· 119 119 feature_id: Uuid, 120 120 speed: u32, 121 121 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 122 - Ok(vec![HardwareWriteCmd::new( 123 - &[feature_id], 124 - Endpoint::Tx, 125 - vec![ 126 - 0x0a, 127 - 0x12, 128 - feature_index as u8 + 1, 129 - 0x08, 130 - 0x00, 131 - 0x00, 132 - 0x00, 133 - 0x00, 134 - speed as u8, 135 - 0x00, 136 - ], 137 - false, 138 - ) 139 - .into()]) 122 + Ok(vec![ 123 + HardwareWriteCmd::new( 124 + &[feature_id], 125 + Endpoint::Tx, 126 + vec![ 127 + 0x0a, 128 + 0x12, 129 + feature_index as u8 + 1, 130 + 0x08, 131 + 0x00, 132 + 0x00, 133 + 0x00, 134 + 0x00, 135 + speed as u8, 136 + 0x00, 137 + ], 138 + false, 139 + ) 140 + .into(), 141 + ]) 140 142 } 141 143 } 142 144
+13 -11
crates/buttplug_server/src/device/protocol_impl/lelof1s.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareSubscribeCmd, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::sync::{ 26 - atomic::{AtomicU8, Ordering}, 27 26 Arc, 27 + atomic::{AtomicU8, Ordering}, 28 28 }; 29 - use uuid::{uuid, Uuid}; 29 + use uuid::{Uuid, uuid}; 30 30 31 31 const LELO_F1S_PROTOCOL_UUID: Uuid = uuid!("4987f232-40f9-47a3-8d0c-e30b74e75310"); 32 32 generic_protocol_initializer_setup!(LeloF1s, "lelo-f1s"); ··· 81 81 .speeds 82 82 .iter() 83 83 .for_each(|v| cmd_vec.push(v.load(Ordering::Relaxed))); 84 - Ok(vec![HardwareWriteCmd::new( 85 - &[LELO_F1S_PROTOCOL_UUID], 86 - Endpoint::Tx, 87 - cmd_vec, 88 - self.write_with_response, 89 - ) 90 - .into()]) 84 + Ok(vec![ 85 + HardwareWriteCmd::new( 86 + &[LELO_F1S_PROTOCOL_UUID], 87 + Endpoint::Tx, 88 + cmd_vec, 89 + self.write_with_response, 90 + ) 91 + .into(), 92 + ]) 91 93 } 92 94 }
+4 -7
crates/buttplug_server/src/device/protocol_impl/lelof1sv2.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use super::{ 9 - lelo_harmony::LeloHarmony, 10 - lelof1s::LeloF1s, 11 - }; 8 + use super::{lelo_harmony::LeloHarmony, lelof1s::LeloF1s}; 12 9 use crate::device::{ 13 10 hardware::{ 14 11 Hardware, ··· 18 15 HardwareWriteCmd, 19 16 }, 20 17 protocol::{ 21 - generic_protocol_initializer_setup, 22 18 ProtocolHandler, 23 19 ProtocolIdentifier, 24 20 ProtocolInitializer, 21 + generic_protocol_initializer_setup, 25 22 }, 26 23 }; 27 24 use async_trait::async_trait; 28 25 use buttplug_core::errors::ButtplugDeviceError; 29 26 use buttplug_server_device_config::Endpoint; 30 27 use buttplug_server_device_config::{ 31 - ServerDeviceDefinition, 32 28 ProtocolCommunicationSpecifier, 29 + ServerDeviceDefinition, 33 30 UserDeviceIdentifier, 34 31 }; 35 32 use std::sync::Arc; 36 - use uuid::{uuid, Uuid}; 33 + use uuid::{Uuid, uuid}; 37 34 38 35 const LELO_F1S_V2_PROTOCOL_UUID: Uuid = uuid!("85c59ac5-89ee-4549-8958-ce5449226a5c"); 39 36 generic_protocol_initializer_setup!(LeloF1sV2, "lelo-f1sv2");
+8 -11
crates/buttplug_server/src/device/protocol_impl/leten.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 - ProtocolInitializer, ProtocolKeepaliveStrategy, 13 + ProtocolInitializer, 14 + ProtocolKeepaliveStrategy, 15 + generic_protocol_initializer_setup, 15 16 }, 16 17 }; 17 18 use async_trait::async_trait; 18 19 use buttplug_core::errors::ButtplugDeviceError; 19 20 use buttplug_server_device_config::Endpoint; 20 21 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 22 ProtocolCommunicationSpecifier, 23 + ServerDeviceDefinition, 23 24 UserDeviceIdentifier, 24 25 }; 25 26 use std::sync::Arc; 26 27 use std::time::Duration; 27 - use uuid::{uuid, Uuid}; 28 + use uuid::{Uuid, uuid}; 28 29 29 30 const LETEN_PROTOCOL_UUID: Uuid = uuid!("7d899f44-2676-4a00-9c68-0c800055ee2a"); 30 31 ··· 73 74 feature_id: Uuid, 74 75 speed: u32, 75 76 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 76 - Ok(vec![HardwareWriteCmd::new( 77 - &[feature_id], 78 - Endpoint::Tx, 79 - vec![0x02, speed as u8], 80 - true, 81 - ) 82 - .into()]) 77 + Ok(vec![ 78 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![0x02, speed as u8], true).into(), 79 + ]) 83 80 } 84 81 }
+1 -1
crates/buttplug_server/src/device/protocol_impl/libo_elle.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint;
+5 -9
crates/buttplug_server/src/device/protocol_impl/libo_shark.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 33 33 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 34 34 self.values[feature_index as usize].store(speed as u8, Ordering::Relaxed); 35 35 let data = self.values[0].load(Ordering::Relaxed) << 4 | self.values[1].load(Ordering::Relaxed); 36 - Ok(vec![HardwareWriteCmd::new( 37 - &[LIBO_SHARK_PROTOCOL_UUID], 38 - Endpoint::Tx, 39 - vec![data], 40 - false, 41 - ) 42 - .into()]) 36 + Ok(vec![ 37 + HardwareWriteCmd::new(&[LIBO_SHARK_PROTOCOL_UUID], Endpoint::Tx, vec![data], false).into(), 38 + ]) 43 39 } 44 40 }
+2 -2
crates/buttplug_server/src/device/protocol_impl/libo_vibes.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use uuid::{uuid, Uuid}; 8 + use uuid::{Uuid, uuid}; 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint;
+12 -10
crates/buttplug_server/src/device/protocol_impl/lioness.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareSubscribeCmd, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::sync::Arc; 26 - use uuid::{uuid, Uuid}; 26 + use uuid::{Uuid, uuid}; 27 27 28 28 const LIONESS_PROTOCOL_UUID: Uuid = uuid!("1912c626-f611-4569-9d62-fb40ff8e1474"); 29 29 generic_protocol_initializer_setup!(Lioness, "lioness"); ··· 73 73 feature_id: Uuid, 74 74 speed: u32, 75 75 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 76 - Ok(vec![HardwareWriteCmd::new( 77 - &[feature_id], 78 - Endpoint::Tx, 79 - vec![0x02, 0xAA, 0xBB, 0xCC, 0xCC, speed as u8], 80 - false, 81 - ) 82 - .into()]) 76 + Ok(vec![ 77 + HardwareWriteCmd::new( 78 + &[feature_id], 79 + Endpoint::Tx, 80 + vec![0x02, 0xAA, 0xBB, 0xCC, 0xCC, speed as u8], 81 + false, 82 + ) 83 + .into(), 84 + ]) 83 85 } 84 86 }
+6 -10
crates/buttplug_server/src/device/protocol_impl/loob.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::cmp::{max, min}; 26 26 use std::sync::Arc; 27 - use uuid::{uuid, Uuid}; 27 + use uuid::{Uuid, uuid}; 28 28 29 29 const LOOB_PROTOCOL_UUID: Uuid = uuid!("b3a02457-3bda-4c5b-8363-aead6eda74ae"); 30 30 generic_protocol_initializer_setup!(Loob, "loob"); ··· 67 67 for b in time.to_be_bytes() { 68 68 data.push(b); 69 69 } 70 - Ok(vec![HardwareWriteCmd::new( 71 - &[feature_id], 72 - Endpoint::Tx, 73 - data, 74 - false, 75 - ) 76 - .into()]) 70 + Ok(vec![ 71 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 72 + ]) 77 73 } 78 74 }
+12 -10
crates/buttplug_server/src/device/protocol_impl/lovedistance.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::sync::Arc; 26 - use uuid::{uuid, Uuid}; 26 + use uuid::{Uuid, uuid}; 27 27 28 28 const LOVEDISTANCE_PROTOCOL_UUID: Uuid = uuid!("a5f50cd5-7985-438c-a5bc-f8ff72bc0117"); 29 29 generic_protocol_initializer_setup!(LoveDistance, "lovedistance"); ··· 66 66 feature_id: Uuid, 67 67 speed: u32, 68 68 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 69 - Ok(vec![HardwareWriteCmd::new( 70 - &[feature_id], 71 - Endpoint::Tx, 72 - vec![0xf3, 0x00, speed as u8], 73 - false, 74 - ) 75 - .into()]) 69 + Ok(vec![ 70 + HardwareWriteCmd::new( 71 + &[feature_id], 72 + Endpoint::Tx, 73 + vec![0xf3, 0x00, speed as u8], 74 + false, 75 + ) 76 + .into(), 77 + ]) 76 78 } 77 79 }
+29 -21
crates/buttplug_server/src/device/protocol_impl/lovehoney_desire.rs
··· 6 6 // for full license information. 7 7 8 8 use std::sync::{ 9 - atomic::{AtomicU8, Ordering}, 10 9 Arc, 10 + atomic::{AtomicU8, Ordering}, 11 11 }; 12 12 13 13 use async_trait::async_trait; 14 - use uuid::{uuid, Uuid}; 14 + use uuid::{Uuid, uuid}; 15 15 16 16 use crate::device::{ 17 17 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 18 18 protocol::{ 19 - generic_protocol_initializer_setup, 20 19 ProtocolHandler, 21 20 ProtocolIdentifier, 22 21 ProtocolInitializer, 22 + generic_protocol_initializer_setup, 23 23 }, 24 24 }; 25 25 use buttplug_core::errors::ButtplugDeviceError; 26 26 use buttplug_server_device_config::Endpoint; 27 - use buttplug_server_device_config::{ServerDeviceDefinition, ProtocolCommunicationSpecifier, UserDeviceIdentifier}; 27 + use buttplug_server_device_config::{ 28 + ProtocolCommunicationSpecifier, 29 + ServerDeviceDefinition, 30 + UserDeviceIdentifier, 31 + }; 28 32 const LOVEHONEY_DESIRE_PROTOCOL_UUID: Uuid = uuid!("5dcd8487-4814-44cb-a768-13bf81d545c0"); 29 33 const LOVEHONEY_DESIRE_VIBE2_PROTOCOL_UUID: Uuid = uuid!("d44a99fe-903b-4fff-bee7-1141767c9cca"); 30 34 ··· 79 83 // We'll need to check what we got back and write our 80 84 // commands accordingly. 81 85 if self.current_commands.len() == 1 { 82 - Ok(vec![HardwareWriteCmd::new( 83 - &[LOVEHONEY_DESIRE_PROTOCOL_UUID], 84 - Endpoint::Tx, 85 - vec![0xF3, 0, speed as u8], 86 - true, 87 - ) 88 - .into()]) 86 + Ok(vec![ 87 + HardwareWriteCmd::new( 88 + &[LOVEHONEY_DESIRE_PROTOCOL_UUID], 89 + Endpoint::Tx, 90 + vec![0xF3, 0, speed as u8], 91 + true, 92 + ) 93 + .into(), 94 + ]) 89 95 } else { 90 96 self.current_commands[feature_index as usize].store(speed as u8, Ordering::Relaxed); 91 97 let speed0 = self.current_commands[0].load(Ordering::Relaxed); 92 98 let speed1 = self.current_commands[1].load(Ordering::Relaxed); 93 99 if speed0 == speed1 { 94 - Ok(vec![HardwareWriteCmd::new( 95 - &[ 96 - LOVEHONEY_DESIRE_PROTOCOL_UUID, 97 - LOVEHONEY_DESIRE_VIBE2_PROTOCOL_UUID, 98 - ], 99 - Endpoint::Tx, 100 - vec![0xF3, 0, speed0 as u8], 101 - true, 102 - ) 103 - .into()]) 100 + Ok(vec![ 101 + HardwareWriteCmd::new( 102 + &[ 103 + LOVEHONEY_DESIRE_PROTOCOL_UUID, 104 + LOVEHONEY_DESIRE_VIBE2_PROTOCOL_UUID, 105 + ], 106 + Endpoint::Tx, 107 + vec![0xF3, 0, speed0 as u8], 108 + true, 109 + ) 110 + .into(), 111 + ]) 104 112 } else { 105 113 Ok(vec![ 106 114 HardwareWriteCmd::new(
+1 -4
crates/buttplug_server/src/device/protocol_impl/lovense/lovense_max.rs
··· 8 8 use super::{form_lovense_command, form_vibrate_command}; 9 9 use crate::device::{ 10 10 hardware::{Hardware, HardwareCommand}, 11 - protocol::{ 12 - ProtocolHandler, 13 - ProtocolKeepaliveStrategy, 14 - }, 11 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy}, 15 12 }; 16 13 use buttplug_core::{errors::ButtplugDeviceError, message::InputReadingV4}; 17 14 use futures::future::BoxFuture;
+5 -12
crates/buttplug_server/src/device/protocol_impl/lovense/lovense_multi_actuator.rs
··· 10 10 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 11 11 protocol::{ProtocolHandler, ProtocolKeepaliveStrategy}, 12 12 }; 13 - use buttplug_core::{ 14 - errors::ButtplugDeviceError, 15 - message::InputReadingV4, 16 - }; 13 + use buttplug_core::{errors::ButtplugDeviceError, message::InputReadingV4}; 17 14 use buttplug_server_device_config::Endpoint; 18 15 use futures::future::BoxFuture; 19 - use std::sync::{atomic::AtomicU32, Arc}; 16 + use std::sync::{Arc, atomic::AtomicU32}; 20 17 use uuid::Uuid; 21 18 22 19 #[derive(Default)] ··· 48 45 let lovense_cmd = format!("Vibrate{}:{};", feature_index + 1, speed) 49 46 .as_bytes() 50 47 .to_vec(); 51 - Ok(vec![HardwareWriteCmd::new( 52 - &[feature_id], 53 - Endpoint::Tx, 54 - lovense_cmd, 55 - false, 56 - ) 57 - .into()]) 48 + Ok(vec![ 49 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, lovense_cmd, false).into(), 50 + ]) 58 51 } 59 52 60 53 fn handle_output_oscillate_cmd(
+2 -5
crates/buttplug_server/src/device/protocol_impl/lovense/lovense_rotate_vibrator.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{Hardware, HardwareCommand}, 12 - protocol::{ 13 - ProtocolHandler, 14 - ProtocolKeepaliveStrategy, 15 - }, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy}, 16 13 }; 17 14 use buttplug_core::{errors::ButtplugDeviceError, message::InputReadingV4}; 18 15 use futures::future::BoxFuture; 19 16 use std::sync::{ 20 - atomic::{AtomicBool, Ordering}, 21 17 Arc, 18 + atomic::{AtomicBool, Ordering}, 22 19 }; 23 20 use uuid::Uuid; 24 21
+2 -2
crates/buttplug_server/src/device/protocol_impl/lovense/lovense_stroker.rs
··· 18 18 use futures::future::BoxFuture; 19 19 use std::{ 20 20 sync::{ 21 - atomic::{AtomicU32, Ordering}, 22 21 Arc, 22 + atomic::{AtomicU32, Ordering}, 23 23 }, 24 24 time::Duration, 25 25 }; 26 - use uuid::{uuid, Uuid}; 26 + use uuid::{Uuid, uuid}; 27 27 28 28 const LOVENSE_STROKER_PROTOCOL_UUID: Uuid = uuid!("a97fc354-5561-459a-bc62-110d7c2868ac"); 29 29
+41 -24
crates/buttplug_server/src/device/protocol_impl/lovense/mod.rs
··· 11 11 mod lovense_single_actuator; 12 12 mod lovense_stroker; 13 13 14 - 15 14 use lovense_max::LovenseMax; 16 15 use lovense_multi_actuator::LovenseMultiActuator; 17 16 use lovense_rotate_vibrator::LovenseRotateVibrator; ··· 20 19 21 20 use crate::device::{ 22 21 hardware::{Hardware, HardwareCommand, HardwareEvent, HardwareSubscribeCmd, HardwareWriteCmd}, 23 - protocol::{ 24 - ProtocolHandler, 25 - ProtocolIdentifier, 26 - ProtocolInitializer, ProtocolKeepaliveStrategy, 27 - }, 22 + protocol::{ProtocolHandler, ProtocolIdentifier, ProtocolInitializer, ProtocolKeepaliveStrategy}, 28 23 }; 29 24 use async_trait::async_trait; 30 25 use buttplug_core::{ ··· 33 28 util::sleep, 34 29 }; 35 30 use buttplug_server_device_config::{ 36 - ServerDeviceDefinition, 31 + Endpoint, 37 32 ProtocolCommunicationSpecifier, 33 + ServerDeviceDefinition, 38 34 UserDeviceIdentifier, 39 - Endpoint 40 35 }; 41 - use futures::{future::BoxFuture, FutureExt}; 36 + use futures::{FutureExt, future::BoxFuture}; 42 37 use regex::Regex; 43 38 use std::{sync::Arc, time::Duration}; 44 39 use tokio::select; 45 - use uuid::{uuid, Uuid}; 40 + use uuid::{Uuid, uuid}; 46 41 47 42 // Constants for dealing with the Lovense subscript/write race condition. The 48 43 // timeout needs to be VERY long, otherwise this trips up old lovense serial ··· 175 170 let vibrator_count = device_definition 176 171 .features() 177 172 .iter() 178 - .filter(|x| x.output().as_ref().is_some_and(|x| x.contains(OutputType::Vibrate) || x.contains(OutputType::Oscillate))) 173 + .filter(|x| { 174 + x.output() 175 + .as_ref() 176 + .is_some_and(|x| x.contains(OutputType::Vibrate) || x.contains(OutputType::Oscillate)) 177 + }) 179 178 .count(); 180 179 181 180 let output_count = device_definition ··· 188 187 && device_definition 189 188 .features() 190 189 .iter() 191 - .filter(|x| x.output().as_ref().is_some_and(|x| x.contains(OutputType::Vibrate))) 190 + .filter(|x| { 191 + x.output() 192 + .as_ref() 193 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 194 + }) 192 195 .count() 193 196 == 1 194 197 && device_definition 195 198 .features() 196 199 .iter() 197 - .filter(|x| x.output().as_ref().is_some_and(|x| x.contains(OutputType::RotateWithDirection))) 200 + .filter(|x| { 201 + x.output() 202 + .as_ref() 203 + .is_some_and(|x| x.contains(OutputType::RotateWithDirection)) 204 + }) 198 205 .count() 199 206 == 1; 200 207 ··· 202 209 && device_definition 203 210 .features() 204 211 .iter() 205 - .filter(|x| x.output().as_ref().is_some_and(|x| x.contains(OutputType::Vibrate))) 212 + .filter(|x| { 213 + x.output() 214 + .as_ref() 215 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 216 + }) 206 217 .count() 207 218 == 1 208 219 && device_definition 209 220 .features() 210 221 .iter() 211 - .filter(|x| x.output().as_ref().is_some_and(|x| x.contains(OutputType::Constrict))) 222 + .filter(|x| { 223 + x.output() 224 + .as_ref() 225 + .is_some_and(|x| x.contains(OutputType::Constrict)) 226 + }) 212 227 .count() 213 228 == 1; 214 229 ··· 472 487 return Ok(message::InputReadingV4::new( 473 488 device_index, 474 489 feature_index, 475 - InputTypeData::Battery(InputData::new(level)) 490 + InputTypeData::Battery(InputData::new(level)), 476 491 )); 477 492 } 478 493 } ··· 481 496 return Err(ButtplugDeviceError::ProtocolSpecificError( 482 497 "Lovense".to_owned(), 483 498 "Lovense Device disconnected while getting Battery info.".to_owned(), 484 - )) 499 + )); 485 500 } 486 501 } 487 502 } ··· 507 522 feature_id: Uuid, 508 523 command: &str, 509 524 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 510 - Ok(vec![HardwareWriteCmd::new( 511 - &[feature_id], 512 - Endpoint::Tx, 513 - command.as_bytes().to_vec(), 514 - false, 515 - ) 516 - .into()]) 525 + Ok(vec![ 526 + HardwareWriteCmd::new( 527 + &[feature_id], 528 + Endpoint::Tx, 529 + command.as_bytes().to_vec(), 530 + false, 531 + ) 532 + .into(), 533 + ]) 517 534 } 518 535 519 536 pub(super) fn form_vibrate_command(
+4 -8
crates/buttplug_server/src/device/protocol_impl/lovenuts.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 31 31 data.push(0x00); 32 32 data.push(0xff); 33 33 34 - Ok(vec![HardwareWriteCmd::new( 35 - &[feature_id], 36 - Endpoint::Tx, 37 - data, 38 - false, 39 - ) 40 - .into()]) 34 + Ok(vec![ 35 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 36 + ]) 41 37 } 42 38 }
+19 -16
crates/buttplug_server/src/device/protocol_impl/luvmazer.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{ProtocolHandler, generic_protocol_setup} 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; 16 - 17 16 18 17 generic_protocol_setup!(Luvmazer, "luvmazer"); 19 18 ··· 27 26 feature_id: Uuid, 28 27 speed: u32, 29 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 30 - Ok(vec![HardwareWriteCmd::new( 31 - &[feature_id], 32 - Endpoint::Tx, 33 - vec![0xa0, 0x01, 0x00, 0x00, 0x64, speed as u8], 34 - false, 35 - ) 36 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xa0, 0x01, 0x00, 0x00, 0x64, speed as u8], 34 + false, 35 + ) 36 + .into(), 37 + ]) 37 38 } 38 39 39 40 fn handle_output_rotate_cmd( ··· 42 43 feature_id: Uuid, 43 44 speed: u32, 44 45 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 45 - Ok(vec![HardwareWriteCmd::new( 46 - &[feature_id], 47 - Endpoint::Tx, 48 - vec![0xa0, 0x0f, 0x00, 0x00, 0x64, speed as u8], 49 - false, 50 - ) 51 - .into()]) 46 + Ok(vec![ 47 + HardwareWriteCmd::new( 48 + &[feature_id], 49 + Endpoint::Tx, 50 + vec![0xa0, 0x0f, 0x00, 0x00, 0x64, speed as u8], 51 + false, 52 + ) 53 + .into(), 54 + ]) 52 55 } 53 56 }
+45 -41
crates/buttplug_server/src/device/protocol_impl/magic_motion_v1.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![ 33 - 0x0b, 34 - 0xff, 35 - 0x04, 36 - 0x0a, 37 - 0x32, 38 - 0x32, 39 - 0x00, 40 - 0x04, 41 - 0x08, 42 - speed as u8, 43 - 0x64, 44 - 0x00, 45 - ], 46 - false, 47 - ) 48 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![ 34 + 0x0b, 35 + 0xff, 36 + 0x04, 37 + 0x0a, 38 + 0x32, 39 + 0x32, 40 + 0x00, 41 + 0x04, 42 + 0x08, 43 + speed as u8, 44 + 0x64, 45 + 0x00, 46 + ], 47 + false, 48 + ) 49 + .into(), 50 + ]) 49 51 } 50 52 51 53 fn handle_output_oscillate_cmd( ··· 54 56 feature_id: Uuid, 55 57 speed: u32, 56 58 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 57 - Ok(vec![HardwareWriteCmd::new( 58 - &[feature_id], 59 - Endpoint::Tx, 60 - vec![ 61 - 0x0b, 62 - 0xff, 63 - 0x04, 64 - 0x0a, 65 - 0x32, 66 - 0x32, 67 - 0x00, 68 - 0x04, 69 - 0x08, 70 - speed as u8, 71 - 0x64, 72 - 0x00, 73 - ], 74 - false, 75 - ) 76 - .into()]) 59 + Ok(vec![ 60 + HardwareWriteCmd::new( 61 + &[feature_id], 62 + Endpoint::Tx, 63 + vec![ 64 + 0x0b, 65 + 0xff, 66 + 0x04, 67 + 0x0a, 68 + 0x32, 69 + 0x32, 70 + 0x00, 71 + 0x04, 72 + 0x08, 73 + speed as u8, 74 + 0x64, 75 + 0x00, 76 + ], 77 + false, 78 + ) 79 + .into(), 80 + ]) 77 81 } 78 82 }
+5 -9
crates/buttplug_server/src/device/protocol_impl/magic_motion_v2.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 59 59 0x64, 60 60 0x01, 61 61 ]; 62 - Ok(vec![HardwareWriteCmd::new( 63 - &[MAGIC_MOTION_2_PROTOCOL_UUID], 64 - Endpoint::Tx, 65 - data, 66 - false, 67 - ) 68 - .into()]) 62 + Ok(vec![ 63 + HardwareWriteCmd::new(&[MAGIC_MOTION_2_PROTOCOL_UUID], Endpoint::Tx, data, false).into(), 64 + ]) 69 65 } 70 66 }
+23 -21
crates/buttplug_server/src/device/protocol_impl/magic_motion_v3.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![ 33 - 0x0b, 34 - 0xff, 35 - 0x04, 36 - 0x0a, 37 - 0x46, 38 - 0x46, 39 - 0x00, 40 - 0x04, 41 - 0x08, 42 - speed as u8, 43 - 0x64, 44 - 0x00, 45 - ], 46 - false, 47 - ) 48 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![ 34 + 0x0b, 35 + 0xff, 36 + 0x04, 37 + 0x0a, 38 + 0x46, 39 + 0x46, 40 + 0x00, 41 + 0x04, 42 + 0x08, 43 + speed as u8, 44 + 0x64, 45 + 0x00, 46 + ], 47 + false, 48 + ) 49 + .into(), 50 + ]) 49 51 } 50 52 }
+7 -11
crates/buttplug_server/src/device/protocol_impl/magic_motion_v4.rs
··· 6 6 // for full license information. 7 7 8 8 use std::sync::{ 9 - atomic::{AtomicU8, Ordering}, 10 9 Arc, 10 + atomic::{AtomicU8, Ordering}, 11 11 }; 12 12 13 13 use async_trait::async_trait; 14 - use uuid::{uuid, Uuid}; 14 + use uuid::{Uuid, uuid}; 15 15 16 - use buttplug_server_device_config::ServerDeviceDefinition; 17 16 use crate::device::{ 18 17 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 19 18 protocol::{ 20 - generic_protocol_initializer_setup, 21 19 ProtocolHandler, 22 20 ProtocolIdentifier, 23 21 ProtocolInitializer, 22 + generic_protocol_initializer_setup, 24 23 }, 25 24 }; 26 25 use buttplug_core::errors::ButtplugDeviceError; 27 26 use buttplug_server_device_config::Endpoint; 27 + use buttplug_server_device_config::ServerDeviceDefinition; 28 28 use buttplug_server_device_config::{ProtocolCommunicationSpecifier, UserDeviceIdentifier}; 29 29 const MAGICMOTIONV4_PROTOCOL_UUID: Uuid = uuid!("d4d62d09-c3e1-44c9-8eba-caa15de5b2a7"); 30 30 ··· 100 100 speed1, 0x64, 0x01, 101 101 ] 102 102 }; 103 - Ok(vec![HardwareWriteCmd::new( 104 - &[MAGICMOTIONV4_PROTOCOL_UUID], 105 - Endpoint::Tx, 106 - data, 107 - true, 108 - ) 109 - .into()]) 103 + Ok(vec![ 104 + HardwareWriteCmd::new(&[MAGICMOTIONV4_PROTOCOL_UUID], Endpoint::Tx, data, true).into(), 105 + ]) 110 106 } 111 107 }
+4 -8
crates/buttplug_server/src/device/protocol_impl/mannuo.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 33 33 crc ^= b; 34 34 } 35 35 data.push(crc); 36 - Ok(vec![HardwareWriteCmd::new( 37 - &[feature_id], 38 - Endpoint::Tx, 39 - data, 40 - true, 41 - ) 42 - .into()]) 36 + Ok(vec![ 37 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, true).into(), 38 + ]) 43 39 } 44 40 }
+4 -8
crates/buttplug_server/src/device/protocol_impl/maxpro.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 45 45 } 46 46 47 47 data[9] = crc; 48 - Ok(vec![HardwareWriteCmd::new( 49 - &[feature_id], 50 - Endpoint::Tx, 51 - data, 52 - false, 53 - ) 54 - .into()]) 48 + Ok(vec![ 49 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 50 + ]) 55 51 } 56 52 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/meese.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0x01, 0x80, 0x01 + (feature_index as u8), (speed as u8)], 33 - true, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0x01, 0x80, 0x01 + (feature_index as u8), (speed as u8)], 34 + true, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+12 -14
crates/buttplug_server/src/device/protocol_impl/metaxsire.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use std::sync::atomic::{AtomicU8, Ordering}; 9 8 use std::sync::Arc; 9 + use std::sync::atomic::{AtomicU8, Ordering}; 10 10 11 11 use async_trait::async_trait; 12 - use uuid::{uuid, Uuid}; 12 + use uuid::{Uuid, uuid}; 13 13 14 - use buttplug_core::{ 15 - errors::ButtplugDeviceError, 16 - message::OutputType, 14 + use buttplug_core::{errors::ButtplugDeviceError, message::OutputType}; 15 + use buttplug_server_device_config::{ 16 + Endpoint, 17 + ProtocolCommunicationSpecifier, 18 + ServerDeviceDefinition, 19 + UserDeviceIdentifier, 17 20 }; 18 - use buttplug_server_device_config::{ServerDeviceDefinition, Endpoint, ProtocolCommunicationSpecifier, UserDeviceIdentifier}; 19 21 20 22 use crate::device::{ 21 23 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 22 24 protocol::{ 23 - generic_protocol_initializer_setup, 24 25 ProtocolHandler, 25 26 ProtocolIdentifier, 26 27 ProtocolInitializer, 28 + generic_protocol_initializer_setup, 27 29 }, 28 30 }; 29 31 ··· 95 97 } 96 98 data.push(crc); 97 99 98 - Ok(vec![HardwareWriteCmd::new( 99 - &[METAXSIRE_PROTOCOL_UUID], 100 - Endpoint::Tx, 101 - data, 102 - false, 103 - ) 104 - .into()]) 100 + Ok(vec![ 101 + HardwareWriteCmd::new(&[METAXSIRE_PROTOCOL_UUID], Endpoint::Tx, data, false).into(), 102 + ]) 105 103 } 106 104 } 107 105
+19 -17
crates/buttplug_server/src/device/protocol_impl/metaxsire_v2.rs
··· 9 9 use crate::device::protocol::ProtocolInitializer; 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_initializer_setup, ProtocolHandler, ProtocolIdentifier}, 12 + protocol::{ProtocolHandler, ProtocolIdentifier, generic_protocol_initializer_setup}, 13 13 }; 14 14 use async_trait::async_trait; 15 15 use buttplug_core::errors::ButtplugDeviceError; 16 16 use buttplug_server_device_config::Endpoint; 17 17 use buttplug_server_device_config::{ 18 - ServerDeviceDefinition, 19 18 ProtocolCommunicationSpecifier, 19 + ServerDeviceDefinition, 20 20 UserDeviceIdentifier, 21 21 }; 22 22 use std::sync::Arc; 23 - use uuid::{uuid, Uuid}; 23 + use uuid::{Uuid, uuid}; 24 24 25 25 const METAXSIRE_V2_PROTOCOL_ID: Uuid = uuid!("28b934b4-ca45-4e14-85e7-4c1524b2b4c1"); 26 26 generic_protocol_initializer_setup!(MetaXSireV2, "metaxsire-v2"); ··· 57 57 feature_id: Uuid, 58 58 speed: u32, 59 59 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 60 - Ok(vec![HardwareWriteCmd::new( 61 - &[feature_id], 62 - Endpoint::Tx, 63 - vec![ 64 - 0xaa, 65 - 0x03, 66 - 0x01, 67 - (feature_index + 1) as u8, 68 - 0x64, 69 - speed as u8, 70 - ], 71 - true, 72 - ) 73 - .into()]) 60 + Ok(vec![ 61 + HardwareWriteCmd::new( 62 + &[feature_id], 63 + Endpoint::Tx, 64 + vec![ 65 + 0xaa, 66 + 0x03, 67 + 0x01, 68 + (feature_index + 1) as u8, 69 + 0x64, 70 + speed as u8, 71 + ], 72 + true, 73 + ) 74 + .into(), 75 + ]) 74 76 } 75 77 } 76 78
+10 -8
crates/buttplug_server/src/device/protocol_impl/metaxsire_v3.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; ··· 28 28 feature_id: Uuid, 29 29 speed: u32, 30 30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[feature_id], 33 - Endpoint::Tx, 34 - vec![0xa1, 0x04, speed as u8, feature_index as u8 + 1], 35 - true, 36 - ) 37 - .into()]) 31 + Ok(vec![ 32 + HardwareWriteCmd::new( 33 + &[feature_id], 34 + Endpoint::Tx, 35 + vec![0xa1, 0x04, speed as u8, feature_index as u8 + 1], 36 + true, 37 + ) 38 + .into(), 39 + ]) 38 40 } 39 41 } 40 42
+10 -8
crates/buttplug_server/src/device/protocol_impl/metaxsire_v4.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xbb, 0x01, speed as u8, 0x66], 33 - true, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xbb, 0x01, speed as u8, 0x66], 34 + true, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/metaxsire_v5.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xaa, 0x03, 0x03, speed as u8, 0x00, 0x00, 0x00], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xaa, 0x03, 0x03, speed as u8, 0x00, 0x00, 0x00], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+17 -15
crates/buttplug_server/src/device/protocol_impl/mizzzee.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![ 33 - 0x69, 34 - 0x96, 35 - 0x03, 36 - 0x01, 37 - if speed == 0 { 0x00 } else { 0x01 }, 38 - speed as u8, 39 - ], 40 - false, 41 - ) 42 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![ 34 + 0x69, 35 + 0x96, 36 + 0x03, 37 + 0x01, 38 + if speed == 0 { 0x00 } else { 0x01 }, 39 + speed as u8, 40 + ], 41 + false, 42 + ) 43 + .into(), 44 + ]) 43 45 } 44 46 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/mizzzee_v2.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0x69, 0x96, 0x04, 0x02, speed as u8, 0x2c, speed as u8], 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0x69, 0x96, 0x04, 0x02, speed as u8, 0x2c, speed as u8], 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+4 -8
crates/buttplug_server/src/device/protocol_impl/mizzzee_v3.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; ··· 69 69 feature_id: Uuid, 70 70 speed: u32, 71 71 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 72 - Ok(vec![HardwareWriteCmd::new( 73 - &[feature_id], 74 - Endpoint::Tx, 75 - scalar_to_vector(speed), 76 - true, 77 - ) 78 - .into()]) 72 + Ok(vec![ 73 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, scalar_to_vector(speed), true).into(), 74 + ]) 79 75 } 80 76 }
+12 -10
crates/buttplug_server/src/device/protocol_impl/mod.rs
··· 2 2 3 3 use crate::device::protocol::ProtocolIdentifierFactory; 4 4 5 - 6 5 // Utility mods 7 6 pub mod fleshlight_launch_helper; 8 7 ··· 206 205 207 206 add_to_protocol_map(&mut map, itoys::setup::IToysIdentifierFactory::default()); 208 207 add_to_protocol_map(&mut map, jejoue::setup::JeJoueIdentifierFactory::default()); 209 - add_to_protocol_map(&mut map, joyhub::joyhub::setup::JoyHubIdentifierFactory::default()); 208 + add_to_protocol_map( 209 + &mut map, 210 + joyhub::joyhub::setup::JoyHubIdentifierFactory::default(), 211 + ); 210 212 add_to_protocol_map( 211 213 &mut map, 212 214 joyhub::joyhub_v2::setup::JoyHubV2IdentifierFactory::default(), ··· 339 341 &mut map, 340 342 metaxsire_v3::setup::MetaXSireV3IdentifierFactory::default(), 341 343 ); 342 - add_to_protocol_map( 343 - &mut map, 344 - metaxsire_v4::setup::MetaXSireV4IdentifierFactory::default(), 345 - ); 346 - add_to_protocol_map( 347 - &mut map, 348 - metaxsire_v5::setup::MetaXSireV5IdentifierFactory::default(), 349 - ); 344 + add_to_protocol_map( 345 + &mut map, 346 + metaxsire_v4::setup::MetaXSireV4IdentifierFactory::default(), 347 + ); 348 + add_to_protocol_map( 349 + &mut map, 350 + metaxsire_v5::setup::MetaXSireV5IdentifierFactory::default(), 351 + ); 350 352 add_to_protocol_map( 351 353 &mut map, 352 354 mizzzee::setup::MizzZeeIdentifierFactory::default(),
+12 -10
crates/buttplug_server/src/device/protocol_impl/monsterpub.rs
··· 13 13 use buttplug_core::errors::ButtplugDeviceError; 14 14 use buttplug_server_device_config::Endpoint; 15 15 use buttplug_server_device_config::{ 16 - ServerDeviceDefinition, 17 16 ProtocolCommunicationSpecifier, 17 + ServerDeviceDefinition, 18 18 UserDeviceIdentifier, 19 19 }; 20 20 use std::sync::{ 21 - atomic::{AtomicU8, Ordering}, 22 21 Arc, 22 + atomic::{AtomicU8, Ordering}, 23 23 }; 24 - use uuid::{uuid, Uuid}; 24 + use uuid::{Uuid, uuid}; 25 25 26 26 pub mod setup { 27 27 use crate::device::protocol::{ProtocolIdentifier, ProtocolIdentifierFactory}; ··· 186 186 } else { 187 187 self.tx 188 188 }; 189 - Ok(vec![HardwareWriteCmd::new( 190 - &[MONSTERPUB_PROTOCOL_UUID], 191 - tx, 192 - data, 193 - tx == Endpoint::TxMode, 194 - ) 195 - .into()]) 189 + Ok(vec![ 190 + HardwareWriteCmd::new( 191 + &[MONSTERPUB_PROTOCOL_UUID], 192 + tx, 193 + data, 194 + tx == Endpoint::TxMode, 195 + ) 196 + .into(), 197 + ]) 196 198 } 197 199 } 198 200
+7 -15
crates/buttplug_server/src/device/protocol_impl/motorbunny.rs
··· 16 16 17 17 use crate::device::{ 18 18 hardware::{HardwareCommand, HardwareWriteCmd}, 19 - protocol::{generic_protocol_setup, ProtocolHandler}, 19 + protocol::{ProtocolHandler, generic_protocol_setup}, 20 20 }; 21 21 use buttplug_core::errors::ButtplugDeviceError; 22 22 use buttplug_server_device_config::Endpoint; ··· 45 45 command_vec.append(&mut vibe_commands); 46 46 command_vec.append(&mut vec![crc, 0xec]); 47 47 } 48 - Ok(vec![HardwareWriteCmd::new( 49 - &[feature_id], 50 - Endpoint::Tx, 51 - command_vec, 52 - false, 53 - ) 54 - .into()]) 48 + Ok(vec![ 49 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, command_vec, false).into(), 50 + ]) 55 51 } 56 52 57 53 fn handle_rotation_with_direction_cmd( ··· 73 69 command_vec.append(&mut rotate_command); 74 70 command_vec.append(&mut vec![crc, 0xec]); 75 71 } 76 - Ok(vec![HardwareWriteCmd::new( 77 - &[feature_id], 78 - Endpoint::Tx, 79 - command_vec, 80 - false, 81 - ) 82 - .into()]) 72 + Ok(vec![ 73 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, command_vec, false).into(), 74 + ]) 83 75 } 84 76 }
+19 -16
crates/buttplug_server/src/device/protocol_impl/mysteryvibe.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 - ProtocolInitializer, ProtocolKeepaliveStrategy, 13 + ProtocolInitializer, 14 + ProtocolKeepaliveStrategy, 15 + generic_protocol_initializer_setup, 15 16 }, 16 17 }; 17 18 use async_trait::async_trait; 18 19 use buttplug_core::errors::ButtplugDeviceError; 19 20 use buttplug_server_device_config::Endpoint; 20 21 use buttplug_server_device_config::{ 22 + ProtocolCommunicationSpecifier, 21 23 ServerDeviceDefinition, 22 - ProtocolCommunicationSpecifier, 23 24 UserDeviceIdentifier, 24 25 }; 25 26 use std::{ 26 27 sync::{ 27 - atomic::{AtomicU8, Ordering}, 28 28 Arc, 29 + atomic::{AtomicU8, Ordering}, 29 30 }, 30 31 time::Duration, 31 32 }; 32 - use uuid::{uuid, Uuid}; 33 + use uuid::{Uuid, uuid}; 33 34 34 35 generic_protocol_initializer_setup!(MysteryVibe, "mysteryvibe"); 35 36 ··· 97 98 speed: u32, 98 99 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 99 100 self.speeds[feature_index as usize].store(speed as u8, Ordering::Relaxed); 100 - Ok(vec![HardwareWriteCmd::new( 101 - &[MYSTERYVIBE_PROTOCOL_UUID], 102 - Endpoint::TxVibrate, 103 - self 104 - .speeds 105 - .iter() 106 - .map(|x| x.load(Ordering::Relaxed)) 107 - .collect(), 108 - false, 109 - ) 110 - .into()]) 101 + Ok(vec![ 102 + HardwareWriteCmd::new( 103 + &[MYSTERYVIBE_PROTOCOL_UUID], 104 + Endpoint::TxVibrate, 105 + self 106 + .speeds 107 + .iter() 108 + .map(|x| x.load(Ordering::Relaxed)) 109 + .collect(), 110 + false, 111 + ) 112 + .into(), 113 + ]) 111 114 } 112 115 }
+3 -3
crates/buttplug_server/src/device/protocol_impl/mysteryvibe_v2.rs
··· 9 9 use crate::device::{ 10 10 hardware::{Hardware, HardwareWriteCmd}, 11 11 protocol::{ 12 - generic_protocol_initializer_setup, 13 12 ProtocolHandler, 14 13 ProtocolIdentifier, 15 14 ProtocolInitializer, 15 + generic_protocol_initializer_setup, 16 16 }, 17 17 }; 18 18 use async_trait::async_trait; 19 19 use buttplug_core::errors::ButtplugDeviceError; 20 20 use buttplug_server_device_config::Endpoint; 21 21 use buttplug_server_device_config::{ 22 - ServerDeviceDefinition, 23 22 ProtocolCommunicationSpecifier, 23 + ServerDeviceDefinition, 24 24 UserDeviceIdentifier, 25 25 }; 26 26 use std::sync::Arc; 27 - use uuid::{uuid, Uuid}; 27 + use uuid::{Uuid, uuid}; 28 28 29 29 generic_protocol_initializer_setup!(MysteryVibeV2, "mysteryvibe-v2"); 30 30
+10 -8
crates/buttplug_server/src/device/protocol_impl/nextlevelracing.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - format!("M{feature_index}{speed}\r").into_bytes(), 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + format!("M{feature_index}{speed}\r").into_bytes(), 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+26 -22
crates/buttplug_server/src/device/protocol_impl/nexus_revo.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xaa, 0x01, 0x01, 0x00, 0x01, speed as u8], 33 - true, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xaa, 0x01, 0x01, 0x00, 0x01, speed as u8], 34 + true, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 38 40 fn handle_rotation_with_direction_cmd( ··· 42 44 speed: u32, 43 45 clockwise: bool, 44 46 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 45 - Ok(vec![HardwareWriteCmd::new( 46 - &[feature_id], 47 - Endpoint::Tx, 48 - vec![ 49 - 0xaa, 50 - 0x01, 51 - 0x02, 52 - 0x00, 53 - speed as u8 + if speed != 0 && clockwise { 2 } else { 0 }, 54 - 0x00, 55 - ], 56 - true, 57 - ) 58 - .into()]) 47 + Ok(vec![ 48 + HardwareWriteCmd::new( 49 + &[feature_id], 50 + Endpoint::Tx, 51 + vec![ 52 + 0xaa, 53 + 0x01, 54 + 0x02, 55 + 0x00, 56 + speed as u8 + if speed != 0 && clockwise { 2 } else { 0 }, 57 + 0x00, 58 + ], 59 + true, 60 + ) 61 + .into(), 62 + ]) 59 63 } 60 64 }
+10 -15
crates/buttplug_server/src/device/protocol_impl/nintendo_joycon.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 - use buttplug_core::{errors::ButtplugDeviceError, util::{self, async_manager}}; 18 + use buttplug_core::{ 19 + errors::ButtplugDeviceError, 20 + util::{self, async_manager}, 21 + }; 19 22 use buttplug_server_device_config::{ 20 23 Endpoint, 21 - ServerDeviceDefinition, 22 24 ProtocolCommunicationSpecifier, 25 + ServerDeviceDefinition, 23 26 UserDeviceIdentifier, 24 27 }; 25 28 use std::{ 26 29 sync::{ 27 - atomic::{AtomicBool, AtomicU16, Ordering}, 28 30 Arc, 31 + atomic::{AtomicBool, AtomicU16, Ordering}, 29 32 }, 30 33 time::Duration, 31 34 }; 32 35 use tokio::sync::Notify; 33 - use uuid::{uuid, Uuid}; 36 + use uuid::{Uuid, uuid}; 34 37 35 38 const NINTENDO_JOYCON_PROTOCOL_UUID: Uuid = uuid!("de9cce17-abb7-4ad5-9754-f1872733c197"); 36 39 ··· 204 207 205 208 let hf_amp: u16 = { 206 209 let hf_amp: u16 = encoded_hex_amp as u16 * 2; 207 - if hf_amp > 0x01FC { 208 - 0x01FC 209 - } else { 210 - hf_amp 211 - } 210 + if hf_amp > 0x01FC { 0x01FC } else { hf_amp } 212 211 }; // encoded_hex_amp<<1; 213 212 let lf_amp: u8 = { 214 213 let lf_amp = encoded_hex_amp / 2 + 64; 215 - if lf_amp > 0x7F { 216 - 0x7F 217 - } else { 218 - lf_amp 219 - } 214 + if lf_amp > 0x7F { 0x7F } else { lf_amp } 220 215 }; // (encoded_hex_amp>>1)+0x40; 221 216 222 217 let mut buf = [0u8; 4];
+6 -10
crates/buttplug_server/src/device/protocol_impl/nobra.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::sync::Arc; 26 - use uuid::{uuid, Uuid}; 26 + use uuid::{Uuid, uuid}; 27 27 28 28 const NOBRA_PROTOCOL_UUID: Uuid = uuid!("166e7d2b-b9ed-4769-aaaf-66127e4e14eb"); 29 29 generic_protocol_initializer_setup!(Nobra, "nobra"); ··· 61 61 speed: u32, 62 62 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 63 63 let output_speed = if speed == 0 { 0x70 } else { 0x60 + speed }; 64 - Ok(vec![HardwareWriteCmd::new( 65 - &[feature_id], 66 - Endpoint::Tx, 67 - vec![output_speed as u8], 68 - false, 69 - ) 70 - .into()]) 64 + Ok(vec![ 65 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![output_speed as u8], false).into(), 66 + ]) 71 67 } 72 68 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/omobo.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0xa1, 0x04, 0x04, 0x01, speed as u8, 0xff, 0x55], 33 - true, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![0xa1, 0x04, 0x04, 0x01, speed as u8, 0xff, 0x55], 34 + true, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+3 -3
crates/buttplug_server/src/device/protocol_impl/patoo.rs
··· 8 8 use buttplug_core::errors::ButtplugDeviceError; 9 9 use buttplug_server_device_config::Endpoint; 10 10 use buttplug_server_device_config::{ 11 - ServerDeviceDefinition, 12 11 ProtocolCommunicationSpecifier, 12 + ServerDeviceDefinition, 13 13 UserDeviceIdentifier, 14 14 }; 15 15 ··· 19 19 }; 20 20 use async_trait::async_trait; 21 21 use std::sync::{ 22 - atomic::{AtomicU8, Ordering}, 23 22 Arc, 23 + atomic::{AtomicU8, Ordering}, 24 24 }; 25 - use uuid::{uuid, Uuid}; 25 + use uuid::{Uuid, uuid}; 26 26 27 27 pub mod setup { 28 28 use crate::device::protocol::{ProtocolIdentifier, ProtocolIdentifierFactory};
+10 -8
crates/buttplug_server/src/device/protocol_impl/picobong.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 29 let mode: u8 = if speed == 0 { 0xff } else { 0x01 }; 30 - Ok(vec![HardwareWriteCmd::new( 31 - &[feature_id], 32 - Endpoint::Tx, 33 - [0x01, mode, speed as u8].to_vec(), 34 - false, 35 - ) 36 - .into()]) 30 + Ok(vec![ 31 + HardwareWriteCmd::new( 32 + &[feature_id], 33 + Endpoint::Tx, 34 + [0x01, mode, speed as u8].to_vec(), 35 + false, 36 + ) 37 + .into(), 38 + ]) 37 39 } 38 40 } 39 41
+4 -8
crates/buttplug_server/src/device/protocol_impl/pink_punch.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![0x09, speed as u8], 33 - true, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![0x09, speed as u8], true).into(), 31 + ]) 36 32 } 37 33 }
+4 -8
crates/buttplug_server/src/device/protocol_impl/prettylove.rs
··· 13 13 use buttplug_core::errors::ButtplugDeviceError; 14 14 use buttplug_server_device_config::Endpoint; 15 15 use buttplug_server_device_config::{ 16 - ServerDeviceDefinition, 17 16 ProtocolCommunicationSpecifier, 17 + ServerDeviceDefinition, 18 18 UserDeviceIdentifier, 19 19 }; 20 20 use std::sync::Arc; ··· 81 81 feature_id: Uuid, 82 82 speed: u32, 83 83 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 84 - Ok(vec![HardwareWriteCmd::new( 85 - &[feature_id], 86 - Endpoint::Tx, 87 - vec![0x00u8, speed as u8], 88 - true, 89 - ) 90 - .into()]) 84 + Ok(vec![ 85 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, vec![0x00u8, speed as u8], true).into(), 86 + ]) 91 87 } 92 88 }
+1 -1
crates/buttplug_server/src/device/protocol_impl/raw_protocol.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use crate::device::protocol::{generic_protocol_setup, ProtocolHandler}; 8 + use crate::device::protocol::{ProtocolHandler, generic_protocol_setup}; 9 9 10 10 generic_protocol_setup!(RawProtocol, "raw"); 11 11
+10 -8
crates/buttplug_server/src/device/protocol_impl/realov.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - [0xc5u8, 0x55, speed as u8, 0xaa].to_vec(), 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + [0xc5u8, 0x55, speed as u8, 0xaa].to_vec(), 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 } 38 40
+45 -41
crates/buttplug_server/src/device/protocol_impl/sakuraneko.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![ 33 - 0xa1, 34 - 0x08, 35 - 0x01, 36 - 0x00, 37 - 0x00, 38 - 0x00, 39 - 0x64, 40 - speed as u8, 41 - 0x00, 42 - 0x64, 43 - 0xdf, 44 - 0x55, 45 - ], 46 - false, 47 - ) 48 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![ 34 + 0xa1, 35 + 0x08, 36 + 0x01, 37 + 0x00, 38 + 0x00, 39 + 0x00, 40 + 0x64, 41 + speed as u8, 42 + 0x00, 43 + 0x64, 44 + 0xdf, 45 + 0x55, 46 + ], 47 + false, 48 + ) 49 + .into(), 50 + ]) 49 51 } 50 52 51 53 fn handle_output_rotate_cmd( ··· 54 56 feature_id: Uuid, 55 57 speed: u32, 56 58 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 57 - Ok(vec![HardwareWriteCmd::new( 58 - &[feature_id], 59 - Endpoint::Tx, 60 - vec![ 61 - 0xa2, 62 - 0x08, 63 - 0x01, 64 - 0x00, 65 - 0x00, 66 - 0x00, 67 - 0x64, 68 - speed as u8, 69 - 0x00, 70 - 0x32, 71 - 0xdf, 72 - 0x55, 73 - ], 74 - false, 75 - ) 76 - .into()]) 59 + Ok(vec![ 60 + HardwareWriteCmd::new( 61 + &[feature_id], 62 + Endpoint::Tx, 63 + vec![ 64 + 0xa2, 65 + 0x08, 66 + 0x01, 67 + 0x00, 68 + 0x00, 69 + 0x00, 70 + 0x64, 71 + speed as u8, 72 + 0x00, 73 + 0x32, 74 + 0xdf, 75 + 0x55, 76 + ], 77 + false, 78 + ) 79 + .into(), 80 + ]) 77 81 } 78 82 }
+6 -10
crates/buttplug_server/src/device/protocol_impl/satisfyer.rs
··· 13 13 use buttplug_core::errors::ButtplugDeviceError; 14 14 use buttplug_server_device_config::Endpoint; 15 15 use buttplug_server_device_config::{ 16 - ServerDeviceDefinition, 17 16 ProtocolCommunicationSpecifier, 17 + ServerDeviceDefinition, 18 18 UserDeviceIdentifier, 19 19 }; 20 20 use std::{ 21 21 sync::{ 22 - atomic::{AtomicU8, Ordering}, 23 22 Arc, 23 + atomic::{AtomicU8, Ordering}, 24 24 }, 25 25 time::Duration, 26 26 }; 27 - use uuid::{uuid, Uuid}; 27 + use uuid::{Uuid, uuid}; 28 28 29 29 const SATISFYER_PROTOCOL_UUID: Uuid = uuid!("79a0ed0d-f392-4c48-967e-f4467438c344"); 30 30 ··· 169 169 self.last_command[feature_index as usize].store(speed as u8, Ordering::Relaxed); 170 170 let data = form_command(self.feature_count, self.last_command.clone()); 171 171 172 - Ok(vec![HardwareWriteCmd::new( 173 - &[SATISFYER_PROTOCOL_UUID], 174 - Endpoint::Tx, 175 - data, 176 - false, 177 - ) 178 - .into()]) 172 + Ok(vec![ 173 + HardwareWriteCmd::new(&[SATISFYER_PROTOCOL_UUID], Endpoint::Tx, data, false).into(), 174 + ]) 179 175 } 180 176 }
+22 -20
crates/buttplug_server/src/device/protocol_impl/sensee.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![ 33 - 0x55, 34 - 0xaa, 35 - 0xf0, 36 - 0x01, 37 - 0x01, 38 - 0x0b, 39 - 0x65, 40 - 0xf7, 41 - 0x01, 42 - 0x01, 43 - speed as u8, 44 - ], 45 - false, 46 - ) 47 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![ 34 + 0x55, 35 + 0xaa, 36 + 0xf0, 37 + 0x01, 38 + 0x01, 39 + 0x0b, 40 + 0x65, 41 + 0xf7, 42 + 0x01, 43 + 0x01, 44 + speed as u8, 45 + ], 46 + false, 47 + ) 48 + .into(), 49 + ]) 48 50 } 49 51 }
+41 -37
crates/buttplug_server/src/device/protocol_impl/sensee_capsule.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - vec![ 33 - 0x55, 34 - 0xaa, 35 - 0xf0, 36 - 0x01, 37 - 0x00, 38 - 0x12, 39 - 0x66, 40 - 0xf9, 41 - 0xf0 | speed as u8, 42 - ], 43 - false, 44 - ) 45 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + vec![ 34 + 0x55, 35 + 0xaa, 36 + 0xf0, 37 + 0x01, 38 + 0x00, 39 + 0x12, 40 + 0x66, 41 + 0xf9, 42 + 0xf0 | speed as u8, 43 + ], 44 + false, 45 + ) 46 + .into(), 47 + ]) 46 48 } 47 49 48 50 fn handle_output_constrict_cmd( ··· 51 53 feature_id: Uuid, 52 54 level: u32, 53 55 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 54 - Ok(vec![HardwareWriteCmd::new( 55 - &[feature_id], 56 - Endpoint::Tx, 57 - vec![ 58 - 0x55, 59 - 0xaa, 60 - 0xf0, 61 - 0x01, 62 - 0x00, 63 - 0x11, 64 - 0x66, 65 - 0xf2, 66 - 0xf0 | level as u8, 67 - 0x00, 68 - 0x00, 69 - ], 70 - false, 71 - ) 72 - .into()]) 56 + Ok(vec![ 57 + HardwareWriteCmd::new( 58 + &[feature_id], 59 + Endpoint::Tx, 60 + vec![ 61 + 0x55, 62 + 0xaa, 63 + 0xf0, 64 + 0x01, 65 + 0x00, 66 + 0x11, 67 + 0x66, 68 + 0xf2, 69 + 0xf0 | level as u8, 70 + 0x00, 71 + 0x00, 72 + ], 73 + false, 74 + ) 75 + .into(), 76 + ]) 73 77 } 74 78 }
+17 -15
crates/buttplug_server/src/device/protocol_impl/sensee_v2.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use buttplug_core::{ 9 - errors::ButtplugDeviceError, 10 - message::OutputType, 11 - }; 8 + use buttplug_core::{errors::ButtplugDeviceError, message::OutputType}; 12 9 use buttplug_server_device_config::{ 13 - ServerDeviceDefinition, Endpoint, ProtocolCommunicationSpecifier, UserDeviceIdentifier 10 + Endpoint, 11 + ProtocolCommunicationSpecifier, 12 + ServerDeviceDefinition, 13 + UserDeviceIdentifier, 14 14 }; 15 15 16 16 use crate::device::{ 17 17 hardware::{Hardware, HardwareCommand, HardwareReadCmd, HardwareWriteCmd}, 18 18 protocol::{ 19 - generic_protocol_initializer_setup, 20 19 ProtocolHandler, 21 20 ProtocolIdentifier, 22 21 ProtocolInitializer, 22 + generic_protocol_initializer_setup, 23 23 }, 24 24 }; 25 25 use async_trait::async_trait; 26 26 use std::{ 27 27 collections::HashMap, 28 28 sync::{ 29 - atomic::{AtomicU8, Ordering}, 30 29 Arc, 30 + atomic::{AtomicU8, Ordering}, 31 31 }, 32 32 }; 33 - use uuid::{uuid, Uuid}; 33 + use uuid::{Uuid, uuid}; 34 34 35 35 generic_protocol_initializer_setup!(SenseeV2, "sensee-v2"); 36 36 ··· 150 150 data_add(1, &self.thrust_map); 151 151 data_add(2, &self.suck_map); 152 152 153 - Ok(vec![HardwareWriteCmd::new( 154 - &[SENSEE_V2_PROTOCOL_UUID], 155 - Endpoint::Tx, 156 - make_cmd(self.device_type, 0xf1, data), 157 - false, 158 - ) 159 - .into()]) 153 + Ok(vec![ 154 + HardwareWriteCmd::new( 155 + &[SENSEE_V2_PROTOCOL_UUID], 156 + Endpoint::Tx, 157 + make_cmd(self.device_type, 0xf1, data), 158 + false, 159 + ) 160 + .into(), 161 + ]) 160 162 } 161 163 } 162 164
+11 -9
crates/buttplug_server/src/device/protocol_impl/serveu.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; 16 16 use std::sync::{ 17 - atomic::{AtomicU8, Ordering}, 18 17 Arc, 18 + atomic::{AtomicU8, Ordering}, 19 19 }; 20 20 21 21 generic_protocol_setup!(ServeU, "serveu"); ··· 54 54 0xFA 55 55 }; 56 56 57 - Ok(vec![HardwareWriteCmd::new( 58 - &[feature_id], 59 - Endpoint::Tx, 60 - vec![0x01, goal_pos, speed], 61 - false, 62 - ) 63 - .into()]) 57 + Ok(vec![ 58 + HardwareWriteCmd::new( 59 + &[feature_id], 60 + Endpoint::Tx, 61 + vec![0x01, goal_pos, speed], 62 + false, 63 + ) 64 + .into(), 65 + ]) 64 66 } 65 67 }
+11 -9
crates/buttplug_server/src/device/protocol_impl/sexverse_lg389.rs
··· 7 7 8 8 use std::sync::atomic::{AtomicU8, Ordering}; 9 9 10 - use uuid::{uuid, Uuid}; 10 + use uuid::{Uuid, uuid}; 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 32 32 let osc = self.osc_speed.load(Ordering::Relaxed); 33 33 let range = if osc == 0 { 0 } else { 4u8 }; // Full range 34 34 let anchor = if osc == 0 { 0 } else { 1u8 }; // Anchor to base 35 - Ok(vec![HardwareWriteCmd::new( 36 - &[SEXVERSE_PROTOCOL_UUID], 37 - Endpoint::Tx, 38 - vec![0xaa, 0x05, vibe, 0x14, anchor, 0x00, range, 0x00, osc, 0x00], 39 - true, 40 - ) 41 - .into()]) 35 + Ok(vec![ 36 + HardwareWriteCmd::new( 37 + &[SEXVERSE_PROTOCOL_UUID], 38 + Endpoint::Tx, 39 + vec![0xaa, 0x05, vibe, 0x14, anchor, 0x00, range, 0x00, osc, 0x00], 40 + true, 41 + ) 42 + .into(), 43 + ]) 42 44 } 43 45 } 44 46
+2 -2
crates/buttplug_server/src/device/protocol_impl/svakom/mod.rs
··· 21 21 22 22 use buttplug_core::errors::ButtplugDeviceError; 23 23 use buttplug_server_device_config::{ 24 - ServerDeviceDefinition, 25 24 ProtocolCommunicationSpecifier, 25 + ServerDeviceDefinition, 26 26 UserDeviceIdentifier, 27 27 }; 28 28 29 29 use crate::device::{ 30 30 hardware::Hardware, 31 31 protocol::{ 32 - generic_protocol_initializer_setup, 33 32 ProtocolHandler, 34 33 ProtocolIdentifier, 35 34 ProtocolInitializer, 35 + generic_protocol_initializer_setup, 36 36 }, 37 37 }; 38 38 use async_trait::async_trait;
+10 -8
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_alex.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 30 30 feature_id: Uuid, 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 - Ok(vec![HardwareWriteCmd::new( 34 - &[feature_id], 35 - Endpoint::Tx, 36 - [18, 1, 3, 0, if speed == 0 { 0xFF } else { speed as u8 }, 0].to_vec(), 37 - false, 38 - ) 39 - .into()]) 33 + Ok(vec![ 34 + HardwareWriteCmd::new( 35 + &[feature_id], 36 + Endpoint::Tx, 37 + [18, 1, 3, 0, if speed == 0 { 0xFF } else { speed as u8 }, 0].to_vec(), 38 + false, 39 + ) 40 + .into(), 41 + ]) 40 42 } 41 43 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_alex_v2.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 30 30 feature_id: Uuid, 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 - Ok(vec![HardwareWriteCmd::new( 34 - &[feature_id], 35 - Endpoint::Tx, 36 - [0x55, 3, 3, 0, speed as u8, speed as u8 + 5].to_vec(), 37 - false, 38 - ) 39 - .into()]) 33 + Ok(vec![ 34 + HardwareWriteCmd::new( 35 + &[feature_id], 36 + Endpoint::Tx, 37 + [0x55, 3, 3, 0, speed as u8, speed as u8 + 5].to_vec(), 38 + false, 39 + ) 40 + .into(), 41 + ]) 40 42 } 41 43 }
+18 -17
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_avaneo.rs
··· 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 - 17 16 18 17 generic_protocol_setup!(SvakomAvaNeo, "svakom-avaneo"); 19 18 ··· 26 25 feature_id: Uuid, 27 26 speed: u32, 28 27 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - [ 33 - 0x55, 34 - 0x03, 35 - 0x00, 36 - 0x00, 37 - if speed == 0 { 0x00 } else { 0x01 }, 38 - speed as u8, 39 - ] 40 - .to_vec(), 41 - false, 42 - ) 43 - .into()]) 28 + Ok(vec![ 29 + HardwareWriteCmd::new( 30 + &[feature_id], 31 + Endpoint::Tx, 32 + [ 33 + 0x55, 34 + 0x03, 35 + 0x00, 36 + 0x00, 37 + if speed == 0 { 0x00 } else { 0x01 }, 38 + speed as u8, 39 + ] 40 + .to_vec(), 41 + false, 42 + ) 43 + .into(), 44 + ]) 44 45 } 45 46 } 46 47
+35 -31
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_barnard.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; ··· 28 28 feature_id: uuid::Uuid, 29 29 speed: u32, 30 30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[feature_id], 33 - Endpoint::Tx, 34 - [ 35 - 0x55, 36 - 0x03, 37 - 0x00, 38 - 0x00, 39 - speed as u8, 40 - if speed == 0 { 0x00 } else { 0x01 }, 41 - ] 42 - .to_vec(), 43 - false, 44 - ) 45 - .into()]) 31 + Ok(vec![ 32 + HardwareWriteCmd::new( 33 + &[feature_id], 34 + Endpoint::Tx, 35 + [ 36 + 0x55, 37 + 0x03, 38 + 0x00, 39 + 0x00, 40 + speed as u8, 41 + if speed == 0 { 0x00 } else { 0x01 }, 42 + ] 43 + .to_vec(), 44 + false, 45 + ) 46 + .into(), 47 + ]) 46 48 } 47 49 48 50 fn handle_output_oscillate_cmd( ··· 51 53 feature_id: uuid::Uuid, 52 54 speed: u32, 53 55 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 54 - Ok(vec![HardwareWriteCmd::new( 55 - &[feature_id], 56 - Endpoint::Tx, 57 - [ 58 - 0x55, 59 - 0x08, 60 - 0x00, 61 - 0x00, 62 - speed as u8, 63 - if speed == 0 { 0x00 } else { 0xff }, 64 - ] 65 - .to_vec(), 66 - false, 67 - ) 68 - .into()]) 56 + Ok(vec![ 57 + HardwareWriteCmd::new( 58 + &[feature_id], 59 + Endpoint::Tx, 60 + [ 61 + 0x55, 62 + 0x08, 63 + 0x00, 64 + 0x00, 65 + speed as u8, 66 + if speed == 0 { 0x00 } else { 0xff }, 67 + ] 68 + .to_vec(), 69 + false, 70 + ) 71 + .into(), 72 + ]) 69 73 } 70 74 }
+18 -16
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_barney.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; ··· 28 28 feature_id: uuid::Uuid, 29 29 speed: u32, 30 30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[feature_id], 33 - Endpoint::Tx, 34 - [ 35 - 0x55, 36 - 0x03, 37 - feature_index as u8 + 1, 38 - 0x00, 39 - if speed == 0 { 0x00 } else { 0x03 }, 40 - speed as u8, 41 - ] 42 - .to_vec(), 43 - false, 44 - ) 45 - .into()]) 31 + Ok(vec![ 32 + HardwareWriteCmd::new( 33 + &[feature_id], 34 + Endpoint::Tx, 35 + [ 36 + 0x55, 37 + 0x03, 38 + feature_index as u8 + 1, 39 + 0x00, 40 + if speed == 0 { 0x00 } else { 0x03 }, 41 + speed as u8, 42 + ] 43 + .to_vec(), 44 + false, 45 + ) 46 + .into(), 47 + ]) 46 48 } 47 49 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_dice.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 30 30 feature_id: Uuid, 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 - Ok(vec![HardwareWriteCmd::new( 34 - &[feature_id], 35 - Endpoint::Tx, 36 - [0x55, 0x04, 0x00, 0x00, 01, speed as u8, 0xaa].to_vec(), 37 - false, 38 - ) 39 - .into()]) 33 + Ok(vec![ 34 + HardwareWriteCmd::new( 35 + &[feature_id], 36 + Endpoint::Tx, 37 + [0x55, 0x04, 0x00, 0x00, 01, speed as u8, 0xaa].to_vec(), 38 + false, 39 + ) 40 + .into(), 41 + ]) 40 42 } 41 43 } 42 44
+23 -22
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_dt250a.rs
··· 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 - 17 16 18 17 generic_protocol_setup!(SvakomDT250A, "svakom-dt250a"); 19 18 ··· 31 30 feature_id: Uuid, 32 31 speed: u32, 33 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 34 - Ok(vec![HardwareWriteCmd::new( 35 - &[feature_id], 36 - Endpoint::Tx, 37 - [ 38 - 0x55, 39 - mode, 40 - 0x00, 41 - 0x00, 42 - if speed == 0 { 0x00 } else { 0x01 }, 43 - speed as u8, 44 - ] 45 - .to_vec(), 46 - false, 47 - ) 48 - .into()]) 33 + Ok(vec![ 34 + HardwareWriteCmd::new( 35 + &[feature_id], 36 + Endpoint::Tx, 37 + [ 38 + 0x55, 39 + mode, 40 + 0x00, 41 + 0x00, 42 + if speed == 0 { 0x00 } else { 0x01 }, 43 + speed as u8, 44 + ] 45 + .to_vec(), 46 + false, 47 + ) 48 + .into(), 49 + ]) 49 50 } 50 51 } 51 52 ··· 60 61 } 61 62 62 63 fn handle_output_constrict_cmd( 63 - &self, 64 - _feature_index: u32, 65 - feature_id: uuid::Uuid, 66 - level: u32, 67 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 64 + &self, 65 + _feature_index: u32, 66 + feature_id: uuid::Uuid, 67 + level: u32, 68 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 68 69 self.form_hardware_command(0x08, feature_id, level) 69 70 } 70 71 }
+11 -9
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_iker.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; 14 - use std::sync::atomic::{AtomicU8, Ordering}; 15 14 use std::sync::Arc; 15 + use std::sync::atomic::{AtomicU8, Ordering}; 16 16 17 17 generic_protocol_setup!(SvakomIker, "svakom-iker"); 18 18 ··· 36 36 let vibe0 = self.last_speeds[0].load(Ordering::Relaxed); 37 37 let vibe1 = self.last_speeds[1].load(Ordering::Relaxed); 38 38 if vibe0 == 0 && vibe1 == 0 { 39 - Ok(vec![HardwareWriteCmd::new( 40 - &[feature_id], 41 - Endpoint::Tx, 42 - [0x55, 0x07, 0x00, 0x00, 0x00, 0x00].to_vec(), 43 - false, 44 - ) 45 - .into()]) 39 + Ok(vec![ 40 + HardwareWriteCmd::new( 41 + &[feature_id], 42 + Endpoint::Tx, 43 + [0x55, 0x07, 0x00, 0x00, 0x00, 0x00].to_vec(), 44 + false, 45 + ) 46 + .into(), 47 + ]) 46 48 } else { 47 49 let mut msgs = vec![]; 48 50 msgs.push(
+35 -31
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_jordan.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; ··· 28 28 feature_id: uuid::Uuid, 29 29 speed: u32, 30 30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[feature_id], 33 - Endpoint::Tx, 34 - vec![ 35 - 0x55, 36 - 0x03, 37 - 0x00, 38 - 0x00, 39 - if speed == 0 { 0x00 } else { 0x01 }, 40 - speed as u8, 41 - 0x00, 42 - ], 43 - false, 44 - ) 45 - .into()]) 31 + Ok(vec![ 32 + HardwareWriteCmd::new( 33 + &[feature_id], 34 + Endpoint::Tx, 35 + vec![ 36 + 0x55, 37 + 0x03, 38 + 0x00, 39 + 0x00, 40 + if speed == 0 { 0x00 } else { 0x01 }, 41 + speed as u8, 42 + 0x00, 43 + ], 44 + false, 45 + ) 46 + .into(), 47 + ]) 46 48 } 47 49 48 50 fn handle_output_oscillate_cmd( ··· 51 53 feature_id: uuid::Uuid, 52 54 speed: u32, 53 55 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 54 - Ok(vec![HardwareWriteCmd::new( 55 - &[feature_id], 56 - Endpoint::Tx, 57 - vec![ 58 - 0x55, 59 - 0x08, 60 - 0x00, 61 - 0x00, 62 - if speed == 0 { 0x00 } else { 0x01 }, 63 - speed as u8, 64 - 0x00, 65 - ], 66 - false, 67 - ) 68 - .into()]) 56 + Ok(vec![ 57 + HardwareWriteCmd::new( 58 + &[feature_id], 59 + Endpoint::Tx, 60 + vec![ 61 + 0x55, 62 + 0x08, 63 + 0x00, 64 + 0x00, 65 + if speed == 0 { 0x00 } else { 0x01 }, 66 + speed as u8, 67 + 0x00, 68 + ], 69 + false, 70 + ) 71 + .into(), 72 + ]) 69 73 } 70 74 }
+18 -16
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_pulse.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; ··· 28 28 feature_id: uuid::Uuid, 29 29 speed: u32, 30 30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[feature_id], 33 - Endpoint::Tx, 34 - [ 35 - 0x55, 36 - 0x03, 37 - 0x03, 38 - 0x00, 39 - if speed == 0 { 0x00 } else { 0x01 }, 40 - speed as u8 + 1, 41 - ] 42 - .to_vec(), 43 - false, 44 - ) 45 - .into()]) 31 + Ok(vec![ 32 + HardwareWriteCmd::new( 33 + &[feature_id], 34 + Endpoint::Tx, 35 + [ 36 + 0x55, 37 + 0x03, 38 + 0x03, 39 + 0x00, 40 + if speed == 0 { 0x00 } else { 0x01 }, 41 + speed as u8 + 1, 42 + ] 43 + .to_vec(), 44 + false, 45 + ) 46 + .into(), 47 + ]) 46 48 } 47 49 }
+36 -30
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_sam.rs
··· 9 9 use crate::device::{ 10 10 hardware::{Hardware, HardwareCommand, HardwareSubscribeCmd, HardwareWriteCmd}, 11 11 protocol::{ 12 - generic_protocol_initializer_setup, 13 12 ProtocolHandler, 14 13 ProtocolIdentifier, 15 14 ProtocolInitializer, 15 + generic_protocol_initializer_setup, 16 16 }, 17 17 }; 18 18 use async_trait::async_trait; 19 19 use buttplug_core::errors::ButtplugDeviceError; 20 20 use buttplug_server_device_config::Endpoint; 21 21 use buttplug_server_device_config::{ 22 - ServerDeviceDefinition, 23 22 ProtocolCommunicationSpecifier, 23 + ServerDeviceDefinition, 24 24 UserDeviceIdentifier, 25 25 }; 26 26 use std::sync::Arc; 27 - use uuid::{uuid, Uuid}; 27 + use uuid::{Uuid, uuid}; 28 28 29 29 generic_protocol_initializer_setup!(SvakomSam, "svakom-sam"); 30 30 const SVAKOM_SAM_PROTOCOL_UUID: Uuid = uuid!("e39a6b4a-230a-4669-be94-68135f97f166"); ··· 48 48 let mut gen2 = hardware.endpoints().contains(&Endpoint::TxMode); 49 49 if !gen2 && hardware.endpoints().contains(&Endpoint::Firmware) { 50 50 gen2 = true; 51 - warn!("Svakom Sam model without speed control detected - This device will only vibrate at 1 speed"); 51 + warn!( 52 + "Svakom Sam model without speed control detected - This device will only vibrate at 1 speed" 53 + ); 52 54 } 53 55 54 56 Ok(Arc::new(SvakomSam::new(gen2))) ··· 77 79 speed: u32, 78 80 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 79 81 if feature_index == 0 { 80 - Ok(vec![HardwareWriteCmd::new( 81 - &[feature_id], 82 - Endpoint::Tx, 83 - if self.gen2 { 84 - [ 85 - 18, 86 - 1, 87 - 3, 88 - 0, 89 - if speed == 0 { 0x00 } else { 0x04 }, 90 - speed as u8, 91 - ] 92 - .to_vec() 93 - } else { 94 - [18, 1, 3, 0, 5, speed as u8].to_vec() 95 - }, 96 - false, 97 - ) 98 - .into()]) 82 + Ok(vec![ 83 + HardwareWriteCmd::new( 84 + &[feature_id], 85 + Endpoint::Tx, 86 + if self.gen2 { 87 + [ 88 + 18, 89 + 1, 90 + 3, 91 + 0, 92 + if speed == 0 { 0x00 } else { 0x04 }, 93 + speed as u8, 94 + ] 95 + .to_vec() 96 + } else { 97 + [18, 1, 3, 0, 5, speed as u8].to_vec() 98 + }, 99 + false, 100 + ) 101 + .into(), 102 + ]) 99 103 } else { 100 - Ok(vec![HardwareWriteCmd::new( 101 - &[feature_id], 102 - Endpoint::Tx, 103 - [18, 6, 1, speed as u8].to_vec(), 104 - false, 105 - ) 106 - .into()]) 104 + Ok(vec![ 105 + HardwareWriteCmd::new( 106 + &[feature_id], 107 + Endpoint::Tx, 108 + [18, 6, 1, speed as u8].to_vec(), 109 + false, 110 + ) 111 + .into(), 112 + ]) 107 113 } 108 114 } 109 115 }
+37 -33
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_sam2.rs
··· 7 7 8 8 use crate::device::{ 9 9 hardware::{HardwareCommand, HardwareWriteCmd}, 10 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 10 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 11 11 }; 12 12 use buttplug_core::errors::ButtplugDeviceError; 13 13 use buttplug_server_device_config::Endpoint; ··· 28 28 feature_id: uuid::Uuid, 29 29 speed: u32, 30 30 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 31 - Ok(vec![HardwareWriteCmd::new( 32 - &[feature_id], 33 - Endpoint::Tx, 34 - [ 35 - 0x55, 36 - 0x03, 37 - 0x00, 38 - 0x00, 39 - if speed == 0 { 0x00 } else { 0x05 }, 40 - speed as u8, 41 - 0x00, 42 - ] 43 - .to_vec(), 44 - true, 45 - ) 46 - .into()]) 31 + Ok(vec![ 32 + HardwareWriteCmd::new( 33 + &[feature_id], 34 + Endpoint::Tx, 35 + [ 36 + 0x55, 37 + 0x03, 38 + 0x00, 39 + 0x00, 40 + if speed == 0 { 0x00 } else { 0x05 }, 41 + speed as u8, 42 + 0x00, 43 + ] 44 + .to_vec(), 45 + true, 46 + ) 47 + .into(), 48 + ]) 47 49 } 48 50 49 51 fn handle_output_constrict_cmd( ··· 52 54 feature_id: uuid::Uuid, 53 55 level: u32, 54 56 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 55 - Ok(vec![HardwareWriteCmd::new( 56 - &[feature_id], 57 - Endpoint::Tx, 58 - [ 59 - 0x55, 60 - 0x09, 61 - 0x00, 62 - 0x00, 63 - if level == 0 { 0x00 } else { 0x01 }, 64 - level as u8, 65 - 0x00, 66 - ] 67 - .to_vec(), 68 - true, 69 - ) 70 - .into()]) 57 + Ok(vec![ 58 + HardwareWriteCmd::new( 59 + &[feature_id], 60 + Endpoint::Tx, 61 + [ 62 + 0x55, 63 + 0x09, 64 + 0x00, 65 + 0x00, 66 + if level == 0 { 0x00 } else { 0x01 }, 67 + level as u8, 68 + 0x00, 69 + ] 70 + .to_vec(), 71 + true, 72 + ) 73 + .into(), 74 + ]) 71 75 } 72 76 }
+15 -13
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_suitcase.rs
··· 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 - 17 16 18 17 generic_protocol_setup!(SvakomSuitcase, "svakom-suitcase"); 19 18 ··· 25 24 // implementation made no sense in terms of knowing which command addressed which index. Putting 26 25 // in a best effort here and we'll see if anyone complains. 27 26 fn handle_output_vibrate_cmd( 28 - &self, 29 - _feature_index: u32, 30 - feature_id: Uuid, 31 - speed: u32, 32 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 27 + &self, 28 + _feature_index: u32, 29 + feature_id: Uuid, 30 + speed: u32, 31 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 32 let scalar = speed; 34 33 let mut speed = (scalar % 10) as u8; 35 34 let mut intensity = if scalar == 0 { ··· 42 41 speed = 10; 43 42 intensity -= 1; 44 43 } 45 - Ok(vec![HardwareWriteCmd::new( 46 - &[feature_id], 47 - Endpoint::Tx, 48 - [0x55, 0x03, 0x00, 0x00, intensity, speed].to_vec(), 49 - false, 50 - ).into()]) 44 + Ok(vec![ 45 + HardwareWriteCmd::new( 46 + &[feature_id], 47 + Endpoint::Tx, 48 + [0x55, 0x03, 0x00, 0x00, intensity, speed].to_vec(), 49 + false, 50 + ) 51 + .into(), 52 + ]) 51 53 } 52 54 }
+12 -9
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_tarax.rs
··· 11 11 12 12 use crate::device::{ 13 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 - protocol::{generic_protocol_setup, ProtocolHandler}, 14 + protocol::{ProtocolHandler, generic_protocol_setup}, 15 15 }; 16 16 17 17 generic_protocol_setup!(SvakomTaraX, "svakom-tarax"); ··· 24 24 // implementation made no sense in terms of knowing which command addressed which index. Putting 25 25 // in a best effort here and we'll see if anyone complains. 26 26 fn handle_output_vibrate_cmd( 27 - &self, 28 - _feature_index: u32, 29 - feature_id: Uuid, 30 - speed: u32, 31 - ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 32 - Ok(vec!(HardwareWriteCmd::new( 33 - &[feature_id], 27 + &self, 28 + _feature_index: u32, 29 + feature_id: Uuid, 30 + speed: u32, 31 + ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 32 + Ok(vec![ 33 + HardwareWriteCmd::new( 34 + &[feature_id], 34 35 Endpoint::Tx, 35 36 [ 36 37 0x55, ··· 42 43 ] 43 44 .to_vec(), 44 45 false, 45 - ).into())) 46 + ) 47 + .into(), 48 + ]) 46 49 } 47 50 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v1.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 33 let multiplier: u8 = if speed == 0 { 0x00 } else { 0x01 }; 34 - Ok(vec![HardwareWriteCmd::new( 35 - &[feature_id], 36 - Endpoint::Tx, 37 - [0x55, 0x04, 0x03, 0x00, multiplier, speed as u8].to_vec(), 38 - false, 39 - ) 40 - .into()]) 34 + Ok(vec![ 35 + HardwareWriteCmd::new( 36 + &[feature_id], 37 + Endpoint::Tx, 38 + [0x55, 0x04, 0x03, 0x00, multiplier, speed as u8].to_vec(), 39 + false, 40 + ) 41 + .into(), 42 + ]) 41 43 } 42 44 }
+27 -23
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v2.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 33 if feature_index == 1 { 34 - Ok(vec![HardwareWriteCmd::new( 35 - &[feature_id], 36 - Endpoint::Tx, 37 - [0x55, 0x06, 0x01, 0x00, speed as u8, speed as u8].to_vec(), 38 - true, 39 - ) 40 - .into()]) 34 + Ok(vec![ 35 + HardwareWriteCmd::new( 36 + &[feature_id], 37 + Endpoint::Tx, 38 + [0x55, 0x06, 0x01, 0x00, speed as u8, speed as u8].to_vec(), 39 + true, 40 + ) 41 + .into(), 42 + ]) 41 43 } else { 42 - Ok(vec![HardwareWriteCmd::new( 43 - &[feature_id], 44 - Endpoint::Tx, 45 - [ 46 - 0x55, 47 - 0x03, 48 - 0x03, 49 - 0x00, 50 - if speed == 0 { 0x00 } else { 0x01 }, 51 - speed as u8, 52 - ] 53 - .to_vec(), 54 - true, 55 - ) 56 - .into()]) 44 + Ok(vec![ 45 + HardwareWriteCmd::new( 46 + &[feature_id], 47 + Endpoint::Tx, 48 + [ 49 + 0x55, 50 + 0x03, 51 + 0x03, 52 + 0x00, 53 + if speed == 0 { 0x00 } else { 0x01 }, 54 + speed as u8, 55 + ] 56 + .to_vec(), 57 + true, 58 + ) 59 + .into(), 60 + ]) 57 61 } 58 62 } 59 63 }
+27 -23
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v3.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 30 30 feature_id: Uuid, 31 31 speed: u32, 32 32 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 33 - Ok(vec![HardwareWriteCmd::new( 34 - &[feature_id], 35 - Endpoint::Tx, 36 - [ 37 - 0x55, 38 - if feature_index == 0 { 0x03 } else { 0x09 }, 39 - if feature_index == 0 { 0x03 } else { 0x00 }, 40 - 0x00, 41 - if speed == 0 { 0x00 } else { 0x01 }, 42 - speed as u8, 43 - ] 44 - .to_vec(), 45 - false, 46 - ) 47 - .into()]) 33 + Ok(vec![ 34 + HardwareWriteCmd::new( 35 + &[feature_id], 36 + Endpoint::Tx, 37 + [ 38 + 0x55, 39 + if feature_index == 0 { 0x03 } else { 0x09 }, 40 + if feature_index == 0 { 0x03 } else { 0x00 }, 41 + 0x00, 42 + if speed == 0 { 0x00 } else { 0x01 }, 43 + speed as u8, 44 + ] 45 + .to_vec(), 46 + false, 47 + ) 48 + .into(), 49 + ]) 48 50 } 49 51 50 52 fn handle_output_rotate_cmd( ··· 53 55 feature_id: Uuid, 54 56 speed: u32, 55 57 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 56 - Ok(vec![HardwareWriteCmd::new( 57 - &[feature_id], 58 - Endpoint::Tx, 59 - [0x55, 0x08, 0x00, 0x00, speed as u8, 0xff].to_vec(), 60 - false, 61 - ) 62 - .into()]) 58 + Ok(vec![ 59 + HardwareWriteCmd::new( 60 + &[feature_id], 61 + Endpoint::Tx, 62 + [0x55, 0x08, 0x00, 0x00, speed as u8, 0xff].to_vec(), 63 + false, 64 + ) 65 + .into(), 66 + ]) 63 67 } 64 68 }
+18 -16
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v4.rs
··· 8 8 use crate::device::protocol::ProtocolKeepaliveStrategy; 9 9 use crate::device::{ 10 10 hardware::{HardwareCommand, HardwareWriteCmd}, 11 - protocol::{generic_protocol_setup, ProtocolHandler}, 11 + protocol::{ProtocolHandler, generic_protocol_setup}, 12 12 }; 13 13 use buttplug_core::errors::ButtplugDeviceError; 14 14 use buttplug_server_device_config::Endpoint; ··· 29 29 feature_id: uuid::Uuid, 30 30 speed: u32, 31 31 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 32 - Ok(vec![HardwareWriteCmd::new( 33 - &[feature_id], 34 - Endpoint::Tx, 35 - [ 36 - 0x55, 37 - 0x03, 38 - feature_index as u8 + 1, 39 - 0x00, 40 - if speed == 0 { 0x00 } else { 0x03 }, 41 - speed as u8, 42 - ] 43 - .to_vec(), 44 - false, 45 - ) 46 - .into()]) 32 + Ok(vec![ 33 + HardwareWriteCmd::new( 34 + &[feature_id], 35 + Endpoint::Tx, 36 + [ 37 + 0x55, 38 + 0x03, 39 + feature_index as u8 + 1, 40 + 0x00, 41 + if speed == 0 { 0x00 } else { 0x03 }, 42 + speed as u8, 43 + ] 44 + .to_vec(), 45 + false, 46 + ) 47 + .into(), 48 + ]) 47 49 } 48 50 }
+38 -34
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v5.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use uuid::{uuid, Uuid}; 8 + use uuid::{Uuid, uuid}; 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler, ProtocolKeepaliveStrategy}, 12 + protocol::{ProtocolHandler, ProtocolKeepaliveStrategy, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 37 37 self.last_vibrator_speeds[feature_index as usize].store(speed as u8, Ordering::Relaxed); 38 38 let vibe1 = self.last_vibrator_speeds[0].load(Ordering::Relaxed); 39 39 let vibe2 = self.last_vibrator_speeds[1].load(Ordering::Relaxed); 40 - Ok(vec![HardwareWriteCmd::new( 41 - &[SVAKOM_V5_VIBRATOR_UUID], 42 - Endpoint::Tx, 43 - [ 44 - 0x55, 45 - 0x03, 46 - if (vibe1 > 0 && vibe2 > 0) || vibe1 == vibe2 { 47 - 0x00 48 - } else if vibe1 > 0 { 49 - 0x01 50 - } else { 51 - 0x02 52 - }, 53 - 0x00, 54 - if vibe1 == vibe2 && vibe1 == 0 { 55 - 0x00 56 - } else { 57 - 0x01 58 - }, 59 - vibe1.max(vibe2) as u8, 60 - ] 61 - .to_vec(), 62 - false, 63 - ) 64 - .into()]) 40 + Ok(vec![ 41 + HardwareWriteCmd::new( 42 + &[SVAKOM_V5_VIBRATOR_UUID], 43 + Endpoint::Tx, 44 + [ 45 + 0x55, 46 + 0x03, 47 + if (vibe1 > 0 && vibe2 > 0) || vibe1 == vibe2 { 48 + 0x00 49 + } else if vibe1 > 0 { 50 + 0x01 51 + } else { 52 + 0x02 53 + }, 54 + 0x00, 55 + if vibe1 == vibe2 && vibe1 == 0 { 56 + 0x00 57 + } else { 58 + 0x01 59 + }, 60 + vibe1.max(vibe2) as u8, 61 + ] 62 + .to_vec(), 63 + false, 64 + ) 65 + .into(), 66 + ]) 65 67 } 66 68 67 69 fn handle_output_oscillate_cmd( ··· 70 72 feature_id: uuid::Uuid, 71 73 speed: u32, 72 74 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 73 - Ok(vec![HardwareWriteCmd::new( 74 - &[feature_id], 75 - Endpoint::Tx, 76 - [0x55, 0x09, 0x00, 0x00, speed as u8, 0x00].to_vec(), 77 - false, 78 - ) 79 - .into()]) 75 + Ok(vec![ 76 + HardwareWriteCmd::new( 77 + &[feature_id], 78 + Endpoint::Tx, 79 + [0x55, 0x09, 0x00, 0x00, speed as u8, 0x00].to_vec(), 80 + false, 81 + ) 82 + .into(), 83 + ]) 80 84 } 81 85 }
+56 -50
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v6.rs
··· 6 6 // for full license information. 7 7 8 8 use async_trait::async_trait; 9 - use uuid::{uuid, Uuid}; 9 + use uuid::{Uuid, uuid}; 10 10 11 - use buttplug_core::{ 12 - errors::ButtplugDeviceError, 13 - message::{OutputType}, 14 - }; 11 + use buttplug_core::{errors::ButtplugDeviceError, message::OutputType}; 15 12 16 13 use crate::device::{ 17 14 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 18 15 protocol::{ 19 - generic_protocol_initializer_setup, 20 16 ProtocolHandler, 21 17 ProtocolIdentifier, 22 18 ProtocolInitializer, 23 19 ProtocolKeepaliveStrategy, 20 + generic_protocol_initializer_setup, 24 21 }, 25 22 }; 26 - use buttplug_server_device_config::{ServerDeviceDefinition, UserDeviceIdentifier, ProtocolCommunicationSpecifier, Endpoint}; 23 + use buttplug_server_device_config::{ 24 + Endpoint, 25 + ProtocolCommunicationSpecifier, 26 + ServerDeviceDefinition, 27 + UserDeviceIdentifier, 28 + }; 27 29 use std::sync::{ 28 - atomic::{AtomicU8, Ordering}, 29 30 Arc, 31 + atomic::{AtomicU8, Ordering}, 30 32 }; 31 33 32 34 const SVAKOM_V6_VIBRATOR_UUID: Uuid = uuid!("4cf33d95-a3d1-4ed4-9ac6-9ba6d6ccb091"); ··· 88 90 if feature_index < 2 { 89 91 let vibe1 = self.last_vibrator_speeds[0].load(Ordering::Relaxed); 90 92 let vibe2 = self.last_vibrator_speeds[1].load(Ordering::Relaxed); 91 - Ok(vec![HardwareWriteCmd::new( 92 - &[SVAKOM_V6_VIBRATOR_UUID], 93 - Endpoint::Tx, 94 - [ 95 - 0x55, 96 - 0x03, 97 - if self.num_vibrators == 1 || (vibe1 > 0 && vibe2 > 0) || vibe1 == vibe2 { 98 - 0x00 99 - } else if vibe1 > 0 { 100 - 0x01 101 - } else { 102 - 0x02 103 - }, 104 - 0x00, 105 - if vibe1 == vibe2 && vibe1 == 0 { 106 - 0x00 107 - } else { 108 - 0x01 109 - }, 110 - vibe1.max(vibe2) as u8, 111 - 0x00, 112 - ] 113 - .to_vec(), 114 - false, 115 - ) 116 - .into()]) 93 + Ok(vec![ 94 + HardwareWriteCmd::new( 95 + &[SVAKOM_V6_VIBRATOR_UUID], 96 + Endpoint::Tx, 97 + [ 98 + 0x55, 99 + 0x03, 100 + if self.num_vibrators == 1 || (vibe1 > 0 && vibe2 > 0) || vibe1 == vibe2 { 101 + 0x00 102 + } else if vibe1 > 0 { 103 + 0x01 104 + } else { 105 + 0x02 106 + }, 107 + 0x00, 108 + if vibe1 == vibe2 && vibe1 == 0 { 109 + 0x00 110 + } else { 111 + 0x01 112 + }, 113 + vibe1.max(vibe2) as u8, 114 + 0x00, 115 + ] 116 + .to_vec(), 117 + false, 118 + ) 119 + .into(), 120 + ]) 117 121 } else { 118 122 let vibe3 = self.last_vibrator_speeds[2].load(Ordering::Relaxed); 119 - Ok(vec![HardwareWriteCmd::new( 120 - &[feature_id], 121 - Endpoint::Tx, 122 - [ 123 - 0x55, 124 - 0x07, 125 - 0x00, 126 - 0x00, 127 - if vibe3 == 0 { 0x00 } else { 0x01 }, 128 - vibe3 as u8, 129 - 0x00, 130 - ] 131 - .to_vec(), 132 - false, 133 - ) 134 - .into()]) 123 + Ok(vec![ 124 + HardwareWriteCmd::new( 125 + &[feature_id], 126 + Endpoint::Tx, 127 + [ 128 + 0x55, 129 + 0x07, 130 + 0x00, 131 + 0x00, 132 + if vibe3 == 0 { 0x00 } else { 0x01 }, 133 + vibe3 as u8, 134 + 0x00, 135 + ] 136 + .to_vec(), 137 + false, 138 + ) 139 + .into(), 140 + ]) 135 141 } 136 142 } 137 143 }
+16 -14
crates/buttplug_server/src/device/protocol_impl/synchro.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 27 27 speed: u32, 28 28 clockwise: bool, 29 29 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 30 - Ok(vec![HardwareWriteCmd::new( 31 - &[feature_id], 32 - Endpoint::Tx, 33 - vec![ 34 - 0xa1, 35 - 0x01, 36 - speed as u8 | if clockwise || speed == 0 { 0x00 } else { 0x80 }, 37 - 0x77, 38 - 0x55, 39 - ], 40 - false, 41 - ) 42 - .into()]) 30 + Ok(vec![ 31 + HardwareWriteCmd::new( 32 + &[feature_id], 33 + Endpoint::Tx, 34 + vec![ 35 + 0xa1, 36 + 0x01, 37 + speed as u8 | if clockwise || speed == 0 { 0x00 } else { 0x80 }, 38 + 0x77, 39 + 0x55, 40 + ], 41 + false, 42 + ) 43 + .into(), 44 + ]) 43 45 } 44 46 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/tcode_v03.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 71 71 feature_id: Uuid, 72 72 speed: u32, 73 73 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 74 - Ok(vec![HardwareWriteCmd::new( 75 - &[feature_id], 76 - Endpoint::Tx, 77 - format!("V{feature_index}{speed:02}\n").as_bytes().to_vec(), 78 - false, 79 - ) 80 - .into()]) 74 + Ok(vec![ 75 + HardwareWriteCmd::new( 76 + &[feature_id], 77 + Endpoint::Tx, 78 + format!("V{feature_index}{speed:02}\n").as_bytes().to_vec(), 79 + false, 80 + ) 81 + .into(), 82 + ]) 81 83 } 82 84 }
+8 -11
crates/buttplug_server/src/device/protocol_impl/thehandy/mod.rs
··· 10 10 use crate::device::{ 11 11 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 12 12 protocol::{ 13 - generic_protocol_initializer_setup, 14 13 ProtocolHandler, 15 14 ProtocolIdentifier, 16 - ProtocolInitializer, ProtocolKeepaliveStrategy, 15 + ProtocolInitializer, 16 + ProtocolKeepaliveStrategy, 17 + generic_protocol_initializer_setup, 17 18 }, 18 19 }; 19 20 use async_trait::async_trait; 20 21 use buttplug_core::errors::ButtplugDeviceError; 21 22 use buttplug_server_device_config::Endpoint; 22 23 use buttplug_server_device_config::{ 23 - ServerDeviceDefinition, 24 24 ProtocolCommunicationSpecifier, 25 + ServerDeviceDefinition, 25 26 UserDeviceIdentifier, 26 27 }; 27 28 use prost::Message; 28 29 use std::sync::Arc; 29 - use uuid::{uuid, Uuid}; 30 + use uuid::{Uuid, uuid}; 30 31 31 32 mod protocomm { 32 33 include!("./protocomm.rs"); ··· 175 176 linear_payload 176 177 .encode(&mut linear_buf) 177 178 .expect("Infallible encode."); 178 - Ok(vec![HardwareWriteCmd::new( 179 - &[THEHANDY_PROTOCOL_UUID], 180 - Endpoint::Tx, 181 - linear_buf, 182 - true, 183 - ) 184 - .into()]) 179 + Ok(vec![ 180 + HardwareWriteCmd::new(&[THEHANDY_PROTOCOL_UUID], Endpoint::Tx, linear_buf, true).into(), 181 + ]) 185 182 } 186 183 }
+26 -32
crates/buttplug_server/src/device/protocol_impl/tryfun.rs
··· 10 10 11 11 use crate::device::{ 12 12 hardware::{HardwareCommand, HardwareWriteCmd}, 13 - protocol::{generic_protocol_setup, ProtocolHandler}, 13 + protocol::{ProtocolHandler, generic_protocol_setup}, 14 14 }; 15 15 16 16 generic_protocol_setup!(TryFun, "tryfun"); ··· 35 35 sum += count; 36 36 data.push(sum); 37 37 38 - Ok(vec![HardwareWriteCmd::new( 39 - &[feature_id], 40 - Endpoint::Tx, 41 - data, 42 - true, 43 - ) 44 - .into()]) 38 + Ok(vec![ 39 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, true).into(), 40 + ]) 45 41 } 46 42 47 43 fn handle_output_rotate_cmd( ··· 60 56 sum += count; 61 57 data.push(sum); 62 58 63 - Ok(vec![HardwareWriteCmd::new( 64 - &[feature_id], 65 - Endpoint::Tx, 66 - data, 67 - true, 68 - ) 69 - .into()]) 59 + Ok(vec![ 60 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, true).into(), 61 + ]) 70 62 } 71 63 72 64 fn handle_output_vibrate_cmd( ··· 75 67 feature_id: uuid::Uuid, 76 68 speed: u32, 77 69 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 78 - Ok(vec![HardwareWriteCmd::new( 79 - &[feature_id], 80 - Endpoint::Tx, 81 - vec![ 82 - 0x00, 83 - 0x02, 84 - 0x00, 85 - 0x05, 86 - if speed == 0 { 1u8 } else { 2u8 }, 87 - if speed == 0 { 2u8 } else { speed as u8 }, 88 - 0x01, 89 - if speed == 0 { 1u8 } else { 0u8 }, 90 - 0xfd - (speed as u8).max(1), 91 - ], 92 - true, 93 - ) 94 - .into()]) 70 + Ok(vec![ 71 + HardwareWriteCmd::new( 72 + &[feature_id], 73 + Endpoint::Tx, 74 + vec![ 75 + 0x00, 76 + 0x02, 77 + 0x00, 78 + 0x05, 79 + if speed == 0 { 1u8 } else { 2u8 }, 80 + if speed == 0 { 2u8 } else { speed as u8 }, 81 + 0x01, 82 + if speed == 0 { 1u8 } else { 0u8 }, 83 + 0xfd - (speed as u8).max(1), 84 + ], 85 + true, 86 + ) 87 + .into(), 88 + ]) 95 89 } 96 90 }
+7 -15
crates/buttplug_server/src/device/protocol_impl/tryfun_blackhole.rs
··· 12 12 13 13 use crate::device::{ 14 14 hardware::{HardwareCommand, HardwareWriteCmd}, 15 - protocol::{generic_protocol_setup, ProtocolHandler}, 15 + protocol::{ProtocolHandler, generic_protocol_setup}, 16 16 }; 17 17 use std::sync::atomic::{AtomicU8, Ordering}; 18 18 ··· 47 47 sum += count; 48 48 data.push(sum); 49 49 50 - Ok(vec![HardwareWriteCmd::new( 51 - &[feature_id], 52 - Endpoint::Tx, 53 - data, 54 - false, 55 - ) 56 - .into()]) 50 + Ok(vec![ 51 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 52 + ]) 57 53 } 58 54 59 55 fn handle_output_vibrate_cmd( ··· 79 75 sum += count; 80 76 data.push(sum); 81 77 82 - Ok(vec![HardwareWriteCmd::new( 83 - &[feature_id], 84 - Endpoint::Tx, 85 - data, 86 - false, 87 - ) 88 - .into()]) 78 + Ok(vec![ 79 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 80 + ]) 89 81 } 90 82 }
+10 -22
crates/buttplug_server/src/device/protocol_impl/tryfun_meta2.rs
··· 12 12 13 13 use crate::device::{ 14 14 hardware::{HardwareCommand, HardwareWriteCmd}, 15 - protocol::{generic_protocol_setup, ProtocolHandler}, 15 + protocol::{ProtocolHandler, generic_protocol_setup}, 16 16 }; 17 17 use std::sync::atomic::{AtomicU8, Ordering}; 18 18 ··· 49 49 sum += count; 50 50 data.push(sum); 51 51 52 - Ok(vec![HardwareWriteCmd::new( 53 - &[feature_id], 54 - Endpoint::Tx, 55 - data, 56 - false, 57 - ) 58 - .into()]) 52 + Ok(vec![ 53 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 54 + ]) 59 55 } 60 56 61 57 fn handle_rotation_with_direction_cmd( ··· 88 84 } 89 85 sum += count; 90 86 data.push(sum); 91 - Ok(vec![HardwareWriteCmd::new( 92 - &[feature_id], 93 - Endpoint::Tx, 94 - data, 95 - false, 96 - ) 97 - .into()]) 87 + Ok(vec![ 88 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 89 + ]) 98 90 } 99 91 100 92 fn handle_output_vibrate_cmd( ··· 122 114 sum += count; 123 115 data.push(sum); 124 116 125 - Ok(vec![HardwareWriteCmd::new( 126 - &[feature_id], 127 - Endpoint::Tx, 128 - data, 129 - false, 130 - ) 131 - .into()]) 117 + Ok(vec![ 118 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 119 + ]) 132 120 } 133 121 }
+18 -16
crates/buttplug_server/src/device/protocol_impl/vibcrafter.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareEvent, HardwareSubscribeCmd, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use aes::Aes128; ··· 19 19 use buttplug_core::errors::ButtplugDeviceError; 20 20 use buttplug_server_device_config::Endpoint; 21 21 use buttplug_server_device_config::{ 22 + ProtocolCommunicationSpecifier, 22 23 ServerDeviceDefinition, 23 - ProtocolCommunicationSpecifier, 24 24 UserDeviceIdentifier, 25 25 }; 26 26 use ecb::cipher::block_padding::Pkcs7; 27 27 use ecb::cipher::{BlockDecryptMut, BlockEncryptMut, KeyInit}; 28 28 use std::sync::{ 29 - atomic::{AtomicU8, Ordering}, 30 29 Arc, 30 + atomic::{AtomicU8, Ordering}, 31 31 }; 32 - use uuid::{uuid, Uuid}; 32 + use uuid::{Uuid, uuid}; 33 33 34 34 use rand::distributions::Alphanumeric; 35 - use rand::{thread_rng, Rng}; 35 + use rand::{Rng, thread_rng}; 36 36 use regex::Regex; 37 37 use sha2::{Digest, Sha256}; 38 38 ··· 156 156 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 157 157 self.speeds[feature_index as usize].store(speed as u8, Ordering::Relaxed); 158 158 159 - Ok(vec![HardwareWriteCmd::new( 160 - &[feature_id], 161 - Endpoint::Tx, 162 - encrypt(format!( 163 - "MtInt:{:02}{:02};", 164 - self.speeds[0].load(Ordering::Relaxed), 165 - self.speeds[1].load(Ordering::Relaxed) 166 - )), 167 - false, 168 - ) 169 - .into()]) 159 + Ok(vec![ 160 + HardwareWriteCmd::new( 161 + &[feature_id], 162 + Endpoint::Tx, 163 + encrypt(format!( 164 + "MtInt:{:02}{:02};", 165 + self.speeds[0].load(Ordering::Relaxed), 166 + self.speeds[1].load(Ordering::Relaxed) 167 + )), 168 + false, 169 + ) 170 + .into(), 171 + ]) 170 172 } 171 173 }
+4 -4
crates/buttplug_server/src/device/protocol_impl/vibratissimo.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use buttplug_core::message::OutputType; 9 8 use buttplug_core::errors::ButtplugDeviceError; 9 + use buttplug_core::message::OutputType; 10 10 use buttplug_server_device_config::Endpoint; 11 11 use buttplug_server_device_config::{ 12 - ServerDeviceDefinition, 13 12 ProtocolCommunicationSpecifier, 13 + ServerDeviceDefinition, 14 14 UserDeviceIdentifier, 15 15 }; 16 16 ··· 19 19 protocol::{ProtocolHandler, ProtocolIdentifier, ProtocolInitializer}, 20 20 }; 21 21 use async_trait::async_trait; 22 - use std::sync::atomic::{AtomicU8, Ordering}; 23 22 use std::sync::Arc; 24 - use uuid::{uuid, Uuid}; 23 + use std::sync::atomic::{AtomicU8, Ordering}; 24 + use uuid::{Uuid, uuid}; 25 25 26 26 const VIBRATISSIMO_PROTOCOL_UUID: Uuid = uuid!("66ef7aa4-1e6a-4067-9066-dcb53c7647f2"); 27 27
+11 -9
crates/buttplug_server/src/device/protocol_impl/vorze_sa/dual_rotator.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use uuid::{uuid, Uuid}; 8 + use uuid::{Uuid, uuid}; 9 9 10 10 use super::VorzeDevice; 11 11 12 12 use crate::device::{ 13 - protocol::ProtocolHandler, 14 13 hardware::{HardwareCommand, HardwareWriteCmd}, 14 + protocol::ProtocolHandler, 15 15 }; 16 16 use buttplug_core::errors::ButtplugDeviceError; 17 17 use buttplug_server_device_config::Endpoint; ··· 45 45 let data_left = ((speed_left >= 0) as u8) << 7 | (speed_left.unsigned_abs()); 46 46 let speed_right = self.speeds[1].load(Ordering::Relaxed); 47 47 let data_right = ((speed_right >= 0) as u8) << 7 | (speed_right.unsigned_abs()); 48 - Ok(vec![HardwareWriteCmd::new( 49 - &[VORZE_UFO_PROTOCOL_UUID], 50 - Endpoint::Tx, 51 - vec![VorzeDevice::UfoTw as u8, data_left, data_right], 52 - true, 53 - ) 54 - .into()]) 48 + Ok(vec![ 49 + HardwareWriteCmd::new( 50 + &[VORZE_UFO_PROTOCOL_UUID], 51 + Endpoint::Tx, 52 + vec![VorzeDevice::UfoTw as u8, data_left, data_right], 53 + true, 54 + ) 55 + .into(), 56 + ]) 55 57 } 56 58 }
+2 -2
crates/buttplug_server/src/device/protocol_impl/vorze_sa/mod.rs
··· 13 13 use crate::device::{ 14 14 hardware::Hardware, 15 15 protocol::{ 16 - generic_protocol_initializer_setup, 17 16 ProtocolHandler, 18 17 ProtocolIdentifier, 19 18 ProtocolInitializer, 19 + generic_protocol_initializer_setup, 20 20 }, 21 21 }; 22 22 use async_trait::async_trait; 23 23 use buttplug_core::errors::ButtplugDeviceError; 24 24 use buttplug_server_device_config::{ 25 - ServerDeviceDefinition, 26 25 ProtocolCommunicationSpecifier, 26 + ServerDeviceDefinition, 27 27 UserDeviceIdentifier, 28 28 }; 29 29 use std::sync::Arc;
+10 -8
crates/buttplug_server/src/device/protocol_impl/vorze_sa/piston.rs
··· 7 7 use buttplug_core::errors::ButtplugDeviceError; 8 8 use buttplug_server_device_config::Endpoint; 9 9 use std::sync::{ 10 - atomic::{AtomicU8, Ordering}, 11 10 Arc, 11 + atomic::{AtomicU8, Ordering}, 12 12 }; 13 13 14 14 #[derive(Default)] ··· 59 59 .previous_position 60 60 .store(position as u8, Ordering::Relaxed); 61 61 62 - Ok(vec![HardwareWriteCmd::new( 63 - &[feature_id], 64 - Endpoint::Tx, 65 - vec![VorzeDevice::Piston as u8, position as u8, speed], 66 - true, 67 - ) 68 - .into()]) 62 + Ok(vec![ 63 + HardwareWriteCmd::new( 64 + &[feature_id], 65 + Endpoint::Tx, 66 + vec![VorzeDevice::Piston as u8, position as u8, speed], 67 + true, 68 + ) 69 + .into(), 70 + ]) 69 71 } 70 72 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/vorze_sa/single_rotator.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::ProtocolHandler 12 + protocol::ProtocolHandler, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 34 34 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 35 35 let clockwise = if clockwise { 1u8 } else { 0 }; 36 36 let data: u8 = (clockwise) << 7 | (speed as u8); 37 - Ok(vec![HardwareWriteCmd::new( 38 - &[feature_id], 39 - Endpoint::Tx, 40 - vec![self.device_type as u8, VorzeActions::Rotate as u8, data], 41 - true, 42 - ) 43 - .into()]) 37 + Ok(vec![ 38 + HardwareWriteCmd::new( 39 + &[feature_id], 40 + Endpoint::Tx, 41 + vec![self.device_type as u8, VorzeActions::Rotate as u8, data], 42 + true, 43 + ) 44 + .into(), 45 + ]) 44 46 } 45 47 }
+16 -14
crates/buttplug_server/src/device/protocol_impl/wetoy.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 18 use buttplug_core::errors::ButtplugDeviceError; 19 19 use buttplug_server_device_config::Endpoint; 20 20 use buttplug_server_device_config::{ 21 - ServerDeviceDefinition, 22 21 ProtocolCommunicationSpecifier, 22 + ServerDeviceDefinition, 23 23 UserDeviceIdentifier, 24 24 }; 25 25 use std::sync::Arc; 26 - use uuid::{uuid, Uuid}; 26 + use uuid::{Uuid, uuid}; 27 27 28 28 const WETOY_PROTOCOL_ID: Uuid = uuid!("9868762e-4203-4876-abf5-83c992e024b4"); 29 29 generic_protocol_initializer_setup!(WeToy, "wetoy"); ··· 60 60 feature_id: Uuid, 61 61 speed: u32, 62 62 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 63 - Ok(vec![HardwareWriteCmd::new( 64 - &[feature_id], 65 - Endpoint::Tx, 66 - if speed == 0 { 67 - vec![0x80, 0x03] 68 - } else { 69 - vec![0xb2, speed as u8 - 1] 70 - }, 71 - true, 72 - ) 73 - .into()]) 63 + Ok(vec![ 64 + HardwareWriteCmd::new( 65 + &[feature_id], 66 + Endpoint::Tx, 67 + if speed == 0 { 68 + vec![0x80, 0x03] 69 + } else { 70 + vec![0xb2, speed as u8 - 1] 71 + }, 72 + true, 73 + ) 74 + .into(), 75 + ]) 74 76 } 75 77 }
+8 -12
crates/buttplug_server/src/device/protocol_impl/wevibe.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; 18 + use buttplug_core::errors::ButtplugDeviceError; 18 19 use buttplug_core::message::OutputType; 19 - use buttplug_core::errors::ButtplugDeviceError; 20 20 use buttplug_server_device_config::Endpoint; 21 21 use buttplug_server_device_config::{ 22 - ServerDeviceDefinition, 23 22 ProtocolCommunicationSpecifier, 23 + ServerDeviceDefinition, 24 24 UserDeviceIdentifier, 25 25 }; 26 + use std::sync::Arc; 26 27 use std::sync::atomic::{AtomicU8, Ordering}; 27 - use std::sync::Arc; 28 - use uuid::{uuid, Uuid}; 28 + use uuid::{Uuid, uuid}; 29 29 30 30 const WEVIBE_PROTOCOL_UUID: Uuid = uuid!("3658e33d-086d-401e-9dce-8e9e88ff791f"); 31 31 generic_protocol_initializer_setup!(WeVibe, "wevibe"); ··· 109 109 0x00, 110 110 ] 111 111 }; 112 - Ok(vec![HardwareWriteCmd::new( 113 - &[WEVIBE_PROTOCOL_UUID], 114 - Endpoint::Tx, 115 - data, 116 - true, 117 - ) 118 - .into()]) 112 + Ok(vec![ 113 + HardwareWriteCmd::new(&[WEVIBE_PROTOCOL_UUID], Endpoint::Tx, data, true).into(), 114 + ]) 119 115 } 120 116 }
+12 -14
crates/buttplug_server/src/device/protocol_impl/wevibe8bit.rs
··· 6 6 // for full license information. 7 7 8 8 use std::sync::{ 9 - atomic::{AtomicU8, Ordering}, 10 9 Arc, 10 + atomic::{AtomicU8, Ordering}, 11 11 }; 12 12 13 13 use async_trait::async_trait; 14 - use uuid::{uuid, Uuid}; 14 + use uuid::{Uuid, uuid}; 15 15 16 16 use crate::device::{ 17 17 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 18 18 protocol::{ 19 - generic_protocol_initializer_setup, 20 19 ProtocolHandler, 21 20 ProtocolIdentifier, 22 21 ProtocolInitializer, 22 + generic_protocol_initializer_setup, 23 23 }, 24 24 }; 25 - use buttplug_core::{ 26 - errors::ButtplugDeviceError, 27 - message::OutputType, 25 + use buttplug_core::{errors::ButtplugDeviceError, message::OutputType}; 26 + use buttplug_server_device_config::{ 27 + Endpoint, 28 + ProtocolCommunicationSpecifier, 29 + ServerDeviceDefinition, 30 + UserDeviceIdentifier, 28 31 }; 29 - use buttplug_server_device_config::{Endpoint, ServerDeviceDefinition, UserDeviceIdentifier, ProtocolCommunicationSpecifier}; 30 32 31 33 generic_protocol_initializer_setup!(WeVibe8Bit, "wevibe-8bit"); 32 34 ··· 96 98 0x00, 97 99 ] 98 100 }; 99 - Ok(vec![HardwareWriteCmd::new( 100 - &[WEVIBE8BIT_PROTOCOL_UUID], 101 - Endpoint::Tx, 102 - data, 103 - true, 104 - ) 105 - .into()]) 101 + Ok(vec![ 102 + HardwareWriteCmd::new(&[WEVIBE8BIT_PROTOCOL_UUID], Endpoint::Tx, data, true).into(), 103 + ]) 106 104 } 107 105 }
+12 -14
crates/buttplug_server/src/device/protocol_impl/wevibe_chorus.rs
··· 6 6 // for full license information. 7 7 8 8 use std::sync::{ 9 - atomic::{AtomicU8, Ordering}, 10 9 Arc, 10 + atomic::{AtomicU8, Ordering}, 11 11 }; 12 12 13 13 use async_trait::async_trait; 14 - use uuid::{uuid, Uuid}; 14 + use uuid::{Uuid, uuid}; 15 15 16 16 use crate::device::{ 17 17 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 18 18 protocol::{ 19 - generic_protocol_initializer_setup, 20 19 ProtocolHandler, 21 20 ProtocolIdentifier, 22 21 ProtocolInitializer, 22 + generic_protocol_initializer_setup, 23 23 }, 24 24 }; 25 - use buttplug_core::{ 26 - errors::ButtplugDeviceError, 27 - message::OutputType, 25 + use buttplug_core::{errors::ButtplugDeviceError, message::OutputType}; 26 + use buttplug_server_device_config::{ 27 + Endpoint, 28 + ProtocolCommunicationSpecifier, 29 + ServerDeviceDefinition, 30 + UserDeviceIdentifier, 28 31 }; 29 - use buttplug_server_device_config::{ServerDeviceDefinition, Endpoint, ProtocolCommunicationSpecifier, UserDeviceIdentifier}; 30 32 31 33 generic_protocol_initializer_setup!(WeVibeChorus, "wevibe-chorus"); 32 34 ··· 97 99 0x00, 98 100 ] 99 101 }; 100 - Ok(vec![HardwareWriteCmd::new( 101 - &[WEVIBE_CHORUS_PROTOCOL_UUID], 102 - Endpoint::Tx, 103 - data, 104 - true, 105 - ) 106 - .into()]) 102 + Ok(vec![ 103 + HardwareWriteCmd::new(&[WEVIBE_CHORUS_PROTOCOL_UUID], Endpoint::Tx, data, true).into(), 104 + ]) 107 105 } 108 106 }
+24 -22
crates/buttplug_server/src/device/protocol_impl/xibao.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 27 27 feature_id: Uuid, 28 28 speed: u32, 29 29 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 30 - Ok(vec![HardwareWriteCmd::new( 31 - &[feature_id], 32 - Endpoint::Tx, 33 - vec![ 34 - 0x66, 35 - 0x3a, 36 - 0x00, 37 - 0x06, 38 - 0x00, 39 - 0x06, 40 - 0x01, 41 - 0x02, 42 - 0x00, 43 - 0x02, 44 - 0x04, 45 - speed as u8, 46 - (Wrapping(speed as u8) + Wrapping(0xb5)).0, 47 - ], 48 - false, 49 - ) 50 - .into()]) 30 + Ok(vec![ 31 + HardwareWriteCmd::new( 32 + &[feature_id], 33 + Endpoint::Tx, 34 + vec![ 35 + 0x66, 36 + 0x3a, 37 + 0x00, 38 + 0x06, 39 + 0x00, 40 + 0x06, 41 + 0x01, 42 + 0x02, 43 + 0x00, 44 + 0x02, 45 + 0x04, 46 + speed as u8, 47 + (Wrapping(speed as u8) + Wrapping(0xb5)).0, 48 + ], 49 + false, 50 + ) 51 + .into(), 52 + ]) 51 53 } 52 54 }
+6 -10
crates/buttplug_server/src/device/protocol_impl/xinput.rs
··· 10 10 11 11 use crate::device::{ 12 12 hardware::{Hardware, HardwareCommand, HardwareReadCmd, HardwareWriteCmd}, 13 - protocol::{generic_protocol_setup, ProtocolHandler}, 13 + protocol::{ProtocolHandler, generic_protocol_setup}, 14 14 }; 15 15 use buttplug_core::{ 16 16 errors::ButtplugDeviceError, ··· 19 19 use byteorder::WriteBytesExt; 20 20 use futures::future::{BoxFuture, FutureExt}; 21 21 use std::sync::{ 22 - atomic::{AtomicU16, Ordering}, 23 22 Arc, 23 + atomic::{AtomicU16, Ordering}, 24 24 }; 25 25 26 26 generic_protocol_setup!(XInput, "xinput"); ··· 55 55 "Cannot convert XInput value for processing".to_owned(), 56 56 )); 57 57 } 58 - Ok(vec![HardwareWriteCmd::new( 59 - &[feature_id], 60 - Endpoint::Tx, 61 - cmd, 62 - false, 63 - ) 64 - .into()]) 58 + Ok(vec![ 59 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, cmd, false).into(), 60 + ]) 65 61 } 66 62 67 63 fn handle_input_read_cmd( ··· 84 80 _ => { 85 81 return Err(ButtplugDeviceError::DeviceCommunicationError( 86 82 "something went wrong".to_string(), 87 - )) 83 + )); 88 84 } 89 85 }; 90 86 Ok(message::InputReadingV4::new(
+10 -8
crates/buttplug_server/src/device/protocol_impl/xiuxiuda.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - [0x00, 0x00, 0x00, 0x00, 0x65, 0x3a, 0x30, speed as u8, 0x64].to_vec(), 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + [0x00, 0x00, 0x00, 0x00, 0x65, 0x3a, 0x30, speed as u8, 0x64].to_vec(), 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+13 -11
crates/buttplug_server/src/device/protocol_impl/xuanhuan.rs
··· 8 8 use crate::device::{ 9 9 hardware::{Hardware, HardwareCommand, HardwareWriteCmd}, 10 10 protocol::{ 11 - generic_protocol_initializer_setup, 12 11 ProtocolHandler, 13 12 ProtocolIdentifier, 14 13 ProtocolInitializer, 14 + generic_protocol_initializer_setup, 15 15 }, 16 16 }; 17 17 use async_trait::async_trait; ··· 21 21 }; 22 22 use buttplug_server_device_config::{ 23 23 Endpoint, 24 - ServerDeviceDefinition, 25 24 ProtocolCommunicationSpecifier, 25 + ServerDeviceDefinition, 26 26 UserDeviceIdentifier, 27 27 }; 28 28 use std::{ 29 29 sync::{ 30 - atomic::{AtomicU8, Ordering}, 31 30 Arc, 31 + atomic::{AtomicU8, Ordering}, 32 32 }, 33 33 time::Duration, 34 34 }; 35 - use uuid::{uuid, Uuid}; 35 + use uuid::{Uuid, uuid}; 36 36 37 37 const XUANHUAN_PROTOCOL_ID: Uuid = uuid!("e9f9f8ab-4fd5-4573-a4ec-ab542568849b"); 38 38 generic_protocol_initializer_setup!(Xuanhuan, "xuanhuan"); ··· 100 100 let speed = speed as u8; 101 101 self.current_command.store(speed, Ordering::Relaxed); 102 102 103 - Ok(vec![HardwareWriteCmd::new( 104 - &[XUANHUAN_PROTOCOL_ID], 105 - Endpoint::Tx, 106 - vec![0x03, 0x02, 0x00, speed], 107 - true, 108 - ) 109 - .into()]) 103 + Ok(vec![ 104 + HardwareWriteCmd::new( 105 + &[XUANHUAN_PROTOCOL_ID], 106 + Endpoint::Tx, 107 + vec![0x03, 0x02, 0x00, speed], 108 + true, 109 + ) 110 + .into(), 111 + ]) 110 112 } 111 113 }
+10 -8
crates/buttplug_server/src/device/protocol_impl/youcups.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 26 26 feature_id: Uuid, 27 27 speed: u32, 28 28 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 29 - Ok(vec![HardwareWriteCmd::new( 30 - &[feature_id], 31 - Endpoint::Tx, 32 - format!("$SYS,{}?", speed as u8).as_bytes().to_vec(), 33 - false, 34 - ) 35 - .into()]) 29 + Ok(vec![ 30 + HardwareWriteCmd::new( 31 + &[feature_id], 32 + Endpoint::Tx, 33 + format!("$SYS,{}?", speed as u8).as_bytes().to_vec(), 34 + false, 35 + ) 36 + .into(), 37 + ]) 36 38 } 37 39 }
+5 -9
crates/buttplug_server/src/device/protocol_impl/youou.rs
··· 8 8 use buttplug_core::errors::ButtplugDeviceError; 9 9 use buttplug_server_device_config::Endpoint; 10 10 use buttplug_server_device_config::{ 11 - ServerDeviceDefinition, 12 11 ProtocolCommunicationSpecifier, 12 + ServerDeviceDefinition, 13 13 UserDeviceIdentifier, 14 14 }; 15 15 ··· 19 19 }; 20 20 use async_trait::async_trait; 21 21 use std::sync::{ 22 - atomic::{AtomicU8, Ordering}, 23 22 Arc, 23 + atomic::{AtomicU8, Ordering}, 24 24 }; 25 25 use uuid::Uuid; 26 26 ··· 115 115 let mut data2 = vec![crc, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; 116 116 data.append(&mut data2); 117 117 118 - Ok(vec![HardwareWriteCmd::new( 119 - &[feature_id], 120 - Endpoint::Tx, 121 - data, 122 - false, 123 - ) 124 - .into()]) 118 + Ok(vec![ 119 + HardwareWriteCmd::new(&[feature_id], Endpoint::Tx, data, false).into(), 120 + ]) 125 121 } 126 122 }
+18 -16
crates/buttplug_server/src/device/protocol_impl/zalo.rs
··· 9 9 10 10 use crate::device::{ 11 11 hardware::{HardwareCommand, HardwareWriteCmd}, 12 - protocol::{generic_protocol_setup, ProtocolHandler}, 12 + protocol::{ProtocolHandler, generic_protocol_setup}, 13 13 }; 14 14 use buttplug_core::errors::ButtplugDeviceError; 15 15 use buttplug_server_device_config::Endpoint; ··· 31 31 self.speeds[feature_index as usize].store(speed as u8, Ordering::Relaxed); 32 32 let speed0: u8 = self.speeds[0].load(Ordering::Relaxed); 33 33 let speed1: u8 = self.speeds[1].load(Ordering::Relaxed); 34 - Ok(vec![HardwareWriteCmd::new( 35 - &[feature_id], 36 - Endpoint::Tx, 37 - vec![ 38 - if speed0 == 0 && speed1 == 0 { 39 - 0x02 40 - } else { 41 - 0x01 42 - }, 43 - if speed0 == 0 { 0x01 } else { speed0 }, 44 - if speed1 == 0 { 0x01 } else { speed1 }, 45 - ], 46 - true, 47 - ) 48 - .into()]) 34 + Ok(vec![ 35 + HardwareWriteCmd::new( 36 + &[feature_id], 37 + Endpoint::Tx, 38 + vec![ 39 + if speed0 == 0 && speed1 == 0 { 40 + 0x02 41 + } else { 42 + 0x01 43 + }, 44 + if speed0 == 0 { 0x01 } else { speed0 }, 45 + if speed1 == 0 { 0x01 } else { speed1 }, 46 + ], 47 + true, 48 + ) 49 + .into(), 50 + ]) 49 51 } 50 52 }
+10 -11
crates/buttplug_server/src/device/server_device_manager.rs
··· 9 9 //! specific) Managers 10 10 11 11 use crate::{ 12 + ButtplugServerError, 13 + ButtplugServerResultFuture, 12 14 device::{ 15 + ServerDevice, 13 16 hardware::communication::{HardwareCommunicationManager, HardwareCommunicationManagerBuilder}, 14 17 server_device_manager_event_loop::ServerDeviceManagerEventLoop, 15 - ServerDevice, 16 18 }, 17 19 message::{ 18 20 server_device_attributes::ServerDeviceAttributes, ··· 22 24 ButtplugDeviceManagerMessageUnion, 23 25 }, 24 26 }, 25 - ButtplugServerError, 26 - ButtplugServerResultFuture, 27 27 }; 28 28 use buttplug_core::{ 29 29 errors::{ButtplugDeviceError, ButtplugMessageError, ButtplugUnknownError}, ··· 33 33 use buttplug_server_device_config::{DeviceConfigurationManager, UserDeviceIdentifier}; 34 34 use dashmap::DashMap; 35 35 use futures::{ 36 - future::{self, FutureExt}, 37 36 Stream, 37 + future::{self, FutureExt}, 38 38 }; 39 39 use getset::Getters; 40 40 use std::{ 41 41 collections::HashMap, 42 42 convert::TryFrom, 43 43 sync::{ 44 - atomic::{AtomicBool, Ordering}, 45 44 Arc, 45 + atomic::{AtomicBool, Ordering}, 46 46 }, 47 47 }; 48 48 use tokio::sync::{broadcast, mpsc}; ··· 131 131 } 132 132 } 133 133 if colliding_dcms.len() > 1 { 134 - warn!("The following device connection methods may collide: {}. This may mean you have lovense dongles and bluetooth dongles connected at the same time. Please disconnect the lovense dongles or turn off the Lovense HID/Serial Dongle support in Intiface/Buttplug. Lovense devices will work with the Bluetooth dongle.", colliding_dcms.join(", ")); 134 + warn!( 135 + "The following device connection methods may collide: {}. This may mean you have lovense dongles and bluetooth dongles connected at the same time. Please disconnect the lovense dongles or turn off the Lovense HID/Serial Dongle support in Intiface/Buttplug. Lovense devices will work with the Bluetooth dongle.", 136 + colliding_dcms.join(", ") 137 + ); 135 138 } 136 139 137 140 let devices = Arc::new(DashMap::new()); ··· 294 297 pub fn device_info(&self, index: u32) -> Option<ServerDeviceInfo> { 295 298 self.devices.get(&index).map(|device| ServerDeviceInfo { 296 299 identifier: device.value().identifier().clone(), 297 - display_name: device 298 - .value() 299 - .definition() 300 - .display_name() 301 - .clone(), 300 + display_name: device.value().definition().display_name().clone(), 302 301 }) 303 302 } 304 303
+27 -28
crates/buttplug_server/src/device/server_device_manager_event_loop.rs
··· 13 13 use tracing::info_span; 14 14 15 15 use crate::device::{ 16 - hardware::communication::{HardwareCommunicationManager, HardwareCommunicationManagerEvent}, 17 16 ServerDevice, 18 17 ServerDeviceEvent, 19 - protocol::ProtocolManager 18 + hardware::communication::{HardwareCommunicationManager, HardwareCommunicationManagerEvent}, 19 + protocol::ProtocolManager, 20 20 }; 21 21 use dashmap::{DashMap, DashSet}; 22 - use futures::{future, pin_mut, FutureExt, StreamExt}; 23 - use std::sync::{atomic::AtomicBool, Arc}; 22 + use futures::{FutureExt, StreamExt, future, pin_mut}; 23 + use std::sync::{Arc, atomic::AtomicBool}; 24 24 use tokio::sync::{broadcast, mpsc}; 25 25 use tokio_util::sync::CancellationToken; 26 26 use tracing_futures::Instrument; ··· 137 137 "System signaled that scanning was finished, check to see if all managers are finished." 138 138 ); 139 139 if self.scanning_bringup_in_progress { 140 - debug!("Hardware Comm Manager finished before scanning was fully started, continuing event loop."); 140 + debug!( 141 + "Hardware Comm Manager finished before scanning was fully started, continuing event loop." 142 + ); 141 143 return; 142 144 } 143 145 // Only send scanning finished if we haven't requested a stop. ··· 194 196 // 195 197 // We used to do this in build_server_device, but we shouldn't mark devices as actually 196 198 // connecting until after this happens, so we're moving it back here. 197 - let protocol_specializers = self 198 - .protocol_manager 199 - .protocol_specializers( 200 - &creator.specifier(), 201 - self.device_config_manager.base_communication_specifiers(), 202 - self.device_config_manager.user_communication_specifiers() 203 - ); 199 + let protocol_specializers = self.protocol_manager.protocol_specializers( 200 + &creator.specifier(), 201 + self.device_config_manager.base_communication_specifiers(), 202 + self.device_config_manager.user_communication_specifiers(), 203 + ); 204 204 205 205 // If we have no identifiers, then there's nothing to do here. Throw an error. 206 206 if protocol_specializers.is_empty() { ··· 285 285 // address), consider it disconnected and eject it from the map. This 286 286 // should also trigger a disconnect event before our new DeviceAdded 287 287 // message goes out, so timing matters here. 288 - match self.device_map.remove(&device_index) { Some((_, old_device)) => { 289 - info!("Device map contains key {}.", device_index); 290 - // After removing the device from the array, manually disconnect it to 291 - // make sure the event is thrown. 292 - if let Err(err) = old_device.disconnect().await { 293 - // If we throw an error during the disconnect, we can't really do 294 - // anything with it, but should at least log it. 295 - error!("Error during index collision disconnect: {:?}", err); 288 + match self.device_map.remove(&device_index) { 289 + Some((_, old_device)) => { 290 + info!("Device map contains key {}.", device_index); 291 + // After removing the device from the array, manually disconnect it to 292 + // make sure the event is thrown. 293 + if let Err(err) = old_device.disconnect().await { 294 + // If we throw an error during the disconnect, we can't really do 295 + // anything with it, but should at least log it. 296 + error!("Error during index collision disconnect: {:?}", err); 297 + } 298 + } 299 + _ => { 300 + info!("Device map does not contain key {}.", device_index); 296 301 } 297 - } _ => { 298 - info!("Device map does not contain key {}.", device_index); 299 - }} 302 + } 300 303 301 304 // Create event loop for forwarding device events into our selector. 302 305 let event_listener = device.event_stream(); ··· 341 344 .remove(&device_index) 342 345 .expect("Remove will always work."); 343 346 let device_update_message: ButtplugServerMessageV4 = self.generate_device_list().into(); 344 - if self 345 - .server_sender 346 - .send(device_update_message) 347 - .is_err() 348 - { 347 + if self.server_sender.send(device_update_message).is_err() { 349 348 debug!("Server not currently available, dropping Device Removed event."); 350 349 } 351 350 }
+1 -3
crates/buttplug_server/src/message/mod.rs
··· 122 122 } 123 123 } 124 124 125 - #[derive( 126 - Debug, Clone, ButtplugMessage, ButtplugMessageFinalizer, ButtplugMessageValidator, 127 - )] 125 + #[derive(Debug, Clone, ButtplugMessage, ButtplugMessageFinalizer, ButtplugMessageValidator)] 128 126 pub enum ButtplugServerMessageVariant { 129 127 V0(ButtplugServerMessageV0), 130 128 V1(ButtplugServerMessageV1),
+8 -8
crates/buttplug_server/src/message/serializer/mod.rs
··· 2 2 errors::{ButtplugError, ButtplugHandshakeError, ButtplugMessageError}, 3 3 message::{ 4 4 self, 5 + ButtplugClientMessageV4, 6 + ButtplugMessageFinalizer, 7 + ButtplugMessageSpecVersion, 8 + ButtplugServerMessageCurrent, 9 + ButtplugServerMessageV4, 5 10 serializer::{ 11 + ButtplugMessageSerializer, 12 + ButtplugSerializedMessage, 13 + ButtplugSerializerError, 6 14 json_serializer::{ 7 15 create_message_validator, 8 16 deserialize_to_message, 9 17 msg_to_protocol_json, 10 18 vec_to_protocol_json, 11 19 }, 12 - ButtplugMessageSerializer, 13 - ButtplugSerializedMessage, 14 - ButtplugSerializerError, 15 20 }, 16 - ButtplugClientMessageV4, 17 - ButtplugMessageFinalizer, 18 - ButtplugMessageSpecVersion, 19 - ButtplugServerMessageCurrent, 20 - ButtplugServerMessageV4, 21 21 }, 22 22 }; 23 23 use jsonschema::Validator;
+1 -1
crates/buttplug_server/src/message/server_device_attributes.rs
··· 1 - use super::v2::ServerDeviceMessageAttributesV2; 2 1 use super::ServerDeviceMessageAttributesV3; 2 + use super::v2::ServerDeviceMessageAttributesV2; 3 3 use buttplug_core::errors::ButtplugError; 4 4 use buttplug_server_device_config::ServerDeviceFeature; 5 5 use getset::Getters;
+10 -6
crates/buttplug_server/src/message/v0/fleshlight_launch_fw12_cmd.rs
··· 81 81 pub fn test_legacy_fleshlight_message_bounds() { 82 82 assert!(FleshlightLaunchFW12CmdV0::new(0, 0, 0).is_valid().is_ok()); 83 83 assert!(FleshlightLaunchFW12CmdV0::new(0, 99, 99).is_valid().is_ok()); 84 - assert!(FleshlightLaunchFW12CmdV0::new(0, 100, 99) 85 - .is_valid() 86 - .is_err()); 87 - assert!(FleshlightLaunchFW12CmdV0::new(0, 99, 100) 88 - .is_valid() 89 - .is_err()); 84 + assert!( 85 + FleshlightLaunchFW12CmdV0::new(0, 100, 99) 86 + .is_valid() 87 + .is_err() 88 + ); 89 + assert!( 90 + FleshlightLaunchFW12CmdV0::new(0, 99, 100) 91 + .is_valid() 92 + .is_err() 93 + ); 90 94 } 91 95 }
+1 -1
crates/buttplug_server/src/message/v1/device_added.rs
··· 11 11 message::{ButtplugMessage, ButtplugMessageFinalizer, ButtplugMessageValidator}, 12 12 }; 13 13 14 - use super::{device_message_info::DeviceMessageInfoV1, ClientDeviceMessageAttributesV1}; 14 + use super::{ClientDeviceMessageAttributesV1, device_message_info::DeviceMessageInfoV1}; 15 15 16 16 use getset::{CopyGetters, Getters}; 17 17
+1 -1
crates/buttplug_server/src/message/v1/device_message_info.rs
··· 8 8 use getset::{CopyGetters, Getters}; 9 9 use serde::{Deserialize, Serialize}; 10 10 11 - use crate::message::{v0::DeviceMessageInfoV0, ButtplugDeviceMessageNameV0}; 11 + use crate::message::{ButtplugDeviceMessageNameV0, v0::DeviceMessageInfoV0}; 12 12 13 13 use super::{ClientDeviceMessageAttributesV1, DeviceAddedV1}; 14 14
+2 -4
crates/buttplug_server/src/message/v2/battery_level_cmd.rs
··· 6 6 // for full license information. 7 7 8 8 use crate::message::{ 9 - checked_input_cmd::CheckedInputCmdV4, 10 9 ServerDeviceAttributes, 11 10 TryFromDeviceAttributes, 11 + checked_input_cmd::CheckedInputCmdV4, 12 12 }; 13 13 use buttplug_core::{ 14 14 errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError}, ··· 76 76 .features() 77 77 .iter() 78 78 .enumerate() 79 - .find(|(_, p)| { 80 - p.input().as_ref().map_or(false, |x| x.battery().is_some()) 81 - }) 79 + .find(|(_, p)| p.input().as_ref().map_or(false, |x| x.battery().is_some())) 82 80 .expect("Already found matching battery feature, can unwrap this.") 83 81 .0; 84 82
+1 -1
crates/buttplug_server/src/message/v2/device_added.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use super::{device_message_info::DeviceMessageInfoV2, ClientDeviceMessageAttributesV2}; 8 + use super::{ClientDeviceMessageAttributesV2, device_message_info::DeviceMessageInfoV2}; 9 9 use crate::message::v1::{DeviceAddedV1, DeviceMessageInfoV1}; 10 10 use buttplug_core::{ 11 11 errors::ButtplugMessageError,
+1 -1
crates/buttplug_server/src/message/v2/server_device_message_attributes.rs
··· 6 6 // for full license information. 7 7 8 8 use crate::message::{ 9 - v1::NullDeviceMessageAttributesV1, 10 9 ServerDeviceMessageAttributesV3, 11 10 ServerGenericDeviceMessageAttributesV3, 11 + v1::NullDeviceMessageAttributesV1, 12 12 }; 13 13 use buttplug_core::message::{InputType, OutputType}; 14 14
+9 -5
crates/buttplug_server/src/message/v3/device_added.rs
··· 12 12 }; 13 13 use buttplug_core::{ 14 14 errors::ButtplugMessageError, 15 - message::{ButtplugMessage, ButtplugMessageFinalizer, ButtplugMessageValidator, DeviceFeature, DeviceMessageInfoV4}, 15 + message::{ 16 + ButtplugMessage, 17 + ButtplugMessageFinalizer, 18 + ButtplugMessageValidator, 19 + DeviceFeature, 20 + DeviceMessageInfoV4, 21 + }, 16 22 }; 17 23 18 24 use getset::{CopyGetters, Getters}; ··· 22 28 use super::{ClientDeviceMessageAttributesV3, DeviceMessageInfoV3}; 23 29 24 30 /// Notification that a device has been found and connected to the server. 25 - #[derive( 26 - ButtplugMessage, Clone, Debug, Getters, CopyGetters, Serialize, Deserialize, 27 - )] 31 + #[derive(ButtplugMessage, Clone, Debug, Getters, CopyGetters, Serialize, Deserialize)] 28 32 pub struct DeviceAddedV3 { 29 33 #[serde(rename = "Id")] 30 34 id: u32, ··· 119 123 value.device_name(), 120 124 value.device_display_name(), 121 125 value.device_message_timing_gap(), 122 - &feature_vec.into() 126 + &feature_vec.into(), 123 127 ); 124 128 da3.set_id(0); 125 129 da3
+6 -5
crates/buttplug_server/src/message/v3/sensor_read_cmd.rs
··· 6 6 // for full license information. 7 7 8 8 use crate::message::{ 9 - checked_input_cmd::CheckedInputCmdV4, 10 9 ServerDeviceAttributes, 11 10 TryFromDeviceAttributes, 11 + checked_input_cmd::CheckedInputCmdV4, 12 12 }; 13 13 use buttplug_core::{ 14 14 errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError}, ··· 77 77 Err(ButtplugError::from( 78 78 ButtplugDeviceError::MessageNotSupported("SensorReadCmdV3".to_owned()), 79 79 )) 80 - } else if let Some((feature_index, feature)) = 81 - features.features().iter().enumerate().find(|(_, p)| { 82 - p.input().as_ref().map_or(false, |x| x.battery().is_some()) 83 - }) 80 + } else if let Some((feature_index, feature)) = features 81 + .features() 82 + .iter() 83 + .enumerate() 84 + .find(|(_, p)| p.input().as_ref().map_or(false, |x| x.battery().is_some())) 84 85 { 85 86 Ok(CheckedInputCmdV4::new( 86 87 msg.device_index(),
+7 -7
crates/buttplug_server/src/message/v4/checked_input_cmd.rs
··· 68 68 if let Some(feature) = features.features().get(msg.feature_index() as usize) { 69 69 if let Some(sensor_map) = feature.input() { 70 70 if sensor_map.contains(msg.input_type()) { 71 - Ok(CheckedInputCmdV4::new( 72 - msg.device_index(), 73 - msg.feature_index(), 74 - msg.input_type(), 75 - msg.input_command(), 76 - feature.id(), 77 - )) 71 + Ok(CheckedInputCmdV4::new( 72 + msg.device_index(), 73 + msg.feature_index(), 74 + msg.input_type(), 75 + msg.input_command(), 76 + feature.id(), 77 + )) 78 78 } else { 79 79 Err(ButtplugError::from( 80 80 ButtplugDeviceError::DeviceNoSensorError("InputCmd".to_string()),
+3 -1
crates/buttplug_server/src/message/v4/checked_output_cmd.rs
··· 107 107 if let Some(output_map) = feature.output() { 108 108 let output_type = cmd.command().as_output_type(); 109 109 let value = cmd.command().value(); 110 - let new_value = output_map.calculate_from_value(output_type, value as i32).map_err(|_| ButtplugDeviceError::DeviceStepRangeError(0, value))?; 110 + let new_value = output_map 111 + .calculate_from_value(output_type, value as i32) 112 + .map_err(|_| ButtplugDeviceError::DeviceStepRangeError(0, value))?; 111 113 let mut new_command = cmd.command(); 112 114 new_command.set_value(new_value as u32); 113 115 // We can't make a private trait impl to turn a ValueCmd into a CheckedValueCmd, and this
+7 -11
crates/buttplug_server/src/message/v4/checked_output_vec_cmd.rs
··· 220 220 )); 221 221 } 222 222 for cmd in msg.scalars() { 223 - let scalar_attrs = if let Some(a) = attrs 224 - .attrs_v3() 225 - .scalar_cmd() { 226 - a 227 - } else { 228 - continue; 229 - }; 223 + let scalar_attrs = if let Some(a) = attrs.attrs_v3().scalar_cmd() { 224 + a 225 + } else { 226 + continue; 227 + }; 230 228 let feature = scalar_attrs 231 229 .get(cmd.index() as usize) 232 230 .ok_or(ButtplugError::from( ··· 318 316 OutputCommand::PositionWithDuration(OutputPositionWithDuration::new( 319 317 actuator.calculate_scaled_float(x.position()).map_err(|_| { 320 318 ButtplugError::from(ButtplugMessageError::InvalidMessageContents( 321 - "Position should be 0.0 < x < 1.0" 322 - .to_owned(), 319 + "Position should be 0.0 < x < 1.0".to_owned(), 323 320 )) 324 321 })?, 325 322 x.duration().try_into().map_err(|_| { ··· 390 387 OutputCommand::RotateWithDirection(OutputRotateWithDirection::new( 391 388 actuator.calculate_scaled_float(cmd.speed()).map_err(|_| { 392 389 ButtplugError::from(ButtplugMessageError::InvalidMessageContents( 393 - "Position should be 0.0 < x < 1.0" 394 - .to_owned(), 390 + "Position should be 0.0 < x < 1.0".to_owned(), 395 391 )) 396 392 })? as u32, 397 393 cmd.clockwise(),
+4 -4
crates/buttplug_server/src/message/v4/spec_enums.rs
··· 1 1 use std::{collections::HashMap, fmt::Debug}; 2 2 3 3 use crate::message::{ 4 + ButtplugClientMessageVariant, 5 + RequestServerInfoV1, 6 + ServerDeviceAttributes, 7 + TryFromDeviceAttributes, 4 8 server_device_attributes::TryFromClientMessage, 5 9 v0::ButtplugClientMessageV0, 6 10 v1::ButtplugClientMessageV1, 7 11 v2::ButtplugClientMessageV2, 8 12 v3::ButtplugClientMessageV3, 9 - ButtplugClientMessageVariant, 10 - RequestServerInfoV1, 11 - ServerDeviceAttributes, 12 - TryFromDeviceAttributes, 13 13 }; 14 14 use buttplug_core::{ 15 15 errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError},
+2 -2
crates/buttplug_server/src/ping_timer.rs
··· 9 9 use futures::Future; 10 10 use std::{ 11 11 sync::{ 12 - atomic::{AtomicBool, Ordering}, 13 12 Arc, 13 + atomic::{AtomicBool, Ordering}, 14 14 }, 15 15 time::Duration, 16 16 }; 17 17 use tokio::{ 18 18 select, 19 - sync::{mpsc, Notify}, 19 + sync::{Notify, mpsc}, 20 20 }; 21 21 22 22 pub enum PingMessage {
+19 -12
crates/buttplug_server/src/server.rs
··· 8 8 use crate::server_message_conversion::ButtplugServerDeviceEventMessageConverter; 9 9 10 10 use super::{ 11 + ButtplugServerResultFuture, 11 12 device::ServerDeviceManager, 12 13 message::{ 14 + ButtplugClientMessageVariant, 15 + ButtplugServerMessageVariant, 13 16 server_device_attributes::TryFromClientMessage, 14 17 spec_enums::{ 15 18 ButtplugCheckedClientMessageV4, 16 19 ButtplugDeviceCommandMessageUnionV4, 17 20 ButtplugDeviceManagerMessageUnion, 18 21 }, 19 - ButtplugClientMessageVariant, 20 - ButtplugServerMessageVariant, 21 22 }, 22 23 ping_timer::PingTimer, 23 24 server_message_conversion::ButtplugServerMessageConverter, 24 - ButtplugServerResultFuture, 25 25 }; 26 26 use buttplug_core::{ 27 27 errors::*, 28 28 message::{ 29 29 self, 30 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 30 31 ButtplugMessage, 31 32 ButtplugMessageSpecVersion, 32 33 ButtplugServerMessageV4, 33 34 ErrorV0, 34 35 StopAllDevicesV0, 35 36 StopScanningV0, 36 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 37 37 }, 38 38 util::stream::convert_broadcast_receiver_to_stream, 39 39 }; 40 40 use futures::{ 41 - future::{self, BoxFuture, FutureExt}, 42 41 Stream, 42 + future::{self, BoxFuture, FutureExt}, 43 43 }; 44 44 use once_cell::sync::OnceCell; 45 45 use std::{ 46 46 fmt, 47 47 sync::{ 48 - atomic::{AtomicBool, Ordering}, 49 48 Arc, 49 + atomic::{AtomicBool, Ordering}, 50 50 }, 51 51 }; 52 52 use tokio::sync::broadcast; ··· 124 124 pub fn event_stream(&self) -> impl Stream<Item = ButtplugServerMessageVariant> + use<> { 125 125 let spec_version = self.spec_version.clone(); 126 126 let converter = ButtplugServerMessageConverter::new(None); 127 - let device_indexes: Vec<u32> = self.device_manager.devices().iter().map(|x| *x.key()).collect(); 127 + let device_indexes: Vec<u32> = self 128 + .device_manager 129 + .devices() 130 + .iter() 131 + .map(|x| *x.key()) 132 + .collect(); 128 133 let device_event_converter = ButtplugServerDeviceEventMessageConverter::new(device_indexes); 129 134 self.server_version_event_stream().map(move |m| { 130 135 if let ButtplugServerMessageV4::DeviceList(list) = m { 131 - device_event_converter.convert_device_list(spec_version 132 - .get() 133 - .unwrap_or(&ButtplugMessageSpecVersion::Version4), &list) 136 + device_event_converter.convert_device_list( 137 + spec_version 138 + .get() 139 + .unwrap_or(&ButtplugMessageSpecVersion::Version4), 140 + &list, 141 + ) 134 142 } else { 135 143 // If we get an event and don't have a spec version yet, just throw out the latest. 136 144 converter ··· 289 297 ) -> BoxFuture<'static, Result<ButtplugServerMessageV4, message::ErrorV0>> { 290 298 trace!( 291 299 "Buttplug Server {} received message to client parse: {:?}", 292 - self.server_name, 293 - msg 300 + self.server_name, msg 294 301 ); 295 302 let id = msg.id(); 296 303 if !self.connected() {
+2 -2
crates/buttplug_server/src/server_builder.rs
··· 6 6 // for full license information. 7 7 8 8 use super::{ 9 + ButtplugServerError, 9 10 device::{ServerDeviceManager, ServerDeviceManagerBuilder}, 10 11 ping_timer::PingTimer, 11 12 server::ButtplugServer, 12 - ButtplugServerError, 13 13 }; 14 14 use buttplug_core::{ 15 15 errors::*, ··· 18 18 }; 19 19 use buttplug_server_device_config::DeviceConfigurationManagerBuilder; 20 20 use std::sync::{ 21 - atomic::{AtomicBool, Ordering}, 22 21 Arc, 22 + atomic::{AtomicBool, Ordering}, 23 23 }; 24 24 use tokio::sync::broadcast; 25 25 use tracing_futures::Instrument;
+48 -16
crates/buttplug_server/src/server_message_conversion.rs
··· 19 19 use buttplug_core::{ 20 20 errors::{ButtplugError, ButtplugMessageError}, 21 21 message::{ 22 - ButtplugDeviceMessage, ButtplugMessage, ButtplugMessageSpecVersion, ButtplugServerMessageV4, DeviceListV4, DeviceMessageInfoV4, DeviceRemovedV0, InputTypeData 22 + ButtplugDeviceMessage, 23 + ButtplugMessage, 24 + ButtplugMessageSpecVersion, 25 + ButtplugServerMessageV4, 26 + DeviceListV4, 27 + DeviceMessageInfoV4, 28 + DeviceRemovedV0, 29 + InputTypeData, 23 30 }, 24 31 }; 25 32 ··· 41 48 }; 42 49 43 50 pub struct ButtplugServerDeviceEventMessageConverter { 44 - device_indexes: DashSet<u32> 51 + device_indexes: DashSet<u32>, 45 52 } 46 53 47 54 impl ButtplugServerDeviceEventMessageConverter { 48 55 pub fn new(indexes: Vec<u32>) -> Self { 49 56 let device_indexes = DashSet::new(); 50 - indexes.iter().for_each(|x| { device_indexes.insert(*x); }); 51 - Self { 52 - device_indexes 53 - } 57 + indexes.iter().for_each(|x| { 58 + device_indexes.insert(*x); 59 + }); 60 + Self { device_indexes } 54 61 } 55 62 56 63 // Due to the way we generate device events, we expect every new DeviceList to only have one 57 64 // change currently. 58 - pub fn convert_device_list(&self, version: &ButtplugMessageSpecVersion, list: &DeviceListV4) -> ButtplugServerMessageVariant { 65 + pub fn convert_device_list( 66 + &self, 67 + version: &ButtplugMessageSpecVersion, 68 + list: &DeviceListV4, 69 + ) -> ButtplugServerMessageVariant { 59 70 let new_indexes: Vec<u32> = list.devices().iter().map(|x| *x.0).collect(); 60 71 if new_indexes.len() > self.device_indexes.len() { 61 72 // Device Added 62 - let connected_devices: Vec<&DeviceMessageInfoV4> = list.devices().values().filter(|x| !self.device_indexes.contains(&x.device_index())).collect(); 63 - self.device_indexes.insert(connected_devices[0].device_index()); 73 + let connected_devices: Vec<&DeviceMessageInfoV4> = list 74 + .devices() 75 + .values() 76 + .filter(|x| !self.device_indexes.contains(&x.device_index())) 77 + .collect(); 78 + self 79 + .device_indexes 80 + .insert(connected_devices[0].device_index()); 64 81 if *version == ButtplugMessageSpecVersion::Version4 { 65 82 return ButtplugServerMessageVariant::V4(list.clone().into()); 66 83 } ··· 80 97 return ButtplugServerMessageVariant::V0(ButtplugServerMessageV0::DeviceAdded(da0)); 81 98 } else { 82 99 // Device Removed 83 - let disconnected_indexes: Vec<u32> = self.device_indexes.iter().filter(|x| !new_indexes.contains(x)).map(|x| *x).collect(); 100 + let disconnected_indexes: Vec<u32> = self 101 + .device_indexes 102 + .iter() 103 + .filter(|x| !new_indexes.contains(x)) 104 + .map(|x| *x) 105 + .collect(); 84 106 self.device_indexes.remove(&disconnected_indexes[0]); 85 107 match version { 86 108 ButtplugMessageSpecVersion::Version0 => { 87 - return ButtplugServerMessageVariant::V0(ButtplugServerMessageV0::DeviceRemoved(DeviceRemovedV0::new(disconnected_indexes[0]))) 109 + return ButtplugServerMessageVariant::V0(ButtplugServerMessageV0::DeviceRemoved( 110 + DeviceRemovedV0::new(disconnected_indexes[0]), 111 + )); 88 112 } 89 113 ButtplugMessageSpecVersion::Version1 => { 90 - return ButtplugServerMessageVariant::V1(DeviceRemovedV0::new(disconnected_indexes[0]).into()) 114 + return ButtplugServerMessageVariant::V1( 115 + DeviceRemovedV0::new(disconnected_indexes[0]).into(), 116 + ); 91 117 } 92 118 ButtplugMessageSpecVersion::Version2 => { 93 - return ButtplugServerMessageVariant::V2(DeviceRemovedV0::new(disconnected_indexes[0]).into()) 119 + return ButtplugServerMessageVariant::V2( 120 + DeviceRemovedV0::new(disconnected_indexes[0]).into(), 121 + ); 94 122 } 95 123 ButtplugMessageSpecVersion::Version3 => { 96 - return ButtplugServerMessageVariant::V3(DeviceRemovedV0::new(disconnected_indexes[0]).into()) 124 + return ButtplugServerMessageVariant::V3( 125 + DeviceRemovedV0::new(disconnected_indexes[0]).into(), 126 + ); 127 + } 128 + ButtplugMessageSpecVersion::Version4 => { 129 + return ButtplugServerMessageVariant::V4(list.clone().into()); 97 130 } 98 - ButtplugMessageSpecVersion::Version4 => return ButtplugServerMessageVariant::V4(list.clone().into()), 99 131 } 100 132 } 101 133 // There is no == here because the only way DeviceList would be returned is via a ··· 159 191 msg.device_index(), 160 192 *msg.sensor_index(), 161 193 *msg.sensor_type(), 162 - vec!(value.data() as i32) 194 + vec![value.data() as i32], 163 195 ); 164 196 Ok(msg_out.into()) 165 197 } else {
+30 -15
crates/buttplug_server_device_config/build.rs
··· 1 1 use std::collections::BTreeMap; 2 2 3 - use serde_yaml; 4 - use serde_json::{self, Value}; 5 - use serde::{Serialize, Deserialize}; 6 3 use buttplug_core::util::json::JSONValidator; 4 + use serde::{Deserialize, Serialize}; 5 + use serde_json::{self, Value}; 6 + use serde_yaml; 7 7 8 8 const VERSION_FILE: &str = "./device-config-v4/version.yaml"; 9 9 const OUTPUT_FILE: &str = "./build-config/buttplug-device-config-v4.json"; ··· 12 12 13 13 #[derive(Serialize, Deserialize, Eq, PartialEq)] 14 14 struct VersionFile { 15 - version: BuildVersion 15 + version: BuildVersion, 16 16 } 17 17 18 18 #[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Copy)] 19 19 struct BuildVersion { 20 20 pub major: u32, 21 - pub minor: u32 21 + pub minor: u32, 22 22 } 23 23 24 24 #[derive(Deserialize, Serialize, Eq, PartialEq)] 25 25 struct JsonOutputFile { 26 26 version: BuildVersion, 27 - protocols: BTreeMap<String, Value> 27 + protocols: BTreeMap<String, Value>, 28 28 } 29 29 30 30 fn main() { 31 - println!("cargo:rerun-if-changed={}", PROTOCOL_DIR); 31 + println!("cargo:rerun-if-changed={}", PROTOCOL_DIR); 32 32 33 33 // Open version file 34 - let mut version: VersionFile = serde_yaml::from_str(&std::fs::read_to_string(VERSION_FILE).unwrap()).unwrap(); 34 + let mut version: VersionFile = 35 + serde_yaml::from_str(&std::fs::read_to_string(VERSION_FILE).unwrap()).unwrap(); 35 36 // Bump minor version 36 37 version.version.minor += 1; 37 - 38 + 38 39 // Compile device config file 39 40 let mut output = JsonOutputFile { 40 41 // lol 41 42 version: version.version, 42 - protocols: BTreeMap::new() 43 + protocols: BTreeMap::new(), 43 44 }; 44 45 45 46 for protocol_file in std::fs::read_dir(PROTOCOL_DIR).unwrap() { 46 47 let f = protocol_file.unwrap(); 47 - output.protocols.insert(f.file_name().into_string().unwrap().split(".").next().unwrap().to_owned(), serde_yaml::from_str(&std::fs::read_to_string(f.path()).unwrap()).unwrap()); 48 + output.protocols.insert( 49 + f.file_name() 50 + .into_string() 51 + .unwrap() 52 + .split(".") 53 + .next() 54 + .unwrap() 55 + .to_owned(), 56 + serde_yaml::from_str(&std::fs::read_to_string(f.path()).unwrap()).unwrap(), 57 + ); 48 58 } 49 59 50 60 let json = serde_json::to_string_pretty(&output).unwrap(); ··· 55 65 56 66 // See if it's actually different than our last output file 57 67 if let Ok(true) = std::fs::exists(OUTPUT_FILE) { 58 - let old_output: JsonOutputFile = serde_json::from_str(&std::fs::read_to_string(OUTPUT_FILE).unwrap()).unwrap(); 68 + let old_output: JsonOutputFile = 69 + serde_json::from_str(&std::fs::read_to_string(OUTPUT_FILE).unwrap()).unwrap(); 59 70 if old_output.protocols == output.protocols { 60 71 // No actual changes, break out early, don't save 61 72 return; ··· 63 74 } 64 75 65 76 // Save it to the build_config directory 66 - std::fs::write(VERSION_FILE, serde_yaml::to_string(&version).unwrap().as_bytes()).unwrap(); 67 - std::fs::write(OUTPUT_FILE, json.as_bytes()).unwrap(); 68 - } 77 + std::fs::write( 78 + VERSION_FILE, 79 + serde_yaml::to_string(&version).unwrap().as_bytes(), 80 + ) 81 + .unwrap(); 82 + std::fs::write(OUTPUT_FILE, json.as_bytes()).unwrap(); 83 + }
+6 -2
crates/buttplug_server_device_config/src/device_config_file/base.rs
··· 3 3 use getset::Getters; 4 4 use serde::{Deserialize, Serialize}; 5 5 6 - use crate::device_config_file::{get_internal_config_version, protocol::ProtocolDefinition, ConfigVersion, ConfigVersionGetter}; 7 - 6 + use crate::device_config_file::{ 7 + ConfigVersion, 8 + ConfigVersionGetter, 9 + get_internal_config_version, 10 + protocol::ProtocolDefinition, 11 + }; 8 12 9 13 #[derive(Deserialize, Serialize, Debug, Getters)] 10 14 #[getset(get_mut = "pub", set = "pub")]
+9 -12
crates/buttplug_server_device_config/src/device_config_file/device.rs
··· 31 31 id: config.id(), 32 32 protocol_variant: config.protocol_variant.or(self.protocol_variant.clone()), 33 33 message_gap_ms: config.message_gap_ms.or(self.message_gap_ms), 34 - features: config.features.or(self.features.clone()) 34 + features: config.features.or(self.features.clone()), 35 35 } 36 36 } 37 37 } ··· 56 56 57 57 #[derive(Serialize, Deserialize, Debug, Getters, CopyGetters, Default, Clone, MutGetters)] 58 58 pub struct ConfigUserDeviceCustomization { 59 - #[serde( 60 - default, 61 - skip_serializing_if = "Option::is_none" 62 - )] 59 + #[serde(default, skip_serializing_if = "Option::is_none")] 63 60 #[getset(get = "pub")] 64 61 display_name: Option<String>, 65 62 #[serde(default)] ··· 71 68 #[getset(get_copy = "pub", get_mut = "pub")] 72 69 index: u32, 73 70 #[getset(get_copy = "pub")] 74 - #[serde( 75 - default, 76 - skip_serializing_if = "Option::is_none" 77 - )] 71 + #[serde(default, skip_serializing_if = "Option::is_none")] 78 72 message_gap_ms: Option<u32>, 79 73 } 80 74 ··· 85 79 allow: value.allow(), 86 80 deny: value.deny(), 87 81 index: value.index(), 88 - message_gap_ms: value.message_gap_ms().clone() 82 + message_gap_ms: value.message_gap_ms().clone(), 89 83 } 90 84 } 91 85 } ··· 106 100 } 107 101 108 102 impl ConfigUserDeviceDefinition { 109 - pub fn build_from_base_definition(&self, base: &ServerDeviceDefinition) -> Result<ServerDeviceDefinition, ButtplugDeviceConfigError> { 103 + pub fn build_from_base_definition( 104 + &self, 105 + base: &ServerDeviceDefinition, 106 + ) -> Result<ServerDeviceDefinition, ButtplugDeviceConfigError> { 110 107 let mut builder = ServerDeviceDefinitionBuilder::from_base(&base, self.id); 111 108 if let Some(display_name) = &self.user_config.display_name { 112 109 builder.display_name(display_name); ··· 140 137 user_config: value.into(), 141 138 } 142 139 } 143 - } 140 + }
+13 -13
crates/buttplug_server_device_config/src/device_config_file/feature.rs
··· 18 18 19 19 #[derive(Serialize, Deserialize, Debug, Clone, Default, CopyGetters)] 20 20 pub struct BaseFeatureSettings { 21 - #[serde( 22 - skip_serializing_if = "Option::is_none", 23 - default 24 - )] 21 + #[serde(skip_serializing_if = "Option::is_none", default)] 25 22 #[getset(get_copy = "pub")] 26 23 alt_protocol_index: Option<u32>, 27 24 } ··· 161 158 fn from(value: &ServerDeviceFeatureOutputValueProperties) -> Self { 162 159 Self { 163 160 value: value.value().user().clone(), 164 - disabled: value.disabled() 161 + disabled: value.disabled(), 165 162 } 166 163 } 167 164 } ··· 190 187 } 191 188 } 192 189 193 - 194 - impl From<&ServerDeviceFeatureOutputPositionProperties> for UserDeviceFeatureOutputPositionProperties { 190 + impl From<&ServerDeviceFeatureOutputPositionProperties> 191 + for UserDeviceFeatureOutputPositionProperties 192 + { 195 193 fn from(value: &ServerDeviceFeatureOutputPositionProperties) -> Self { 196 194 Self { 197 195 value: value.position().user().clone(), 198 196 reverse: value.reverse_position(), 199 - disabled: value.disabled() 197 + disabled: value.disabled(), 200 198 } 201 199 } 202 200 } ··· 232 230 } 233 231 } 234 232 235 - impl From<&ServerDeviceFeatureOutputPositionWithDurationProperties> for UserDeviceFeatureOutputPositionWithDurationProperties { 233 + impl From<&ServerDeviceFeatureOutputPositionWithDurationProperties> 234 + for UserDeviceFeatureOutputPositionWithDurationProperties 235 + { 236 236 fn from(value: &ServerDeviceFeatureOutputPositionWithDurationProperties) -> Self { 237 237 Self { 238 238 position: value.position().user().clone(), 239 239 duration: value.duration().user().clone(), 240 240 reverse: value.reverse_position(), 241 - disabled: value.disabled() 241 + disabled: value.disabled(), 242 242 } 243 243 } 244 244 } ··· 346 346 vibrate: value.vibrate().as_ref().map(|x| x.into()), 347 347 rotate: value.rotate().as_ref().map(|x| x.into()), 348 348 rotate_with_direction: value.rotate_with_direction().as_ref().map(|x| x.into()), 349 - oscillate: value.oscillate().as_ref().map(|x| x.into()), 350 - constrict: value.constrict().as_ref().map(|x| x.into()), 349 + oscillate: value.oscillate().as_ref().map(|x| x.into()), 350 + constrict: value.constrict().as_ref().map(|x| x.into()), 351 351 heater: value.heater().as_ref().map(|x| x.into()), 352 352 led: value.led().as_ref().map(|x| x.into()), 353 353 position: value.position().as_ref().map(|x| x.into()), 354 354 position_with_duration: value.position_with_duration().as_ref().map(|x| x.into()), 355 - spray: value.spray().as_ref().map(|x| x.into()) 355 + spray: value.spray().as_ref().map(|x| x.into()), 356 356 } 357 357 } 358 358 }
+7 -2
crates/buttplug_server_device_config/src/device_config_file/mod.rs
··· 228 228 .config() 229 229 .build_from_base_definition(base_config) 230 230 { 231 - if let Err(e) = dcm_builder.user_device_definition(user_device_config_pair.identifier(), &user_config) { 232 - error!("Device definition not valid, skipping:\n{:?}\n{:?}", e, user_config) 231 + if let Err(e) = 232 + dcm_builder.user_device_definition(user_device_config_pair.identifier(), &user_config) 233 + { 234 + error!( 235 + "Device definition not valid, skipping:\n{:?}\n{:?}", 236 + e, user_config 237 + ) 233 238 } 234 239 } 235 240 } else {
+1 -1
crates/buttplug_server_device_config/src/device_config_file/protocol.rs
··· 5 5 6 6 use super::device::ConfigBaseDeviceDefinition; 7 7 8 - use crate::{ProtocolCommunicationSpecifier}; 8 + use crate::ProtocolCommunicationSpecifier; 9 9 10 10 #[derive(Deserialize, Serialize, Debug, Clone, Default, Getters, Setters, MutGetters)] 11 11 #[getset(get = "pub", set = "pub", get_mut = "pub(crate)")]
+8 -2
crates/buttplug_server_device_config/src/device_config_file/user.rs
··· 4 4 5 5 use crate::UserDeviceIdentifier; 6 6 7 - use super::{get_internal_config_version, device::ConfigUserDeviceDefinition, protocol::ProtocolDefinition, ConfigVersion, ConfigVersionGetter}; 7 + use super::{ 8 + ConfigVersion, 9 + ConfigVersionGetter, 10 + device::ConfigUserDeviceDefinition, 11 + get_internal_config_version, 12 + protocol::ProtocolDefinition, 13 + }; 8 14 9 15 #[derive(Deserialize, Serialize, Debug, Clone, Getters, Setters, MutGetters)] 10 16 #[getset(get = "pub", set = "pub", get_mut = "pub(crate)")] ··· 61 67 serde_json::to_string(self) 62 68 .expect("All types below this are Serialize, so this should be infallible.") 63 69 } 64 - } 70 + }
+23 -12
crates/buttplug_server_device_config/src/device_config_manager.rs
··· 1 - 2 1 use buttplug_core::errors::ButtplugDeviceError; 3 2 use dashmap::DashMap; 4 3 use getset::Getters; 5 - use uuid::Uuid; 6 4 use std::{ 7 5 collections::HashMap, 8 6 fmt::{self, Debug}, 9 7 }; 8 + use uuid::Uuid; 10 9 11 - use crate::{BaseDeviceIdentifier, ButtplugDeviceConfigError, ProtocolCommunicationSpecifier, ServerDeviceDefinition, ServerDeviceDefinitionBuilder, UserDeviceIdentifier}; 10 + use crate::{ 11 + BaseDeviceIdentifier, 12 + ButtplugDeviceConfigError, 13 + ProtocolCommunicationSpecifier, 14 + ServerDeviceDefinition, 15 + ServerDeviceDefinitionBuilder, 16 + UserDeviceIdentifier, 17 + }; 12 18 13 19 #[derive(Default, Clone)] 14 20 pub struct DeviceConfigurationManagerBuilder { ··· 67 73 .find(|(_, x)| x.id() == device_definition.base_id().unwrap_or_default()) 68 74 .is_some() 69 75 { 70 - self.user_device_definitions.insert( 71 - identifier.clone(), 72 - device_definition.clone() 73 - ); 76 + self 77 + .user_device_definitions 78 + .insert(identifier.clone(), device_definition.clone()); 74 79 Ok(self) 75 80 } else { 76 81 error!( ··· 78 83 device_definition.base_id(), 79 84 device_definition.id() 80 85 ); 81 - Err(ButtplugDeviceConfigError::BaseIdNotFound(device_definition.id())) 86 + Err(ButtplugDeviceConfigError::BaseIdNotFound( 87 + device_definition.id(), 88 + )) 82 89 } 83 - 84 90 } 85 91 86 92 pub fn finish(&mut self) -> Result<DeviceConfigurationManager, ButtplugDeviceError> { ··· 247 253 index 248 254 } 249 255 250 - pub fn device_definition(&self, identifier: &UserDeviceIdentifier) -> Option<ServerDeviceDefinition> { 256 + pub fn device_definition( 257 + &self, 258 + identifier: &UserDeviceIdentifier, 259 + ) -> Option<ServerDeviceDefinition> { 251 260 let features = if let Some(definition) = self.user_device_definitions.get(identifier) { 252 261 debug!("User device config found for {:?}", identifier); 253 262 definition.clone() ··· 265 274 .base_device_definitions 266 275 .get(&BaseDeviceIdentifier::new(identifier.protocol(), &None)) 267 276 { 268 - debug!("Protocol device config found for {:?}, creating new user device from protocol defaults", identifier); 277 + debug!( 278 + "Protocol device config found for {:?}, creating new user device from protocol defaults", 279 + identifier 280 + ); 269 281 let mut builder = ServerDeviceDefinitionBuilder::from_base(definition, Uuid::new_v4()); 270 282 builder.index(self.device_index(identifier)).finish() 271 283 } else { ··· 285 297 286 298 Some(features) 287 299 } 288 - 289 300 }
+3 -5
crates/buttplug_server_device_config/src/device_definitions.rs
··· 1 1 use getset::{CopyGetters, Getters}; 2 2 use uuid::Uuid; 3 3 4 - use super::server_device_feature::{ 5 - ServerDeviceFeature, 6 - }; 4 + use super::server_device_feature::ServerDeviceFeature; 7 5 #[derive(Debug, Clone, Getters, CopyGetters)] 8 6 pub struct ServerDeviceDefinition { 9 7 #[getset(get = "pub")] ··· 26 24 #[getset(get_copy = "pub")] 27 25 index: u32, 28 26 #[getset(get = "pub")] 29 - features: Vec<ServerDeviceFeature> 27 + features: Vec<ServerDeviceFeature>, 30 28 } 31 29 32 30 pub struct ServerDeviceDefinitionBuilder { ··· 46 44 allow: false, 47 45 deny: false, 48 46 index: 0, 49 - features: vec!() 47 + features: vec![], 50 48 }, 51 49 } 52 50 }
+1 -1
crates/buttplug_server_device_config/src/endpoint.rs
··· 1 1 use serde::{ 2 - de::{self, Visitor}, 3 2 Deserialize, 4 3 Deserializer, 5 4 Serialize, 6 5 Serializer, 6 + de::{self, Visitor}, 7 7 }; 8 8 use std::{ 9 9 fmt::{self, Debug},
+1 -2
crates/buttplug_server_device_config/src/lib.rs
··· 158 158 pub use endpoint::*; 159 159 use uuid::Uuid; 160 160 161 - 162 161 use thiserror::Error; 163 162 164 163 #[derive(Error, Debug)] ··· 182 181 #[error("Output type {0} not available on device")] 183 182 InvalidOutput(OutputType), 184 183 #[error("Float value {0} is not 0 < x < 1")] 185 - InvalidFloatConversion(f64) 184 + InvalidFloatConversion(f64), 186 185 }
+19 -4
crates/buttplug_server_device_config/src/server_device_feature.rs
··· 8 8 use crate::ButtplugDeviceConfigError; 9 9 10 10 use buttplug_core::message::{ 11 - DeviceFeature, DeviceFeatureInput, DeviceFeatureInputBuilder, DeviceFeatureInputProperties, DeviceFeatureOutput, DeviceFeatureOutputBuilder, DeviceFeatureOutputPositionWithDurationProperties, DeviceFeatureOutputValueProperties, InputCommandType, InputType, OutputType 11 + DeviceFeature, 12 + DeviceFeatureInput, 13 + DeviceFeatureInputBuilder, 14 + DeviceFeatureInputProperties, 15 + DeviceFeatureOutput, 16 + DeviceFeatureOutputBuilder, 17 + DeviceFeatureOutputPositionWithDurationProperties, 18 + DeviceFeatureOutputValueProperties, 19 + InputCommandType, 20 + InputType, 21 + OutputType, 12 22 }; 13 23 use getset::{CopyGetters, Getters, Setters}; 14 24 use std::{collections::HashSet, ops::RangeInclusive}; ··· 19 29 /// ranges with negatives (i.e. rotate with direction) are considered to be symettric around 0, we 20 30 /// let the system handle that conversion. 21 31 #[derive(Debug, Clone, Getters)] 22 - #[getset(get = "pub")] 32 + #[getset(get = "pub")] 23 33 pub struct RangeWithLimit { 24 34 base: RangeInclusive<i32>, 25 35 internal_base: RangeInclusive<u32>, ··· 262 272 } 263 273 } 264 274 265 - impl Into<DeviceFeatureOutputPositionWithDurationProperties> for &ServerDeviceFeatureOutputPositionWithDurationProperties { 275 + impl Into<DeviceFeatureOutputPositionWithDurationProperties> 276 + for &ServerDeviceFeatureOutputPositionWithDurationProperties 277 + { 266 278 fn into(self) -> DeviceFeatureOutputPositionWithDurationProperties { 267 - DeviceFeatureOutputPositionWithDurationProperties::new(&self.position().step_limit(), &self.duration().step_limit()) 279 + DeviceFeatureOutputPositionWithDurationProperties::new( 280 + &self.position().step_limit(), 281 + &self.duration().step_limit(), 282 + ) 268 283 } 269 284 } 270 285
+12 -4
crates/buttplug_server_device_config/tests/test_device_config.rs
··· 14 14 &None, 15 15 false, 16 16 ) 17 - .unwrap().finish().unwrap(); 17 + .unwrap() 18 + .finish() 19 + .unwrap(); 18 20 } 19 21 20 22 #[test_case("base_tcode_protocol.json", "user_tcode_protocol.json" ; "TCode Protocol")] ··· 32 34 ), 33 35 false, 34 36 ) 35 - .unwrap().finish().unwrap(); 37 + .unwrap() 38 + .finish() 39 + .unwrap(); 36 40 } 37 41 38 42 #[test] ··· 50 54 ), 51 55 false, 52 56 ) 53 - .unwrap().finish().unwrap(); 54 - let device = dcm.device_definition(&UserDeviceIdentifier::new("COM1", "tcode-v03", &None)).unwrap(); 57 + .unwrap() 58 + .finish() 59 + .unwrap(); 60 + let device = dcm 61 + .device_definition(&UserDeviceIdentifier::new("COM1", "tcode-v03", &None)) 62 + .unwrap(); 55 63 assert_eq!(device.name(), "TCode v0.3 (Single Linear Axis)"); 56 64 }
+4 -2
crates/buttplug_server_hwmgr_btleplug/src/btleplug_adapter_task.rs
··· 15 15 use std::{ 16 16 collections::HashMap, 17 17 sync::{ 18 - atomic::{AtomicBool, Ordering}, 19 18 Arc, 19 + atomic::{AtomicBool, Ordering}, 20 20 }, 21 21 time::Duration, 22 22 }; ··· 206 206 } else { 207 207 if adapter_found { 208 208 self.adapter_connected.store(false, Ordering::Relaxed); 209 - warn!("Bluetooth LE adapter not found, will not be using bluetooth scanning until found. Buttplug will continue polling for the adapter, but no more warning messages will be posted."); 209 + warn!( 210 + "Bluetooth LE adapter not found, will not be using bluetooth scanning until found. Buttplug will continue polling for the adapter, but no more warning messages will be posted." 211 + ); 210 212 } 211 213 continue; 212 214 }
+3 -3
crates/buttplug_server_hwmgr_btleplug/src/btleplug_comm_manager.rs
··· 6 6 // for full license information. 7 7 8 8 use super::btleplug_adapter_task::{BtleplugAdapterCommand, BtleplugAdapterTask}; 9 - use buttplug_core::{errors::ButtplugDeviceError, util::async_manager, ButtplugResultFuture}; 9 + use buttplug_core::{ButtplugResultFuture, errors::ButtplugDeviceError, util::async_manager}; 10 10 use buttplug_server::device::hardware::communication::{ 11 11 HardwareCommunicationManager, 12 12 HardwareCommunicationManagerBuilder, ··· 14 14 }; 15 15 use futures::future::FutureExt; 16 16 use std::sync::{ 17 - atomic::{AtomicBool, Ordering}, 18 17 Arc, 18 + atomic::{AtomicBool, Ordering}, 19 19 }; 20 - use tokio::sync::mpsc::{channel, Sender}; 20 + use tokio::sync::mpsc::{Sender, channel}; 21 21 22 22 #[derive(Default, Clone)] 23 23 pub struct BtlePlugCommunicationManagerBuilder {
+30 -12
crates/buttplug_server_hwmgr_btleplug/src/btleplug_hardware.rs
··· 13 13 }; 14 14 use buttplug_core::{errors::ButtplugDeviceError, util::async_manager}; 15 15 use buttplug_server::device::hardware::{ 16 - communication::HardwareSpecificError, 17 16 Hardware, 18 17 HardwareConnector, 19 18 HardwareEvent, ··· 24 23 HardwareSubscribeCmd, 25 24 HardwareUnsubscribeCmd, 26 25 HardwareWriteCmd, 26 + communication::HardwareSpecificError, 27 27 }; 28 - use buttplug_server_device_config::{BluetoothLESpecifier, ProtocolCommunicationSpecifier, Endpoint}; 28 + use buttplug_server_device_config::{ 29 + BluetoothLESpecifier, 30 + Endpoint, 31 + ProtocolCommunicationSpecifier, 32 + }; 29 33 use dashmap::DashSet; 30 34 use futures::{ 31 - future::{self, BoxFuture, FutureExt}, 32 35 Stream, 33 36 StreamExt, 37 + future::{self, BoxFuture, FutureExt}, 34 38 }; 35 39 use std::{ 36 40 collections::HashMap, ··· 335 339 let characteristic = match self.endpoints.get(&msg.endpoint()) { 336 340 Some(chr) => chr.clone(), 337 341 None => { 338 - return future::ready(Err(ButtplugDeviceError::InvalidEndpoint(msg.endpoint().to_string()))).boxed(); 342 + return future::ready(Err(ButtplugDeviceError::InvalidEndpoint( 343 + msg.endpoint().to_string(), 344 + ))) 345 + .boxed(); 339 346 } 340 347 }; 341 348 ··· 355 362 if write_type == WriteType::WithoutResponse 356 363 && (characteristic.properties & CharPropFlags::WRITE) == CharPropFlags::WRITE 357 364 { 358 - warn!("BTLEPlug device doesn't support write-without-response! Falling back to write-with-response!"); 365 + warn!( 366 + "BTLEPlug device doesn't support write-without-response! Falling back to write-with-response!" 367 + ); 359 368 write_type = WriteType::WithResponse 360 369 } else if write_type == WriteType::WithResponse 361 370 && (characteristic.properties & CharPropFlags::WRITE_WITHOUT_RESPONSE) 362 371 == CharPropFlags::WRITE_WITHOUT_RESPONSE 363 372 { 364 - warn!("BTLEPlug device doesn't support write-with-response! Falling back to write-without-response!"); 373 + warn!( 374 + "BTLEPlug device doesn't support write-with-response! Falling back to write-without-response!" 375 + ); 365 376 write_type = WriteType::WithoutResponse 366 377 } else { 367 378 error!( ··· 381 392 Ok(()) => { 382 393 trace!( 383 394 "Sent write: {:?}, {:?} to {:?}", 384 - data, 385 - write_type, 386 - characteristic 395 + data, write_type, characteristic 387 396 ); 388 397 Ok(()) 389 398 } ··· 408 417 let characteristic = match self.endpoints.get(&msg.endpoint()) { 409 418 Some(chr) => chr.clone(), 410 419 None => { 411 - return future::ready(Err(ButtplugDeviceError::InvalidEndpoint(msg.endpoint().to_string()))).boxed(); 420 + return future::ready(Err(ButtplugDeviceError::InvalidEndpoint( 421 + msg.endpoint().to_string(), 422 + ))) 423 + .boxed(); 412 424 } 413 425 }; 414 426 let device = self.device.clone(); ··· 446 458 let characteristic = match self.endpoints.get(&endpoint) { 447 459 Some(chr) => chr.clone(), 448 460 None => { 449 - return future::ready(Err(ButtplugDeviceError::InvalidEndpoint(msg.endpoint().to_string()))).boxed(); 461 + return future::ready(Err(ButtplugDeviceError::InvalidEndpoint( 462 + msg.endpoint().to_string(), 463 + ))) 464 + .boxed(); 450 465 } 451 466 }; 452 467 let endpoints = self.subscribed_endpoints.clone(); ··· 479 494 let characteristic = match self.endpoints.get(&msg.endpoint()) { 480 495 Some(chr) => chr.clone(), 481 496 None => { 482 - return future::ready(Err(ButtplugDeviceError::InvalidEndpoint(msg.endpoint().to_string()))).boxed(); 497 + return future::ready(Err(ButtplugDeviceError::InvalidEndpoint( 498 + msg.endpoint().to_string(), 499 + ))) 500 + .boxed(); 483 501 } 484 502 }; 485 503 let endpoints = self.subscribed_endpoints.clone();
+5 -5
crates/buttplug_server_hwmgr_hid/src/hid_device_impl.rs
··· 1 1 use super::hidapi_async::HidAsyncDevice; 2 2 use async_trait::async_trait; 3 - use buttplug_core::{errors::ButtplugDeviceError}; 3 + use buttplug_core::errors::ButtplugDeviceError; 4 4 use buttplug_server::device::hardware::{ 5 5 GenericHardwareSpecializer, 6 6 Hardware, ··· 14 14 HardwareUnsubscribeCmd, 15 15 HardwareWriteCmd, 16 16 }; 17 - use buttplug_server_device_config::{ProtocolCommunicationSpecifier, VIDPIDSpecifier, Endpoint}; 18 - use futures::{future::BoxFuture, AsyncWriteExt}; 17 + use buttplug_server_device_config::{Endpoint, ProtocolCommunicationSpecifier, VIDPIDSpecifier}; 18 + use futures::{AsyncWriteExt, future::BoxFuture}; 19 19 use hidapi::{DeviceInfo, HidApi}; 20 20 use std::{ 21 21 fmt::{self, Debug}, 22 22 sync::{ 23 - atomic::{AtomicBool, Ordering}, 24 23 Arc, 24 + atomic::{AtomicBool, Ordering}, 25 25 }, 26 26 }; 27 - use tokio::sync::{broadcast, Mutex}; 27 + use tokio::sync::{Mutex, broadcast}; 28 28 29 29 pub struct HidHardwareConnector { 30 30 hid_instance: Arc<HidApi>,
+3 -3
crates/buttplug_server_hwmgr_lovense_connect/src/lovense_connect_service_hardware.rs
··· 5 5 // Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6 6 // for full license information. 7 7 8 - use super::lovense_connect_service_comm_manager::{get_local_info, LovenseServiceToyInfo}; 8 + use super::lovense_connect_service_comm_manager::{LovenseServiceToyInfo, get_local_info}; 9 9 use async_trait::async_trait; 10 10 use buttplug_core::{errors::ButtplugDeviceError, util::async_manager}; 11 11 use buttplug_server::device::hardware::{ ··· 22 22 HardwareWriteCmd, 23 23 }; 24 24 use buttplug_server_device_config::{ 25 + Endpoint, 25 26 LovenseConnectServiceSpecifier, 26 27 ProtocolCommunicationSpecifier, 27 - Endpoint, 28 28 }; 29 29 use futures::future::{self, BoxFuture, FutureExt}; 30 30 use std::{ 31 31 fmt::{self, Debug}, 32 32 sync::{ 33 - atomic::{AtomicU8, Ordering}, 34 33 Arc, 34 + atomic::{AtomicU8, Ordering}, 35 35 }, 36 36 time::Duration, 37 37 };
+6 -2
crates/buttplug_server_hwmgr_lovense_dongle/src/lovense_dongle_hardware.rs
··· 27 27 HardwareUnsubscribeCmd, 28 28 HardwareWriteCmd, 29 29 }; 30 - use buttplug_server_device_config::{BluetoothLESpecifier, ProtocolCommunicationSpecifier, Endpoint}; 30 + use buttplug_server_device_config::{ 31 + BluetoothLESpecifier, 32 + Endpoint, 33 + ProtocolCommunicationSpecifier, 34 + }; 31 35 use futures::future::{self, BoxFuture, FutureExt}; 32 36 use std::{ 33 37 collections::HashMap, 34 38 fmt::{self, Debug}, 35 39 sync::{ 36 - atomic::{AtomicBool, Ordering}, 37 40 Arc, 41 + atomic::{AtomicBool, Ordering}, 38 42 }, 39 43 time::Duration, 40 44 };
+6 -4
crates/buttplug_server_hwmgr_lovense_dongle/src/lovense_dongle_state_machine.rs
··· 8 8 use super::{lovense_dongle_hardware::*, lovense_dongle_messages::*}; 9 9 use async_trait::async_trait; 10 10 use buttplug_server::device::hardware::communication::HardwareCommunicationManagerEvent; 11 - use futures::{pin_mut, select, FutureExt}; 11 + use futures::{FutureExt, pin_mut, select}; 12 12 use std::sync::{ 13 - atomic::{AtomicBool, Ordering}, 14 13 Arc, 14 + atomic::{AtomicBool, Ordering}, 15 15 }; 16 16 use tokio::{ 17 - sync::mpsc::{channel, Receiver, Sender}, 17 + sync::mpsc::{Receiver, Sender, channel}, 18 18 time::sleep, 19 19 }; 20 20 ··· 248 248 should_scan = true; 249 249 } 250 250 LovenseDeviceCommand::StopScanning => { 251 - debug!("Lovense dongle not found, clearing StartScanning command and emitting ScanningFinished."); 251 + debug!( 252 + "Lovense dongle not found, clearing StartScanning command and emitting ScanningFinished." 253 + ); 252 254 self.is_scanning.store(false, Ordering::Relaxed); 253 255 should_scan = false; 254 256 // If we were requested to scan and then asked to stop, act like we at least tried.
+3 -3
crates/buttplug_server_hwmgr_lovense_dongle/src/lovense_hid_dongle_comm_manager.rs
··· 13 13 }, 14 14 lovense_dongle_state_machine::create_lovense_dongle_machine, 15 15 }; 16 - use buttplug_core::{errors::ButtplugDeviceError, util::async_manager, ButtplugResultFuture}; 16 + use buttplug_core::{ButtplugResultFuture, errors::ButtplugDeviceError, util::async_manager}; 17 17 use buttplug_server::device::hardware::communication::{ 18 18 HardwareCommunicationManager, 19 19 HardwareCommunicationManagerBuilder, ··· 24 24 use serde_json::Deserializer; 25 25 use std::{ 26 26 sync::{ 27 - atomic::{AtomicBool, Ordering}, 28 27 Arc, 28 + atomic::{AtomicBool, Ordering}, 29 29 }, 30 30 thread, 31 31 }; ··· 33 33 runtime, 34 34 select, 35 35 sync::{ 36 - mpsc::{channel, Receiver, Sender}, 37 36 Mutex, 37 + mpsc::{Receiver, Sender, channel}, 38 38 }, 39 39 }; 40 40 use tokio_util::sync::CancellationToken;
+5 -5
crates/buttplug_server_hwmgr_serial/src/serialport_hardware.rs
··· 8 8 use async_trait::async_trait; 9 9 use buttplug_core::{errors::ButtplugDeviceError, util::async_manager}; 10 10 use buttplug_server::device::hardware::{ 11 - communication::HardwareSpecificError, 12 11 Hardware, 13 12 HardwareConnector, 14 13 HardwareEvent, ··· 19 18 HardwareSubscribeCmd, 20 19 HardwareUnsubscribeCmd, 21 20 HardwareWriteCmd, 21 + communication::HardwareSpecificError, 22 22 }; 23 - use buttplug_server_device_config::{ProtocolCommunicationSpecifier, SerialSpecifier, Endpoint}; 23 + use buttplug_server_device_config::{Endpoint, ProtocolCommunicationSpecifier, SerialSpecifier}; 24 24 use futures::future; 25 - use futures::{future::BoxFuture, FutureExt}; 25 + use futures::{FutureExt, future::BoxFuture}; 26 26 use serialport::{SerialPort, SerialPortInfo}; 27 27 use std::{ 28 28 fmt::{self, Debug}, 29 29 io::ErrorKind, 30 30 sync::{ 31 - atomic::{AtomicBool, Ordering}, 32 31 Arc, 32 + atomic::{AtomicBool, Ordering}, 33 33 }, 34 34 thread, 35 35 time::Duration, 36 36 }; 37 - use tokio::sync::{broadcast, mpsc, Mutex}; 37 + use tokio::sync::{Mutex, broadcast, mpsc}; 38 38 use tokio_util::sync::CancellationToken; 39 39 40 40 pub struct SerialPortHardwareConnector {
+1 -1
crates/buttplug_server_hwmgr_websocket/src/websocket_server_comm_manager.rs
··· 6 6 // for full license information. 7 7 8 8 use super::websocket_server_hardware::WebsocketServerHardwareConnector; 9 - use buttplug_core::{util::async_manager, ButtplugResultFuture}; 9 + use buttplug_core::{ButtplugResultFuture, util::async_manager}; 10 10 use buttplug_server::device::hardware::communication::{ 11 11 HardwareCommunicationManager, 12 12 HardwareCommunicationManagerBuilder,
+4 -4
crates/buttplug_server_hwmgr_websocket/src/websocket_server_hardware.rs
··· 23 23 }; 24 24 use buttplug_server_device_config::{Endpoint, ProtocolCommunicationSpecifier, WebsocketSpecifier}; 25 25 use futures::{ 26 - future::{self, BoxFuture}, 27 26 FutureExt, 28 27 SinkExt, 29 28 StreamExt, 29 + future::{self, BoxFuture}, 30 30 }; 31 31 use std::{ 32 32 fmt::{self, Debug}, 33 33 sync::{ 34 - atomic::{AtomicBool, Ordering}, 35 34 Arc, 35 + atomic::{AtomicBool, Ordering}, 36 36 }, 37 37 time::Duration, 38 38 }; ··· 40 40 net::TcpStream, 41 41 select, 42 42 sync::{ 43 - broadcast, 44 - mpsc::{channel, Receiver, Sender}, 45 43 Mutex, 44 + broadcast, 45 + mpsc::{Receiver, Sender, channel}, 46 46 }, 47 47 time::sleep, 48 48 };
+2 -2
crates/buttplug_server_hwmgr_xinput/src/xinput_hardware.rs
··· 9 9 use async_trait::async_trait; 10 10 use buttplug_core::{errors::ButtplugDeviceError, util::async_manager}; 11 11 use buttplug_server::device::hardware::{ 12 - communication::HardwareSpecificError, 13 12 GenericHardwareSpecializer, 14 13 Hardware, 15 14 HardwareConnector, ··· 21 20 HardwareSubscribeCmd, 22 21 HardwareUnsubscribeCmd, 23 22 HardwareWriteCmd, 23 + communication::HardwareSpecificError, 24 24 }; 25 - use buttplug_server_device_config::{ProtocolCommunicationSpecifier, XInputSpecifier, Endpoint}; 25 + use buttplug_server_device_config::{Endpoint, ProtocolCommunicationSpecifier, XInputSpecifier}; 26 26 use byteorder::{LittleEndian, ReadBytesExt}; 27 27 use futures::future::{self, BoxFuture, FutureExt}; 28 28 use rusty_xinput::{XInputHandle, XInputUsageError};
+12 -16
crates/buttplug_tests/tests/test_client_device.rs
··· 7 7 8 8 mod util; 9 9 use buttplug_client::{ButtplugClientDeviceEvent, ButtplugClientError, ButtplugClientEvent}; 10 - use buttplug_core::{ 11 - errors::ButtplugError, 12 - message::{OutputType,}, 13 - util::async_manager 14 - }; 15 - use buttplug_server_device_config::{load_protocol_configs, ServerDeviceDefinition, UserDeviceIdentifier, ServerDeviceFeature, ServerDeviceFeatureOutput, Endpoint}; 16 - use buttplug_server::{ 17 - device::{ 18 - hardware::{HardwareCommand, HardwareWriteCmd}, 19 - }, 10 + use buttplug_core::{errors::ButtplugError, message::OutputType, util::async_manager}; 11 + use buttplug_server::device::hardware::{HardwareCommand, HardwareWriteCmd}; 12 + use buttplug_server_device_config::{ 13 + Endpoint, 14 + ServerDeviceDefinition, 15 + ServerDeviceFeature, 16 + ServerDeviceFeatureOutput, 17 + UserDeviceIdentifier, 18 + load_protocol_configs, 20 19 }; 21 20 use futures::StreamExt; 22 21 use std::{collections::HashMap, sync::Arc, time::Duration}; 23 22 use tokio::time::sleep; 24 - use util::test_device_manager::{check_test_recv_value, TestDeviceIdentifier}; 23 + use util::test_device_manager::{TestDeviceIdentifier, check_test_recv_value}; 25 24 use util::{ 26 25 test_client_with_device, 27 26 test_client_with_device_and_custom_dcm, ··· 66 65 assert!(!client.connected()); 67 66 } 68 67 69 - 70 68 #[tokio::test] 71 69 async fn test_client_device_client_disconnected_status() { 72 70 let (client, _) = test_client_with_device().await; ··· 103 101 } 104 102 } 105 103 } 106 - 107 104 108 105 #[tokio::test] 109 106 async fn test_client_device_connected_no_event_listener() { ··· 128 125 sleep(Duration::from_millis(100)).await; 129 126 } 130 127 131 - 132 128 #[tokio::test] 133 129 async fn test_client_device_invalid_command() { 134 130 use buttplug_core::errors::ButtplugDeviceError; ··· 150 146 151 147 assert!(matches!( 152 148 test_device.vibrate(1000).await.unwrap_err(), 153 - ButtplugClientError::ButtplugOutputCommandConversionError(_)) 154 - ); 149 + ButtplugClientError::ButtplugOutputCommandConversionError(_) 150 + )); 155 151 } 156 152 157 153 /*
+24 -24
crates/buttplug_tests/tests/test_device_config.rs
··· 84 84 } 85 85 "#; 86 86 87 - 88 87 #[tokio::test] 89 88 async fn test_valid_null_version_config() { 90 89 assert_ok!(load_protocol_configs( ··· 93 92 false 94 93 )); 95 94 } 96 - 97 95 98 96 #[tokio::test] 99 97 async fn test_valid_null_user_config() { ··· 103 101 false 104 102 )); 105 103 } 106 - 107 104 108 105 #[tokio::test] 109 106 async fn test_invalid_null_version_config() { 110 - assert!(load_protocol_configs( 111 - &None, 112 - &Some(BASE_INVALID_VERSION_CONFIG_JSON.to_owned()), 113 - false 114 - ) 115 - .is_err()); 107 + assert!( 108 + load_protocol_configs( 109 + &None, 110 + &Some(BASE_INVALID_VERSION_CONFIG_JSON.to_owned()), 111 + false 112 + ) 113 + .is_err() 114 + ); 116 115 } 117 - 118 116 119 117 #[tokio::test] 120 118 #[ignore = "Still need to update for new message format"] 121 119 async fn test_basic_device_config() { 122 120 assert!(load_protocol_configs(&Some(BASE_CONFIG_JSON.to_owned()), &None, false).is_ok()); 123 121 } 124 - 125 122 126 123 #[tokio::test] 127 124 async fn test_valid_user_config() { ··· 184 181 ] 185 182 } 186 183 }"#; 187 - assert!(load_protocol_configs( 188 - &Some(BASE_CONFIG_JSON.to_owned()), 189 - &Some(user_config_json.to_owned()), 190 - false 191 - ) 192 - .is_err()); 184 + assert!( 185 + load_protocol_configs( 186 + &Some(BASE_CONFIG_JSON.to_owned()), 187 + &Some(user_config_json.to_owned()), 188 + false 189 + ) 190 + .is_err() 191 + ); 193 192 } 194 - 195 193 196 194 #[tokio::test] 197 195 async fn test_invalid_step_range_device_config_wrong_range_length() { ··· 250 248 } 251 249 } 252 250 "#; 253 - assert!(load_protocol_configs( 254 - &Some(BASE_CONFIG_JSON.to_owned()), 255 - &Some(user_config_json.to_owned()), 256 - false 257 - ) 258 - .is_err()); 251 + assert!( 252 + load_protocol_configs( 253 + &Some(BASE_CONFIG_JSON.to_owned()), 254 + &Some(user_config_json.to_owned()), 255 + false 256 + ) 257 + .is_err() 258 + ); 259 259 } 260 260 261 261 #[tokio::test]
+1 -2
crates/buttplug_tests/tests/test_device_protocols.rs
··· 500 500 util::device_test::client::client_v3::run_json_test_case(&load_test_case(test_file).await).await; 501 501 } 502 502 503 - 504 503 /* 505 504 //#[test_case("test_cowgirl_cone_protocol.yaml" ; "The Cowgirl Cone Protocol")] 506 505 #[test_case("test_activejoy_protocol.yaml" ; "ActiveJoy Protocol")] ··· 735 734 async fn test_device_protocols_json_v2(test_file: &str) { 736 735 util::device_test::client::client_v2::run_json_test_case(&load_test_case(test_file).await).await; 737 736 } 738 - */ 737 + */
+7 -7
crates/buttplug_tests/tests/test_message_downgrades.rs
··· 12 12 pub use util::test_device_manager::check_test_recv_value; 13 13 14 14 use buttplug_core::message::{ 15 - serializer::{ButtplugMessageSerializer, ButtplugSerializedMessage}, 16 - StartScanningV0, 17 - }; 15 + StartScanningV0, 16 + serializer::{ButtplugMessageSerializer, ButtplugSerializedMessage}, 17 + }; 18 18 use buttplug_server::{ 19 - device::hardware::{HardwareCommand, HardwareWriteCmd}, 20 - message::{serializer::ButtplugServerJSONSerializer, ButtplugClientMessageVariant}, 21 - ButtplugServerBuilder, 19 + ButtplugServerBuilder, 20 + device::hardware::{HardwareCommand, HardwareWriteCmd}, 21 + message::{ButtplugClientMessageVariant, serializer::ButtplugServerJSONSerializer}, 22 22 }; 23 - use futures::{pin_mut, StreamExt}; 23 + use futures::{StreamExt, pin_mut}; 24 24 use util::test_server_with_device; 25 25 use uuid::Uuid; 26 26
+15 -15
crates/buttplug_tests/tests/test_serializers.rs
··· 9 9 10 10 use buttplug_client::ButtplugClientError; 11 11 use buttplug_core::{ 12 - connector::transport::ButtplugTransportIncomingMessage, 13 - errors::{ButtplugError, ButtplugUnknownError}, 14 - message::{ 15 - serializer::ButtplugSerializedMessage, 16 - ButtplugClientMessageV4, 17 - ButtplugMessage, 18 - ButtplugServerMessageV4, 19 - ErrorV0, 20 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 21 - }, 12 + connector::transport::ButtplugTransportIncomingMessage, 13 + errors::{ButtplugError, ButtplugUnknownError}, 14 + message::{ 15 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 16 + ButtplugClientMessageV4, 17 + ButtplugMessage, 18 + ButtplugServerMessageV4, 19 + ErrorV0, 20 + serializer::ButtplugSerializedMessage, 21 + }, 22 22 util::async_manager, 23 - }; 23 + }; 24 24 use buttplug_server::message::{ 25 - ButtplugClientMessageVariant, 26 - ButtplugServerMessageVariant, 27 - DeviceListV3, 28 - ServerInfoV2, 25 + ButtplugClientMessageVariant, 26 + ButtplugServerMessageVariant, 27 + DeviceListV3, 28 + ServerInfoV2, 29 29 }; 30 30 use std::sync::Arc; 31 31 use tokio::sync::Notify;
+72 -64
crates/buttplug_tests/tests/test_server.rs
··· 11 11 pub use util::{ 12 12 create_test_dcm, 13 13 test_device_manager::{ 14 - check_test_recv_value, 15 14 TestDeviceCommunicationManagerBuilder, 16 15 TestDeviceIdentifier, 16 + check_test_recv_value, 17 17 }, 18 18 test_server_with_comm_manager, 19 19 test_server_with_device, 20 20 }; 21 21 22 22 use buttplug_core::{ 23 - errors::{ButtplugDeviceError, ButtplugError, ButtplugHandshakeError}, 24 - message::{ 25 - OutputCmdV4, 26 - OutputCommand, 27 - OutputValue, 28 - ButtplugClientMessageV4, 29 - ButtplugMessageSpecVersion, 30 - ButtplugServerMessageV4, 31 - ErrorCode, 32 - PingV0, 33 - RequestServerInfoV4, 34 - ServerInfoV4, 35 - StartScanningV0, 36 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 37 - BUTTPLUG_CURRENT_API_MINOR_VERSION, 38 - }, 39 - }; 23 + errors::{ButtplugDeviceError, ButtplugError, ButtplugHandshakeError}, 24 + message::{ 25 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 26 + BUTTPLUG_CURRENT_API_MINOR_VERSION, 27 + ButtplugClientMessageV4, 28 + ButtplugMessageSpecVersion, 29 + ButtplugServerMessageV4, 30 + ErrorCode, 31 + OutputCmdV4, 32 + OutputCommand, 33 + OutputValue, 34 + PingV0, 35 + RequestServerInfoV4, 36 + ServerInfoV4, 37 + StartScanningV0, 38 + }, 39 + }; 40 40 use buttplug_server::{ 41 - device::{ 42 - hardware::{HardwareCommand, HardwareWriteCmd}, 43 - ServerDeviceManagerBuilder, 44 - }, 45 - message::{ 46 - checked_output_cmd::CheckedOutputCmdV4, 47 - spec_enums::ButtplugCheckedClientMessageV4, 48 - ButtplugClientMessageV3, 49 - ButtplugClientMessageVariant, 50 - ButtplugServerMessageV2, 51 - ButtplugServerMessageV3, 52 - ButtplugServerMessageVariant, 53 - RequestServerInfoV1, 54 - ServerInfoV2, 55 - }, 56 - ButtplugServer, 57 - ButtplugServerBuilder, 41 + ButtplugServer, 42 + ButtplugServerBuilder, 43 + device::{ 44 + ServerDeviceManagerBuilder, 45 + hardware::{HardwareCommand, HardwareWriteCmd}, 46 + }, 47 + message::{ 48 + ButtplugClientMessageV3, 49 + ButtplugClientMessageVariant, 50 + ButtplugServerMessageV2, 51 + ButtplugServerMessageV3, 52 + ButtplugServerMessageVariant, 53 + RequestServerInfoV1, 54 + ServerInfoV2, 55 + checked_output_cmd::CheckedOutputCmdV4, 56 + spec_enums::ButtplugCheckedClientMessageV4, 57 + }, 58 58 }; 59 - use futures::{pin_mut, Stream, StreamExt}; 59 + use futures::{Stream, StreamExt, pin_mut}; 60 60 use std::time::Duration; 61 61 use tokio::time::sleep; 62 62 use uuid::Uuid; ··· 356 356 357 357 let recv = server.server_version_event_stream(); 358 358 pin_mut!(recv); 359 - assert!(server 360 - .parse_checked_message( 361 - RequestServerInfoV4::new( 362 - "Test Client", 363 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 364 - BUTTPLUG_CURRENT_API_MINOR_VERSION 359 + assert!( 360 + server 361 + .parse_checked_message( 362 + RequestServerInfoV4::new( 363 + "Test Client", 364 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 365 + BUTTPLUG_CURRENT_API_MINOR_VERSION 366 + ) 367 + .into() 365 368 ) 366 - .into() 367 - ) 368 - .await 369 - .is_ok()); 370 - assert!(server 371 - .parse_checked_message(StartScanningV0::default().into()) 372 - .await 373 - .is_ok()); 369 + .await 370 + .is_ok() 371 + ); 372 + assert!( 373 + server 374 + .parse_checked_message(StartScanningV0::default().into()) 375 + .await 376 + .is_ok() 377 + ); 374 378 // Check that we got an event back about a new device. 375 379 let mut index = 0u32; 376 380 while let Some(msg) = recv.next().await { ··· 407 411 408 412 let recv = server.server_version_event_stream(); 409 413 pin_mut!(recv); 410 - assert!(server 411 - .parse_checked_message( 412 - RequestServerInfoV4::new( 413 - "Test Client", 414 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 415 - BUTTPLUG_CURRENT_API_MINOR_VERSION 414 + assert!( 415 + server 416 + .parse_checked_message( 417 + RequestServerInfoV4::new( 418 + "Test Client", 419 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 420 + BUTTPLUG_CURRENT_API_MINOR_VERSION 421 + ) 422 + .into() 416 423 ) 417 - .into() 418 - ) 419 - .await 420 - .is_ok()); 421 - assert!(server 422 - .parse_checked_message(StartScanningV0::default().into()) 423 - .await 424 - .is_ok()); 424 + .await 425 + .is_ok() 426 + ); 427 + assert!( 428 + server 429 + .parse_checked_message(StartScanningV0::default().into()) 430 + .await 431 + .is_ok() 432 + ); 425 433 // Check that we got an event back about a new device. 426 434 let mut count = 0u32; 427 435 let mut finish_received = false;
+8 -13
crates/buttplug_tests/tests/test_server_device.rs
··· 6 6 // for full license information. 7 7 8 8 mod util; 9 - use buttplug_core::{ 10 - message::{ 11 - ButtplugServerMessageV4, 12 - RequestServerInfoV4, 13 - StartScanningV0, 14 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 15 - BUTTPLUG_CURRENT_API_MINOR_VERSION, 16 - }, 17 - }; 18 - use buttplug_server::message::{ 19 - ButtplugClientMessageVariant, 20 - ButtplugServerMessageVariant, 9 + use buttplug_core::message::{ 10 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 11 + BUTTPLUG_CURRENT_API_MINOR_VERSION, 12 + ButtplugServerMessageV4, 13 + RequestServerInfoV4, 14 + StartScanningV0, 21 15 }; 16 + use buttplug_server::message::{ButtplugClientMessageVariant, ButtplugServerMessageVariant}; 22 17 23 - use futures::{pin_mut, StreamExt}; 18 + use futures::{StreamExt, pin_mut}; 24 19 pub use util::test_device_manager::TestDeviceCommunicationManagerBuilder; 25 20 use util::test_server_with_device; 26 21
+1 -1
crates/buttplug_tests/tests/test_websocket_device_comm_manager.rs
··· 11 11 mod test { 12 12 13 13 use buttplug::{ 14 - client::connector::ButtplugInProcessClientConnectorBuilder, 15 14 client::ButtplugClient, 15 + client::connector::ButtplugInProcessClientConnectorBuilder, 16 16 server::device::hardware::communication::websocket_server::websocket_server_comm_manager::WebsocketServerDeviceCommunicationManagerBuilder, 17 17 }; 18 18
+29 -30
crates/buttplug_tests/tests/util/channel_transport.rs
··· 9 9 10 10 use crate::util::ButtplugTestServer; 11 11 use buttplug_client::{ 12 - connector::ButtplugRemoteClientConnector, 13 - serializer::ButtplugClientJSONSerializer, 14 - ButtplugClient, 15 - ButtplugClientError, 16 - }; 12 + ButtplugClient, 13 + ButtplugClientError, 14 + connector::ButtplugRemoteClientConnector, 15 + serializer::ButtplugClientJSONSerializer, 16 + }; 17 17 use buttplug_core::{ 18 - connector::{ 19 - transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 20 - ButtplugConnectorError, 21 - }, 22 - message::{ 23 - serializer::{ButtplugMessageSerializer, ButtplugSerializedMessage}, 24 - ButtplugClientMessageV4, 25 - ButtplugMessage, 26 - DeviceListV4, 27 - RequestServerInfoV4, 28 - ServerInfoV4, 29 - BUTTPLUG_CURRENT_API_MAJOR_VERSION, 30 - BUTTPLUG_CURRENT_API_MINOR_VERSION, 31 - }, 32 - util::async_manager, 33 - 34 - }; 18 + connector::{ 19 + ButtplugConnectorError, 20 + transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 21 + }, 22 + message::{ 23 + BUTTPLUG_CURRENT_API_MAJOR_VERSION, 24 + BUTTPLUG_CURRENT_API_MINOR_VERSION, 25 + ButtplugClientMessageV4, 26 + ButtplugMessage, 27 + DeviceListV4, 28 + RequestServerInfoV4, 29 + ServerInfoV4, 30 + serializer::{ButtplugMessageSerializer, ButtplugSerializedMessage}, 31 + }, 32 + util::async_manager, 33 + }; 35 34 use buttplug_server::{ 36 - connector::ButtplugRemoteServerConnector, 37 - message::{ 38 - serializer::ButtplugServerJSONSerializer, 39 - ButtplugClientMessageVariant, 40 - ButtplugServerMessageVariant, 41 - }, 35 + connector::ButtplugRemoteServerConnector, 36 + message::{ 37 + ButtplugClientMessageVariant, 38 + ButtplugServerMessageVariant, 39 + serializer::ButtplugServerJSONSerializer, 40 + }, 42 41 }; 43 42 use futures::{ 43 + FutureExt, 44 44 future::{self, BoxFuture}, 45 45 select, 46 - FutureExt, 47 46 }; 48 47 use log::*; 49 48 use std::sync::Arc; 50 49 use tokio::sync::{ 51 - mpsc::{channel, Receiver, Sender}, 52 50 Mutex, 53 51 Notify, 52 + mpsc::{Receiver, Sender, channel}, 54 53 }; 55 54 56 55 struct ChannelTransport {
+4 -4
crates/buttplug_tests/tests/util/delay_device_communication_manager.rs
··· 7 7 8 8 use buttplug_core::ButtplugResultFuture; 9 9 use buttplug_server::device::hardware::communication::{ 10 - HardwareCommunicationManager, 11 - HardwareCommunicationManagerBuilder, 12 - HardwareCommunicationManagerEvent, 10 + HardwareCommunicationManager, 11 + HardwareCommunicationManagerBuilder, 12 + HardwareCommunicationManagerEvent, 13 13 }; 14 14 use futures::FutureExt; 15 15 use std::sync::{ 16 - atomic::{AtomicBool, Ordering}, 17 16 Arc, 17 + atomic::{AtomicBool, Ordering}, 18 18 }; 19 19 use tokio::sync::mpsc::Sender; 20 20
+19 -15
crates/buttplug_tests/tests/util/device_test/client/client_v2/client.rs
··· 9 9 10 10 use super::client_event_loop::{ButtplugClientEventLoop, ButtplugClientRequest}; 11 11 use super::device::ButtplugClientDevice; 12 - use buttplug_server::message::{RequestServerInfoV1, ButtplugClientMessageV2, ButtplugServerMessageV2}; 13 12 use buttplug_core::{ 14 - connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorFuture}, 15 - errors::{ButtplugError, ButtplugHandshakeError}, 16 - message::{ 17 - ButtplugMessageSpecVersion, 18 - PingV0, 19 - RequestDeviceListV0, 20 - StartScanningV0, 21 - StopAllDevicesV0, 22 - StopScanningV0, 23 - }, 13 + connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorFuture}, 14 + errors::{ButtplugError, ButtplugHandshakeError}, 15 + message::{ 16 + ButtplugMessageSpecVersion, 17 + PingV0, 18 + RequestDeviceListV0, 19 + StartScanningV0, 20 + StopAllDevicesV0, 21 + StopScanningV0, 22 + }, 24 23 util::{ 25 24 async_manager, 26 25 future::{ButtplugFuture, ButtplugFutureStateShared}, 27 26 stream::convert_broadcast_receiver_to_stream, 28 27 }, 28 + }; 29 + use buttplug_server::message::{ 30 + ButtplugClientMessageV2, 31 + ButtplugServerMessageV2, 32 + RequestServerInfoV1, 29 33 }; 30 34 use dashmap::DashMap; 31 35 use futures::{ 32 - future::{self, BoxFuture}, 33 36 Stream, 37 + future::{self, BoxFuture}, 34 38 }; 35 39 use log::*; 36 40 use std::sync::{ 37 - atomic::{AtomicBool, Ordering}, 38 41 Arc, 42 + atomic::{AtomicBool, Ordering}, 39 43 }; 40 44 use thiserror::Error; 41 - use tokio::sync::{broadcast, mpsc, Mutex}; 42 - use tracing::{span, Level, Span}; 45 + use tokio::sync::{Mutex, broadcast, mpsc}; 46 + use tracing::{Level, Span, span}; 43 47 use tracing_futures::Instrument; 44 48 45 49 /// Result type used for public APIs.
+9 -9
crates/buttplug_tests/tests/util/device_test/client/client_v2/client_event_loop.rs
··· 13 13 device::{ButtplugClientDevice, ButtplugClientDeviceEvent}, 14 14 }; 15 15 use buttplug_core::{ 16 - connector::{ButtplugConnector, ButtplugConnectorStateShared}, 17 - errors::{ButtplugDeviceError, ButtplugError}, 18 - message::ButtplugMessageValidator, 19 - }; 16 + connector::{ButtplugConnector, ButtplugConnectorStateShared}, 17 + errors::{ButtplugDeviceError, ButtplugError}, 18 + message::ButtplugMessageValidator, 19 + }; 20 20 use buttplug_server::message::{ 21 - ButtplugClientMessageV2, 22 - ButtplugServerMessageV2, 23 - DeviceListV2, 24 - DeviceMessageInfoV2, 21 + ButtplugClientMessageV2, 22 + ButtplugServerMessageV2, 23 + DeviceListV2, 24 + DeviceMessageInfoV2, 25 25 }; 26 26 use dashmap::DashMap; 27 27 use log::*; 28 28 use std::sync::{ 29 - atomic::{AtomicBool, Ordering}, 30 29 Arc, 30 + atomic::{AtomicBool, Ordering}, 31 31 }; 32 32 use tokio::sync::{broadcast, mpsc}; 33 33
+1 -1
crates/buttplug_tests/tests/util/device_test/client/client_v2/client_message_sorter.rs
··· 17 17 use dashmap::DashMap; 18 18 use log::*; 19 19 use std::sync::{ 20 - atomic::{AtomicU32, Ordering}, 21 20 Arc, 21 + atomic::{AtomicU32, Ordering}, 22 22 }; 23 23 24 24 /// Message sorting and pairing for remote client connectors.
+18 -18
crates/buttplug_tests/tests/util/device_test/client/client_v2/device.rs
··· 17 17 client_event_loop::ButtplugClientRequest, 18 18 }; 19 19 use buttplug_core::{ 20 - connector::ButtplugConnectorError, 21 - errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError}, 22 - message::{ButtplugMessage, StopDeviceCmdV0}, 23 - util::stream::convert_broadcast_receiver_to_stream, 20 + connector::ButtplugConnectorError, 21 + errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError}, 22 + message::{ButtplugMessage, StopDeviceCmdV0}, 23 + util::stream::convert_broadcast_receiver_to_stream, 24 24 }; 25 25 use buttplug_server::message::{ 26 - BatteryLevelCmdV2, 27 - ButtplugClientMessageV2, 28 - ButtplugDeviceMessageNameV2, 29 - ButtplugServerMessageV2, 30 - ClientDeviceMessageAttributesV2, 31 - DeviceMessageInfoV2, 32 - LinearCmdV1, 33 - RotateCmdV1, 34 - RotationSubcommandV1, 35 - VectorSubcommandV1, 36 - VibrateCmdV1, 37 - VibrateSubcommandV1, 26 + BatteryLevelCmdV2, 27 + ButtplugClientMessageV2, 28 + ButtplugDeviceMessageNameV2, 29 + ButtplugServerMessageV2, 30 + ClientDeviceMessageAttributesV2, 31 + DeviceMessageInfoV2, 32 + LinearCmdV1, 33 + RotateCmdV1, 34 + RotationSubcommandV1, 35 + VectorSubcommandV1, 36 + VibrateCmdV1, 37 + VibrateSubcommandV1, 38 38 }; 39 - use futures::{future, Stream}; 39 + use futures::{Stream, future}; 40 40 use getset::Getters; 41 41 use log::*; 42 42 use std::{ 43 43 collections::HashMap, 44 44 fmt, 45 45 sync::{ 46 - atomic::{AtomicBool, Ordering}, 47 46 Arc, 47 + atomic::{AtomicBool, Ordering}, 48 48 }, 49 49 }; 50 50 use tokio::sync::broadcast;
+10 -13
crates/buttplug_tests/tests/util/device_test/client/client_v2/in_process_connector.rs
··· 8 8 //! In-process communication between clients and servers 9 9 10 10 use buttplug_core::{ 11 - connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorResultFuture}, 12 - errors::{ButtplugError, ButtplugMessageError}, 13 - util::async_manager, 14 - }; 11 + connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorResultFuture}, 12 + errors::{ButtplugError, ButtplugMessageError}, 13 + util::async_manager, 14 + }; 15 15 use buttplug_server::{ 16 - message::{ButtplugClientMessageV2, ButtplugServerMessageV2, ButtplugServerMessageVariant}, 17 - ButtplugServer, 18 - ButtplugServerBuilder, 16 + ButtplugServer, 17 + ButtplugServerBuilder, 18 + message::{ButtplugClientMessageV2, ButtplugServerMessageV2, ButtplugServerMessageVariant}, 19 19 }; 20 20 use futures::{ 21 + StreamExt, 21 22 future::{self, BoxFuture, FutureExt}, 22 23 pin_mut, 23 - StreamExt, 24 24 }; 25 25 use log::*; 26 26 use std::sync::{ 27 - atomic::{AtomicBool, Ordering}, 28 27 Arc, 28 + atomic::{AtomicBool, Ordering}, 29 29 }; 30 - use tokio::sync::mpsc::{channel, Sender}; 30 + use tokio::sync::mpsc::{Sender, channel}; 31 31 use tracing_futures::Instrument; 32 32 33 33 #[derive(Default)] ··· 75 75 connected: Arc<AtomicBool>, 76 76 } 77 77 78 - 79 78 impl Default for ButtplugInProcessClientConnector { 80 79 fn default() -> Self { 81 80 ButtplugInProcessClientConnectorBuilder::default().finish() 82 81 } 83 82 } 84 - 85 83 86 84 impl ButtplugInProcessClientConnector { 87 85 /// Creates a new in-process connector, with a server instance. ··· 103 101 } 104 102 } 105 103 } 106 - 107 104 108 105 impl ButtplugConnector<ButtplugClientMessageV2, ButtplugServerMessageV2> 109 106 for ButtplugInProcessClientConnector
+2 -2
crates/buttplug_tests/tests/util/device_test/client/client_v2/mod.rs
··· 5 5 mod in_process_connector; 6 6 7 7 use crate::util::{ 8 - device_test::connector::build_channel_connector_v2, 9 8 ButtplugTestServer, 10 9 TestDeviceChannelHost, 10 + device_test::connector::build_channel_connector_v2, 11 11 }; 12 - use buttplug_server::{device::ServerDeviceManagerBuilder, ButtplugServer, ButtplugServerBuilder}; 13 12 use buttplug_core::util::async_manager; 13 + use buttplug_server::{ButtplugServer, ButtplugServerBuilder, device::ServerDeviceManagerBuilder}; 14 14 use buttplug_server_device_config::load_protocol_configs; 15 15 16 16 use client::{ButtplugClient, ButtplugClientEvent};
+19 -14
crates/buttplug_tests/tests/util/device_test/client/client_v3/client.rs
··· 8 8 use super::client_event_loop::{ButtplugClientEventLoop, ButtplugClientRequest}; 9 9 pub use super::device::ButtplugClientDevice; 10 10 use buttplug_core::{ 11 - connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorFuture}, 12 - errors::{ButtplugError, ButtplugHandshakeError}, 13 - message::{ 14 - ButtplugMessageSpecVersion, 15 - PingV0, 16 - RequestDeviceListV0, 17 - StartScanningV0, 18 - StopAllDevicesV0, 19 - StopScanningV0, 20 - }, util::{ 11 + connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorFuture}, 12 + errors::{ButtplugError, ButtplugHandshakeError}, 13 + message::{ 14 + ButtplugMessageSpecVersion, 15 + PingV0, 16 + RequestDeviceListV0, 17 + StartScanningV0, 18 + StopAllDevicesV0, 19 + StopScanningV0, 20 + }, 21 + util::{ 21 22 async_manager, 22 23 future::{ButtplugFuture, ButtplugFutureStateShared}, 23 24 stream::convert_broadcast_receiver_to_stream, 24 25 }, 25 26 }; 26 - use buttplug_server::message::{ButtplugClientMessageV3, ButtplugServerMessageV3, RequestServerInfoV1}; 27 + use buttplug_server::message::{ 28 + ButtplugClientMessageV3, 29 + ButtplugServerMessageV3, 30 + RequestServerInfoV1, 31 + }; 27 32 use dashmap::DashMap; 28 33 use futures::{ 29 - future::{self, BoxFuture, FutureExt}, 30 34 Stream, 35 + future::{self, BoxFuture, FutureExt}, 31 36 }; 32 37 use log::*; 33 38 use std::sync::{ 34 - atomic::{AtomicBool, Ordering}, 35 39 Arc, 40 + atomic::{AtomicBool, Ordering}, 36 41 }; 37 42 use thiserror::Error; 38 - use tokio::sync::{broadcast, mpsc, Mutex}; 43 + use tokio::sync::{Mutex, broadcast, mpsc}; 39 44 use tracing_futures::Instrument; 40 45 41 46 /// Result type used for public APIs.
+10 -10
crates/buttplug_tests/tests/util/device_test/client/client_v3/client_event_loop.rs
··· 8 8 //! Implementation of internal Buttplug Client event loop. 9 9 10 10 use super::{ 11 + ButtplugClientEvent, 11 12 client::{ButtplugClientMessageFuturePair, ButtplugClientMessageSender}, 12 13 client_message_sorter::ClientMessageSorter, 13 14 device::{ButtplugClientDevice, ButtplugClientDeviceEvent}, 14 - ButtplugClientEvent, 15 15 }; 16 16 use buttplug_core::{ 17 - connector::{ButtplugConnector, ButtplugConnectorStateShared}, 18 - errors::{ButtplugDeviceError, ButtplugError}, 19 - message::{ButtplugDeviceMessage, ButtplugMessageValidator}, 20 - }; 17 + connector::{ButtplugConnector, ButtplugConnectorStateShared}, 18 + errors::{ButtplugDeviceError, ButtplugError}, 19 + message::{ButtplugDeviceMessage, ButtplugMessageValidator}, 20 + }; 21 21 use buttplug_server::message::{ 22 - ButtplugClientMessageV3, 23 - ButtplugServerMessageV3, 24 - DeviceListV3, 25 - DeviceMessageInfoV3, 22 + ButtplugClientMessageV3, 23 + ButtplugServerMessageV3, 24 + DeviceListV3, 25 + DeviceMessageInfoV3, 26 26 }; 27 27 use dashmap::DashMap; 28 28 use futures::FutureExt; 29 29 use log::*; 30 30 use std::sync::{ 31 - atomic::{AtomicBool, Ordering}, 32 31 Arc, 32 + atomic::{AtomicBool, Ordering}, 33 33 }; 34 34 use tokio::{ 35 35 select,
+1 -1
crates/buttplug_tests/tests/util/device_test/client/client_v3/client_message_sorter.rs
··· 18 18 use dashmap::DashMap; 19 19 use log::*; 20 20 use std::sync::{ 21 - atomic::{AtomicU32, Ordering}, 22 21 Arc, 22 + atomic::{AtomicU32, Ordering}, 23 23 }; 24 24 25 25 /// Message sorting and pairing for remote client connectors.
+10 -11
crates/buttplug_tests/tests/util/device_test/client/client_v3/connector/in_process_connector.rs
··· 8 8 //! In-process communication between clients and servers 9 9 10 10 use buttplug_core::{ 11 - connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorResultFuture}, 12 - errors::{ButtplugError, ButtplugMessageError}, 13 - util::async_manager, 14 - 15 - }; 11 + connector::{ButtplugConnector, ButtplugConnectorError, ButtplugConnectorResultFuture}, 12 + errors::{ButtplugError, ButtplugMessageError}, 13 + util::async_manager, 14 + }; 16 15 use buttplug_server::{ 17 - message::{ButtplugClientMessageV3, ButtplugServerMessageV3, ButtplugServerMessageVariant}, 18 - ButtplugServer, 19 - ButtplugServerBuilder, 16 + ButtplugServer, 17 + ButtplugServerBuilder, 18 + message::{ButtplugClientMessageV3, ButtplugServerMessageV3, ButtplugServerMessageVariant}, 20 19 }; 21 20 use futures::{ 21 + StreamExt, 22 22 future::{self, BoxFuture, FutureExt}, 23 23 pin_mut, 24 - StreamExt, 25 24 }; 26 25 use log::info; 27 26 use std::sync::{ 28 - atomic::{AtomicBool, Ordering}, 29 27 Arc, 28 + atomic::{AtomicBool, Ordering}, 30 29 }; 31 - use tokio::sync::mpsc::{channel, Sender}; 30 + use tokio::sync::mpsc::{Sender, channel}; 32 31 use tracing_futures::Instrument; 33 32 34 33 #[derive(Default)]
+1 -5
crates/buttplug_tests/tests/util/device_test/client/client_v3/connector/mod.rs
··· 1 1 mod in_process_connector; 2 - pub use in_process_connector::{ 3 - ButtplugInProcessClientConnectorBuilder, 4 - }; 5 - 2 + pub use in_process_connector::ButtplugInProcessClientConnectorBuilder; 6 3 7 4 use buttplug_client::serializer::ButtplugClientJSONSerializer; 8 5 use buttplug_core::connector::ButtplugRemoteConnector; 9 6 use buttplug_server::message::{ButtplugClientMessageV3, ButtplugServerMessageV3}; 10 - 11 7 12 8 pub type ButtplugRemoteClientConnector< 13 9 TransportType,
+20 -24
crates/buttplug_tests/tests/util/device_test/client/client_v3/device.rs
··· 8 8 //! Representation and management of devices connected to the server. 9 9 10 10 use super::client::{ 11 - create_boxed_future_client_error, 12 11 ButtplugClientMessageSender, 13 12 ButtplugClientResultFuture, 13 + create_boxed_future_client_error, 14 14 }; 15 15 use buttplug_core::{ 16 - errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError}, 17 - message::{OutputType, InputType, StopDeviceCmdV0}, 18 - util::stream::convert_broadcast_receiver_to_stream, 16 + errors::{ButtplugDeviceError, ButtplugError, ButtplugMessageError}, 17 + message::{InputType, OutputType, StopDeviceCmdV0}, 18 + util::stream::convert_broadcast_receiver_to_stream, 19 19 }; 20 20 use buttplug_server::message::{ 21 - ButtplugDeviceMessageNameV3, 22 - ButtplugServerMessageV3, 23 - ClientDeviceMessageAttributesV3, 24 - ClientGenericDeviceMessageAttributesV3, 25 - DeviceMessageInfoV3, 26 - LinearCmdV1, 27 - RotateCmdV1, 28 - RotationSubcommandV1, 29 - ScalarCmdV3, 30 - ScalarSubcommandV3, 31 - SensorReadCmdV3, 32 - SensorSubscribeCmdV3, 33 - SensorUnsubscribeCmdV3, 34 - VectorSubcommandV1, 21 + ButtplugDeviceMessageNameV3, 22 + ButtplugServerMessageV3, 23 + ClientDeviceMessageAttributesV3, 24 + ClientGenericDeviceMessageAttributesV3, 25 + DeviceMessageInfoV3, 26 + LinearCmdV1, 27 + RotateCmdV1, 28 + RotationSubcommandV1, 29 + ScalarCmdV3, 30 + ScalarSubcommandV3, 31 + SensorReadCmdV3, 32 + SensorSubscribeCmdV3, 33 + SensorUnsubscribeCmdV3, 34 + VectorSubcommandV1, 35 35 }; 36 36 use futures::{FutureExt, Stream}; 37 37 use getset::{CopyGetters, Getters}; ··· 40 40 collections::HashMap, 41 41 fmt, 42 42 sync::{ 43 - atomic::{AtomicBool, Ordering}, 44 43 Arc, 44 + atomic::{AtomicBool, Ordering}, 45 45 }, 46 46 }; 47 47 use tokio::sync::broadcast; ··· 335 335 336 336 /// Commands device to vibrate, assuming it has the features to do so. 337 337 pub fn vibrate(&self, speed_cmd: &ScalarValueCommand) -> ButtplugClientResultFuture { 338 - self.scalar_from_value_command( 339 - speed_cmd, 340 - &OutputType::Vibrate, 341 - &self.vibrate_attributes(), 342 - ) 338 + self.scalar_from_value_command(speed_cmd, &OutputType::Vibrate, &self.vibrate_attributes()) 343 339 } 344 340 345 341 pub fn oscillate_attributes(&self) -> Vec<ClientGenericDeviceMessageAttributesV3> {
+3 -3
crates/buttplug_tests/tests/util/device_test/client/client_v3/mod.rs
··· 5 5 pub mod device; 6 6 pub mod serializer; 7 7 8 + use crate::util::device_test::client::client_v3::connector::ButtplugInProcessClientConnectorBuilder; 8 9 use crate::util::{ 9 - device_test::connector::build_channel_connector_v3, 10 10 ButtplugTestServer, 11 11 TestDeviceChannelHost, 12 + device_test::connector::build_channel_connector_v3, 12 13 }; 13 14 use client::{ButtplugClient, ButtplugClientDevice, ButtplugClientEvent}; 14 - use crate::util::device_test::client::client_v3::connector::ButtplugInProcessClientConnectorBuilder; 15 15 use device::{LinearCommand, RotateCommand, ScalarCommand, ScalarValueCommand}; 16 16 17 - use buttplug_server::{device::ServerDeviceManagerBuilder, ButtplugServer, ButtplugServerBuilder}; 18 17 use buttplug_core::util::async_manager; 18 + use buttplug_server::{ButtplugServer, ButtplugServerBuilder, device::ServerDeviceManagerBuilder}; 19 19 use buttplug_server_device_config::load_protocol_configs; 20 20 use tokio::sync::Notify; 21 21
+9 -9
crates/buttplug_tests/tests/util/device_test/client/client_v3/serializer/mod.rs
··· 1 1 use buttplug_core::message::{ 2 - serializer::{ 3 - json_serializer::{create_message_validator, deserialize_to_message, vec_to_protocol_json}, 4 - ButtplugMessageSerializer, 5 - ButtplugSerializedMessage, 6 - ButtplugSerializerError, 7 - }, 8 - ButtplugMessage, 9 - ButtplugMessageFinalizer, 10 - }; 2 + ButtplugMessage, 3 + ButtplugMessageFinalizer, 4 + serializer::{ 5 + ButtplugMessageSerializer, 6 + ButtplugSerializedMessage, 7 + ButtplugSerializerError, 8 + json_serializer::{create_message_validator, deserialize_to_message, vec_to_protocol_json}, 9 + }, 10 + }; 11 11 use buttplug_server::message::{ButtplugClientMessageV3, ButtplugServerMessageV3}; 12 12 13 13 use jsonschema::Validator;
+23 -11
crates/buttplug_tests/tests/util/device_test/client/client_v4/mod.rs
··· 1 1 use crate::util::{ 2 - device_test::connector::build_channel_connector, 3 2 ButtplugTestServer, 4 3 TestDeviceChannelHost, 4 + device_test::connector::build_channel_connector, 5 5 }; 6 6 use buttplug_client::{ 7 - device::{ClientDeviceFeature, ClientDeviceOutputCommand}, 8 - ButtplugClient, 9 - ButtplugClientDevice, 10 - ButtplugClientEvent, 11 - }; 7 + ButtplugClient, 8 + ButtplugClientDevice, 9 + ButtplugClientEvent, 10 + device::{ClientDeviceFeature, ClientDeviceOutputCommand}, 11 + }; 12 12 use buttplug_client_in_process::ButtplugInProcessClientConnectorBuilder; 13 - use buttplug_server_device_config::load_protocol_configs; 14 13 use buttplug_core::{message::OutputType, util::async_manager}; 15 - use buttplug_server::{device::ServerDeviceManagerBuilder, ButtplugServer, ButtplugServerBuilder}; 14 + use buttplug_server::{ButtplugServer, ButtplugServerBuilder, device::ServerDeviceManagerBuilder}; 15 + use buttplug_server_device_config::load_protocol_configs; 16 16 use tokio::sync::Notify; 17 17 18 18 use super::super::{ ··· 35 35 OutputType::Rotate => ClientDeviceOutputCommand::RotateFloat(value), 36 36 OutputType::Spray => ClientDeviceOutputCommand::SprayFloat(value), 37 37 OutputType::Vibrate => ClientDeviceOutputCommand::VibrateFloat(value), 38 - _ => panic!("Value not translatable, test cannot run") 38 + _ => panic!("Value not translatable, test cannot run"), 39 39 } 40 40 } 41 41 ··· 59 59 let vibe_features: Vec<&ClientDeviceFeature> = device 60 60 .device_features() 61 61 .iter() 62 - .filter(|f| f.1.feature().output().as_ref().is_some_and(|x| x.contains(OutputType::Vibrate))) 62 + .filter(|f| { 63 + f.1 64 + .feature() 65 + .output() 66 + .as_ref() 67 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 68 + }) 63 69 .map(|(_, x)| x) 64 70 .collect(); 65 71 let f = vibe_features[cmd.index() as usize].clone(); ··· 78 84 let rotate_features: Vec<&ClientDeviceFeature> = device 79 85 .device_features() 80 86 .iter() 81 - .filter(|f| f.1.feature().output().as_ref().is_some_and(|x| x.contains(OutputType::RotateWithDirection))) 87 + .filter(|f| { 88 + f.1 89 + .feature() 90 + .output() 91 + .as_ref() 92 + .is_some_and(|x| x.contains(OutputType::RotateWithDirection)) 93 + }) 82 94 .map(|(_, x)| x) 83 95 .collect(); 84 96 let f = rotate_features[cmd.index() as usize].clone();
+8 -8
crates/buttplug_tests/tests/util/device_test/connector/channel_transport.rs
··· 1 1 use buttplug_core::{ 2 - connector::{ 3 - transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 4 - ButtplugConnectorError, 5 - ButtplugConnectorResultFuture, 6 - }, 7 - message::serializer::ButtplugSerializedMessage, 2 + connector::{ 3 + ButtplugConnectorError, 4 + ButtplugConnectorResultFuture, 5 + transport::{ButtplugConnectorTransport, ButtplugTransportIncomingMessage}, 6 + }, 7 + message::serializer::ButtplugSerializedMessage, 8 8 util::async_manager, 9 9 }; 10 - use futures::{future::BoxFuture, FutureExt}; 10 + use futures::{FutureExt, future::BoxFuture}; 11 11 use std::sync::Arc; 12 12 use tokio::{ 13 13 select, 14 14 sync::{ 15 - mpsc::{Receiver, Sender}, 16 15 Mutex, 17 16 Notify, 17 + mpsc::{Receiver, Sender}, 18 18 }, 19 19 }; 20 20
+23 -23
crates/buttplug_tests/tests/util/device_test/connector/mod.rs
··· 1 1 pub mod channel_transport; 2 2 use buttplug_client::{ 3 - connector::ButtplugRemoteClientConnector, 4 - serializer::{ButtplugClientJSONSerializer, ButtplugClientJSONSerializerImpl}, 5 - }; 3 + connector::ButtplugRemoteClientConnector, 4 + serializer::{ButtplugClientJSONSerializer, ButtplugClientJSONSerializerImpl}, 5 + }; 6 6 use buttplug_core::{ 7 - connector::ButtplugRemoteConnector, 8 - message::serializer::{ 9 - ButtplugMessageSerializer, 10 - ButtplugSerializedMessage, 11 - ButtplugSerializerError, 12 - }, 13 - }; 7 + connector::ButtplugRemoteConnector, 8 + message::serializer::{ 9 + ButtplugMessageSerializer, 10 + ButtplugSerializedMessage, 11 + ButtplugSerializerError, 12 + }, 13 + }; 14 14 use buttplug_server::{ 15 - connector::ButtplugRemoteServerConnector, 16 - message::{ 17 - serializer::ButtplugServerJSONSerializer, 18 - ButtplugClientMessageV0, 19 - ButtplugClientMessageV1, 20 - ButtplugClientMessageV2, 21 - ButtplugClientMessageV3, 22 - ButtplugServerMessageV0, 23 - ButtplugServerMessageV1, 24 - ButtplugServerMessageV2, 25 - ButtplugServerMessageV3, 26 - }, 15 + connector::ButtplugRemoteServerConnector, 16 + message::{ 17 + ButtplugClientMessageV0, 18 + ButtplugClientMessageV1, 19 + ButtplugClientMessageV2, 20 + ButtplugClientMessageV3, 21 + ButtplugServerMessageV0, 22 + ButtplugServerMessageV1, 23 + ButtplugServerMessageV2, 24 + ButtplugServerMessageV3, 25 + serializer::ButtplugServerJSONSerializer, 26 + }, 27 27 }; 28 28 use std::sync::Arc; 29 - use tokio::sync::{mpsc, Notify}; 29 + use tokio::sync::{Notify, mpsc}; 30 30 31 31 use self::channel_transport::ChannelTransport; 32 32
+4 -4
crates/buttplug_tests/tests/util/device_test/mod.rs
··· 5 5 use super::{TestDeviceIdentifier, TestHardwareEvent}; 6 6 use buttplug_server::device::hardware::HardwareCommand; 7 7 use buttplug_server::message::{ 8 - RotationSubcommandV1, 9 - ScalarSubcommandV3, 10 - VectorSubcommandV1, 11 - VibrateSubcommandV1, 8 + RotationSubcommandV1, 9 + ScalarSubcommandV3, 10 + VectorSubcommandV1, 11 + VibrateSubcommandV1, 12 12 }; 13 13 use serde::{Deserialize, Serialize}; 14 14
+11 -21
crates/buttplug_tests/tests/util/mod.rs
··· 14 14 pub mod channel_transport; 15 15 use buttplug_client::ButtplugClient; 16 16 use buttplug_client_in_process::ButtplugInProcessClientConnectorBuilder; 17 - use buttplug_server_device_config::{load_protocol_configs, DeviceConfigurationManager}; 18 17 use buttplug_server::{ 19 - device::{ 20 - hardware::communication::HardwareCommunicationManagerBuilder, 21 - ServerDeviceManagerBuilder, 22 - }, 23 - ButtplugServer, 24 - ButtplugServerBuilder, 18 + ButtplugServer, 19 + ButtplugServerBuilder, 20 + device::{ 21 + ServerDeviceManagerBuilder, 22 + hardware::communication::HardwareCommunicationManagerBuilder, 23 + }, 25 24 }; 25 + use buttplug_server_device_config::{DeviceConfigurationManager, load_protocol_configs}; 26 26 pub use test_device_manager::{ 27 27 TestDeviceChannelHost, 28 28 TestDeviceCommunicationManagerBuilder, ··· 158 158 } 159 159 160 160 #[allow(dead_code)] 161 - pub fn test_server_with_device( 162 - device_type: &str, 163 - ) -> (ButtplugServer, TestDeviceChannelHost) { 161 + pub fn test_server_with_device(device_type: &str) -> (ButtplugServer, TestDeviceChannelHost) { 164 162 let mut builder = TestDeviceCommunicationManagerBuilder::default(); 165 163 let device = builder.add_test_device(&TestDeviceIdentifier::new(device_type, None)); 166 164 167 - ( 168 - test_server_with_comm_manager(builder), 169 - device, 170 - ) 165 + (test_server_with_comm_manager(builder), device) 171 166 } 172 167 173 168 #[allow(dead_code)] 174 - pub fn test_server_v4_with_device( 175 - device_type: &str, 176 - ) -> (ButtplugServer, TestDeviceChannelHost) { 169 + pub fn test_server_v4_with_device(device_type: &str) -> (ButtplugServer, TestDeviceChannelHost) { 177 170 let mut builder = TestDeviceCommunicationManagerBuilder::default(); 178 171 let device = builder.add_test_device(&TestDeviceIdentifier::new(device_type, None)); 179 172 180 - ( 181 - test_server_with_comm_manager(builder), 182 - device, 183 - ) 173 + (test_server_with_comm_manager(builder), device) 184 174 }
+28 -20
crates/buttplug_tests/tests/util/test_device_manager/test_device.rs
··· 6 6 // for full license information. 7 7 8 8 use buttplug_core::{errors::ButtplugDeviceError, util::async_manager}; 9 + use buttplug_server::device::hardware::{ 10 + Hardware, 11 + HardwareCommand, 12 + HardwareConnector, 13 + HardwareEvent, 14 + HardwareInternal, 15 + HardwareReadCmd, 16 + HardwareReading, 17 + HardwareSpecializer, 18 + HardwareSubscribeCmd, 19 + HardwareUnsubscribeCmd, 20 + HardwareWriteCmd, 21 + }; 9 22 use buttplug_server_device_config::{Endpoint, ProtocolCommunicationSpecifier}; 10 - use buttplug_server::device::{ 11 - hardware::{ 12 - Hardware, 13 - HardwareCommand, 14 - HardwareConnector, 15 - HardwareEvent, 16 - HardwareInternal, 17 - HardwareReadCmd, 18 - HardwareReading, 19 - HardwareSpecializer, 20 - HardwareSubscribeCmd, 21 - HardwareUnsubscribeCmd, 22 - HardwareWriteCmd, 23 - }, 24 - }; 25 23 26 24 use async_trait::async_trait; 27 25 use dashmap::DashSet; ··· 30 28 use std::{ 31 29 collections::{HashSet, VecDeque}, 32 30 fmt::{self, Debug}, 33 - sync::Arc, time::Duration, 31 + sync::Arc, 32 + time::Duration, 34 33 }; 35 - use tokio::sync::{broadcast, mpsc, Mutex}; 34 + use tokio::sync::{Mutex, broadcast, mpsc}; 36 35 37 36 #[derive(Serialize, Deserialize, Debug, Clone)] 38 37 pub struct TestHardwareNotification { ··· 299 298 msg: &HardwareWriteCmd, 300 299 ) -> BoxFuture<'static, Result<(), ButtplugDeviceError>> { 301 300 if !self.endpoints.contains(&msg.endpoint()) { 302 - return future::ready(Err(ButtplugDeviceError::InvalidEndpoint(msg.endpoint().to_string()))).boxed(); 301 + return future::ready(Err(ButtplugDeviceError::InvalidEndpoint( 302 + msg.endpoint().to_string(), 303 + ))) 304 + .boxed(); 303 305 } 304 306 self.send_command(msg.clone().into()) 305 307 } ··· 309 311 msg: &HardwareSubscribeCmd, 310 312 ) -> BoxFuture<'static, Result<(), ButtplugDeviceError>> { 311 313 if !self.endpoints.contains(&msg.endpoint()) { 312 - return future::ready(Err(ButtplugDeviceError::InvalidEndpoint(msg.endpoint().to_string()))).boxed(); 314 + return future::ready(Err(ButtplugDeviceError::InvalidEndpoint( 315 + msg.endpoint().to_string(), 316 + ))) 317 + .boxed(); 313 318 } 314 319 self.subscribed_endpoints.insert(msg.endpoint()); 315 320 self.send_command((*msg).into()) ··· 320 325 msg: &HardwareUnsubscribeCmd, 321 326 ) -> BoxFuture<'static, Result<(), ButtplugDeviceError>> { 322 327 if !self.endpoints.contains(&msg.endpoint()) { 323 - return future::ready(Err(ButtplugDeviceError::InvalidEndpoint(msg.endpoint().to_string()))).boxed(); 328 + return future::ready(Err(ButtplugDeviceError::InvalidEndpoint( 329 + msg.endpoint().to_string(), 330 + ))) 331 + .boxed(); 324 332 } 325 333 self.subscribed_endpoints.remove(&msg.endpoint()); 326 334 self.send_command((*msg).into())
+7 -7
crates/buttplug_tests/tests/util/test_device_manager/test_device_comm_manager.rs
··· 6 6 // for full license information. 7 7 8 8 use super::{ 9 + TestDevice, 9 10 test_device::{ 10 - new_device_channel, 11 11 TestDeviceChannelDevice, 12 12 TestDeviceChannelHost, 13 13 TestHardwareConnector, 14 + new_device_channel, 14 15 }, 15 - TestDevice, 16 16 }; 17 17 use buttplug_core::ButtplugResultFuture; 18 - use buttplug_server_device_config::{BluetoothLESpecifier, ProtocolCommunicationSpecifier}; 19 18 use buttplug_server::device::hardware::communication::{ 20 - HardwareCommunicationManager, 21 - HardwareCommunicationManagerBuilder, 22 - HardwareCommunicationManagerEvent, 19 + HardwareCommunicationManager, 20 + HardwareCommunicationManagerBuilder, 21 + HardwareCommunicationManagerEvent, 23 22 }; 23 + use buttplug_server_device_config::{BluetoothLESpecifier, ProtocolCommunicationSpecifier}; 24 24 use futures::future::{self, FutureExt}; 25 25 use log::*; 26 26 use serde::{Deserialize, Serialize}; 27 27 use std::{ 28 28 collections::HashMap, 29 29 sync::{ 30 - atomic::{AtomicBool, Ordering}, 31 30 Arc, 31 + atomic::{AtomicBool, Ordering}, 32 32 }, 33 33 time::{SystemTime, UNIX_EPOCH}, 34 34 };
+10 -11
crates/buttplug_tests/tests/util/test_server.rs
··· 6 6 // for full license information. 7 7 8 8 use buttplug_core::{ 9 - connector::ButtplugConnector, 10 - errors::ButtplugError, 11 - message::{ButtplugMessage, ButtplugMessageValidator, ErrorV0}, 12 - util::async_manager, 13 - 14 - }; 9 + connector::ButtplugConnector, 10 + errors::ButtplugError, 11 + message::{ButtplugMessage, ButtplugMessageValidator, ErrorV0}, 12 + util::async_manager, 13 + }; 15 14 use buttplug_server::{ 16 - message::{ButtplugClientMessageVariant, ButtplugServerMessageVariant}, 17 - ButtplugServer, 18 - ButtplugServerBuilder, 15 + ButtplugServer, 16 + ButtplugServerBuilder, 17 + message::{ButtplugClientMessageVariant, ButtplugServerMessageVariant}, 19 18 }; 20 - use futures::{future::Future, pin_mut, select, FutureExt, StreamExt}; 19 + use futures::{FutureExt, StreamExt, future::Future, pin_mut, select}; 21 20 use log::*; 22 21 use std::sync::Arc; 23 22 use thiserror::Error; 24 - use tokio::sync::{mpsc, Notify}; 23 + use tokio::sync::{Notify, mpsc}; 25 24 26 25 #[derive(Error, Debug)] 27 26 pub enum ButtplugServerConnectorError {
+6 -6
crates/buttplug_transport_websocket_tungstenite/src/websocket_client.rs
··· 9 9 10 10 use buttplug_core::{ 11 11 connector::{ 12 + ButtplugConnectorError, 13 + ButtplugConnectorResultFuture, 12 14 transport::{ 13 15 ButtplugConnectorTransport, 14 16 ButtplugConnectorTransportSpecificError, 15 17 ButtplugTransportIncomingMessage, 16 18 }, 17 - ButtplugConnectorError, 18 - ButtplugConnectorResultFuture, 19 19 }, 20 20 message::serializer::ButtplugSerializedMessage, 21 21 util::async_manager, 22 22 }; 23 - use futures::{future::BoxFuture, FutureExt, SinkExt, StreamExt}; 23 + use futures::{FutureExt, SinkExt, StreamExt, future::BoxFuture}; 24 24 use rustls::{ 25 - client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}, 26 25 ClientConfig, 27 26 SignatureScheme, 27 + client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}, 28 28 }; 29 29 use std::sync::Arc; 30 30 use tokio::{ 31 31 select, 32 32 sync::{ 33 - mpsc::{Receiver, Sender}, 34 33 Notify, 34 + mpsc::{Receiver, Sender}, 35 35 }, 36 36 }; 37 37 use tokio_tungstenite::{ 38 + Connector, 38 39 connect_async, 39 40 connect_async_tls_with_config, 40 41 tungstenite::protocol::Message, 41 - Connector, 42 42 }; 43 43 use tracing::Instrument; 44 44 use url::Url;
+4 -4
crates/buttplug_transport_websocket_tungstenite/src/websocket_server.rs
··· 7 7 8 8 use buttplug_core::{ 9 9 connector::{ 10 + ButtplugConnectorError, 11 + ButtplugConnectorResultFuture, 10 12 transport::{ 11 13 ButtplugConnectorTransport, 12 14 ButtplugConnectorTransportSpecificError, 13 15 ButtplugTransportIncomingMessage, 14 16 }, 15 - ButtplugConnectorError, 16 - ButtplugConnectorResultFuture, 17 17 }, 18 18 message::serializer::ButtplugSerializedMessage, 19 19 util::async_manager, 20 20 }; 21 - use futures::{future::BoxFuture, FutureExt, SinkExt, StreamExt}; 21 + use futures::{FutureExt, SinkExt, StreamExt, future::BoxFuture}; 22 22 use std::{sync::Arc, time::Duration}; 23 23 use tokio::{ 24 24 net::{TcpListener, TcpStream}, 25 25 select, 26 26 sync::{ 27 - mpsc::{Receiver, Sender}, 28 27 Notify, 28 + mpsc::{Receiver, Sender}, 29 29 }, 30 30 time::sleep, 31 31 };
+6 -1
crates/examples/src/bin/async.rs
··· 1 - use buttplug_client::{connector::ButtplugRemoteClientConnector, serializer::ButtplugClientJSONSerializer, ButtplugClient, ButtplugClientEvent}; 1 + use buttplug_client::{ 2 + ButtplugClient, 3 + ButtplugClientEvent, 4 + connector::ButtplugRemoteClientConnector, 5 + serializer::ButtplugClientJSONSerializer, 6 + }; 2 7 use buttplug_transport_websocket_tungstenite::ButtplugWebsocketClientTransport; 3 8 use futures::StreamExt; 4 9
+6 -1
crates/examples/src/bin/connection.rs
··· 1 - use buttplug_client::{connector::ButtplugRemoteClientConnector, serializer::ButtplugClientJSONSerializer, ButtplugClient, ButtplugClientError}; 1 + use buttplug_client::{ 2 + ButtplugClient, 3 + ButtplugClientError, 4 + connector::ButtplugRemoteClientConnector, 5 + serializer::ButtplugClientJSONSerializer, 6 + }; 2 7 3 8 use buttplug_core::errors::ButtplugError; 4 9 use buttplug_transport_websocket_tungstenite::ButtplugWebsocketClientTransport;
+14 -15
crates/examples/src/bin/device_control.rs
··· 1 1 use std::collections::HashMap; 2 2 3 - use buttplug_client::{connector::ButtplugRemoteClientConnector, serializer::ButtplugClientJSONSerializer, ButtplugClient, ButtplugClientError}; 3 + use buttplug_client::{ 4 + ButtplugClient, 5 + ButtplugClientError, 6 + connector::ButtplugRemoteClientConnector, 7 + serializer::ButtplugClientJSONSerializer, 8 + }; 4 9 5 10 use buttplug_core::message::OutputType; 6 11 use buttplug_transport_websocket_tungstenite::ButtplugWebsocketClientTransport; ··· 45 50 for (_, device) in client.devices() { 46 51 println!("{} supports these outputs:", device.name()); 47 52 for output_type in OutputType::iter() { 48 - for (_, feature) in device.device_features() { 49 - if let Some(output) = feature.feature().output() && output.contains(output_type) { 53 + for (_, feature) in device.device_features() { 54 + if let Some(output) = feature.feature().output() 55 + && output.contains(output_type) 56 + { 50 57 println!("- {}", output_type); 51 58 } 52 59 } ··· 66 73 // We can use the convenience functions on ButtplugClientDevice to 67 74 // send the message. This version sets all of the motors on a 68 75 // vibrating device to the same speed. 69 - test_client_device 70 - .vibrate(10) 71 - .await?; 76 + test_client_device.vibrate(10).await?; 72 77 73 78 // If we wanted to just set one motor on and the other off, we could 74 79 // try this version that uses an array. It'll throw an exception if ··· 77 82 // 78 83 // You can get the vibrator count using the following code, though we 79 84 // know it's 2 so we don't really have to use it. 80 - let vibrator_count = test_client_device 81 - .vibrate_features() 82 - .len(); 85 + let vibrator_count = test_client_device.vibrate_features().len(); 83 86 84 87 println!( 85 88 "{} has {} vibrators.", ··· 89 92 90 93 // Just set all of the vibrators to full speed. 91 94 if vibrator_count > 0 { 92 - test_client_device 93 - .vibrate(10) 94 - .await?; 95 + test_client_device.vibrate(10).await?; 95 96 } else { 96 97 println!("Device does not have > 1 vibrators, not running multiple vibrator test."); 97 98 } ··· 103 104 println!("Trying error"); 104 105 // If we try to send a command to a device after the client has 105 106 // disconnected, we'll get an exception thrown. 106 - let vibrate_result = test_client_device 107 - .vibrate(30) 108 - .await; 107 + let vibrate_result = test_client_device.vibrate(30).await; 109 108 if let Err(ButtplugClientError::ButtplugConnectorError(error)) = vibrate_result { 110 109 println!("Tried to send after disconnection! Error: "); 111 110 println!("{}", error);
+6 -1
crates/examples/src/bin/device_enumeration.rs
··· 1 - use buttplug_client::{connector::ButtplugRemoteClientConnector, serializer::ButtplugClientJSONSerializer, ButtplugClient, ButtplugClientEvent}; 1 + use buttplug_client::{ 2 + ButtplugClient, 3 + ButtplugClientEvent, 4 + connector::ButtplugRemoteClientConnector, 5 + serializer::ButtplugClientJSONSerializer, 6 + }; 2 7 use buttplug_transport_websocket_tungstenite::ButtplugWebsocketClientTransport; 3 8 use futures::StreamExt; 4 9 use tokio::io::{self, AsyncBufReadExt, BufReader};
+1 -1
crates/examples/src/bin/device_tester.rs
··· 369 369 .init(); 370 370 device_tester().await; 371 371 } 372 - */ 372 + */
+6 -4
crates/examples/src/bin/embedded_connector.rs
··· 1 1 use buttplug_client::ButtplugClient; 2 - use buttplug_server::{device::ServerDeviceManagerBuilder, ButtplugServerBuilder}; 2 + use buttplug_client_in_process::{ButtplugInProcessClientConnectorBuilder, in_process_client}; 3 + use buttplug_server::{ButtplugServerBuilder, device::ServerDeviceManagerBuilder}; 3 4 use buttplug_server_device_config::DeviceConfigurationManagerBuilder; 4 5 use buttplug_server_hwmgr_btleplug::BtlePlugCommunicationManagerBuilder; 5 - use buttplug_client_in_process::{ButtplugInProcessClientConnectorBuilder, in_process_client}; 6 6 7 7 #[allow(dead_code)] 8 8 async fn main_the_hard_way() -> anyhow::Result<()> { ··· 14 14 device_manager_builder.comm_manager(BtlePlugCommunicationManagerBuilder::default()); 15 15 16 16 // This is how we add Bluetooth manually. (We could also do this with any other communication manager.) 17 - 18 - let server = ButtplugServerBuilder::new(device_manager_builder.finish().unwrap()).finish().unwrap(); 17 + 18 + let server = ButtplugServerBuilder::new(device_manager_builder.finish().unwrap()) 19 + .finish() 20 + .unwrap(); 19 21 20 22 // First off, we'll set up our Embedded Connector. 21 23 let connector = ButtplugInProcessClientConnectorBuilder::default()
+6 -1
crates/examples/src/bin/external_connector.rs
··· 1 - use buttplug_client::{connector::ButtplugRemoteClientConnector, serializer::ButtplugClientJSONSerializer, ButtplugClient, ButtplugClientEvent}; 1 + use buttplug_client::{ 2 + ButtplugClient, 3 + ButtplugClientEvent, 4 + connector::ButtplugRemoteClientConnector, 5 + serializer::ButtplugClientJSONSerializer, 6 + }; 2 7 use buttplug_transport_websocket_tungstenite::ButtplugWebsocketClientTransport; 3 8 4 9 #[tokio::main]
+8 -5
crates/intiface_engine/src/backdoor_server.rs
··· 1 1 use buttplug_core::{ 2 - connector::transport::stream::ButtplugStreamTransport, 3 - message::serializer::ButtplugSerializedMessage, 4 - util::stream::convert_broadcast_receiver_to_stream, 2 + connector::transport::stream::ButtplugStreamTransport, 3 + message::serializer::ButtplugSerializedMessage, 4 + util::stream::convert_broadcast_receiver_to_stream, 5 + }; 6 + use buttplug_server::{ 7 + ButtplugServerBuilder, connector::ButtplugRemoteServerConnector, device::ServerDeviceManager, 8 + message::serializer::ButtplugServerJSONSerializer, 5 9 }; 6 - use buttplug_server::{connector::ButtplugRemoteServerConnector, device::ServerDeviceManager, message::serializer::ButtplugServerJSONSerializer, ButtplugServerBuilder}; 7 10 use std::sync::Arc; 8 11 use tokio::sync::{ 9 12 broadcast, ··· 28 31 .name("Intiface Backdoor Server") 29 32 .finish() 30 33 .unwrap(), 31 - &None 34 + &None, 32 35 ); 33 36 let (s_out, mut r_out) = mpsc::channel(255); 34 37 let (s_in, r_in) = mpsc::channel(255);
+3 -3
crates/intiface_engine/src/bin/main.rs
··· 5 5 }; 6 6 use std::fs; 7 7 use tokio::{select, signal::ctrl_c}; 8 - use tracing::{debug, info, Level}; 8 + use tracing::{Level, debug, info}; 9 9 use tracing_subscriber::{ 10 10 filter::{EnvFilter, LevelFilter}, 11 11 layer::SubscriberExt, ··· 204 204 return Err(IntifaceError::new(&format!( 205 205 "Error opening external device configuration: {:?}", 206 206 err 207 - ))) 207 + ))); 208 208 } 209 209 }; 210 210 } ··· 220 220 return Err(IntifaceError::new(&format!( 221 221 "Error opening user device configuration: {:?}", 222 222 err 223 - ))) 223 + ))); 224 224 } 225 225 }; 226 226 }
+3 -2
crates/intiface_engine/src/buttplug_server.rs
··· 1 1 use std::sync::Arc; 2 2 3 3 use crate::{ 4 - remote_server::ButtplugRemoteServerEvent, BackdoorServer, ButtplugRemoteServer, ButtplugServerConnectorError, EngineOptions, IntifaceEngineError, IntifaceError 4 + BackdoorServer, ButtplugRemoteServer, ButtplugServerConnectorError, EngineOptions, 5 + IntifaceEngineError, IntifaceError, remote_server::ButtplugRemoteServerEvent, 5 6 }; 6 7 use buttplug_server::{ 7 8 ButtplugServerBuilder, ··· 78 79 pub async fn reset_buttplug_server( 79 80 options: &EngineOptions, 80 81 device_manager: &Arc<ServerDeviceManager>, 81 - sender: &Sender<ButtplugRemoteServerEvent> 82 + sender: &Sender<ButtplugRemoteServerEvent>, 82 83 ) -> Result<ButtplugRemoteServer, IntifaceEngineError> { 83 84 match ButtplugServerBuilder::with_shared_device_manager(device_manager.clone()) 84 85 .name(options.server_name())
+4 -4
crates/intiface_engine/src/engine.rs
··· 1 1 use crate::{ 2 + ButtplugRepeater, 2 3 backdoor_server::BackdoorServer, 3 4 buttplug_server::{reset_buttplug_server, run_server, setup_buttplug_server}, 4 5 error::IntifaceEngineError, 5 6 frontend::{ 6 - frontend_external_event_loop, frontend_server_event_loop, process_messages::EngineMessage, 7 - Frontend, 7 + Frontend, frontend_external_event_loop, frontend_server_event_loop, 8 + process_messages::EngineMessage, 8 9 }, 9 10 mdns::IntifaceMdns, 10 11 options::EngineOptions, 11 12 remote_server::ButtplugRemoteServerEvent, 12 - ButtplugRepeater, 13 13 }; 14 14 15 15 use buttplug_server_device_config::{DeviceConfigurationManager, save_user_config}; 16 - use futures::{pin_mut, StreamExt}; 16 + use futures::{StreamExt, pin_mut}; 17 17 use once_cell::sync::OnceCell; 18 18 use std::{path::Path, sync::Arc, time::Duration}; 19 19 use tokio::{fs, select};
+3 -3
crates/intiface_engine/src/frontend/mod.rs
··· 2 2 use crate::error::IntifaceError; 3 3 use crate::remote_server::ButtplugRemoteServerEvent; 4 4 use async_trait::async_trait; 5 - use futures::{pin_mut, Stream, StreamExt}; 5 + use futures::{Stream, StreamExt, pin_mut}; 6 6 pub use process_messages::{EngineMessage, IntifaceMessage}; 7 7 use std::sync::Arc; 8 8 use tokio::{ 9 9 select, 10 - sync::{broadcast, Notify}, 10 + sync::{Notify, broadcast}, 11 11 }; 12 12 use tokio_util::sync::CancellationToken; 13 13 ··· 131 131 receiver 132 132 } 133 133 } 134 - */ 134 + */
+28 -16
crates/intiface_engine/src/remote_server.rs
··· 6 6 // for full license information. 7 7 8 8 use buttplug_core::{ 9 - connector::ButtplugConnector, 10 - errors::ButtplugError, 11 - message::ButtplugServerMessageV4, 12 - util::{async_manager, stream::convert_broadcast_receiver_to_stream}, 9 + connector::ButtplugConnector, 10 + errors::ButtplugError, 11 + message::ButtplugServerMessageV4, 12 + util::{async_manager, stream::convert_broadcast_receiver_to_stream}, 13 13 }; 14 - use buttplug_server_device_config::UserDeviceIdentifier; 15 14 use buttplug_server::{ 16 - message::{ButtplugClientMessageVariant, ButtplugServerMessageVariant}, ButtplugServer, ButtplugServerBuilder 15 + ButtplugServer, ButtplugServerBuilder, 16 + message::{ButtplugClientMessageVariant, ButtplugServerMessageVariant}, 17 17 }; 18 + use buttplug_server_device_config::UserDeviceIdentifier; 18 19 use dashmap::DashSet; 19 - use futures::{future::Future, pin_mut, select, FutureExt, Stream, StreamExt}; 20 + use futures::{FutureExt, Stream, StreamExt, future::Future, pin_mut, select}; 20 21 use getset::Getters; 21 22 use serde::{Deserialize, Serialize}; 22 23 use std::sync::Arc; 23 24 use thiserror::Error; 24 - use tokio::sync::{broadcast::{self, Sender}, mpsc, Notify}; 25 + use tokio::sync::{ 26 + Notify, 27 + broadcast::{self, Sender}, 28 + mpsc, 29 + }; 25 30 26 31 // Clone derived here to satisfy tokio broadcast requirements. 27 32 #[derive(Clone, Debug, Serialize, Deserialize)] ··· 70 75 break; 71 76 } 72 77 Some(msg) => { 73 - if let ButtplugServerMessageV4::DeviceList(dl) = msg && remote_event_sender.receiver_count() > 0 { 78 + if let ButtplugServerMessageV4::DeviceList(dl) = msg 79 + && remote_event_sender.receiver_count() > 0 80 + { 74 81 for da in dl.devices() { 75 82 if known_indexes.contains(&da.1.device_index()) { 76 83 continue; ··· 83 90 display_name: device_info.display_name().clone(), 84 91 }; 85 92 if remote_event_sender.send(added_event).is_err() { 86 - error!("Cannot send event to owner, dropping and assuming local server thread has exited."); 93 + error!( 94 + "Cannot send event to owner, dropping and assuming local server thread has exited." 95 + ); 87 96 } 88 97 known_indexes.insert(da.1.device_index()); 89 98 } ··· 94 103 if current_indexes.contains(&dr) { 95 104 continue; 96 105 } 97 - let removed_event = ButtplugRemoteServerEvent::DeviceRemoved { 98 - index: dr, 99 - }; 106 + let removed_event = ButtplugRemoteServerEvent::DeviceRemoved { index: dr }; 100 107 if remote_event_sender.send(removed_event).is_err() { 101 - error!("Cannot send event to owner, dropping and assuming local server thread has exited."); 108 + error!( 109 + "Cannot send event to owner, dropping and assuming local server thread has exited." 110 + ); 102 111 } 103 112 known_indexes.remove(&dr); 104 113 } ··· 223 232 ButtplugServerBuilder::default() 224 233 .finish() 225 234 .expect("Default is infallible"), 226 - &None 235 + &None, 227 236 ) 228 237 } 229 238 } 230 239 231 240 impl ButtplugRemoteServer { 232 - pub fn new(server: ButtplugServer, event_sender: &Option<Sender<ButtplugRemoteServerEvent>>) -> Self { 241 + pub fn new( 242 + server: ButtplugServer, 243 + event_sender: &Option<Sender<ButtplugRemoteServerEvent>>, 244 + ) -> Self { 233 245 let event_sender = if let Some(sender) = event_sender { 234 246 sender.clone() 235 247 } else {
+1 -1
crates/intiface_engine/src/repeater.rs
··· 2 2 // 3 3 // It absolute is! 4 4 5 - use futures_util::{future, StreamExt, TryStreamExt}; 5 + use futures_util::{StreamExt, TryStreamExt, future}; 6 6 use log::info; 7 7 use tokio::{ 8 8 net::{TcpListener, TcpStream},