Merge remote-tracking branch 'origin/master' into develop

This commit is contained in:
QMK Bot 2022-08-06 17:19:59 +00:00
commit e938c663e5

View file

@ -3,12 +3,24 @@
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
typedef union {
uint32_t raw;
struct {
int8_t trackball_movement_ratio;
int8_t mode;
};
} user_config_t;
user_config_t user_config;
enum custom_keycodes { enum custom_keycodes {
KC_MY_BTN1 = SAFE_RANGE, KC_MY_BTN1 = SAFE_RANGE,
KC_MY_BTN2, KC_MY_BTN2,
KC_MY_BTN3, KC_MY_BTN3,
KC_MY_SCR, KC_MY_SCR,
KC_TB_RAT_INC,
KC_TB_RAT_DEC,
KC_TB_MODE,
}; };
@ -37,7 +49,6 @@ int16_t scroll_h_threshold = 30; // この閾値を超える度に水平ス
int16_t after_click_lock_movement = 0; // クリック入力後の移動量を測定する変数。 Variable that measures the amount of movement after a click input. int16_t after_click_lock_movement = 0; // クリック入力後の移動量を測定する変数。 Variable that measures the amount of movement after a click input.
int16_t mouse_record_threshold = 30; // ポインターの動きを一時的に記録するフレーム数。 Number of frames in which the pointer movement is temporarily recorded. int16_t mouse_record_threshold = 30; // ポインターの動きを一時的に記録するフレーム数。 Number of frames in which the pointer movement is temporarily recorded.
int16_t mouse_move_count_ratio = 5; // ポインターの動きを再生する際の移動フレームの係数。 The coefficient of the moving frame when replaying the pointer movement.
int16_t mouse_record_x; int16_t mouse_record_x;
int16_t mouse_record_y; int16_t mouse_record_y;
@ -113,8 +124,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
), ),
LAYOUT( LAYOUT(
RGB_TOG, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, KC_NO, KC_NO, KC_NO, DF(0), DF(3), RGB_TOG, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, KC_TB_RAT_INC, KC_TB_RAT_DEC, KC_TB_MODE, DF(0), DF(3),
RGB_M_P, RGB_M_B, RGB_M_R, RGB_M_SW, RGB_M_SN, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RGB_M_P, RGB_M_B, RGB_M_R, RGB_M_SW, RGB_M_SN, EEP_RST, KC_NO, KC_NO, KC_NO, KC_NO,
RGB_M_K, RGB_M_X, RGB_M_G, KC_NO, KC_NO, QK_BOOT, KC_NO, KC_NO, KC_NO, KC_NO, RGB_M_K, RGB_M_X, RGB_M_G, KC_NO, KC_NO, QK_BOOT, KC_NO, KC_NO, KC_NO, KC_NO,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
), ),
@ -127,6 +138,17 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
) )
}; };
void eeconfig_init_user(void) {
user_config.raw = 0;
user_config.trackball_movement_ratio = 10;
user_config.mode = 0;
eeconfig_update_user(user_config.raw);
}
void keyboard_post_init_user(void) {
user_config.raw = eeconfig_read_user();
}
// クリック用のレイヤーを有効にする。 Enable layers for clicks // クリック用のレイヤーを有効にする。 Enable layers for clicks
void enable_click_layer(void) { void enable_click_layer(void) {
layer_on(click_layer); layer_on(click_layer);
@ -152,7 +174,7 @@ int16_t my_abs(int16_t num) {
} }
// 自前の符号を返す関数。 Function to return the sign. // 自前の符号を返す関数。 Function to return the sign.
int16_t mmouse_move_y_sign(int16_t num) { int16_t my_sign(int16_t num) {
if (num < 0) { if (num < 0) {
return -1; return -1;
} }
@ -201,7 +223,39 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
} else { } else {
enable_click_layer(); // スクロールキーを離した時に再度クリックレイヤーを有効にする。 Enable click layer again when the scroll key is released. enable_click_layer(); // スクロールキーを離した時に再度クリックレイヤーを有効にする。 Enable click layer again when the scroll key is released.
} }
return false; return false;
case KC_TB_RAT_INC:
if (record->event.pressed) {
user_config.trackball_movement_ratio += 1;
eeconfig_update_user(user_config.raw);
}
return false;
case KC_TB_RAT_DEC:
if (record->event.pressed) {
if (user_config.trackball_movement_ratio > 1) user_config.trackball_movement_ratio -= 1;
eeconfig_update_user(user_config.raw);
}
return false;
case KC_TB_MODE:
if (record->event.pressed) {
if (user_config.mode == 0)
{
user_config.mode = 1;
}
else
{
user_config.mode = 0;
}
eeconfig_update_user(user_config.raw);
}
return false;
default: default:
if (record->event.pressed) { if (record->event.pressed) {
@ -216,83 +270,91 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
if (!is_record_mouse) { if (user_config.mode == 0)
if (mouse_report.x != 0 || mouse_report.y != 0) { {
is_record_mouse = true; if (!is_record_mouse) {
mouse_record_x = 0; if (mouse_report.x != 0 || mouse_report.y != 0) {
mouse_record_y = 0; is_record_mouse = true;
mouse_record_count = 0; mouse_record_x = 0;
mouse_record_y = 0;
mouse_record_count = 0;
}
} }
}
if (is_record_mouse) { if (is_record_mouse) {
mouse_record_x += mouse_report.x; mouse_record_x += mouse_report.x; // * user_config.trackball_movement_ratio;
mouse_record_y += mouse_report.y; mouse_record_y += mouse_report.y; // * user_config.trackball_movement_ratio;
mouse_record_count++; mouse_record_count++;
if (mouse_record_count >= mouse_record_threshold) { if (mouse_record_count >= mouse_record_threshold) {
mouse_interval_counter = 0; mouse_interval_counter = 0;
int16_t absX = my_abs(mouse_record_x); int16_t absX = my_abs(mouse_record_x);
int16_t absY = my_abs(mouse_record_y); int16_t absY = my_abs(mouse_record_y);
is_mouse_move_x_min = absX < absY; is_mouse_move_x_min = absX < absY;
mouse_move_remain_count = absY + absX; mouse_move_remain_count = is_mouse_move_x_min ? absY : absX;
mouse_move_remain_count *= mouse_move_count_ratio; mouse_move_remain_count *= user_config.trackball_movement_ratio;
mouse_move_x_sign = mmouse_move_y_sign(mouse_record_x); mouse_move_x_sign = my_sign(mouse_record_x);
mouse_move_y_sign = mmouse_move_y_sign(mouse_record_y); mouse_move_y_sign = my_sign(mouse_record_y);
if (is_mouse_move_x_min) {
if (mouse_record_x == 0) {
mouse_interval_delta = 0;
} else {
mouse_interval_delta = (double)absX / (double)absY;
}
} else {
if (mouse_record_y == 0) {
mouse_interval_delta = 0;
} else {
mouse_interval_delta = (double)absY / (double)absX;
}
}
is_record_mouse = false;
mouse_record_count = 0;
}
}
if (mouse_move_remain_count > 0) {
mouse_interval_counter += mouse_interval_delta;
bool can_move_min = mouse_interval_counter >= 0.99;
if (can_move_min) {
mouse_interval_counter -= 0.99;
}
if (is_mouse_move_x_min) { if (is_mouse_move_x_min) {
if (mouse_record_x == 0) {
mouse_interval_delta = 0; mouse_report.y = mouse_move_y_sign;
} else {
mouse_interval_delta = (double)absX / (double)absY; if (can_move_min) {
mouse_report.x = mouse_move_x_sign;
} }
} else { } else {
if (mouse_record_y == 0) {
mouse_interval_delta = 0; mouse_report.x = mouse_move_x_sign;
} else {
mouse_interval_delta = (double)absY / (double)absX; if (can_move_min) {
} mouse_report.y = mouse_move_y_sign;
}
} }
is_record_mouse = false; mouse_report.x *= 1 + mouse_move_remain_count / 10;
mouse_record_count = 0; mouse_report.y *= 1 + mouse_move_remain_count / 10;
mouse_move_remain_count--;
} else {
mouse_report.x = 0;
mouse_report.y = 0;
} }
} }
else
if (mouse_move_remain_count > 0) { {
mouse_interval_counter += mouse_interval_delta; mouse_report.x *= user_config.trackball_movement_ratio;
mouse_report.y *= user_config.trackball_movement_ratio;
bool can_move_min = mouse_interval_counter >= 1;
if (can_move_min) {
mouse_interval_counter -= 1;
}
if (is_mouse_move_x_min) {
mouse_report.y = mouse_move_y_sign;
if (can_move_min) {
mouse_report.x = mouse_move_x_sign;
}
} else {
mouse_report.x = mouse_move_x_sign;
if (can_move_min) {
mouse_report.y = mouse_move_y_sign;
}
}
mouse_report.x *= 1 + mouse_move_remain_count / 10;
mouse_report.y *= 1 + mouse_move_remain_count / 10;
mouse_move_remain_count--;
} else {
mouse_report.x = 0;
mouse_report.y = 0;
} }
int16_t current_x = mouse_report.x; int16_t current_x = mouse_report.x;