CButtonMapping::CButtonMapping(IButtonMapper* buttonMapper, IButtonMap* buttonMap, IKeymap* keymap) : m_buttonMapper(buttonMapper), m_buttonMap(buttonMap), m_keymap(keymap), m_lastAction(0), m_frameCount(0) { assert(m_buttonMapper != nullptr); assert(m_buttonMap != nullptr); // Make sure axes mapped to Select are centered before they can be mapped. // This ensures that they are not immediately mapped to the first button. if (m_keymap) { using namespace GAME; CControllerManager& controllerManager = CServiceBroker::GetGameControllerManager(); ControllerPtr controller = controllerManager.GetController(m_keymap->ControllerID()); const auto& features = controller->Features(); for (const auto& feature : features) { bool bIsSelectAction = false; const auto &actions = m_keymap->GetActions(CJoystickUtils::MakeKeyName(feature.Name())).actions; if (!actions.empty() && actions.begin()->actionId == ACTION_SELECT_ITEM) bIsSelectAction = true; if (!bIsSelectAction) continue; CDriverPrimitive primitive; if (!m_buttonMap->GetScalar(feature.Name(), primitive)) continue; if (primitive.Type() != PRIMITIVE_TYPE::SEMIAXIS) continue; // Set initial config, as detection will fail because axis is already activated AxisConfiguration axisConfig; axisConfig.bKnown = true; axisConfig.center = primitive.Center(); axisConfig.range = primitive.Range(); GetAxis(primitive.Index(), static_cast<float>(primitive.Center()), axisConfig).SetEmitted(primitive); } } }
ADDON::DriverPrimitive CPeripheralAddonTranslator::TranslatePrimitive(const CDriverPrimitive& primitive) { ADDON::DriverPrimitive retVal; switch (primitive.Type()) { case BUTTON: { retVal = ADDON::DriverPrimitive::CreateButton(primitive.Index()); break; } case HAT: { retVal = ADDON::DriverPrimitive(primitive.Index(), TranslateHatDirection(primitive.HatDirection())); break; } case SEMIAXIS: { retVal = ADDON::DriverPrimitive(primitive.Index(), primitive.Center(), TranslateSemiAxisDirection(primitive.SemiAxisDirection()), primitive.Range()); break; } case MOTOR: { retVal = ADDON::DriverPrimitive::CreateMotor(primitive.Index()); break; } default: break; } return retVal; }
CButtonMapping::CButtonMapping(IButtonMapper* buttonMapper, IButtonMap* buttonMap, IActionMap* actionMap) : m_buttonMapper(buttonMapper), m_buttonMap(buttonMap), m_actionMap(actionMap), m_lastAction(0), m_frameCount(0) { assert(m_buttonMapper != nullptr); assert(m_buttonMap != nullptr); // Make sure axes mapped to Select are centered before they can be mapped. // This ensures that they are not immediately mapped to the first button. if (m_actionMap && m_actionMap->ControllerID() == m_buttonMap->ControllerID()) { using namespace GAME; CGameServices& gameServices = CServiceBroker::GetGameServices(); ControllerPtr controller = gameServices.GetController(m_actionMap->ControllerID()); const auto& features = controller->Layout().Features(); for (const auto& feature : features) { if (m_actionMap->GetActionID(feature.Name()) != ACTION_SELECT_ITEM) continue; CDriverPrimitive primitive; if (!m_buttonMap->GetScalar(feature.Name(), primitive)) continue; if (primitive.Type() != PRIMITIVE_TYPE::SEMIAXIS) continue; // Set initial config, as detection will fail because axis is already activated AxisConfiguration axisConfig; axisConfig.bKnown = true; axisConfig.center = primitive.Center(); axisConfig.range = primitive.Range(); GetAxis(primitive.Index(), primitive.Center(), axisConfig).SetEmitted(primitive); } } }
kodi::addon::DriverPrimitive CPeripheralAddonTranslator::TranslatePrimitive(const CDriverPrimitive& primitive) { kodi::addon::DriverPrimitive retVal; switch (primitive.Type()) { case PRIMITIVE_TYPE::BUTTON: { retVal = kodi::addon::DriverPrimitive::CreateButton(primitive.Index()); break; } case PRIMITIVE_TYPE::HAT: { retVal = kodi::addon::DriverPrimitive(primitive.Index(), TranslateHatDirection(primitive.HatDirection())); break; } case PRIMITIVE_TYPE::SEMIAXIS: { retVal = kodi::addon::DriverPrimitive(primitive.Index(), primitive.Center(), TranslateSemiAxisDirection(primitive.SemiAxisDirection()), primitive.Range()); break; } case PRIMITIVE_TYPE::MOTOR: { retVal = kodi::addon::DriverPrimitive::CreateMotor(primitive.Index()); break; } case PRIMITIVE_TYPE::KEY: { std::string keysym = GAME::CControllerTranslator::TranslateKeycode(primitive.Keycode()); retVal = kodi::addon::DriverPrimitive(keysym); break; } case PRIMITIVE_TYPE::MOUSE_BUTTON: { retVal = kodi::addon::DriverPrimitive::CreateMouseButton(TranslateMouseButton(primitive.MouseButton())); break; } case PRIMITIVE_TYPE::RELATIVE_POINTER: { retVal = kodi::addon::DriverPrimitive(TranslateRelPointerDirection(primitive.PointerDirection())); break; } default: break; } return retVal; }