From bdd8d563ff3f0eec41cc45d07f6c00622a531a72 Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Tue, 21 May 2024 22:51:55 -0600 Subject: first commit --- jsi/src/test.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 jsi/src/test.c (limited to 'jsi/src/test.c') diff --git a/jsi/src/test.c b/jsi/src/test.c new file mode 100644 index 0000000..fa34b01 --- /dev/null +++ b/jsi/src/test.c @@ -0,0 +1,45 @@ +/* + * jsi (Joystick interface) c libray +*/ + +#include "jsi.h" +#include +#include + +jsi_joystick a_joystick; + +void handle_sig(int sig) { + jsi_close_joystick(a_joystick); + putchar('\n'); + exit(0); +} + +int main() { + signal(SIGINT, handle_sig); + + puts("test"); + printf("joystick count: %d\n", jsi_joy_count()); + + if (jsi_get_joystick(0, &a_joystick) == -1) { + perror("Couldn't get joystick"); + return -1; + } + + printf("axes: %d, buttons: %d, name: %s\n", a_joystick.layout.axes, + a_joystick.layout.buttons, a_joystick.layout.name); + + struct jsi_event a_event; + + while (JSI_TRUE) { + + if (jsi_get_event(a_joystick, &a_event) == -1) { + perror("Error getting input"); + return -1; + } + + printf("value: %hx, type: %hx, num: %hx\n", a_event.value, a_event.type, a_event.num); + } + + jsi_close_joystick(a_joystick); + return 0; +} -- cgit v1.2.3