-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_polling.ts
More file actions
236 lines (236 loc) · 10.9 KB
/
Copy pathbasic_polling.ts
File metadata and controls
236 lines (236 loc) · 10.9 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
codex_pad.onDisconnected(function () {
serial.writeLine("disconnected")
basic.showIcon(IconNames.No)
})
codex_pad.onConnected(function () {
serial.writeLine("connected")
basic.showIcon(IconNames.Yes)
})
basic.showIcon(IconNames.Happy)
codex_pad.startReceiverService("E4:66:E5:A2:24:5D")
basic.forever(function () {
codex_pad.update()
// check button UP state
if (codex_pad.pressed(codex_pad.Button.UP)) {
serial.writeLine("Button Up: pressed")
basic.showArrow(ArrowNames.North, 0)
} else if (codex_pad.released(codex_pad.Button.UP)) {
serial.writeLine("Button Up: released")
} else if (codex_pad.holding(codex_pad.Button.UP)) {
serial.writeLine("Button Up: holding")
}
// check button DOWN state
if (codex_pad.pressed(codex_pad.Button.DOWN)) {
serial.writeLine("Button Down: pressed")
basic.showArrow(ArrowNames.South, 0)
} else if (codex_pad.released(codex_pad.Button.DOWN)) {
serial.writeLine("Button Down: released")
} else if (codex_pad.holding(codex_pad.Button.DOWN)) {
serial.writeLine("Button Down: holding")
}
// check button LEFT state
if (codex_pad.pressed(codex_pad.Button.LEFT)) {
serial.writeLine("Button Left: pressed")
basic.showArrow(ArrowNames.West, 0)
} else if (codex_pad.released(codex_pad.Button.LEFT)) {
serial.writeLine("Button Left: released")
} else if (codex_pad.holding(codex_pad.Button.LEFT)) {
serial.writeLine("Button Left: holding")
}
// check button RIGHT state
if (codex_pad.pressed(codex_pad.Button.RIGHT)) {
serial.writeLine("Button Right: pressed")
basic.showArrow(ArrowNames.East, 0)
} else if (codex_pad.released(codex_pad.Button.RIGHT)) {
serial.writeLine("Button Right: released")
} else if (codex_pad.holding(codex_pad.Button.RIGHT)) {
serial.writeLine("Button Right: holding")
}
// check button SQUARE_X state
if (codex_pad.pressed(codex_pad.Button.SQUARE_X)) {
serial.writeLine("Button Square(X): pressed")
basic.showString("X", 0)
} else if (codex_pad.released(codex_pad.Button.SQUARE_X)) {
serial.writeLine("Button Square(X): released")
} else if (codex_pad.holding(codex_pad.Button.SQUARE_X)) {
serial.writeLine("Button Square(X): holding")
}
// check button TRIANGLE_Y state
if (codex_pad.pressed(codex_pad.Button.TRIANGLE_Y)) {
serial.writeLine("Button Triangle(Y): pressed")
basic.showString("Y", 0)
} else if (codex_pad.released(codex_pad.Button.TRIANGLE_Y)) {
serial.writeLine("Button Triangle(Y): released")
} else if (codex_pad.holding(codex_pad.Button.TRIANGLE_Y)) {
serial.writeLine("Button Triangle(Y): holding")
}
// check button CIRCLE_B state
if (codex_pad.pressed(codex_pad.Button.CIRCLE_B)) {
serial.writeLine("Button Circle(B): pressed")
basic.showString("B", 0)
} else if (codex_pad.released(codex_pad.Button.CIRCLE_B)) {
serial.writeLine("Button Circle(B): released")
} else if (codex_pad.holding(codex_pad.Button.CIRCLE_B)) {
serial.writeLine("Button Circle(B): holding")
}
// check button CROSS_A state
if (codex_pad.pressed(codex_pad.Button.CROSS_A)) {
serial.writeLine("Button Cross(A): pressed")
basic.showString("A", 0)
} else if (codex_pad.released(codex_pad.Button.CROSS_A)) {
serial.writeLine("Button Cross(A): released")
} else if (codex_pad.holding(codex_pad.Button.CROSS_A)) {
serial.writeLine("Button Cross(A): holding")
}
// check button L1 state
if (codex_pad.pressed(codex_pad.Button.L1)) {
serial.writeLine("Button L1: pressed")
basic.showString("1", 0)
} else if (codex_pad.released(codex_pad.Button.L1)) {
serial.writeLine("Button L1: released")
} else if (codex_pad.holding(codex_pad.Button.L1)) {
serial.writeLine("Button L1: holding")
}
// check button L2 state
if (codex_pad.pressed(codex_pad.Button.L2)) {
serial.writeLine("Button L2: pressed")
basic.showString("2", 0)
} else if (codex_pad.released(codex_pad.Button.L2)) {
serial.writeLine("Button L2: released")
} else if (codex_pad.holding(codex_pad.Button.L2)) {
serial.writeLine("Button L2: holding")
}
// check button L3 state
if (codex_pad.pressed(codex_pad.Button.L3)) {
serial.writeLine("Button L3: pressed")
basic.showString("3", 0)
} else if (codex_pad.released(codex_pad.Button.L3)) {
serial.writeLine("Button L3: released")
} else if (codex_pad.holding(codex_pad.Button.L3)) {
serial.writeLine("Button L3: holding")
}
// check button R1 state
if (codex_pad.pressed(codex_pad.Button.R1)) {
serial.writeLine("Button R1: pressed")
basic.showString("4", 0)
} else if (codex_pad.released(codex_pad.Button.R1)) {
serial.writeLine("Button R1: released")
} else if (codex_pad.holding(codex_pad.Button.R1)) {
serial.writeLine("Button R1: holding")
}
// check button R2 state
if (codex_pad.pressed(codex_pad.Button.R2)) {
serial.writeLine("Button R2: pressed")
basic.showString("5", 0)
} else if (codex_pad.released(codex_pad.Button.R2)) {
serial.writeLine("Button R2: released")
} else if (codex_pad.holding(codex_pad.Button.R2)) {
serial.writeLine("Button R2: holding")
}
// check button R3 state
if (codex_pad.pressed(codex_pad.Button.R3)) {
serial.writeLine("Button R3: pressed")
basic.showString("6", 0)
} else if (codex_pad.released(codex_pad.Button.R3)) {
serial.writeLine("Button R3: released")
} else if (codex_pad.holding(codex_pad.Button.R3)) {
serial.writeLine("Button R3: holding")
}
// check button SELECT state
if (codex_pad.pressed(codex_pad.Button.SELECT)) {
serial.writeLine("Button Select: pressed")
basic.showString("7", 0)
} else if (codex_pad.released(codex_pad.Button.SELECT)) {
serial.writeLine("Button Select: released")
} else if (codex_pad.holding(codex_pad.Button.SELECT)) {
serial.writeLine("Button Select: holding")
}
// check button START state
if (codex_pad.pressed(codex_pad.Button.START)) {
serial.writeLine("Button Start: pressed")
basic.showString("8", 0)
} else if (codex_pad.released(codex_pad.Button.START)) {
serial.writeLine("Button Start: released")
} else if (codex_pad.holding(codex_pad.Button.START)) {
serial.writeLine("Button Start: holding")
}
// check button HOME state
if (codex_pad.pressed(codex_pad.Button.HOME)) {
serial.writeLine("Button Home: pressed")
basic.showString("9", 0)
} else if (codex_pad.released(codex_pad.Button.HOME)) {
serial.writeLine("Button Home: released")
} else if (codex_pad.holding(codex_pad.Button.HOME)) {
serial.writeLine("Button Home: holding")
}
// check axis state
if (codex_pad.hasAxisValueChanged(codex_pad.Axis.LEFT_STICK_X, 2) || codex_pad.hasAxisValueChanged(codex_pad.Axis.LEFT_STICK_Y, 2) || codex_pad.hasAxisValueChanged(codex_pad.Axis.RIGHT_STICK_X, 2) || codex_pad.hasAxisValueChanged(codex_pad.Axis.RIGHT_STICK_Y, 2)) {
serial.writeLine("L(" + codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_X) + ", " + codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_Y) + "), R(" + codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_X) + ", " + codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_Y) + ")")
if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_X) <= 16) {
if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_Y) <= 16) {
basic.showArrow(ArrowNames.SouthWest, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_Y) >= 240) {
basic.showArrow(ArrowNames.NorthWest, 0)
} else {
basic.showArrow(ArrowNames.West, 0)
}
} else if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_X) >= 240) {
if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_Y) <= 16) {
basic.showArrow(ArrowNames.SouthEast, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_Y) >= 240) {
basic.showArrow(ArrowNames.NorthEast, 0)
} else {
basic.showArrow(ArrowNames.East, 0)
}
} else if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_Y) <= 16) {
if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_X) <= 16) {
basic.showArrow(ArrowNames.SouthWest, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_X) >= 240) {
basic.showArrow(ArrowNames.SouthEast, 0)
} else {
basic.showArrow(ArrowNames.South, 0)
}
} else if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_Y) >= 240) {
if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_X) <= 16) {
basic.showArrow(ArrowNames.NorthWest, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.LEFT_STICK_X) >= 240) {
basic.showArrow(ArrowNames.NorthEast, 0)
} else {
basic.showArrow(ArrowNames.North, 0)
}
}
if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_X) <= 16) {
if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_Y) <= 16) {
basic.showArrow(ArrowNames.SouthWest, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_Y) >= 240) {
basic.showArrow(ArrowNames.NorthWest, 0)
} else {
basic.showArrow(ArrowNames.West, 0)
}
} else if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_X) >= 240) {
if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_Y) <= 16) {
basic.showArrow(ArrowNames.SouthEast, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_Y) >= 240) {
basic.showArrow(ArrowNames.NorthEast, 0)
} else {
basic.showArrow(ArrowNames.East, 0)
}
} else if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_Y) <= 16) {
if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_X) <= 16) {
basic.showArrow(ArrowNames.SouthWest, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_X) >= 240) {
basic.showArrow(ArrowNames.SouthEast, 0)
} else {
basic.showArrow(ArrowNames.South, 0)
}
} else if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_Y) >= 240) {
if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_X) <= 16) {
basic.showArrow(ArrowNames.NorthWest, 0)
} else if (codex_pad.axisValue(codex_pad.Axis.RIGHT_STICK_X) >= 240) {
basic.showArrow(ArrowNames.NorthEast, 0)
} else {
basic.showArrow(ArrowNames.North, 0)
}
}
}
})