bool CPeripheralAddon::Register(unsigned int peripheralIndex, const PeripheralPtr& peripheral) { if (!peripheral) return false; CSingleLock lock(m_critSection); if (m_peripherals.find(peripheralIndex) == m_peripherals.end()) { if (peripheral->Type() == PERIPHERAL_JOYSTICK) { m_peripherals[peripheralIndex] = std::static_pointer_cast<CPeripheralJoystick>(peripheral); CLog::Log(LOGNOTICE, "%s - new %s device registered on %s->%s: %s", __FUNCTION__, PeripheralTypeTranslator::TypeToString(peripheral->Type()), PeripheralTypeTranslator::BusTypeToString(PERIPHERAL_BUS_ADDON), peripheral->Location().c_str(), peripheral->DeviceName().c_str()); return true; } } return false; }
void CPeripheralBus::Register(const PeripheralPtr& peripheral) { if (!peripheral) return; bool bPeripheralAdded = false; { CSingleLock lock(m_critSection); if (!HasPeripheral(peripheral->Location())) { m_peripherals.push_back(peripheral); bPeripheralAdded = true; } } if (bPeripheralAdded) { CLog::Log(LOGNOTICE, "%s - new %s device registered on %s->%s: %s (%s:%s)", __FUNCTION__, PeripheralTypeTranslator::TypeToString(peripheral->Type()), PeripheralTypeTranslator::BusTypeToString(m_type), peripheral->Location().c_str(), peripheral->DeviceName().c_str(), peripheral->VendorIdAsString(), peripheral->ProductIdAsString()); m_manager.OnDeviceAdded(*this, *peripheral); } }
bool CPeripheralAddon::ProcessEvents(void) { if (!m_bProvidesJoysticks) return false; PERIPHERAL_ERROR retVal; unsigned int eventCount = 0; PERIPHERAL_EVENT* pEvents = NULL; LogError(retVal = m_pStruct->GetEvents(&eventCount, &pEvents), "GetEvents()"); if (retVal == PERIPHERAL_NO_ERROR) { for (unsigned int i = 0; i < eventCount; i++) { ADDON::PeripheralEvent event(pEvents[i]); PeripheralPtr device = GetPeripheral(event.PeripheralIndex()); if (!device) continue; switch (device->Type()) { case PERIPHERAL_JOYSTICK: { std::shared_ptr<CPeripheralJoystick> joystickDevice = std::static_pointer_cast<CPeripheralJoystick>(device); switch (event.Type()) { case PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON: { const bool bPressed = (event.ButtonState() == JOYSTICK_STATE_BUTTON_PRESSED); CLog::Log(LOGDEBUG, "Button [ %u ] on %s %s", event.DriverIndex(), joystickDevice->DeviceName().c_str(), bPressed ? "pressed" : "released"); if (joystickDevice->OnButtonMotion(event.DriverIndex(), bPressed)) CLog::Log(LOGDEBUG, "Joystick button event handled"); break; } case PERIPHERAL_EVENT_TYPE_DRIVER_HAT: { const HAT_STATE state = CPeripheralAddonTranslator::TranslateHatState(event.HatState()); CLog::Log(LOGDEBUG, "Hat [ %u ] on %s %s", event.DriverIndex(), joystickDevice->DeviceName().c_str(), CJoystickTranslator::HatStateToString(state)); if (joystickDevice->OnHatMotion(event.DriverIndex(), state)) CLog::Log(LOGDEBUG, "Joystick hat event handled"); break; } case PERIPHERAL_EVENT_TYPE_DRIVER_AXIS: { joystickDevice->OnAxisMotion(event.DriverIndex(), event.AxisState()); break; } default: break; } break; } default: break; } } for (auto it : m_peripherals) { if (it.second->Type() == PERIPHERAL_JOYSTICK) std::static_pointer_cast<CPeripheralJoystick>(it.second)->ProcessAxisMotions(); } m_pStruct->FreeEvents(eventCount, pEvents); return true; } return false; }