-
Notifications
You must be signed in to change notification settings - Fork 6
/
demo.js
84 lines (72 loc) · 1.81 KB
/
demo.js
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
const VGen = require("./vgen-xbox.js")
const _vgen = new VGen();
try {
// Try plugging in first controller
_vgen.plugin(1);
startDemo();
}
catch (e) {
// Exception most probably due to drivers not installed
_vgen.installDriver(() => {
_vgen.plugin(1);
startDemo();
});
}
function startDemo() {
console.log("starting demo");
rLeft(0);
rRight(0);
buttons(0);
dpad(0);
}
function rLeft(x) {
_vgen.setAxisL(1, Math.sin(x), Math.cos(x));
setTimeout(function() {
rLeft(x + 0.1);
}, 100);
}
function rRight(x) {
_vgen.setAxisR(1, Math.sin(x), Math.cos(x));
setTimeout(function() {
rRight(x + 0.1);
}, 100);
}
function dpad(x) {
var arr = [];
arr[0] = _vgen.Dpad.NONE;
arr[1] = _vgen.Dpad.UP;
arr[2] = _vgen.Dpad.UP_RIGHT;
arr[3] = _vgen.Dpad.RIGHT;
arr[4] = _vgen.Dpad.DOWN_RIGHT;
arr[5] = _vgen.Dpad.DOWN;
arr[6] = _vgen.Dpad.DOWN_LEFT;
arr[7] = _vgen.Dpad.LEFT;
arr[8] = _vgen.Dpad.UP_LEFT;
arr[9] = _vgen.Dpad.UP;
_vgen.setDpad(1, arr[x]);
setTimeout(function() {
dpad((x + 1) % arr.length);
}, 250);
}
function buttons(x) {
var arr = [];
arr[0] = _vgen.Buttons.A;
arr[1] = _vgen.Buttons.B;
arr[2] = _vgen.Buttons.X;
arr[3] = _vgen.Buttons.Y;
arr[4] = _vgen.Buttons.LEFT_SHOULDER;
arr[5] = _vgen.Buttons.RIGHT_SHOULDER;
arr[6] = _vgen.Buttons.BACK;
arr[7] = _vgen.Buttons.START;
arr[8] = _vgen.Buttons.LEFT_THUMB;
arr[9] = _vgen.Buttons.RIGHT_THUMB;
_vgen.setButton(1, arr[0] | arr[1]
| arr[2] | arr[3]
| arr[4] | arr[5]
| arr[6] | arr[7]
| arr[8] | arr[9], false);
_vgen.setButton(1, arr[x], true);
setTimeout(function() {
buttons((x + 1) % arr.length);
}, 250);
}