This commit is contained in:
takashicompany 2024-11-19 16:56:05 +09:00
parent b4ac67cf53
commit 4c94a00512
3 changed files with 79 additions and 62 deletions

View File

@ -6,7 +6,7 @@
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( [0] = LAYOUT(
KC_Q , KC_W , KC_E , KC_Q , KC_W , KC_E ,
KC_TAB , KC_A , KC_S , KC_D , MY_JSKE, KC_A , KC_S , KC_D ,
KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_LSFT, KC_Z , KC_X , KC_C , KC_V ,
KC_LCTL, KC_UP , KC_LALT, KC_1 , KC_2 , KC_LCTL, KC_UP , KC_LALT, KC_1 , KC_2 ,
KC_LEFT, KC_DOWN, KC_RGHT, KC_3 KC_LEFT, KC_DOWN, KC_RGHT, KC_3
@ -54,7 +54,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[6] = LAYOUT( [6] = LAYOUT(
KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO ,
KC_NO , MY_BTN2, MY_SCRL, MY_BTN1, KC_TRNS, 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 ,
KC_NO , KC_NO , KC_NO , KC_NO KC_NO , KC_NO , KC_NO , KC_NO
@ -64,7 +64,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO ,
KC_NO , KC_NO , MY_CLKD, MY_CLKI, KC_NO , KC_NO , MY_CLKD, MY_CLKI,
QK_BOOT, KC_NO , MY_SCDV, MY_SCDH, KC_NO , QK_BOOT, KC_NO , MY_SCDV, MY_SCDH, KC_NO ,
KC_NO , MY_JSDD, MY_JSDI, KC_NO , KC_NO , MY_JSKD, MY_JSDD, MY_JSDI, KC_NO , KC_NO ,
KC_NO , MY_STGE, KC_NO , KC_NO KC_NO , MY_STGE, KC_NO , KC_NO
), ),
}; };

View File

@ -13,6 +13,7 @@
#define MOUSE_SCROLL_V_REVERSE_BIT (1 << 0) // 0000 0001 #define MOUSE_SCROLL_V_REVERSE_BIT (1 << 0) // 0000 0001
#define MOUSE_SCROLL_H_REVERSE_BIT (1 << 1) // 0000 0010 #define MOUSE_SCROLL_H_REVERSE_BIT (1 << 1) // 0000 0010
#define JOYSTICK_KEY_DEFAULT_ENABLE (1 << 2) // 0000 0100
enum click_state { enum click_state {
NONE = 0, NONE = 0,
@ -59,6 +60,8 @@ const uint16_t ignore_disable_mouse_layer_keys[] = {KC_LGUI, KC_LCTL}; // こ
int16_t mouse_movement; int16_t mouse_movement;
bool joystick_key_flag = false;
void eeconfig_init_kb(void) { void eeconfig_init_kb(void) {
user_config.raw = 0; user_config.raw = 0;
user_config.joystick_ratio = 100; user_config.joystick_ratio = 100;
@ -68,6 +71,7 @@ void eeconfig_init_kb(void) {
user_config.settings = 0; // 初期化 user_config.settings = 0; // 初期化
user_config.settings |= MOUSE_SCROLL_V_REVERSE_BIT * false; // ここでfalseなので実際にはセットしない user_config.settings |= MOUSE_SCROLL_V_REVERSE_BIT * false; // ここでfalseなので実際にはセットしない
user_config.settings |= MOUSE_SCROLL_H_REVERSE_BIT * false; // 同上 user_config.settings |= MOUSE_SCROLL_H_REVERSE_BIT * false; // 同上
user_config.settings |= JOYSTICK_KEY_DEFAULT_ENABLE * false;
eeconfig_update_kb(user_config.raw); eeconfig_update_kb(user_config.raw);
} }
@ -96,6 +100,18 @@ void set_mouse_scroll_h_reverse(bool value) {
} }
} }
bool get_joystick_key_default_enable(void) {
return user_config.settings & JOYSTICK_KEY_DEFAULT_ENABLE;
}
void set_joystick_key_default_enable(bool value) {
if (value) {
user_config.settings |= JOYSTICK_KEY_DEFAULT_ENABLE;
} else {
user_config.settings &= ~JOYSTICK_KEY_DEFAULT_ENABLE;
}
}
void keyboard_post_init_kb(void) { void keyboard_post_init_kb(void) {
user_config.raw = eeconfig_read_kb(); user_config.raw = eeconfig_read_kb();
joystick_ratio = user_config.joystick_ratio; joystick_ratio = user_config.joystick_ratio;
@ -125,7 +141,7 @@ void enable_setting_layer(void) {
} }
layer_on(setting_layer); layer_on(setting_layer);
SEND_STRING("Setting Layer Start."); SEND_STRING(" Setting Layer Start.");
} }
void disable_setting_layer(void) { void disable_setting_layer(void) {
@ -136,7 +152,7 @@ void disable_setting_layer(void) {
} }
layer_off(setting_layer); layer_off(setting_layer);
SEND_STRING("Setting Layer End."); SEND_STRING(" Setting Layer End.");
} }
// 自前の絶対数を返す関数。 Functions that return absolute numbers. // 自前の絶対数を返す関数。 Functions that return absolute numbers.
@ -163,10 +179,6 @@ bool is_clickable_mode(void) {
bool process_record_kb(uint16_t keycode, keyrecord_t *record) { bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
#ifdef CONSOLE_ENABLE
uprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
#endif
if (record->event.key.row == 0 && record->event.key.col == 0) if (record->event.key.row == 0 && record->event.key.col == 0)
{ {
setting_flags[0] = record->event.pressed; setting_flags[0] = record->event.pressed;
@ -241,7 +253,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
case MY_CLKI: case MY_CLKI:
if (record->event.pressed) { if (record->event.pressed) {
user_config.to_clickable_movement += 5; // user_config.to_clickable_time += 10; user_config.to_clickable_movement += 5;
eeconfig_update_kb(user_config.raw); eeconfig_update_kb(user_config.raw);
} }
return false; return false;
@ -249,31 +261,26 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
case MY_CLKD: case MY_CLKD:
if (record->event.pressed) { if (record->event.pressed) {
user_config.to_clickable_movement -= 5; // user_config.to_clickable_time -= 10; user_config.to_clickable_movement -= 5;
if (user_config.to_clickable_movement < 5) if (user_config.to_clickable_movement < 5) {
{
user_config.to_clickable_movement = 5; user_config.to_clickable_movement = 5;
} }
// if (user_config.to_clickable_time < 10) {
// user_config.to_clickable_time = 10;
// }
eeconfig_update_kb(user_config.raw); eeconfig_update_kb(user_config.raw);
} }
return false; return false;
case MY_SCDV: case MY_SCDV:
if (record->event.pressed) { if (record->event.pressed) {
set_mouse_scroll_v_reverse(!get_mouse_scroll_v_reverse()); // user_config.mouse_scroll_v_reverse = !user_config.mouse_scroll_v_reverse; set_mouse_scroll_v_reverse(!get_mouse_scroll_v_reverse());
eeconfig_update_kb(user_config.raw); eeconfig_update_kb(user_config.raw);
} }
return false; return false;
case MY_SCDH: case MY_SCDH:
if (record->event.pressed) { if (record->event.pressed) {
set_mouse_scroll_h_reverse(!get_mouse_scroll_h_reverse()); // user_config.mouse_scroll_h_reverse = !user_config.mouse_scroll_h_reverse; set_mouse_scroll_h_reverse(!get_mouse_scroll_h_reverse());
eeconfig_update_kb(user_config.raw); eeconfig_update_kb(user_config.raw);
} }
return false; return false;
@ -283,10 +290,6 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
joystick_ratio = joystick_ratio + 5; joystick_ratio = joystick_ratio + 5;
user_config.joystick_ratio = joystick_ratio; user_config.joystick_ratio = joystick_ratio;
eeconfig_update_kb(user_config.raw); eeconfig_update_kb(user_config.raw);
// char str[256];
// sprintf(str, "%d", joystick_ratio);
// SEND_STRING(str);
} }
break; break;
@ -296,10 +299,6 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
joystick_ratio = joystick_ratio - 5; joystick_ratio = joystick_ratio - 5;
user_config.joystick_ratio = joystick_ratio; user_config.joystick_ratio = joystick_ratio;
eeconfig_update_kb(user_config.raw); eeconfig_update_kb(user_config.raw);
// char str[256];
// sprintf(str, "%d", joystick_ratio);
// SEND_STRING(str);
} }
break; break;
@ -310,6 +309,17 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
} }
break; break;
case MY_JSKD:
if (record->event.pressed) {
set_joystick_key_default_enable(!get_joystick_key_default_enable());
eeconfig_update_kb(user_config.raw);
}
break;
case MY_JSKE:
joystick_key_flag = record->event.pressed;
break;
default: default:
if (record->event.pressed) { if (record->event.pressed) {
@ -335,6 +345,26 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
return process_record_user(keycode, record); return process_record_user(keycode, record);
} }
int8_t joystick_key_column = -1;
uint16_t joystick_key_timer;
void reset_joystick_key(void) {
if (joystick_key_column >= 0) {
action_exec(MAKE_KEYEVENT(6, joystick_key_column, false));
}
joystick_key_column = -1;
}
void press_joystick_key(int8_t column) {
if (joystick_key_column != -1 || timer_elapsed(joystick_key_timer) < 200) {
return;
}
joystick_key_column = column;
joystick_key_timer = timer_read();
action_exec(MAKE_KEYEVENT(6, column, true));
}
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
int8_t current_x = mouse_report.x; int8_t current_x = mouse_report.x;
@ -342,47 +372,32 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
int8_t current_h = 0; int8_t current_h = 0;
int8_t current_v = 0; int8_t current_v = 0;
if (get_joystick_key_default_enable() != joystick_key_flag) {
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
// 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); uprintf("x: %d, y: %d, raw_x: %d, raw_y: %d \n", current_x, current_y, joystick_raw_x, joystick_raw_y);
#endif
if ((current_x != 0 || current_y != 0) && if ((current_x != 0 || current_y != 0) &&
(joystick_raw_x > range || joystick_raw_y > range) == false && (joystick_raw_x > 100 || joystick_raw_y > 100) == false &&
(my_abs_16(joystick_raw_x) + my_abs_16(joystick_raw_y) > 200)){ (my_abs_16(joystick_raw_x) + my_abs_16(joystick_raw_y) > 200)){
if (joystick_raw_y < joystick_raw_x * 3) { if (joystick_raw_y < joystick_raw_x * 4) {
// 上 // 上
uprintf("up\n"); press_joystick_key(1);
} else if (joystick_raw_x < joystick_raw_y * 3) { } else if (joystick_raw_x < joystick_raw_y * 5) {
uprintf("left\n"); press_joystick_key(2);
} else { } else {
uprintf("left-up\n"); press_joystick_key(0);
}
}
else {
reset_joystick_key();
} }
// 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.x = 0;
mouse_report.y = 0; mouse_report.y = 0;
mouse_report.h = 0; mouse_report.h = 0;
mouse_report.v = 0; mouse_report.v = 0;
}
return mouse_report; return mouse_report;
} }

View File

@ -14,4 +14,6 @@ enum custom_keycodes_kb {
MY_JSDI, // Joy stick movement divisor increase MY_JSDI, // Joy stick movement divisor increase
MY_JSDD, // Joy stick movement divisor decrease MY_JSDD, // Joy stick movement divisor decrease
MY_STGE, // Setting End MY_STGE, // Setting End
MY_JSKD, // Joy stick key default
MY_JSKE, // Joy stick key enable
}; };