Skip to content

A library for interfacing with a twin joystick usb gamepad. Hardcoded for a specific model.

Notifications You must be signed in to change notification settings

Boerworz/libgamepad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libgamepad

A library for interfacing with a twin joystick usb gamepad. Hardcoded for a specific model (Vendor ID 0x0810, Product ID 0x0001).

Requires hidapi.

Usage

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

#include <libgamepad.h>

void button_callback(int controller, gp_event_type type, gp_state state, float x, float y) {
	const char *event_name = gp_event_name(type);
	const char *state_name = gp_state_name(state);
	printf("%d - %s --- %s\n", controller, event_name, state_name);
}

int main(int argc, char *argv[]) {
	if(gp_init() != 0) {
		fprintf(stderr, "Unable to init libgamepad.\n");
		exit(1);
	} else {
		printf("Found device.\n");
		gp_register(2, GP_1, &button_callback);
		gp_register(2, GP_3, &button_callback);
		gp_register(2, GP_SPECIAL_UP, &button_callback);
		// Note: GP_LEFT_JOYSTICK events are also generated by
		// the directional buttons when not in analog mode.
		gp_register(2, GP_LEFT_JOYSTICK, &button_callback);
		gp_register(1, GP_SELECT, &button_callback);
		gp_run();

		dispatch_main();
	}
	return 0;
}

About

A library for interfacing with a twin joystick usb gamepad. Hardcoded for a specific model.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages