Skip to content

Commit

Permalink
Merge branch 'feature/method-arrays'
Browse files Browse the repository at this point in the history
  • Loading branch information
Clive Galway committed Mar 7, 2021
2 parents 81eeb75 + e203615 commit 29a15ed
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
12 changes: 12 additions & 0 deletions C#/ViGEmWrapper/TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@ static void Main(string[] args)
//xb.SendReport();
//xb.SetButtonState(Xbox360Buttons.A, false);
//xb.SendReport();
//xb.SubscribeFeedback(new Action<byte, byte, byte>(OnXbFeedback));

var ds4 = new Ds4();
ds4.SetButtonState(DualShock4Buttons.Circle, true);
ds4.SendReport();
ds4.SubscribeFeedback(new Action<byte, byte, string>(OnDs4Feedback));

ds4.SetButtonState(DualShock4Buttons.Circle, false);
ds4.SendReport();
Console.ReadLine();
}

private static void OnXbFeedback(byte largeMotor, byte smallMotor, byte ledNumber)
{
Console.WriteLine($"XB360 Feedback received - LargeMotor: {largeMotor}, SmallMotor: {smallMotor}. LedNumber: {ledNumber}");
}

private static void OnDs4Feedback(byte largeMotor, byte smallMotor, string lightbarColor)
{
Console.WriteLine($"DS4 Feedback received - LargeMotor: {largeMotor}, SmallMotor: {smallMotor}. LightbarColor: {lightbarColor}");
}
}
}
25 changes: 23 additions & 2 deletions C#/ViGEmWrapper/ViGEmWrapper/Ds4.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.DualShock4;

namespace ViGEmWrapper
Expand All @@ -8,6 +7,10 @@ public class Ds4
{
private readonly DualShock4Controller _controller;
private readonly DualShock4Report _report;
private dynamic _feedbackCallback;
private byte _lastLargeMotor;
private byte _lastSmallMotor;
private string _lastLightBarColor = "0x000000";

public Ds4()
{
Expand Down Expand Up @@ -45,5 +48,23 @@ public void SendReport()
{
_controller.SendReport(_report);
}

public void SubscribeFeedback(dynamic callback)
{
_feedbackCallback = callback;
_controller.FeedbackReceived += OnFeedbackReceived;
}

private void OnFeedbackReceived(object sender, DualShock4FeedbackReceivedEventArgs e)
{
if (_feedbackCallback == null) return;
var lightBarColor = $"0x{e.LightbarColor.Red:X2}{e.LightbarColor.Green:X2}{e.LightbarColor.Blue:X2}";
if (e.LargeMotor == _lastLargeMotor && e.SmallMotor == _lastSmallMotor &&
lightBarColor == _lastLightBarColor) return;
_lastLargeMotor = e.LargeMotor;
_lastSmallMotor = e.SmallMotor;
_lastLightBarColor = lightBarColor;
_feedbackCallback(e.LargeMotor, e.SmallMotor, lightBarColor);
}
}
}
13 changes: 13 additions & 0 deletions C#/ViGEmWrapper/ViGEmWrapper/Xb360.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Xb360
{
private readonly Xbox360Controller _controller;
private readonly Xbox360Report _report;
private dynamic _feedbackCallback;

public Xb360()
{
Expand Down Expand Up @@ -34,5 +35,17 @@ public void SendReport()
{
_controller.SendReport(_report);
}

public void SubscribeFeedback(dynamic callback)
{
_feedbackCallback = callback;
_controller.FeedbackReceived += OnFeedbackReceived;
}

private void OnFeedbackReceived(object sender, Xbox360FeedbackReceivedEventArgs e)
{
if (_feedbackCallback == null) return;
_feedbackCallback(e.LargeMotor, e.SmallMotor, e.LedNumber);
}
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
### Added
- Added support for feedback (Rumble, LEDs)
### Changed
### Deprecated
### Removed
### Fixed

## [0.0.2] - 2020-05-08
- Fix Xbox360 Dpad

## [0.0.1] - 2020-04-29
- Initial release
21 changes: 19 additions & 2 deletions DS4 Example.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

; Create a new controller controller
controller := new ViGEmDS4()
controller.SubscribeFeedback(Func("OnFeedback"))
return

OnFeedback(largeMotor, smallMotor, lightbarColor){
OutputDebug % "AHK| Feedback received - LargeMotor: " largeMotor ", SmallMotor: " smallMotor ", LightBarColor: " lightbarColor
}

; === Buttons
1::
controller.Buttons.Square.SetState(true)
Expand Down Expand Up @@ -173,10 +178,22 @@ l up::
controller.Axes.RX.SetState(50)
return

Left::
; == Left Trigger
left::
controller.Axes.LT.SetState(100)
return

left up::
controller.Axes.LT.SetState(0)
return

; == Right Trigger
right::
controller.Axes.RT.SetState(100)
return

Right::
right up::
controller.Axes.RT.SetState(0)
return

; === Dpad
Expand Down
6 changes: 5 additions & 1 deletion Lib/AHK-ViGEm-Bus.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ViGEmTarget {
SendReport(){
this.Instance.SendReport()
}

SubscribeFeedback(callback){
this.Instance.SubscribeFeedback(callback)
}
}

; DS4 (DualShock 4 for Playstation 4)
Expand Down Expand Up @@ -198,7 +202,7 @@ class ViGEmXb360 extends ViGEmTarget {
oldState := this._DpadStates[id]
if (oldState != newState){
this._DpadStates[id] := newState
this._Parent.SetButtonState(id, newState)
this._Parent.Instance.SetButtonState(id, newState)
}
this._Parent.SendReport()
}
Expand Down
23 changes: 23 additions & 0 deletions XB360 Example.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

; Create a new Xbox 360 controller
controller := new ViGEmXb360()
controller.SubscribeFeedback(Func("OnFeedback"))
return

OnFeedback(largeMotor, smallMotor, ledNumber){
Tooltip % "Feedback received - LargeMotor: " largeMotor ", SmallMotor: " smallMotor ", LedNumber: " ledNumber
}

; === Buttons
1::
controller.Buttons.A.SetState(true)
Expand Down Expand Up @@ -148,6 +153,24 @@ l up::
controller.Axes.RX.SetState(50)
return

; == Left Trigger
left::
controller.Axes.LT.SetState(100)
return

left up::
controller.Axes.LT.SetState(0)
return

; == Right Trigger
right::
controller.Axes.RT.SetState(100)
return

right up::
controller.Axes.RT.SetState(0)
return

; === Dpad
Numpad8::
controller.Dpad.SetState("Up")
Expand Down

0 comments on commit 29a15ed

Please sign in to comment.