Merge branch 'jay' into vigem-udpserver

This commit is contained in:
Travis Nickles 2019-01-11 16:08:19 -06:00
commit 619cbbf53a
16 changed files with 240 additions and 221 deletions

View File

@ -158,7 +158,7 @@ namespace DS4Windows
Monitor.Wait(busThrLck);
}
});
tempThread.Priority = ThreadPriority.AboveNormal;
tempThread.Priority = ThreadPriority.Normal;
tempThread.IsBackground = true;
tempThread.Start();
//while (_udpServer == null)

View File

@ -304,7 +304,8 @@ namespace DS4Windows
if (tempLightBarOnDuration != haptics.LightBarFlashDurationOn && tempLightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
device.pushHapticState(ref haptics);
device.SetHapticState(ref haptics);
//device.pushHapticState(ref haptics);
}
public static bool defaultLight = false, shuttingdown = false;

View File

@ -1,8 +1,10 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
namespace DS4Windows
{
[SuppressUnmanagedCodeSecurity]
class InputMethods
{
public static void MoveCursorBy(int x, int y)

View File

@ -779,28 +779,28 @@ namespace DS4Windows
if (absX <= 0.4)
{
outputX = 0.54 * absX;
outputX = 0.544 * absX;
}
else if (absX <= 0.75)
{
outputX = absX - 0.184;
outputX = absX - 0.1824;
}
else if (absX > 0.75)
{
outputX = (absX * 1.736) - 0.736;
outputX = (absX * 1.7296) - 0.7296;
}
if (absY <= 0.4)
{
outputY = 0.54 * absY;
outputY = 0.544 * absY;
}
else if (absY <= 0.75)
{
outputY = absY - 0.184;
outputY = absY - 0.1824;
}
else if (absY > 0.75)
{
outputY = (absY * 1.736) - 0.736;
outputY = (absY * 1.7296) - 0.7296;
}
dState.LX = (byte)(outputX * signX * 127.5 + 127.5);
@ -839,28 +839,28 @@ namespace DS4Windows
if (absX <= 0.4)
{
outputX = 0.545 * absX;
outputX = 0.544 * absX;
}
else if (absX <= 0.75)
{
outputX = absX - 0.182;
outputX = absX - 0.1824;
}
else if (absX > 0.75)
{
outputX = (absX * 1.728) - 0.728;
outputX = (absX * 1.7296) - 0.7296;
}
if (absY <= 0.4)
{
outputY = 0.545 * absY;
outputY = 0.544 * absY;
}
else if (absY <= 0.75)
{
outputY = absY - 0.182;
outputY = absY - 0.1824;
}
else if (absY > 0.75)
{
outputY = (absY * 1.728) - 0.728;
outputY = (absY * 1.7296) - 0.7296;
}
dState.RX = (byte)(outputX * signX * 127.5 + 127.5);
@ -1841,6 +1841,9 @@ namespace DS4Windows
}
}
}
string prolog = Properties.Resources.UsingProfile.Replace("*number*", (device + 1).ToString()).Replace("*Profile name*", action.details);
AppLogger.LogToGui(prolog, false);
LoadTempProfile(device, action.details, true, ctrl);
return;
}
@ -2209,6 +2212,8 @@ namespace DS4Windows
}
untriggeraction[device] = null;
string prolog = Properties.Resources.UsingProfile.Replace("*number*", (device + 1).ToString()).Replace("*Profile name*", ProfilePath[device]);
AppLogger.LogToGui(prolog, false);
LoadProfile(device, false, ctrl);
}
}
@ -2466,7 +2471,7 @@ namespace DS4Windows
if (now >= oldnow + TimeSpan.FromMilliseconds(10) && !pressagain)
{
oldnow = now;
InputMethods.MouseWheel((int)(getByteMapping(device, control, cState, eState, tp) / 51f * (down ? -1 : 1)), 0);
InputMethods.MouseWheel((int)(getByteMapping(device, control, cState, eState, tp) / 1.5f * (down ? -1 : 1)), 0);
}
}

View File

@ -6,7 +6,6 @@ using System.Reflection;
using System.Collections.Generic;
using System.Net;
using System.Drawing;
using Microsoft.Win32;
using System.Diagnostics;
using System.Xml;
using System.Text;
@ -18,6 +17,7 @@ using TaskRunner = System.Threading.Tasks.Task;
using NonFormTimer = System.Timers.Timer;
using static DS4Windows.Global;
using System.Security;
using System.Management;
namespace DS4Windows
{
@ -37,9 +37,8 @@ namespace DS4Windows
private ToolStripMenuItem[] shortcuts;
private ToolStripMenuItem[] disconnectShortcuts;
protected CheckBox[] linkedProfileCB;
WebClient wc = new WebClient();
NonFormTimer hotkeysTimer = new NonFormTimer();
NonFormTimer autoProfilesTimer = new NonFormTimer();
NonFormTimer hotkeysTimer = null;// new NonFormTimer();
NonFormTimer autoProfilesTimer = null;// new NonFormTimer();
string tempProfileProgram = string.Empty;
double dpix, dpiy;
List<string> profilenames = new List<string>();
@ -57,14 +56,14 @@ namespace DS4Windows
bool runningBat;
private bool changingService;
private IntPtr regHandle = new IntPtr();
private static DS4Form instance;
private ManagementEventWatcher managementEvWatcher;
Dictionary<Control, string> hoverTextDict = new Dictionary<Control, string>();
// 0 index is used for application version text. 1 - 4 indices are used for controller status
string[] notifyText = new string[5]
{ "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion,
string.Empty, string.Empty, string.Empty, string.Empty };
private const string UPDATER_VERSION = "1.2.8.0";
private const string UPDATER_VERSION = "1.3.0";
private const int WM_QUERYENDSESSION = 0x11;
private const int WM_CLOSE = 0x10;
internal string updaterExe = Environment.Is64BitProcess ? "DS4Updater.exe" : "DS4Updater_x86.exe";
@ -127,7 +126,13 @@ namespace DS4Windows
linkedProfileCB = new CheckBox[4] { linkCB1, linkCB2, linkCB3, linkCB4 };
SystemEvents.PowerModeChanged += OnPowerChange;
WqlEventQuery q = new WqlEventQuery();
ManagementScope scope = new ManagementScope("root\\CIMV2");
q.EventClassName = "Win32_PowerManagementEvent";
managementEvWatcher = new ManagementEventWatcher(scope, q);
managementEvWatcher.EventArrived += PowerEventArrive;
managementEvWatcher.Start();
tSOptions.Visible = false;
TaskRunner.Run(() => CheckDrivers());
@ -151,11 +156,6 @@ namespace DS4Windows
blankControllerTab();
Program.rootHub.Debug += On_Debug;
AppLogger.GuiLog += On_Debug;
AppLogger.TrayIconLog += ShowNotification;
Directory.CreateDirectory(appdatapath);
if (!Save()) //if can't write to file
{
@ -189,6 +189,7 @@ namespace DS4Windows
cBUseWhiteIcon.Checked = UseWhiteIcon;
Icon = Properties.Resources.DS4W;
notifyIcon1.Icon = UseWhiteIcon ? Properties.Resources.DS4W___White : Properties.Resources.DS4W;
populateNotifyText();
foreach (ToolStripMenuItem t in shortcuts)
t.DropDownItemClicked += Profile_Changed_Menu;
@ -248,16 +249,9 @@ namespace DS4Windows
*/
//tabProfiles.Controls.Add(opt);
//autoProfilesTimer.Elapsed += CheckAutoProfiles;
autoProfilesTimer.Interval = 1000;
autoProfilesTimer.AutoReset = false;
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string version = fvi.FileVersion;
AppLogger.LogToGui("DS4Windows version " + version, false);
LoadP();
LoadLinkedProfiles();
LogDebug(DateTime.Now, "DS4Windows version " + version, false);
Global.BatteryStatusChange += BatteryStatusUpdate;
Global.ControllerRemoved += ControllerRemovedChange;
@ -270,17 +264,9 @@ namespace DS4Windows
Enable_Controls(3, false);
btnStartStop.Text = Properties.Resources.StartText;
//hotkeysTimer.Elapsed += Hotkeys;
hotkeysTimer.AutoReset = false;
if (SwipeProfiles)
{
ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
}
startToolStripMenuItem.Text = btnStartStop.Text;
cBoxNotifications.SelectedIndex = Notifications;
cBSwipeProfiles.Checked = SwipeProfiles;
//cBSwipeProfiles.Checked = SwipeProfiles;
int checkwhen = CheckWhen;
cBUpdate.Checked = checkwhen > 0;
if (checkwhen > 23)
@ -294,15 +280,6 @@ namespace DS4Windows
nUDUpdateTime.Value = checkwhen;
}
Uri url = new Uri("http://23.239.26.40/ds4windows/files/builds/newest.txt"); // Sorry other devs, gonna have to find your own server
if (checkwhen > 0 && DateTime.Now >= LastChecked + TimeSpan.FromHours(checkwhen))
{
wc.DownloadFileAsync(url, appdatapath + "\\version.txt");
wc.DownloadFileCompleted += (sender, e) => { TaskRunner.Run(() => Check_Version(sender, e)); };
LastChecked = DateTime.Now;
}
if (File.Exists(exepath + "\\Updater.exe"))
{
Thread.Sleep(2000);
@ -351,8 +328,6 @@ namespace DS4Windows
}
}
TaskRunner.Run(() => { UpdateTheUpdater(); });
StartWindowsCheckBox.CheckedChanged += new EventHandler(StartWindowsCheckBox_CheckedChanged);
new ToolTip().SetToolTip(StartWindowsCheckBox, Properties.Resources.RunAtStartup);
@ -395,12 +370,68 @@ namespace DS4Windows
}
}
instance = this;
this.Resize += Form_Resize;
this.LocationChanged += TrackLocationChanged;
if (!(StartMinimized || mini))
Form_Resize(null, null);
Program.rootHub.Debug += On_Debug;
AppLogger.GuiLog += On_Debug;
AppLogger.TrayIconLog += ShowNotification;
LoadLinkedProfiles();
TaskRunner.Delay(50).ContinueWith((t) =>
{
if (checkwhen > 0 && DateTime.Now >= LastChecked + TimeSpan.FromHours(checkwhen))
{
this.BeginInvoke((System.Action)(() =>
{
// Sorry other devs, gonna have to find your own server
Uri url = new Uri("https://raw.githubusercontent.com/Ryochan7/DS4Windows/jay/DS4Windows/newest.txt");
WebClient wc = new WebClient();
wc.DownloadFileAsync(url, appdatapath + "\\version.txt");
wc.DownloadFileCompleted += (sender, e) => { TaskRunner.Run(() => Check_Version(sender, e)); };
LastChecked = DateTime.Now;
}));
}
UpdateTheUpdater();
});
if (btnStartStop.Enabled && start)
TaskRunner.Delay(50).ContinueWith((t) => this.BeginInvoke((System.Action)(() => BtnStartStop_Clicked())));
{
TaskRunner.Delay(50).ContinueWith((t) => {
this.BeginInvoke((System.Action)(() => BtnStartStop_Clicked()));
});
}
Thread timerThread = new Thread(() =>
{
hotkeysTimer = new NonFormTimer();
//hotkeysTimer.Elapsed += Hotkeys;
hotkeysTimer.AutoReset = false;
if (SwipeProfiles)
{
ChangeHotkeysStatus(true);
//hotkeysTimer.Start();
}
autoProfilesTimer = new NonFormTimer();
//autoProfilesTimer.Elapsed += CheckAutoProfiles;
autoProfilesTimer.Interval = 1000;
autoProfilesTimer.AutoReset = false;
LoadP();
this.BeginInvoke((System.Action)(() =>
{
cBSwipeProfiles.Checked = SwipeProfiles;
}));
});
timerThread.IsBackground = true;
timerThread.Priority = ThreadPriority.Lowest;
timerThread.Start();
}
private void populateHoverTextDict()
@ -516,38 +547,44 @@ namespace DS4Windows
return text.ToString();
}
private static void OnPowerChange(object s, PowerModeChangedEventArgs e)
private void PowerEventArrive(object sender, EventArrivedEventArgs e)
{
switch (e.Mode)
short evType = Convert.ToInt16(e.NewEvent.GetPropertyValue("EventType"));
switch (evType)
{
case PowerModes.Resume:
case 7:
{
if (instance.btnStartStop.Text == Properties.Resources.StartText && instance.wasrunning)
if (btnStartStop.Text == Properties.Resources.StartText && wasrunning)
{
DS4LightBar.shuttingdown = false;
instance.wasrunning = false;
wasrunning = false;
Program.rootHub.suspending = false;
instance.BtnStartStop_Clicked();
this.Invoke((System.Action)(() => BtnStartStop_Clicked()));
}
break;
}
case PowerModes.Suspend:
case 4:
{
if (instance.btnStartStop.Text == Properties.Resources.StopText)
if (btnStartStop.Text == Properties.Resources.StopText)
{
DS4LightBar.shuttingdown = true;
Program.rootHub.suspending = true;
instance.BtnStartStop_Clicked();
instance.wasrunning = true;
this.Invoke((System.Action)(() => BtnStartStop_Clicked()));
wasrunning = true;
}
break;
}
default: break;
default:
break;
}
}
void Hotkeys(object sender, EventArgs e)
{
hotkeysTimer.Stop();
if (SwipeProfiles)
{
for (int i = 0; i < 4; i++)
@ -599,6 +636,8 @@ namespace DS4Windows
private void CheckAutoProfiles(object sender, EventArgs e)
{
autoProfilesTimer.Stop();
//Check for process for auto profiles
if (string.IsNullOrEmpty(tempProfileProgram))
{
@ -747,23 +786,23 @@ namespace DS4Windows
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string version = fvi.FileVersion;
string newversion = File.ReadAllText(appdatapath + "\\version.txt").Trim();
if (version.Replace(',', '.').CompareTo(newversion) == -1)
if (version.Replace(',', '.').CompareTo(newversion) != 0)
{
if ((DialogResult)this.Invoke(new Func<DialogResult>(() => {
return MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion),
Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question); })) == DialogResult.Yes)
{
if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe")
&& (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo("1.1.0.0") == -1)))
&& (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo(UPDATER_VERSION) != 0)))
{
Uri url2 = new Uri($"http://23.239.26.40/ds4windows/files/{updaterExe}");
Uri url2 = new Uri($"https://github.com/Ryochan7/DS4Updater/releases/download/v{UPDATER_VERSION}/{updaterExe}");
WebClient wc2 = new WebClient();
if (appdatapath == exepath)
wc2.DownloadFile(url2, exepath + "\\DS4Updater.exe");
else
{
this.BeginInvoke((System.Action)(() => MessageBox.Show(Properties.Resources.PleaseDownloadUpdater)));
Process.Start($"http://23.239.26.40/ds4windows/files/{updaterExe}");
Process.Start($"https://github.com/Ryochan7/DS4Updater/releases/download/v{UPDATER_VERSION}/{updaterExe}");
}
}
@ -1150,7 +1189,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
string temp = Program.rootHub.getShortDS4ControllerInfo(i);
if (temp != Properties.Resources.NoneText)
{
notifyText[i + 1] = (i + 1) + ": " + temp; // Carefully stay under the 63 character limit.
notifyText[i + 1] = (i + 1) + ": " + temp;
}
else
{
@ -1166,7 +1205,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
string temp = Program.rootHub.getShortDS4ControllerInfo(index);
if (temp != Properties.Resources.NoneText)
{
notifyText[index + 1] = (index + 1) + ": " + temp; // Carefully stay under the 63 character limit.
notifyText[index + 1] = (index + 1) + ": " + temp;
}
else
{
@ -1182,14 +1221,11 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
string temp = notifyText[i];
if (!string.IsNullOrEmpty(temp))
{
tooltip += "\n" + notifyText[i]; // Carefully stay under the 63 character limit.
tooltip += "\n" + notifyText[i];
}
}
if (tooltip.Length > 63)
notifyIcon1.Text = tooltip.Substring(0, 63);
else
notifyIcon1.Text = tooltip;
notifyIcon1.Text = tooltip.Length > 63 ? tooltip.Substring(0, 63) : tooltip; // Carefully stay under the 63 character limit.
}
protected void DeviceSerialChanged(object sender, SerialChangeArgs args)
@ -1780,7 +1816,6 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
private void StartWindowsCheckBox_CheckedChanged(object sender, EventArgs e)
{
bool isChecked = StartWindowsCheckBox.Checked;
RegistryKey KeyLoc = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (isChecked && !File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"))
{
appShortcutToStartup();
@ -1790,8 +1825,6 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
}
KeyLoc.DeleteValue("DS4Tool", false);
if (isChecked)
{
runStartupPanel.Visible = true;
@ -2047,7 +2080,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
private void lLBUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Sorry other devs, gonna have to find your own server
Uri url = new Uri("http://23.239.26.40/ds4windows/files/builds/newest.txt");
Uri url = new Uri("https://raw.githubusercontent.com/Ryochan7/DS4Windows/jay/DS4Windows/newest.txt");
WebClient wct = new WebClient();
wct.DownloadFileAsync(url, appdatapath + "\\version.txt");
wct.DownloadFileCompleted += (sender2, e2) => TaskRunner.Run(() => wct_DownloadFileCompleted(sender2, e2));
@ -2064,7 +2097,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string version2 = fvi.FileVersion;
string newversion2 = File.ReadAllText(appdatapath + "\\version.txt").Trim();
if (version2.Replace(',', '.').CompareTo(newversion2) == -1)
if (version2.Replace(',', '.').CompareTo(newversion2) != 0)
{
if ((DialogResult)this.Invoke(new Func<DialogResult>(() =>
{
@ -2073,16 +2106,16 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
})) == DialogResult.Yes)
{
if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe")
&& (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo(UPDATER_VERSION) == -1)))
&& (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo(UPDATER_VERSION) != 0)))
{
Uri url2 = new Uri($"http://23.239.26.40/ds4windows/files/{updaterExe}");
Uri url2 = new Uri($"https://github.com/Ryochan7/DS4Updater/releases/download/v{UPDATER_VERSION}/{updaterExe}");
WebClient wc2 = new WebClient();
if (appdatapath == exepath)
wc2.DownloadFile(url2, exepath + "\\DS4Updater.exe");
else
{
this.BeginInvoke((System.Action)(() => MessageBox.Show(Properties.Resources.PleaseDownloadUpdater)));
Process.Start($"http://23.239.26.40/ds4windows/files/{updaterExe}");
Process.Start($"https://github.com/Ryochan7/DS4Updater/releases/download/v{UPDATER_VERSION}/{updaterExe}");
}
}

View File

@ -418,7 +418,7 @@
<value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="notifyIcon1.Text" xml:space="preserve">
<value>DS4 Xinput Tool</value>
<value>DS4Windows</value>
</data>
<data name="notifyIcon1.Visible" type="System.Boolean, mscorlib">
<value>True</value>

View File

@ -43,7 +43,7 @@ namespace DS4Windows
WebClient wb = new WebClient();
if (!driverinstalling)
{
wb.DownloadFileAsync(new Uri("http://23.239.26.40/ds4windows/files/Virtual Bus Driver.zip"), exepath + "\\VBus.zip");
wb.DownloadFileAsync(new Uri("https://github.com/Ryochan7/DS4Windows/raw/jay/extras/Virtual Bus Driver.zip"), exepath + "\\VBus.zip");
wb.DownloadProgressChanged += wb_DownloadProgressChanged;
wb.DownloadFileCompleted += wb_DownloadFileCompleted;
driverinstalling = true;

View File

@ -140,10 +140,6 @@ namespace DS4Windows
private byte[] outReportBuffer, outputReport;
private readonly DS4Touchpad touchpad = null;
private readonly DS4SixAxis sixAxis = null;
private byte rightLightFastRumble;
private byte leftHeavySlowRumble;
private DS4Color ligtBarColor;
private byte ledFlashOn, ledFlashOff;
private Thread ds4Input, ds4Output;
private int battery;
private DS4Audio audio = null;
@ -274,73 +270,44 @@ namespace DS4Windows
public byte RightLightFastRumble
{
get { return rightLightFastRumble; }
get { return currentHap.RumbleMotorStrengthRightLightFast; }
set
{
if (rightLightFastRumble != value)
rightLightFastRumble = value;
if (currentHap.RumbleMotorStrengthRightLightFast != value)
currentHap.RumbleMotorStrengthRightLightFast = value;
}
}
public byte LeftHeavySlowRumble
{
get { return leftHeavySlowRumble; }
get { return currentHap.RumbleMotorStrengthLeftHeavySlow; }
set
{
if (leftHeavySlowRumble != value)
leftHeavySlowRumble = value;
if (currentHap.RumbleMotorStrengthLeftHeavySlow != value)
currentHap.RumbleMotorStrengthLeftHeavySlow = value;
}
}
public byte getLeftHeavySlowRumble()
{
return leftHeavySlowRumble;
return currentHap.RumbleMotorStrengthLeftHeavySlow;
}
public DS4Color LightBarColor
{
get { return ligtBarColor; }
get { return currentHap.LightBarColor; }
set
{
if (ligtBarColor.red != value.red || ligtBarColor.green != value.green || ligtBarColor.blue != value.blue)
if (currentHap.LightBarColor.red != value.red || currentHap.LightBarColor.green != value.green || currentHap.LightBarColor.blue != value.blue)
{
ligtBarColor = value;
}
}
}
public byte LightBarOnDuration
{
get { return ledFlashOn; }
set
{
if (ledFlashOn != value)
{
ledFlashOn = value;
currentHap.LightBarColor = value;
}
}
}
public byte getLightBarOnDuration()
{
return ledFlashOn;
}
public byte LightBarOffDuration
{
get { return ledFlashOff; }
set
{
if (ledFlashOff != value)
{
ledFlashOff = value;
}
}
}
public byte getLightBarOffDuration()
{
return ledFlashOff;
return currentHap.LightBarFlashDurationOn;
}
// Specify the poll rate interval used for the DS4 hardware when
@ -529,7 +496,7 @@ namespace DS4Windows
if (conType == ConnectionType.BT)
{
ds4Output = new Thread(performDs4Output);
ds4Output.Priority = ThreadPriority.AboveNormal;
ds4Output.Priority = ThreadPriority.Normal;
ds4Output.Name = "DS4 Output thread: " + Mac;
ds4Output.IsBackground = true;
ds4Output.Start();
@ -543,7 +510,7 @@ namespace DS4Windows
else
{
ds4Output = new Thread(OutReportCopy);
ds4Output.Priority = ThreadPriority.AboveNormal;
ds4Output.Priority = ThreadPriority.Normal;
ds4Output.Name = "DS4 Arr Copy thread: " + Mac;
ds4Output.IsBackground = true;
ds4Output.Start();
@ -615,6 +582,7 @@ namespace DS4Windows
}
private byte outputPendCount = 0;
private readonly Stopwatch standbySw = new Stopwatch();
private unsafe void performDs4Output()
{
try
@ -657,7 +625,15 @@ namespace DS4Windows
byteR[i] = byteB[i];
}
//outReportBuffer.CopyTo(outputReport, 0);
if (outputPendCount > 1)
outputPendCount--;
else if (outputPendCount == 1)
{
outputPendCount--;
standbySw.Restart();
}
else
standbySw.Restart();
}
currentRumble = true;
@ -742,6 +718,7 @@ namespace DS4Windows
int crcpos = BT_INPUT_REPORT_CRC32_POS;
int crcoffset = 0;
long latencySum = 0;
standbySw.Start();
while (!exitInputThread)
{
@ -861,7 +838,7 @@ namespace DS4Windows
}
utcNow = DateTime.UtcNow; // timestamp with UTC in case system time zone changes
resetHapticState();
cState.PacketCounter = pState.PacketCounter + 1;
cState.ReportTimeStamp = utcNow;
cState.LX = inputReport[1];
@ -1130,8 +1107,9 @@ namespace DS4Windows
private unsafe void sendOutputReport(bool synchronous, bool force = false)
{
setTestRumble();
setHapticState();
MergeStates();
//setTestRumble();
//setHapticState();
bool quitOutputThread = false;
bool usingBT = conType == ConnectionType.BT;
@ -1146,13 +1124,13 @@ namespace DS4Windows
outReportBuffer[1] = (byte)(0x80 | btPollRate); // input report rate
// enable rumble (0x01), lightbar (0x02), flash (0x04)
outReportBuffer[3] = 0xf7;
outReportBuffer[6] = rightLightFastRumble; // fast motor
outReportBuffer[7] = leftHeavySlowRumble; // slow motor
outReportBuffer[8] = ligtBarColor.red; // red
outReportBuffer[9] = ligtBarColor.green; // green
outReportBuffer[10] = ligtBarColor.blue; // blue
outReportBuffer[11] = ledFlashOn; // flash on duration
outReportBuffer[12] = ledFlashOff; // flash off duration
outReportBuffer[6] = currentHap.RumbleMotorStrengthRightLightFast; // fast motor
outReportBuffer[7] = currentHap.RumbleMotorStrengthLeftHeavySlow; // slow motor
outReportBuffer[8] = currentHap.LightBarColor.red; // red
outReportBuffer[9] = currentHap.LightBarColor.green; // green
outReportBuffer[10] = currentHap.LightBarColor.blue; // blue
outReportBuffer[11] = currentHap.LightBarFlashDurationOn; // flash on duration
outReportBuffer[12] = currentHap.LightBarFlashDurationOff; // flash off duration
fixed (byte* byteR = outputReport, byteB = outReportBuffer)
{
@ -1165,13 +1143,13 @@ namespace DS4Windows
outReportBuffer[0] = 0x05;
// enable rumble (0x01), lightbar (0x02), flash (0x04)
outReportBuffer[1] = 0xf7;
outReportBuffer[4] = rightLightFastRumble; // fast motor
outReportBuffer[5] = leftHeavySlowRumble; // slow motor
outReportBuffer[6] = ligtBarColor.red; // red
outReportBuffer[7] = ligtBarColor.green; // green
outReportBuffer[8] = ligtBarColor.blue; // blue
outReportBuffer[9] = ledFlashOn; // flash on duration
outReportBuffer[10] = ledFlashOff; // flash off duration
outReportBuffer[4] = currentHap.RumbleMotorStrengthRightLightFast; // fast motor
outReportBuffer[5] = currentHap.RumbleMotorStrengthLeftHeavySlow; // slow motor
outReportBuffer[6] = currentHap.LightBarColor.red; // red
outReportBuffer[7] = currentHap.LightBarColor.green; // green
outReportBuffer[8] = currentHap.LightBarColor.blue; // blue
outReportBuffer[9] = currentHap.LightBarFlashDurationOn; // flash on duration
outReportBuffer[10] = currentHap.LightBarFlashDurationOff; // flash off duration
fixed (byte* byteR = outputReport, byteB = outReportBuffer)
{
@ -1191,10 +1169,24 @@ namespace DS4Windows
if (synchronous)
{
outputPendCount = 3;
output = output || standbySw.ElapsedMilliseconds >= 4000L;
if (output || change)
{
if (change)
{
outputPendCount = 3;
standbySw.Reset();
}
else if (outputPendCount > 1)
outputPendCount--;
else if (outputPendCount == 1)
{
outputPendCount--;
standbySw.Restart();
}
else
standbySw.Restart();
if (usingBT)
{
Monitor.Enter(outputReport);
@ -1226,11 +1218,13 @@ namespace DS4Windows
//for (int i = 0, arlen = outputReport.Length; !change && i < arlen; i++)
// change = outputReport[i] != outReportBuffer[i];
output = output || standbySw.ElapsedMilliseconds >= 4000L;
if (output || change)
{
if (change)
{
outputPendCount = 3;
standbySw.Reset();
}
Monitor.Pulse(outReportBuffer);
@ -1366,13 +1360,15 @@ namespace DS4Windows
testRumble.RumbleMotorsExplicitlyOff = rightLightFastMotor == 0 && leftHeavySlowMotor == 0;
}
private void setTestRumble()
private void MergeStates()
{
if (testRumble.IsRumbleSet())
{
pushHapticState(ref testRumble);
if (testRumble.RumbleMotorsExplicitlyOff)
testRumble.RumbleMotorsExplicitlyOff = false;
currentHap.RumbleMotorStrengthLeftHeavySlow = testRumble.RumbleMotorStrengthLeftHeavySlow;
currentHap.RumbleMotorStrengthRightLightFast = testRumble.RumbleMotorStrengthRightLightFast;
}
}
@ -1427,60 +1423,10 @@ namespace DS4Windows
return true;
}
private DS4HapticState[] hapticState = new DS4HapticState[1];
private int hapticStackIndex = 0;
private void resetHapticState()
private DS4HapticState currentHap = new DS4HapticState();
public void SetHapticState(ref DS4HapticState hs)
{
hapticStackIndex = 0;
}
delegate void HapticItem(ref DS4HapticState haptic);
// Use the "most recently set" haptic state for each of light bar/motor.
private void setHapticState()
{
byte lightBarFlashDurationOn = ledFlashOn, lightBarFlashDurationOff = ledFlashOff;
byte rumbleMotorStrengthLeftHeavySlow = leftHeavySlowRumble,
rumbleMotorStrengthRightLightFast = rightLightFastRumble;
int hapticLen = hapticState.Length;
for (int i=0; i < hapticLen; i++)
{
if (i == hapticStackIndex)
break; // rest haven't been used this time
((HapticItem)((ref DS4HapticState haptic) => {
if (haptic.IsLightBarSet())
{
ligtBarColor = haptic.LightBarColor;
lightBarFlashDurationOn = haptic.LightBarFlashDurationOn;
lightBarFlashDurationOff = haptic.LightBarFlashDurationOff;
}
if (haptic.IsRumbleSet())
{
rumbleMotorStrengthLeftHeavySlow = haptic.RumbleMotorStrengthLeftHeavySlow;
rumbleMotorStrengthRightLightFast = haptic.RumbleMotorStrengthRightLightFast;
}
}))(ref hapticState[i]);
}
ledFlashOn = lightBarFlashDurationOn;
ledFlashOff = lightBarFlashDurationOff;
leftHeavySlowRumble = rumbleMotorStrengthLeftHeavySlow;
rightLightFastRumble = rumbleMotorStrengthRightLightFast;
}
public void pushHapticState(ref DS4HapticState hs)
{
int hapsLen = hapticState.Length;
if (hapticStackIndex == hapsLen)
{
DS4HapticState[] newHaptics = new DS4HapticState[hapsLen + 1];
Array.Copy(hapticState, newHaptics, hapsLen);
hapticState = newHaptics;
}
hapticState[hapticStackIndex++] = hs;
currentHap = hs;
}
override

View File

@ -42,7 +42,8 @@ namespace DS4Windows
new VidPidInfo(NACON_VID, 0x0D01),
new VidPidInfo(NACON_VID, 0x0D02),
new VidPidInfo(HORI_VID, 0x00EE), // Hori PS4 Mini Wired Gamepad
new VidPidInfo(0x7545, 0x0104)
new VidPidInfo(0x7545, 0x0104),
new VidPidInfo(0x2E95, 0x7725), // Scuf Vantage gamepad
};
private static string devicePathToInstanceId(string devicePath)

View File

@ -82,7 +82,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DefineConstants>WIN64</DefineConstants>
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
<LangVersion>6</LangVersion>
<LangVersion>7.2</LangVersion>
<DebugSymbols>false</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WarningLevel>1</WarningLevel>
@ -107,7 +107,7 @@
<ErrorReport>none</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>6</LangVersion>
<LangVersion>7.2</LangVersion>
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WarningLevel>1</WarningLevel>
@ -126,6 +126,7 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
@ -1175,7 +1176,19 @@
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="PostBuildMacros">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="Targets" />
</GetAssemblyIdentity>
<ItemGroup>
<VersionNumber Include="$([System.Text.RegularExpressions.Regex]::Replace(&quot;%(Targets.Version)&quot;, &quot;^(.+?)(\.0+)$&quot;, &quot;$1&quot;))" />
</ItemGroup>
</Target>
<PropertyGroup>
<PostBuildEventDependsOn>
$(PostBuildEventDependsOn);
PostBuildMacros;
</PostBuildEventDependsOn>
<PostBuildEvent>rem Copy compiled l18n assemblies to alt folder
GOTO END
if not exist $(TargetDir)Lang mkdir $(TargetDir)Lang
@ -1187,7 +1200,10 @@ for %25%25l in (%25langs%25) do (
xcopy $(TargetDir)%25%25l $(TargetDir)Lang\%25%25l\ /s /y
)
:END</PostBuildEvent>
echo @(VersionNumber)&gt; $(ProjectDir)\newest.txt
:END
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -11,7 +11,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DS4Windows")]
[assembly: AssemblyCopyright("Copyright © Scarlet.Crush Productions 2012, 2013; InhexSTER, HecticSeptic, electrobrains 2013, 2014; Jays2Kings 2013, 2014, 2015, 2016; Ryochan7 2017, 2018")]
[assembly: AssemblyCopyright("Copyright © Scarlet.Crush Productions 2012, 2013; InhexSTER, HecticSeptic, electrobrains 2013, 2014; Jays2Kings 2013, 2014, 2015, 2016; Ryochan7 2017, 2018, 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -33,7 +33,7 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.18")]
[assembly: AssemblyFileVersion("1.5.18")]
[assembly: AssemblyVersion("1.6.5")]
[assembly: AssemblyFileVersion("1.6.5")]
[assembly: NeutralResourcesLanguage("en")]

View File

@ -1419,7 +1419,7 @@ namespace DS4Windows.Properties {
}
/// <summary>
/// Looks up a localized string similar to Please Download the Updater now, and place it in the programs folder, then check for update again.
/// Looks up a localized string similar to Please Download the Updater now, place it in the programs folder and rename to DS4Updater.exe if on x86, then check for update again.
/// </summary>
public static string PleaseDownloadUpdater {
get {

View File

@ -545,7 +545,7 @@
<value>..\Resources\Pairmode.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="PleaseDownloadUpdater" xml:space="preserve">
<value>Please Download the Updater now, and place it in the programs folder, then check for update again</value>
<value>Please Download the Updater now, place it in the programs folder and rename to DS4Updater.exe if on x86, then check for update again</value>
</data>
<data name="PleaseImport" xml:space="preserve">
<value>Please import or make a profile</value>

1
DS4Windows/newest.txt Normal file
View File

@ -0,0 +1 @@
1.6.5

View File

@ -27,6 +27,7 @@ you've used a 360 controller before)
- Bluetooth 2.1+ (via an
[adapter like this](https://www.newegg.com/Product/Product.aspx?Item=N82E16833166126)
or built in pc). Toshiba's adapters currently do not work.
- Disable Steam Controller Mapping support in Steam
## Device Detection Issue
@ -50,6 +51,19 @@ DualShock 4 device. Right click the device item and select "Enable device"
from the menu. That will re-enable the device and be seen by applications
again.
## Disable Steam Controller Mapping Support
With recent updates to the Steam client at the time writing this (2018-12-13),
Steam has enabled Xbox Configuration Support in the Steam client by default.
What this means is that Steam will automatically map a detected Xbox 360
controller to KB+M bindings initially (Desktop Mode) before launching Steam
Big Picture Mode or launching a game. This presents a problem for DS4Windows
since the created virtual Xbox 360 controller will be mapped to KB+M actions
for desktop mode and games launched outside of the Steam client. In order to
use DS4Windows properly, you have to open Steam Big Picture Mode, navigate to
Settings > Controller> Controller Settings and uncheck **Xbox Configuration
Support** along with **PlayStation Configuration Support**.
## Pull Requests
Pull requests for DS4Windows are welcome. Before making a pull request, please

Binary file not shown.