From b4ac67cf5330eae312e8fe71a6e6d2c7013e1046 Mon Sep 17 00:00:00 2001 From: takashicompany Date: Tue, 19 Nov 2024 14:22:56 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=84=E3=82=8D=E3=81=84=E3=82=8D=E9=80=94?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../left_slinger/custom_joystick.c | 10 +++- .../left_slinger/custom_joystick.h | 4 +- .../takashicompany/left_slinger/keyboard.json | 34 +++++++++++-- .../left_slinger/keymaps/default/keymap.c | 32 ++++++------ .../left_slinger/left_slinger.c | 51 ++++++++++++++++++- 5 files changed, 108 insertions(+), 23 deletions(-) diff --git a/keyboards/takashicompany/left_slinger/custom_joystick.c b/keyboards/takashicompany/left_slinger/custom_joystick.c index 91de7245137..5c68bd9789e 100644 --- a/keyboards/takashicompany/left_slinger/custom_joystick.c +++ b/keyboards/takashicompany/left_slinger/custom_joystick.c @@ -10,6 +10,8 @@ int16_t xOrigin, yOrigin; uint16_t lastCursor = 0; int16_t joystick_ratio = 100; +int16_t joystick_raw_x = 0; +int16_t joystick_raw_y = 0; int16_t axisCoordinate_custom(pin_t pin, uint16_t origin) { int8_t direction; // 符号 @@ -34,6 +36,7 @@ void pointing_device_driver_init(void) { xOrigin = analogReadPin(ANALOG_JOYSTICK_X_AXIS_PIN); yOrigin = analogReadPin(ANALOG_JOYSTICK_Y_AXIS_PIN); } + report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) { if (timer_elapsed(lastCursor) > ANALOG_JOYSTICK_READ_INTERVAL) { // 多分、指定のミリ秒経過したかを見て処理を走らせている @@ -47,8 +50,11 @@ report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) { jsr = -10; } - mouse_report.x = axisCoordinate_custom(ANALOG_JOYSTICK_X_AXIS_PIN, xOrigin) / jsr; - mouse_report.y = axisCoordinate_custom(ANALOG_JOYSTICK_Y_AXIS_PIN, yOrigin) / jsr; + joystick_raw_x = axisCoordinate_custom(ANALOG_JOYSTICK_X_AXIS_PIN, xOrigin); + joystick_raw_y = axisCoordinate_custom(ANALOG_JOYSTICK_Y_AXIS_PIN, yOrigin); + + mouse_report.x = joystick_raw_x / jsr; + mouse_report.y = joystick_raw_y / jsr; } return mouse_report; diff --git a/keyboards/takashicompany/left_slinger/custom_joystick.h b/keyboards/takashicompany/left_slinger/custom_joystick.h index 0d7f6b94316..b56425bc79a 100644 --- a/keyboards/takashicompany/left_slinger/custom_joystick.h +++ b/keyboards/takashicompany/left_slinger/custom_joystick.h @@ -3,4 +3,6 @@ #include #include -extern int16_t joystick_ratio; \ No newline at end of file +extern int16_t joystick_ratio; +extern int16_t joystick_raw_x; +extern int16_t joystick_raw_y; \ No newline at end of file diff --git a/keyboards/takashicompany/left_slinger/keyboard.json b/keyboards/takashicompany/left_slinger/keyboard.json index f0e0862ddc6..872662456aa 100644 --- a/keyboards/takashicompany/left_slinger/keyboard.json +++ b/keyboards/takashicompany/left_slinger/keyboard.json @@ -6,7 +6,10 @@ "diode_direction": "COL2ROW", "encoder": { "rotary": [ - {"pin_a": "GP14", "pin_b": "GP15"} + { + "pin_a": "GP14", + "pin_b": "GP15" + } ] }, "features": { @@ -30,7 +33,8 @@ "GP10", "GP11", "GP12", - "GP13" + "GP13", + "GP0" ] }, "processor": "RP2040", @@ -137,7 +141,7 @@ 2 ], "x": 4.25, - "y": 2.25 + "y": 2 }, { "matrix": [ @@ -163,6 +167,22 @@ "x": 3, "y": 3.25 }, + { + "matrix": [ + 6, + 0 + ], + "x": 4.25, + "y": 3.25 + }, + { + "matrix": [ + 6, + 1 + ], + "x": 5.25, + "y": 3.25 + }, { "matrix": [ 5, @@ -186,6 +206,14 @@ ], "x": 3, "y": 4.25 + }, + { + "matrix": [ + 6, + 2 + ], + "x": 4.25, + "y": 4.25 } ] } diff --git a/keyboards/takashicompany/left_slinger/keymaps/default/keymap.c b/keyboards/takashicompany/left_slinger/keymaps/default/keymap.c index 43f716d8adb..40bac09ca9b 100644 --- a/keyboards/takashicompany/left_slinger/keymaps/default/keymap.c +++ b/keyboards/takashicompany/left_slinger/keymaps/default/keymap.c @@ -8,64 +8,64 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_Q , KC_W , KC_E , KC_TAB , KC_A , KC_S , KC_D , KC_LSFT, KC_Z , KC_X , KC_C , KC_V , - KC_LCTL, KC_UP , KC_LALT, - KC_LEFT, KC_DOWN, KC_RGHT + KC_LCTL, KC_UP , KC_LALT, KC_1 , KC_2 , + KC_LEFT, KC_DOWN, KC_RGHT, KC_3 ), [1] = LAYOUT( KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO + KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , + KC_NO , KC_NO , KC_NO , KC_NO ), [2] = LAYOUT( KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO + KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , + KC_NO , KC_NO , KC_NO , KC_NO ), [3] = LAYOUT( KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO + KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , + KC_NO , KC_NO , KC_NO , KC_NO ), [4] = LAYOUT( KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO + KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , + KC_NO , KC_NO , KC_NO , KC_NO ), [5] = LAYOUT( KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO + KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , + KC_NO , KC_NO , KC_NO , KC_NO ), [6] = LAYOUT( KC_NO , KC_NO , KC_NO , KC_NO , MY_BTN2, MY_SCRL, MY_BTN1, KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO , - KC_NO , KC_NO , KC_NO + KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , + KC_NO , KC_NO , KC_NO , KC_NO ), [7] = LAYOUT( KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , MY_CLKD, MY_CLKI, QK_BOOT, KC_NO , MY_SCDV, MY_SCDH, KC_NO , - KC_NO , MY_JSDD, MY_JSDI, - KC_NO , MY_STGE, KC_NO + KC_NO , MY_JSDD, MY_JSDI, KC_NO , KC_NO , + KC_NO , MY_STGE, KC_NO , KC_NO ), }; diff --git a/keyboards/takashicompany/left_slinger/left_slinger.c b/keyboards/takashicompany/left_slinger/left_slinger.c index 9d37f1670e9..2126a015c9a 100644 --- a/keyboards/takashicompany/left_slinger/left_slinger.c +++ b/keyboards/takashicompany/left_slinger/left_slinger.c @@ -148,6 +148,14 @@ int8_t my_abs(int8_t num) { return num; } +int16_t my_abs_16(int16_t num) { + if (num < 0) { + num = -num; + } + + return num; +} + // 現在クリックが可能な状態か。 Is it currently clickable? bool is_clickable_mode(void) { return state == CLICKABLE || state == CLICKING || state == SCROLLING; @@ -335,8 +343,49 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { int8_t current_v = 0; #ifdef CONSOLE_ENABLE - uprintf("pointing x: %d y:%d \n", current_x, current_y); + // uprintf("pointing x: %d y:%d \n", current_x, current_y); #endif + + int16_t range = 100; + + if (true) { + uprintf("x: %d, y: %d, raw_x: %d, raw_y: %d \n", current_x, current_y, joystick_raw_x, joystick_raw_y); + if ((current_x != 0 || current_y != 0) && + (joystick_raw_x > range || joystick_raw_y > range) == false && + (my_abs_16(joystick_raw_x) + my_abs_16(joystick_raw_y) > 200)){ + + if (joystick_raw_y < joystick_raw_x * 3) { + // 上 + uprintf("up\n"); + } else if (joystick_raw_x < joystick_raw_y * 3) { + uprintf("left\n"); + } else { + uprintf("left-up\n"); + } + + // if (current_y < 0) { + // if (current_y < current_x * 2) { + // // 上 + // uprintf("up d: %d, x: %d, y: %d, raw_x: %d, raw_y: %d \n", joystick_ratio, current_x, current_y, joystick_raw_x, joystick_raw_y); + // } else { + // // 左上 + // uprintf("UL d: %d, x: %d, y: %d, raw_x: %d, raw_y: %d \n", joystick_ratio, current_x, current_y, joystick_raw_x, joystick_raw_y); + // } + // } else if (current_y == 0 && current_x < 0) { + // // 左 + // uprintf("left d: %d, x: %d, y: %d, raw_x: %d, raw_y: %d \n", joystick_ratio, current_x, current_y, joystick_raw_x, joystick_raw_y); + // } + + mouse_report.x = 0; + mouse_report.y = 0; + mouse_report.h = 0; + mouse_report.v = 0; + + + } + return mouse_report; + } + if (current_x != 0 || current_y != 0) { switch (state) {