From 5b659e1cfbc4b8fbbd2f2bf41dc716929976c77d Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 28 Aug 2021 01:19:18 -0400 Subject: add per-device configuration adds input and [in, out] cap for classic mode adds input cap for power mode change wrapper/input, now gets useful device names change (now dev specific) dpi to adjust sensitivity change y sensitivity to y/x ratio remove spaced LUTs grapher and convert do not build --- common/rawaccel.hpp | 221 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 144 insertions(+), 77 deletions(-) (limited to 'common/rawaccel.hpp') diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 4e8b46c..4f98c8d 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -1,6 +1,6 @@ #pragma once -#include "accel-invoke.hpp" +#include "accel-union.hpp" namespace rawaccel { @@ -28,45 +28,75 @@ namespace rawaccel { return pow(pow(v.x, p) + pow(v.y, p), 1 / p); } - class mouse_modifier { - public: - enum accel_distance_mode : unsigned char { - separate, - max, - Lp, - euclidean, + struct time_clamp { + milliseconds min = DEFAULT_TIME_MIN; + milliseconds max = DEFAULT_TIME_MAX; + }; + + struct device_config { + bool disable = false; + bool set_extra_info = false; + int dpi = 0; + int polling_rate = 0; + time_clamp clamp; + }; + + struct device_settings { + wchar_t name[MAX_NAME_LEN] = {}; + wchar_t profile[MAX_NAME_LEN] = {}; + wchar_t id[MAX_DEV_ID_LEN] = {}; + device_config config; + }; + + struct driver_settings { + profile prof; + + struct data_t { + vec2d rot_direction; + accel_union accel_x; + accel_union accel_y; + } data = {}; + }; + + inline void init_data(driver_settings& settings) + { + auto set_accel = [](accel_union& u, const accel_args& args) { + u.visit([&](auto& impl) { + impl = { args }; + }, args); }; - bool apply_rotate = false; - bool compute_ref_angle = false; - bool apply_snap = false; - bool cap_speed = false; - accel_distance_mode dist_mode = euclidean; - bool apply_directional_weight = false; - bool apply_dir_mul_x = false; - bool apply_dir_mul_y = false; - - vec2d rot_vec = { 1, 0 }; - double snap = 0; - double dpi_norm_factor = 1; - double speed_min = 0; - double speed_max = 0; - vec2d domain_weights = { 1, 1 }; - double p = 2; - vec2d range_weights = { 1, 1 }; - vec2d directional_multipliers = { 1, 1 }; - vec2d sensitivity = { 1, 1 }; - vec2 accel; + set_accel(settings.data.accel_x, settings.prof.accel_x); + set_accel(settings.data.accel_y, settings.prof.accel_y); + + settings.data.rot_direction = direction(settings.prof.degrees_rotation); + } + + inline constexpr unsigned DRIVER_CAPACITY = POOL_SIZE / sizeof(driver_settings); + inline constexpr unsigned DEVICE_CAPACITY = POOL_SIZE / sizeof(device_settings); + struct io_t { + device_config default_dev_cfg; + unsigned driver_data_size; + unsigned device_data_size; + driver_settings driver_data[DRIVER_CAPACITY]; + device_settings device_data[DEVICE_CAPACITY]; + }; + + class modifier { + public: #ifdef _KERNEL_MODE __forceinline #endif - void modify(vec2d& in, const vec2& inv, milliseconds time = 1) const + void modify(vec2d& in, const driver_settings& settings, double dpi_factor, milliseconds time) const { - double ips_factor = dpi_norm_factor / time; + auto& args = settings.prof; + auto& data = settings.data; + double reference_angle = 0; + double ips_factor = dpi_factor / time; - if (apply_rotate) in = rotate(in, rot_vec); + if (apply_rotate) in = rotate(in, data.rot_direction); if (compute_ref_angle && in.y != 0) { if (in.x == 0) { @@ -76,6 +106,8 @@ namespace rawaccel { reference_angle = atan(fabs(in.y / in.x)); if (apply_snap) { + double snap = args.degrees_snap * PI / 180; + if (reference_angle > PI / 2 - snap) { reference_angle = PI / 2; in = { 0, _copysign(magnitude(in), in.y) }; @@ -88,92 +120,127 @@ namespace rawaccel { } } - if (cap_speed) { + if (clamp_speed) { double speed = magnitude(in) * ips_factor; - double ratio = clampsd(speed, speed_min, speed_max) / speed; + double ratio = clampsd(speed, args.speed_min, args.speed_max) / speed; in.x *= ratio; in.y *= ratio; } vec2d abs_weighted_vel = { - fabs(in.x * ips_factor * domain_weights.x), - fabs(in.y * ips_factor * domain_weights.y) + fabs(in.x * ips_factor * args.domain_weights.x), + fabs(in.y * ips_factor * args.domain_weights.y) }; - if (dist_mode == separate) { - in.x *= inv.x.invoke(accel.x, abs_weighted_vel.x, range_weights.x); - in.y *= inv.y.invoke(accel.y, abs_weighted_vel.y, range_weights.y); + if (distance_mode == separate) { + in.x *= (*cb_x)(data.accel_x, args.accel_x, abs_weighted_vel.x, args.range_weights.x); + in.y *= (*cb_y)(data.accel_y, args.accel_y, abs_weighted_vel.y, args.range_weights.y); } - else { + else { double speed; - if (dist_mode == max) { + if (distance_mode == max) { speed = maxsd(abs_weighted_vel.x, abs_weighted_vel.y); } - else if (dist_mode == Lp) { - speed = lp_distance(abs_weighted_vel, p); + else if (distance_mode == Lp) { + speed = lp_distance(abs_weighted_vel, args.lp_norm); } else { speed = magnitude(abs_weighted_vel); } - double weight = range_weights.x; + double weight = args.range_weights.x; if (apply_directional_weight) { - double diff = range_weights.y - range_weights.x; + double diff = args.range_weights.y - args.range_weights.x; weight += 2 / PI * reference_angle * diff; } - double scale = inv.x.invoke(accel.x, speed, weight); + double scale = (*cb_x)(data.accel_x, args.accel_x, speed, weight); in.x *= scale; in.y *= scale; } + double dpi_adjusted_sens = args.sensitivity * dpi_factor; + in.x *= dpi_adjusted_sens; + in.y *= dpi_adjusted_sens * args.yx_sens_ratio; + if (apply_dir_mul_x && in.x < 0) { - in.x *= directional_multipliers.x; + in.x *= args.dir_multipliers.x; } if (apply_dir_mul_y && in.y < 0) { - in.y *= directional_multipliers.y; + in.y *= args.dir_multipliers.y; } - - in.x *= sensitivity.x; - in.y *= sensitivity.y; } - mouse_modifier(const settings& args) : - rot_vec(direction(args.degrees_rotation)), - snap(args.degrees_snap * PI / 180), - dpi_norm_factor(1000 / args.dpi), - speed_min(args.speed_min), - speed_max(args.speed_max), - p(args.dom_args.lp_norm), - domain_weights(args.dom_args.domain_weights), - range_weights(args.range_weights), - directional_multipliers(args.dir_multipliers), - sensitivity(args.sens), - accel({ { args.argsv.x }, { args.argsv.y } }) + modifier(driver_settings& settings) { - cap_speed = speed_max > 0 && speed_min <= speed_max; - apply_rotate = rot_vec.x != 1; - apply_snap = snap != 0; - apply_directional_weight = range_weights.x != range_weights.y; + auto& args = settings.prof; + + clamp_speed = args.speed_max > 0 && args.speed_min <= args.speed_max; + apply_rotate = args.degrees_rotation != 0; + apply_snap = args.degrees_snap != 0; + apply_directional_weight = args.range_weights.x != args.range_weights.y; compute_ref_angle = apply_snap || apply_directional_weight; - apply_dir_mul_x = directional_multipliers.x != 1; - apply_dir_mul_y = directional_multipliers.y != 1; + apply_dir_mul_x = args.dir_multipliers.x != 1; + apply_dir_mul_y = args.dir_multipliers.y != 1; - if (!args.combine_mags) dist_mode = separate; - else if (p >= MAX_NORM || p <= 0) dist_mode = max; - else if (p != 2) dist_mode = Lp; - else dist_mode = euclidean; + if (!args.whole) { + distance_mode = distance_mode::separate; + } + else if (args.lp_norm >= MAX_NORM || args.lp_norm <= 0) { + distance_mode = distance_mode::max; + } + else if (args.lp_norm != 2) { + distance_mode = distance_mode::Lp; + } + else { + distance_mode = distance_mode::euclidean; + } + + set_callback(cb_x, settings.data.accel_x, args.accel_x); + set_callback(cb_y, settings.data.accel_y, args.accel_y); } - mouse_modifier() = default; - }; + modifier() = default; - struct io_t { - settings args; - mouse_modifier mod; + private: + using callback_t = double (*)(const accel_union&, const accel_args&, double, double); + + void set_callback(callback_t& cb, accel_union& u, const accel_args& args) + { + u.visit([&](auto& impl) { + cb = &callback_template>; + }, args); + } + + template + static double callback_template(const accel_union& u, + const accel_args& args, + double x, + double range_weight) + { + auto& accel_fn = reinterpret_cast(u); + return 1 + (accel_fn(x, args) - 1) * range_weight; + } + + bool apply_rotate = 0; + bool compute_ref_angle = 0; + bool apply_snap = 0; + bool clamp_speed = 0; + enum distance_mode : unsigned char { + separate, + max, + Lp, + euclidean, + } distance_mode = {}; + bool apply_directional_weight = 0; + bool apply_dir_mul_x = 0; + bool apply_dir_mul_y = 0; + + callback_t cb_x = &callback_template; + callback_t cb_y = &callback_template; }; } // rawaccel -- cgit v1.2.3 From 6a9272d3af202274dfbced245f0ba20b263fcd8b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Fri, 3 Sep 2021 18:09:00 -0400 Subject: refactor vec2/math --- common/rawaccel.hpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'common/rawaccel.hpp') diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 4f98c8d..b7e632b 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -4,30 +4,6 @@ namespace rawaccel { - inline vec2d direction(double degrees) - { - double radians = degrees * PI / 180; - return { cos(radians), sin(radians) }; - } - - constexpr vec2d rotate(const vec2d& v, const vec2d& direction) - { - return { - v.x * direction.x - v.y * direction.y, - v.x * direction.y + v.y * direction.x - }; - } - - inline double magnitude(const vec2d& v) - { - return sqrt(v.x * v.x + v.y * v.y); - } - - inline double lp_distance(const vec2d& v, double p) - { - return pow(pow(v.x, p) + pow(v.y, p), 1 / p); - } - struct time_clamp { milliseconds min = DEFAULT_TIME_MIN; milliseconds max = DEFAULT_TIME_MAX; @@ -100,16 +76,16 @@ namespace rawaccel { if (compute_ref_angle && in.y != 0) { if (in.x == 0) { - reference_angle = PI / 2; + reference_angle = M_PI / 2; } else { reference_angle = atan(fabs(in.y / in.x)); if (apply_snap) { - double snap = args.degrees_snap * PI / 180; + double snap = args.degrees_snap * M_PI / 180; - if (reference_angle > PI / 2 - snap) { - reference_angle = PI / 2; + if (reference_angle > M_PI / 2 - snap) { + reference_angle = M_PI / 2; in = { 0, _copysign(magnitude(in), in.y) }; } else if (reference_angle < snap) { @@ -153,7 +129,7 @@ namespace rawaccel { if (apply_directional_weight) { double diff = args.range_weights.y - args.range_weights.x; - weight += 2 / PI * reference_angle * diff; + weight += 2 / M_PI * reference_angle * diff; } double scale = (*cb_x)(data.accel_x, args.accel_x, speed, weight); -- cgit v1.2.3 From 8680805b267bf5280b8f446ed33ef07981ea5475 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Mon, 6 Sep 2021 19:11:47 -0400 Subject: make profile count dynamic (unlimited) --- common/rawaccel.hpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'common/rawaccel.hpp') diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index b7e632b..c7bf33d 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -48,17 +48,14 @@ namespace rawaccel { settings.data.rot_direction = direction(settings.prof.degrees_rotation); } - inline constexpr unsigned DRIVER_CAPACITY = POOL_SIZE / sizeof(driver_settings); - inline constexpr unsigned DEVICE_CAPACITY = POOL_SIZE / sizeof(device_settings); - - struct io_t { + struct io_base { device_config default_dev_cfg; - unsigned driver_data_size; - unsigned device_data_size; - driver_settings driver_data[DRIVER_CAPACITY]; - device_settings device_data[DEVICE_CAPACITY]; + unsigned driver_data_size = 0; + unsigned device_data_size = 0; }; + static_assert(alignof(io_base) == alignof(driver_settings) && alignof(driver_settings) == alignof(device_settings)); + class modifier { public: #ifdef _KERNEL_MODE -- cgit v1.2.3 From 427a94bc4086c67a044ebbaed8bc789b1ed174c9 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Wed, 8 Sep 2021 04:43:15 -0400 Subject: rename driver_settings found a better one refactor driver/DeviceSetup --- common/rawaccel.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'common/rawaccel.hpp') diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index c7bf33d..be4e1a5 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -24,7 +24,7 @@ namespace rawaccel { device_config config; }; - struct driver_settings { + struct modifier_settings { profile prof; struct data_t { @@ -34,7 +34,7 @@ namespace rawaccel { } data = {}; }; - inline void init_data(driver_settings& settings) + inline void init_data(modifier_settings& settings) { auto set_accel = [](accel_union& u, const accel_args& args) { u.visit([&](auto& impl) { @@ -50,18 +50,18 @@ namespace rawaccel { struct io_base { device_config default_dev_cfg; - unsigned driver_data_size = 0; + unsigned modifier_data_size = 0; unsigned device_data_size = 0; }; - static_assert(alignof(io_base) == alignof(driver_settings) && alignof(driver_settings) == alignof(device_settings)); + static_assert(alignof(io_base) == alignof(modifier_settings) && alignof(modifier_settings) == alignof(device_settings)); class modifier { public: #ifdef _KERNEL_MODE __forceinline #endif - void modify(vec2d& in, const driver_settings& settings, double dpi_factor, milliseconds time) const + void modify(vec2d& in, const modifier_settings& settings, double dpi_factor, milliseconds time) const { auto& args = settings.prof; auto& data = settings.data; @@ -147,7 +147,7 @@ namespace rawaccel { } } - modifier(driver_settings& settings) + modifier(modifier_settings& settings) { auto& args = settings.prof; -- cgit v1.2.3 From 94ce1542b03090b81a4250f7f799895c58ab286c Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 18 Sep 2021 05:34:59 -0400 Subject: rename directional multipliers changes profile layout --- common/rawaccel.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common/rawaccel.hpp') diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index be4e1a5..e2f31b1 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -139,11 +139,11 @@ namespace rawaccel { in.y *= dpi_adjusted_sens * args.yx_sens_ratio; if (apply_dir_mul_x && in.x < 0) { - in.x *= args.dir_multipliers.x; + in.x *= args.lr_sens_ratio; } if (apply_dir_mul_y && in.y < 0) { - in.y *= args.dir_multipliers.y; + in.y *= args.ud_sens_ratio; } } @@ -156,8 +156,8 @@ namespace rawaccel { apply_snap = args.degrees_snap != 0; apply_directional_weight = args.range_weights.x != args.range_weights.y; compute_ref_angle = apply_snap || apply_directional_weight; - apply_dir_mul_x = args.dir_multipliers.x != 1; - apply_dir_mul_y = args.dir_multipliers.y != 1; + apply_dir_mul_x = args.lr_sens_ratio != 1; + apply_dir_mul_y = args.ud_sens_ratio != 1; if (!args.whole) { distance_mode = distance_mode::separate; -- cgit v1.2.3 From 330f2f4c2a574b30eab0bb874f73cc98b8fa8fc7 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 18 Sep 2021 05:58:35 -0400 Subject: set modifier flags in userspace --- common/rawaccel.hpp | 109 +++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 49 deletions(-) (limited to 'common/rawaccel.hpp') diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index e2f31b1..b12fb8b 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -24,10 +24,55 @@ namespace rawaccel { device_config config; }; + enum class distance_mode : unsigned char { + separate, + max, + Lp, + euclidean, + }; + + struct modifier_flags { + bool apply_rotate = 0; + bool compute_ref_angle = 0; + bool apply_snap = 0; + bool clamp_speed = 0; + distance_mode dist_mode = {}; + bool apply_directional_weight = 0; + bool apply_dir_mul_x = 0; + bool apply_dir_mul_y = 0; + + modifier_flags(const profile& args) + { + clamp_speed = args.speed_max > 0 && args.speed_min <= args.speed_max; + apply_rotate = args.degrees_rotation != 0; + apply_snap = args.degrees_snap != 0; + apply_directional_weight = args.range_weights.x != args.range_weights.y; + compute_ref_angle = apply_snap || apply_directional_weight; + apply_dir_mul_x = args.lr_sens_ratio != 1; + apply_dir_mul_y = args.ud_sens_ratio != 1; + + if (!args.whole) { + dist_mode = distance_mode::separate; + } + else if (args.lp_norm >= MAX_NORM || args.lp_norm <= 0) { + dist_mode = distance_mode::max; + } + else if (args.lp_norm != 2) { + dist_mode = distance_mode::Lp; + } + else { + dist_mode = distance_mode::euclidean; + } + } + + modifier_flags() = default; + }; + struct modifier_settings { profile prof; struct data_t { + modifier_flags flags; vec2d rot_direction; accel_union accel_x; accel_union accel_y; @@ -46,6 +91,8 @@ namespace rawaccel { set_accel(settings.data.accel_y, settings.prof.accel_y); settings.data.rot_direction = direction(settings.prof.degrees_rotation); + + settings.data.flags = modifier_flags(settings.prof); } struct io_base { @@ -65,20 +112,21 @@ namespace rawaccel { { auto& args = settings.prof; auto& data = settings.data; + auto& flags = settings.data.flags; double reference_angle = 0; double ips_factor = dpi_factor / time; - if (apply_rotate) in = rotate(in, data.rot_direction); + if (flags.apply_rotate) in = rotate(in, data.rot_direction); - if (compute_ref_angle && in.y != 0) { + if (flags.compute_ref_angle && in.y != 0) { if (in.x == 0) { reference_angle = M_PI / 2; } else { reference_angle = atan(fabs(in.y / in.x)); - if (apply_snap) { + if (flags.apply_snap) { double snap = args.degrees_snap * M_PI / 180; if (reference_angle > M_PI / 2 - snap) { @@ -93,7 +141,7 @@ namespace rawaccel { } } - if (clamp_speed) { + if (flags.clamp_speed) { double speed = magnitude(in) * ips_factor; double ratio = clampsd(speed, args.speed_min, args.speed_max) / speed; in.x *= ratio; @@ -105,17 +153,17 @@ namespace rawaccel { fabs(in.y * ips_factor * args.domain_weights.y) }; - if (distance_mode == separate) { + if (flags.dist_mode == distance_mode::separate) { in.x *= (*cb_x)(data.accel_x, args.accel_x, abs_weighted_vel.x, args.range_weights.x); in.y *= (*cb_y)(data.accel_y, args.accel_y, abs_weighted_vel.y, args.range_weights.y); } else { double speed; - if (distance_mode == max) { + if (flags.dist_mode == distance_mode::max) { speed = maxsd(abs_weighted_vel.x, abs_weighted_vel.y); } - else if (distance_mode == Lp) { + else if (flags.dist_mode == distance_mode::Lp) { speed = lp_distance(abs_weighted_vel, args.lp_norm); } else { @@ -124,7 +172,7 @@ namespace rawaccel { double weight = args.range_weights.x; - if (apply_directional_weight) { + if (flags.apply_directional_weight) { double diff = args.range_weights.y - args.range_weights.x; weight += 2 / M_PI * reference_angle * diff; } @@ -138,42 +186,19 @@ namespace rawaccel { in.x *= dpi_adjusted_sens; in.y *= dpi_adjusted_sens * args.yx_sens_ratio; - if (apply_dir_mul_x && in.x < 0) { + if (flags.apply_dir_mul_x && in.x < 0) { in.x *= args.lr_sens_ratio; } - if (apply_dir_mul_y && in.y < 0) { + if (flags.apply_dir_mul_y && in.y < 0) { in.y *= args.ud_sens_ratio; } } modifier(modifier_settings& settings) { - auto& args = settings.prof; - - clamp_speed = args.speed_max > 0 && args.speed_min <= args.speed_max; - apply_rotate = args.degrees_rotation != 0; - apply_snap = args.degrees_snap != 0; - apply_directional_weight = args.range_weights.x != args.range_weights.y; - compute_ref_angle = apply_snap || apply_directional_weight; - apply_dir_mul_x = args.lr_sens_ratio != 1; - apply_dir_mul_y = args.ud_sens_ratio != 1; - - if (!args.whole) { - distance_mode = distance_mode::separate; - } - else if (args.lp_norm >= MAX_NORM || args.lp_norm <= 0) { - distance_mode = distance_mode::max; - } - else if (args.lp_norm != 2) { - distance_mode = distance_mode::Lp; - } - else { - distance_mode = distance_mode::euclidean; - } - - set_callback(cb_x, settings.data.accel_x, args.accel_x); - set_callback(cb_y, settings.data.accel_y, args.accel_y); + set_callback(cb_x, settings.data.accel_x, settings.prof.accel_x); + set_callback(cb_y, settings.data.accel_y, settings.prof.accel_y); } modifier() = default; @@ -198,20 +223,6 @@ namespace rawaccel { return 1 + (accel_fn(x, args) - 1) * range_weight; } - bool apply_rotate = 0; - bool compute_ref_angle = 0; - bool apply_snap = 0; - bool clamp_speed = 0; - enum distance_mode : unsigned char { - separate, - max, - Lp, - euclidean, - } distance_mode = {}; - bool apply_directional_weight = 0; - bool apply_dir_mul_x = 0; - bool apply_dir_mul_y = 0; - callback_t cb_x = &callback_template; callback_t cb_y = &callback_template; }; -- cgit v1.2.3