static void loadController(GameController* controller) { // Query libscreen for information about this device. SCREEN_API(screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_TYPE, &controller->type), "SCREEN_PROPERTY_TYPE"); SCREEN_API(screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_ID_STRING, sizeof(controller->id), controller->id), "SCREEN_PROPERTY_ID_STRING"); SCREEN_API(screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_VENDOR, sizeof(controller->vendor), controller->vendor), "SCREEN_PROPERTY_VENDOR"); SCREEN_API(screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_PRODUCT, sizeof(controller->product), controller->product), "SCREEN_PROPERTY_PRODUCT"); SCREEN_API(screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_BUTTON_COUNT, &controller->buttonCount), "SCREEN_PROPERTY_BUTTON_COUNT"); if (controller->type == SCREEN_EVENT_GAMEPAD) { sprintf(controller->deviceString0, "Gamepad device ID: %s", controller->id); } else { sprintf(controller->deviceString0, "Joystick device: %s", controller->id); } if (strcmp(controller->vendor, "") == 0) { strcat(controller->vendor, "Unknown"); } if (strcmp(controller->product, "") == 0) { strcat(controller->product, "Unknown"); } sprintf(controller->deviceString1, "Vendor: %s, Product: %s, Button count: %d", controller->vendor, controller->product, controller->buttonCount); }
static void handle_device(void *data, input_device_t* controller) { int device; qnx_input_t *qnx = (qnx_input_t*)data; (void)device; if (!qnx) return; /* Query libscreen for information about this device. */ screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_TYPE, &controller->type); screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_ID_STRING, sizeof(controller->id), controller->id); screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_VENDOR, sizeof(controller->id), controller->vid); screen_get_device_property_cv(controller->handle, SCREEN_PROPERTY_PRODUCT, sizeof(controller->id), controller->pid); if (controller->type == SCREEN_EVENT_GAMEPAD || controller->type == SCREEN_EVENT_JOYSTICK) { screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_BUTTON_COUNT, &controller->buttonCount); /* Check for the existence of analog sticks. */ if (!screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_ANALOG0, controller->analog0)) ++controller->analogCount; if (!screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_ANALOG1, controller->analog1)) ++controller->analogCount; } /* Screen service will map supported controllers, * we still might need to adjust. */ qnx_input_autodetect_gamepad(qnx, controller, controller->port); if (controller->type == SCREEN_EVENT_GAMEPAD) RARCH_LOG("Gamepad Device Connected:\n"); else if (controller->type == SCREEN_EVENT_JOYSTICK) RARCH_LOG("Joystick Device Connected:\n"); else if (controller->type == SCREEN_EVENT_KEYBOARD) RARCH_LOG("Keyboard Device Connected:\n"); RARCH_LOG("\tID: %s\n", controller->id); RARCH_LOG("\tVendor ID: %s\n", controller->vid); RARCH_LOG("\tProduct ID: %s\n", controller->pid); RARCH_LOG("\tButton Count: %d\n", controller->buttonCount); RARCH_LOG("\tAnalog Count: %d\n", controller->analogCount); }
static void pollDevices() { int i; for (i = 0; i < MAX_CONTROLLERS; i++) { GameController* controller = &_controllers[i]; if (controller->handle) { // Get the current state of a gamepad device. SCREEN_API(screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_BUTTONS, &controller->buttons), "SCREEN_PROPERTY_BUTTONS"); SCREEN_API(screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_ANALOG0, controller->analog0), "SCREEN_PROPERTY_ANALOG0"); SCREEN_API(screen_get_device_property_iv(controller->handle, SCREEN_PROPERTY_ANALOG1, controller->analog1), "SCREEN_PROPERTY_ANALOG1"); } } }
void discoverControllers() { // Get an array of all available devices. int deviceCount; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount); screen_device_t* devices_found = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t)); screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices_found); // Scan the list for gamepad and joystick devices. int i; for(i=0;i<pads_connected;++i) initController(&devices[i]); pads_connected = 0; for (i = 0; i < deviceCount; i++) { int type; screen_get_device_property_iv(devices_found[i], SCREEN_PROPERTY_TYPE, &type); if (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD) { devices[pads_connected].handle = devices_found[i]; loadController(&devices[pads_connected]); pads_connected++; if (pads_connected == MAX_PADS) break; } } free(devices_found); }
static void discoverControllers() { // Get an array of all available devices. int deviceCount; SCREEN_API(screen_get_context_property_iv(_screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount), "SCREEN_PROPERTY_DEVICE_COUNT"); screen_device_t* devices = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t)); SCREEN_API(screen_get_context_property_pv(_screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices), "SCREEN_PROPERTY_DEVICES"); // Scan the list for gamepad and joystick devices. int i; int controllerIndex = 0; for (i = 0; i < deviceCount; i++) { int type; SCREEN_API(screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &type), "SCREEN_PROPERTY_TYPE"); if (!rc && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK)) { // Assign this device to control Player 1 or Player 2. GameController* controller = &_controllers[controllerIndex]; controller->handle = devices[i]; loadController(controller); // We'll just use the first compatible devices we find. controllerIndex++; if (controllerIndex == MAX_CONTROLLERS) { break; } } } free(devices); }
static void discoverControllers(void *data) { /* Get an array of all available devices. */ int deviceCount; unsigned i; screen_event_t *event; qnx_input_t *qnx = (qnx_input_t*)data; (void)event; screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount); screen_device_t* devices_found = (screen_device_t*) calloc(deviceCount, sizeof(screen_device_t)); screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices_found); /* Scan the list for gamepad and joystick devices. */ for(i = 0; i < qnx->pads_connected; ++i) initController(qnx, &qnx->devices[i]); qnx->pads_connected = 0; for (i = 0; i < deviceCount; i++) { int type; screen_get_device_property_iv( devices_found[i], SCREEN_PROPERTY_TYPE, &type); if ( type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD) { qnx->devices[qnx->pads_connected].handle = devices_found[i]; qnx->devices[qnx->pads_connected].index = qnx->pads_connected; handle_device(qnx, &qnx->devices[qnx->pads_connected]); if (qnx->pads_connected == MAX_PADS) break; } } free(devices_found); }
static void handle_screen_event(bps_event_t *event) { int type; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &type); switch(type) { case SCREEN_EVENT_MTOUCH_TOUCH: case SCREEN_EVENT_MTOUCH_RELEASE: case SCREEN_EVENT_MTOUCH_MOVE: process_touch_event(screen_event, type); break; case SCREEN_EVENT_KEYBOARD: process_keyboard_event(screen_event, type); break; #ifdef HAVE_BB10 case SCREEN_EVENT_GAMEPAD: case SCREEN_EVENT_JOYSTICK: process_gamepad_event(screen_event, type); break; case SCREEN_EVENT_DEVICE: { // A device was attached or removed. screen_device_t device; int attached; int type; screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ATTACHED, &attached); if (attached) screen_get_device_property_iv(device, SCREEN_PROPERTY_TYPE, &type); int i; if (attached && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD)) { for (i = 0; i < MAX_PADS; ++i) { if (!devices[i].handle) { devices[i].handle = device; loadController(&devices[i]); break; } } } else { for (i = 0; i < MAX_PADS; ++i) { if (device == devices[i].handle) { RARCH_LOG("Device %s: Disconnected.\n", devices[i].id); initController(&devices[i]); break; } } } } break; #endif default: break; } }
static void handleScreenEvent(bps_event_t *event) { int eventType; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType); switch (eventType) { case SCREEN_EVENT_GAMEPAD: case SCREEN_EVENT_JOYSTICK: { if (!_polling) { // Determine which controller this is. screen_device_t device; SCREEN_API(screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device), "SCREEN_PROPERTY_DEVICE"); GameController* controller = NULL; int i; for (i = 0; i < MAX_CONTROLLERS; ++i) { if (device == _controllers[i].handle) { controller = &_controllers[i]; break; } } if (!controller) { break; } // Store the controller's new state. SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &controller->buttons), "SCREEN_PROPERTY_BUTTONS"); SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ANALOG0, controller->analog0), "SCREEN_PROPERTY_ANALOG0"); if (controller->type == SCREEN_EVENT_GAMEPAD) { SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ANALOG1, controller->analog1), "SCREEN_PROPERTY_ANALOG1"); } } break; } case SCREEN_EVENT_DEVICE: { // A device was attached or removed. screen_device_t device; int attached; int type; SCREEN_API(screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device), "SCREEN_PROPERTY_DEVICE"); SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ATTACHED, &attached), "SCREEN_PROPERTY_ATTACHED"); if (attached) { SCREEN_API(screen_get_device_property_iv(device, SCREEN_PROPERTY_TYPE, &type), "SCREEN_PROPERTY_TYPE"); } int i; if (attached && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK)) { for (i = 0; i < MAX_CONTROLLERS; ++i) { if (!_controllers[i].handle) { _controllers[i].handle = device; loadController(&_controllers[i]); break; } } } else { for (i = 0; i < MAX_CONTROLLERS; ++i) { if (device == _controllers[i].handle) { initController(&_controllers[i], i); break; } } } break; } case SCREEN_EVENT_MTOUCH_RELEASE: { int pos[2]; SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pos), "SCREEN_PROPERTY_SOURCE_POSITION"); int x = pos[0]; int y = _surfaceHeight - pos[1]; int i; for (i = 0; i < MAX_CONTROLLERS; ++i) { bool buttonTapped = false; int j; for (j = 0; j < MAX_BUTTONS; ++j) { Button* button = &_buttons[i][j]; Quad* quad = button->quad; // Detect that a button was tapped. if (x > quad->x && x < quad->x + quad->width && y > quad->y && y < quad->y + quad->height) { _activeButton[i] = button; buttonTapped = true; break; } } if (_activeButton[i] && !buttonTapped) { // Cancel the button's active state. _activeButton[i] = NULL; } } // The polling button is used to switch between handling all device events and polling devices once per frame. Quad* quad = _pollingButton.quad; if (x > quad->x && x < quad->x + quad->width && y > quad->y && y < quad->y + quad->height) { _polling = !_polling; // The polling button lights up when polling is enabled. if (_polling) { quad->uvs = _triggerDownUVs; } else { quad->uvs = _triggerUpUVs; } } break; } } }
static void qnx_handle_screen_event(qnx_input_t *qnx, bps_event_t *event) { int type; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &type); switch(type) { case SCREEN_EVENT_MTOUCH_TOUCH: case SCREEN_EVENT_MTOUCH_RELEASE: case SCREEN_EVENT_MTOUCH_MOVE: qnx_process_touch_event(qnx, screen_event, type); break; case SCREEN_EVENT_KEYBOARD: qnx_process_keyboard_event(qnx, screen_event, type); break; #ifdef HAVE_BB10 case SCREEN_EVENT_GAMEPAD: qnx_process_gamepad_event(qnx, screen_event, type); break; case SCREEN_EVENT_JOYSTICK: qnx_process_joystick_event(qnx, screen_event, type); break; case SCREEN_EVENT_DEVICE: { /* A device was attached or removed. */ screen_device_t device; int attached, type, i; screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ATTACHED, &attached); if (attached) screen_get_device_property_iv(device, SCREEN_PROPERTY_TYPE, &type); if (attached && ( type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD) ) { for (i = 0; i < MAX_PADS; ++i) { if (!qnx->devices[i].handle) { qnx->devices[i].handle = device; qnx_handle_device(qnx, &qnx->devices[i]); break; } } } else { for (i = 0; i < MAX_PADS; ++i) { if (device == qnx->devices[i].handle) { RARCH_LOG("Device %s: Disconnected.\n", qnx->devices[i].id); qnx_init_controller(qnx, &qnx->devices[i]); break; } } } } break; #endif default: break; } }