Skip to content

Commit e8f2c86

Browse files
blackspherefollowerqdot
authored andcommitted
Updating the applications to support the MessageAttribute changes
The ExampleClientGUI also gains support for some generic commands.
1 parent dc1072d commit e8f2c86

5 files changed

Lines changed: 98 additions & 28 deletions

File tree

Buttplug.Apps.ExampleClientGUI/ExampleClientPanel.xaml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
<RowDefinition Height="Auto"/>
1212
<RowDefinition Height="Auto"/>
1313
<RowDefinition Height="Auto"/>
14+
<RowDefinition Height="Auto"/>
1415
<RowDefinition Height="*"/>
1516
</Grid.RowDefinitions>
1617
<Label Content="Address:" Grid.Row="0" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Center"/>
1718
<TextBox Name="AdressTextBox" Grid.Row="0" HorizontalAlignment="Left" Height="23" Margin="80,0,0,0" TextWrapping="Wrap" Text="ws://localhost:12345" VerticalAlignment="Center" Width="120"/>
1819
<Button Name="ConnToggleButton" Grid.Row="0" Content="Connect" HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center" Width="75" Click="ConnToggleButton_Click"/>
1920

20-
<GroupBox Grid.Row="1" Header="Linerar">
21+
<GroupBox Grid.Row="1" Header="Linear (Fleshlight Launch)">
2122
<Grid>
2223
<Grid.RowDefinitions>
2324
<RowDefinition Height="Auto"/>
@@ -35,7 +36,27 @@
3536
<Button Name="SendLinear" Content="Send" Grid.Row="1" Grid.Column="2" Click="SendLinear_Click"/>
3637
</Grid>
3738
</GroupBox>
38-
<GroupBox Grid.Row="2" Header="Vibrate">
39+
40+
<GroupBox Grid.Row="2" Header="Linear (generic)">
41+
<Grid>
42+
<Grid.RowDefinitions>
43+
<RowDefinition Height="Auto"/>
44+
<RowDefinition Height="Auto"/>
45+
</Grid.RowDefinitions>
46+
<Grid.ColumnDefinitions>
47+
<ColumnDefinition Width="Auto"/>
48+
<ColumnDefinition Width="*"/>
49+
<ColumnDefinition Width="Auto"/>
50+
</Grid.ColumnDefinitions>
51+
<Label Content="Position:" Grid.Row="0" Grid.Column="0"/>
52+
<Slider Name="Linear2Position" Grid.Row="0" Grid.Column="1" Maximum="1" SmallChange="0.01" LargeChange="0.1"/>
53+
<Label Content="Duration:" Grid.Row="1" Grid.Column="0"/>
54+
<TextBox Name="LinearDuration" Grid.Row="1" Grid.Column="1" Text="500"/>
55+
<Button Name="SendLinear2" Content="Send" Grid.Row="1" Grid.Column="2" Click="SendLinear2_Click"/>
56+
</Grid>
57+
</GroupBox>
58+
59+
<GroupBox Grid.Row="3" Header="Vibrate">
3960
<Grid>
4061
<Grid.RowDefinitions>
4162
<RowDefinition Height="Auto"/>
@@ -50,7 +71,8 @@
5071
<Button Name="SendVibrate" Content="Send" Grid.Row="0" Grid.Column="2" Click="SendVibrate_Click"/>
5172
</Grid>
5273
</GroupBox>
53-
<GroupBox Grid.Row="3" Header="Rotate">
74+
75+
<GroupBox Grid.Row="4" Header="Rotate">
5476
<Grid>
5577
<Grid.RowDefinitions>
5678
<RowDefinition Height="Auto"/>
@@ -61,7 +83,7 @@
6183
<ColumnDefinition Width="Auto"/>
6284
</Grid.ColumnDefinitions>
6385
<Label Content="Speed:" Grid.Row="0" Grid.Column="0"/>
64-
<Slider Name="RotateSpeed" Grid.Row="0" Grid.Column="1" SmallChange="2" LargeChange="20" Maximum="99" Minimum="-99"/>
86+
<Slider Name="RotateSpeed" Grid.Row="0" Grid.Column="1" Maximum="1" LargeChange="0.1" SmallChange="0.01" Minimum="-1"/>
6587
<Button Name="SendRotate" Content="Send" Grid.Row="0" Grid.Column="2" Height="26" Click="SendRotate_Click"/>
6688
</Grid>
6789
</GroupBox>

Buttplug.Apps.ExampleClientGUI/ExampleClientPanel.xaml.cs

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
34
using System.Windows;
45
using Buttplug.Client;
56
using Buttplug.Components.Controls;
@@ -71,7 +72,7 @@ private async void Connect()
7172

7273
foreach (var dev in _client.getDevices())
7374
{
74-
devControl.DeviceAdded(new ButtplugDeviceInfo(dev.Index, dev.Name, dev.AllowedMessages.ToArray()));
75+
devControl.DeviceAdded(new ButtplugDeviceInfo(dev.Index, dev.Name, dev.AllowedMessages));
7576
}
7677
}
7778
}
@@ -86,7 +87,7 @@ private void OnDeviceChanged(object sender, DeviceEventArgs e)
8687
switch (e.Action)
8788
{
8889
case DeviceAction.ADDED:
89-
devControl.DeviceAdded(new ButtplugDeviceInfo(e.Device.Index, e.Device.Name, e.Device.AllowedMessages.ToArray()));
90+
devControl.DeviceAdded(new ButtplugDeviceInfo(e.Device.Index, e.Device.Name, e.Device.AllowedMessages));
9091
break;
9192

9293
case DeviceAction.REMOVED:
@@ -135,7 +136,7 @@ private void SendLinear_Click(object sender, RoutedEventArgs e)
135136

136137
foreach (var dev in Devices.Values)
137138
{
138-
if (dev.AllowedMessages.Contains("FleshlightLaunchFW12Cmd"))
139+
if (dev.AllowedMessages.ContainsKey("FleshlightLaunchFW12Cmd"))
139140
{
140141
_client.SendDeviceMessage(dev,
141142
new FleshlightLaunchFW12Cmd(dev.Index,
@@ -155,12 +156,24 @@ private void SendVibrate_Click(object sender, RoutedEventArgs e)
155156

156157
foreach (var dev in Devices.Values)
157158
{
158-
if (dev.AllowedMessages.Contains("SingleMotorVibrateCmd"))
159+
if (dev.AllowedMessages.TryGetValue("VibrateCmd", out var attrs))
159160
{
160-
_client.SendDeviceMessage(dev,
161-
new SingleMotorVibrateCmd(dev.Index,
162-
Convert.ToDouble(VibrateSpeed.Value),
163-
_client.nextMsgId));
161+
try
162+
{
163+
uint vibratorCount = attrs.FeatureCount ?? 0;
164+
165+
for (uint i = 0; i < vibratorCount; i++)
166+
{
167+
_client.SendDeviceMessage(dev,
168+
new VibrateCmd(dev.Index,
169+
new List<VibrateCmd.VibrateIndex>
170+
{ new VibrateCmd.VibrateIndex(i, VibrateSpeed.Value) },
171+
_client.nextMsgId));
172+
}
173+
}
174+
catch
175+
{
176+
}
164177
}
165178
}
166179
}
@@ -174,14 +187,45 @@ private void SendRotate_Click(object sender, RoutedEventArgs e)
174187

175188
foreach (var dev in Devices.Values)
176189
{
177-
if (dev.AllowedMessages.Contains("VorzeA10CycloneCmd"))
190+
if (dev.AllowedMessages.TryGetValue("RotateCmd", out var attrs))
191+
{
192+
try
193+
{
194+
uint rotatorCount = attrs.FeatureCount ?? 0;
195+
196+
for (uint i = 0; i < rotatorCount; i++)
197+
{
198+
bool clockwise = RotateSpeed.Value > 0;
199+
_client.SendDeviceMessage(dev,
200+
new RotateCmd(dev.Index,
201+
new List<RotateCmd.RotateIndex>
202+
{ new RotateCmd.RotateIndex(i, RotateSpeed.Value * (clockwise ? 1 : -1), clockwise) },
203+
_client.nextMsgId));
204+
}
205+
}
206+
catch
207+
{
208+
}
209+
}
210+
}
211+
}
212+
213+
private void SendLinear2_Click(object sender, RoutedEventArgs e)
214+
{
215+
if (!_client.IsConnected)
216+
{
217+
return;
218+
}
219+
220+
foreach (var dev in Devices.Values)
221+
{
222+
if (dev.AllowedMessages.ContainsKey("FleshlightLaunchFW12Cmd"))
178223
{
179-
bool clockwise = RotateSpeed.Value > 0;
180224
_client.SendDeviceMessage(dev,
181-
new VorzeA10CycloneCmd(dev.Index,
182-
Convert.ToUInt32(RotateSpeed.Value * (clockwise ? 1 : -1)),
183-
clockwise,
184-
_client.nextMsgId));
225+
new LinearCmd(dev.Index, new List<LinearCmd.VectorIndex>()
226+
{
227+
new LinearCmd.VectorIndex(0, Convert.ToUInt32(LinearDuration.Text), Linear2Position.Value),
228+
}, _client.nextMsgId));
185229
}
186230
}
187231
}

Buttplug.Apps.GameVibrationRouter.GUI/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ await Dispatcher.Invoke(async () =>
107107
foreach (var device in _devices)
108108
{
109109
// For now, we only handle devices that can take vibration messages.
110-
if (!device.Messages.Contains(typeof(SingleMotorVibrateCmd).Name))
110+
if (!device.Messages.Keys.Contains(typeof(SingleMotorVibrateCmd).Name))
111111
{
112112
continue;
113113
}

Buttplug.Apps.KiirooEmulatorGUI/MainWindow.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void ClosingHandler(object aObj, CancelEventArgs e)
8080
private void SelectionChangedHandler(object aObj, List<ButtplugDeviceInfo> aDevices)
8181
{
8282
_devices = aDevices;
83-
if (_devices.Any(aDevice => aDevice.Messages.Contains("SingleMotorVibrateCmd")))
83+
if (_devices.Any(aDevice => aDevice.Messages.Keys.Contains("SingleMotorVibrateCmd")))
8484
{
8585
_translator.StartVibrateTimer();
8686
return;
@@ -133,7 +133,7 @@ private void OnVibrateEvent(object aObj, VibrateEventArgs aEvent)
133133
{
134134
foreach (var device in _devices)
135135
{
136-
if (device.Messages.Contains("SingleMotorVibrateCmd"))
136+
if (device.Messages.Keys.Contains("SingleMotorVibrateCmd"))
137137
{
138138
await _bpServer.SendMessage(new SingleMotorVibrateCmd(device.Index, aEvent.VibrateValue));
139139
}
@@ -150,19 +150,19 @@ await Dispatcher.InvokeAsync(async () =>
150150
FleshlightLaunchFW12Cmd currentTranslatedCommand = null;
151151
foreach (var device in _devices)
152152
{
153-
if (device.Messages.Contains(typeof(KiirooCmd).Name))
153+
if (device.Messages.Keys.Contains(typeof(KiirooCmd).Name))
154154
{
155155
await _bpServer.SendMessage(new KiirooCmd(device.Index, aEvent.Position));
156156
}
157-
else if (device.Messages.Contains("FleshlightLaunchFW12Cmd") ||
158-
device.Messages.Contains("SingleMotorVibrateCmd"))
157+
else if (device.Messages.Keys.Contains("FleshlightLaunchFW12Cmd") ||
158+
device.Messages.Keys.Contains("SingleMotorVibrateCmd"))
159159
{
160160
if (currentTranslatedCommand == null)
161161
{
162162
currentTranslatedCommand = _translator.Translate(new KiirooCmd(device.Index, aEvent.Position));
163163
}
164164
currentTranslatedCommand.DeviceIndex = device.Index;
165-
if (device.Messages.Contains("FleshlightLaunchFW12Cmd"))
165+
if (device.Messages.Keys.Contains("FleshlightLaunchFW12Cmd"))
166166
{
167167
await _bpServer.SendMessage(currentTranslatedCommand);
168168
}

Buttplug.Components.Controls/ButtplugDeviceInfo.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
namespace Buttplug.Components.Controls
1+
using System.Collections.Generic;
2+
using Buttplug.Core.Messages;
3+
4+
namespace Buttplug.Components.Controls
25
{
36
public class ButtplugDeviceInfo
47
{
58
public string Name { get; }
69

710
public uint Index { get; }
811

9-
public string[] Messages { get; }
12+
public Dictionary<string, MessageAttributes> Messages { get; }
1013

11-
public ButtplugDeviceInfo(uint aIndex, string aName, string[] aMessages)
14+
public ButtplugDeviceInfo(uint aIndex, string aName,
15+
Dictionary<string, MessageAttributes> aMessages)
1216
{
1317
Index = aIndex;
1418
Name = aName;

0 commit comments

Comments
 (0)