///////////////////////////////////////////////////////
| 498 | |
| 499 | //////////////////////////////////////////////////////////// |
| 500 | bool JoystickImpl::open(unsigned int index) |
| 501 | { |
| 502 | if (index >= joystickList.size()) |
| 503 | return false; |
| 504 | |
| 505 | if (joystickList[index].plugged) |
| 506 | { |
| 507 | const std::string devnode = joystickList[index].deviceNode; |
| 508 | |
| 509 | // Open the joystick's file descriptor (read-only and non-blocking) |
| 510 | m_file = ::open(devnode.c_str(), O_RDONLY | O_NONBLOCK); |
| 511 | if (m_file >= 0) |
| 512 | { |
| 513 | // Retrieve the axes mapping |
| 514 | ioctl(m_file, JSIOCGAXMAP, m_mapping.data()); |
| 515 | |
| 516 | // Get info |
| 517 | m_identification.name = getJoystickName(index); |
| 518 | |
| 519 | if (udevContext) |
| 520 | { |
| 521 | m_identification.vendorId = getJoystickVendorId(index); |
| 522 | m_identification.productId = getJoystickProductId(index); |
| 523 | } |
| 524 | |
| 525 | // Reset the joystick state |
| 526 | m_state = JoystickState(); |
| 527 | |
| 528 | return true; |
| 529 | } |
| 530 | |
| 531 | err() << "Failed to open joystick " << devnode << ": " << errno << std::endl; |
| 532 | } |
| 533 | |
| 534 | return false; |
| 535 | } |
| 536 | |
| 537 | |
| 538 | //////////////////////////////////////////////////////////// |
nothing calls this directly
no test coverage detected