2014-03-28 02:50:40 +01:00
using System ;
using System.Collections.Generic ;
2017-05-14 01:47:54 +02:00
using System.IO ;
using System.Threading.Tasks ;
2017-06-08 22:52:47 +02:00
using System.Threading ;
2018-07-16 07:21:34 +02:00
using System.Diagnostics ;
2019-12-27 21:25:17 +01:00
using static DS4Windows . Global ;
2018-05-06 09:13:11 +02:00
using Nefarius.ViGEm.Client ;
2018-07-18 07:04:51 +02:00
2015-02-08 22:51:52 +01:00
namespace DS4Windows
2014-03-28 02:50:40 +01:00
{
2015-02-08 22:51:52 +01:00
public class ControlService
2014-03-28 02:50:40 +01:00
{
2018-05-06 09:13:11 +02:00
public ViGEmClient vigemTestClient = null ;
2017-04-02 02:46:51 +02:00
public const int DS4_CONTROLLER_COUNT = 4 ;
public DS4Device [ ] DS4Controllers = new DS4Device [ DS4_CONTROLLER_COUNT ] ;
public Mouse [ ] touchPad = new Mouse [ DS4_CONTROLLER_COUNT ] ;
2019-12-18 22:33:23 +01:00
public bool running = false ;
2017-04-02 02:46:51 +02:00
private DS4State [ ] MappedState = new DS4State [ DS4_CONTROLLER_COUNT ] ;
private DS4State [ ] CurrentState = new DS4State [ DS4_CONTROLLER_COUNT ] ;
private DS4State [ ] PreviousState = new DS4State [ DS4_CONTROLLER_COUNT ] ;
2017-12-02 08:45:51 +01:00
private DS4State [ ] TempState = new DS4State [ DS4_CONTROLLER_COUNT ] ;
2017-04-02 02:46:51 +02:00
public DS4StateExposed [ ] ExposedState = new DS4StateExposed [ DS4_CONTROLLER_COUNT ] ;
2019-12-18 22:33:23 +01:00
public ControllerSlotManager slotManager = new ControllerSlotManager ( ) ;
2014-11-14 20:44:50 +01:00
public bool recordingMacro = false ;
2014-03-28 02:50:40 +01:00
public event EventHandler < DebugEventArgs > Debug = null ;
2017-07-19 22:15:59 +02:00
bool [ ] buttonsdown = new bool [ 4 ] { false , false , false , false } ;
2017-04-02 02:46:51 +02:00
bool [ ] held = new bool [ DS4_CONTROLLER_COUNT ] ;
int [ ] oldmouse = new int [ DS4_CONTROLLER_COUNT ] { - 1 , - 1 , - 1 , - 1 } ;
2019-04-18 04:29:16 +02:00
public OutputDevice [ ] outputDevices = new OutputDevice [ 4 ] { null , null , null , null } ;
2017-09-06 04:28:54 +02:00
Thread tempThread ;
2019-12-27 21:25:17 +01:00
Thread tempBusThread ;
2018-01-25 22:40:59 +01:00
public List < string > affectedDevs = new List < string > ( )
{
@"HID\VID_054C&PID_05C4" ,
@"HID\VID_054C&PID_09CC&MI_03" ,
2018-01-27 00:51:03 +01:00
@"HID\VID_054C&PID_0BA0&MI_03" ,
2018-01-25 22:40:59 +01:00
@"HID\{00001124-0000-1000-8000-00805f9b34fb}_VID&0002054c_PID&05c4" ,
@"HID\{00001124-0000-1000-8000-00805f9b34fb}_VID&0002054c_PID&09cc" ,
} ;
2018-02-26 10:51:24 +01:00
public bool suspending ;
2017-05-11 17:13:51 +02:00
//SoundPlayer sp = new SoundPlayer();
2018-05-06 09:13:11 +02:00
private UdpServer _udpServer ;
2019-12-11 16:58:31 +01:00
private OutputSlotManager outputslotMan ;
2014-03-28 02:50:40 +01:00
2019-12-18 22:33:23 +01:00
public event EventHandler ServiceStarted ;
public event EventHandler PreServiceStop ;
public event EventHandler ServiceStopped ;
public event EventHandler RunningChanged ;
//public event EventHandler HotplugFinished;
public delegate void HotplugControllerHandler ( ControlService sender , DS4Device device , int index ) ;
public event HotplugControllerHandler HotplugController ;
2019-07-02 09:06:32 +02:00
private byte [ ] [ ] udpOutBuffers = new byte [ 4 ] [ ]
{
new byte [ 100 ] , new byte [ 100 ] ,
new byte [ 100 ] , new byte [ 100 ]
} ;
2014-03-28 02:50:40 +01:00
2018-05-06 09:13:11 +02:00
void GetPadDetailForIdx ( int padIdx , ref DualShockPadMeta meta )
{
//meta = new DualShockPadMeta();
meta . PadId = ( byte ) padIdx ;
meta . Model = DsModel . DS4 ;
var d = DS4Controllers [ padIdx ] ;
if ( d = = null )
{
meta . PadMacAddress = null ;
meta . PadState = DsState . Disconnected ;
meta . ConnectionType = DsConnection . None ;
meta . Model = DsModel . None ;
meta . BatteryStatus = 0 ;
meta . IsActive = false ;
2018-07-18 03:46:40 +02:00
return ;
2018-05-06 09:13:11 +02:00
//return meta;
}
bool isValidSerial = false ;
//if (d.isValidSerial())
//{
string stringMac = d . getMacAddress ( ) ;
if ( ! string . IsNullOrEmpty ( stringMac ) )
{
stringMac = string . Join ( "" , stringMac . Split ( ':' ) ) ;
//stringMac = stringMac.Replace(":", "").Trim();
meta . PadMacAddress = System . Net . NetworkInformation . PhysicalAddress . Parse ( stringMac ) ;
isValidSerial = d . isValidSerial ( ) ;
}
//}
if ( ! isValidSerial )
{
//meta.PadMacAddress = null;
meta . PadState = DsState . Disconnected ;
}
else
{
if ( d . isSynced ( ) | | d . IsAlive ( ) )
meta . PadState = DsState . Connected ;
else
meta . PadState = DsState . Reserved ;
}
meta . ConnectionType = ( d . getConnectionType ( ) = = ConnectionType . USB ) ? DsConnection . Usb : DsConnection . Bluetooth ;
meta . IsActive = ! d . isDS4Idle ( ) ;
if ( d . isCharging ( ) & & d . getBattery ( ) > = 100 )
meta . BatteryStatus = DsBattery . Charged ;
else
{
if ( d . getBattery ( ) > = 95 )
meta . BatteryStatus = DsBattery . Full ;
else if ( d . getBattery ( ) > = 70 )
meta . BatteryStatus = DsBattery . High ;
else if ( d . getBattery ( ) > = 50 )
meta . BatteryStatus = DsBattery . Medium ;
else if ( d . getBattery ( ) > = 20 )
meta . BatteryStatus = DsBattery . Low ;
else if ( d . getBattery ( ) > = 5 )
meta . BatteryStatus = DsBattery . Dying ;
else
meta . BatteryStatus = DsBattery . None ;
}
//return meta;
}
2018-08-06 12:00:37 +02:00
private object busThrLck = new object ( ) ;
private bool busThrRunning = false ;
private Queue < Action > busEvtQueue = new Queue < Action > ( ) ;
private object busEvtQueueLock = new object ( ) ;
2015-02-08 22:51:52 +01:00
public ControlService ( )
2014-03-28 02:50:40 +01:00
{
2019-09-06 16:41:55 +02:00
Crc32Algorithm . InitializeTable ( DS4Device . DefaultPolynomial ) ;
2019-12-18 22:33:23 +01:00
//sp.Stream = DS4WinWPF.Properties.Resources.EE;
2017-06-18 16:07:48 +02:00
// Cause thread affinity to not be tied to main GUI thread
2020-01-26 04:22:18 +01:00
tempBusThread = new Thread ( ( ) = >
{
2018-08-06 12:00:37 +02:00
//_udpServer = new UdpServer(GetPadDetailForIdx);
busThrRunning = true ;
while ( busThrRunning )
{
lock ( busEvtQueueLock )
{
Action tempAct = null ;
for ( int actInd = 0 , actLen = busEvtQueue . Count ; actInd < actLen ; actInd + + )
{
tempAct = busEvtQueue . Dequeue ( ) ;
tempAct . Invoke ( ) ;
}
}
lock ( busThrLck )
Monitor . Wait ( busThrLck ) ;
}
} ) ;
2019-12-27 21:25:17 +01:00
tempBusThread . Priority = ThreadPriority . Normal ;
tempBusThread . IsBackground = true ;
tempBusThread . Start ( ) ;
2018-08-06 12:00:37 +02:00
//while (_udpServer == null)
//{
// Thread.SpinWait(500);
//}
2017-06-18 16:07:48 +02:00
2020-01-26 04:22:18 +01:00
for ( int i = 0 , arlength = DS4Controllers . Length ; i < arlength ; i + + )
{
MappedState [ i ] = new DS4State ( ) ;
CurrentState [ i ] = new DS4State ( ) ;
TempState [ i ] = new DS4State ( ) ;
PreviousState [ i ] = new DS4State ( ) ;
ExposedState [ i ] = new DS4StateExposed ( CurrentState [ i ] ) ;
}
outputslotMan = new OutputSlotManager ( ) ;
}
public void LaunchHidGuardHelper ( )
{
2020-01-26 04:02:37 +01:00
if ( Global . hidguardInstalled )
2019-01-18 22:38:13 +01:00
{
2020-01-26 04:22:18 +01:00
LogDebug ( "HidGuardian in use. Launching HidGuardHelper." ) ;
2019-01-18 22:38:13 +01:00
ProcessStartInfo startInfo =
2019-12-18 22:33:23 +01:00
new ProcessStartInfo ( Global . exedirpath + "\\HidGuardHelper.exe" ) ;
2019-01-18 22:38:13 +01:00
startInfo . Verb = "runas" ;
startInfo . Arguments = Process . GetCurrentProcess ( ) . Id . ToString ( ) ;
2019-12-18 22:33:23 +01:00
startInfo . WorkingDirectory = Global . exedirpath ;
2019-01-18 22:38:13 +01:00
try
{ Process tempProc = Process . Start ( startInfo ) ; tempProc . Dispose ( ) ; }
catch { }
}
2014-03-28 02:50:40 +01:00
}
2018-08-06 12:00:37 +02:00
private void TestQueueBus ( Action temp )
{
lock ( busEvtQueueLock )
{
busEvtQueue . Enqueue ( temp ) ;
}
lock ( busThrLck )
Monitor . Pulse ( busThrLck ) ;
}
2018-12-05 12:16:54 +01:00
public void ChangeUDPStatus ( bool state , bool openPort = true )
2018-08-06 12:00:37 +02:00
{
if ( state & & _udpServer = = null )
{
2018-12-01 07:58:50 +01:00
udpChangeStatus = true ;
2018-08-06 12:00:37 +02:00
TestQueueBus ( ( ) = >
{
_udpServer = new UdpServer ( GetPadDetailForIdx ) ;
2018-12-05 12:16:54 +01:00
if ( openPort )
2018-08-06 12:00:37 +02:00
{
2018-12-06 00:57:01 +01:00
// Change thread affinity of object to have normal priority
2018-12-05 12:16:54 +01:00
Task . Run ( ( ) = >
{
var UDP_SERVER_PORT = Global . getUDPServerPortNum ( ) ;
2019-05-27 00:07:17 +02:00
var UDP_SERVER_LISTEN_ADDRESS = Global . getUDPServerListenAddress ( ) ;
2018-08-06 12:00:37 +02:00
2018-12-05 12:16:54 +01:00
try
{
2019-05-27 00:07:17 +02:00
_udpServer . Start ( UDP_SERVER_PORT , UDP_SERVER_LISTEN_ADDRESS ) ;
LogDebug ( $"UDP server listening on address {UDP_SERVER_LISTEN_ADDRESS} port {UDP_SERVER_PORT}" ) ;
2018-12-05 12:16:54 +01:00
}
catch ( System . Net . Sockets . SocketException ex )
{
2019-05-27 00:07:17 +02:00
var errMsg = String . Format ( "Couldn't start UDP server on address {0}:{1}, outside applications won't be able to access pad data ({2})" , UDP_SERVER_LISTEN_ADDRESS , UDP_SERVER_PORT , ex . SocketErrorCode ) ;
2018-12-05 12:16:54 +01:00
LogDebug ( errMsg , true ) ;
AppLogger . LogToTray ( errMsg , true , true ) ;
}
} ) . Wait ( ) ;
2018-08-06 12:00:37 +02:00
}
udpChangeStatus = false ;
} ) ;
}
else if ( ! state & & _udpServer ! = null )
{
TestQueueBus ( ( ) = >
{
udpChangeStatus = true ;
_udpServer . Stop ( ) ;
_udpServer = null ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToGui ( "Closed UDP server" , false ) ;
2018-08-06 12:00:37 +02:00
udpChangeStatus = false ;
} ) ;
}
}
public void ChangeMotionEventStatus ( bool state )
{
IEnumerable < DS4Device > devices = DS4Devices . getDS4Controllers ( ) ;
if ( state )
{
foreach ( DS4Device dev in devices )
{
dev . queueEvent ( ( ) = >
{
dev . Report + = dev . MotionEvent ;
} ) ;
}
}
else
{
foreach ( DS4Device dev in devices )
{
dev . queueEvent ( ( ) = >
{
dev . Report - = dev . MotionEvent ;
} ) ;
}
}
}
private bool udpChangeStatus = false ;
public bool changingUDPPort = false ;
public async void UseUDPPort ( )
{
changingUDPPort = true ;
IEnumerable < DS4Device > devices = DS4Devices . getDS4Controllers ( ) ;
foreach ( DS4Device dev in devices )
{
dev . queueEvent ( ( ) = >
{
dev . Report - = dev . MotionEvent ;
} ) ;
}
await Task . Delay ( 100 ) ;
2018-08-08 10:54:19 +02:00
var UDP_SERVER_PORT = Global . getUDPServerPortNum ( ) ;
2019-05-27 00:07:17 +02:00
var UDP_SERVER_LISTEN_ADDRESS = Global . getUDPServerListenAddress ( ) ;
2018-08-08 10:54:19 +02:00
try
2018-08-06 12:00:37 +02:00
{
2019-05-27 00:07:17 +02:00
_udpServer . Start ( UDP_SERVER_PORT , UDP_SERVER_LISTEN_ADDRESS ) ;
2018-08-08 10:54:19 +02:00
foreach ( DS4Device dev in devices )
2018-08-06 12:00:37 +02:00
{
2018-08-08 10:54:19 +02:00
dev . queueEvent ( ( ) = >
{
dev . Report + = dev . MotionEvent ;
} ) ;
}
2019-05-27 00:07:17 +02:00
LogDebug ( $"UDP server listening on address {UDP_SERVER_LISTEN_ADDRESS} port {UDP_SERVER_PORT}" ) ;
2018-08-08 10:54:19 +02:00
}
catch ( System . Net . Sockets . SocketException ex )
{
2019-05-27 00:07:17 +02:00
var errMsg = String . Format ( "Couldn't start UDP server on address {0}:{1}, outside applications won't be able to access pad data ({2})" , UDP_SERVER_LISTEN_ADDRESS , UDP_SERVER_PORT , ex . SocketErrorCode ) ;
2018-08-08 10:54:19 +02:00
LogDebug ( errMsg , true ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( errMsg , true , true ) ;
2018-08-06 12:00:37 +02:00
}
changingUDPPort = false ;
}
2017-08-25 06:08:35 +02:00
private void WarnExclusiveModeFailure ( DS4Device device )
2014-03-29 06:29:08 +01:00
{
2017-04-25 11:24:14 +02:00
if ( DS4Devices . isExclusiveMode & & ! device . isExclusive ( ) )
2014-03-29 06:29:08 +01:00
{
2019-12-18 22:33:23 +01:00
string message = DS4WinWPF . Properties . Resources . CouldNotOpenDS4 . Replace ( "*Mac address*" , device . getMacAddress ( ) ) + " " +
DS4WinWPF . Properties . Resources . QuitOtherPrograms ;
Version 1.4.222
Added Press/Toggle Key to Special Actions, you can hold a trigger to
hold a key or toggle a key with one set of buttons, and untoggle it by
pressing or releasing another set of buttons
Added Disconnect BT to Special Actions, PS+Options to d/c is now added
to Special actions and can be enabled for each profile. You can now set
Disconnect BT to any control(s) and how long you need to hold the
control(s) to take affect
Added Partial German Translation (Thanks Michél)
Added 95% Finished Russian Translation (Thanks overclockers.ru members:
KoNoRIMCI & Sr_psycho)
Added Partial Italian Translation (Thanks Giulio)
Updates to the translations sheets, they should now have every bit of
text in DS4Windows, minus the controls of the controller
English Spelling fixes
Main/Starting tab only shows info for connected controllers, and context
menu only shows options for connected controllers.
Mouse wheel scrolling with analog sticks/triggers/gyro, the mouse now
scrolls smoothly
Slightly reworked analog mouse movement + mouse acceleration (not as
janky anymore)
When starting DS4Windows, if no controllers are connected, DS4Windows
defaults to the profile tab
Certain log warnings (Like unable to get controller exclusively) shows
up in red
Easter egg: try pressing a few buttons in sequence while in the log tab
Fixed Start Profile with TP off being unchecked next time a profile is
opened
Other minor Bug Fixes, such as clearing the log then moving to a new tab
crashing DS4W
2015-01-17 21:16:48 +01:00
LogDebug ( message , true ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( message , true ) ;
2014-03-29 06:29:08 +01:00
}
2017-04-21 05:09:08 +02:00
}
2018-05-06 09:13:11 +02:00
private void startViGEm ( )
{
tempThread = new Thread ( ( ) = > { try { vigemTestClient = new ViGEmClient ( ) ; } catch { } } ) ;
tempThread . Priority = ThreadPriority . AboveNormal ;
tempThread . IsBackground = true ;
tempThread . Start ( ) ;
while ( tempThread . IsAlive )
{
Thread . SpinWait ( 500 ) ;
}
2019-12-27 21:25:17 +01:00
tempThread = null ;
2018-05-06 09:13:11 +02:00
}
private void stopViGEm ( )
{
if ( vigemTestClient ! = null )
{
vigemTestClient . Dispose ( ) ;
vigemTestClient = null ;
}
}
2019-12-02 22:04:23 +01:00
public void PluginOutDev ( int index , DS4Device device )
{
OutContType contType = Global . OutContType [ index ] ;
if ( useDInputOnly [ index ] )
{
if ( contType = = OutContType . X360 )
{
2019-12-11 16:58:31 +01:00
LogDebug ( "Plugging in X360 Controller for input #" + ( index + 1 ) ) ;
2019-12-02 22:04:23 +01:00
activeOutDevType [ index ] = OutContType . X360 ;
2019-12-11 16:58:31 +01:00
//Xbox360OutDevice tempXbox = new Xbox360OutDevice(vigemTestClient);
Xbox360OutDevice tempXbox = outputslotMan . AllocateController ( OutContType . X360 , vigemTestClient )
as Xbox360OutDevice ;
//outputDevices[index] = tempXbox;
2019-12-02 22:04:23 +01:00
int devIndex = index ;
tempXbox . cont . FeedbackReceived + = ( sender , args ) = >
{
SetDevRumble ( device , args . LargeMotor , args . SmallMotor , devIndex ) ;
} ;
2019-12-11 16:58:31 +01:00
outputslotMan . DeferredPlugin ( tempXbox , index , outputDevices ) ;
2019-12-18 22:33:23 +01:00
//tempXbox.Connect();
//LogDebug("X360 Controller #" + (index + 1) + " connected");
2019-12-02 22:04:23 +01:00
}
else if ( contType = = OutContType . DS4 )
{
2019-12-11 16:58:31 +01:00
LogDebug ( "Plugging in DS4 Controller for input #" + ( index + 1 ) ) ;
2019-12-02 22:04:23 +01:00
activeOutDevType [ index ] = OutContType . DS4 ;
2019-12-11 16:58:31 +01:00
//DS4OutDevice tempDS4 = new DS4OutDevice(vigemTestClient);
DS4OutDevice tempDS4 = outputslotMan . AllocateController ( OutContType . DS4 , vigemTestClient )
as DS4OutDevice ;
//outputDevices[index] = tempDS4;
2019-12-02 22:04:23 +01:00
int devIndex = index ;
tempDS4 . cont . FeedbackReceived + = ( sender , args ) = >
{
SetDevRumble ( device , args . LargeMotor , args . SmallMotor , devIndex ) ;
} ;
2019-12-11 16:58:31 +01:00
outputslotMan . DeferredPlugin ( tempDS4 , index , outputDevices ) ;
2019-12-18 22:33:23 +01:00
//tempDS4.Connect();
//LogDebug("DS4 Controller #" + (index + 1) + " connected");
2019-12-02 22:04:23 +01:00
}
}
useDInputOnly [ index ] = false ;
}
2019-12-11 16:58:31 +01:00
public void UnplugOutDev ( int index , DS4Device device , bool immediate = false )
2019-12-02 22:04:23 +01:00
{
if ( ! useDInputOnly [ index ] )
{
//OutContType contType = Global.OutContType[index];
string tempType = outputDevices [ index ] . GetDeviceType ( ) ;
2019-12-11 16:58:31 +01:00
LogDebug ( "Unplugging " + tempType + " Controller for input #" + ( index + 1 ) , false ) ;
2019-12-02 22:04:23 +01:00
OutputDevice dev = outputDevices [ index ] ;
outputDevices [ index ] = null ;
activeOutDevType [ index ] = OutContType . None ;
2019-12-11 16:58:31 +01:00
outputslotMan . DeferredRemoval ( dev , index , outputDevices , immediate ) ;
2019-12-18 22:33:23 +01:00
//dev.Disconnect();
//LogDebug(tempType + " Controller # " + (index + 1) + " unplugged");
2019-12-02 22:04:23 +01:00
useDInputOnly [ index ] = true ;
}
}
2019-12-18 22:33:23 +01:00
public bool Start ( bool showlog = true )
2014-03-28 02:50:40 +01:00
{
2018-05-06 09:13:11 +02:00
startViGEm ( ) ;
if ( vigemTestClient ! = null )
//if (x360Bus.Open() && x360Bus.Start())
2014-03-28 02:50:40 +01:00
{
2014-05-25 01:08:40 +02:00
if ( showlog )
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . Starting ) ;
2017-04-25 11:24:14 +02:00
2019-05-12 07:33:43 +02:00
LogDebug ( $"Connection to ViGEmBus {Global.vigembusVersion} established" ) ;
2017-05-01 11:29:19 +02:00
2017-04-25 11:24:14 +02:00
DS4Devices . isExclusiveMode = getUseExclusiveMode ( ) ;
2019-12-18 22:33:23 +01:00
//uiContext = tempui as SynchronizationContext;
2014-05-25 01:08:40 +02:00
if ( showlog )
{
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . SearchingController ) ;
LogDebug ( DS4Devices . isExclusiveMode ? DS4WinWPF . Properties . Resources . UsingExclusive : DS4WinWPF . Properties . Resources . UsingShared ) ;
2014-05-25 01:08:40 +02:00
}
2017-04-25 11:24:14 +02:00
2018-08-06 12:00:37 +02:00
if ( isUsingUDPServer ( ) & & _udpServer = = null )
{
2018-12-05 12:16:54 +01:00
ChangeUDPStatus ( true , false ) ;
2018-08-06 12:00:37 +02:00
while ( udpChangeStatus = = true )
{
2018-12-01 07:58:50 +01:00
Thread . SpinWait ( 500 ) ;
2018-08-06 12:00:37 +02:00
}
}
2014-03-28 02:50:40 +01:00
try
{
DS4Devices . findControllers ( ) ;
IEnumerable < DS4Device > devices = DS4Devices . getDS4Controllers ( ) ;
2017-04-25 11:24:14 +02:00
//int ind = 0;
2017-04-22 05:01:20 +02:00
DS4LightBar . defaultLight = false ;
2017-04-25 11:24:14 +02:00
//foreach (DS4Device device in devices)
2017-05-01 11:29:19 +02:00
2019-02-16 09:50:53 +01:00
//for (int i = 0, devCount = devices.Count(); i < devCount; i++)
int i = 0 ;
for ( var devEnum = devices . GetEnumerator ( ) ; devEnum . MoveNext ( ) ; i + + )
2014-03-28 02:50:40 +01:00
{
2019-02-16 09:50:53 +01:00
DS4Device device = devEnum . Current ;
//DS4Device device = devices.ElementAt(i);
2014-05-25 01:08:40 +02:00
if ( showlog )
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . FoundController + " " + device . getMacAddress ( ) + " (" + device . getConnectionType ( ) + ") (" +
2019-09-07 15:29:25 +02:00
device . DisplayName + ")" ) ;
2017-04-25 11:24:14 +02:00
2017-08-25 06:08:35 +02:00
Task task = new Task ( ( ) = > { Thread . Sleep ( 5 ) ; WarnExclusiveModeFailure ( device ) ; } ) ;
task . Start ( ) ;
2017-04-25 11:24:14 +02:00
DS4Controllers [ i ] = device ;
2019-12-18 22:33:23 +01:00
slotManager . AddController ( device , i ) ;
2014-03-28 02:50:40 +01:00
device . Removal + = this . On_DS4Removal ;
2014-04-27 21:32:09 +02:00
device . Removal + = DS4Devices . On_Removal ;
2017-06-30 04:27:08 +02:00
device . SyncChange + = this . On_SyncChange ;
2017-05-25 11:51:28 +02:00
device . SyncChange + = DS4Devices . UpdateSerial ;
device . SerialChange + = this . On_SerialChange ;
2019-12-21 03:08:27 +01:00
device . ChargingChanged + = CheckQuickCharge ;
2019-04-23 11:32:12 +02:00
touchPad [ i ] = new Mouse ( i , device ) ;
2019-03-05 12:14:39 +01:00
if ( ! useTempProfile [ i ] )
2017-10-19 21:16:09 +02:00
{
2019-03-05 12:14:39 +01:00
if ( device . isValidSerial ( ) & & containsLinkedProfile ( device . getMacAddress ( ) ) )
{
ProfilePath [ i ] = getLinkedProfile ( device . getMacAddress ( ) ) ;
2020-01-14 03:42:58 +01:00
Global . linkedProfileCheck [ i ] = true ;
2019-03-05 12:14:39 +01:00
}
else
{
ProfilePath [ i ] = OlderProfilePath [ i ] ;
2020-01-14 03:42:58 +01:00
Global . linkedProfileCheck [ i ] = false ;
2019-03-05 12:14:39 +01:00
}
LoadProfile ( i , false , this , false , false ) ;
2017-10-19 21:16:09 +02:00
}
2019-01-31 17:59:00 +01:00
2017-04-25 11:24:14 +02:00
device . LightBarColor = getMainColor ( i ) ;
2017-06-30 04:27:08 +02:00
if ( ! getDInputOnly ( i ) & & device . isSynced ( ) )
2017-05-01 11:29:19 +02:00
{
2019-12-18 22:33:23 +01:00
//useDInputOnly[i] = false;
2019-12-02 22:04:23 +01:00
PluginOutDev ( i , device ) ;
2019-12-18 22:33:23 +01:00
2017-05-01 11:29:19 +02:00
}
2018-10-08 12:51:27 +02:00
else
{
useDInputOnly [ i ] = true ;
2019-10-25 08:48:56 +02:00
Global . activeOutDevType [ i ] = OutContType . None ;
2018-10-08 12:51:27 +02:00
}
2017-04-25 11:24:14 +02:00
2018-04-09 23:04:44 +02:00
int tempIdx = i ;
device . Report + = ( sender , e ) = >
{
this . On_Report ( sender , e , tempIdx ) ;
} ;
2018-05-06 09:13:11 +02:00
2019-02-24 22:03:12 +01:00
DS4Device . ReportHandler < EventArgs > tempEvnt = ( sender , args ) = >
2018-05-06 09:13:11 +02:00
{
2018-08-06 12:00:37 +02:00
DualShockPadMeta padDetail = new DualShockPadMeta ( ) ;
GetPadDetailForIdx ( tempIdx , ref padDetail ) ;
2019-07-02 09:06:32 +02:00
_udpServer . NewReportIncoming ( ref padDetail , CurrentState [ tempIdx ] , udpOutBuffers [ tempIdx ] ) ;
2018-08-06 12:00:37 +02:00
} ;
device . MotionEvent = tempEvnt ;
2018-05-06 09:13:11 +02:00
2018-08-06 12:00:37 +02:00
if ( _udpServer ! = null )
{
2018-05-06 09:13:11 +02:00
device . Report + = tempEvnt ;
}
2017-04-25 11:24:14 +02:00
TouchPadOn ( i , device ) ;
2017-05-17 08:02:12 +02:00
CheckProfileOptions ( i , device , true ) ;
2017-05-01 11:29:19 +02:00
device . StartUpdate ( ) ;
Version 1.4.266
Flash Lightbar when at high latency now has the option to choose what
you decide is high latency
Show Notifications now has the option to only show warnings, such as
when a controller cannot be grabbed exclusively
Speaking of bad news for Windows 10 users: Hide DS4 has now been
disabled, until i can figure out why this is, it will be disabled, this
means some games that rely on this may not work properly or at all,
sorry about that
As for good news for Windows 10, did you know you can press Windows + G
to open a game bar which can record games. For Windows 10 users, there's
a new special action: Xbox Game DVR. Pick a trigger (only one button)
and tapping/holding/or double tapping does various things, such as
start/stop recording, save an ongoing recording, take a screenshot (via
the xbox app's option or your own hotkey ie form steam), or just open
the gamebar
Much of the code has been updated with c# 6.0
Added manifest so DS4Windows can notice Windows 10 and high DPIs, also
reorganized files
2015-07-31 05:34:22 +02:00
//string filename = ProfilePath[ind];
2017-04-25 11:24:14 +02:00
//ind++;
2014-05-25 01:08:40 +02:00
if ( showlog )
2017-04-21 05:09:08 +02:00
{
2017-05-17 08:02:12 +02:00
if ( File . Exists ( appdatapath + "\\Profiles\\" + ProfilePath [ i ] + ".xml" ) )
2014-05-25 01:08:40 +02:00
{
2019-12-18 22:33:23 +01:00
string prolog = DS4WinWPF . Properties . Resources . UsingProfile . Replace ( "*number*" , ( i + 1 ) . ToString ( ) ) . Replace ( "*Profile name*" , ProfilePath [ i ] ) ;
2014-08-17 00:09:15 +02:00
LogDebug ( prolog ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( prolog ) ;
2014-05-25 01:08:40 +02:00
}
else
{
2019-12-18 22:33:23 +01:00
string prolog = DS4WinWPF . Properties . Resources . NotUsingProfile . Replace ( "*number*" , ( i + 1 ) . ToString ( ) ) ;
2015-02-08 22:51:52 +01:00
LogDebug ( prolog ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( prolog ) ;
2014-05-25 01:08:40 +02:00
}
2017-04-21 05:09:08 +02:00
}
2017-04-25 11:24:14 +02:00
if ( i > = 4 ) // out of Xinput devices!
2014-03-28 02:50:40 +01:00
break ;
}
}
catch ( Exception e )
{
LogDebug ( e . Message ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( e . Message ) ;
2014-03-28 02:50:40 +01:00
}
2014-05-05 09:31:24 +02:00
2017-04-25 11:24:14 +02:00
running = true ;
2018-12-05 12:16:54 +01:00
if ( _udpServer ! = null )
{
//var UDP_SERVER_PORT = 26760;
var UDP_SERVER_PORT = Global . getUDPServerPortNum ( ) ;
2019-05-27 00:07:17 +02:00
var UDP_SERVER_LISTEN_ADDRESS = Global . getUDPServerListenAddress ( ) ;
2018-12-05 12:16:54 +01:00
try
{
2019-05-27 00:07:17 +02:00
_udpServer . Start ( UDP_SERVER_PORT , UDP_SERVER_LISTEN_ADDRESS ) ;
LogDebug ( $"UDP server listening on address {UDP_SERVER_LISTEN_ADDRESS} port {UDP_SERVER_PORT}" ) ;
2018-12-05 12:16:54 +01:00
}
catch ( System . Net . Sockets . SocketException ex )
{
2019-05-27 00:07:17 +02:00
var errMsg = String . Format ( "Couldn't start UDP server on address {0}:{1}, outside applications won't be able to access pad data ({2})" , UDP_SERVER_LISTEN_ADDRESS , UDP_SERVER_PORT , ex . SocketErrorCode ) ;
2018-12-05 12:16:54 +01:00
LogDebug ( errMsg , true ) ;
AppLogger . LogToTray ( errMsg , true , true ) ;
}
}
2014-03-28 02:50:40 +01:00
}
2017-04-26 05:07:02 +02:00
else
{
2019-11-27 21:10:44 +01:00
string logMessage = string . Empty ;
if ( ! vigemInstalled )
{
logMessage = "ViGEmBus is not installed" ;
}
else
{
logMessage = "Could not connect to ViGEmBus. Please check the status of the System device in Device Manager and if Visual C++ 2017 Redistributable is installed." ;
}
2017-04-26 05:07:02 +02:00
LogDebug ( logMessage ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( logMessage ) ;
2017-04-26 05:07:02 +02:00
}
2017-04-25 11:24:14 +02:00
2017-04-26 05:07:02 +02:00
runHotPlug = true ;
2019-12-18 22:33:23 +01:00
ServiceStarted ? . Invoke ( this , EventArgs . Empty ) ;
RunningChanged ? . Invoke ( this , EventArgs . Empty ) ;
2014-03-28 02:50:40 +01:00
return true ;
}
2019-12-21 03:08:27 +01:00
private void CheckQuickCharge ( object sender , EventArgs e )
{
DS4Device device = sender as DS4Device ;
if ( device . ConnectionType = = ConnectionType . BT & & getQuickCharge ( ) & &
device . Charging )
{
device . DisconnectBT ( ) ;
}
}
2018-02-26 10:51:24 +01:00
public bool Stop ( bool showlog = true )
2014-03-28 02:50:40 +01:00
{
if ( running )
{
running = false ;
2017-04-26 05:07:02 +02:00
runHotPlug = false ;
2019-12-18 22:33:23 +01:00
PreServiceStop ? . Invoke ( this , EventArgs . Empty ) ;
2017-04-26 05:07:02 +02:00
2014-05-25 01:08:40 +02:00
if ( showlog )
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . StoppingX360 ) ;
2017-04-25 11:24:14 +02:00
2019-03-19 07:30:54 +01:00
LogDebug ( "Closing connection to ViGEmBus" ) ;
2017-10-02 20:38:39 +02:00
2017-03-28 17:27:15 +02:00
for ( int i = 0 , arlength = DS4Controllers . Length ; i < arlength ; i + + )
2014-03-28 02:50:40 +01:00
{
2017-05-09 12:11:50 +02:00
DS4Device tempDevice = DS4Controllers [ i ] ;
if ( tempDevice ! = null )
2014-06-21 20:00:28 +02:00
{
2018-02-26 10:51:24 +01:00
if ( ( DCBTatStop & & ! tempDevice . isCharging ( ) ) | | suspending )
2017-04-06 03:37:38 +02:00
{
2017-05-09 12:11:50 +02:00
if ( tempDevice . getConnectionType ( ) = = ConnectionType . BT )
2017-04-06 03:37:38 +02:00
{
2017-05-09 12:11:50 +02:00
tempDevice . StopUpdate ( ) ;
tempDevice . DisconnectBT ( true ) ;
2017-04-06 03:37:38 +02:00
}
2017-05-09 12:11:50 +02:00
else if ( tempDevice . getConnectionType ( ) = = ConnectionType . SONYWA )
2017-04-06 03:37:38 +02:00
{
2017-05-09 12:11:50 +02:00
tempDevice . StopUpdate ( ) ;
tempDevice . DisconnectDongle ( true ) ;
2017-04-06 03:37:38 +02:00
}
2019-03-04 02:27:57 +01:00
else
{
tempDevice . StopUpdate ( ) ;
}
2017-04-06 03:37:38 +02:00
}
2014-06-21 20:00:28 +02:00
else
{
2015-02-08 22:51:52 +01:00
DS4LightBar . forcelight [ i ] = false ;
DS4LightBar . forcedFlash [ i ] = 0 ;
2017-04-22 05:01:20 +02:00
DS4LightBar . defaultLight = true ;
2017-09-20 07:52:33 +02:00
DS4LightBar . updateLightBar ( DS4Controllers [ i ] , i ) ;
2017-05-09 12:11:50 +02:00
tempDevice . IsRemoved = true ;
2018-02-21 08:30:36 +01:00
tempDevice . StopUpdate ( ) ;
2018-02-21 19:46:08 +01:00
DS4Devices . RemoveDevice ( tempDevice ) ;
2017-07-18 22:37:01 +02:00
Thread . Sleep ( 50 ) ;
2014-06-21 20:00:28 +02:00
}
2017-05-01 11:29:19 +02:00
2014-04-27 21:32:09 +02:00
CurrentState [ i ] . Battery = PreviousState [ i ] . Battery = 0 ; // Reset for the next connection's initial status change.
2019-12-11 16:58:31 +01:00
OutputDevice tempout = outputDevices [ i ] ;
if ( tempout ! = null )
{
UnplugOutDev ( i , tempDevice , true ) ;
}
//outputDevices[i] = null;
//useDInputOnly[i] = true;
//Global.activeOutDevType[i] = OutContType.None;
2014-03-28 02:50:40 +01:00
DS4Controllers [ i ] = null ;
2014-04-27 21:32:09 +02:00
touchPad [ i ] = null ;
2017-05-01 12:40:37 +02:00
lag [ i ] = false ;
inWarnMonitor [ i ] = false ;
2014-03-28 02:50:40 +01:00
}
}
2017-04-25 11:24:14 +02:00
2014-05-25 01:08:40 +02:00
if ( showlog )
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . StoppingDS4 ) ;
2017-04-21 05:09:08 +02:00
2014-03-28 02:50:40 +01:00
DS4Devices . stopControllers ( ) ;
2019-12-18 22:33:23 +01:00
slotManager . ClearControllerList ( ) ;
2018-05-06 09:13:11 +02:00
if ( _udpServer ! = null )
2018-08-06 12:00:37 +02:00
ChangeUDPStatus ( false ) ;
//_udpServer.Stop();
2018-05-06 09:13:11 +02:00
2014-05-25 01:08:40 +02:00
if ( showlog )
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . StoppedDS4Windows ) ;
2018-05-06 09:13:11 +02:00
2019-12-11 16:58:31 +01:00
while ( outputslotMan . RunningQueue )
{
Thread . SpinWait ( 500 ) ;
}
2018-05-06 09:13:11 +02:00
stopViGEm ( ) ;
2014-03-28 02:50:40 +01:00
}
2017-04-25 11:24:14 +02:00
2017-04-26 05:07:02 +02:00
runHotPlug = false ;
2019-12-18 22:33:23 +01:00
ServiceStopped ? . Invoke ( this , EventArgs . Empty ) ;
RunningChanged ? . Invoke ( this , EventArgs . Empty ) ;
2014-03-28 02:50:40 +01:00
return true ;
}
2018-08-20 11:35:41 +02:00
public bool HotPlug ( )
2014-03-28 02:50:40 +01:00
{
2014-03-29 06:29:08 +01:00
if ( running )
2014-03-28 02:50:40 +01:00
{
DS4Devices . findControllers ( ) ;
IEnumerable < DS4Device > devices = DS4Devices . getDS4Controllers ( ) ;
2017-04-21 05:09:08 +02:00
//foreach (DS4Device device in devices)
2019-02-16 09:50:53 +01:00
//for (int i = 0, devlen = devices.Count(); i < devlen; i++)
for ( var devEnum = devices . GetEnumerator ( ) ; devEnum . MoveNext ( ) ; )
2014-03-28 02:50:40 +01:00
{
2019-02-16 09:50:53 +01:00
DS4Device device = devEnum . Current ;
//DS4Device device = devices.ElementAt(i);
2017-04-22 16:49:01 +02:00
2017-04-23 03:01:31 +02:00
if ( device . isDisconnectingStatus ( ) )
continue ;
2014-03-28 02:50:40 +01:00
if ( ( ( Func < bool > ) delegate
{
2017-03-29 16:26:07 +02:00
for ( Int32 Index = 0 , arlength = DS4Controllers . Length ; Index < arlength ; Index + + )
2017-04-23 03:01:31 +02:00
{
if ( DS4Controllers [ Index ] ! = null & &
DS4Controllers [ Index ] . getMacAddress ( ) = = device . getMacAddress ( ) )
2014-03-28 02:50:40 +01:00
return true ;
2017-04-23 03:01:31 +02:00
}
2014-03-28 02:50:40 +01:00
return false ;
} ) ( ) )
2017-04-26 10:00:05 +02:00
{
2014-03-28 02:50:40 +01:00
continue ;
2017-04-26 10:00:05 +02:00
}
2017-04-21 05:09:08 +02:00
2017-03-29 16:26:07 +02:00
for ( Int32 Index = 0 , arlength = DS4Controllers . Length ; Index < arlength ; Index + + )
2017-04-21 05:09:08 +02:00
{
2014-03-28 02:50:40 +01:00
if ( DS4Controllers [ Index ] = = null )
{
2019-12-18 22:33:23 +01:00
//LogDebug(DS4WinWPF.Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
LogDebug ( DS4WinWPF . Properties . Resources . FoundController + " " + device . getMacAddress ( ) + " (" + device . getConnectionType ( ) + ") (" +
2019-09-07 15:29:25 +02:00
device . DisplayName + ")" ) ;
2017-08-25 06:08:35 +02:00
Task task = new Task ( ( ) = > { Thread . Sleep ( 5 ) ; WarnExclusiveModeFailure ( device ) ; } ) ;
task . Start ( ) ;
2014-03-28 02:50:40 +01:00
DS4Controllers [ Index ] = device ;
2019-12-18 22:33:23 +01:00
slotManager . AddController ( device , Index ) ;
2014-03-28 02:50:40 +01:00
device . Removal + = this . On_DS4Removal ;
2014-04-27 21:32:09 +02:00
device . Removal + = DS4Devices . On_Removal ;
2017-06-30 04:27:08 +02:00
device . SyncChange + = this . On_SyncChange ;
2017-05-25 11:51:28 +02:00
device . SyncChange + = DS4Devices . UpdateSerial ;
device . SerialChange + = this . On_SerialChange ;
2019-12-21 03:08:27 +01:00
device . ChargingChanged + = CheckQuickCharge ;
2019-04-23 11:32:12 +02:00
touchPad [ Index ] = new Mouse ( Index , device ) ;
2019-03-05 12:14:39 +01:00
if ( ! useTempProfile [ Index ] )
2017-10-19 21:16:09 +02:00
{
2019-03-05 12:14:39 +01:00
if ( device . isValidSerial ( ) & & containsLinkedProfile ( device . getMacAddress ( ) ) )
{
ProfilePath [ Index ] = getLinkedProfile ( device . getMacAddress ( ) ) ;
2020-01-14 03:42:58 +01:00
Global . linkedProfileCheck [ Index ] = true ;
2019-03-05 12:14:39 +01:00
}
else
{
ProfilePath [ Index ] = OlderProfilePath [ Index ] ;
2020-01-14 03:42:58 +01:00
Global . linkedProfileCheck [ Index ] = false ;
2019-03-05 12:14:39 +01:00
}
LoadProfile ( Index , false , this , false , false ) ;
2017-10-19 21:16:09 +02:00
}
2017-04-26 10:00:05 +02:00
device . LightBarColor = getMainColor ( Index ) ;
2018-04-10 01:21:49 +02:00
2018-04-09 23:04:44 +02:00
int tempIdx = Index ;
device . Report + = ( sender , e ) = >
{
this . On_Report ( sender , e , tempIdx ) ;
} ;
2018-05-06 09:13:11 +02:00
2019-02-24 22:03:12 +01:00
DS4Device . ReportHandler < EventArgs > tempEvnt = ( sender , args ) = >
2018-05-06 09:10:49 +02:00
{
2018-08-06 12:00:37 +02:00
DualShockPadMeta padDetail = new DualShockPadMeta ( ) ;
GetPadDetailForIdx ( tempIdx , ref padDetail ) ;
2019-07-02 09:06:32 +02:00
_udpServer . NewReportIncoming ( ref padDetail , CurrentState [ tempIdx ] , udpOutBuffers [ tempIdx ] ) ;
2018-08-06 12:00:37 +02:00
} ;
device . MotionEvent = tempEvnt ;
2018-05-06 09:10:49 +02:00
2018-05-06 09:13:11 +02:00
if ( _udpServer ! = null )
2018-08-06 12:00:37 +02:00
{
2018-05-06 09:10:49 +02:00
device . Report + = tempEvnt ;
}
2018-05-06 09:13:11 +02:00
if ( ! getDInputOnly ( Index ) & & device . isSynced ( ) )
{
2019-12-18 22:33:23 +01:00
//useDInputOnly[Index] = false;
2019-12-02 22:04:23 +01:00
PluginOutDev ( Index , device ) ;
2017-05-01 11:29:19 +02:00
}
2018-10-08 12:51:27 +02:00
else
{
useDInputOnly [ Index ] = true ;
2019-10-25 08:48:56 +02:00
Global . activeOutDevType [ Index ] = OutContType . None ;
2018-10-08 12:51:27 +02:00
}
2017-05-01 11:29:19 +02:00
2014-04-27 21:32:09 +02:00
TouchPadOn ( Index , device ) ;
2017-05-14 01:47:54 +02:00
CheckProfileOptions ( Index , device ) ;
2017-05-01 11:29:19 +02:00
device . StartUpdate ( ) ;
2017-04-23 03:01:31 +02:00
Version 1.4.266
Flash Lightbar when at high latency now has the option to choose what
you decide is high latency
Show Notifications now has the option to only show warnings, such as
when a controller cannot be grabbed exclusively
Speaking of bad news for Windows 10 users: Hide DS4 has now been
disabled, until i can figure out why this is, it will be disabled, this
means some games that rely on this may not work properly or at all,
sorry about that
As for good news for Windows 10, did you know you can press Windows + G
to open a game bar which can record games. For Windows 10 users, there's
a new special action: Xbox Game DVR. Pick a trigger (only one button)
and tapping/holding/or double tapping does various things, such as
start/stop recording, save an ongoing recording, take a screenshot (via
the xbox app's option or your own hotkey ie form steam), or just open
the gamebar
Much of the code has been updated with c# 6.0
Added manifest so DS4Windows can notice Windows 10 and high DPIs, also
reorganized files
2015-07-31 05:34:22 +02:00
//string filename = Path.GetFileName(ProfilePath[Index]);
2017-05-17 08:02:12 +02:00
if ( File . Exists ( appdatapath + "\\Profiles\\" + ProfilePath [ Index ] + ".xml" ) )
2014-05-07 06:35:08 +02:00
{
2019-12-18 22:33:23 +01:00
string prolog = DS4WinWPF . Properties . Resources . UsingProfile . Replace ( "*number*" , ( Index + 1 ) . ToString ( ) ) . Replace ( "*Profile name*" , ProfilePath [ Index ] ) ;
2014-08-17 00:09:15 +02:00
LogDebug ( prolog ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( prolog ) ;
2014-05-07 06:35:08 +02:00
}
else
{
2019-12-18 22:33:23 +01:00
string prolog = DS4WinWPF . Properties . Resources . NotUsingProfile . Replace ( "*number*" , ( Index + 1 ) . ToString ( ) ) ;
2015-02-08 22:51:52 +01:00
LogDebug ( prolog ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( prolog ) ;
2014-05-07 06:35:08 +02:00
}
2017-04-21 05:09:08 +02:00
2019-12-18 22:33:23 +01:00
HotplugController ? . Invoke ( this , device , Index ) ;
2014-03-28 02:50:40 +01:00
break ;
}
2017-04-21 05:09:08 +02:00
}
2014-03-28 02:50:40 +01:00
}
}
2017-04-22 16:49:01 +02:00
2014-03-28 02:50:40 +01:00
return true ;
}
2017-05-17 08:02:12 +02:00
private void CheckProfileOptions ( int ind , DS4Device device , bool startUp = false )
{
device . setIdleTimeout ( getIdleDisconnectTimeout ( ind ) ) ;
device . setBTPollRate ( getBTPollRate ( ind ) ) ;
2018-01-07 16:52:37 +01:00
touchPad [ ind ] . ResetTrackAccel ( getTrackballFriction ( ind ) ) ;
2017-05-17 08:02:12 +02:00
if ( ! startUp )
{
CheckLauchProfileOption ( ind , device ) ;
}
}
private void CheckLauchProfileOption ( int ind , DS4Device device )
2017-05-14 01:47:54 +02:00
{
string programPath = LaunchProgram [ ind ] ;
if ( programPath ! = string . Empty )
{
2017-11-07 03:17:21 +01:00
System . Diagnostics . Process [ ] localAll = System . Diagnostics . Process . GetProcesses ( ) ;
2017-05-14 01:47:54 +02:00
bool procFound = false ;
for ( int procInd = 0 , procsLen = localAll . Length ; ! procFound & & procInd < procsLen ; procInd + + )
{
try
{
string temp = localAll [ procInd ] . MainModule . FileName ;
if ( temp = = programPath )
{
procFound = true ;
}
}
// Ignore any process for which this information
// is not exposed
catch { }
}
if ( ! procFound )
{
Task processTask = new Task ( ( ) = >
{
2017-11-10 18:22:26 +01:00
Thread . Sleep ( 5000 ) ;
2017-11-07 03:17:21 +01:00
System . Diagnostics . Process tempProcess = new System . Diagnostics . Process ( ) ;
2017-05-14 01:47:54 +02:00
tempProcess . StartInfo . FileName = programPath ;
tempProcess . StartInfo . WorkingDirectory = new FileInfo ( programPath ) . Directory . ToString ( ) ;
//tempProcess.StartInfo.UseShellExecute = false;
try { tempProcess . Start ( ) ; }
catch { }
} ) ;
processTask . Start ( ) ;
}
}
}
2014-04-27 21:32:09 +02:00
public void TouchPadOn ( int ind , DS4Device device )
{
2019-04-24 10:19:06 +02:00
Mouse tPad = touchPad [ ind ] ;
//ITouchpadBehaviour tPad = touchPad[ind];
2014-04-27 21:32:09 +02:00
device . Touchpad . TouchButtonDown + = tPad . touchButtonDown ;
device . Touchpad . TouchButtonUp + = tPad . touchButtonUp ;
device . Touchpad . TouchesBegan + = tPad . touchesBegan ;
device . Touchpad . TouchesMoved + = tPad . touchesMoved ;
device . Touchpad . TouchesEnded + = tPad . touchesEnded ;
device . Touchpad . TouchUnchanged + = tPad . touchUnchanged ;
2017-06-05 10:31:29 +02:00
//device.Touchpad.PreTouchProcess += delegate { touchPad[ind].populatePriorButtonStates(); };
device . Touchpad . PreTouchProcess + = ( sender , args ) = > { touchPad [ ind ] . populatePriorButtonStates ( ) ; } ;
2015-11-28 06:47:26 +01:00
device . SixAxis . SixAccelMoved + = tPad . sixaxisMoved ;
2014-04-27 21:32:09 +02:00
//LogDebug("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
//Log.LogToTray("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
}
2014-03-28 02:50:40 +01:00
public string getDS4ControllerInfo ( int index )
{
2017-05-10 02:23:51 +02:00
DS4Device d = DS4Controllers [ index ] ;
if ( d ! = null )
2014-03-28 02:50:40 +01:00
{
2014-03-29 06:29:08 +01:00
if ( ! d . IsAlive ( ) )
2014-05-24 01:44:30 +02:00
{
2019-12-18 22:33:23 +01:00
return DS4WinWPF . Properties . Resources . Connecting ;
2014-05-24 01:44:30 +02:00
}
2017-04-21 05:09:08 +02:00
2017-04-24 16:16:42 +02:00
string battery ;
2017-04-21 05:09:08 +02:00
if ( d . isCharging ( ) )
2014-03-29 06:29:08 +01:00
{
2017-04-21 05:09:08 +02:00
if ( d . getBattery ( ) > = 100 )
2019-12-18 22:33:23 +01:00
battery = DS4WinWPF . Properties . Resources . Charged ;
2014-03-29 06:29:08 +01:00
else
2019-12-18 22:33:23 +01:00
battery = DS4WinWPF . Properties . Resources . Charging . Replace ( "*number*" , d . getBattery ( ) . ToString ( ) ) ;
2014-03-29 06:29:08 +01:00
}
else
{
2019-12-18 22:33:23 +01:00
battery = DS4WinWPF . Properties . Resources . Battery . Replace ( "*number*" , d . getBattery ( ) . ToString ( ) ) ;
2014-03-29 06:29:08 +01:00
}
2017-04-21 05:09:08 +02:00
2017-04-29 10:19:45 +02:00
return d . getMacAddress ( ) + " (" + d . getConnectionType ( ) + "), " + battery ;
2014-04-27 21:32:09 +02:00
//return d.MacAddress + " (" + d.ConnectionType + "), Battery is " + battery + ", Touchpad in " + modeSwitcher[index].ToString();
2014-03-28 02:50:40 +01:00
}
else
2017-04-24 16:16:42 +02:00
return string . Empty ;
2014-03-28 02:50:40 +01:00
}
2014-05-30 22:39:39 +02:00
public string getDS4MacAddress ( int index )
{
2017-05-10 02:23:51 +02:00
DS4Device d = DS4Controllers [ index ] ;
if ( d ! = null )
2014-05-30 22:39:39 +02:00
{
if ( ! d . IsAlive ( ) )
{
2019-12-18 22:33:23 +01:00
return DS4WinWPF . Properties . Resources . Connecting ;
2014-05-30 22:39:39 +02:00
}
2017-05-11 17:13:51 +02:00
2017-04-21 05:09:08 +02:00
return d . getMacAddress ( ) ;
2014-05-30 22:39:39 +02:00
}
else
2017-04-24 16:16:42 +02:00
return string . Empty ;
2014-05-30 22:39:39 +02:00
}
2014-04-27 21:32:09 +02:00
public string getShortDS4ControllerInfo ( int index )
{
2017-05-10 02:23:51 +02:00
DS4Device d = DS4Controllers [ index ] ;
if ( d ! = null )
2014-04-27 21:32:09 +02:00
{
2017-05-10 02:23:51 +02:00
string battery ;
2014-04-27 21:32:09 +02:00
if ( ! d . IsAlive ( ) )
battery = "..." ;
2017-04-21 05:09:08 +02:00
if ( d . isCharging ( ) )
2014-04-27 21:32:09 +02:00
{
2017-04-21 05:09:08 +02:00
if ( d . getBattery ( ) > = 100 )
2019-12-18 22:33:23 +01:00
battery = DS4WinWPF . Properties . Resources . Full ;
2014-04-27 21:32:09 +02:00
else
2017-04-21 05:09:08 +02:00
battery = d . getBattery ( ) + "%+" ;
2014-04-27 21:32:09 +02:00
}
else
{
2017-04-21 05:09:08 +02:00
battery = d . getBattery ( ) + "%" ;
2014-04-27 21:32:09 +02:00
}
2017-04-21 05:09:08 +02:00
return ( d . getConnectionType ( ) + " " + battery ) ;
2014-05-30 22:39:39 +02:00
}
else
2019-12-18 22:33:23 +01:00
return DS4WinWPF . Properties . Resources . NoneText ;
2014-05-30 22:39:39 +02:00
}
public string getDS4Battery ( int index )
{
2017-05-10 02:23:51 +02:00
DS4Device d = DS4Controllers [ index ] ;
if ( d ! = null )
2014-05-30 22:39:39 +02:00
{
2017-04-24 11:43:56 +02:00
string battery ;
2014-05-30 22:39:39 +02:00
if ( ! d . IsAlive ( ) )
battery = "..." ;
2017-04-21 05:09:08 +02:00
if ( d . isCharging ( ) )
2014-05-30 22:39:39 +02:00
{
2017-04-21 05:09:08 +02:00
if ( d . getBattery ( ) > = 100 )
2019-12-18 22:33:23 +01:00
battery = DS4WinWPF . Properties . Resources . Full ;
2014-05-30 22:39:39 +02:00
else
2017-04-21 05:09:08 +02:00
battery = d . getBattery ( ) + "%+" ;
2014-05-30 22:39:39 +02:00
}
else
{
2017-04-21 05:09:08 +02:00
battery = d . getBattery ( ) + "%" ;
2014-05-30 22:39:39 +02:00
}
2017-04-21 05:09:08 +02:00
2014-05-30 22:39:39 +02:00
return battery ;
}
else
2019-12-18 22:33:23 +01:00
return DS4WinWPF . Properties . Resources . NA ;
2014-05-30 22:39:39 +02:00
}
public string getDS4Status ( int index )
{
2017-05-10 02:23:51 +02:00
DS4Device d = DS4Controllers [ index ] ;
if ( d ! = null )
2014-05-30 22:39:39 +02:00
{
2017-04-21 05:09:08 +02:00
return d . getConnectionType ( ) + "" ;
2014-04-27 21:32:09 +02:00
}
else
2019-12-18 22:33:23 +01:00
return DS4WinWPF . Properties . Resources . NoneText ;
2014-04-27 21:32:09 +02:00
}
2017-05-25 11:51:28 +02:00
protected void On_SerialChange ( object sender , EventArgs e )
{
DS4Device device = ( DS4Device ) sender ;
int ind = - 1 ;
for ( int i = 0 , arlength = DS4_CONTROLLER_COUNT ; ind = = - 1 & & i < arlength ; i + + )
{
DS4Device tempDev = DS4Controllers [ i ] ;
if ( tempDev ! = null & & device = = tempDev )
ind = i ;
}
if ( ind > = 0 )
{
OnDeviceSerialChange ( this , ind , device . getMacAddress ( ) ) ;
}
}
2017-06-30 04:27:08 +02:00
protected void On_SyncChange ( object sender , EventArgs e )
{
DS4Device device = ( DS4Device ) sender ;
int ind = - 1 ;
for ( int i = 0 , arlength = DS4_CONTROLLER_COUNT ; ind = = - 1 & & i < arlength ; i + + )
{
DS4Device tempDev = DS4Controllers [ i ] ;
if ( tempDev ! = null & & device = = tempDev )
ind = i ;
}
if ( ind > = 0 )
{
bool synced = device . isSynced ( ) ;
if ( ! synced )
{
if ( ! useDInputOnly [ ind ] )
{
2019-10-25 09:08:48 +02:00
Global . activeOutDevType [ ind ] = OutContType . None ;
2019-12-02 22:04:23 +01:00
UnplugOutDev ( ind , device ) ;
2017-06-30 04:27:08 +02:00
}
}
else
{
if ( ! getDInputOnly ( ind ) )
{
2019-12-02 22:04:23 +01:00
PluginOutDev ( ind , device ) ;
2017-06-30 04:27:08 +02:00
}
}
}
}
2014-03-28 02:50:40 +01:00
//Called when DS4 is disconnected or timed out
protected virtual void On_DS4Removal ( object sender , EventArgs e )
{
DS4Device device = ( DS4Device ) sender ;
int ind = - 1 ;
2017-03-29 16:26:07 +02:00
for ( int i = 0 , arlength = DS4Controllers . Length ; ind = = - 1 & & i < arlength ; i + + )
2017-04-26 10:00:05 +02:00
{
2017-04-21 05:09:08 +02:00
if ( DS4Controllers [ i ] ! = null & & device . getMacAddress ( ) = = DS4Controllers [ i ] . getMacAddress ( ) )
2014-03-28 02:50:40 +01:00
ind = i ;
2017-04-26 10:00:05 +02:00
}
2017-04-09 01:13:56 +02:00
2014-03-28 02:50:40 +01:00
if ( ind ! = - 1 )
{
2017-03-30 02:44:10 +02:00
bool removingStatus = false ;
lock ( device . removeLocker )
{
2017-04-09 01:13:56 +02:00
if ( ! device . IsRemoving )
2017-03-30 02:44:10 +02:00
{
removingStatus = true ;
2017-04-09 01:13:56 +02:00
device . IsRemoving = true ;
2017-03-30 02:44:10 +02:00
}
}
if ( removingStatus )
{
CurrentState [ ind ] . Battery = PreviousState [ ind ] . Battery = 0 ; // Reset for the next connection's initial status change.
2017-05-14 00:01:43 +02:00
if ( ! useDInputOnly [ ind ] )
{
2019-12-02 22:04:23 +01:00
UnplugOutDev ( ind , device ) ;
2017-05-14 00:01:43 +02:00
}
2018-10-02 02:18:52 +02:00
// Use Task to reset device synth state and commit it
Task . Run ( ( ) = >
{
Mapping . Commit ( ind ) ;
} ) . Wait ( ) ;
2019-12-18 22:33:23 +01:00
string removed = DS4WinWPF . Properties . Resources . ControllerWasRemoved . Replace ( "*Mac address*" , ( ind + 1 ) . ToString ( ) ) ;
2017-04-24 11:43:56 +02:00
if ( device . getBattery ( ) < = 20 & &
device . getConnectionType ( ) = = ConnectionType . BT & & ! device . isCharging ( ) )
2017-05-11 15:41:18 +02:00
{
2019-12-18 22:33:23 +01:00
removed + = ". " + DS4WinWPF . Properties . Resources . ChargeController ;
2017-05-11 15:41:18 +02:00
}
2017-04-24 11:43:56 +02:00
2017-03-30 02:44:10 +02:00
LogDebug ( removed ) ;
2018-09-29 11:42:22 +02:00
AppLogger . LogToTray ( removed ) ;
2017-06-04 00:35:13 +02:00
/ * Stopwatch sw = new Stopwatch ( ) ;
sw . Start ( ) ;
while ( sw . ElapsedMilliseconds < XINPUT_UNPLUG_SETTLE_TIME )
{
// Use SpinWait to keep control of current thread. Using Sleep could potentially
// cause other events to get run out of order
System . Threading . Thread . SpinWait ( 500 ) ;
}
sw . Stop ( ) ;
* /
2017-04-09 01:13:56 +02:00
device . IsRemoved = true ;
2017-05-25 11:51:28 +02:00
device . Synced = false ;
2017-03-30 02:44:10 +02:00
DS4Controllers [ ind ] = null ;
2019-12-18 22:33:23 +01:00
slotManager . RemoveController ( device , ind ) ;
2017-03-30 02:44:10 +02:00
touchPad [ ind ] = null ;
lag [ ind ] = false ;
inWarnMonitor [ ind ] = false ;
2017-06-08 22:52:47 +02:00
useDInputOnly [ ind ] = true ;
2019-10-25 08:48:56 +02:00
Global . activeOutDevType [ ind ] = OutContType . None ;
2019-12-18 22:33:23 +01:00
/ * uiContext ? . Post ( new SendOrPostCallback ( ( state ) = >
2018-08-25 00:35:57 +02:00
{
OnControllerRemoved ( this , ind ) ;
} ) , null ) ;
2019-12-18 22:33:23 +01:00
* /
2018-08-25 00:35:57 +02:00
//Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
2017-03-30 02:44:10 +02:00
}
2014-03-28 02:50:40 +01:00
}
}
2017-05-09 12:11:50 +02:00
2017-07-19 22:15:59 +02:00
public bool [ ] lag = new bool [ 4 ] { false , false , false , false } ;
public bool [ ] inWarnMonitor = new bool [ 4 ] { false , false , false , false } ;
private byte [ ] currentBattery = new byte [ 4 ] { 0 , 0 , 0 , 0 } ;
private bool [ ] charging = new bool [ 4 ] { false , false , false , false } ;
2017-07-27 04:38:34 +02:00
private string [ ] tempStrings = new string [ 4 ] { string . Empty , string . Empty , string . Empty , string . Empty } ;
2017-05-12 16:48:58 +02:00
2017-06-05 10:31:29 +02:00
// Called every time a new input report has arrived
2019-02-24 22:03:12 +01:00
//protected virtual void On_Report(object sender, EventArgs e, int ind)
protected virtual void On_Report ( DS4Device device , EventArgs e , int ind )
2014-03-28 02:50:40 +01:00
{
2019-02-24 22:03:12 +01:00
//DS4Device device = (DS4Device)sender;
2014-03-28 02:50:40 +01:00
2014-05-05 09:31:24 +02:00
if ( ind ! = - 1 )
2014-03-28 02:50:40 +01:00
{
2017-03-28 10:48:02 +02:00
if ( getFlushHIDQueue ( ind ) )
2014-11-18 22:23:41 +01:00
device . FlushHID ( ) ;
2017-04-21 05:09:08 +02:00
2017-07-27 04:38:34 +02:00
string devError = tempStrings [ ind ] = device . error ;
if ( ! string . IsNullOrEmpty ( devError ) )
2014-12-17 19:29:22 +01:00
{
2019-12-18 22:33:23 +01:00
LogDebug ( devError ) ;
/ * uiContext ? . Post ( new SendOrPostCallback ( delegate ( object state )
2017-07-27 04:38:34 +02:00
{
LogDebug ( devError ) ;
} ) , null ) ;
2019-12-18 22:33:23 +01:00
* /
2014-12-17 19:29:22 +01:00
}
2017-03-29 16:26:07 +02:00
if ( inWarnMonitor [ ind ] )
2015-02-08 22:51:52 +01:00
{
2017-03-28 10:48:02 +02:00
int flashWhenLateAt = getFlashWhenLateAt ( ) ;
2017-03-29 16:26:07 +02:00
if ( ! lag [ ind ] & & device . Latency > = flashWhenLateAt )
2017-06-08 22:52:47 +02:00
{
2017-06-29 15:16:02 +02:00
lag [ ind ] = true ;
2019-12-18 22:33:23 +01:00
LagFlashWarning ( ind , true ) ;
/ * uiContext ? . Post ( new SendOrPostCallback ( delegate ( object state )
2017-06-08 22:52:47 +02:00
{
LagFlashWarning ( ind , true ) ;
} ) , null ) ;
2019-12-18 22:33:23 +01:00
* /
2017-06-08 22:52:47 +02:00
}
2017-03-29 16:26:07 +02:00
else if ( lag [ ind ] & & device . Latency < flashWhenLateAt )
2017-06-08 22:52:47 +02:00
{
2017-06-29 15:16:02 +02:00
lag [ ind ] = false ;
2019-12-18 22:33:23 +01:00
LagFlashWarning ( ind , false ) ;
/ * uiContext ? . Post ( new SendOrPostCallback ( delegate ( object state )
2017-06-08 22:52:47 +02:00
{
LagFlashWarning ( ind , false ) ;
} ) , null ) ;
2019-12-18 22:33:23 +01:00
* /
2017-06-08 22:52:47 +02:00
}
2015-02-08 22:51:52 +01:00
}
2017-03-29 16:26:07 +02:00
else
{
if ( DateTime . UtcNow - device . firstActive > TimeSpan . FromSeconds ( 5 ) )
{
inWarnMonitor [ ind ] = true ;
}
}
2017-07-16 10:30:49 +02:00
device . getCurrentState ( CurrentState [ ind ] ) ;
2014-03-29 06:29:08 +01:00
DS4State cState = CurrentState [ ind ] ;
2017-07-27 04:38:34 +02:00
DS4State pState = device . getPreviousStateRef ( ) ;
//device.getPreviousState(PreviousState[ind]);
//DS4State pState = PreviousState[ind];
2017-04-24 02:48:13 +02:00
2017-10-19 10:21:33 +02:00
if ( device . firstReport & & device . IsAlive ( ) )
2017-04-29 10:19:45 +02:00
{
2017-10-19 10:21:33 +02:00
device . firstReport = false ;
2019-12-18 22:33:23 +01:00
/ * uiContext ? . Post ( new SendOrPostCallback ( delegate ( object state )
2017-06-08 22:52:47 +02:00
{
OnDeviceStatusChanged ( this , ind ) ;
} ) , null ) ;
2019-12-18 22:33:23 +01:00
* /
2017-04-29 10:19:45 +02:00
}
2019-12-18 22:33:23 +01:00
//else if (pState.Battery != cState.Battery || device.oldCharging != device.isCharging())
//{
// byte tempBattery = currentBattery[ind] = cState.Battery;
// bool tempCharging = charging[ind] = device.isCharging();
// /*uiContext?.Post(new SendOrPostCallback(delegate (object state)
// {
// OnBatteryStatusChange(this, ind, tempBattery, tempCharging);
// }), null);
// */
//}
2017-04-29 10:19:45 +02:00
2017-04-26 23:51:15 +02:00
if ( getEnableTouchToggle ( ind ) )
CheckForTouchToggle ( ind , cState , pState ) ;
2017-04-24 02:48:13 +02:00
2017-12-02 08:45:51 +01:00
cState = Mapping . SetCurveAndDeadzone ( ind , cState , TempState [ ind ] ) ;
2017-04-16 11:54:34 +02:00
2019-03-05 12:14:39 +01:00
if ( ! recordingMacro & & ( useTempProfile [ ind ] | |
2017-04-21 05:09:08 +02:00
containsCustomAction ( ind ) | | containsCustomExtras ( ind ) | |
2019-07-27 22:34:38 +02:00
getProfileActionCount ( ind ) > 0 | |
GetSASteeringWheelEmulationAxis ( ind ) > = SASteeringWheelEmulationAxisType . VJoy1X ) )
2014-03-28 02:50:40 +01:00
{
2014-12-13 21:12:03 +01:00
Mapping . MapCustom ( ind , cState , MappedState [ ind ] , ExposedState [ ind ] , touchPad [ ind ] , this ) ;
2014-10-21 20:31:36 +02:00
cState = MappedState [ ind ] ;
2014-03-28 02:50:40 +01:00
}
2017-03-28 05:27:51 +02:00
2017-05-11 15:41:18 +02:00
if ( ! useDInputOnly [ ind ] )
2014-03-28 02:50:40 +01:00
{
2019-04-18 04:29:16 +02:00
outputDevices [ ind ] ? . ConvertandSendReport ( cState , ind ) ;
//testNewReport(ref x360reports[ind], cState, ind);
//x360controls[ind]?.SendReport(x360reports[ind]);
2018-05-06 09:13:11 +02:00
//x360Bus.Parse(cState, processingData[ind].Report, ind);
2017-05-04 17:42:27 +02:00
// We push the translated Xinput state, and simultaneously we
// pull back any possible rumble data coming from Xinput consumers.
2018-05-06 09:13:11 +02:00
/ * if ( x360Bus . Report ( processingData [ ind ] . Report , processingData [ ind ] . Rumble ) )
2014-03-28 02:50:40 +01:00
{
2017-05-19 01:33:37 +02:00
byte Big = processingData [ ind ] . Rumble [ 3 ] ;
byte Small = processingData [ ind ] . Rumble [ 4 ] ;
2017-05-04 17:42:27 +02:00
if ( processingData [ ind ] . Rumble [ 1 ] = = 0x08 )
{
2019-03-03 07:35:17 +01:00
SetDevRumble ( device , Big , Small , ind ) ;
2017-05-04 17:42:27 +02:00
}
2014-03-28 02:50:40 +01:00
}
2018-05-06 09:13:11 +02:00
* /
2014-03-28 02:50:40 +01:00
}
2019-07-27 22:34:38 +02:00
else
{
// UseDInputOnly profile may re-map sixaxis gyro sensor values as a VJoy joystick axis (steering wheel emulation mode using VJoy output device). Handle this option because VJoy output works even in USeDInputOnly mode.
// If steering wheel emulation uses LS/RS/R2/L2 output axies then the profile should NOT use UseDInputOnly option at all because those require a virtual output device.
SASteeringWheelEmulationAxisType steeringWheelMappedAxis = Global . GetSASteeringWheelEmulationAxis ( ind ) ;
switch ( steeringWheelMappedAxis )
{
case SASteeringWheelEmulationAxisType . None : break ;
case SASteeringWheelEmulationAxisType . VJoy1X :
case SASteeringWheelEmulationAxisType . VJoy2X :
DS4Windows . VJoyFeeder . vJoyFeeder . FeedAxisValue ( cState . SASteeringWheelEmulationUnit , ( ( ( ( uint ) steeringWheelMappedAxis ) - ( ( uint ) SASteeringWheelEmulationAxisType . VJoy1X ) ) / 3 ) + 1 , DS4Windows . VJoyFeeder . HID_USAGES . HID_USAGE_X ) ;
break ;
case SASteeringWheelEmulationAxisType . VJoy1Y :
case SASteeringWheelEmulationAxisType . VJoy2Y :
DS4Windows . VJoyFeeder . vJoyFeeder . FeedAxisValue ( cState . SASteeringWheelEmulationUnit , ( ( ( ( uint ) steeringWheelMappedAxis ) - ( ( uint ) SASteeringWheelEmulationAxisType . VJoy1X ) ) / 3 ) + 1 , DS4Windows . VJoyFeeder . HID_USAGES . HID_USAGE_Y ) ;
break ;
case SASteeringWheelEmulationAxisType . VJoy1Z :
case SASteeringWheelEmulationAxisType . VJoy2Z :
DS4Windows . VJoyFeeder . vJoyFeeder . FeedAxisValue ( cState . SASteeringWheelEmulationUnit , ( ( ( ( uint ) steeringWheelMappedAxis ) - ( ( uint ) SASteeringWheelEmulationAxisType . VJoy1X ) ) / 3 ) + 1 , DS4Windows . VJoyFeeder . HID_USAGES . HID_USAGE_Z ) ;
break ;
}
}
2014-04-27 21:32:09 +02:00
// Output any synthetic events.
Mapping . Commit ( ind ) ;
2017-05-31 00:00:23 +02:00
// Update the GUI/whatever.
2017-09-20 07:52:33 +02:00
DS4LightBar . updateLightBar ( device , ind ) ;
2014-03-28 02:50:40 +01:00
}
}
Version 1.4.222
Added Press/Toggle Key to Special Actions, you can hold a trigger to
hold a key or toggle a key with one set of buttons, and untoggle it by
pressing or releasing another set of buttons
Added Disconnect BT to Special Actions, PS+Options to d/c is now added
to Special actions and can be enabled for each profile. You can now set
Disconnect BT to any control(s) and how long you need to hold the
control(s) to take affect
Added Partial German Translation (Thanks Michél)
Added 95% Finished Russian Translation (Thanks overclockers.ru members:
KoNoRIMCI & Sr_psycho)
Added Partial Italian Translation (Thanks Giulio)
Updates to the translations sheets, they should now have every bit of
text in DS4Windows, minus the controls of the controller
English Spelling fixes
Main/Starting tab only shows info for connected controllers, and context
menu only shows options for connected controllers.
Mouse wheel scrolling with analog sticks/triggers/gyro, the mouse now
scrolls smoothly
Slightly reworked analog mouse movement + mouse acceleration (not as
janky anymore)
When starting DS4Windows, if no controllers are connected, DS4Windows
defaults to the profile tab
Certain log warnings (Like unable to get controller exclusively) shows
up in red
Easter egg: try pressing a few buttons in sequence while in the log tab
Fixed Start Profile with TP off being unchecked next time a profile is
opened
Other minor Bug Fixes, such as clearing the log then moving to a new tab
crashing DS4W
2015-01-17 21:16:48 +01:00
2015-02-08 22:51:52 +01:00
public void LagFlashWarning ( int ind , bool on )
{
if ( on )
{
lag [ ind ] = true ;
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . LatencyOverTen . Replace ( "*number*" , ( ind + 1 ) . ToString ( ) ) , true ) ;
2017-04-26 10:00:05 +02:00
if ( getFlashWhenLate ( ) )
2015-03-15 19:16:01 +01:00
{
DS4Color color = new DS4Color { red = 50 , green = 0 , blue = 0 } ;
DS4LightBar . forcedColor [ ind ] = color ;
DS4LightBar . forcedFlash [ ind ] = 2 ;
DS4LightBar . forcelight [ ind ] = true ;
}
2015-02-08 22:51:52 +01:00
}
else
{
lag [ ind ] = false ;
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . LatencyNotOverTen . Replace ( "*number*" , ( ind + 1 ) . ToString ( ) ) ) ;
2015-02-08 22:51:52 +01:00
DS4LightBar . forcelight [ ind ] = false ;
DS4LightBar . forcedFlash [ ind ] = 0 ;
}
}
Version 1.4.222
Added Press/Toggle Key to Special Actions, you can hold a trigger to
hold a key or toggle a key with one set of buttons, and untoggle it by
pressing or releasing another set of buttons
Added Disconnect BT to Special Actions, PS+Options to d/c is now added
to Special actions and can be enabled for each profile. You can now set
Disconnect BT to any control(s) and how long you need to hold the
control(s) to take affect
Added Partial German Translation (Thanks Michél)
Added 95% Finished Russian Translation (Thanks overclockers.ru members:
KoNoRIMCI & Sr_psycho)
Added Partial Italian Translation (Thanks Giulio)
Updates to the translations sheets, they should now have every bit of
text in DS4Windows, minus the controls of the controller
English Spelling fixes
Main/Starting tab only shows info for connected controllers, and context
menu only shows options for connected controllers.
Mouse wheel scrolling with analog sticks/triggers/gyro, the mouse now
scrolls smoothly
Slightly reworked analog mouse movement + mouse acceleration (not as
janky anymore)
When starting DS4Windows, if no controllers are connected, DS4Windows
defaults to the profile tab
Certain log warnings (Like unable to get controller exclusively) shows
up in red
Easter egg: try pressing a few buttons in sequence while in the log tab
Fixed Start Profile with TP off being unchecked next time a profile is
opened
Other minor Bug Fixes, such as clearing the log then moving to a new tab
crashing DS4W
2015-01-17 21:16:48 +01:00
2017-08-23 02:52:32 +02:00
public DS4Controls GetActiveInputControl ( int ind )
2014-05-19 07:55:12 +02:00
{
DS4State cState = CurrentState [ ind ] ;
2014-06-24 00:27:14 +02:00
DS4StateExposed eState = ExposedState [ ind ] ;
2014-10-31 00:56:51 +01:00
Mouse tp = touchPad [ ind ] ;
2017-08-23 02:52:32 +02:00
DS4Controls result = DS4Controls . None ;
2017-04-15 05:11:48 +02:00
2014-05-30 22:39:39 +02:00
if ( DS4Controllers [ ind ] ! = null )
2017-04-15 05:11:48 +02:00
{
if ( Mapping . getBoolButtonMapping ( cState . Cross ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . Cross ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . Circle ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . Circle ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . Triangle ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . Triangle ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . Square ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . Square ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . L1 ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . L1 ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolTriggerMapping ( cState . L2 ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . L2 ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . L3 ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . L3 ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . R1 ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . R1 ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolTriggerMapping ( cState . R2 ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . R2 ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . R3 ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . R3 ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . DpadUp ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . DpadUp ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . DpadDown ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . DpadDown ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . DpadLeft ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . DpadLeft ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . DpadRight ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . DpadRight ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . Share ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . Share ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . Options ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . Options ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolButtonMapping ( cState . PS ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . PS ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . LX , true ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . LXPos ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . LX , false ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . LXNeg ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . LY , true ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . LYPos ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . LY , false ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . LYNeg ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . RX , true ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . RXPos ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . RX , false ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . RXNeg ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . RY , true ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . RYPos ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolAxisDirMapping ( cState . RY , false ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . RYNeg ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolTouchMapping ( tp . leftDown ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . TouchLeft ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolTouchMapping ( tp . rightDown ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . TouchRight ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolTouchMapping ( tp . multiDown ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . TouchMulti ;
2017-04-15 05:11:48 +02:00
else if ( Mapping . getBoolTouchMapping ( tp . upperDown ) )
2017-08-23 02:52:32 +02:00
result = DS4Controls . TouchUpper ;
2017-04-15 05:11:48 +02:00
}
return result ;
2014-05-19 07:55:12 +02:00
}
2017-07-18 22:37:01 +02:00
public bool [ ] touchreleased = new bool [ 4 ] { true , true , true , true } ,
touchslid = new bool [ 4 ] { false , false , false , false } ;
2017-04-26 23:51:15 +02:00
protected virtual void CheckForTouchToggle ( int deviceID , DS4State cState , DS4State pState )
2014-03-28 02:50:40 +01:00
{
2017-03-28 10:48:02 +02:00
if ( ! getUseTPforControls ( deviceID ) & & cState . Touch1 & & pState . PS )
2014-04-27 21:32:09 +02:00
{
2019-04-02 07:54:29 +02:00
if ( GetTouchActive ( deviceID ) & & touchreleased [ deviceID ] )
2014-04-27 21:32:09 +02:00
{
2019-04-02 07:54:29 +02:00
TouchActive [ deviceID ] = false ;
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . TouchpadMovementOff ) ;
AppLogger . LogToTray ( DS4WinWPF . Properties . Resources . TouchpadMovementOff ) ;
2014-06-02 19:29:38 +02:00
touchreleased [ deviceID ] = false ;
2014-04-27 21:32:09 +02:00
}
2014-06-02 19:29:38 +02:00
else if ( touchreleased [ deviceID ] )
2014-04-27 21:32:09 +02:00
{
2019-04-02 07:54:29 +02:00
TouchActive [ deviceID ] = true ;
2019-12-18 22:33:23 +01:00
LogDebug ( DS4WinWPF . Properties . Resources . TouchpadMovementOn ) ;
AppLogger . LogToTray ( DS4WinWPF . Properties . Resources . TouchpadMovementOn ) ;
2014-06-02 19:29:38 +02:00
touchreleased [ deviceID ] = false ;
2014-04-27 21:32:09 +02:00
}
2014-03-28 02:50:40 +01:00
}
2014-04-27 21:32:09 +02:00
else
2017-04-26 21:43:01 +02:00
touchreleased [ deviceID ] = true ;
2014-03-28 02:50:40 +01:00
}
2014-09-15 04:37:14 +02:00
public virtual void StartTPOff ( int deviceID )
{
2015-03-15 19:16:01 +01:00
if ( deviceID < 4 )
Version 1.4.222
Added Press/Toggle Key to Special Actions, you can hold a trigger to
hold a key or toggle a key with one set of buttons, and untoggle it by
pressing or releasing another set of buttons
Added Disconnect BT to Special Actions, PS+Options to d/c is now added
to Special actions and can be enabled for each profile. You can now set
Disconnect BT to any control(s) and how long you need to hold the
control(s) to take affect
Added Partial German Translation (Thanks Michél)
Added 95% Finished Russian Translation (Thanks overclockers.ru members:
KoNoRIMCI & Sr_psycho)
Added Partial Italian Translation (Thanks Giulio)
Updates to the translations sheets, they should now have every bit of
text in DS4Windows, minus the controls of the controller
English Spelling fixes
Main/Starting tab only shows info for connected controllers, and context
menu only shows options for connected controllers.
Mouse wheel scrolling with analog sticks/triggers/gyro, the mouse now
scrolls smoothly
Slightly reworked analog mouse movement + mouse acceleration (not as
janky anymore)
When starting DS4Windows, if no controllers are connected, DS4Windows
defaults to the profile tab
Certain log warnings (Like unable to get controller exclusively) shows
up in red
Easter egg: try pressing a few buttons in sequence while in the log tab
Fixed Start Profile with TP off being unchecked next time a profile is
opened
Other minor Bug Fixes, such as clearing the log then moving to a new tab
crashing DS4W
2015-01-17 21:16:48 +01:00
{
2019-04-02 07:54:29 +02:00
TouchActive [ deviceID ] = false ;
Version 1.4.222
Added Press/Toggle Key to Special Actions, you can hold a trigger to
hold a key or toggle a key with one set of buttons, and untoggle it by
pressing or releasing another set of buttons
Added Disconnect BT to Special Actions, PS+Options to d/c is now added
to Special actions and can be enabled for each profile. You can now set
Disconnect BT to any control(s) and how long you need to hold the
control(s) to take affect
Added Partial German Translation (Thanks Michél)
Added 95% Finished Russian Translation (Thanks overclockers.ru members:
KoNoRIMCI & Sr_psycho)
Added Partial Italian Translation (Thanks Giulio)
Updates to the translations sheets, they should now have every bit of
text in DS4Windows, minus the controls of the controller
English Spelling fixes
Main/Starting tab only shows info for connected controllers, and context
menu only shows options for connected controllers.
Mouse wheel scrolling with analog sticks/triggers/gyro, the mouse now
scrolls smoothly
Slightly reworked analog mouse movement + mouse acceleration (not as
janky anymore)
When starting DS4Windows, if no controllers are connected, DS4Windows
defaults to the profile tab
Certain log warnings (Like unable to get controller exclusively) shows
up in red
Easter egg: try pressing a few buttons in sequence while in the log tab
Fixed Start Profile with TP off being unchecked next time a profile is
opened
Other minor Bug Fixes, such as clearing the log then moving to a new tab
crashing DS4W
2015-01-17 21:16:48 +01:00
}
2014-09-15 04:37:14 +02:00
}
2015-06-01 21:04:22 +02:00
2014-05-30 22:39:39 +02:00
public virtual string TouchpadSlide ( int ind )
{
DS4State cState = CurrentState [ ind ] ;
string slidedir = "none" ;
2017-04-21 05:09:08 +02:00
if ( DS4Controllers [ ind ] ! = null & & cState . Touch2 & &
! ( touchPad [ ind ] . dragging | | touchPad [ ind ] . dragging2 ) )
{
2015-06-01 21:04:22 +02:00
if ( touchPad [ ind ] . slideright & & ! touchslid [ ind ] )
{
slidedir = "right" ;
touchslid [ ind ] = true ;
}
else if ( touchPad [ ind ] . slideleft & & ! touchslid [ ind ] )
{
slidedir = "left" ;
touchslid [ ind ] = true ;
}
else if ( ! touchPad [ ind ] . slideleft & & ! touchPad [ ind ] . slideright )
{
slidedir = "" ;
touchslid [ ind ] = false ;
}
2017-04-21 05:09:08 +02:00
}
2014-05-30 22:39:39 +02:00
return slidedir ;
}
2017-04-15 05:11:48 +02:00
Version 1.4.222
Added Press/Toggle Key to Special Actions, you can hold a trigger to
hold a key or toggle a key with one set of buttons, and untoggle it by
pressing or releasing another set of buttons
Added Disconnect BT to Special Actions, PS+Options to d/c is now added
to Special actions and can be enabled for each profile. You can now set
Disconnect BT to any control(s) and how long you need to hold the
control(s) to take affect
Added Partial German Translation (Thanks Michél)
Added 95% Finished Russian Translation (Thanks overclockers.ru members:
KoNoRIMCI & Sr_psycho)
Added Partial Italian Translation (Thanks Giulio)
Updates to the translations sheets, they should now have every bit of
text in DS4Windows, minus the controls of the controller
English Spelling fixes
Main/Starting tab only shows info for connected controllers, and context
menu only shows options for connected controllers.
Mouse wheel scrolling with analog sticks/triggers/gyro, the mouse now
scrolls smoothly
Slightly reworked analog mouse movement + mouse acceleration (not as
janky anymore)
When starting DS4Windows, if no controllers are connected, DS4Windows
defaults to the profile tab
Certain log warnings (Like unable to get controller exclusively) shows
up in red
Easter egg: try pressing a few buttons in sequence while in the log tab
Fixed Start Profile with TP off being unchecked next time a profile is
opened
Other minor Bug Fixes, such as clearing the log then moving to a new tab
crashing DS4W
2015-01-17 21:16:48 +01:00
public virtual void LogDebug ( String Data , bool warning = false )
2014-03-28 02:50:40 +01:00
{
2017-05-09 12:11:50 +02:00
//Console.WriteLine(System.DateTime.Now.ToString("G") + "> " + Data);
2014-03-28 02:50:40 +01:00
if ( Debug ! = null )
{
Version 1.4.222
Added Press/Toggle Key to Special Actions, you can hold a trigger to
hold a key or toggle a key with one set of buttons, and untoggle it by
pressing or releasing another set of buttons
Added Disconnect BT to Special Actions, PS+Options to d/c is now added
to Special actions and can be enabled for each profile. You can now set
Disconnect BT to any control(s) and how long you need to hold the
control(s) to take affect
Added Partial German Translation (Thanks Michél)
Added 95% Finished Russian Translation (Thanks overclockers.ru members:
KoNoRIMCI & Sr_psycho)
Added Partial Italian Translation (Thanks Giulio)
Updates to the translations sheets, they should now have every bit of
text in DS4Windows, minus the controls of the controller
English Spelling fixes
Main/Starting tab only shows info for connected controllers, and context
menu only shows options for connected controllers.
Mouse wheel scrolling with analog sticks/triggers/gyro, the mouse now
scrolls smoothly
Slightly reworked analog mouse movement + mouse acceleration (not as
janky anymore)
When starting DS4Windows, if no controllers are connected, DS4Windows
defaults to the profile tab
Certain log warnings (Like unable to get controller exclusively) shows
up in red
Easter egg: try pressing a few buttons in sequence while in the log tab
Fixed Start Profile with TP off being unchecked next time a profile is
opened
Other minor Bug Fixes, such as clearing the log then moving to a new tab
crashing DS4W
2015-01-17 21:16:48 +01:00
DebugEventArgs args = new DebugEventArgs ( Data , warning ) ;
2014-03-28 02:50:40 +01:00
OnDebug ( this , args ) ;
}
}
public virtual void OnDebug ( object sender , DebugEventArgs args )
{
if ( Debug ! = null )
Debug ( this , args ) ;
}
2019-03-03 07:35:17 +01:00
// sets the rumble adjusted with rumble boost. General use method
2014-03-28 02:50:40 +01:00
public virtual void setRumble ( byte heavyMotor , byte lightMotor , int deviceNum )
2019-03-03 07:35:17 +01:00
{
if ( deviceNum < 4 )
{
DS4Device device = DS4Controllers [ deviceNum ] ;
if ( device ! = null )
SetDevRumble ( device , heavyMotor , lightMotor , deviceNum ) ;
//device.setRumble((byte)lightBoosted, (byte)heavyBoosted);
}
}
// sets the rumble adjusted with rumble boost. Method more used for
// report handling. Avoid constant checking for a device.
public void SetDevRumble ( DS4Device device ,
byte heavyMotor , byte lightMotor , int deviceNum )
2014-03-28 02:50:40 +01:00
{
2017-04-26 10:00:05 +02:00
byte boost = getRumbleBoost ( deviceNum ) ;
2014-03-28 02:50:40 +01:00
uint lightBoosted = ( ( uint ) lightMotor * ( uint ) boost ) / 100 ;
if ( lightBoosted > 255 )
lightBoosted = 255 ;
uint heavyBoosted = ( ( uint ) heavyMotor * ( uint ) boost ) / 100 ;
if ( heavyBoosted > 255 )
heavyBoosted = 255 ;
2017-04-21 05:09:08 +02:00
2019-03-03 07:35:17 +01:00
device . setRumble ( ( byte ) lightBoosted , ( byte ) heavyBoosted ) ;
2014-03-28 02:50:40 +01:00
}
2014-05-28 04:49:58 +02:00
public DS4State getDS4State ( int ind )
{
return CurrentState [ ind ] ;
}
2017-04-21 05:09:08 +02:00
Rest of DS4Windows has been upped to .NET 4.5 (If you have .net 4/already can run DS4Windows, this won't affect you), thanks to this update, you can now...
Add delay to macros from one millisecond to 60 seconds, macros with delays only run once until pressed again. Without delays, the macro can be repeated while held down.
Profiles and settings are now back inside the application folder to help portability. It will remain in appdata as previous versions if DS4Windows is in a admin folder, I may try to add a setting for location saving.
Import profile option will automatically go to the appdata profile folder, auto profiles and settings will automatically copy over.
Option to delete the appdata folder if not in use in the settings tab, this way it helps with cleanup.
Another fix for auto profiles startup bug
Better reading of autoprofile program path names
Now only one instance of DS4Windows is possible, if another DS4Tool or DS4Windows that is not this version is started, this DS4Windows comes back into focus.
UI fixes
2014-06-10 21:45:09 +02:00
public DS4State getDS4StateMapped ( int ind )
{
return MappedState [ ind ] ;
2019-03-07 08:06:55 +01:00
}
public DS4State getDS4StateTemp ( int ind )
{
return TempState [ ind ] ;
}
2014-03-28 02:50:40 +01:00
}
}