Ejemplo n.º 1
0
bool CGameClientInput::OpenJoystick(const std::string &portAddress, const ControllerPtr &controller)
{
  using namespace JOYSTICK;

  if (!controller)
  {
    CLog::Log(LOGERROR, "Failed to open port \"%s\", no controller given", portAddress.c_str());
    return false;
  }

  const CControllerPortNode &port = m_controllers.GetPort(portAddress);
  if (!port.IsControllerAccepted(portAddress, controller->ID()))
  {
    CLog::Log(LOGERROR, "Failed to open port: Invalid controller \"%s\" on port \"%s\"",
              controller->ID().c_str(), portAddress.c_str());
    return false;
  }

  std::string strId = controller->ID();

  game_controller controllerStruct{};

  controllerStruct.controller_id        = strId.c_str();
  controllerStruct.provides_input       = controller->Topology().ProvidesInput();
  controllerStruct.digital_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::DIGITAL);
  controllerStruct.analog_button_count  = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::ANALOG);
  controllerStruct.analog_stick_count   = controller->FeatureCount(FEATURE_TYPE::ANALOG_STICK);
  controllerStruct.accelerometer_count  = controller->FeatureCount(FEATURE_TYPE::ACCELEROMETER);
  controllerStruct.key_count            = controller->FeatureCount(FEATURE_TYPE::KEY);
  controllerStruct.rel_pointer_count    = controller->FeatureCount(FEATURE_TYPE::RELPOINTER);
  controllerStruct.abs_pointer_count    = controller->FeatureCount(FEATURE_TYPE::ABSPOINTER);
  controllerStruct.motor_count          = controller->FeatureCount(FEATURE_TYPE::MOTOR);

  bool bSuccess = false;

  {
    CSingleLock lock(m_clientAccess);

    if (m_gameClient.Initialized())
    {
      try
      {
        bSuccess = m_struct.toAddon.ConnectController(true, portAddress.c_str(), &controllerStruct);
      }
      catch (...)
      {
        m_gameClient.LogException("ConnectController()");
      }
    }
  }

  if (bSuccess)
  {
    m_joysticks[portAddress].reset(new CGameClientJoystick(m_gameClient, portAddress, controller, m_struct.toAddon));
    ProcessJoysticks();
    return true;
  }

  return false;
}
Ejemplo n.º 2
0
void CGameClient::UpdatePort(unsigned int port, const ControllerPtr& controller)
{
  using namespace JOYSTICK;

  CSingleLock lock(m_critSection);

  if (Initialized())
  {
    if (controller != CController::EmptyPtr)
    {
      std::string strId = controller->ID();

      game_controller controllerStruct;

      controllerStruct.controller_id        = strId.c_str();
      controllerStruct.digital_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::DIGITAL);
      controllerStruct.analog_button_count  = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::ANALOG);
      controllerStruct.analog_stick_count   = controller->FeatureCount(FEATURE_TYPE::ANALOG_STICK);
      controllerStruct.accelerometer_count  = controller->FeatureCount(FEATURE_TYPE::ACCELEROMETER);
      controllerStruct.key_count            = 0; //! @todo
      controllerStruct.rel_pointer_count    = controller->FeatureCount(FEATURE_TYPE::RELPOINTER);
      controllerStruct.abs_pointer_count    = controller->FeatureCount(FEATURE_TYPE::ABSPOINTER);
      controllerStruct.motor_count          = controller->FeatureCount(FEATURE_TYPE::MOTOR);

      try { m_struct.toAddon.UpdatePort(port, true, &controllerStruct); }
      catch (...) { LogException("UpdatePort()"); }
    }
    else
    {
      try { m_struct.toAddon.UpdatePort(port, false, nullptr); }
      catch (...) { LogException("UpdatePort()"); }
    }
  }
}
Ejemplo n.º 3
0
bool CGameClientInput::OpenMouse(const ControllerPtr &controller)
{
  using namespace JOYSTICK;

  if (!controller)
  {
    CLog::Log(LOGERROR, "Failed to open mouse, no controller given");
    return false;
  }

  //! @todo Move to player manager
  PERIPHERALS::PeripheralVector mice;
  CServiceBroker::GetPeripherals().GetPeripheralsWithFeature(mice, PERIPHERALS::FEATURE_MOUSE);
  if (mice.empty())
    return false;

  std::string controllerId = controller->ID();

  game_controller controllerStruct{};

  controllerStruct.controller_id        = controllerId.c_str();
  controllerStruct.digital_button_count = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::DIGITAL);
  controllerStruct.analog_button_count  = controller->FeatureCount(FEATURE_TYPE::SCALAR, INPUT_TYPE::ANALOG);
  controllerStruct.analog_stick_count   = controller->FeatureCount(FEATURE_TYPE::ANALOG_STICK);
  controllerStruct.accelerometer_count  = controller->FeatureCount(FEATURE_TYPE::ACCELEROMETER);
  controllerStruct.key_count            = controller->FeatureCount(FEATURE_TYPE::KEY);
  controllerStruct.rel_pointer_count    = controller->FeatureCount(FEATURE_TYPE::RELPOINTER);
  controllerStruct.abs_pointer_count    = controller->FeatureCount(FEATURE_TYPE::ABSPOINTER);
  controllerStruct.motor_count          = controller->FeatureCount(FEATURE_TYPE::MOTOR);

  bool bSuccess = false;

  {
    CSingleLock lock(m_clientAccess);

    if (m_gameClient.Initialized())
    {
      try
      {
        bSuccess = m_struct.toAddon.EnableMouse(true, &controllerStruct);
      }
      catch (...)
      {
        m_gameClient.LogException("EnableMouse()");
      }
    }
  }

  if (bSuccess)
  {
    m_mouse.reset(new CGameClientMouse(m_gameClient, controllerId, m_struct.toAddon, mice.at(0).get()));
    return true;
  }

  return false;
}
Ejemplo n.º 4
0
void CGUIFeatureList::Load(const ControllerPtr& controller)
{
  if (m_controller && m_controller->ID() == controller->ID())
    return; // Already loaded

  CleanupButtons();

  m_controller = controller;

  const std::vector<CControllerFeature>& features = controller->Layout().Features();

  for (unsigned int buttonIndex = 0; buttonIndex < features.size(); buttonIndex++)
  {
    const CControllerFeature& feature = features[buttonIndex];

    CGUIButtonControl* pButton = nullptr;
    switch (feature.Type())
    {
      case JOYSTICK::FEATURE_TYPE::SCALAR:
      {
        pButton = new CGUIScalarFeatureButton(*m_guiButtonTemplate, m_wizard, feature, buttonIndex);
        break;
      }
      case JOYSTICK::FEATURE_TYPE::ANALOG_STICK:
      {
        pButton = new CGUIAnalogStickButton(*m_guiButtonTemplate, m_wizard, feature, buttonIndex);
        break;
      }
      default:
        break;
    }
    if (pButton)
      m_guiList->AddControl(pButton);

    // Just in case
    if (buttonIndex >= MAX_FEATURE_COUNT)
      break;
  }
}