Beispiel #1
0
int main(int argc, char* argv[]) {
    init();
    if (argc > 1) load_mappings(argv[1]);

    printf("Listening for gamepads...\n");
    while (1) {
        SDL_WaitEvent(NULL);

        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                quit();
            }
            else if (event.type == SDL_CONTROLLERDEVICEADDED) {
                printf("Gamepad connected (index: %d)\n", event.cdevice.which);
                add_controller(event.cdevice.which);
            }
            else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
                printf("Gamepad disconnected (instance id: %d)\n",
                       event.cdevice.which);

                // Close the controller and free its slot in our array (if it
                // is currently in our array)
                remove_controller(event.cdevice.which);
            }
            else if (event.type == SDL_CONTROLLERBUTTONDOWN) {
                process_button(event.cbutton.which, event.cbutton.button);
            }
        }
    }

    return 0;
}
Beispiel #2
0
static void mgmt_index_removed(int sk, void *buf, size_t len)
{
	struct mgmt_ev_index_removed *ev = buf;
	uint16_t index;

	if (len < sizeof(*ev)) {
		error("Too small index removed event");
		return;
	}

	index = btohs(bt_get_unaligned(&ev->index));

	remove_controller(index);
}
static void mgmt_index_removed(int sk, uint16_t index)
{
	remove_controller(index);
}
Beispiel #4
0
/*
 * We pass in the current controller pointer (currp) so we can double check
 * that we aren't corrupting the list by removing the element we are on.  This
 * should never happen, but it doesn't hurt to double check.
 */
static void
remove_invalid_controller(char *name, controller_t *currp,
    struct search_args *args)
{
	controller_t *cp;
	bus_t *bp;
	controller_t *prevp;

	bp = args->bus_listp;
	while (bp != NULL) {
		int i;

		for (i = 0; bp->controllers[i]; i++) {
			if (libdiskmgt_str_eq(bp->controllers[i]->name, name)) {
				int j;
				/*
				 * remove pointer to invalid controller.
				 * (it is a path)
				 */
				for (j = i; bp->controllers[j]; j++) {
					bp->controllers[j] =
					    bp->controllers[j + 1];
				}
			}
		}
		bp = bp->next;
	}

	if (args->controller_listp == NULL) {
		return;
	}

	cp = args->controller_listp;
	if (libdiskmgt_str_eq(cp->name, name)) {
		args->controller_listp = cp->next;
		if (dm_debug) {
			(void) fprintf(stderr,
			    "INFO: Removed controller %s from list\n",
			    cp->name);
		}
		remove_controller(cp, currp);
		return;
	}

	prevp = cp;
	cp = cp->next;
	while (cp != NULL) {
		if (libdiskmgt_str_eq(cp->name, name)) {
			if (dm_debug) {
				(void) fprintf(stderr,
				    "INFO: Removed controller %s from list\n",
				    cp->name);
			}
			prevp->next = cp->next;
			remove_controller(cp, currp);
			return;
		}
		prevp = cp;
		cp = cp->next;
	}
}