This commit is contained in:
Serge
2023-08-18 18:15:14 +02:00
5 changed files with 425 additions and 72 deletions

View File

@@ -33,6 +33,14 @@
labelProfile = new Label(); labelProfile = new Label();
panelPerformance = new Panel(); panelPerformance = new Panel();
panelPerformanceOther = new Panel(); panelPerformanceOther = new Panel();
panelDeceleration = new Panel();
labelDeceleration = new Label();
sliderDeceleration = new UI.Slider();
labelDecelerationValue = new Label();
panelAcceleration = new Panel();
labelAcceleration = new Label();
sliderAcceleration = new UI.Slider();
labelAccelerationValue = new Label();
panelLiftOffDistance = new Panel(); panelLiftOffDistance = new Panel();
labelLiftOffDistance = new Label(); labelLiftOffDistance = new Label();
comboBoxLiftOffDistance = new UI.RComboBox(); comboBoxLiftOffDistance = new UI.RComboBox();
@@ -108,6 +116,8 @@
panelProfiles.SuspendLayout(); panelProfiles.SuspendLayout();
panelPerformance.SuspendLayout(); panelPerformance.SuspendLayout();
panelPerformanceOther.SuspendLayout(); panelPerformanceOther.SuspendLayout();
panelDeceleration.SuspendLayout();
panelAcceleration.SuspendLayout();
panelLiftOffDistance.SuspendLayout(); panelLiftOffDistance.SuspendLayout();
panelDebounce.SuspendLayout(); panelDebounce.SuspendLayout();
panelAngleSnapping.SuspendLayout(); panelAngleSnapping.SuspendLayout();
@@ -182,13 +192,15 @@
panelPerformance.Location = new Point(11, 68); panelPerformance.Location = new Point(11, 68);
panelPerformance.Name = "panelPerformance"; panelPerformance.Name = "panelPerformance";
panelPerformance.Padding = new Padding(0, 11, 0, 25); panelPerformance.Padding = new Padding(0, 11, 0, 25);
panelPerformance.Size = new Size(654, 461); panelPerformance.Size = new Size(654, 555);
panelPerformance.TabIndex = 1; panelPerformance.TabIndex = 1;
// //
// panelPerformanceOther // panelPerformanceOther
// //
panelPerformanceOther.AutoSize = true; panelPerformanceOther.AutoSize = true;
panelPerformanceOther.AutoSizeMode = AutoSizeMode.GrowAndShrink; panelPerformanceOther.AutoSizeMode = AutoSizeMode.GrowAndShrink;
panelPerformanceOther.Controls.Add(panelDeceleration);
panelPerformanceOther.Controls.Add(panelAcceleration);
panelPerformanceOther.Controls.Add(panelLiftOffDistance); panelPerformanceOther.Controls.Add(panelLiftOffDistance);
panelPerformanceOther.Controls.Add(panelDebounce); panelPerformanceOther.Controls.Add(panelDebounce);
panelPerformanceOther.Controls.Add(panelAngleSnapping); panelPerformanceOther.Controls.Add(panelAngleSnapping);
@@ -197,9 +209,103 @@
panelPerformanceOther.Location = new Point(0, 240); panelPerformanceOther.Location = new Point(0, 240);
panelPerformanceOther.Name = "panelPerformanceOther"; panelPerformanceOther.Name = "panelPerformanceOther";
panelPerformanceOther.Padding = new Padding(0, 11, 0, 11); panelPerformanceOther.Padding = new Padding(0, 11, 0, 11);
panelPerformanceOther.Size = new Size(654, 196); panelPerformanceOther.Size = new Size(654, 290);
panelPerformanceOther.TabIndex = 49; panelPerformanceOther.TabIndex = 49;
// //
// panelDeceleration
//
panelDeceleration.AutoSize = true;
panelDeceleration.AutoSizeMode = AutoSizeMode.GrowAndShrink;
panelDeceleration.Controls.Add(labelDeceleration);
panelDeceleration.Controls.Add(sliderDeceleration);
panelDeceleration.Controls.Add(labelDecelerationValue);
panelDeceleration.Dock = DockStyle.Top;
panelDeceleration.Location = new Point(0, 232);
panelDeceleration.Name = "panelDeceleration";
panelDeceleration.Padding = new Padding(5);
panelDeceleration.Size = new Size(654, 47);
panelDeceleration.TabIndex = 58;
//
// labelDeceleration
//
labelDeceleration.Location = new Point(6, 7);
labelDeceleration.Margin = new Padding(6, 0, 6, 0);
labelDeceleration.Name = "labelDeceleration";
labelDeceleration.Size = new Size(348, 33);
labelDeceleration.TabIndex = 52;
labelDeceleration.Text = "Deceleration";
//
// sliderDeceleration
//
sliderDeceleration.AccessibleName = "DPI Slider";
sliderDeceleration.Location = new Point(368, 9);
sliderDeceleration.Max = 9;
sliderDeceleration.Min = 0;
sliderDeceleration.Name = "sliderDeceleration";
sliderDeceleration.Size = new Size(213, 30);
sliderDeceleration.Step = 1;
sliderDeceleration.TabIndex = 50;
sliderDeceleration.TabStop = false;
sliderDeceleration.Text = "sliderBattery";
sliderDeceleration.Value = 0;
//
// labelDecelerationValue
//
labelDecelerationValue.Location = new Point(590, 9);
labelDecelerationValue.Margin = new Padding(6, 0, 6, 0);
labelDecelerationValue.Name = "labelDecelerationValue";
labelDecelerationValue.Size = new Size(60, 30);
labelDecelerationValue.TabIndex = 51;
labelDecelerationValue.Text = "0";
labelDecelerationValue.TextAlign = ContentAlignment.MiddleRight;
//
// panelAcceleration
//
panelAcceleration.AutoSize = true;
panelAcceleration.AutoSizeMode = AutoSizeMode.GrowAndShrink;
panelAcceleration.Controls.Add(labelAcceleration);
panelAcceleration.Controls.Add(sliderAcceleration);
panelAcceleration.Controls.Add(labelAccelerationValue);
panelAcceleration.Dock = DockStyle.Top;
panelAcceleration.Location = new Point(0, 185);
panelAcceleration.Name = "panelAcceleration";
panelAcceleration.Padding = new Padding(5);
panelAcceleration.Size = new Size(654, 47);
panelAcceleration.TabIndex = 57;
//
// labelAcceleration
//
labelAcceleration.Location = new Point(6, 7);
labelAcceleration.Margin = new Padding(6, 0, 6, 0);
labelAcceleration.Name = "labelAcceleration";
labelAcceleration.Size = new Size(348, 33);
labelAcceleration.TabIndex = 52;
labelAcceleration.Text = "Acceleration";
//
// sliderAcceleration
//
sliderAcceleration.AccessibleName = "DPI Slider";
sliderAcceleration.Location = new Point(368, 9);
sliderAcceleration.Max = 9;
sliderAcceleration.Min = 0;
sliderAcceleration.Name = "sliderAcceleration";
sliderAcceleration.Size = new Size(213, 30);
sliderAcceleration.Step = 1;
sliderAcceleration.TabIndex = 50;
sliderAcceleration.TabStop = false;
sliderAcceleration.Text = "sliderBattery";
sliderAcceleration.Value = 0;
//
// labelAccelerationValue
//
labelAccelerationValue.Location = new Point(590, 9);
labelAccelerationValue.Margin = new Padding(6, 0, 6, 0);
labelAccelerationValue.Name = "labelAccelerationValue";
labelAccelerationValue.Size = new Size(60, 30);
labelAccelerationValue.TabIndex = 51;
labelAccelerationValue.Text = "0";
labelAccelerationValue.TextAlign = ContentAlignment.MiddleRight;
//
// panelLiftOffDistance // panelLiftOffDistance
// //
panelLiftOffDistance.AutoSize = true; panelLiftOffDistance.AutoSize = true;
@@ -656,7 +762,7 @@
panelLighting.Controls.Add(panelLightingContent); panelLighting.Controls.Add(panelLightingContent);
panelLighting.Controls.Add(panelLightingHeader); panelLighting.Controls.Add(panelLightingHeader);
panelLighting.Dock = DockStyle.Top; panelLighting.Dock = DockStyle.Top;
panelLighting.Location = new Point(11, 529); panelLighting.Location = new Point(11, 623);
panelLighting.Name = "panelLighting"; panelLighting.Name = "panelLighting";
panelLighting.Padding = new Padding(0, 0, 0, 25); panelLighting.Padding = new Padding(0, 0, 0, 25);
panelLighting.Size = new Size(654, 329); panelLighting.Size = new Size(654, 329);
@@ -985,7 +1091,7 @@
panelEnergy.Controls.Add(labelAutoPowerOff); panelEnergy.Controls.Add(labelAutoPowerOff);
panelEnergy.Controls.Add(panelEnergyHeader); panelEnergy.Controls.Add(panelEnergyHeader);
panelEnergy.Dock = DockStyle.Top; panelEnergy.Dock = DockStyle.Top;
panelEnergy.Location = new Point(11, 858); panelEnergy.Location = new Point(11, 952);
panelEnergy.Name = "panelEnergy"; panelEnergy.Name = "panelEnergy";
panelEnergy.Padding = new Padding(0, 0, 0, 25); panelEnergy.Padding = new Padding(0, 0, 0, 25);
panelEnergy.Size = new Size(654, 143); panelEnergy.Size = new Size(654, 143);
@@ -1166,7 +1272,7 @@
panelBottomButtons.AutoSizeMode = AutoSizeMode.GrowAndShrink; panelBottomButtons.AutoSizeMode = AutoSizeMode.GrowAndShrink;
panelBottomButtons.Controls.Add(buttonSync); panelBottomButtons.Controls.Add(buttonSync);
panelBottomButtons.Dock = DockStyle.Top; panelBottomButtons.Dock = DockStyle.Top;
panelBottomButtons.Location = new Point(11, 1001); panelBottomButtons.Location = new Point(11, 1095);
panelBottomButtons.Name = "panelBottomButtons"; panelBottomButtons.Name = "panelBottomButtons";
panelBottomButtons.Size = new Size(654, 67); panelBottomButtons.Size = new Size(654, 67);
panelBottomButtons.TabIndex = 47; panelBottomButtons.TabIndex = 47;
@@ -1260,6 +1366,8 @@
panelPerformance.PerformLayout(); panelPerformance.PerformLayout();
panelPerformanceOther.ResumeLayout(false); panelPerformanceOther.ResumeLayout(false);
panelPerformanceOther.PerformLayout(); panelPerformanceOther.PerformLayout();
panelDeceleration.ResumeLayout(false);
panelAcceleration.ResumeLayout(false);
panelLiftOffDistance.ResumeLayout(false); panelLiftOffDistance.ResumeLayout(false);
panelDebounce.ResumeLayout(false); panelDebounce.ResumeLayout(false);
panelAngleSnapping.ResumeLayout(false); panelAngleSnapping.ResumeLayout(false);
@@ -1379,5 +1487,13 @@
private Panel panelAngleSnapping; private Panel panelAngleSnapping;
private Panel panelLiftOffDistance; private Panel panelLiftOffDistance;
private Panel panelDebounce; private Panel panelDebounce;
private Panel panelDeceleration;
private Label labelDeceleration;
private UI.Slider sliderDeceleration;
private Label labelDecelerationValue;
private Panel panelAcceleration;
private Label labelAcceleration;
private UI.Slider sliderAcceleration;
private Label labelAccelerationValue;
} }
} }

View File

@@ -46,6 +46,8 @@ namespace GHelper
labelChargingState.Text = "(" + Properties.Strings.Charging + ")"; labelChargingState.Text = "(" + Properties.Strings.Charging + ")";
labelProfile.Text = Properties.Strings.Profile; labelProfile.Text = Properties.Strings.Profile;
labelButtonDebounce.Text = Properties.Strings.MouseButtonResponse; labelButtonDebounce.Text = Properties.Strings.MouseButtonResponse;
labelAcceleration.Text = Properties.Strings.Acceleration;
labelDeceleration.Text = Properties.Strings.Deceleration;
buttonLightingZoneLogo.Text = Properties.Strings.AuraZoneLogo; buttonLightingZoneLogo.Text = Properties.Strings.AuraZoneLogo;
buttonLightingZoneScroll.Text = Properties.Strings.AuraZoneScroll; buttonLightingZoneScroll.Text = Properties.Strings.AuraZoneScroll;
@@ -80,6 +82,12 @@ namespace GHelper
sliderButtonDebounce.ValueChanged += SliderButtonDebounce_ValueChanged; sliderButtonDebounce.ValueChanged += SliderButtonDebounce_ValueChanged;
sliderButtonDebounce.MouseUp += SliderButtonDebounce_MouseUp; sliderButtonDebounce.MouseUp += SliderButtonDebounce_MouseUp;
sliderAcceleration.MouseUp += SliderAcceleration_MouseUp;
sliderAcceleration.ValueChanged += SliderAcceleration_ValueChanged;
sliderDeceleration.MouseUp += SliderDeceleration_MouseUp;
sliderDeceleration.ValueChanged += SliderDeceleration_ValueChanged;
buttonLightingColor.Click += ButtonLightingColor_Click; buttonLightingColor.Click += ButtonLightingColor_Click;
comboBoxLightingMode.DropDownClosed += ComboBoxLightingMode_DropDownClosed; comboBoxLightingMode.DropDownClosed += ComboBoxLightingMode_DropDownClosed;
sliderBrightness.MouseUp += SliderBrightness_MouseUp; sliderBrightness.MouseUp += SliderBrightness_MouseUp;
@@ -103,6 +111,26 @@ namespace GHelper
RefreshMouseData(); RefreshMouseData();
} }
private void SliderAcceleration_MouseUp(object? sender, MouseEventArgs e)
{
mouse.SetAcceleration(sliderAcceleration.Value);
}
private void SliderAcceleration_ValueChanged(object? sender, EventArgs e)
{
labelAccelerationValue.Text = sliderAcceleration.Value.ToString();
}
private void SliderDeceleration_MouseUp(object? sender, MouseEventArgs e)
{
mouse.SetDeceleration(sliderDeceleration.Value);
}
private void SliderDeceleration_ValueChanged(object? sender, EventArgs e)
{
labelDecelerationValue.Text = sliderDeceleration.Value.ToString();
}
private void SliderButtonDebounce_MouseUp(object? sender, MouseEventArgs e) private void SliderButtonDebounce_MouseUp(object? sender, MouseEventArgs e)
{ {
DebounceTime dbt = (DebounceTime)sliderButtonDebounce.Value; DebounceTime dbt = (DebounceTime)sliderButtonDebounce.Value;
@@ -513,6 +541,24 @@ namespace GHelper
panelAngleSnapping.Visible = false; panelAngleSnapping.Visible = false;
} }
if (mouse.HasAcceleration())
{
sliderAcceleration.Max = mouse.MaxAcceleration();
}
else
{
panelAcceleration.Visible = false;
}
if (mouse.HasDeceleration())
{
sliderDeceleration.Max = mouse.MaxDeceleration();
}
else
{
panelDeceleration.Visible = false;
}
if (mouse.HasLiftOffSetting()) if (mouse.HasLiftOffSetting())
{ {
comboBoxLiftOffDistance.Items.AddRange(new string[] { comboBoxLiftOffDistance.Items.AddRange(new string[] {
@@ -681,6 +727,16 @@ namespace GHelper
{ {
sliderButtonDebounce.Value = (int)mouse.Debounce; sliderButtonDebounce.Value = (int)mouse.Debounce;
} }
if (mouse.HasAcceleration())
{
sliderAcceleration.Value = mouse.Acceleration;
}
if (mouse.HasDeceleration())
{
sliderDeceleration.Value = mouse.Deceleration;
}
} }
private void VisualizeBatteryState() private void VisualizeBatteryState()

View File

@@ -149,6 +149,8 @@ namespace GHelper.Peripherals.Mouse
private readonly string path; private readonly string path;
protected byte reportId = 0x00;
public bool IsDeviceReady { get; protected set; } public bool IsDeviceReady { get; protected set; }
private void SetDeviceReady(bool ready) private void SetDeviceReady(bool ready)
@@ -180,6 +182,8 @@ namespace GHelper.Peripherals.Mouse
public bool AngleSnapping { get; protected set; } public bool AngleSnapping { get; protected set; }
public short AngleAdjustmentDegrees { get; protected set; } public short AngleAdjustmentDegrees { get; protected set; }
public DebounceTime Debounce { get; protected set; } public DebounceTime Debounce { get; protected set; }
public int Acceleration { get; protected set; }
public int Deceleration { get; protected set; }
public AsusMouse(ushort vendorId, ushort productId, string path, bool wireless) : base(vendorId, productId) public AsusMouse(ushort vendorId, ushort productId, string path, bool wireless) : base(vendorId, productId)
@@ -195,7 +199,12 @@ namespace GHelper.Peripherals.Mouse
{ {
LightingSetting = new LightingSetting[SupportedLightingZones().Length]; LightingSetting = new LightingSetting[SupportedLightingZones().Length];
} }
this.reportId = 0x00;
}
public AsusMouse(ushort vendorId, ushort productId, string path, bool wireless, byte reportId) : this(vendorId, productId, path, wireless)
{
this.reportId = reportId;
} }
public override bool Equals(object? obj) public override bool Equals(object? obj)
@@ -279,7 +288,7 @@ namespace GHelper.Peripherals.Mouse
} }
} }
private static bool IsPacketLoggerEnabled() protected static bool IsPacketLoggerEnabled()
{ {
#if DEBUG #if DEBUG
return true; return true;
@@ -307,59 +316,86 @@ namespace GHelper.Peripherals.Mouse
[MethodImpl(MethodImplOptions.Synchronized)] [MethodImpl(MethodImplOptions.Synchronized)]
protected virtual byte[]? WriteForResponse(byte[] packet) protected virtual byte[]? WriteForResponse(byte[] packet)
{ {
Array.Resize(ref packet, ASUS_MOUSE_PACKET_SIZE);
byte[] response = new byte[ASUS_MOUSE_PACKET_SIZE]; byte[] response = new byte[ASUS_MOUSE_PACKET_SIZE];
try int retries = 3;
while (retries > 0)
{ {
if (IsPacketLoggerEnabled()) response = new byte[ASUS_MOUSE_PACKET_SIZE];
Logger.WriteLine(GetDisplayName() + ": Sending packet: " + ByteArrayToString(packet));
long time = MeasuredIO(Write, packet); try
Logger.WriteLine(GetDisplayName() + ": Write took " + time + "ms");
time = MeasuredIO(Read, response);
Logger.WriteLine(GetDisplayName() + ": Read took " + time + "ms");
if (IsPacketLoggerEnabled())
Logger.WriteLine(GetDisplayName() + ": Read packet: " + ByteArrayToString(response));
if (IsMouseError(response))
{ {
Logger.WriteLine(GetDisplayName() + ": Mouse returned error (FF AA). Packet probably not supported by mouse firmware."); if (IsPacketLoggerEnabled())
//Error. Mouse could not understand or process the sent packet Logger.WriteLine(GetDisplayName() + ": Sending packet: " + ByteArrayToString(packet)
return response; + " Try " + (retries - 2) + " of 3");
}
long time = MeasuredIO(Write, packet);
Logger.WriteLine(GetDisplayName() + ": Write took " + time + "ms");
//Not the response we were looking for, continue reading
while (response[0] != packet[0] || response[1] != packet[1] || response[2] != packet[2])
{
Logger.WriteLine(GetDisplayName() + ": Read wrong packet left in buffer: " + ByteArrayToString(response) + ". Retrying...");
//Read again
time = MeasuredIO(Read, response); time = MeasuredIO(Read, response);
Logger.WriteLine(GetDisplayName() + ": Read took " + time + "ms"); Logger.WriteLine(GetDisplayName() + ": Read took " + time + "ms");
if (IsMouseError(response))
{
if (IsPacketLoggerEnabled())
Logger.WriteLine(GetDisplayName() + ": Read packet: " + ByteArrayToString(response));
Logger.WriteLine(GetDisplayName() + ": Mouse returned error (FF AA). Packet probably not supported by mouse firmware.");
//Error. Mouse could not understand or process the sent packet
return response;
}
if (response[1] == 0 && response[2] == 0 && response[3] == 0)
{
if (IsPacketLoggerEnabled())
Logger.WriteLine(GetDisplayName() + ": Read packet: " + ByteArrayToString(response));
Logger.WriteLine(GetDisplayName() + ": Received empty packet. Stopping here.");
//Empty packet
return null;
}
//Not the response we were looking for, continue reading
while (response[0] != packet[0] || response[1] != packet[1] || response[2] != packet[2])
{
if (IsPacketLoggerEnabled())
Logger.WriteLine(GetDisplayName() + ": Read wrong packet left in buffer: " + ByteArrayToString(response) + ". Retrying...");
//Read again
time = MeasuredIO(Read, response);
Logger.WriteLine(GetDisplayName() + ": Read took " + time + "ms");
}
if (IsPacketLoggerEnabled())
Logger.WriteLine(GetDisplayName() + ": Read packet: " + ByteArrayToString(response));
return response;
}
catch (IOException e)
{
Logger.WriteLine(GetDisplayName() + ": Failed to read packet " + e.Message);
OnDisconnect();
return null;
}
catch (TimeoutException e)
{
Logger.WriteLine(GetDisplayName() + ": Timeout reading packet " + e.Message + " Trying again.");
retries--;
continue;
}
catch (ObjectDisposedException)
{
Logger.WriteLine(GetDisplayName() + ": Channel closed ");
OnDisconnect();
return null;
} }
} }
catch (IOException e) return null;
{
Logger.WriteLine(GetDisplayName() + ": Failed to read packet " + e.Message);
OnDisconnect();
return null;
}
catch (TimeoutException e)
{
Logger.WriteLine(GetDisplayName() + ": Timeout reading packet " + e.Message);
return null;
}
catch (ObjectDisposedException)
{
Logger.WriteLine(GetDisplayName() + ": Channel closed ");
OnDisconnect();
return null;
}
return response;
} }
public abstract string GetDisplayName(); public abstract string GetDisplayName();
@@ -386,6 +422,7 @@ namespace GHelper.Peripherals.Mouse
ReadPollingRate(); ReadPollingRate();
ReadLiftOffDistance(); ReadLiftOffDistance();
ReadDebounce(); ReadDebounce();
ReadAcceleration();
ReadLightingSetting(); ReadLightingSetting();
} }
@@ -410,7 +447,7 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetBatteryReportPacket() protected virtual byte[] GetBatteryReportPacket()
{ {
return new byte[] { 0x00, 0x12, 0x07 }; return new byte[] { reportId, 0x12, 0x07 };
} }
protected virtual int ParseBattery(byte[] packet) protected virtual int ParseBattery(byte[] packet)
@@ -452,7 +489,7 @@ namespace GHelper.Peripherals.Mouse
} }
protected virtual byte[] GetUpdateEnergySettingsPacket(int lowBatteryWarning, PowerOffSetting powerOff) protected virtual byte[] GetUpdateEnergySettingsPacket(int lowBatteryWarning, PowerOffSetting powerOff)
{ {
return new byte[] { 0x00, 0x51, 0x37, 0x00, 0x00, (byte)powerOff, 0x00, (byte)lowBatteryWarning }; return new byte[] { reportId, 0x51, 0x37, 0x00, 0x00, (byte)powerOff, 0x00, (byte)lowBatteryWarning };
} }
public void SetEnergySettings(int lowBatteryWarning, PowerOffSetting powerOff) public void SetEnergySettings(int lowBatteryWarning, PowerOffSetting powerOff)
@@ -538,7 +575,7 @@ namespace GHelper.Peripherals.Mouse
return packet[11]; return packet[11];
} }
Logger.WriteLine(GetDisplayName() + ": Failed to decode active profile"); Logger.WriteLine(GetDisplayName() + ": Failed to decode active profile");
return 1; return 0;
} }
protected virtual int ParseDPIProfile(byte[] packet) protected virtual int ParseDPIProfile(byte[] packet)
@@ -553,12 +590,12 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetReadProfilePacket() protected virtual byte[] GetReadProfilePacket()
{ {
return new byte[] { 0x00, 0x12, 0x00 }; return new byte[] { reportId, 0x12, 0x00 };
} }
protected virtual byte[] GetUpdateProfilePacket(int profile) protected virtual byte[] GetUpdateProfilePacket(int profile)
{ {
return new byte[] { 0x00, 0x50, 0x02, (byte)profile }; return new byte[] { reportId, 0x50, 0x02, (byte)profile };
} }
public void ReadProfile() public void ReadProfile()
@@ -667,20 +704,20 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetReadPollingRatePacket() protected virtual byte[] GetReadPollingRatePacket()
{ {
return new byte[] { 0x00, 0x12, 0x04, 0x00 }; return new byte[] { reportId, 0x12, 0x04, 0x00 };
} }
protected virtual byte[] GetUpdatePollingRatePacket(PollingRate pollingRate) protected virtual byte[] GetUpdatePollingRatePacket(PollingRate pollingRate)
{ {
return new byte[] { 0x00, 0x51, 0x31, 0x04, 0x00, (byte)pollingRate }; return new byte[] { reportId, 0x51, 0x31, 0x04, 0x00, (byte)pollingRate };
} }
protected virtual byte[] GetUpdateAngleSnappingPacket(bool angleSnapping) protected virtual byte[] GetUpdateAngleSnappingPacket(bool angleSnapping)
{ {
return new byte[] { 0x00, 0x51, 0x31, 0x06, 0x00, (byte)(angleSnapping ? 0x01 : 0x00) }; return new byte[] { reportId, 0x51, 0x31, 0x06, 0x00, (byte)(angleSnapping ? 0x01 : 0x00) };
} }
protected virtual byte[] GetUpdateAngleAdjustmentPacket(short angleAdjustment) protected virtual byte[] GetUpdateAngleAdjustmentPacket(short angleAdjustment)
{ {
return new byte[] { 0x00, 0x51, 0x31, 0x0B, 0x00, (byte)(angleAdjustment & 0xFF), (byte)((angleAdjustment >> 8) & 0xFF) }; return new byte[] { reportId, 0x51, 0x31, 0x0B, 0x00, (byte)(angleAdjustment & 0xFF), (byte)((angleAdjustment >> 8) & 0xFF) };
} }
protected virtual PollingRate ParsePollingRate(byte[] packet) protected virtual PollingRate ParsePollingRate(byte[] packet)
@@ -791,6 +828,126 @@ namespace GHelper.Peripherals.Mouse
this.AngleAdjustmentDegrees = angleAdjustment; this.AngleAdjustmentDegrees = angleAdjustment;
} }
// ------------------------------------------------------------------------------
// Acceleration/Deceleration
// ------------------------------------------------------------------------------
public virtual bool HasAcceleration()
{
return false;
}
public virtual bool HasDeceleration()
{
return false;
}
public virtual int MaxAcceleration()
{
return 0;
}
public virtual int MaxDeceleration()
{
return 0;
}
protected virtual byte[] GetChangeAccelerationPacket(int acceleration)
{
return new byte[] { reportId, 0x51, 0x31, 0x07, 0x00, (byte)acceleration };
}
protected virtual byte[] GetChangeDecelerationPacket(int deceleration)
{
return new byte[] { reportId, 0x51, 0x31, 0x08, 0x00, (byte)deceleration };
}
public virtual void SetAcceleration(int acceleration)
{
if (!HasAcceleration())
{
return;
}
if (acceleration > MaxAcceleration() || acceleration < 0)
{
Logger.WriteLine(GetDisplayName() + ": Acceleration " + acceleration + " is invalid.");
return;
}
WriteForResponse(GetChangeAccelerationPacket(acceleration));
FlushSettings();
Logger.WriteLine(GetDisplayName() + ": Acceleration set to " + acceleration);
this.Acceleration = acceleration;
}
public virtual void SetDeceleration(int deceleration)
{
if (!HasDeceleration())
{
return;
}
if (deceleration > MaxDeceleration() || deceleration < 0)
{
Logger.WriteLine(GetDisplayName() + ": Deceleration " + deceleration + " is invalid.");
return;
}
WriteForResponse(GetChangeDecelerationPacket(deceleration));
FlushSettings();
Logger.WriteLine(GetDisplayName() + ": Deceleration set to " + deceleration);
this.Deceleration = deceleration;
}
protected virtual byte[] GetReadAccelerationPacket()
{
return new byte[] { reportId, 0x12, 0x04, 0x01 };
}
protected virtual int ParseAcceleration(byte[] packet)
{
if (packet[1] != 0x12 || packet[2] != 0x04 || packet[3] != 0x01)
{
return 0;
}
return packet[5];
}
protected virtual int ParseDeceleration(byte[] packet)
{
if (packet[1] != 0x12 || packet[2] != 0x04 || packet[3] != 0x01)
{
return 0;
}
return packet[7];
}
public virtual void ReadAcceleration()
{
if (!HasAcceleration() && !HasDeceleration())
{
return;
}
byte[]? response = WriteForResponse(GetReadAccelerationPacket());
if (response is null) return;
if (HasAcceleration())
{
Acceleration = ParseAcceleration(response);
Logger.WriteLine(GetDisplayName() + ": Read Acceleration: " + Acceleration);
}
if (HasDeceleration())
{
Deceleration = ParseDeceleration(response);
Logger.WriteLine(GetDisplayName() + ": Read Deceleration: " + Deceleration);
}
}
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// DPI // DPI
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
@@ -826,12 +983,12 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetChangeDPIProfilePacket(int profile) protected virtual byte[] GetChangeDPIProfilePacket(int profile)
{ {
return new byte[] { 0x00, 0x51, 0x31, 0x0A, 0x00, (byte)profile }; return new byte[] { reportId, 0x51, 0x31, 0x0A, 0x00, (byte)profile };
} }
protected virtual byte[] GetChangeDPIProfilePacket2(int profile) protected virtual byte[] GetChangeDPIProfilePacket2(int profile)
{ {
return new byte[] { 0x00, 0x51, 0x31, 0x09, 0x00, (byte)profile }; return new byte[] { reportId, 0x51, 0x31, 0x09, 0x00, (byte)profile };
} }
//profiles start to count at 1 //profiles start to count at 1
@@ -863,10 +1020,10 @@ namespace GHelper.Peripherals.Mouse
{ {
if (!HasXYDPI()) if (!HasXYDPI())
{ {
return new byte[] { 0x00, 0x12, 0x04, 0x00 }; return new byte[] { reportId, 0x12, 0x04, 0x00 };
} }
return new byte[] { 0x00, 0x12, 0x04, 0x02 }; return new byte[] { reportId, 0x12, 0x04, 0x02 };
} }
protected virtual byte[]? GetUpdateDPIPacket(AsusMouseDPI dpi, int profile) protected virtual byte[]? GetUpdateDPIPacket(AsusMouseDPI dpi, int profile)
@@ -883,11 +1040,11 @@ namespace GHelper.Peripherals.Mouse
if (HasDPIColors()) if (HasDPIColors())
{ {
return new byte[] { 0x00, 0x51, 0x31, (byte)(profile - 1), 0x00, (byte)(dpiEncoded & 0xFF), (byte)((dpiEncoded >> 8) & 0xFF), dpi.Color.R, dpi.Color.G, dpi.Color.B }; return new byte[] { reportId, 0x51, 0x31, (byte)(profile - 1), 0x00, (byte)(dpiEncoded & 0xFF), (byte)((dpiEncoded >> 8) & 0xFF), dpi.Color.R, dpi.Color.G, dpi.Color.B };
} }
else else
{ {
return new byte[] { 0x00, 0x51, 0x31, (byte)(profile - 1), 0x00, (byte)(dpiEncoded & 0xFF), (byte)((dpiEncoded >> 8) & 0xFF) }; return new byte[] { reportId, 0x51, 0x31, (byte)(profile - 1), 0x00, (byte)(dpiEncoded & 0xFF), (byte)((dpiEncoded >> 8) & 0xFF) };
} }
} }
@@ -918,7 +1075,7 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetReadDPIColorsPacket() protected virtual byte[] GetReadDPIColorsPacket()
{ {
return new byte[] { 0x00, 0x12, 0x04, 0x03 }; return new byte[] { reportId, 0x12, 0x04, 0x03 };
} }
protected virtual void ParseDPIColors(byte[] packet) protected virtual void ParseDPIColors(byte[] packet)
@@ -996,13 +1153,13 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetReadLiftOffDistancePacket() protected virtual byte[] GetReadLiftOffDistancePacket()
{ {
return new byte[] { 0x00, 0x12, 0x06 }; return new byte[] { reportId, 0x12, 0x06 };
} }
//This also resets the "calibration" to default. There is no seperate command to only set the lift off distance //This also resets the "calibration" to default. There is no seperate command to only set the lift off distance
protected virtual byte[] GetUpdateLiftOffDistancePacket(LiftOffDistance liftOffDistance) protected virtual byte[] GetUpdateLiftOffDistancePacket(LiftOffDistance liftOffDistance)
{ {
return new byte[] { 0x00, 0x51, 0x35, 0xFF, 0x00, 0xFF, ((byte)liftOffDistance) }; return new byte[] { reportId, 0x51, 0x35, 0xFF, 0x00, 0xFF, ((byte)liftOffDistance) };
} }
protected virtual LiftOffDistance ParseLiftOffDistance(byte[] packet) protected virtual LiftOffDistance ParseLiftOffDistance(byte[] packet)
@@ -1071,13 +1228,13 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetReadDebouncePacket() protected virtual byte[] GetReadDebouncePacket()
{ {
return new byte[] { 0x00, 0x12, 0x04, 0x00 }; return new byte[] { reportId, 0x12, 0x04, 0x00 };
} }
protected virtual byte[] GetUpdateDebouncePacket(DebounceTime debounce) protected virtual byte[] GetUpdateDebouncePacket(DebounceTime debounce)
{ {
return new byte[] { 0x00, 0x51, 0x31, 0x05, 0x00, ((byte)debounce) }; return new byte[] { reportId, 0x51, 0x31, 0x05, 0x00, ((byte)debounce) };
} }
protected virtual DebounceTime ParseDebounce(byte[] packet) protected virtual DebounceTime ParseDebounce(byte[] packet)
@@ -1261,7 +1418,7 @@ namespace GHelper.Peripherals.Mouse
idx = IndexForZone(zone); idx = IndexForZone(zone);
} }
return new byte[] { 0x00, 0x12, 0x03, (byte)idx }; return new byte[] { reportId, 0x12, 0x03, (byte)idx };
} }
protected virtual byte[] GetUpdateLightingModePacket(LightingSetting lightingSetting, LightingZone zone) protected virtual byte[] GetUpdateLightingModePacket(LightingSetting lightingSetting, LightingZone zone)
@@ -1279,7 +1436,7 @@ namespace GHelper.Peripherals.Mouse
lightingSetting.LightingMode = LightingMode.ColorCycle; lightingSetting.LightingMode = LightingMode.ColorCycle;
} }
return new byte[] { 0x00, 0x51, 0x28, (byte)zone, 0x00, return new byte[] { reportId, 0x51, 0x28, (byte)zone, 0x00,
IndexForLightingMode(lightingSetting.LightingMode), IndexForLightingMode(lightingSetting.LightingMode),
(byte)lightingSetting.Brightness, (byte)lightingSetting.Brightness,
lightingSetting.RGBColor.R, lightingSetting.RGBColor.G, lightingSetting.RGBColor.B, lightingSetting.RGBColor.R, lightingSetting.RGBColor.G, lightingSetting.RGBColor.B,
@@ -1375,7 +1532,7 @@ namespace GHelper.Peripherals.Mouse
protected virtual byte[] GetSaveProfilePacket() protected virtual byte[] GetSaveProfilePacket()
{ {
return new byte[] { 0x00, 0x50, 0x03 }; return new byte[] { reportId, 0x50, 0x03 };
} }
public void FlushSettings() public void FlushSettings()

View File

@@ -60,6 +60,15 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Acceleration.
/// </summary>
internal static string Acceleration {
get {
return ResourceManager.GetString("Acceleration", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Can&apos;t connect to ASUS ACPI. Application can&apos;t function without it. Try to install Asus System Control Interface. /// Looks up a localized string similar to Can&apos;t connect to ASUS ACPI. Application can&apos;t function without it. Try to install Asus System Control Interface.
/// </summary> /// </summary>
@@ -537,6 +546,15 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Deceleration.
/// </summary>
internal static string Deceleration {
get {
return ResourceManager.GetString("Deceleration", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Default. /// Looks up a localized string similar to Default.
/// </summary> /// </summary>

View File

@@ -117,6 +117,9 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="Acceleration" xml:space="preserve">
<value>Acceleration</value>
</data>
<data name="ACPIError" xml:space="preserve"> <data name="ACPIError" xml:space="preserve">
<value>Can't connect to ASUS ACPI. Application can't function without it. Try to install Asus System Control Interface</value> <value>Can't connect to ASUS ACPI. Application can't function without it. Try to install Asus System Control Interface</value>
</data> </data>
@@ -276,6 +279,9 @@
<data name="Custom" xml:space="preserve"> <data name="Custom" xml:space="preserve">
<value>Custom</value> <value>Custom</value>
</data> </data>
<data name="Deceleration" xml:space="preserve">
<value>Deceleration</value>
</data>
<data name="Default" xml:space="preserve"> <data name="Default" xml:space="preserve">
<value>Default</value> <value>Default</value>
</data> </data>