From 14bde56daf188bfc027dc8ead5b45ec0aa1109d6 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:51:31 -0400 Subject: update rest grapher is still broken refactored io / error handling a bit --- common/rawaccel-validate.hpp | 168 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 common/rawaccel-validate.hpp (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp new file mode 100644 index 0000000..b9ee2af --- /dev/null +++ b/common/rawaccel-validate.hpp @@ -0,0 +1,168 @@ +#pragma once + +#include "rawaccel-base.hpp" +#include "utility.hpp" + +namespace rawaccel { + + struct valid_ret_t { + int count_x = 0; + int count_y = 0; + int count = 0; + + explicit operator bool() const + { + return count == 0; + } + }; + + template + valid_ret_t valid(const settings& args, MsgHandler fn = {}) + { + valid_ret_t ret; + + auto error = [&](auto msg) { + ++ret.count; + fn(msg); + }; + + auto check_accel = [&error](const accel_args& args) { + static_assert(LUT_CAPACITY == 1025, "update error msg"); + + const auto& lut_args = args.lut_args; + + if (lut_args.partitions <= 0) { + error("lut partitions"" must be positive"); + } + + if (lut_args.mode == table_mode::linear) { + if (lut_args.start <= 0) { + error("start"" must be positive"); + } + + if (lut_args.stop <= lut_args.start) { + error("stop must be greater than start"); + } + + if (lut_args.num_elements < 2 || + lut_args.num_elements > 1025) { + error("num must be between 2 and 1025"); + } + } + else if (lut_args.mode == table_mode::binlog) { + int istart = static_cast(lut_args.start); + int istop = static_cast(lut_args.stop); + + if (lut_args.start < -99) { + error("start is too small"); + } + else if (lut_args.stop > 99) { + error("stop is too large"); + } + else if (istart != lut_args.start || istop != lut_args.stop) { + error("start and stop must be integers"); + } + else if (istop <= istart) { + error("stop must be greater than start"); + } + else if (lut_args.num_elements <= 0) { + error("num"" must be positive"); + } + else if (((lut_args.stop - lut_args.start) * lut_args.num_elements) >= 1025) { + error("binlog mode requires (num * (stop - start)) < 1025"); + } + } + + if (args.offset < 0) { + error("offset can not be negative"); + } + + if (args.cap <= 0) { + error("cap"" must be positive"); + } + + if (args.accel_motivity <= 0 || + args.accel_natural <= 0 || + args.accel_classic <= 0) { + error("acceleration"" must be positive"); + } + + if (args.motivity <= 1) { + error("motivity must be greater than 1"); + } + + if (args.power <= 1) { + error("power must be greater than 1"); + } + + if (args.scale <= 0) { + error("scale"" must be positive"); + } + + if (args.weight <= 0) { + error("weight"" must be positive"); + } + + if (args.exponent <= 0) { + error("exponent"" must be positive"); + } + + if (args.limit <= 0) { + error("limit"" must be positive"); + } + + if (args.midpoint <= 0) { + error("midpoint"" must be positive"); + } + + if (args.smooth < 0 || args.smooth > 1) { + error("smooth must be between 0 and 1"); + } + + }; + + check_accel(args.argsv.x); + + if (!args.combine_mags) { + ret.count_x = ret.count; + check_accel(args.argsv.y); + ret.count_y = ret.count; + } + + if (args.dpi <= 0) { + error("dpi"" must be positive"); + } + + if (args.speed_cap <= 0) { + error("speed cap"" must be positive"); + } + + if (args.sens.x == 0 || args.sens.y == 0) { + error("sens multiplier is 0"); + } + + if (args.dom_args.domain_weights.x <= 0 || + args.dom_args.domain_weights.y <= 0) { + error("domain weights"" must be positive"); + } + + if (args.dom_args.lp_norm <= 0) { + error("Lp norm can not be negative"); + } + + if (args.dir_multipliers.x < 0 || args.dir_multipliers.y < 0) { + error("directional multipliers can not be negative"); + } + + if (args.range_weights.x <= 0 || args.range_weights.y <= 0) { + error("range weights"" must be positive"); + } + + if (args.time_min <= 0) { + error("minimum time"" must be positive"); + } + + return ret; + } + +} -- cgit v1.2.3 From e9866f27d78d9909fd4639cbd14a54b8ad5c2ec1 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 1 Apr 2021 18:33:00 -0400 Subject: driver - apply accel disregarding num packets add setting for max time threshold --- common/rawaccel-validate.hpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index b9ee2af..a02324b 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -162,6 +162,10 @@ namespace rawaccel { error("minimum time"" must be positive"); } + if (args.time_max < args.time_min) { + error("max time is less than min time"); + } + return ret; } -- cgit v1.2.3 From 3751ac95831412dbdf9de9744c0ef59c34033d3d Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 1 Apr 2021 20:56:29 -0400 Subject: add minimum to complement speed cap important feature fixes some validation checks --- common/rawaccel-validate.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index a02324b..bccb21c 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -133,8 +133,11 @@ namespace rawaccel { error("dpi"" must be positive"); } - if (args.speed_cap <= 0) { - error("speed cap"" must be positive"); + if (args.speed_max < 0) { + error("speed cap is negative"); + } + else if (args.speed_max < args.speed_min) { + error("max speed is less than min speed"); } if (args.sens.x == 0 || args.sens.y == 0) { @@ -147,7 +150,7 @@ namespace rawaccel { } if (args.dom_args.lp_norm <= 0) { - error("Lp norm can not be negative"); + error("Lp norm must be positive"); } if (args.dir_multipliers.x < 0 || args.dir_multipliers.y < 0) { -- cgit v1.2.3 From 7c1f14845bc948e9ea25908e96099203d9433a69 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Apr 2021 01:21:42 -0400 Subject: update wrapper + writer to handle lut grapher is building but applying options still broken for the most part --- common/rawaccel-validate.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index bccb21c..d625d20 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -44,7 +44,7 @@ namespace rawaccel { error("stop must be greater than start"); } - if (lut_args.num_elements < 2 || + if (lut_args.num_elements < 2 || lut_args.num_elements > 1025) { error("num must be between 2 and 1025"); } @@ -73,6 +73,7 @@ namespace rawaccel { } } + if (args.offset < 0) { error("offset can not be negative"); } -- cgit v1.2.3 From 758de1d236f591de1d8b2fba4c58bfd8d5bbd26e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 6 Apr 2021 18:04:28 -0700 Subject: Rename accelMotivity to growthRate --- common/rawaccel-validate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index d625d20..338fbdc 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -82,7 +82,7 @@ namespace rawaccel { error("cap"" must be positive"); } - if (args.accel_motivity <= 0 || + if (args.growth_rate <= 0 || args.accel_natural <= 0 || args.accel_classic <= 0) { error("acceleration"" must be positive"); -- cgit v1.2.3 From 258fcd3bd236a787f07d7dac2049be524d86cb75 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 6 Apr 2021 23:11:20 -0700 Subject: Fix natural legacy algorithm, rename accelNatural to decayRate --- common/rawaccel-validate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index 338fbdc..230ddac 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -83,7 +83,7 @@ namespace rawaccel { } if (args.growth_rate <= 0 || - args.accel_natural <= 0 || + args.decay_rate <= 0 || args.accel_classic <= 0) { error("acceleration"" must be positive"); } -- cgit v1.2.3 From c55d1bfd01147fa014ac07d4b03ef3cad8427ae6 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Apr 2021 02:30:01 -0400 Subject: optimize a bit/refactor modify --- common/rawaccel-validate.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index 230ddac..4f7dd9c 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -141,6 +141,10 @@ namespace rawaccel { error("max speed is less than min speed"); } + if (args.degrees_snap < 0 || args.degrees_snap > 45) { + error("snap angle must be between 0 and 45 degrees"); + } + if (args.sens.x == 0 || args.sens.y == 0) { error("sens multiplier is 0"); } @@ -150,12 +154,12 @@ namespace rawaccel { error("domain weights"" must be positive"); } - if (args.dom_args.lp_norm <= 0) { - error("Lp norm must be positive"); + if (args.dir_multipliers.x <= 0 || args.dir_multipliers.y <= 0) { + error("directional multipliers must be positive"); } - if (args.dir_multipliers.x < 0 || args.dir_multipliers.y < 0) { - error("directional multipliers can not be negative"); + if (args.dom_args.lp_norm < 2) { + error("Lp norm is less than 2 (default=2)"); } if (args.range_weights.x <= 0 || args.range_weights.y <= 0) { -- cgit v1.2.3 From 74ffcb8553795f4b50e544a1b2a0e53aec32a860 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Apr 2021 21:48:17 -0400 Subject: make sizeof arbitrary close to others refactor constructor/fix conversions --- common/rawaccel-validate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index 4f7dd9c..ef6f667 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -27,7 +27,7 @@ namespace rawaccel { }; auto check_accel = [&error](const accel_args& args) { - static_assert(LUT_CAPACITY == 1025, "update error msg"); + static_assert(SPACED_LUT_CAPACITY == 1025, "update error msg"); const auto& lut_args = args.lut_args; -- cgit v1.2.3 From a6926be0e911b7b7637861866f41c3bca31a87a3 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 13 Apr 2021 23:59:21 -0400 Subject: move arbitrary input into settings separate arbitrary mode from spaced modes, arbitrary now deserializes from default settings file --- common/rawaccel-validate.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index ef6f667..2f54b5f 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -29,13 +29,13 @@ namespace rawaccel { auto check_accel = [&error](const accel_args& args) { static_assert(SPACED_LUT_CAPACITY == 1025, "update error msg"); - const auto& lut_args = args.lut_args; + const auto& lut_args = args.spaced_args; if (lut_args.partitions <= 0) { error("lut partitions"" must be positive"); } - if (lut_args.mode == table_mode::linear) { + if (lut_args.mode == spaced_lut_mode::linear) { if (lut_args.start <= 0) { error("start"" must be positive"); } @@ -49,7 +49,7 @@ namespace rawaccel { error("num must be between 2 and 1025"); } } - else if (lut_args.mode == table_mode::binlog) { + else if (lut_args.mode == spaced_lut_mode::binlog) { int istart = static_cast(lut_args.start); int istop = static_cast(lut_args.stop); @@ -73,6 +73,11 @@ namespace rawaccel { } } + if (args.mode == accel_mode::arb_lookup) { + if (args.arb_args.length < 2) { + error("lookup mode requires at least 2 points"); + } + } if (args.offset < 0) { error("offset can not be negative"); -- cgit v1.2.3 From 44c20e12d53434c47b08dbe855567316159d0469 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sat, 3 Jul 2021 14:52:54 -0700 Subject: Small fixes, guide additions, tweaks --- common/rawaccel-validate.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index 2f54b5f..e9d1120 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -83,8 +83,8 @@ namespace rawaccel { error("offset can not be negative"); } - if (args.cap <= 0) { - error("cap"" must be positive"); + if (args.cap < 0) { + error("cap"" must not be negative"); } if (args.growth_rate <= 0 || -- cgit v1.2.3 From 0b7bad55819d4a7ea9a8e3e4198acc35a8a7371a Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sun, 29 Aug 2021 19:09:27 -0400 Subject: add validation checks for jump mode --- common/rawaccel-validate.hpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index e9d1120..e776298 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -82,10 +82,16 @@ namespace rawaccel { if (args.offset < 0) { error("offset can not be negative"); } + else if (args.mode == accel_mode::jump && args.offset == 0) { + error("offset can not be 0"); + } if (args.cap < 0) { error("cap"" must not be negative"); } + else if (args.mode == accel_mode::jump && args.cap == 0) { + error("cap can not be 0"); + } if (args.growth_rate <= 0 || args.decay_rate <= 0 || -- cgit v1.2.3 From 598ffa03b4191a6b51374c8ee2528f2d1dadbb62 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sun, 29 Aug 2021 20:42:32 -0400 Subject: bugfix - oob in SettingsErrors::ToString --- common/rawaccel-validate.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common/rawaccel-validate.hpp') diff --git a/common/rawaccel-validate.hpp b/common/rawaccel-validate.hpp index e776298..a03f56a 100644 --- a/common/rawaccel-validate.hpp +++ b/common/rawaccel-validate.hpp @@ -6,8 +6,8 @@ namespace rawaccel { struct valid_ret_t { - int count_x = 0; - int count_y = 0; + int last_x = 0; + int last_y = 0; int count = 0; explicit operator bool() const @@ -136,9 +136,9 @@ namespace rawaccel { check_accel(args.argsv.x); if (!args.combine_mags) { - ret.count_x = ret.count; + ret.last_x = ret.count; check_accel(args.argsv.y); - ret.count_y = ret.count; + ret.last_y = ret.count; } if (args.dpi <= 0) { -- cgit v1.2.3