From 2e26185c1e01cdd1b9dc15d5e59e7590a3ebb47e Mon Sep 17 00:00:00 2001 From: shiiba-cba Date: Sun, 19 Jun 2022 20:43:19 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E9=87=8F=E3=82=92=E8=93=84=E7=A9=8D=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=8B=E3=82=89=E8=A3=9C=E6=AD=A3=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyboards/cocot46plus/cocot46plus.c | 30 +++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/keyboards/cocot46plus/cocot46plus.c b/keyboards/cocot46plus/cocot46plus.c index 1cae4aa76c58..f1d97798889b 100644 --- a/keyboards/cocot46plus/cocot46plus.c +++ b/keyboards/cocot46plus/cocot46plus.c @@ -40,7 +40,7 @@ along with this program. If not, see . #endif #ifndef COCOT_SCROLL_DIVIDERS -# define COCOT_SCROLL_DIVIDERS { 1, 2, 4, 8 } +# define COCOT_SCROLL_DIVIDERS { 1, 2, 4, 8, 64 } # ifndef COCOT_SCROLL_DIV_DEFAULT # define COCOT_SCROLL_DIV_DEFAULT 3 # endif @@ -74,6 +74,10 @@ uint16_t angle_array[] = COCOT_ROTATION_ANGLE; bool BurstState = false; // init burst state for Trackball module uint16_t MotionStart = 0; // Timer for accel, 0 is resting state +// Scroll Accumulation +static int8_t h_acm = 0; +static int8_t v_acm = 0; + void pointing_device_init_kb(void) { // set the CPI. @@ -89,13 +93,23 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { if (cocot_get_scroll_mode()) { - x_rev = x_rev / scrl_div_array[cocot_config.scrl_div] * cocot_config.scrl_inv; - y_rev = -y_rev / scrl_div_array[cocot_config.scrl_div] * cocot_config.scrl_inv; - x_rev = convert_twoscomp(x_rev); - y_rev = convert_twoscomp(y_rev); + // accumulate scroll + h_acm += convert_twoscomp(x_rev) * cocot_config.scrl_inv; + v_acm += convert_twoscomp(y_rev) * cocot_config.scrl_inv * -1; + + int8_t h_rev = h_acm / scrl_div_array[cocot_config.scrl_div]; + int8_t v_rev = v_acm / scrl_div_array[cocot_config.scrl_div]; - mouse_report.h = x_rev; - mouse_report.v = y_rev; + // clear accumulated scroll on assignment + + if (h_rev != 0) { + mouse_report.h = h_rev; + h_acm = 0; + } + if (v_rev != 0) { + mouse_report.v = v_rev; + v_acm = 0; + } mouse_report.x = 0; mouse_report.y = 0; @@ -229,7 +243,7 @@ void oled_write_layer_state(void) { char buf2[2]; char buf3[4]; snprintf(buf1, 5, "%4d", cpi); - snprintf(buf2, 2, "%1d", scroll_div); + snprintf(buf2, 3, "%2d", scroll_div); snprintf(buf3, 4, "%3d", angle); switch (get_highest_layer(layer_state | default_layer_state)) { From bc27cd9042b0f49bebddbd458931b6d168b5fd3a Mon Sep 17 00:00:00 2001 From: shiiba-cba Date: Mon, 20 Jun 2022 18:37:27 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyboards/cocot46plus/cocot46plus.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/keyboards/cocot46plus/cocot46plus.c b/keyboards/cocot46plus/cocot46plus.c index f1d97798889b..ddf4c013bf02 100644 --- a/keyboards/cocot46plus/cocot46plus.c +++ b/keyboards/cocot46plus/cocot46plus.c @@ -40,7 +40,7 @@ along with this program. If not, see . #endif #ifndef COCOT_SCROLL_DIVIDERS -# define COCOT_SCROLL_DIVIDERS { 1, 2, 4, 8, 64 } +# define COCOT_SCROLL_DIVIDERS { 1, 2, 4, 8, 30, 60 } # ifndef COCOT_SCROLL_DIV_DEFAULT # define COCOT_SCROLL_DIV_DEFAULT 3 # endif @@ -75,8 +75,8 @@ bool BurstState = false; // init burst state for Trackball module uint16_t MotionStart = 0; // Timer for accel, 0 is resting state // Scroll Accumulation -static int8_t h_acm = 0; -static int8_t v_acm = 0; +static int16_t h_acm = 0; +static int16_t v_acm = 0; void pointing_device_init_kb(void) { @@ -87,15 +87,15 @@ void pointing_device_init_kb(void) { report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { - double rad = angle_array[cocot_config.rotation_angle] * (M_PI / 180); - uint16_t x_rev = + mouse_report.x * cos(rad) + mouse_report.y * sin(rad); - uint16_t y_rev = - mouse_report.x * sin(rad) + mouse_report.y * cos(rad); + double rad = angle_array[cocot_config.rotation_angle] * (M_PI / 180) * -1; + int8_t x_rev = + mouse_report.x * cos(rad) - mouse_report.y * sin(rad); + int8_t y_rev = + mouse_report.x * sin(rad) + mouse_report.y * cos(rad); if (cocot_get_scroll_mode()) { // accumulate scroll - h_acm += convert_twoscomp(x_rev) * cocot_config.scrl_inv; - v_acm += convert_twoscomp(y_rev) * cocot_config.scrl_inv * -1; + h_acm += x_rev * cocot_config.scrl_inv; + v_acm += y_rev * cocot_config.scrl_inv * -1; int8_t h_rev = h_acm / scrl_div_array[cocot_config.scrl_div]; int8_t v_rev = v_acm / scrl_div_array[cocot_config.scrl_div]; @@ -103,19 +103,17 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { // clear accumulated scroll on assignment if (h_rev != 0) { - mouse_report.h = h_rev; - h_acm = 0; + mouse_report.h += h_rev; + h_acm -= h_rev * scrl_div_array[cocot_config.scrl_div]; } if (v_rev != 0) { - mouse_report.v = v_rev; - v_acm = 0; + mouse_report.v += v_rev; + v_acm -= v_rev * scrl_div_array[cocot_config.scrl_div]; } mouse_report.x = 0; mouse_report.y = 0; } else { - x_rev = convert_twoscomp(x_rev); - y_rev = convert_twoscomp(y_rev); mouse_report.x = x_rev; mouse_report.y = y_rev; } @@ -240,7 +238,7 @@ void oled_write_layer_state(void) { int angle = angle_array[cocot_config.rotation_angle]; char buf1[5]; - char buf2[2]; + char buf2[3]; char buf3[4]; snprintf(buf1, 5, "%4d", cpi); snprintf(buf2, 3, "%2d", scroll_div); From 9cd0c0243ce2391e658b6fa45e6f1510e17719bb Mon Sep 17 00:00:00 2001 From: shiiba-cba Date: Mon, 20 Jun 2022 19:41:47 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E9=87=8F=E3=81=AE=E5=A4=89=E6=95=B0=E3=81=8C=E7=AF=84?= =?UTF-8?q?=E5=9B=B2=E5=A4=96=E3=81=AB=E3=81=AA=E3=82=8B=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AE=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyboards/cocot46plus/cocot46plus.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/keyboards/cocot46plus/cocot46plus.c b/keyboards/cocot46plus/cocot46plus.c index ddf4c013bf02..546ffee4081b 100644 --- a/keyboards/cocot46plus/cocot46plus.c +++ b/keyboards/cocot46plus/cocot46plus.c @@ -103,10 +103,20 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { // clear accumulated scroll on assignment if (h_rev != 0) { + if (mouse_report.h + h_rev > 127) { + h_rev = 127 - mouse_report.h; + } else if (mouse_report.h + h_rev < -127) { + h_rev = -127 - mouse_report.h; + } mouse_report.h += h_rev; h_acm -= h_rev * scrl_div_array[cocot_config.scrl_div]; } if (v_rev != 0) { + if (mouse_report.v + v_rev > 127) { + v_rev = 127 - mouse_report.v; + } else if (mouse_report.v + v_rev < -127) { + v_rev = -127 - mouse_report.v; + } mouse_report.v += v_rev; v_acm -= v_rev * scrl_div_array[cocot_config.scrl_div]; }