Skip to content

Commit

Permalink
feat: Readd multipler/baseline features
Browse files Browse the repository at this point in the history
Make the multiplier and baseline settings work again. Also hook up
visualizer, and feed baseline/multiplier to visualizer.

Fixes #14
Fixes #15
  • Loading branch information
qdot committed Jul 26, 2019
1 parent 69882fd commit 3b9541c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
24 changes: 22 additions & 2 deletions IntifaceGameHapticsRouter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class MainWindow : Window
private readonly NLog.Logger _log;
private Timer vrTimer = new Timer();
private Timer xinputTimer = new Timer();
private XInputHaptics _lastXInput;
private XInputHaptics _lastXInput = new XInputHaptics(0, 0);
private bool _needXInputRecalc;
private double _multiplier;
private double _baseline;
Expand Down Expand Up @@ -45,6 +45,8 @@ public MainWindow()

_intifaceTab.LogMessageHandler += OnLogMessage;
_modTab.MessageReceivedHandler += OnGVRMessageReceived;
_modTab.ProcessAttached += OnProcessAttached;
_modTab.ProcessDetached += OnProcessDetached;
_graphTab.MultiplierChanged += OnMultiplierChanged;
_graphTab.BaselineChanged += OnBaselineChanged;
_multiplier = _graphTab.Multiplier;
Expand All @@ -53,6 +55,16 @@ public MainWindow()
_log.Info("Application started.");
}

protected void OnProcessAttached(object aObj, EventArgs aNull)
{
_graphTab.StartUpdates();
}

protected void OnProcessDetached(object aObj, EventArgs aNull)
{
_graphTab.StopUpdates();
}

protected void OnMultiplierChanged(object aObj, double aValue)
{
_needXInputRecalc = true;
Expand All @@ -63,6 +75,10 @@ protected void OnBaselineChanged(object aObj, double aValue)
{
_needXInputRecalc = true;
_baseline = aValue;
if (!xinputTimer.Enabled)
{
xinputTimer.Start();
}
}

protected void OnLogMessage(object aObj, string aMsg)
Expand All @@ -84,11 +100,15 @@ protected async void OnXInputTimer(object aObj, ElapsedEventArgs aArgs)
}

// If we've received an off packet, just assume we won't be updating again until we get something new.
if (_lastXInput.LeftMotor == 0 && _lastXInput.RightMotor == 0)
if (_lastXInput.LeftMotor == 0 && _lastXInput.RightMotor == 0 && _baseline == 0)
{
xinputTimer.Stop();
}

_graphTab.UpdateVibrationValues(
Math.Max((uint)(_lastXInput.LeftMotor * _multiplier), (uint)(_baseline * 65535.0)),
Math.Max((uint)(_lastXInput.RightMotor * _multiplier), (uint)(_baseline * 65535.0)));

var averageVibeSpeed = (_lastXInput.LeftMotor + _lastXInput.RightMotor) / (2.0 * 65535.0);

// Calculate the vibe speed by first adding the multiplier to the averaged speed
Expand Down
13 changes: 11 additions & 2 deletions IntifaceGameHapticsRouter/ModControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public string ProcessError

private ProcessInfoList _processList = new ProcessInfoList();

public event EventHandler<int> ProcessAttachRequested;
public event EventHandler<EventArgs> ProcessAttached;

public event EventHandler<bool> ProcessDetachRequested;
public event EventHandler<EventArgs> ProcessDetached;

private bool _attached;
private readonly Logger _log;
Expand Down Expand Up @@ -187,22 +187,31 @@ private void AttachButton_Click(object aObj, System.Windows.RoutedEventArgs aEve
if (!_attached)
{
var process = ProcessListBox.SelectedItems.Cast<ProcessInfo>().ToList();
var attached = false;
if (process[0].CanUseMono)
{
_unityMod = new UnityVRMod();
_unityMod.MessageReceivedHandler += OnMessageReceived;
_unityMod.Inject(process[0].Id, process[0].FrameworkVersion, process[0].MonoModule);
attached = true;
}

if (process[0].CanUseXInput)
{
_xinputMod = new XInputMod();
_xinputMod.Attach(process[0].Id);
_xinputMod.MessageReceivedHandler += OnMessageReceived;
attached = true;
}

if (attached)
{
ProcessAttached?.Invoke(this, null);
}
}
else
{
ProcessDetached?.Invoke(this, null);
Detach();
}
}
Expand Down
2 changes: 1 addition & 1 deletion IntifaceGameHapticsRouter/Resources/BuildDate.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Wed 05/22/2019 15:32:50.12
Thu 07/25/2019 18:24:39.63
4 changes: 2 additions & 2 deletions IntifaceGameHapticsRouter/VisualizerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Slider x:Name="multiplierSlider" Foreground="Black" Grid.Column="0" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" TickPlacement="BottomRight" Value="1" Maximum="5" TickFrequency="0.1" IsSnapToTickEnabled="True" Margin="0,2,0,1.667"/>
<Slider x:Name="multiplierSlider" Foreground="Black" Grid.Column="0" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" TickPlacement="BottomRight" Value="1" Maximum="5" TickFrequency="0.1" IsSnapToTickEnabled="True" Margin="0,2,0,1.667" ValueChanged="MultiplierSlider_OnValueChanged"/>
<TextBlock Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding ElementName=multiplierSlider, Path=Value, StringFormat='x\{0:0.0\}'}" Height="16" Margin="15.333,0,14,0.333" Width="auto"></TextBlock>
</Grid>
</GroupBox>
Expand All @@ -37,7 +37,7 @@
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Slider x:Name="baselineSlider" Foreground="Black" Grid.Column="0" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" TickPlacement="BottomRight" Value="0" Maximum="1" TickFrequency="0.02" IsSnapToTickEnabled="True" Margin="0,2,0,1.667"/>
<Slider x:Name="baselineSlider" Foreground="Black" Grid.Column="0" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" TickPlacement="BottomRight" Value="0" Maximum="1" TickFrequency="0.02" IsSnapToTickEnabled="True" ValueChanged="BaselineSlider_OnValueChanged" Margin="0,2,0,1.667"/>
<TextBlock Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding ElementName=baselineSlider, Path=Value, StringFormat='P0'}" Height="16" Margin="15.333,0,14,0.333" Width="auto"></TextBlock>
</Grid>
</GroupBox>
Expand Down
11 changes: 11 additions & 0 deletions IntifaceGameHapticsRouter/VisualizerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,16 @@ private void PassthruCheckBox_Changed(object aSender, RoutedEventArgs aArgs)
{
PassthruChanged?.Invoke(this, PassthruCheckBox.IsChecked.Value);
}

private void BaselineSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
BaselineChanged?.Invoke(this, Baseline);
}


private void MultiplierSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
MultiplierChanged?.Invoke(this, Multiplier);
}
}
}

0 comments on commit 3b9541c

Please sign in to comment.