-
Notifications
You must be signed in to change notification settings - Fork 0
/
joystick.c
58 lines (48 loc) · 1.08 KB
/
joystick.c
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
#include <stdio.h>
#include <ncurses.h>
#include "gamepad.h"
#include "joystick.h"
int ch, i, j, k;
double output = 0;
static void update(GAMEPAD_DEVICE dev) {
float lx, ly, rx, ry;
if (!GamepadIsConnected(dev)) {
return;
}
GamepadStickNormXY(dev, STICK_LEFT, &lx, &ly);
GamepadStickNormXY(dev, STICK_RIGHT, &rx, &ry);
}
void init()
{
GamepadInit();
}
double read_joystick()
{
GamepadUpdate();
if (ch == 'r') {
for (i = 0; i != GAMEPAD_COUNT; ++i) {
GamepadSetRumble((GAMEPAD_DEVICE)i, 0.25f, 0.25f);
}
}
update(GAMEPAD_0);
i=0;
if (GamepadIsConnected(i)) {
for (j = 0; j != BUTTON_COUNT; ++j) {
if (GamepadButtonTriggered(i, j)) {
if (j != 0){
printf("button triggered: %d \n", j);
output = j;
}
}
}
for (k = 0; k != STICKDIR_COUNT; ++k) {
if (GamepadStickDirTriggered(i, 0, k)) {
if (j != 0){
printf("stick direction: %d \n", k);
output = k;
}
}
}
}
return(output);
}