forked from mirrors/qmk_firmware
Merge remote-tracking branch 'origin/master' into develop
This commit is contained in:
commit
e938c663e5
1 changed files with 131 additions and 69 deletions
|
@ -3,12 +3,24 @@
|
|||
|
||||
#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 {
|
||||
KC_MY_BTN1 = SAFE_RANGE,
|
||||
KC_MY_BTN2,
|
||||
KC_MY_BTN3,
|
||||
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 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_y;
|
||||
|
@ -113,8 +124,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|||
),
|
||||
|
||||
LAYOUT(
|
||||
RGB_TOG, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, KC_NO, KC_NO, KC_NO, 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_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, 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,
|
||||
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
|
||||
void enable_click_layer(void) {
|
||||
layer_on(click_layer);
|
||||
|
@ -152,7 +174,7 @@ int16_t my_abs(int16_t num) {
|
|||
}
|
||||
|
||||
// 自前の符号を返す関数。 Function to return the sign.
|
||||
int16_t mmouse_move_y_sign(int16_t num) {
|
||||
int16_t my_sign(int16_t num) {
|
||||
if (num < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -203,6 +225,38 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|||
}
|
||||
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:
|
||||
if (record->event.pressed) {
|
||||
disable_click_layer();
|
||||
|
@ -216,6 +270,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|||
|
||||
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
||||
|
||||
if (user_config.mode == 0)
|
||||
{
|
||||
if (!is_record_mouse) {
|
||||
if (mouse_report.x != 0 || mouse_report.y != 0) {
|
||||
is_record_mouse = true;
|
||||
|
@ -226,8 +282,8 @@ report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
|||
}
|
||||
|
||||
if (is_record_mouse) {
|
||||
mouse_record_x += mouse_report.x;
|
||||
mouse_record_y += mouse_report.y;
|
||||
mouse_record_x += mouse_report.x; // * user_config.trackball_movement_ratio;
|
||||
mouse_record_y += mouse_report.y; // * user_config.trackball_movement_ratio;
|
||||
mouse_record_count++;
|
||||
|
||||
if (mouse_record_count >= mouse_record_threshold) {
|
||||
|
@ -236,11 +292,11 @@ report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
|||
int16_t absY = my_abs(mouse_record_y);
|
||||
is_mouse_move_x_min = absX < absY;
|
||||
|
||||
mouse_move_remain_count = absY + absX;
|
||||
mouse_move_remain_count *= mouse_move_count_ratio;
|
||||
mouse_move_remain_count = is_mouse_move_x_min ? absY : absX;
|
||||
mouse_move_remain_count *= user_config.trackball_movement_ratio;
|
||||
|
||||
mouse_move_x_sign = mmouse_move_y_sign(mouse_record_x);
|
||||
mouse_move_y_sign = mmouse_move_y_sign(mouse_record_y);
|
||||
mouse_move_x_sign = my_sign(mouse_record_x);
|
||||
mouse_move_y_sign = my_sign(mouse_record_y);
|
||||
|
||||
if (is_mouse_move_x_min) {
|
||||
if (mouse_record_x == 0) {
|
||||
|
@ -264,10 +320,10 @@ report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
|||
if (mouse_move_remain_count > 0) {
|
||||
mouse_interval_counter += mouse_interval_delta;
|
||||
|
||||
bool can_move_min = mouse_interval_counter >= 1;
|
||||
bool can_move_min = mouse_interval_counter >= 0.99;
|
||||
|
||||
if (can_move_min) {
|
||||
mouse_interval_counter -= 1;
|
||||
mouse_interval_counter -= 0.99;
|
||||
}
|
||||
|
||||
if (is_mouse_move_x_min) {
|
||||
|
@ -294,6 +350,12 @@ report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
|
|||
mouse_report.x = 0;
|
||||
mouse_report.y = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mouse_report.x *= user_config.trackball_movement_ratio;
|
||||
mouse_report.y *= user_config.trackball_movement_ratio;
|
||||
}
|
||||
|
||||
int16_t current_x = mouse_report.x;
|
||||
int16_t current_y = mouse_report.y;
|
||||
|
|
Loading…
Reference in a new issue