diff --git a/app/AsusMouseSettings.Designer.cs b/app/AsusMouseSettings.Designer.cs index d26fe3b4..e6a4f5a6 100644 --- a/app/AsusMouseSettings.Designer.cs +++ b/app/AsusMouseSettings.Designer.cs @@ -33,6 +33,14 @@ labelProfile = new Label(); panelPerformance = 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(); labelLiftOffDistance = new Label(); comboBoxLiftOffDistance = new UI.RComboBox(); @@ -108,6 +116,8 @@ panelProfiles.SuspendLayout(); panelPerformance.SuspendLayout(); panelPerformanceOther.SuspendLayout(); + panelDeceleration.SuspendLayout(); + panelAcceleration.SuspendLayout(); panelLiftOffDistance.SuspendLayout(); panelDebounce.SuspendLayout(); panelAngleSnapping.SuspendLayout(); @@ -182,13 +192,15 @@ panelPerformance.Location = new Point(11, 68); panelPerformance.Name = "panelPerformance"; panelPerformance.Padding = new Padding(0, 11, 0, 25); - panelPerformance.Size = new Size(654, 461); + panelPerformance.Size = new Size(654, 555); panelPerformance.TabIndex = 1; // // panelPerformanceOther // panelPerformanceOther.AutoSize = true; panelPerformanceOther.AutoSizeMode = AutoSizeMode.GrowAndShrink; + panelPerformanceOther.Controls.Add(panelDeceleration); + panelPerformanceOther.Controls.Add(panelAcceleration); panelPerformanceOther.Controls.Add(panelLiftOffDistance); panelPerformanceOther.Controls.Add(panelDebounce); panelPerformanceOther.Controls.Add(panelAngleSnapping); @@ -197,9 +209,103 @@ panelPerformanceOther.Location = new Point(0, 240); panelPerformanceOther.Name = "panelPerformanceOther"; panelPerformanceOther.Padding = new Padding(0, 11, 0, 11); - panelPerformanceOther.Size = new Size(654, 196); + panelPerformanceOther.Size = new Size(654, 290); 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.AutoSize = true; @@ -656,7 +762,7 @@ panelLighting.Controls.Add(panelLightingContent); panelLighting.Controls.Add(panelLightingHeader); panelLighting.Dock = DockStyle.Top; - panelLighting.Location = new Point(11, 529); + panelLighting.Location = new Point(11, 623); panelLighting.Name = "panelLighting"; panelLighting.Padding = new Padding(0, 0, 0, 25); panelLighting.Size = new Size(654, 329); @@ -985,7 +1091,7 @@ panelEnergy.Controls.Add(labelAutoPowerOff); panelEnergy.Controls.Add(panelEnergyHeader); panelEnergy.Dock = DockStyle.Top; - panelEnergy.Location = new Point(11, 858); + panelEnergy.Location = new Point(11, 952); panelEnergy.Name = "panelEnergy"; panelEnergy.Padding = new Padding(0, 0, 0, 25); panelEnergy.Size = new Size(654, 143); @@ -1166,7 +1272,7 @@ panelBottomButtons.AutoSizeMode = AutoSizeMode.GrowAndShrink; panelBottomButtons.Controls.Add(buttonSync); panelBottomButtons.Dock = DockStyle.Top; - panelBottomButtons.Location = new Point(11, 1001); + panelBottomButtons.Location = new Point(11, 1095); panelBottomButtons.Name = "panelBottomButtons"; panelBottomButtons.Size = new Size(654, 67); panelBottomButtons.TabIndex = 47; @@ -1260,6 +1366,8 @@ panelPerformance.PerformLayout(); panelPerformanceOther.ResumeLayout(false); panelPerformanceOther.PerformLayout(); + panelDeceleration.ResumeLayout(false); + panelAcceleration.ResumeLayout(false); panelLiftOffDistance.ResumeLayout(false); panelDebounce.ResumeLayout(false); panelAngleSnapping.ResumeLayout(false); @@ -1379,5 +1487,13 @@ private Panel panelAngleSnapping; private Panel panelLiftOffDistance; 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; } } \ No newline at end of file diff --git a/app/AsusMouseSettings.cs b/app/AsusMouseSettings.cs index 3687b9be..62a9715b 100644 --- a/app/AsusMouseSettings.cs +++ b/app/AsusMouseSettings.cs @@ -46,6 +46,8 @@ namespace GHelper labelChargingState.Text = "(" + Properties.Strings.Charging + ")"; labelProfile.Text = Properties.Strings.Profile; labelButtonDebounce.Text = Properties.Strings.MouseButtonResponse; + labelAcceleration.Text = Properties.Strings.Acceleration; + labelDeceleration.Text = Properties.Strings.Deceleration; buttonLightingZoneLogo.Text = Properties.Strings.AuraZoneLogo; buttonLightingZoneScroll.Text = Properties.Strings.AuraZoneScroll; @@ -80,6 +82,12 @@ namespace GHelper sliderButtonDebounce.ValueChanged += SliderButtonDebounce_ValueChanged; sliderButtonDebounce.MouseUp += SliderButtonDebounce_MouseUp; + sliderAcceleration.MouseUp += SliderAcceleration_MouseUp; + sliderAcceleration.ValueChanged += SliderAcceleration_ValueChanged; + + sliderDeceleration.MouseUp += SliderDeceleration_MouseUp; + sliderDeceleration.ValueChanged += SliderDeceleration_ValueChanged; + buttonLightingColor.Click += ButtonLightingColor_Click; comboBoxLightingMode.DropDownClosed += ComboBoxLightingMode_DropDownClosed; sliderBrightness.MouseUp += SliderBrightness_MouseUp; @@ -103,6 +111,26 @@ namespace GHelper 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) { DebounceTime dbt = (DebounceTime)sliderButtonDebounce.Value; @@ -513,6 +541,24 @@ namespace GHelper 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()) { comboBoxLiftOffDistance.Items.AddRange(new string[] { @@ -681,6 +727,16 @@ namespace GHelper { sliderButtonDebounce.Value = (int)mouse.Debounce; } + + if (mouse.HasAcceleration()) + { + sliderAcceleration.Value = mouse.Acceleration; + } + + if (mouse.HasDeceleration()) + { + sliderDeceleration.Value = mouse.Deceleration; + } } private void VisualizeBatteryState() diff --git a/app/Peripherals/Mouse/AsusMouse.cs b/app/Peripherals/Mouse/AsusMouse.cs index 8e1ddbbb..cd6eae26 100644 --- a/app/Peripherals/Mouse/AsusMouse.cs +++ b/app/Peripherals/Mouse/AsusMouse.cs @@ -182,6 +182,8 @@ namespace GHelper.Peripherals.Mouse public bool AngleSnapping { get; protected set; } public short AngleAdjustmentDegrees { 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) @@ -420,6 +422,7 @@ namespace GHelper.Peripherals.Mouse ReadPollingRate(); ReadLiftOffDistance(); ReadDebounce(); + ReadAcceleration(); ReadLightingSetting(); } @@ -825,6 +828,125 @@ namespace GHelper.Peripherals.Mouse 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); + if (HasDeceleration()) Deceleration = ParseDeceleration(response); + + for (int i = 0; i < DPIProfileCount(); ++i) + { + Logger.WriteLine(GetDisplayName() + ": Read DPI Setting " + (i + 1) + ": " + DpiSettings[i].ToString()); + } + + } + + //TODO: Implement Acceleration Reading + // ------------------------------------------------------------------------------ // DPI // ------------------------------------------------------------------------------ diff --git a/app/Properties/Strings.Designer.cs b/app/Properties/Strings.Designer.cs index fc4656b1..a2a77ee5 100644 --- a/app/Properties/Strings.Designer.cs +++ b/app/Properties/Strings.Designer.cs @@ -60,6 +60,15 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized string similar to Acceleration. + /// + internal static string Acceleration { + get { + return ResourceManager.GetString("Acceleration", resourceCulture); + } + } + /// /// Looks up a localized string similar to Can't connect to ASUS ACPI. Application can't function without it. Try to install Asus System Control Interface. /// @@ -537,6 +546,15 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized string similar to Deceleration. + /// + internal static string Deceleration { + get { + return ResourceManager.GetString("Deceleration", resourceCulture); + } + } + /// /// Looks up a localized string similar to Default. /// diff --git a/app/Properties/Strings.resx b/app/Properties/Strings.resx index 4dcf8faf..5170a065 100644 --- a/app/Properties/Strings.resx +++ b/app/Properties/Strings.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Acceleration + Can't connect to ASUS ACPI. Application can't function without it. Try to install Asus System Control Interface @@ -276,6 +279,9 @@ Custom + + Deceleration + Default