forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91c9cc8
commit 0e61df8
Showing
13 changed files
with
1,703 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
keyboards/tarohayashi/killerwhale/solo/keymaps/via_layer_rgb_mod/add_joystick.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2021 Hayashi (@w_vwbw) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "add_joystick.h" | ||
#include "quantum.h" | ||
#include "analog.h" | ||
|
||
// ファイル内のみ変数 | ||
int16_t gp27_newt; | ||
int16_t gp28_newt; | ||
bool joystick_attached; | ||
|
||
keypos_t key_up; | ||
keypos_t key_left; | ||
keypos_t key_right; | ||
keypos_t key_down; | ||
bool pressed_up = false; | ||
bool pressed_down = false; | ||
bool pressed_left = false; | ||
bool pressed_right = false; | ||
|
||
void matrix_init_addedjoystick(void) { | ||
gp27_newt = analogReadPin(GP27); | ||
gp28_newt = analogReadPin(GP28); | ||
if(gp27_newt < NO_STICK_VAL || gp28_newt < NO_STICK_VAL ){ | ||
joystick_attached = false; | ||
}else{ | ||
joystick_attached = true; | ||
} | ||
key_up.row = 3; | ||
key_up.col = 6; | ||
key_left.row = 2; | ||
key_left.col = 6; | ||
key_right.row = 4; | ||
key_right.col = 6; | ||
key_down.row = 1; | ||
key_down.col = 6; | ||
} | ||
|
||
void matrix_scan_addedjoystick(void) { | ||
if(joystick_attached){ | ||
|
||
int8_t layer = layer_switch_get_layer(key_up); | ||
int16_t keycode_up = keymap_key_to_keycode(layer, key_up); | ||
int16_t keycode_left = keymap_key_to_keycode(layer, key_left); | ||
int16_t keycode_right = keymap_key_to_keycode(layer, key_right); | ||
int16_t keycode_down = keymap_key_to_keycode(layer, key_down); | ||
|
||
if(!pressed_left && analogReadPin(GP27) - 512 > STICK_OFFSET){ | ||
pressed_left = true; | ||
register_code(keycode_left); | ||
}else if(pressed_left && analogReadPin(GP27) - 512 < STICK_OFFSET){ | ||
pressed_left = false; | ||
unregister_code(keycode_left); | ||
}else if(!pressed_right && analogReadPin(GP27) - 512 < -STICK_OFFSET){ | ||
pressed_right = true; | ||
register_code(keycode_right); | ||
}else if (pressed_right && analogReadPin(GP27) - 512 > -STICK_OFFSET){ | ||
pressed_right = false; | ||
unregister_code(keycode_right); | ||
} | ||
|
||
if(!pressed_up && analogReadPin(GP28) - 512 > STICK_OFFSET){ | ||
pressed_up = true; | ||
register_code(keycode_up); | ||
}else if(pressed_up && analogReadPin(GP28) - 512 < STICK_OFFSET){ | ||
pressed_up = false; | ||
unregister_code(keycode_up); | ||
}else if(!pressed_down && analogReadPin(GP28) - 512 < -STICK_OFFSET){ | ||
pressed_down = true; | ||
register_code(keycode_down); | ||
}else if(pressed_down && analogReadPin(GP28) - 512 > -STICK_OFFSET){ | ||
pressed_down = false; | ||
unregister_code(keycode_down); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
keyboards/tarohayashi/killerwhale/solo/keymaps/via_layer_rgb_mod/add_joystick.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2021 Hayashi (@w_vwbw) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
#include "quantum.h" | ||
|
||
// ジョイスティックの定数 | ||
#define STICK_OFFSET 220 | ||
#define STICK_WAIT 50 | ||
#define NO_STICK_VAL 100 | ||
|
||
void matrix_init_addedjoystick(void); | ||
void matrix_scan_addedjoystick(void); |
Oops, something went wrong.