-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardToSplatoon.gpc
218 lines (210 loc) · 5.78 KB
/
KeyboardToSplatoon.gpc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#pragma METAINFO("Mouse to Splatoon", 1, 72, "Edited by: DaMu, Originally Created by: nspl")
#include <switch.gph>
#include <mouse.gph>
#include <display.gph>
#define segTime 1500
#define SEGMAX 5
#define MAXGX 25.0
#define DEFAULT_MMY 0.0
#define MAXR 212.5
uint8 status_a, status_b, status_j, protocol_a, protocol_b, protocol_j, device_a, device_b, device_j;
uint8 seg = 0;
fix32 mmy;
bool y_toggle = FALSE;
bool e_toggle = FALSE;
bool r_toggle = FALSE;
// GIVMXYF:FF0014008000000002000200FC00050A0F14191E23282D32373C41464B50555A5F64
const uint8 mmap[] = { 0x04, 0x04, 0x05, 0x07, 0x06, 0x03, 0x00, 0x15, 0x01, 0x16 };
const uint8 mxyc[] = { 0xFF, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0xFC, 0x00, 0x05, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x23, 0x28, 0x2D, 0x32, 0x37, 0x3C, 0x41, 0x46, 0x4B, 0x50, 0x55, 0x5A, 0x5F, 0x64 };
// Load an Mouse Mapping to reproduce the default BF1 layout
const uint8 custom_mmap[] = {
MOUSE_X, SWITCH_RX,
MOUSE_Y, SWITCH_RY,
MWHEEL_FORWARD, SWITCH_R,
MWHEEL_BACKWARD, SWITCH_R,
MBUTTON_1, SWITCH_ZR,
MBUTTON_2, SWITCH_R,
MBUTTON_3, SWITCH_RS,
MBUTTON_4, SWITCH_Y,
MBUTTON_5, SWITCH_B,
};
uint8 segDis () {
status_a = port_status(PORT_USB_A, &protocol_a, &device_a);
status_b = port_status(PORT_USB_B, &protocol_b, &device_b);
if((status_b & DIR_INPUT) && (protocol_b == PROTOCOL_HID)) {
printf("%u", device_a);
return(_M_);
}
return(_T_);
}
uint8 segDisRepeat (uint8 i) {
status_a = port_status(PORT_USB_A, &protocol_a, &device_b);
status_b = port_status(PORT_USB_B, &protocol_b, &device_b);
const uint8 mouseName[5] = {
_M_, _O_, _U_, _S_, _E_
},
noController[5] = {
_N_, _O_, _T_, _I_, _T_
};
if((status_b & DIR_INPUT) && (protocol_b == PROTOCOL_HID)) {
return(mouseName[i]);
}
return(noController[i]);
}
bool getJoyCon (){
port_connect(PORT_BT_A, PROTOCOL_SWITCH);
status_j = port_status(PORT_BT_A, &protocol_j, &device_j);
if((status_j & !DIR_INPUT) || (protocol_j != PROTOCOL_SWITCH)){
printf("no Joy-Con".);
return FALSE;
};
printf("%u", device_j);
return TRUE;
}
void JoyConButtons(){
set_val(SWITCH_A, get_actual(SWITCH_SL));
set_val(SWITCH_X, get_actual(SWITCH_SR));
}
init {
display_overlay(segDis(), segTime);
// keymapping(kmap);
if(!mousemapping(custom_mmap)){
printf("Mouse mapping failed!");
}
if(!mxyconverter(mxyc)){
printf("Mouse converter failed!");
}
mmy = DEFAULT_MMY;
getJoyCon();
}
main {
if(mod((fix32)system_time(), (fix32)segTime) == 0.0) {
display_overlay(segDisRepeat(seg), segTime);
seg++;
if(seg >= SEGMAX) {
seg = 0;
}
}
set_val(SWITCH_ACCX, 0.0);
set_val(SWITCH_ACCY,0.0 );
set_val(SWITCH_ACCZ,0.0 );
set_val(SWITCH_GYROX, 0.0 );
set_val(SWITCH_GYROY, 0.0 );
set_val(SWITCH_GYROZ, 0.0 );
gyro_aim();
JoyConButtons();
// shortcutsAndCombos();
}
void gyro_aim(){
fix32 my = rad2deg(get_val(SWITCH_RY) / 840.0 * PI) / MAXGX;
mmy = clamp( mmy + my , -MAXGX , MAXGX );
set_val(SWITCH_ACCY, mmy );
if( abs(mmy) != MAXGX ){
fix32 mybak = rad2deg(get_val(SWITCH_RY) / 440.0 * PI) / (MAXGX - 4.2);
set_val(SWITCH_GYROX, mybak * MAXR );
//set_val(SWITCH_GYROX, my * MAXR );
}
else {
set_val(SWITCH_GYROX,0.0);
}
set_val(SWITCH_ACCZ, abs(get_val(SWITCH_ACCY)) - 25.0 );
fix32 gyroz = rad2deg(get_val(SWITCH_RX) / 240.0 * PI) / 45.0 * MAXR;
set_val(SWITCH_GYROZ, gyroz * -get_val(SWITCH_ACCZ) / 25.0 );
set_val(SWITCH_GYROY, gyroz * -get_val(SWITCH_ACCY) / 25.0 );
set_val(SWITCH_ACCX, 0.0 );
set_val(SWITCH_RY, 0.0);
set_val(SWITCH_RX, 0.0);
}
void shortcutsAndCombos() {
/*
if(event_active(SWITCH_Y)) {
y_toggle = !y_toggle;
mmy = DEFAULT_MMY;
}
*/
if(event_active(MBUTTON_2)) {
r_toggle = !r_toggle;
printf("%d", r_toggle);
}
// set_val(SWITCH_Y, y_toggle);
set_val(SWITCH_R, r_toggle);
/*
if(key_status(KEY_LEFTCONTROL)) {
if(get_val(SWITCH_LX) && get_val(SWITCH_LY)) {
set_val(SWITCH_LX, clamp(get_val(SWITCH_LX), -57.0, 57.0));
set_val(SWITCH_LY, clamp(get_val(SWITCH_LY), -57.0, 57.0));
}
else {
set_val(SWITCH_LX, clamp(get_val(SWITCH_LX), -83.0, 83.0));
set_val(SWITCH_LY, clamp(get_val(SWITCH_LY), -83.0, 83.0));
}
}
else {
set_val(SWITCH_LX, clamp(get_val(SWITCH_LX), -100.0, 100.0));
set_val(SWITCH_LY, clamp(get_val(SWITCH_LY), -100.0, 100.0));
}
if(key_status(KEY_H)) {
combo_run(home);
}
if(get_val(SWITCH_DOWN)) {
combo_run(booya);
}
if(key_status(KEY_T)) {
mmy = DEFAULT_MMY;
combo_run(cam_reset);
}
if(key_status(KEY_P) && e_toggle == FALSE) {
combo_run(quickswim_thr);
combo_run(quickswim_swm);
e_toggle = TRUE;
}
else if(key_status(KEY_P) && e_toggle == TRUE) {
set_val(SWITCH_ZL, 100.0);
}
else if(!key_status(KEY_P)) {
e_toggle = FALSE;
}
*/
}
combo home {
set_val(SWITCH_X, 100.0);
//wait(50);
set_val(SWITCH_DOWN, 100.0);
//wait(50);
set_val(SWITCH_A, 100.0);
//wait(50);
}
combo booya {
set_val(SWITCH_DOWN, 100.0);
wait(70);
set_val(SWITCH_DOWN, 0.0);
wait(70);
}
combo cam_reset {
set_val(SWITCH_Y, 100.0);
wait(70);
set_val(SWITCH_Y, 0.0);
wait(70);
}
combo quickswim_thr {
set_val(SWITCH_ZL, 0.0);
set_val(SWITCH_R, 100.0);
wait(500);
}
combo quickswim_swm {
wait(50);
set_val(SWITCH_ZL, 100.0);
wait(500);
}