aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/common/mousekey.c
diff options
context:
space:
mode:
authorCallum Oakley <callum@pusher.com>2017-08-19 10:34:45 +0100
committerCallum Oakley <callum@pusher.com>2017-08-19 10:34:45 +0100
commita6845036e25c4f4d936dcd12cd0ddedd2894b30e (patch)
treeb23b4e8d9d757aa3c0d42be561572533ae0d126c /tmk_core/common/mousekey.c
parent84a8aabe5bf8807595f98de44d18f6a31b892edf (diff)
parent7277f09bbadcce120f819132dec8ff7172caacc4 (diff)
downloadfirmware-a6845036e25c4f4d936dcd12cd0ddedd2894b30e.tar.gz
firmware-a6845036e25c4f4d936dcd12cd0ddedd2894b30e.tar.bz2
firmware-a6845036e25c4f4d936dcd12cd0ddedd2894b30e.zip
Merge branch 'master' of https://github.com/qmk/qmk_firmware
Diffstat (limited to 'tmk_core/common/mousekey.c')
-rw-r--r--tmk_core/common/mousekey.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 23469476e..aa128f0e8 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -55,6 +55,14 @@ uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
static uint16_t last_timer = 0;
+inline int8_t times_inv_sqrt2(int8_t x)
+{
+ // 181/256 is pretty close to 1/sqrt(2)
+ // 0.70703125 0.707106781
+ // 1 too small for x=99 and x=198
+ // This ends up being a mult and discard lower 8 bits
+ return (x * 181) >> 8;
+}
static uint8_t move_unit(void)
{
@@ -111,10 +119,10 @@ void mousekey_task(void)
if (mouse_report.y > 0) mouse_report.y = move_unit();
if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
- /* diagonal move [1/sqrt(2) = 0.7] */
+ /* diagonal move [1/sqrt(2)] */
if (mouse_report.x && mouse_report.y) {
- mouse_report.x *= 0.7;
- mouse_report.y *= 0.7;
+ mouse_report.x = times_inv_sqrt2(mouse_report.x);
+ mouse_report.y = times_inv_sqrt2(mouse_report.y);
}
if (mouse_report.v > 0) mouse_report.v = wheel_unit();