Skip to content

Commit 10ada5c

Browse files
bnm12qdot
authored andcommitted
feat: Early vibration multiplier feature implemented
Fixes #374
1 parent 8c83b83 commit 10ada5c

6 files changed

Lines changed: 86 additions & 1 deletion

File tree

Buttplug.Apps.GameVibrationRouter.GUI/Buttplug.Apps.GameVibrationRouter.GUI.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
<Generator>MSBuild:Compile</Generator>
8181
<SubType>Designer</SubType>
8282
</ApplicationDefinition>
83+
<Compile Include="VibeConfigTab.xaml.cs">
84+
<DependentUpon>VibeConfigTab.xaml</DependentUpon>
85+
</Compile>
8386
<Compile Include="VibeGraphTab.xaml.cs">
8487
<DependentUpon>VibeGraphTab.xaml</DependentUpon>
8588
</Compile>
@@ -95,6 +98,10 @@
9598
<DependentUpon>MainWindow.xaml</DependentUpon>
9699
<SubType>Code</SubType>
97100
</Compile>
101+
<Page Include="VibeConfigTab.xaml">
102+
<Generator>MSBuild:Compile</Generator>
103+
<SubType>Designer</SubType>
104+
</Page>
98105
<Page Include="ProcessTab.xaml">
99106
<Generator>MSBuild:Compile</Generator>
100107
<SubType>Designer</SubType>

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ public partial class MainWindow
3636
[NotNull]
3737
private readonly VibeGraphTab _graphTab;
3838

39+
[NotNull]
40+
private readonly VibeConfigTab _vibeTab;
41+
3942
private IpcServerChannel _xinputHookServer;
4043
private string _channelName;
4144
private List<ButtplugDeviceInfo> _devices = new List<ButtplugDeviceInfo>();
4245
private Vibration _lastVibration = new Vibration();
4346
private Vibration _lastSentVibration = new Vibration();
4447
private Timer runTimer;
4548
private Timer commandTimer;
49+
private double _vibrationMultiplier = 1;
4650

4751
public MainWindow()
4852
{
@@ -70,6 +74,10 @@ public MainWindow()
7074
ButtplugTab.AddDevicePanel(_bpServer);
7175
ButtplugTab.SelectedDevicesChanged += OnSelectedDevicesChanged;
7276

77+
_vibeTab = new VibeConfigTab();
78+
_vibeTab.MultiplierChanged += MultiplierChanged;
79+
ButtplugTab.SetOtherTab2("Vibe Config", _vibeTab);
80+
7381
var config = new ButtplugConfig("Buttplug");
7482
ButtplugTab.GetAboutControl().CheckUpdate(config, "buttplug-csharp");
7583

@@ -82,6 +90,11 @@ public MainWindow()
8290
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
8391
}
8492

93+
private void MultiplierChanged(object sender, double vibeMultiplier)
94+
{
95+
_vibrationMultiplier = vibeMultiplier;
96+
}
97+
8598
public void AddPoint(object o, ElapsedEventArgs e)
8699
{
87100
_graphTab.AddVibrationValue(_lastVibration.LeftMotorSpeed, _lastVibration.RightMotorSpeed);
@@ -142,14 +155,17 @@ await Dispatcher.Invoke(async () =>
142155
{
143156
continue;
144157
}
158+
double vibeSpeed = (_lastVibration.LeftMotorSpeed + _lastVibration.RightMotorSpeed) / (2.0 * 65535.0);
145159
await _bpServer.SendMessage(new SingleMotorVibrateCmd(device.Index,
146-
(_lastVibration.LeftMotorSpeed + _lastVibration.RightMotorSpeed) / (2.0 * 65535.0)));
160+
Math.Min(vibeSpeed * _vibrationMultiplier, 1.0)));
147161
}
148162
});
149163
}
150164

151165
private void OnVibrationCommand(object aObj, Vibration aVibration)
152166
{
167+
aVibration.LeftMotorSpeed = Convert.ToUInt16(aVibration.LeftMotorSpeed * _vibrationMultiplier > 65535 ? 65535 : aVibration.LeftMotorSpeed * _vibrationMultiplier);
168+
aVibration.RightMotorSpeed = Convert.ToUInt16(aVibration.RightMotorSpeed * _vibrationMultiplier > 65535 ? 65535 : aVibration.RightMotorSpeed * _vibrationMultiplier);
153169
_lastVibration = aVibration;
154170
}
155171

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<UserControl x:Class="Buttplug.Apps.GameVibrationRouter.GUI.VibeConfigTab"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Buttplug.Apps.GameVibrationRouter.GUI"
7+
mc:Ignorable="d"
8+
d:DesignHeight="300" d:DesignWidth="500">
9+
<Grid Background="#FFE5E5E5">
10+
<Grid.ColumnDefinitions>
11+
<ColumnDefinition></ColumnDefinition>
12+
<ColumnDefinition></ColumnDefinition>
13+
</Grid.ColumnDefinitions>
14+
<Grid.RowDefinitions>
15+
<RowDefinition></RowDefinition>
16+
<RowDefinition></RowDefinition>
17+
<RowDefinition></RowDefinition>
18+
</Grid.RowDefinitions>
19+
<Label Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center">Vibration Multiplier:</Label>
20+
<Slider x:Name="multiplierSlider" Foreground="Black" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" TickPlacement="BottomRight" ValueChanged="multiplierSlider_ValueChanged" Value="1" Maximum="5" TickFrequency="0.1" IsSnapToTickEnabled="True"/>
21+
<TextBlock Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding ElementName=multiplierSlider, Path=Value, StringFormat='x\{0\}'}"></TextBlock>
22+
23+
</Grid>
24+
</UserControl>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using EasyHook;
2+
using NLog;
3+
using System;
4+
using System.Collections.ObjectModel;
5+
using System.ComponentModel;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
9+
namespace Buttplug.Apps.GameVibrationRouter.GUI
10+
{
11+
/// <summary>
12+
/// Interaction logic for UserControl1.xaml
13+
/// </summary>
14+
15+
public partial class VibeConfigTab
16+
{
17+
public event EventHandler<double> MultiplierChanged;
18+
private readonly Logger _log;
19+
public VibeConfigTab()
20+
{
21+
_log = LogManager.GetCurrentClassLogger();
22+
InitializeComponent();
23+
}
24+
25+
private void multiplierSlider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
26+
{
27+
MultiplierChanged?.Invoke(this, e.NewValue);
28+
}
29+
}
30+
}

Buttplug.Components.Controls/ButtplugTabControl.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
</TabItem>
1515
<TabItem Name="OtherTab" Visibility="Collapsed">
1616
</TabItem>
17+
<TabItem Name="OtherTab2" Visibility="Collapsed">
18+
</TabItem>
1719
<TabItem Header="Logs">
1820
<local:ButtplugLogControl x:Name="LogControl" />
1921
</TabItem>

Buttplug.Components.Controls/ButtplugTabControl.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ public void SetOtherTab(string aTabName, UserControl aTabControl)
241241
OtherTab.Content = aTabControl;
242242
OtherTab.Visibility = Visibility.Visible;
243243
}
244+
public void SetOtherTab2(string aTabName, UserControl aTabControl)
245+
{
246+
OtherTab2.Header = aTabName;
247+
OtherTab2.Content = aTabControl;
248+
OtherTab2.Visibility = Visibility.Visible;
249+
}
244250

245251
public ButtplugLogControl GetLogControl()
246252
{

0 commit comments

Comments
 (0)