static void teardown() { printf("Exiting.\n"); SYSLOG(LOG_NOTICE, "Exiting."); input_xarcade_close(&xarcdev); uinput_gpad_close(&uinp_gpads[0]); uinput_gpad_close(&uinp_gpads[1]); uinput_kbd_close(&uinp_kbd); }
/* Signal callback function */ void sig_handler(int signo) { int16_t ctr = 0; if ((signo == SIGINT) | (signo == SIGQUIT) | (signo == SIGABRT) | (signo = SIGTERM)) { printf("Releasing SNESDev-Rpi device(s).\n"); pollButton = 0; pollPads = 0; uinput_kbd_close(&uinp_kbd); for (ctr = 0; ctr < GPADSNUM; ctr++) { uinput_gpad_close(&uinp_gpads[ctr]); } cfg_free(cfg); free(confres.gamepad1_type); free(confres.gamepad2_type); doRun = 0; } }
int main(int argc, char* argv[]) { int result = 0; int rd, ctr; int detach = 0; int opt; while ((opt = getopt(argc, argv, "+d")) != -1) { switch (opt) { case 'd': detach = 1; break; default: fprintf(stderr, "Usage: %s [-d]\n", argv[0]); exit(1); break; } } printf("[MadCatz] Getting exclusive access: "); result = input_madcatz_open(&madcatzdev, INPUT_MADCATZ_TYPE); printf("%s\n", (result == 0) ? "SUCCESS" : "FAILURE"); if (result != 0) { exit(-1); } uinput_gpad_open(&uinp_gpads[0], UINPUT_GPAD_TYPE_MADCATZ); uinput_kbd_open(&uinp_kbd); if (detach) { if (daemon(0, 1)) { perror("daemon"); return 1; } } while (1) { rd = input_madcatz_read(&madcatzdev); if (rd < 0) { break; } for (ctr = 0; ctr < rd; ctr++) { if (madcatzdev.ev[ctr].type == 0) continue; if (madcatzdev.ev[ctr].type == EV_MSC) continue; if (EV_ABS == madcatzdev.ev[ctr].type) { const __s32 value = madcatzdev.ev[ctr].value; switch (madcatzdev.ev[ctr].code) { case 0: /* LS x */ uinput_gpad_write(&uinp_gpads[0], ABS_X, value < 127 ? 0 : (value > 128 ? 4 : 2), EV_ABS); break; case 1: /* LS y */ uinput_gpad_write(&uinp_gpads[0], ABS_Y, value < 127 ? 0 : (value > 128 ? 4 : 2), EV_ABS); break; case 16: /* DP x */ uinput_gpad_write(&uinp_gpads[0], ABS_X, value < 0 ? 0 : (value > 0 ? 4 : 2), EV_ABS); break; case 17: /* DP y */ uinput_gpad_write(&uinp_gpads[0], ABS_Y, value < 0 ? 0 : (value > 0 ? 4 : 2), EV_ABS); break; case 2: /* RS x */ uinput_gpad_write(&uinp_gpads[0], ABS_X, value < 127 ? 0 : (value > 128 ? 4 : 2), EV_ABS); break; case 5: /* RS y */ uinput_gpad_write(&uinp_gpads[0], ABS_Y, value < 127 ? 0 : (value > 128 ? 4 : 2), EV_ABS); break; } } else if (EV_KEY == madcatzdev.ev[ctr].type) { switch (madcatzdev.ev[ctr].code) { case BTN_TL2: uinput_gpad_write(&uinp_gpads[0], BTN_SELECT, madcatzdev.ev[ctr].value, EV_KEY); break; case BTN_TR2: uinput_gpad_write(&uinp_gpads[0], BTN_START, madcatzdev.ev[ctr].value, EV_KEY); break; default: uinput_gpad_write(&uinp_gpads[0], madcatzdev.ev[ctr].code, madcatzdev.ev[ctr].value, EV_KEY); break; } } } } printf("Exiting.\n"); input_madcatz_close(&madcatzdev); uinput_gpad_close(&uinp_gpads[0]); uinput_gpad_close(&uinp_gpads[1]); uinput_kbd_close(&uinp_kbd); return 0; }