@@ -2,6 +2,7 @@ use buttplug_core::message::OutputType;
22
33use crate :: ButtplugClientError ;
44
5+ #[ derive( Debug , Clone , Copy ) ]
56pub enum ClientDeviceCommandValue {
67 Int ( i32 ) ,
78 Float ( f64 ) ,
@@ -27,41 +28,31 @@ impl From<f64> for ClientDeviceCommandValue {
2728
2829pub enum ClientDeviceOutputCommand {
2930 // u32 types use steps, need to compare before sending
30- Vibrate ( u32 ) ,
31- Rotate ( i32 ) ,
32- Oscillate ( u32 ) ,
33- Constrict ( u32 ) ,
34- Temperature ( i32 ) ,
35- Led ( u32 ) ,
36- Spray ( u32 ) ,
37- Position ( u32 ) ,
38- PositionWithDuration ( u32 , u32 ) ,
39- // f64 types are old style float, will need to convert before sending
40- VibrateFloat ( f64 ) ,
41- RotateFloat ( f64 ) ,
42- OscillateFloat ( f64 ) ,
43- ConstrictFloat ( f64 ) ,
44- TemperatureFloat ( f64 ) ,
45- LedFloat ( f64 ) ,
46- SprayFloat ( f64 ) ,
47- PositionFloat ( f64 ) ,
48- PositionWithDurationFloat ( f64 , u32 ) ,
31+ Vibrate ( ClientDeviceCommandValue ) ,
32+ Rotate ( ClientDeviceCommandValue ) ,
33+ Oscillate ( ClientDeviceCommandValue ) ,
34+ Constrict ( ClientDeviceCommandValue ) ,
35+ Temperature ( ClientDeviceCommandValue ) ,
36+ Led ( ClientDeviceCommandValue ) ,
37+ Spray ( ClientDeviceCommandValue ) ,
38+ Position ( ClientDeviceCommandValue ) ,
39+ PositionWithDuration ( ClientDeviceCommandValue , u32 ) ,
4940}
5041
5142impl ClientDeviceOutputCommand {
52- pub fn from_command_value_float (
43+ pub fn from_command_value (
5344 output_type : OutputType ,
54- value : f64 ,
45+ value : & ClientDeviceCommandValue ,
5546 ) -> Result < Self , ButtplugClientError > {
5647 match output_type {
57- OutputType :: Vibrate => Ok ( ClientDeviceOutputCommand :: VibrateFloat ( value) ) ,
58- OutputType :: Oscillate => Ok ( ClientDeviceOutputCommand :: OscillateFloat ( value) ) ,
59- OutputType :: Rotate => Ok ( ClientDeviceOutputCommand :: RotateFloat ( value) ) ,
60- OutputType :: Constrict => Ok ( ClientDeviceOutputCommand :: ConstrictFloat ( value) ) ,
61- OutputType :: Temperature => Ok ( ClientDeviceOutputCommand :: TemperatureFloat ( value) ) ,
62- OutputType :: Led => Ok ( ClientDeviceOutputCommand :: LedFloat ( value) ) ,
63- OutputType :: Spray => Ok ( ClientDeviceOutputCommand :: SprayFloat ( value) ) ,
64- OutputType :: Position => Ok ( ClientDeviceOutputCommand :: PositionFloat ( value) ) ,
48+ OutputType :: Vibrate => Ok ( ClientDeviceOutputCommand :: Vibrate ( * value) ) ,
49+ OutputType :: Oscillate => Ok ( ClientDeviceOutputCommand :: Oscillate ( * value) ) ,
50+ OutputType :: Rotate => Ok ( ClientDeviceOutputCommand :: Rotate ( * value) ) ,
51+ OutputType :: Constrict => Ok ( ClientDeviceOutputCommand :: Constrict ( * value) ) ,
52+ OutputType :: Temperature => Ok ( ClientDeviceOutputCommand :: Temperature ( * value) ) ,
53+ OutputType :: Led => Ok ( ClientDeviceOutputCommand :: Led ( * value) ) ,
54+ OutputType :: Spray => Ok ( ClientDeviceOutputCommand :: Spray ( * value) ) ,
55+ OutputType :: Position => Ok ( ClientDeviceOutputCommand :: Position ( * value) ) ,
6556 _ => Err ( ButtplugClientError :: ButtplugOutputCommandConversionError (
6657 "Cannot use PositionWithDuration with this method" . to_owned ( ) ,
6758 ) ) ,
@@ -72,31 +63,15 @@ impl ClientDeviceOutputCommand {
7263impl From < & ClientDeviceOutputCommand > for OutputType {
7364 fn from ( val : & ClientDeviceOutputCommand ) -> Self {
7465 match val {
75- ClientDeviceOutputCommand :: Vibrate ( _) | ClientDeviceOutputCommand :: VibrateFloat ( _) => {
76- OutputType :: Vibrate
77- }
78- ClientDeviceOutputCommand :: Oscillate ( _) | ClientDeviceOutputCommand :: OscillateFloat ( _) => {
79- OutputType :: Oscillate
80- }
81- ClientDeviceOutputCommand :: Rotate ( _) | ClientDeviceOutputCommand :: RotateFloat ( _) => {
82- OutputType :: Rotate
83- }
84- ClientDeviceOutputCommand :: Constrict ( _) | ClientDeviceOutputCommand :: ConstrictFloat ( _) => {
85- OutputType :: Constrict
86- }
87- ClientDeviceOutputCommand :: Temperature ( _)
88- | ClientDeviceOutputCommand :: TemperatureFloat ( _) => OutputType :: Temperature ,
89- ClientDeviceOutputCommand :: Led ( _) | ClientDeviceOutputCommand :: LedFloat ( _) => OutputType :: Led ,
90- ClientDeviceOutputCommand :: Spray ( _) | ClientDeviceOutputCommand :: SprayFloat ( _) => {
91- OutputType :: Spray
92- }
93- ClientDeviceOutputCommand :: Position ( _) | ClientDeviceOutputCommand :: PositionFloat ( _) => {
94- OutputType :: Position
95- }
96- ClientDeviceOutputCommand :: PositionWithDuration ( _, _)
97- | ClientDeviceOutputCommand :: PositionWithDurationFloat ( _, _) => {
98- OutputType :: PositionWithDuration
99- }
66+ ClientDeviceOutputCommand :: Vibrate ( _) => OutputType :: Vibrate ,
67+ ClientDeviceOutputCommand :: Oscillate ( _) => OutputType :: Oscillate ,
68+ ClientDeviceOutputCommand :: Rotate ( _) => OutputType :: Rotate ,
69+ ClientDeviceOutputCommand :: Constrict ( _) => OutputType :: Constrict ,
70+ ClientDeviceOutputCommand :: Temperature ( _) => OutputType :: Temperature ,
71+ ClientDeviceOutputCommand :: Led ( _) => OutputType :: Led ,
72+ ClientDeviceOutputCommand :: Spray ( _) => OutputType :: Spray ,
73+ ClientDeviceOutputCommand :: Position ( _) => OutputType :: Position ,
74+ ClientDeviceOutputCommand :: PositionWithDuration ( _, _) => OutputType :: PositionWithDuration ,
10075 }
10176 }
10277}
0 commit comments