Polling rates are fixed index numbers for all mice. 0 is immer 125Hz for example, if the mouse, like the Ckakram, do not support 125Hz, the first valid polling rate is 250Hz = 1.

This commit is contained in:
IceStormNG
2023-07-24 14:14:09 +02:00
parent 217074c640
commit 3b5cfe958d
4 changed files with 78 additions and 26 deletions

View File

@@ -105,7 +105,7 @@ namespace GHelper
private void ComboBoxPollingRate_DropDownClosed(object? sender, EventArgs e) private void ComboBoxPollingRate_DropDownClosed(object? sender, EventArgs e)
{ {
mouse.SetPollingRate(comboBoxPollingRate.SelectedIndex + 1); mouse.SetPollingRate(mouse.SupportedPollingrates()[comboBoxPollingRate.SelectedIndex]);
} }
private void ButtonDPIColor_Click(object? sender, EventArgs e) private void ButtonDPIColor_Click(object? sender, EventArgs e)
@@ -337,7 +337,11 @@ namespace GHelper
if (mouse.CanSetPollingRate()) if (mouse.CanSetPollingRate())
{ {
comboBoxPollingRate.Items.AddRange(mouse.PollingRateDisplayStrings()); foreach(PollingRate pr in mouse.SupportedPollingrates())
{
comboBoxPollingRate.Items.Add(mouse.PollingRateDisplayString(pr));
}
} }
else else
{ {
@@ -433,7 +437,12 @@ namespace GHelper
if (mouse.CanSetPollingRate()) if (mouse.CanSetPollingRate())
{ {
comboBoxPollingRate.SelectedIndex = mouse.PollingRate - 1; int idx = mouse.PollingRateIndex(mouse.PollingRate);
if(idx == -1)
{
return;
}
comboBoxPollingRate.SelectedIndex = idx;
} }
if (mouse.HasAngleSnapping()) if (mouse.HasAngleSnapping())

View File

@@ -15,6 +15,18 @@ namespace GHelper.Peripherals.Mouse
Never = 0xFF Never = 0xFF
} }
public enum PollingRate
{
PR125Hz = 0,
PR250Hz = 1,
PR500Hz = 2,
PR1000Hz = 3,
PR2000Hz = 4,
PR4000Hz = 5,
PR8000Hz = 6,
PR16000Hz = 7 //for whenever that gets supported lol
}
public enum LiftOffDistance public enum LiftOffDistance
{ {
Low = 0, Low = 0,
@@ -88,6 +100,8 @@ namespace GHelper.Peripherals.Mouse
public abstract class AsusMouse : Device, IPeripheral public abstract class AsusMouse : Device, IPeripheral
{ {
private static string[] POLLING_RATES = { "125 Hz", "250 Hz", "500 Hz", "1000 Hz", "2000 Hz", "4000 Hz", "8000 Hz", "16000 Hz" };
internal const int ASUS_MOUSE_PACKET_SIZE = 65; internal const int ASUS_MOUSE_PACKET_SIZE = 65;
public event EventHandler? Disconnect; public event EventHandler? Disconnect;
@@ -106,7 +120,7 @@ namespace GHelper.Peripherals.Mouse
public int DpiProfile { get; protected set; } public int DpiProfile { get; protected set; }
public AsusMouseDPI[] DpiSettings { get; protected set; } public AsusMouseDPI[] DpiSettings { get; protected set; }
public int Profile { get; protected set; } public int Profile { get; protected set; }
public int PollingRate { get; protected set; } public PollingRate PollingRate { get; protected set; }
public bool AngleSnapping { get; protected set; } public bool AngleSnapping { get; protected set; }
public short AngleAdjustmentDegrees { get; protected set; } public short AngleAdjustmentDegrees { get; protected set; }
@@ -453,17 +467,35 @@ namespace GHelper.Peripherals.Mouse
return false; return false;
} }
public virtual string PollingRateDisplayString(int pollingRate) public virtual string PollingRateDisplayString(PollingRate pollingRate)
{ {
return PollingRateDisplayStrings()[pollingRate -1]; return POLLING_RATES[(int)pollingRate];
} }
public virtual int PollingRateCount() public virtual int PollingRateCount()
{ {
return PollingRateDisplayStrings().Length; return SupportedPollingrates().Length;
} }
public abstract string[] PollingRateDisplayStrings(); public virtual int PollingRateIndex(PollingRate pollingRate)
{
for (int i = 0; i < PollingRateCount(); ++i)
{
if (SupportedPollingrates()[i] == pollingRate)
{
return i;
}
}
return -1;
}
public virtual bool IsPollingRateSupported(PollingRate pollingRate)
{
return SupportedPollingrates().Contains(pollingRate);
}
public abstract PollingRate[] SupportedPollingrates();
public virtual bool CanSetPollingRate() public virtual bool CanSetPollingRate()
{ {
@@ -475,7 +507,7 @@ namespace GHelper.Peripherals.Mouse
return new byte[] { 0x00, 0x12, 0x04, 0x00 }; return new byte[] { 0x00, 0x12, 0x04, 0x00 };
} }
protected virtual byte[] GetUpdatePollingRatePacket(int pollingRate) protected virtual byte[] GetUpdatePollingRatePacket(PollingRate pollingRate)
{ {
return new byte[] { 0x00, 0x51, 0x31, 0x04, 0x00, (byte)pollingRate }; return new byte[] { 0x00, 0x51, 0x31, 0x04, 0x00, (byte)pollingRate };
} }
@@ -488,14 +520,14 @@ namespace GHelper.Peripherals.Mouse
return new byte[] { 0x00, 0x51, 0x31, 0x0B, 0x00, (byte)(angleAdjustment & 0xFF), (byte)((angleAdjustment >> 8) & 0xFF) }; return new byte[] { 0x00, 0x51, 0x31, 0x0B, 0x00, (byte)(angleAdjustment & 0xFF), (byte)((angleAdjustment >> 8) & 0xFF) };
} }
protected virtual int ParsePollingRate(byte[] packet) protected virtual PollingRate ParsePollingRate(byte[] packet)
{ {
if (packet[1] == 0x12 && packet[2] == 0x04 && packet[3] == 0x00) if (packet[1] == 0x12 && packet[2] == 0x04 && packet[3] == 0x00)
{ {
return packet[13]; return (PollingRate)packet[13];
} }
return -1; return PollingRate.PR125Hz;
} }
protected virtual bool ParseAngleSnapping(byte[] packet) protected virtual bool ParseAngleSnapping(byte[] packet)
@@ -539,16 +571,16 @@ namespace GHelper.Peripherals.Mouse
} }
} }
public void SetPollingRate(int pollingRate) public void SetPollingRate(PollingRate pollingRate)
{ {
if (!CanSetPollingRate()) if (!CanSetPollingRate())
{ {
return; return;
} }
if (pollingRate > PollingRateCount() || pollingRate < 1) if (!IsPollingRateSupported(pollingRate))
{ {
Logger.WriteLine(GetDisplayName() + ": Pollingrate:" + pollingRate + " is invalid."); Logger.WriteLine(GetDisplayName() + ": Pollingrate:" + pollingRate + " is not supported by this mouse.");
return; return;
} }

View File

@@ -3,8 +3,6 @@ namespace GHelper.Peripherals.Mouse.Models
{ {
public class ChakramX : AsusMouse public class ChakramX : AsusMouse
{ {
private static string[] POLLING_RATES = { "250Hz", "500Hz", "1000Hz" };
public ChakramX() : base(0x0B05, 0x1A1A, "mi_00", true) public ChakramX() : base(0x0B05, 0x1A1A, "mi_00", true)
{ {
} }
@@ -18,9 +16,13 @@ namespace GHelper.Peripherals.Mouse.Models
return "ROG Chakram X (Wireless)"; return "ROG Chakram X (Wireless)";
} }
public override string[] PollingRateDisplayStrings() public override PollingRate[] SupportedPollingrates()
{ {
return POLLING_RATES; return new PollingRate[] {
PollingRate.PR250Hz,
PollingRate.PR500Hz,
PollingRate.PR1000Hz
};
} }
public override bool HasAngleSnapping() public override bool HasAngleSnapping()
@@ -62,7 +64,6 @@ namespace GHelper.Peripherals.Mouse.Models
public class ChakramXWired : ChakramX public class ChakramXWired : ChakramX
{ {
private static string[] POLLING_RATES = { "250Hz", "500Hz", "1000Hz", "2000Hz", "4000Hz", "8000Hz" };
public ChakramXWired() : base(0x1A18, false) public ChakramXWired() : base(0x1A18, false)
{ {
} }
@@ -72,9 +73,16 @@ namespace GHelper.Peripherals.Mouse.Models
return "ROG Chakram X (Wired)"; return "ROG Chakram X (Wired)";
} }
public override string[] PollingRateDisplayStrings() public override PollingRate[] SupportedPollingrates()
{ {
return POLLING_RATES; return new PollingRate[] {
PollingRate.PR250Hz,
PollingRate.PR500Hz,
PollingRate.PR1000Hz,
PollingRate.PR2000Hz,
PollingRate.PR4000Hz,
PollingRate.PR8000Hz
};
} }
} }
} }

View File

@@ -2,8 +2,6 @@
{ {
public class P711 : AsusMouse public class P711 : AsusMouse
{ {
private static string[] POLLING_RATES = { "125Hz", "250Hz", "500Hz", "1000Hz" };
public P711() : base(0x0B05, 0x1A70, "mi_01", true) public P711() : base(0x0B05, 0x1A70, "mi_01", true)
{ {
} }
@@ -23,9 +21,14 @@
} }
public override string[] PollingRateDisplayStrings() public override PollingRate[] SupportedPollingrates()
{ {
return POLLING_RATES; return new PollingRate[] {
PollingRate.PR125Hz,
PollingRate.PR250Hz,
PollingRate.PR500Hz,
PollingRate.PR1000Hz
};
} }
public override int ProfileCount() public override int ProfileCount()