diff options
| author | Jacob Palecki <[email protected]> | 2020-09-25 19:35:54 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-25 19:35:54 -0700 |
| commit | f2279a5c52d5da43e48133e753514b3806bb7e3c (patch) | |
| tree | 328830580cf5bb96a317a61bef3e155dc2a17fd5 | |
| parent | Use log LUT rather than binary search for last mouse move point (diff) | |
| parent | add initial writer (diff) | |
| download | rawaccel-f2279a5c52d5da43e48133e753514b3806bb7e3c.tar.xz rawaccel-f2279a5c52d5da43e48133e753514b3806bb7e3c.zip | |
merge with writer
| -rw-r--r-- | common/rawaccel-settings.h | 5 | ||||
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 10 | ||||
| -rw-r--r-- | grapher/Models/Serialized/DriverSettings.cs | 116 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 41 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 5 | ||||
| -rw-r--r-- | rawaccel.sln | 7 | ||||
| -rw-r--r-- | wrapper/wrapper.cpp | 139 | ||||
| -rw-r--r-- | writer/App.config | 6 | ||||
| -rw-r--r-- | writer/Program.cs | 30 | ||||
| -rw-r--r-- | writer/Properties/AssemblyInfo.cs | 36 | ||||
| -rw-r--r-- | writer/writer.csproj | 65 |
11 files changed, 304 insertions, 156 deletions
diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index 2ba6a98..93f4768 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -4,6 +4,9 @@ #include "accel-base.hpp" namespace rawaccel { + using milliseconds = double; + + inline constexpr milliseconds WRITE_DELAY = 1000; enum class accel_mode { linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel @@ -15,7 +18,7 @@ namespace rawaccel { vec2<accel_mode> modes = { accel_mode::noaccel, accel_mode::noaccel }; vec2<accel_args> argsv; vec2d sens = { 1, 1 }; - double time_min = 0.4; + milliseconds time_min = 0.4; }; } diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 95d0c25..dd394c5 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -83,14 +83,8 @@ namespace grapher minimumTime = .4 }; - Settings.UpdateActiveSettings(settings, () => - { - AccelForm.Invoke((MethodInvoker)delegate - { - WriteButtonDelay(); - UpdateGraph(); - }); - }); + WriteButtonDelay(); + Settings.UpdateActiveSettings(settings); RefreshOnRead(); } diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs deleted file mode 100644 index cc37ad7..0000000 --- a/grapher/Models/Serialized/DriverSettings.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Threading; - -namespace grapher.Models.Serialized -{ - #region Enumerations - - public enum AccelMode - { - linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel - } - - #endregion Enumerations - - #region Structs - - [StructLayout(LayoutKind.Sequential)] - public struct AccelArgs - { - public double offset; - public double legacy_offset; - public double accel; - public double limit; - public double exponent; - public double midpoint; - public double powerScale; - public double powerExponent; - public double weight; - public double rate; - public double scaleCap; - public double gainCap; - }; - - [StructLayout(LayoutKind.Sequential)] - public struct Vec2 <T> - { - public T x; - public T y; - } - - #endregion Structs - - [StructLayout(LayoutKind.Sequential)] - [Serializable] - public class DriverSettings - { - #region Fields - - private static readonly IntPtr UnmanagedSettingsHandle = - Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>()); - private static object UnmanagedSettingsLock = new object(); - - public double rotation; - public bool combineMagnitudes; - public Vec2<AccelMode> modes; - public Vec2<AccelArgs> args; - public Vec2<double> sensitivity; - public double minimumTime; - - #endregion Fields - - #region Methods - - public static DriverSettings GetActive() - { - DriverInterop.GetActiveSettings(UnmanagedSettingsHandle); - return Marshal.PtrToStructure<DriverSettings>(UnmanagedSettingsHandle); - } - - public static void SetActive(DriverSettings settings, Action<IntPtr> unmanagedActionBefore = null) - { - new Thread(() => - { - lock (UnmanagedSettingsLock) - { - Marshal.StructureToPtr(settings, UnmanagedSettingsHandle, false); - unmanagedActionBefore?.Invoke(UnmanagedSettingsHandle); - DriverInterop.SetActiveSettings(UnmanagedSettingsHandle); - } - }).Start(); - } - - public void SendToDriver(Action<IntPtr> unmanagedActionBefore = null) - { - SetActive(this, unmanagedActionBefore); - } - - public void SendToDriverAndUpdate(ManagedAccel accel, Action betweenAccelAndWrite = null) - { - SendToDriver(settingsHandle => - { - accel.UpdateFromSettings(settingsHandle); - betweenAccelAndWrite?.Invoke(); - }); - } - - public bool verify() - { - /* - if (args.accel < 0 || args.rate < 0) - bad_arg("accel can not be negative, use a negative weight to compensate"); - if (args.rate > 1) bad_arg("rate can not be greater than 1"); - if (args.exponent <= 1) bad_arg("exponent must be greater than 1"); - if (args.limit <= 1) bad_arg("limit must be greater than 1"); - if (args.power_scale <= 0) bad_arg("scale must be positive"); - if (args.power_exp <= 0) bad_arg("exponent must be positive"); - if (args.midpoint < 0) bad_arg("midpoint must not be negative"); - if (args.time_min <= 0) bad_arg("min time must be positive"); - */ - return true; - } - - #endregion Methods - } -} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index cac2bd0..26160f5 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using System; using System.Windows.Forms; +using System.Threading; namespace grapher.Models.Serialized { @@ -46,29 +47,28 @@ namespace grapher.Models.Serialized #region Methods - public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null) + public void UpdateActiveSettings(DriverSettings settings) { - settings.SendToDriverAndUpdate(ActiveAccel, () => - { - RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = new GUISettings - { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, - }; + ActiveAccel.UpdateFromSettings(settings); + SendToDriver(settings); - RawAccelSettings.Save(); + RawAccelSettings.AccelerationSettings = settings; + RawAccelSettings.GUISettings = new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, + }; - afterAccelSettingsUpdate?.Invoke(); - }); + RawAccelSettings.Save(); } public void UpdateActiveAccelFromFileSettings(DriverSettings settings) - { - settings.SendToDriverAndUpdate(ActiveAccel); + { + ActiveAccel.UpdateFromSettings(settings); + SendToDriver(settings); DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); @@ -77,6 +77,11 @@ namespace grapher.Models.Serialized ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; } + public static void SendToDriver(DriverSettings settings) + { + new Thread(() => DriverInterop.SetActiveSettings(settings)).Start(); + } + public void Startup() { if (RawAccelSettings.Exists()) @@ -97,7 +102,7 @@ namespace grapher.Models.Serialized } RawAccelSettings = new RawAccelSettings( - DriverSettings.GetActive(), + DriverInterop.GetActiveSettings(), new GUISettings { AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index bc9fcf2..29b5cff 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -15,7 +15,7 @@ </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <DebugSymbols>true</DebugSymbols> - <OutputPath>bin\x64\Debug\</OutputPath> + <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <DebugType>full</DebugType> <PlatformTarget>x64</PlatformTarget> @@ -25,7 +25,7 @@ <Prefer32Bit>true</Prefer32Bit> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> - <OutputPath>bin\x64\Release\</OutputPath> + <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath> <DefineConstants>TRACE</DefineConstants> <Optimize>true</Optimize> <DebugType>pdbonly</DebugType> @@ -101,7 +101,6 @@ <Compile Include="Models\Options\OptionBase.cs" /> <Compile Include="Models\Options\OptionXY.cs" /> <Compile Include="Models\Serialized\GUISettings.cs" /> - <Compile Include="Models\Serialized\DriverSettings.cs" /> <Compile Include="Models\Serialized\RawAccelSettings.cs" /> <Compile Include="Models\Serialized\SettingsManager.cs" /> <Compile Include="Program.cs" /> diff --git a/rawaccel.sln b/rawaccel.sln index f2eab80..cfbbc23 100644 --- a/rawaccel.sln +++ b/rawaccel.sln @@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wrapper", "wrapper\wrapper. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "grapher", "grapher\grapher.csproj", "{EF67F71F-ABF5-4760-B50D-D1B9836DF01C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "writer", "writer\writer.csproj", "{28ACF254-E4EF-4A0E-9761-0FE22048D6FD}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution common-install\common-install.vcxitems*{058d66c6-d88b-4fdb-b0e4-0a6fe7483b95}*SharedItemsImports = 9 @@ -49,8 +51,13 @@ Global {28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x64.ActiveCfg = Release|x64 {28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x64.Build.0 = Release|x64 {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x64.ActiveCfg = Debug|x64 + {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x64.Build.0 = Debug|x64 {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.ActiveCfg = Release|x64 {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.Build.0 = Release|x64 + {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Debug|x64.ActiveCfg = Debug|x64 + {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Debug|x64.Build.0 = Debug|x64 + {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Release|x64.ActiveCfg = Release|x64 + {28ACF254-E4EF-4A0E-9761-0FE22048D6FD}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 0778bc3..9a53189 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -1,21 +1,139 @@ #pragma once +#include <type_traits> + #include <rawaccel.hpp> #include "wrapper_io.hpp" using namespace System; +using namespace System::Runtime::InteropServices; + +public enum class AccelMode +{ + linear, classic, natural, naturalgain, power, logarithm, motivity, noaccel +}; + +[StructLayout(LayoutKind::Sequential)] +public value struct AccelArgs +{ + double offset; + double legacy_offset; + double accel; + double limit; + double exponent; + double midpoint; + double powerScale; + double powerExponent; + double weight; + double rate; + double scaleCap; + double gainCap; +}; + +generic <typename T> +[StructLayout(LayoutKind::Sequential)] +public value struct Vec2 +{ + T x; + T y; +}; + +[Serializable] +[StructLayout(LayoutKind::Sequential)] +public ref struct DriverSettings +{ + double rotation; + [MarshalAs(UnmanagedType::U1)] + bool combineMagnitudes; + Vec2<AccelMode> modes; + Vec2<AccelArgs> args; + Vec2<double> sensitivity; + double minimumTime; +}; + + +template <typename NativeSettingsFunc> +void as_native(DriverSettings^ managed_args, NativeSettingsFunc fn) +{ +#ifndef NDEBUG + if (Marshal::SizeOf(managed_args) != sizeof(settings)) + throw gcnew InvalidOperationException("setting sizes differ"); +#endif + IntPtr unmanagedHandle = Marshal::AllocHGlobal(sizeof(settings)); + Marshal::StructureToPtr(managed_args, unmanagedHandle, false); + fn(*reinterpret_cast<settings*>(unmanagedHandle.ToPointer())); + if constexpr (!std::is_invocable_v<NativeSettingsFunc, const settings&>) { + Marshal::PtrToStructure(unmanagedHandle, managed_args); + } + Marshal::FreeHGlobal(unmanagedHandle); +} + +DriverSettings^ get_default() +{ + DriverSettings^ managed = gcnew DriverSettings(); + as_native(managed, [](settings& args) { + args = {}; + }); + return managed; +} + +void set_active(DriverSettings^ managed) +{ + as_native(managed, [](const settings& args) { + wrapper_io::writeToDriver(args); + }); +} + +DriverSettings^ get_active() +{ + DriverSettings^ managed = gcnew DriverSettings(); + as_native(managed, [](settings& args) { + wrapper_io::readFromDriver(args); + }); + return managed; +} + +void update_modifier(mouse_modifier& mod, DriverSettings^ managed, vec2<si_pair*> luts = {}) +{ + as_native(managed, [&](const settings& args) { + mod = { args, luts }; + }); +} public ref struct DriverInterop { - static void GetActiveSettings(IntPtr argsOut) + static DriverSettings^ GetActiveSettings() { - wrapper_io::readFromDriver(*reinterpret_cast<settings*>(argsOut.ToPointer())); + return get_active(); } - static void SetActiveSettings(IntPtr argsIn) + static void SetActiveSettings(DriverSettings^ args) { - wrapper_io::writeToDriver(*reinterpret_cast<settings*>(argsIn.ToPointer())); + set_active(args); + } + + static DriverSettings^ GetDefaultSettings() + { + return get_default(); + } + + using error_list_t = Collections::Generic::List<String^>; + + static error_list_t^ GetErrors(AccelArgs^ args) + { + auto error_list = gcnew error_list_t(); + + if (args->accel < 0 || args->rate < 0) + error_list->Add("accel can not be negative, use a negative weight to compensate"); + if (args->rate > 1) error_list->Add("rate can not be greater than 1"); + if (args->exponent <= 1) error_list->Add("exponent must be greater than 1"); + if (args->limit <= 1) error_list->Add("limit must be greater than 1"); + if (args->powerScale <= 0) error_list->Add("scale must be positive"); + if (args->powerExponent <= 0) error_list->Add("exponent must be positive"); + if (args->midpoint < 0) error_list->Add("midpoint must not be negative"); + + return error_list; } }; @@ -31,7 +149,7 @@ public ref class ManagedAccel #endif public: - static initonly double WriteDelay = -10000000 / -10000.0; + static initonly double WriteDelay = WRITE_DELAY; virtual ~ManagedAccel() { @@ -58,12 +176,13 @@ public: return gcnew Tuple<double, double>(in_out_vec.x, in_out_vec.y); } - void UpdateFromSettings(IntPtr argsIn) + void UpdateFromSettings(DriverSettings^ args) { - *modifier_instance = { - *reinterpret_cast<settings*>(argsIn.ToPointer()) - , vec2<si_pair*>{ lut_x, lut_y } - }; + update_modifier( + *modifier_instance, + args, + vec2<si_pair*>{ lut_x, lut_y } + ); } static ManagedAccel^ GetActiveAccel() diff --git a/writer/App.config b/writer/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/writer/App.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> + </startup> +</configuration>
\ No newline at end of file diff --git a/writer/Program.cs b/writer/Program.cs new file mode 100644 index 0000000..7f9c37c --- /dev/null +++ b/writer/Program.cs @@ -0,0 +1,30 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +using System; +using System.IO; + +namespace writer +{ + class Program + { + static void Main(string[] args) + { + try + { + var serializerSettings = new JsonSerializerSettings + { + MissingMemberHandling = MissingMemberHandling.Error, + }; + var token = JObject.Parse(File.ReadAllText(args[0]))["AccelerationSettings"]; + var settings = token.ToObject<DriverSettings>(JsonSerializer.Create(serializerSettings)); + DriverInterop.SetActiveSettings(settings); + } + catch (Exception e) + { + Console.WriteLine(e); + Console.ReadLine(); + } + } + } +} diff --git a/writer/Properties/AssemblyInfo.cs b/writer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..37e79ad --- /dev/null +++ b/writer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("writer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("writer")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("28acf254-e4ef-4a0e-9761-0fe22048d6fd")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/writer/writer.csproj b/writer/writer.csproj new file mode 100644 index 0000000..4befc1a --- /dev/null +++ b/writer/writer.csproj @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{28ACF254-E4EF-4A0E-9761-0FE22048D6FD}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>writer</RootNamespace> + <AssemblyName>writer</AssemblyName> + <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <Deterministic>true</Deterministic> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x64</PlatformTarget> + <LangVersion>7.3</LangVersion> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> + <OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <Optimize>true</Optimize> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x64</PlatformTarget> + <LangVersion>7.3</LangVersion> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <ItemGroup> + <Reference Include="Newtonsoft.Json"> + <HintPath>..\x64\Release\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\wrapper\wrapper.vcxproj"> + <Project>{28a3656f-a1de-405c-b547-191c32ec555f}</Project> + <Name>wrapper</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project>
\ No newline at end of file |