diff options
| author | a1xd <[email protected]> | 2020-07-31 17:56:46 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-07-31 17:56:46 -0400 |
| commit | 1fcbb0fa51dbc35958d211026e4d40384a049049 (patch) | |
| tree | efb65bf3f305f376ea75f4f687b08bf8998c020f | |
| parent | Merge pull request #6 from a1xd/st-refactor (diff) | |
| parent | Show no settings for off, remove unused class for PR (diff) | |
| download | rawaccel-1fcbb0fa51dbc35958d211026e4d40384a049049.tar.xz rawaccel-1fcbb0fa51dbc35958d211026e4d40384a049049.zip | |
Merge pull request #7 from JacobPalecki/GUI
Add GUI
28 files changed, 1388 insertions, 75 deletions
diff --git a/console/console.cpp b/console/console.cpp index 490051c..549cb68 100644 --- a/console/console.cpp +++ b/console/console.cpp @@ -4,39 +4,7 @@ #include <Windows.h> #include <rawaccel-userspace.hpp> - -#define RA_WRITE CTL_CODE(0x8888, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS) - -namespace ra = rawaccel; - -void write(ra::mouse_modifier vars) { - HANDLE ra_handle = INVALID_HANDLE_VALUE; - - ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); - - if (ra_handle == INVALID_HANDLE_VALUE) { - throw std::system_error(GetLastError(), std::system_category(), "CreateFile failed"); - } - - DWORD dummy; - - BOOL success = DeviceIoControl( - ra_handle, - RA_WRITE, - &vars, - sizeof(ra::mouse_modifier), - NULL, // output buffer - 0, // output buffer size - &dummy, // bytes returned - NULL // overlapped structure - ); - - CloseHandle(ra_handle); - - if (!success) { - throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); - } -} +#include "console_write.hpp" int main(int argc, char** argv) { try { diff --git a/console/console.vcxproj b/console/console.vcxproj index d0ad292..05780cd 100644 --- a/console/console.vcxproj +++ b/console/console.vcxproj @@ -90,6 +90,8 @@ </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="console.cpp" /> + <ClCompile Include="console_write.cpp" /> + <ClCompile Include="console_write.hpp" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/console/console_write.cpp b/console/console_write.cpp new file mode 100644 index 0000000..3240ea5 --- /dev/null +++ b/console/console_write.cpp @@ -0,0 +1,32 @@ +#pragma once + +#include "console_write.hpp" + +void write(ra::mouse_modifier vars) { + HANDLE ra_handle = INVALID_HANDLE_VALUE; + + ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); + + if (ra_handle == INVALID_HANDLE_VALUE) { + throw std::system_error(GetLastError(), std::system_category(), "CreateFile failed"); + } + + DWORD dummy; + + BOOL success = DeviceIoControl( + ra_handle, + RA_WRITE, + &vars, + sizeof(ra::mouse_modifier), + NULL, // output buffer + 0, // output buffer size + &dummy, // bytes returned + NULL // overlapped structure + ); + + CloseHandle(ra_handle); + + if (!success) { + throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); + } +} diff --git a/console/console_write.hpp b/console/console_write.hpp new file mode 100644 index 0000000..31eb575 --- /dev/null +++ b/console/console_write.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include <iostream> + +#define NOMINMAX +#include <Windows.h> + +#include "..\common\rawaccel.hpp" + +#define RA_WRITE CTL_CODE(0x8888, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS) + +namespace ra = rawaccel; + +void write(ra::mouse_modifier vars);
\ No newline at end of file diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs new file mode 100644 index 0000000..b233552 --- /dev/null +++ b/grapher/AccelOptions.cs @@ -0,0 +1,79 @@ +using grapher.Layouts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public class AccelOptions + { + public const int PossibleOptionsCount = 4; + public const int PossibleOptionsXYCount = 2; + + public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase> + { + new DefaultLayout(), + new LinearLayout(), + new ClassicLayout(), + new NaturalLayout(), + new LogLayout(), + new SigmoidLayout(), + new PowerLayout(), + new OffLayout() + }.ToDictionary(k => k.Name); + + public AccelOptions( + ComboBox accelDropdown, + Option[] options, + OptionXY[] optionsXY, + Button writeButton) + { + AccelDropdown = accelDropdown; + AccelDropdown.Items.Clear(); + AccelDropdown.Items.AddRange(AccelerationTypes.Keys.Skip(1).ToArray()); + AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); + + if (options.Length > PossibleOptionsCount) + { + throw new Exception("Layout given too many options."); + } + + if (optionsXY.Length > PossibleOptionsXYCount) + { + throw new Exception("Layout given too many options."); + } + + Options = options; + OptionsXY = optionsXY; + WriteButton = writeButton; + + Layout("Default"); + } + + public Button WriteButton { get; } + + public ComboBox AccelDropdown { get; } + + public int AccelerationIndex { get; private set; } + + public Option[] Options { get; } + + public OptionXY[] OptionsXY { get; } + + private void OnIndexChanged(object sender, EventArgs e) + { + var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); + Layout(accelerationTypeString); + } + + private void Layout(string type) + { + var accelerationType = AccelerationTypes[type]; + AccelerationIndex = accelerationType.Index; + accelerationType.Layout(Options, OptionsXY, WriteButton); + } + } +} diff --git a/grapher/Field.cs b/grapher/Field.cs new file mode 100644 index 0000000..5ef057d --- /dev/null +++ b/grapher/Field.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public class Field + { + #region Enums + + public enum FieldState + { + Undefined, + Default, + Typing, + Entered, + Unavailable, + } + + #endregion Enums + + + #region Constructors + + public Field(TextBox box, Form containingForm, double defaultData) + { + DefaultText = DecimalString(defaultData); + Box = box; + Data = defaultData; + DefaultData = defaultData; + State = FieldState.Undefined; + ContainingForm = containingForm; + box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown); + box.Leave += new System.EventHandler(FocusLeave); + + SetToDefault(); + } + + #endregion Constructors + + #region Properties + + public TextBox Box { get; } + + private Form ContainingForm { get; } + + public double Data { get; private set; } + + public string DefaultText { get; } + + public FieldState State { get; private set; } + + public FieldState PreviousState { get; private set; } + + private double DefaultData { get; } + + #endregion Properties + + #region Methods + + public void SetToDefault() + { + if (State != FieldState.Default) + { + Box.BackColor = Color.White; + Box.ForeColor = Color.Gray; + State = FieldState.Default; + PreviousState = FieldState.Default; + } + + Data = DefaultData; + Box.Text = DefaultText; + ContainingForm.ActiveControl = null; + } + + public void SetToTyping() + { + if (State != FieldState.Typing) + { + Box.BackColor = Color.White; + Box.ForeColor = Color.Black; + + PreviousState = State; + State = FieldState.Typing; + } + + Box.Text = string.Empty; + } + + public void SetToEntered() + { + if (State != FieldState.Entered) + { + Box.BackColor = Color.AntiqueWhite; + Box.ForeColor = Color.DarkGray; + + PreviousState = State; + State = FieldState.Entered; + } + + ContainingForm.ActiveControl = null; + } + + public void SetToEntered(double value) + { + SetToEntered(); + + Data = value; + Box.Text = DecimalString(Data); + } + + public void SetToUnavailable() + { + if (State != FieldState.Unavailable) + { + Box.BackColor = Color.LightGray; + Box.ForeColor = Color.LightGray; + Box.Text = string.Empty; + + PreviousState = State; + State = FieldState.Unavailable; + } + } + + public void KeyDown(object sender, KeyEventArgs e) + { + switch(State) + { + case FieldState.Default: + if (e.KeyCode == Keys.Enter) + { + SetToDefault(); + } + else + { + SetToTyping(); + } + break; + + case FieldState.Entered: + if (e.KeyCode != Keys.Enter) + { + SetToTyping(); + } + break; + case FieldState.Typing: + HandleTyping(sender, e); + break; + case FieldState.Unavailable: + Box.Text = string.Empty; + ContainingForm.ActiveControl = null; + break; + default: + break; + } + } + + private void FocusLeave(object sender, EventArgs e) + { + if (State == FieldState.Typing) + { + if (PreviousState == FieldState.Default) + { + SetToDefault(); + } + else if (PreviousState == FieldState.Entered) + { + SetToEntered(); + Box.Text = DecimalString(Data); + } + } + } + + private void HandleTyping(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + try + { + Data = Convert.ToDouble(((TextBox)sender).Text); + } + catch + { + } + + Box.Text = DecimalString(Data); + e.Handled = true; + e.SuppressKeyPress = true; + + SetToEntered(); + } + else if (e.KeyCode == Keys.Escape) + { + ContainingForm.ActiveControl = null; + e.Handled = true; + e.SuppressKeyPress = true; + } + } + + private static string DecimalString(double value) + { + return value.ToString("N2"); + } + + #endregion Methods + } +} diff --git a/grapher/FieldXY.cs b/grapher/FieldXY.cs new file mode 100644 index 0000000..23c5de1 --- /dev/null +++ b/grapher/FieldXY.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public class FieldXY + { + public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData) + { + XField = new Field(xBox, containingForm, defaultData); + YField = new Field(yBox, containingForm, defaultData); + LockCheckBox = lockCheckBox; + LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); + SetLocked(); + } + public double X + { + get => XField.Data; + } + + public double Y + { + get + { + if (Locked) + { + return X; + } + else + { + return YField.Data; + } + } + } + + public CheckBox LockCheckBox { get; } + + public Field XField { get; } + + public Field YField { get; } + + private bool Locked { get; set; } + + private void CheckChanged(object sender, EventArgs e) + { + if (LockCheckBox.CheckState == CheckState.Checked) + { + SetLocked(); + } + else + { + SetUnlocked(); + } + } + + private void SetLocked() + { + Locked = true; + YField.SetToUnavailable(); + } + + private void SetUnlocked() + { + Locked = false; + if (XField.State == Field.FieldState.Default) + { + YField.SetToDefault(); + } + else + { + YField.SetToEntered(XField.Data); + } + } + } +} diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index b39c887..667abf1 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -1,4 +1,6 @@ -namespace grapher +using System.Linq; + +namespace grapher { partial class RawAcceleration { @@ -28,49 +30,341 @@ /// </summary> private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.accelTypeDrop = new System.Windows.Forms.ComboBox(); + this.sensitivityBoxX = new System.Windows.Forms.TextBox(); + this.sensitivityLabel = new System.Windows.Forms.Label(); + this.rotationBox = new System.Windows.Forms.TextBox(); + this.rotationLabel = new System.Windows.Forms.Label(); + this.accelerationBox = new System.Windows.Forms.TextBox(); + this.constantOneLabel = new System.Windows.Forms.Label(); + this.capBoxX = new System.Windows.Forms.TextBox(); + this.capLabel = new System.Windows.Forms.Label(); + this.weightBoxFirst = new System.Windows.Forms.TextBox(); + this.weightLabel = new System.Windows.Forms.Label(); + this.weightBoxSecond = new System.Windows.Forms.TextBox(); + this.limitBox = new System.Windows.Forms.TextBox(); + this.constantTwoLabel = new System.Windows.Forms.Label(); + this.midpointBox = new System.Windows.Forms.TextBox(); + this.constantThreeLabel = new System.Windows.Forms.Label(); + this.offsetBox = new System.Windows.Forms.TextBox(); + this.offsetLabel = new System.Windows.Forms.Label(); + this.writeButton = new System.Windows.Forms.Button(); + this.sensitivityBoxY = new System.Windows.Forms.TextBox(); + this.capBoxY = new System.Windows.Forms.TextBox(); + this.sensXYLock = new System.Windows.Forms.CheckBox(); + this.capXYLock = new System.Windows.Forms.CheckBox(); + this.weightXYLock = new System.Windows.Forms.CheckBox(); + this.LockXYLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); this.SuspendLayout(); // // AccelerationChart // - chartArea1.AxisX.Title = "Speed (counts/ms)"; - chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea1.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend1); - this.AccelerationChart.Location = new System.Drawing.Point(0, 0); + chartArea2.AxisX.Title = "Speed (counts/ms)"; + chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea2.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend2); + this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series1.ChartArea = "ChartArea1"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series1.Legend = "Legend1"; - series1.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series1); - this.AccelerationChart.Size = new System.Drawing.Size(800, 312); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series2); + this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; // + // accelTypeDrop + // + this.accelTypeDrop.FormattingEnabled = true; + this.accelTypeDrop.Location = new System.Drawing.Point(14, 89); + this.accelTypeDrop.Name = "accelTypeDrop"; + this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); + this.accelTypeDrop.TabIndex = 2; + this.accelTypeDrop.Text = "Acceleration Type"; + // + // sensitivityBoxX + // + this.sensitivityBoxX.Location = new System.Drawing.Point(95, 37); + this.sensitivityBoxX.Name = "sensitivityBoxX"; + this.sensitivityBoxX.Size = new System.Drawing.Size(32, 20); + this.sensitivityBoxX.TabIndex = 3; + // + // sensitivityLabel + // + this.sensitivityLabel.AutoSize = true; + this.sensitivityLabel.Location = new System.Drawing.Point(14, 40); + this.sensitivityLabel.Name = "sensitivityLabel"; + this.sensitivityLabel.Size = new System.Drawing.Size(54, 13); + this.sensitivityLabel.TabIndex = 4; + this.sensitivityLabel.Text = "Sensitivity"; + // + // rotationBox + // + this.rotationBox.Location = new System.Drawing.Point(95, 63); + this.rotationBox.Name = "rotationBox"; + this.rotationBox.Size = new System.Drawing.Size(70, 20); + this.rotationBox.TabIndex = 5; + // + // rotationLabel + // + this.rotationLabel.AutoSize = true; + this.rotationLabel.Location = new System.Drawing.Point(24, 66); + this.rotationLabel.Name = "rotationLabel"; + this.rotationLabel.Size = new System.Drawing.Size(47, 13); + this.rotationLabel.TabIndex = 6; + this.rotationLabel.Text = "Rotation"; + // + // accelerationBox + // + this.accelerationBox.Location = new System.Drawing.Point(96, 116); + this.accelerationBox.Name = "accelerationBox"; + this.accelerationBox.Size = new System.Drawing.Size(70, 20); + this.accelerationBox.TabIndex = 7; + // + // constantOneLabel + // + this.constantOneLabel.AutoSize = true; + this.constantOneLabel.Location = new System.Drawing.Point(14, 119); + this.constantOneLabel.Name = "constantOneLabel"; + this.constantOneLabel.Size = new System.Drawing.Size(66, 13); + this.constantOneLabel.TabIndex = 9; + this.constantOneLabel.Text = "Acceleration"; + this.constantOneLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // capBoxX + // + this.capBoxX.Location = new System.Drawing.Point(95, 142); + this.capBoxX.Name = "capBoxX"; + this.capBoxX.Size = new System.Drawing.Size(32, 20); + this.capBoxX.TabIndex = 10; + // + // capLabel + // + this.capLabel.AutoSize = true; + this.capLabel.Location = new System.Drawing.Point(24, 146); + this.capLabel.Name = "capLabel"; + this.capLabel.Size = new System.Drawing.Size(26, 13); + this.capLabel.TabIndex = 11; + this.capLabel.Text = "Cap"; + this.capLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // weightBoxFirst + // + this.weightBoxFirst.Location = new System.Drawing.Point(95, 168); + this.weightBoxFirst.Name = "weightBoxFirst"; + this.weightBoxFirst.Size = new System.Drawing.Size(32, 20); + this.weightBoxFirst.TabIndex = 12; + // + // weightLabel + // + this.weightLabel.AutoSize = true; + this.weightLabel.Location = new System.Drawing.Point(24, 171); + this.weightLabel.Name = "weightLabel"; + this.weightLabel.Size = new System.Drawing.Size(41, 13); + this.weightLabel.TabIndex = 13; + this.weightLabel.Text = "Weight"; + this.weightLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // weightBoxSecond + // + this.weightBoxSecond.Location = new System.Drawing.Point(134, 168); + this.weightBoxSecond.Name = "weightBoxSecond"; + this.weightBoxSecond.Size = new System.Drawing.Size(32, 20); + this.weightBoxSecond.TabIndex = 14; + // + // limitBox + // + this.limitBox.Location = new System.Drawing.Point(95, 220); + this.limitBox.Name = "limitBox"; + this.limitBox.Size = new System.Drawing.Size(70, 20); + this.limitBox.TabIndex = 15; + // + // constantTwoLabel + // + this.constantTwoLabel.AutoSize = true; + this.constantTwoLabel.Location = new System.Drawing.Point(14, 223); + this.constantTwoLabel.Name = "constantTwoLabel"; + this.constantTwoLabel.Size = new System.Drawing.Size(78, 13); + this.constantTwoLabel.TabIndex = 16; + this.constantTwoLabel.Text = "Limit/Exponent"; + this.constantTwoLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // midpointBox + // + this.midpointBox.Location = new System.Drawing.Point(95, 246); + this.midpointBox.Name = "midpointBox"; + this.midpointBox.Size = new System.Drawing.Size(70, 20); + this.midpointBox.TabIndex = 17; + // + // constantThreeLabel + // + this.constantThreeLabel.AutoSize = true; + this.constantThreeLabel.Location = new System.Drawing.Point(21, 249); + this.constantThreeLabel.Name = "constantThreeLabel"; + this.constantThreeLabel.Size = new System.Drawing.Size(47, 13); + this.constantThreeLabel.TabIndex = 18; + this.constantThreeLabel.Text = "Midpoint"; + this.constantThreeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // offsetBox + // + this.offsetBox.Location = new System.Drawing.Point(95, 194); + this.offsetBox.Name = "offsetBox"; + this.offsetBox.Size = new System.Drawing.Size(70, 20); + this.offsetBox.TabIndex = 19; + // + // offsetLabel + // + this.offsetLabel.AutoSize = true; + this.offsetLabel.Location = new System.Drawing.Point(24, 197); + this.offsetLabel.Name = "offsetLabel"; + this.offsetLabel.Size = new System.Drawing.Size(35, 13); + this.offsetLabel.TabIndex = 20; + this.offsetLabel.Text = "Offset"; + this.offsetLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // writeButton + // + this.writeButton.Location = new System.Drawing.Point(47, 272); + this.writeButton.Name = "writeButton"; + this.writeButton.Size = new System.Drawing.Size(102, 23); + this.writeButton.TabIndex = 21; + this.writeButton.Text = "Write To Driver"; + this.writeButton.UseVisualStyleBackColor = true; + this.writeButton.Click += new System.EventHandler(this.writeButton_Click); + // + // sensitivityBoxY + // + this.sensitivityBoxY.Location = new System.Drawing.Point(133, 37); + this.sensitivityBoxY.Name = "sensitivityBoxY"; + this.sensitivityBoxY.Size = new System.Drawing.Size(32, 20); + this.sensitivityBoxY.TabIndex = 22; + // + // capBoxY + // + this.capBoxY.Location = new System.Drawing.Point(135, 142); + this.capBoxY.Name = "capBoxY"; + this.capBoxY.Size = new System.Drawing.Size(31, 20); + this.capBoxY.TabIndex = 23; + // + // sensXYLock + // + this.sensXYLock.AutoSize = true; + this.sensXYLock.Checked = true; + this.sensXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.sensXYLock.Location = new System.Drawing.Point(188, 40); + this.sensXYLock.Name = "sensXYLock"; + this.sensXYLock.Size = new System.Drawing.Size(15, 14); + this.sensXYLock.TabIndex = 24; + this.sensXYLock.UseVisualStyleBackColor = true; + // + // capXYLock + // + this.capXYLock.AutoSize = true; + this.capXYLock.Checked = true; + this.capXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.capXYLock.Location = new System.Drawing.Point(188, 145); + this.capXYLock.Name = "capXYLock"; + this.capXYLock.Size = new System.Drawing.Size(15, 14); + this.capXYLock.TabIndex = 25; + this.capXYLock.UseVisualStyleBackColor = true; + // + // weightXYLock + // + this.weightXYLock.AutoSize = true; + this.weightXYLock.Checked = true; + this.weightXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.weightXYLock.Location = new System.Drawing.Point(188, 171); + this.weightXYLock.Name = "weightXYLock"; + this.weightXYLock.Size = new System.Drawing.Size(15, 14); + this.weightXYLock.TabIndex = 26; + this.weightXYLock.UseVisualStyleBackColor = true; + // + // LockXYLabel + // + this.LockXYLabel.AutoSize = true; + this.LockXYLabel.Location = new System.Drawing.Point(165, 21); + this.LockXYLabel.Name = "LockXYLabel"; + this.LockXYLabel.Size = new System.Drawing.Size(60, 13); + this.LockXYLabel.TabIndex = 27; + this.LockXYLabel.Text = "Lock X && Y"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 310); + this.ClientSize = new System.Drawing.Size(963, 312); + this.Controls.Add(this.LockXYLabel); + this.Controls.Add(this.weightXYLock); + this.Controls.Add(this.capXYLock); + this.Controls.Add(this.sensXYLock); + this.Controls.Add(this.capBoxY); + this.Controls.Add(this.sensitivityBoxY); + this.Controls.Add(this.writeButton); + this.Controls.Add(this.offsetLabel); + this.Controls.Add(this.offsetBox); + this.Controls.Add(this.constantThreeLabel); + this.Controls.Add(this.midpointBox); + this.Controls.Add(this.constantTwoLabel); + this.Controls.Add(this.limitBox); + this.Controls.Add(this.weightBoxSecond); + this.Controls.Add(this.weightLabel); + this.Controls.Add(this.weightBoxFirst); + this.Controls.Add(this.capLabel); + this.Controls.Add(this.capBoxX); + this.Controls.Add(this.constantOneLabel); + this.Controls.Add(this.accelerationBox); + this.Controls.Add(this.rotationLabel); + this.Controls.Add(this.rotationBox); + this.Controls.Add(this.sensitivityLabel); + this.Controls.Add(this.sensitivityBoxX); + this.Controls.Add(this.accelTypeDrop); this.Controls.Add(this.AccelerationChart); this.Name = "RawAcceleration"; this.Text = "Raw Acceleration Graph"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; + private System.Windows.Forms.ComboBox accelTypeDrop; + private System.Windows.Forms.TextBox sensitivityBoxX; + private System.Windows.Forms.Label sensitivityLabel; + private System.Windows.Forms.TextBox rotationBox; + private System.Windows.Forms.Label rotationLabel; + private System.Windows.Forms.TextBox accelerationBox; + private System.Windows.Forms.Label constantOneLabel; + private System.Windows.Forms.TextBox capBoxX; + private System.Windows.Forms.Label capLabel; + private System.Windows.Forms.TextBox weightBoxFirst; + private System.Windows.Forms.Label weightLabel; + private System.Windows.Forms.TextBox weightBoxSecond; + private System.Windows.Forms.TextBox limitBox; + private System.Windows.Forms.Label constantTwoLabel; + private System.Windows.Forms.TextBox midpointBox; + private System.Windows.Forms.Label constantThreeLabel; + private System.Windows.Forms.TextBox offsetBox; + private System.Windows.Forms.Label offsetLabel; + private System.Windows.Forms.Button writeButton; + private System.Windows.Forms.TextBox sensitivityBoxY; + private System.Windows.Forms.TextBox capBoxY; + private System.Windows.Forms.CheckBox sensXYLock; + private System.Windows.Forms.CheckBox capXYLock; + private System.Windows.Forms.CheckBox weightXYLock; + private System.Windows.Forms.Label LockXYLabel; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 47ef1d9..3807d2a 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Drawing; @@ -54,10 +55,20 @@ namespace grapher public partial class RawAcceleration : Form { + public struct MagnitudeData + { + public double magnitude; + public int x; + public int y; + } + + #region Constructor + + public static ReadOnlyCollection<MagnitudeData> Magnitudes = GetMagnitudes(); + public RawAcceleration() { InitializeComponent(); - modifier_args args; args.degrees = 0; @@ -79,38 +90,105 @@ namespace grapher IntPtr args_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(args)); Marshal.StructureToPtr(args, args_ptr, false); - var managedAccel = new ManagedAccel(args_ptr); + ManagedAcceleration = new ManagedAccel(args_ptr); Marshal.FreeHGlobal(args_ptr); - var orderedPoints = new SortedDictionary<double, double>(); + Sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity"); + Rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); + Weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight"); + Cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap"); + Offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); - for (int i = 0; i < 100; i++) - { - for (int j = 0; j <= i; j++) + // The name and layout of these options is handled by AccelerationOptions object. + Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); + LimitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); + Midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); + + AccelerationOptions = new AccelOptions( + accelTypeDrop, + new Option[] + { + Offset, + Acceleration, + LimitOrExponent, + Midpoint, + }, + new OptionXY[] { - var output = managedAccel.Accelerate(i, j, 1); + Weight, + Cap, + }, + writeButton); - var inMagnitude = Magnitude(i,j); - var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : 0; + UpdateGraph(); + + this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); - if (!orderedPoints.ContainsKey(inMagnitude)) - { - orderedPoints.Add(inMagnitude, ratio); - } - } - } + this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; - var series = this.AccelerationChart.Series.FirstOrDefault(); - series.Points.Clear(); + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; - foreach (var point in orderedPoints) + this.AccelerationChart.ChartAreas[0].CursorY.Interval = 0.001; + + this.AccelerationChart.ChartAreas[0].CursorX.AutoScroll = true; + this.AccelerationChart.ChartAreas[0].CursorY.AutoScroll = true; + + this.AccelerationChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + this.AccelerationChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + + this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; + this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; + } + + #endregion Constructor + + #region Properties + + public ManagedAccel ManagedAcceleration { get; set; } + + private AccelOptions AccelerationOptions { get; set; } + + private OptionXY Sensitivity { get; set; } + + private Option Rotation { get; set; } + + private OptionXY Weight { get; set; } + + private OptionXY Cap { get; set; } + + private Option Offset { get; set; } + + private Option Acceleration { get; set; } + + private Option LimitOrExponent { get; set; } + + private Option Midpoint { get; set; } + + #endregion Properties + + #region Methods + + public static ReadOnlyCollection<MagnitudeData> GetMagnitudes() + { + var magnitudes = new List<MagnitudeData>(); + for (int i = 0; i < 100; i++) { - series.Points.AddXY(point.Key, point.Value); + for (int j = 0; j <= i; j++) + { + MagnitudeData magnitudeData; + magnitudeData.magnitude = Magnitude(i, j); + magnitudeData.x = i; + magnitudeData.y = j; + magnitudes.Add(magnitudeData); + } } - this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); + magnitudes.Sort((m1, m2) => m1.magnitude.CompareTo(m2.magnitude)); + + return magnitudes.AsReadOnly(); } public static double Magnitude(int x, int y) @@ -127,5 +205,52 @@ namespace grapher { } + + private void UpdateGraph() + { + var orderedPoints = new SortedDictionary<double, double>(); + + foreach (var magnitudeData in Magnitudes) + { + var output = ManagedAcceleration.Accelerate(magnitudeData.x, magnitudeData.y, 1); + + var outMagnitude = Magnitude(output.Item1, output.Item2); + var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X; + + if (!orderedPoints.ContainsKey(magnitudeData.magnitude)) + { + orderedPoints.Add(magnitudeData.magnitude, ratio); + } + } + + var series = this.AccelerationChart.Series.FirstOrDefault(); + series.Points.Clear(); + + foreach (var point in orderedPoints) + { + series.Points.AddXY(point.Key, point.Value); + } + } + + private void writeButton_Click(object sender, EventArgs e) + { + ManagedAcceleration.UpdateAccel( + AccelerationOptions.AccelerationIndex, + Rotation.Field.Data, + Sensitivity.Fields.X, + Sensitivity.Fields.Y, + Weight.Fields.X, + Weight.Fields.Y, + Cap.Fields.X, + Cap.Fields.Y, + Offset.Field.Data, + Acceleration.Field.Data, + LimitOrExponent.Field.Data, + Midpoint.Field.Data); + ManagedAcceleration.WriteToDriver(); + UpdateGraph(); + } + + #endregion Methods } } diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs new file mode 100644 index 0000000..093f7fa --- /dev/null +++ b/grapher/Layouts/ClassicLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class ClassicLayout : LayoutBase + { + public ClassicLayout() + : base() + { + Name = "Classic"; + Index = 2; + ShowOptions = new bool[] { true, true, true, false }; + OptionNames = new string[] { Offset, Acceleration, Exponent, string.Empty }; + } + } +} diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs new file mode 100644 index 0000000..095afdf --- /dev/null +++ b/grapher/Layouts/DefaultLayout.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Layouts +{ + public class DefaultLayout : LayoutBase + { + public DefaultLayout() + : base() + { + Name = "Default"; + Index = 0; + ShowOptions = new bool[] { true, true, true, true }; + OptionNames = new string[] { Offset, Acceleration, $"{Limit}\\{Exponent}", Midpoint }; + ButtonEnabled = false; + } + } +} diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs new file mode 100644 index 0000000..a4d0827 --- /dev/null +++ b/grapher/Layouts/LayoutBase.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Layouts +{ + public abstract class LayoutBase + { + public const string Acceleration = "Acceleration"; + public const string Scale = "Scale"; + public const string Exponent = "Exponent"; + public const string Limit = "Limit"; + public const string Midpoint = "Midpoint"; + public const string Offset = "Offset"; + + public LayoutBase() + { + ShowOptions = new bool[] { false, false, false, false }; + ShowOptionsXY = new bool[] { true, true }; + OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty }; + ButtonEnabled = true; + } + + /// <summary> + /// Gets or sets mapping from acceleration type to identifying integer. + /// Must match order in tagged_union in rawaccel.hpp (which is 1-indexed, meaning 0 is off.) + /// </summary> + public int Index { get; internal set; } + + public string Name { get; internal set; } + + internal bool[] ShowOptions { get; set; } + + internal bool[] ShowOptionsXY { get; set; } + + internal string[] OptionNames { get; set; } + + internal bool ButtonEnabled { get; set; } + + public void Layout(Option[] options, OptionXY[] optionsXY, Button button) + { + // Relies on AccelOptions to keep lengths correct. + for (int i = 0; i< options.Length; i++) + { + if (ShowOptions[i]) + { + options[i].Show(OptionNames[i]); + } + else + { + options[i].Hide(); + } + } + + // Relies on AccelOptions to keep lengths correct. + for (int i = 0; i< optionsXY.Length; i++) + { + if (ShowOptionsXY[i]) + { + optionsXY[i].Show(); + } + else + { + optionsXY[i].Hide(); + } + } + + button.Enabled = ButtonEnabled; + } + } +} diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs new file mode 100644 index 0000000..2a0358e --- /dev/null +++ b/grapher/Layouts/LinearLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class LinearLayout : LayoutBase + { + public LinearLayout() + : base() + { + Name = "Linear"; + Index = 1; + ShowOptions = new bool[] { true, true, false, false }; + OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty }; + } + } +} diff --git a/grapher/Layouts/LogLayout.cs b/grapher/Layouts/LogLayout.cs new file mode 100644 index 0000000..ae1a8f5 --- /dev/null +++ b/grapher/Layouts/LogLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class LogLayout : LayoutBase + { + public LogLayout() + : base() + { + Name = "Logarithmic"; + Index = 4; + ShowOptions = new bool[] { true, true, false, false }; + OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty }; + } + } +} diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs new file mode 100644 index 0000000..743135c --- /dev/null +++ b/grapher/Layouts/NaturalLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class NaturalLayout : LayoutBase + { + public NaturalLayout() + : base() + { + Name = "Natural"; + Index = 3; + ShowOptions = new bool[] { true, true, true, false }; + OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty }; + } + } +} diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs new file mode 100644 index 0000000..cecba05 --- /dev/null +++ b/grapher/Layouts/OffLayout.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class OffLayout : LayoutBase + { + public OffLayout() + : base() + { + Name = "Off"; + Index = 7; + ShowOptions = new bool[] { false, false, false, false }; + OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty }; + ShowOptionsXY = new bool[] { false, false }; + ButtonEnabled = true; + } + } +} diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs new file mode 100644 index 0000000..da02cf5 --- /dev/null +++ b/grapher/Layouts/PowerLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class PowerLayout : LayoutBase + { + public PowerLayout() + : base() + { + Name = "Power"; + Index = 6; + ShowOptions = new bool[] { true, true, true, false }; + OptionNames = new string[] { Offset, Scale, Exponent, string.Empty }; + } + } +} diff --git a/grapher/Layouts/SigmoidLayout.cs b/grapher/Layouts/SigmoidLayout.cs new file mode 100644 index 0000000..0dec3bf --- /dev/null +++ b/grapher/Layouts/SigmoidLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class SigmoidLayout : LayoutBase + { + public SigmoidLayout() + : base() + { + Name = "Sigmoid"; + Index = 5; + ShowOptions = new bool[] { true, true, true, true }; + OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint }; + } + } +} diff --git a/grapher/Option.cs b/grapher/Option.cs new file mode 100644 index 0000000..eb5105e --- /dev/null +++ b/grapher/Option.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public class Option + { + public Option(Field field, Label label) + { + Field = field; + Label = label; + } + + public Option(TextBox box, Form containingForm, double defaultData, Label label) + : this(new Field(box, containingForm, defaultData), label) + { + } + + public Option(TextBox box, Form containingForm, double defaultData, Label label, string startingName) + : this(box, containingForm, defaultData, label) + { + SetName(startingName); + } + + public Field Field { get; } + + public Label Label { get; } + + public void SetName(string name) + { + Label.Text = name; + Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); + } + + public void Hide() + { + Field.Box.Hide(); + Label.Hide(); + } + + public void Show() + { + Field.Box.Show(); + Label.Show(); + } + + public void Show(string name) + { + SetName(name); + + Show(); + } + } +} diff --git a/grapher/OptionXY.cs b/grapher/OptionXY.cs new file mode 100644 index 0000000..1fdf244 --- /dev/null +++ b/grapher/OptionXY.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public class OptionXY + { + public OptionXY(FieldXY fields, Label label) + { + Fields = fields; + Label = label; + } + + public OptionXY( + TextBox xBox, + TextBox yBox, + CheckBox lockCheckBox, + Form containingForm, + double defaultData, + Label label) + : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData), label) + { + } + + public OptionXY( + TextBox xBox, + TextBox yBox, + CheckBox lockCheckBox, + Form containingForm, + double defaultData, + Label label, + string startingName): + this( + xBox, + yBox, + lockCheckBox, + containingForm, + defaultData, + label) + { + SetName(startingName); + } + + public FieldXY Fields { get; } + + public Label Label { get; } + + public void SetName(string name) + { + Label.Text = name; + Label.Left = Convert.ToInt32((Fields.XField.Box.Left / 2.0) - (Label.Width / 2.0)); + } + + public void Hide() + { + Fields.XField.Box.Hide(); + Fields.YField.Box.Hide(); + Fields.LockCheckBox.Hide(); + Label.Hide(); + } + + public void Show() + { + Fields.XField.Box.Show(); + Fields.YField.Box.Show(); + Fields.LockCheckBox.Show(); + Label.Show(); + } + + public void Show(string name) + { + SetName(name); + + Show(); + } + + } +} diff --git a/grapher/VectorXY.cs b/grapher/VectorXY.cs new file mode 100644 index 0000000..53c9e68 --- /dev/null +++ b/grapher/VectorXY.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher +{ + public class VectorXY + { + public VectorXY(double x) + { + X = x; + Y = x; + } + + public VectorXY(double x, double y) + { + X = x; + Y = y; + } + + public double X { get; set; } + + public double Y { get; set; } + + public void SetBoth(double value) + { + X = value; + Y = value; + } + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index f67ced1..bd86a0c 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -47,14 +47,29 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="AccelOptions.cs" /> + <Compile Include="Field.cs" /> + <Compile Include="FieldXY.cs" /> <Compile Include="Form1.cs"> <SubType>Form</SubType> </Compile> <Compile Include="Form1.Designer.cs"> <DependentUpon>Form1.cs</DependentUpon> </Compile> + <Compile Include="Layouts\ClassicLayout.cs" /> + <Compile Include="Layouts\DefaultLayout.cs" /> + <Compile Include="Layouts\LayoutBase.cs" /> + <Compile Include="Layouts\LinearLayout.cs" /> + <Compile Include="Layouts\LogLayout.cs" /> + <Compile Include="Layouts\NaturalLayout.cs" /> + <Compile Include="Layouts\OffLayout.cs" /> + <Compile Include="Layouts\PowerLayout.cs" /> + <Compile Include="Layouts\SigmoidLayout.cs" /> + <Compile Include="Option.cs" /> + <Compile Include="OptionXY.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="VectorXY.cs" /> <EmbeddedResource Include="Form1.resx"> <DependentUpon>Form1.cs</DependentUpon> </EmbeddedResource> diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 26d05ec..ceee1a1 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -1,7 +1,6 @@ #pragma once -#include "..\common\rawaccel.hpp"; -#include "wrapper.hpp"; +#include "wrapper.hpp" using namespace rawaccel; using namespace System; @@ -14,4 +13,43 @@ Tuple<double, double>^ ManagedAccel::Accelerate(int x, int y, double time) vec2d output = (*modifier_instance).modify_with_accel(input_vec2d, (milliseconds)time); return gcnew Tuple<double, double>(output.x, output.y); -}
\ No newline at end of file +} + +void ManagedAccel::UpdateAccel( + int mode, + double rotation, + double sensitivityX, + double sensitivityY, + double weightX, + double weightY, + double capX, + double capY, + double offset, + double accel, + double lim_exp, + double midpoint) +{ + delete modifier_instance; + + modifier_args args{}; + args.acc_fn_args.accel_mode = mode; + args.degrees = rotation; + args.sens.x = sensitivityX; + args.sens.y = sensitivityY; + args.acc_fn_args.acc_args.weight.x = weightX; + args.acc_fn_args.acc_args.weight.y = weightY; + args.acc_fn_args.cap.x = capX; + args.acc_fn_args.cap.y = capY; + args.acc_fn_args.acc_args.offset = offset; + args.acc_fn_args.acc_args.accel = accel; + args.acc_fn_args.acc_args.limit = lim_exp; + args.acc_fn_args.acc_args.exponent = lim_exp; + args.acc_fn_args.acc_args.midpoint = midpoint; + + modifier_instance = new mouse_modifier(args); +} + +void ManagedAccel::WriteToDriver() +{ + driverWriter->writeToDriver(modifier_instance); +} diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp index 42f5865..870aca7 100644 --- a/wrapper/wrapper.hpp +++ b/wrapper/wrapper.hpp @@ -1,5 +1,6 @@ #pragma once +#include "wrapper_writer.hpp" #include "..\common\rawaccel.hpp"; #include "..\common\accel-error.hpp"; #include <iostream> @@ -15,15 +16,18 @@ public ref class ManagedAccel { protected: mouse_modifier* modifier_instance; + writer* driverWriter; public: ManagedAccel(mouse_modifier* accel) : modifier_instance(accel) { + driverWriter = new writer(); } ManagedAccel(System::IntPtr args) { modifier_instance = new mouse_modifier(*reinterpret_cast<modifier_args*>(args.ToPointer())); + driverWriter = new writer(); } virtual ~ManagedAccel() @@ -47,4 +51,21 @@ public: } Tuple<double, double>^ Accelerate(int x, int y, double time); + + void UpdateAccel( + int mode, + double rotation, + double sensitivityX, + double sensitivityY, + double weightX, + double weightY, + double capX, + double capY, + double offset, + double accel, + double lim_exp, + double midpoint); + + + void WriteToDriver(); };
\ No newline at end of file diff --git a/wrapper/wrapper.vcxproj b/wrapper/wrapper.vcxproj index d27266d..28acbe7 100644 --- a/wrapper/wrapper.vcxproj +++ b/wrapper/wrapper.vcxproj @@ -116,9 +116,11 @@ </ItemDefinitionGroup> <ItemGroup> <ClInclude Include="wrapper.hpp" /> + <ClInclude Include="wrapper_writer.hpp" /> </ItemGroup> <ItemGroup> <ClCompile Include="wrapper.cpp" /> + <ClCompile Include="wrapper_writer.cpp" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/wrapper/wrapper.vcxproj.filters b/wrapper/wrapper.vcxproj.filters index 22d967d..28b22ba 100644 --- a/wrapper/wrapper.vcxproj.filters +++ b/wrapper/wrapper.vcxproj.filters @@ -18,10 +18,16 @@ <ClInclude Include="wrapper.hpp"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="wrapper_writer.hpp"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="wrapper.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="wrapper_writer.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project>
\ No newline at end of file diff --git a/wrapper/wrapper_writer.cpp b/wrapper/wrapper_writer.cpp new file mode 100644 index 0000000..0a74105 --- /dev/null +++ b/wrapper/wrapper_writer.cpp @@ -0,0 +1,9 @@ +#pragma once + +#include "..\console\console_write.cpp" +#include "wrapper_writer.hpp" + +void writer::writeToDriver(rawaccel::mouse_modifier* modifier) +{ + write(*modifier); +} diff --git a/wrapper/wrapper_writer.hpp b/wrapper/wrapper_writer.hpp new file mode 100644 index 0000000..591f62f --- /dev/null +++ b/wrapper/wrapper_writer.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "..\common\rawaccel.hpp" + +struct writer { + void writeToDriver(rawaccel::mouse_modifier* modifier); +};
\ No newline at end of file |