summaryrefslogtreecommitdiff
path: root/grapher
diff options
context:
space:
mode:
authorTomáš Pazdiora <[email protected]>2021-01-07 23:21:33 +0100
committerTomáš Pazdiora <[email protected]>2021-01-07 23:21:33 +0100
commit215a21f9b62aa50d9ca4037ca0a22f5b0920f373 (patch)
tree3f0cbca12e4575cc325c86996d952d01829b2acd /grapher
parentupdate devicelist app (diff)
downloadrawaccel-215a21f9b62aa50d9ca4037ca0a22f5b0920f373.tar.xz
rawaccel-215a21f9b62aa50d9ca4037ca0a22f5b0920f373.zip
rough GUI integration of "Device Hardware ID"
Diffstat (limited to 'grapher')
-rw-r--r--grapher/Form1.Designer.cs31
-rw-r--r--grapher/Form1.cs1
-rw-r--r--grapher/Models/AccelGUIFactory.cs2
-rw-r--r--grapher/Models/Devices/DeviceList.cs33
-rw-r--r--grapher/Models/Serialized/SettingsManager.cs66
-rw-r--r--grapher/grapher.csproj2
6 files changed, 124 insertions, 11 deletions
diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs
index 6fd9478..c388d79 100644
--- a/grapher/Form1.Designer.cs
+++ b/grapher/Form1.Designer.cs
@@ -161,6 +161,8 @@ namespace grapher
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.wholeVectorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.byVectorComponentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.UseSpecificDeviceMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.chartsPanel = new System.Windows.Forms.Panel();
this.GainChartY = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.VelocityChartY = new System.Windows.Forms.DataVisualization.Charting.Chart();
@@ -168,7 +170,6 @@ namespace grapher
this.GainChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.VelocityChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
- this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsPanel.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.chartsPanel.SuspendLayout();
@@ -956,7 +957,8 @@ namespace grapher
this.capStyleToolStripMenuItem,
this.offsetStyleToolStripMenuItem,
this.toolStripMenuItem1,
- this.AutoWriteMenuItem});
+ this.AutoWriteMenuItem,
+ this.UseSpecificDeviceMenuItem});
this.advancedToolStripMenuItem.Name = "advancedToolStripMenuItem";
this.advancedToolStripMenuItem.Size = new System.Drawing.Size(72, 20);
this.advancedToolStripMenuItem.Text = "Advanced";
@@ -1029,6 +1031,21 @@ namespace grapher
this.byVectorComponentToolStripMenuItem.Size = new System.Drawing.Size(154, 22);
this.byVectorComponentToolStripMenuItem.Text = "By Component";
//
+ // AutoWriteMenuItem
+ //
+ this.AutoWriteMenuItem.Checked = true;
+ this.AutoWriteMenuItem.CheckOnClick = true;
+ this.AutoWriteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.AutoWriteMenuItem.Name = "AutoWriteMenuItem";
+ this.AutoWriteMenuItem.Size = new System.Drawing.Size(210, 22);
+ this.AutoWriteMenuItem.Text = "Apply Settings On Startup";
+ //
+ // UseSpecificDeviceMenuItem
+ //
+ this.UseSpecificDeviceMenuItem.Name = "UseSpecificDeviceMenuItem";
+ this.UseSpecificDeviceMenuItem.Size = new System.Drawing.Size(210, 22);
+ this.UseSpecificDeviceMenuItem.Text = "Use Specific Device";
+ //
// chartsPanel
//
this.chartsPanel.AutoScroll = true;
@@ -1281,15 +1298,6 @@ namespace grapher
title6.Text = "Sensitivity";
this.AccelerationChart.Titles.Add(title6);
//
- // AutoWriteMenuItem
- //
- this.AutoWriteMenuItem.Checked = true;
- this.AutoWriteMenuItem.CheckOnClick = true;
- this.AutoWriteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
- this.AutoWriteMenuItem.Name = "AutoWriteMenuItem";
- this.AutoWriteMenuItem.Size = new System.Drawing.Size(210, 22);
- this.AutoWriteMenuItem.Text = "Apply Settings On Startup";
- //
// RawAcceleration
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1418,6 +1426,7 @@ namespace grapher
private System.Windows.Forms.DataVisualization.Charting.Chart VelocityChart;
private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart;
private System.Windows.Forms.ToolStripMenuItem AutoWriteMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem UseSpecificDeviceMenuItem;
}
}
diff --git a/grapher/Form1.cs b/grapher/Form1.cs
index 0c12b86..e149163 100644
--- a/grapher/Form1.cs
+++ b/grapher/Form1.cs
@@ -71,6 +71,7 @@ namespace grapher
gainOffsetToolStripMenuItem,
legacyOffsetToolStripMenuItem,
AutoWriteMenuItem,
+ UseSpecificDeviceMenuItem,
ScaleMenuItem,
DPITextBox,
PollRateTextBox,
diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs
index 901a1b5..0e3646d 100644
--- a/grapher/Models/AccelGUIFactory.cs
+++ b/grapher/Models/AccelGUIFactory.cs
@@ -34,6 +34,7 @@ namespace grapher.Models
ToolStripMenuItem gainOffsetToolStripMenuItem,
ToolStripMenuItem legacyOffsetToolStripMenuItem,
ToolStripMenuItem autoWriteMenuItem,
+ ToolStripMenuItem useSpecificDeviceMenuItem,
ToolStripMenuItem scaleMenuItem,
ToolStripTextBox dpiTextBox,
ToolStripTextBox pollRateTextBox,
@@ -329,6 +330,7 @@ namespace grapher.Models
accelCalculator.DPI,
accelCalculator.PollRate,
autoWriteMenuItem,
+ useSpecificDeviceMenuItem,
showLastMouseMoveMenuItem,
showVelocityGainToolStripMenuItem);
diff --git a/grapher/Models/Devices/DeviceList.cs b/grapher/Models/Devices/DeviceList.cs
new file mode 100644
index 0000000..9f2b81d
--- /dev/null
+++ b/grapher/Models/Devices/DeviceList.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Management;
+using System.Collections.Generic;
+
+namespace grapher.Models.Devices
+{
+ class DeviceList
+ {
+ public static List<Tuple<string, string>> GetDeviceHardwareIDs(string PNPClass = "Mouse")
+ {
+ var results = new List<Tuple<string, string>>();
+
+ ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity"));
+
+ foreach (ManagementObject obj in searcher.Get())
+ {
+ if (obj["PNPClass"] != null && obj["PNPClass"].ToString() == PNPClass && obj["HardwareID"] != null)
+ {
+ String[] hwidArray = (String[])(obj["HardwareID"]);
+ if (hwidArray.Length > 0)
+ {
+ String hwid = hwidArray[0].ToString();
+ String name = obj["Name"].ToString();
+ results.Add(Tuple.Create(name, hwid));
+ }
+ }
+ }
+
+ return results;
+ }
+
+ }
+}
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs
index 41ebcb5..3adbc8b 100644
--- a/grapher/Models/Serialized/SettingsManager.cs
+++ b/grapher/Models/Serialized/SettingsManager.cs
@@ -3,6 +3,7 @@ using System;
using System.Windows.Forms;
using System.Threading;
using System.Text;
+using System.Drawing;
namespace grapher.Models.Serialized
{
@@ -15,6 +16,7 @@ namespace grapher.Models.Serialized
Field dpiField,
Field pollRateField,
ToolStripMenuItem autoWrite,
+ ToolStripMenuItem useSpecificDevice,
ToolStripMenuItem showLastMouseMove,
ToolStripMenuItem showVelocityAndGain)
{
@@ -22,6 +24,7 @@ namespace grapher.Models.Serialized
DpiField = dpiField;
PollRateField = pollRateField;
AutoWriteMenuItem = autoWrite;
+ UseSpecificDeviceMenuItem = useSpecificDevice;
ShowLastMouseMoveMenuItem = showLastMouseMove;
ShowVelocityAndGainMoveMenuItem = showVelocityAndGain;
}
@@ -40,6 +43,8 @@ namespace grapher.Models.Serialized
private ToolStripMenuItem AutoWriteMenuItem { get; set; }
+ private ToolStripMenuItem UseSpecificDeviceMenuItem { get; set; }
+
private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; }
private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; }
@@ -61,6 +66,66 @@ namespace grapher.Models.Serialized
return errors;
}
+ private void SpecificDeviceClickHnadler(Object o, EventArgs a, string hwid)
+ {
+ var item = (ToolStripMenuItem)o;
+ foreach (ToolStripMenuItem i in UseSpecificDeviceMenuItem.DropDownItems)
+ {
+ i.Checked = false;
+ }
+ item.Checked = true;
+ if (hwid == null || hwid == "")
+ {
+ UseSpecificDeviceMenuItem.Checked = false;
+ } else
+ {
+ UseSpecificDeviceMenuItem.Checked = true;
+ }
+ RawAccelSettings.AccelerationSettings.deviceHardwareID = hwid;
+
+ TryUpdateActiveSettings(RawAccelSettings.AccelerationSettings);
+
+ }
+ private void UpdateUseSpecificDeviceMenu()
+ {
+ var hwid = RawAccelSettings.AccelerationSettings.deviceHardwareID;
+ if (hwid == null) { hwid = ""; }
+
+ UseSpecificDeviceMenuItem.Checked = hwid.Length > 0;
+ UseSpecificDeviceMenuItem.DropDownItems.Clear();
+
+ var any_device = new ToolStripMenuItem();
+ any_device.Text = "";
+ any_device.Checked = hwid.Length == 0;
+ any_device.Click += new EventHandler(delegate(Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, ""); });
+ UseSpecificDeviceMenuItem.DropDownItems.Add(any_device);
+
+ var hwid_not_found = true;
+
+ foreach (Tuple<string,string> device in Models.Devices.DeviceList.GetDeviceHardwareIDs())
+ {
+ if (hwid == device.Item2)
+ {
+ hwid_not_found = false;
+ }
+ var dev = new ToolStripMenuItem();
+ dev.Text = device.Item1;
+ dev.Checked = device.Item2 == RawAccelSettings.AccelerationSettings.deviceHardwareID;
+ dev.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, device.Item2); });
+ UseSpecificDeviceMenuItem.DropDownItems.Add(dev);
+ }
+
+ if (hwid.Length > 0 && hwid_not_found)
+ {
+ var current_hwid = new ToolStripMenuItem();
+ current_hwid.Text = "Disconnected (" + hwid + ")";
+ current_hwid.ForeColor = Color.DarkGray;
+ current_hwid.Checked = true;
+ current_hwid.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, hwid); });
+ UseSpecificDeviceMenuItem.DropDownItems.Add(current_hwid);
+ }
+ }
+
public void UpdateFieldsFromGUISettings()
{
DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI);
@@ -110,6 +175,7 @@ namespace grapher.Models.Serialized
{
RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields());
UpdateFieldsFromGUISettings();
+ UpdateUseSpecificDeviceMenu();
if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup)
{
TryUpdateAccel(RawAccelSettings.AccelerationSettings);
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index f6bdcb9..8adfa75 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -59,6 +59,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Management" />
<Reference Include="System.Windows.Forms.DataVisualization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -92,6 +93,7 @@
<Compile Include="Models\Charts\EstimatedPoints.cs" />
<Compile Include="Models\Charts\ChartState\XYOneGraphState.cs" />
<Compile Include="Models\Charts\ChartState\XYTwoGraphState.cs" />
+ <Compile Include="Models\Devices\DeviceList.cs" />
<Compile Include="Models\Mouse\MouseData.cs" />
<Compile Include="Models\Mouse\MouseWatcher.cs" />
<Compile Include="Models\Mouse\PointData.cs" />