Skip to content

Commit 7f58d7e

Browse files
committed
chore: Finish implementing basic commands
Not the nicest way to do things but eh.
1 parent 268e91c commit 7f58d7e

File tree

3 files changed

+211
-3
lines changed

3 files changed

+211
-3
lines changed

Buttplug/Client/ButtplugClientDevice.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,94 @@ public async Task VibrateAsync(uint speed)
7272
}
7373
}
7474

75+
public async Task RotateAsync(uint speed)
76+
{
77+
foreach (var feature in _features.Values)
78+
{
79+
if (feature.CanRotate())
80+
{
81+
await feature.RotateAsync(speed);
82+
}
83+
}
84+
}
85+
86+
public async Task OscillateAsync(uint speed)
87+
{
88+
foreach (var feature in _features.Values)
89+
{
90+
if (feature.CanOscillate())
91+
{
92+
await feature.OscillateAsync(speed);
93+
}
94+
}
95+
}
96+
97+
public async Task ConstrictAsync(uint speed)
98+
{
99+
foreach (var feature in _features.Values)
100+
{
101+
if (feature.CanConstrict())
102+
{
103+
await feature.ConstrictAsync(speed);
104+
}
105+
}
106+
}
107+
108+
public async Task SprayAsync(uint speed)
109+
{
110+
foreach (var feature in _features.Values)
111+
{
112+
if (feature.CanSpray())
113+
{
114+
await feature.SprayAsync(speed);
115+
}
116+
}
117+
}
118+
119+
public async Task HeaterAsync(uint speed)
120+
{
121+
foreach (var feature in _features.Values)
122+
{
123+
if (feature.CanHeater())
124+
{
125+
await feature.HeaterAsync(speed);
126+
}
127+
}
128+
}
129+
130+
public async Task LedAsync(uint speed)
131+
{
132+
foreach (var feature in _features.Values)
133+
{
134+
if (feature.CanLed())
135+
{
136+
await feature.LedAsync(speed);
137+
}
138+
}
139+
}
140+
141+
public async Task PositionWithDurationAsync(uint position, uint duration)
142+
{
143+
foreach (var feature in _features.Values)
144+
{
145+
if (feature.CanPositionWithDuration())
146+
{
147+
await feature.PositionWithDurationAsync(position, duration);
148+
}
149+
}
150+
}
151+
152+
public async Task RotateWithDirectionAsync(uint speed, bool clockwise)
153+
{
154+
foreach (var feature in _features.Values)
155+
{
156+
if (feature.CanRotateWithDirection())
157+
{
158+
await feature.RotateWithDirectionAsync(speed, clockwise);
159+
}
160+
}
161+
}
162+
75163
public async Task Stop()
76164
{
77165
await _handler.SendMessageExpectOk(new StopDeviceCmd(Index)).ConfigureAwait(false);

Buttplug/Client/ButtplugClientDeviceFeature.cs

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,128 @@ public bool CanVibrate()
2525

2626
public async Task VibrateAsync(uint speed)
2727
{
28-
var outputCmd = new OutputCommand();
29-
outputCmd.Vibrate = new OutputCommandValue(speed);
28+
var outputCmd = new OutputCommand
29+
{
30+
Vibrate = new OutputCommandValue(speed)
31+
};
32+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
33+
}
34+
35+
public bool CanOscillate()
36+
{
37+
return _feature.Output.ContainsKey(OutputType.Oscillate);
38+
}
39+
40+
public async Task OscillateAsync(uint speed)
41+
{
42+
var outputCmd = new OutputCommand
43+
{
44+
Oscillate = new OutputCommandValue(speed)
45+
};
46+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
47+
}
48+
49+
public bool CanRotate()
50+
{
51+
return _feature.Output.ContainsKey(OutputType.Rotate);
52+
}
53+
54+
public async Task RotateAsync(uint speed)
55+
{
56+
var outputCmd = new OutputCommand
57+
{
58+
Rotate = new OutputCommandValue(speed)
59+
};
60+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
61+
}
62+
63+
public bool CanConstrict()
64+
{
65+
return _feature.Output.ContainsKey(OutputType.Constrict);
66+
}
67+
68+
public async Task ConstrictAsync(uint speed)
69+
{
70+
var outputCmd = new OutputCommand
71+
{
72+
Constrict = new OutputCommandValue(speed)
73+
};
74+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
75+
}
76+
77+
public bool CanHeater()
78+
{
79+
return _feature.Output.ContainsKey(OutputType.Heater);
80+
}
81+
82+
public async Task HeaterAsync(uint speed)
83+
{
84+
var outputCmd = new OutputCommand
85+
{
86+
Heater = new OutputCommandValue(speed)
87+
};
88+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
89+
}
90+
91+
public bool CanSpray()
92+
{
93+
return _feature.Output.ContainsKey(OutputType.Spray);
94+
}
95+
96+
public async Task SprayAsync(uint speed)
97+
{
98+
var outputCmd = new OutputCommand
99+
{
100+
Spray = new OutputCommandValue(speed)
101+
};
102+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
103+
}
104+
105+
public bool CanLed()
106+
{
107+
return _feature.Output.ContainsKey(OutputType.Led);
108+
}
109+
110+
public async Task LedAsync(uint speed)
111+
{
112+
var outputCmd = new OutputCommand
113+
{
114+
Led = new OutputCommandValue(speed)
115+
};
116+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
117+
}
118+
119+
public bool CanPositionWithDuration()
120+
{
121+
return _feature.Output.ContainsKey(OutputType.PositionWithDuration);
122+
}
123+
124+
public async Task PositionWithDurationAsync(uint position, uint duration)
125+
{
126+
var outputCmd = new OutputCommand
127+
{
128+
PositionWithDuration = new OutputCommandPositionWithDuration {
129+
Position = position,
130+
Duration = duration
131+
}
132+
};
133+
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
134+
}
135+
136+
public bool CanRotateWithDirection()
137+
{
138+
return _feature.Output.ContainsKey(OutputType.RotateWithDirection);
139+
}
140+
141+
public async Task RotateWithDirectionAsync(uint speed, bool clockwork)
142+
{
143+
var outputCmd = new OutputCommand
144+
{
145+
RotateWithDirection = new OutputCommandRotationWithDirection {
146+
Speed = speed,
147+
Clockwise = clockwork
148+
}
149+
};
30150
await _handler.SendMessageExpectOk(new OutputCmd(_deviceIndex, _feature.FeatureIndex, outputCmd));
31151
}
32152
}

Buttplug/Core/Messages/OutputCmd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class OutputCommand
3434
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
3535
public OutputCommandPositionWithDuration PositionWithDuration;
3636
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
37-
public OutputCommandRotationWithDirection RotationWithDirection;
37+
public OutputCommandRotationWithDirection RotateWithDirection;
3838
}
3939

4040
public class OutputCommandValue

0 commit comments

Comments
 (0)