diff options
| author | a1xd <[email protected]> | 2020-09-01 22:28:45 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-09-01 22:28:45 -0400 |
| commit | 7ff79f4e711c2d55daf667092cfce0289b1a7a9b (patch) | |
| tree | 28ebe356b2954911c2bbb4f09ac5ddee12578b31 | |
| parent | Merge pull request #17 from a1xd/indep (diff) | |
| download | rawaccel-7ff79f4e711c2d55daf667092cfce0289b1a7a9b.tar.xz rawaccel-7ff79f4e711c2d55daf667092cfce0289b1a7a9b.zip | |
add 1s write delay to driver
| -rw-r--r-- | common/rawaccel-error.hpp | 5 | ||||
| -rw-r--r-- | common/rawaccel-io.hpp | 5 | ||||
| -rw-r--r-- | driver/driver.cpp | 18 | ||||
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 12 | ||||
| -rw-r--r-- | grapher/Models/Serialized/DriverSettings.cs | 29 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 24 | ||||
| -rw-r--r-- | wrapper/wrapper_io.cpp | 4 | ||||
| -rw-r--r-- | wrapper/wrapper_io.hpp | 2 |
8 files changed, 43 insertions, 56 deletions
diff --git a/common/rawaccel-error.hpp b/common/rawaccel-error.hpp index f5498f9..ecee526 100644 --- a/common/rawaccel-error.hpp +++ b/common/rawaccel-error.hpp @@ -21,9 +21,4 @@ namespace rawaccel { install_error() : io_error("rawaccel is not installed") {} }; - class cooldown_error : public io_error { - public: - cooldown_error() : io_error("write is on cooldown") {} - }; - } diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 74e2d1e..e8641d1 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -74,10 +74,7 @@ namespace rawaccel { CloseHandle(ra_handle); if (!success) { - if (auto err = GetLastError(); err != ERROR_BUSY) { - throw std::system_error(err, std::system_category(), "DeviceIoControl failed"); - } - throw cooldown_error(); + throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); } } diff --git a/driver/driver.cpp b/driver/driver.cpp index 57b3c8a..fb47477 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -14,7 +14,6 @@ namespace ra = rawaccel; using milliseconds = double; struct { - counter_t last_write = 0; ra::settings args; milliseconds tick_interval = 0; // set in DriverEntry ra::mouse_modifier modifier; @@ -150,18 +149,10 @@ Return Value: DebugPrint(("Ioctl received into filter control object.\n")); if (InputBufferLength == sizeof(ra::settings)) { - constexpr milliseconds WRITE_COOLDOWN_TIME = 1000; - - counter_t now = KeQueryPerformanceCounter(NULL).QuadPart; - counter_t ticks = now - global.last_write; - milliseconds time = ticks * global.tick_interval; - - if (global.last_write > 0 && time < WRITE_COOLDOWN_TIME) { - DebugPrint(("RA write on cooldown\n")); - // status maps to win32 error code 170: ERROR_BUSY - WdfRequestComplete(Request, STATUS_ENCOUNTERED_WRITE_IN_PROGRESS); - return; - } + // 1 second wait + LARGE_INTEGER interval; + interval.QuadPart = -10000000; + KeDelayExecutionThread(KernelMode, FALSE, &interval); status = WdfRequestRetrieveInputBuffer( Request, @@ -179,7 +170,6 @@ Return Value: global.args = *reinterpret_cast<ra::settings*>(buffer); global.modifier = { global.args }; - global.last_write = now; WdfRequestComplete(Request, STATUS_SUCCESS); } diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index a15dba8..7a32b4e 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -102,7 +102,7 @@ namespace grapher public void UpdateActiveSettingsFromFields() { - Settings.UpdateActiveSettings(new DriverSettings + var settings = new DriverSettings { rotation = Rotation.Field.Data, sensitivity = new Vec2<double> @@ -133,8 +133,16 @@ namespace grapher } }, minimumTime = .4 + }; + + Settings.UpdateActiveSettings(settings, () => + { + AccelForm.Invoke((MethodInvoker)delegate + { + UpdateGraph(); + }); }); - UpdateGraph(); + } public void UpdateGraph() diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs index 91d7e9f..4595bf2 100644 --- a/grapher/Models/Serialized/DriverSettings.cs +++ b/grapher/Models/Serialized/DriverSettings.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using System.Threading; namespace grapher.Models.Serialized { @@ -37,6 +38,7 @@ namespace grapher.Models.Serialized { private static readonly IntPtr UnmanagedSettingsHandle = Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>()); + private static object UnmanagedSettingsLock = new object(); public double rotation; public bool combineMagnitudes; @@ -51,21 +53,32 @@ namespace grapher.Models.Serialized return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle); } - public static void SetActive(DriverSettings settings) + public static void SetActive(DriverSettings settings, Action<IntPtr> unmanagedActionBefore = null) { - Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); - DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); + new Thread(() => + { + lock (UnmanagedSettingsLock) + { + Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); + unmanagedActionBefore?.Invoke(UnmanagedSettingsHandle); + DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); + } + }).Start(); + } - public void SendToDriver() + public void SendToDriver(Action<IntPtr> unmanagedActionBefore = null) { - SetActive(this); + SetActive(this, unmanagedActionBefore); } - public void SendToDriverAndUpdate(ManagedAccel accel) + public void SendToDriverAndUpdate(ManagedAccel accel, Action betweenAccelAndWrite = null) { - SendToDriver(); - accel.UpdateFromSettings(UnmanagedSettingsHandle); + SendToDriver(settingsHandle => + { + accel.UpdateFromSettings(settingsHandle); + betweenAccelAndWrite?.Invoke(); + }); } public bool verify() diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index fc58387..c300bde 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -28,12 +28,10 @@ namespace grapher.Models.Serialized private ToolStripMenuItem AutoWriteMenuItem { get; set; } - public void UpdateActiveSettings(DriverSettings settings) + public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null) { - try + settings.SendToDriverAndUpdate(ActiveAccel, () => { - settings.SendToDriverAndUpdate(ActiveAccel); - RawAccelSettings.AccelerationSettings = settings; RawAccelSettings.GUISettings = new GUISettings { @@ -43,23 +41,15 @@ namespace grapher.Models.Serialized }; RawAccelSettings.Save(); - } - catch (DriverWriteCDException) - { - Console.WriteLine("write on cooldown"); - } + + afterAccelSettingsUpdate?.Invoke(); + }); } public void UpdateActiveAccelFromFileSettings(DriverSettings settings) { - try - { - settings.SendToDriverAndUpdate(ActiveAccel); - } - catch (DriverWriteCDException) - { - Console.WriteLine("write on cd during file init"); - } + settings.SendToDriverAndUpdate(ActiveAccel); + DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; diff --git a/wrapper/wrapper_io.cpp b/wrapper/wrapper_io.cpp index 3f5673a..0f257bf 100644 --- a/wrapper/wrapper_io.cpp +++ b/wrapper/wrapper_io.cpp @@ -9,10 +9,6 @@ void wrapper_io::writeToDriver(const settings& args) { write(args); } - catch (const cooldown_error&) - { - throw gcnew DriverWriteCDException(); - } catch (const install_error&) { throw gcnew DriverNotInstalledException(); diff --git a/wrapper/wrapper_io.hpp b/wrapper/wrapper_io.hpp index aff572b..19f096f 100644 --- a/wrapper/wrapper_io.hpp +++ b/wrapper/wrapper_io.hpp @@ -17,5 +17,3 @@ public: }; public ref struct DriverNotInstalledException : public DriverIOException {}; - -public ref struct DriverWriteCDException : public DriverIOException {}; |