Skip to content
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.

Commit

Permalink
Version 1.4.157
Browse files Browse the repository at this point in the history
Experimental: Quick Charge controller by turning off BT when plugged via
USB
Settings a deadzone of .10+ to the sticks or higher now affects the
mouse movement as well
Use DS4 for Mapping checkbox now remembers how it was last set
Fix for starting minimized showing up in task manager and alt+tab, this
also more reliably starts minimized
  • Loading branch information
Jays2Kings committed Nov 20, 2014
1 parent 631172c commit d088687
Show file tree
Hide file tree
Showing 14 changed files with 5,020 additions and 4,879 deletions.
15 changes: 8 additions & 7 deletions DS4Control/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,14 +1347,15 @@ private static int getMouseMapping(int device, DS4Controls control, DS4State cSt
int controlnum = DS4ControltoInt(control);
double SXD = Global.getSXDeadzone(device);
double SZD = Global.getSZDeadzone(device);
int deadzone = 10;
int deadzoneL = Math.Max((byte)10, Global.getLSDeadzone(device));
int deadzoneR = Math.Max((byte)10, Global.getRSDeadzone(device));
double value = 0;
int speed = Global.getButtonMouseSensitivity(device)+15;
double root = 1.002;
double divide = 10000d;
DateTime now = mousenow[mnum];
bool leftsitcklive = ((cState.LX < 127 - deadzone || 127 + deadzone < cState.LX) || (cState.LY < 127 - deadzone || 127 + deadzone < cState.LY));
bool rightsitcklive = ((cState.RX < 127 - deadzone || 127 + deadzone < cState.RX) || (cState.RY < 127 - deadzone || 127 + deadzone < cState.RY));
bool leftsitcklive = ((cState.LX < 127 - deadzoneL || 127 + deadzoneL < cState.LX) || (cState.LY < 127 - deadzoneL || 127 + deadzoneL < cState.LY));
bool rightsitcklive = ((cState.RX < 127 - deadzoneR || 127 + deadzoneR < cState.RX) || (cState.RY < 127 - deadzoneR || 127 + deadzoneR < cState.RY));
switch (control)
{
case DS4Controls.LXNeg:
Expand Down Expand Up @@ -1419,10 +1420,10 @@ private static int getMouseMapping(int device, DS4Controls control, DS4State cSt
case DS4Controls.GyroZNeg: return (byte)(eState.GyroZ < -SZD * 7500 ?
Math.Pow(root + speed / divide, -eState.GyroZ / 62) : 0);
}
bool LXChanged = (Math.Abs(127 - cState.LX) < deadzone);
bool LYChanged = (Math.Abs(127 - cState.LY) < deadzone);
bool RXChanged = (Math.Abs(127 - cState.RX) < deadzone);
bool RYChanged = (Math.Abs(127 - cState.RY) < deadzone);
bool LXChanged = (Math.Abs(127 - cState.LX) < deadzoneL);
bool LYChanged = (Math.Abs(127 - cState.LY) < deadzoneL);
bool RXChanged = (Math.Abs(127 - cState.RX) < deadzoneR);
bool RYChanged = (Math.Abs(127 - cState.RY) < deadzoneR);
if (LXChanged || LYChanged || RXChanged || RYChanged)
now = DateTime.UtcNow;
if (Global.getMouseAccel(device))
Expand Down
2 changes: 1 addition & 1 deletion DS4Control/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,22 @@ public static bool getSwipeProfiles()
{
return m_Config.swipeProfiles;
}
// New settings
public static void setDS4Mapping(bool data)
{
m_Config.ds4Mapping = data;
}
public static bool getDS4Mapping()
{
return m_Config.ds4Mapping;
}
public static void setQuickCharge(bool data)
{
m_Config.quickCharge = data;
}
public static bool getQuickCharge()
{
return m_Config.quickCharge;
}
public static void saveLowColor(int device, byte red, byte green, byte blue)
{
m_Config.m_LowLeds[device][0] = red;
Expand Down Expand Up @@ -792,6 +807,8 @@ public class BackingStore
public bool notifications = true;
public bool disconnectBTAtStop = false;
public bool swipeProfiles = true;
public bool ds4Mapping = true;
public bool quickCharge = false;
public Dictionary<DS4Controls, DS4KeyType>[] customMapKeyTypes = { null, null, null, null, null };
public Dictionary<DS4Controls, UInt16>[] customMapKeys = { null, null, null, null, null };
public Dictionary<DS4Controls, String>[] customMapMacros = { null, null, null, null, null };
Expand Down Expand Up @@ -1662,7 +1679,6 @@ public bool Load()

m_Xdoc.Load(m_Profile);


try { Item = m_Xdoc.SelectSingleNode("/Profile/useExclusiveMode"); Boolean.TryParse(Item.InnerText, out useExclusiveMode); }
catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/startMinimized"); Boolean.TryParse(Item.InnerText, out startMinimized); }
Expand All @@ -1689,6 +1705,10 @@ public bool Load()
catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/SwipeProfiles"); Boolean.TryParse(Item.InnerText, out swipeProfiles); }
catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/UseDS4ForMapping"); Boolean.TryParse(Item.InnerText, out ds4Mapping); }
catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/QuickCharge"); Boolean.TryParse(Item.InnerText, out quickCharge); }
catch { missingSetting = true; }
}
}
catch { }
Expand Down Expand Up @@ -1731,6 +1751,8 @@ public bool Save()
XmlNode xmlNotifications = m_Xdoc.CreateNode(XmlNodeType.Element, "Notifications", null); xmlNotifications.InnerText = notifications.ToString(); Node.AppendChild(xmlNotifications);
XmlNode xmlDisconnectBT = m_Xdoc.CreateNode(XmlNodeType.Element, "DisconnectBTAtStop", null); xmlDisconnectBT.InnerText = disconnectBTAtStop.ToString(); Node.AppendChild(xmlDisconnectBT);
XmlNode xmlSwipeProfiles = m_Xdoc.CreateNode(XmlNodeType.Element, "SwipeProfiles", null); xmlSwipeProfiles.InnerText = swipeProfiles.ToString(); Node.AppendChild(xmlSwipeProfiles);
XmlNode xmlDS4Mapping = m_Xdoc.CreateNode(XmlNodeType.Element, "UseDS4ForMapping", null); xmlDS4Mapping.InnerText = ds4Mapping.ToString(); Node.AppendChild(xmlDS4Mapping);
XmlNode xmlQuickCharge = m_Xdoc.CreateNode(XmlNodeType.Element, "QuickCharge", null); xmlQuickCharge.InnerText = quickCharge.ToString(); Node.AppendChild(xmlQuickCharge);
m_Xdoc.AppendChild(Node);

try { m_Xdoc.Save(m_Profile); }
Expand Down
4 changes: 4 additions & 0 deletions DS4Library/DS4Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,11 @@ private void sendOutputReport(bool synchronous)
try
{
if (!writeOutput())
{
Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> encountered synchronous write failure: " + Marshal.GetLastWin32Error());
ds4Output.Abort();
ds4Output.Join();
}
}
catch
{
Expand Down
14 changes: 14 additions & 0 deletions DS4Tool/DS4Form.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 70 additions & 18 deletions DS4Tool/DS4Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Xml;
using System.Text;
using System.Globalization;
using System.Threading.Tasks;
namespace DS4Windows
{
public partial class DS4Form : Form
Expand Down Expand Up @@ -48,20 +49,7 @@ public partial class DS4Form : Form
ToolTip tt = new ToolTip();
public String m_Profile = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + "\\Profiles.xml";
protected XmlDocument m_Xdoc = new XmlDocument();

protected void SetupArrays()
{
Pads = new Label[4] { lbPad1, lbPad2, lbPad3, lbPad4 };
Batteries = new Label[4] { lBBatt1, lBBatt2, lBBatt3, lBBatt4 };
cbs = new ComboBox[4] { cBController1, cBController2, cBController3, cBController4 };
ebns = new Button[4] { bnEditC1, bnEditC2, bnEditC3, bnEditC4 };
statPB = new PictureBox[4] { pBStatus1, pBStatus2, pBStatus3, pBStatus4 };

shortcuts = new ToolStripMenuItem[4] { (ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[0],
(ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[1],
(ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[2],
(ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[3] };
}
public bool mAllowVisible;

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
Expand All @@ -86,12 +74,22 @@ public DS4Form(string[] args)
InitializeComponent();
arguements = args;
ThemeUtil.SetTheme(lvDebug);
SetupArrays();
Pads = new Label[4] { lbPad1, lbPad2, lbPad3, lbPad4 };
Batteries = new Label[4] { lBBatt1, lBBatt2, lBBatt3, lBBatt4 };
cbs = new ComboBox[4] { cBController1, cBController2, cBController3, cBController4 };
ebns = new Button[4] { bnEditC1, bnEditC2, bnEditC3, bnEditC4 };
statPB = new PictureBox[4] { pBStatus1, pBStatus2, pBStatus3, pBStatus4 };

shortcuts = new ToolStripMenuItem[4] { (ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[0],
(ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[1],
(ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[2],
(ToolStripMenuItem)notifyIcon1.ContextMenuStrip.Items[3] };
SystemEvents.PowerModeChanged += OnPowerChange;
tSOptions.Visible = false;
if (File.Exists(appdatapath + "\\Profiles.xml"))
tt.SetToolTip(linkUninstall, Properties.Resources.IfRemovingDS4Windows);
tt.SetToolTip(cBSwipeProfiles, Properties.Resources.TwoFingerSwipe);
tt.SetToolTip(cBQuickCharge, Properties.Resources.QuickCharge);
bool firstrun = false;
if (File.Exists(exepath + "\\Auto Profiles.xml")
&& File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool\\Auto Profiles.xml"))
Expand Down Expand Up @@ -177,14 +175,19 @@ public DS4Form(string[] args)
hideDS4CheckBox.Checked = Global.getUseExclusiveMode();
hideDS4CheckBox.CheckedChanged += hideDS4CheckBox_CheckedChanged;
cBDisconnectBT.Checked = Global.getDCBTatStop();
cBQuickCharge.Checked = Global.getQuickCharge();
// New settings
this.Width = Global.getFormWidth();
this.Height = Global.getFormHeight();
startMinimizedCheckBox.CheckedChanged -= startMinimizedCheckBox_CheckedChanged;
startMinimizedCheckBox.Checked = Global.getStartMinimized();
startMinimizedCheckBox.CheckedChanged += startMinimizedCheckBox_CheckedChanged;
if (startMinimizedCheckBox.Checked)
this.WindowState = FormWindowState.Minimized;
if (!startMinimizedCheckBox.Checked)
{
mAllowVisible = true;
Show();
}
//this.WindowState = FormWindowState.Minimized;
Form_Resize(null, null);
RefreshProfiles();
for (int i = 0; i < 4; i++)
Expand Down Expand Up @@ -241,6 +244,30 @@ public DS4Form(string[] args)
StartWindowsCheckBox.Checked = File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
}


protected override void SetVisibleCore(bool value)
{
if (!mAllowVisible)
{
value = false;
if (!this.IsHandleCreated) CreateHandle();
}
base.SetVisibleCore(value);
}

private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
mAllowVisible = true;
Show();
}

/*private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
mAllowClose = mAllowVisible = true;
if (!mLoadFired) Show();
Close();
}*/

public static string GetTopWindowName()
{
IntPtr hWnd = GetForegroundWindow();
Expand Down Expand Up @@ -559,6 +586,7 @@ protected void Form_Resize(object sender, EventArgs e)

else if (FormWindowState.Normal == this.WindowState)
{
//mAllowVisible = true;
this.Show();
this.ShowInTaskbar = true;
this.FormBorderStyle = FormBorderStyle.Sizable;
Expand Down Expand Up @@ -631,6 +659,12 @@ protected void ControllerStatusChanged()
for (Int32 Index = 0; Index < Pads.Length; Index++)
{
Pads[Index].Text = rootHub.getDS4MacAddress(Index);
DS4Device d = rootHub.DS4Controllers[Index];
if (d != null && Global.getQuickCharge() && d.ConnectionType == ConnectionType.BT && d.Charging)
{
d.DisconnectBT();
return;
}
switch (rootHub.getDS4Status(Index))
{
case "USB": statPB[Index].Image = Properties.Resources.USB; tt.SetToolTip(statPB[Index], ""); break;
Expand Down Expand Up @@ -672,10 +706,21 @@ protected void ControllerStatusChanged()
private void pBStatus_MouseClick(object sender, MouseEventArgs e)
{
int i = Int32.Parse(((PictureBox)sender).Tag.ToString());
if (e.Button == System.Windows.Forms.MouseButtons.Right && rootHub.getDS4Status(i) == "BT")
if (e.Button == System.Windows.Forms.MouseButtons.Right && rootHub.getDS4Status(i) == "BT" && !rootHub.DS4Controllers[i].Charging)
rootHub.DS4Controllers[i].DisconnectBT();
}

private async void lbPad1_TextChanged(object sender, EventArgs e)
{
Label lb = ((Label)sender);
int i = int.Parse(lb.Name.Substring(lb.Name.Length-1)) - 1;
if (lb.Text == Properties.Resources.Disconnected && Pads[i].Enabled)
{
await Task.Delay(10);
Enable_Controls(i, false);
}
}

private void Enable_Controls(int device, bool on)
{
Pads[device].Enabled = on;
Expand Down Expand Up @@ -975,6 +1020,7 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e)

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
mAllowVisible = true;
this.Show();
WindowState = FormWindowState.Normal;
}
Expand All @@ -987,6 +1033,7 @@ private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
mAllowVisible = true;
this.Show();
WindowState = FormWindowState.Normal;
}
Expand Down Expand Up @@ -1335,6 +1382,11 @@ private void cBSwipeProfiles_CheckedChanged(object sender, EventArgs e)
Global.setSwipeProfiles(cBSwipeProfiles.Checked);
}

private void cBQuickCharge_CheckedChanged(object sender, EventArgs e)
{
Global.setQuickCharge(cBQuickCharge.Checked);
}

private void lbLastMessage_MouseHover(object sender, EventArgs e)
{
tt.Show(lbLastMessage.Text, lbLastMessage, -3, -3);
Expand Down
Loading

0 comments on commit d088687

Please sign in to comment.