Skip to content

Commit

Permalink
Merge pull request #38 from a1xd/1.2
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
a1xd authored Oct 26, 2020
2 parents 7d02822 + fa3a5f4 commit 1601eaf
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 80 deletions.
1 change: 1 addition & 0 deletions common/accel-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace rawaccel {
double weight = 1;
double scale_cap = 0;
double gain_cap = 0;
double speed_cap = 0;
};

template <typename Func>
Expand Down
4 changes: 3 additions & 1 deletion common/rawaccel-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include "accel-base.hpp"

namespace rawaccel {

using milliseconds = double;

inline constexpr int MAX_POLL_RATE_KHZ = 8;
inline constexpr milliseconds DEFAULT_TIME_MIN = 1.0 / MAX_POLL_RATE_KHZ * 0.8;
inline constexpr milliseconds WRITE_DELAY = 1000;
inline constexpr milliseconds DEFAULT_TIME_MIN = 0.4;

enum class accel_mode {
linear, classic, natural, naturalgain, power, motivity, noaccel
Expand Down
23 changes: 19 additions & 4 deletions common/rawaccel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,31 @@ namespace rawaccel {
accel_variant accel;
velocity_gain_cap gain_cap;
accel_scale_clamp clamp;
double output_speed_cap = 0;

accelerator(const accel_args& args, accel_mode mode, si_pair* lut = nullptr) :
accel(args, mode, lut), gain_cap(args.gain_cap, accel), clamp(args.scale_cap)
{}
{
output_speed_cap = maxsd(args.speed_cap, 0);
}

inline double apply(double speed) const {
double scale;

inline double apply(double speed) const {
if (gain_cap.should_apply(speed)) {
return clamp(gain_cap.apply(speed));
scale = gain_cap.apply(speed);
}
else {
scale = accel.apply(speed);
}
else return clamp(accel.apply(speed));

scale = clamp(scale);

if (output_speed_cap > 0 && (scale * speed) > output_speed_cap) {
scale = output_speed_cap / speed;
}

return scale;
}

accelerator() = default;
Expand Down
20 changes: 16 additions & 4 deletions grapher/Form1.Designer.cs

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

1 change: 1 addition & 0 deletions grapher/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public RawAcceleration()
legacyCapToolStripMenuItem,
gainOffsetToolStripMenuItem,
legacyOffsetToolStripMenuItem,
AutoWriteMenuItem,
ScaleMenuItem,
DPITextBox,
PollRateTextBox,
Expand Down
99 changes: 47 additions & 52 deletions grapher/Models/AccelGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ public AccelGUI(
ToggleButton = (CheckBox)toggleButton;
ScaleMenuItem = scaleMenuItem;
Settings = settings;
Settings.Startup();
RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings);
AccelForm.DoResize();

DefaultButtonFont = WriteButton.Font;
SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor);

MouseWatcher = mouseWatcher;

ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick);
Expand All @@ -50,9 +45,30 @@ public AccelGUI(
ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs);
ButtonTimer = new Timer();
ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick);
SetupButtons();

ChartRefresh = SetupChartTimer();

bool settingsActive = Settings.Startup();
SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent();

if (settingsActive)
{
LastToggleChecked = SettingsNotDefault;
ToggleButton.Enabled = LastToggleChecked;
RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings);
}
else
{
DriverSettings active = DriverInterop.GetActiveSettings();
bool activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active);

LastToggleChecked = activeNotDefault;
ToggleButton.Enabled = SettingsNotDefault || activeNotDefault;
RefreshOnRead(active);
}

SetupButtons();
AccelForm.DoResize();
}

#endregion Constructors
Expand Down Expand Up @@ -109,6 +125,10 @@ public void UpdateActiveSettingsFromFields()
{
var driverSettings = Settings.RawAccelSettings.AccelerationSettings;

var newArgs = ApplyOptions.GetArgs();
newArgs.x.speedCap = driverSettings.args.x.speedCap;
newArgs.y.speedCap = driverSettings.args.y.speedCap;

var settings = new DriverSettings
{
rotation = ApplyOptions.Rotation.Field.Data,
Expand All @@ -119,15 +139,16 @@ public void UpdateActiveSettingsFromFields()
},
combineMagnitudes = ApplyOptions.IsWhole,
modes = ApplyOptions.GetModes(),
args = ApplyOptions.GetArgs(),
args = newArgs,
minimumTime = driverSettings.minimumTime
};

WriteButtonDelay();
ButtonDelay(WriteButton);
SettingsErrors errors = Settings.TryUpdateActiveSettings(settings);
if (errors.Empty())
{
RefreshToggleStateFromNewSettings();
SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent();
LastToggleChecked = SettingsNotDefault;
RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings);
}
else
Expand Down Expand Up @@ -176,34 +197,23 @@ private void SetupButtons()
ToggleButton.Size = WriteButton.Size;
ToggleButton.Top = WriteButton.Top;

RefreshToggleStateFromNewSettings();
SetToggleButtonDefault();
SetWriteButtonDefault();
SetButtonDefaults();
}

private void RefreshToggleStateFromNewSettings()
private void SetButtonDefaults()
{
SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent();
LastToggleChecked = SettingsNotDefault;
}
ToggleButton.Checked = LastToggleChecked;

ToggleButton.Font = DefaultButtonFont;
ToggleButton.Text = ToggleButton.Checked ? "Enabled" : "Disabled";
ToggleButton.Update();

private void SetWriteButtonDefault()
{
WriteButton.Font = DefaultButtonFont;
WriteButton.Text = Constants.WriteButtonDefaultText;
WriteButton.Enabled = ToggleButton.Checked || !ToggleButton.Enabled;
WriteButton.Update();
}

private void SetToggleButtonDefault()
{
ToggleButton.Checked = LastToggleChecked;
ToggleButton.Enabled = SettingsNotDefault;
ToggleButton.Font = DefaultButtonFont;
ToggleButton.Text = ToggleButton.Checked ? "Enabled" : "Disabled";
ToggleButton.Update();
}

private void OnScaleMenuItemClick(object sender, EventArgs e)
{
UpdateGraph(Settings.RawAccelSettings.AccelerationSettings);
Expand All @@ -220,7 +230,8 @@ private void OnToggleButtonClick(object sender, EventArgs e)
Settings.RawAccelSettings.AccelerationSettings :
DriverInterop.DefaultSettings;

ToggleButtonDelay();
LastToggleChecked = ToggleButton.Checked;
ButtonDelay(ToggleButton);

SettingsManager.SendToDriver(settings);
Settings.ActiveAccel.UpdateFromSettings(settings);
Expand All @@ -230,8 +241,8 @@ private void OnToggleButtonClick(object sender, EventArgs e)
private void OnButtonTimerTick(object sender, EventArgs e)
{
ButtonTimer.Stop();
SetToggleButtonDefault();
SetWriteButtonDefault();
ToggleButton.Enabled = SettingsNotDefault;
SetButtonDefaults();
}

private void StartButtonTimer()
Expand All @@ -240,33 +251,17 @@ private void StartButtonTimer()
ButtonTimer.Start();
}

private void WriteButtonDelay()
private void ButtonDelay(ButtonBase btn)
{
WriteButton.Font = SmallButtonFont;
WriteButton.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms";
ToggleButton.Checked = false;

ToggleButton.Enabled = false;
WriteButton.Enabled = false;
WriteButton.Update();

if (ToggleButton.Enabled)
{
LastToggleChecked = ToggleButton.Checked;
ToggleButton.Checked = false;
ToggleButton.Enabled = false;
ToggleButton.Update();
}
StartButtonTimer();
}
btn.Font = SmallButtonFont;
btn.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms";

private void ToggleButtonDelay()
{
LastToggleChecked = ToggleButton.Checked;
ToggleButton.Checked = false;
ToggleButton.Enabled = false;
ToggleButton.Font = SmallButtonFont;
ToggleButton.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms";
ToggleButton.Update();

WriteButton.Enabled = false;
WriteButton.Update();

StartButtonTimer();
Expand Down
2 changes: 2 additions & 0 deletions grapher/Models/AccelGUIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static AccelGUI Construct(
ToolStripMenuItem legacyCapToolStripMenuItem,
ToolStripMenuItem gainOffsetToolStripMenuItem,
ToolStripMenuItem legacyOffsetToolStripMenuItem,
ToolStripMenuItem autoWriteMenuItem,
ToolStripMenuItem scaleMenuItem,
ToolStripTextBox dpiTextBox,
ToolStripTextBox pollRateTextBox,
Expand Down Expand Up @@ -326,6 +327,7 @@ public static AccelGUI Construct(
activeAccel,
accelCalculator.DPI,
accelCalculator.PollRate,
autoWriteMenuItem,
showLastMouseMoveMenuItem,
showVelocityGainToolStripMenuItem);

Expand Down
3 changes: 2 additions & 1 deletion grapher/Models/Options/ActiveValueLabelXY.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public void AlignActiveValues()
private void Align (int width)
{
FullWidth = width;
ShortenedWidth = FullWidth / 2;
// ShortenedWidth = FullWidth / 2;
ShortenedWidth = FullWidth;

SetYLeft();
Y.Width = ShortenedWidth;
Expand Down
10 changes: 8 additions & 2 deletions grapher/Models/Serialized/GUISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace grapher.Models.Serialized
{
[Serializable]
[JsonObject(ItemRequired = Required.Always)]
public class GUISettings
{
#region Constructors
Expand All @@ -27,6 +28,9 @@ public GUISettings() {}
[JsonProperty(Order = 4)]
public bool ShowVelocityAndGain { get; set; }

[JsonProperty(Order = 5)]
public bool AutoWriteToDriverOnStartup { get; set; }

#endregion Properties

#region Methods
Expand All @@ -48,15 +52,17 @@ public bool Equals(GUISettings other)
return DPI == other.DPI &&
PollRate == other.PollRate &&
ShowLastMouseMove == other.ShowLastMouseMove &&
ShowVelocityAndGain == other.ShowVelocityAndGain;
ShowVelocityAndGain == other.ShowVelocityAndGain &&
AutoWriteToDriverOnStartup == other.AutoWriteToDriverOnStartup;
}

public override int GetHashCode()
{
return DPI.GetHashCode() ^
PollRate.GetHashCode() ^
ShowLastMouseMove.GetHashCode() ^
ShowVelocityAndGain.GetHashCode();
ShowVelocityAndGain.GetHashCode() ^
AutoWriteToDriverOnStartup.GetHashCode();
}

#endregion Methods
Expand Down
Loading

0 comments on commit 1601eaf

Please sign in to comment.