예제 #1
0
bool CPeripheralAddon::MapFeature(const CPeripheral* device,
                                  const std::string& strControllerId,
                                  const ADDON::JoystickFeature& feature)
{
  if (!m_bProvidesButtonMaps)
    return false;

  PERIPHERAL_ERROR retVal;

  ADDON::Joystick joystickInfo;
  GetJoystickInfo(device, joystickInfo);

  JOYSTICK_INFO joystickStruct;
  joystickInfo.ToStruct(joystickStruct);

  JOYSTICK_FEATURE addonFeature;
  feature.ToStruct(addonFeature);

  try { LogError(retVal = m_pStruct->MapFeatures(&joystickStruct, strControllerId.c_str(),
                                                 1, &addonFeature), "MapFeatures()"); }
  catch (std::exception &e) { LogException(e, "MapFeatures()"); return false;  }

  if (retVal == PERIPHERAL_NO_ERROR)
  {
    // Notify observing button maps
    RefreshButtonMaps(device->DeviceName());
  }

  return retVal == PERIPHERAL_NO_ERROR;
}
bool CButtonMapXml::IsValid(const ADDON::JoystickFeature& feature)
{
  bool bIsValid = false;

  switch (feature.Type())
  {
    case JOYSTICK_FEATURE_TYPE_SCALAR:
    {
      if (feature.Primitive().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN)
        bIsValid = true;
      break;
    }
    case JOYSTICK_FEATURE_TYPE_ANALOG_STICK:
    {
      if (feature.Up().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN ||
          feature.Down().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN ||
          feature.Right().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN ||
          feature.Left().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN)
      {
        bIsValid = true;
      }
      break;
    }
    case JOYSTICK_FEATURE_TYPE_ACCELEROMETER:
    {
      if (feature.PositiveX().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN ||
          feature.PositiveY().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN ||
          feature.PositiveZ().Type() != JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN)
      {
        bIsValid = true;
      }
      break;
    }
    default:
      break;
  }

  return bIsValid;
}
예제 #3
0
bool CPeripheralAddon::MapFeature(const CPeripheral* device,
                                  const std::string& strControllerId,
                                  const ADDON::JoystickFeature& feature)
{
  if (!m_bProvidesButtonMaps)
    return false;

  PERIPHERAL_ERROR retVal;

  ADDON::Joystick joystickInfo;
  GetJoystickInfo(device, joystickInfo);

  JOYSTICK_INFO joystickStruct;
  joystickInfo.ToStruct(joystickStruct);

  JOYSTICK_FEATURE addonFeature;
  feature.ToStruct(addonFeature);

  LogError(retVal = m_pStruct->MapFeatures(&joystickStruct, strControllerId.c_str(),
                                                 1, &addonFeature), "MapFeatures()");
  return retVal == PERIPHERAL_NO_ERROR;
}
예제 #4
0
bool CAddonButtonMap::ResetPrimitive(ADDON::JoystickFeature& feature, const ADDON::DriverPrimitive& primitive)
{
  bool bModified = false;

  switch (feature.Type())
  {
    case JOYSTICK_FEATURE_TYPE_SCALAR:
    {
      if (primitive == feature.Primitive())
      {
        CLog::Log(LOGDEBUG, "Removing \"%s\" from button map due to conflict", feature.Name().c_str());
        feature.SetType(JOYSTICK_FEATURE_TYPE_UNKNOWN);
        bModified = true;
      }
      break;
    }
    case JOYSTICK_FEATURE_TYPE_ANALOG_STICK:
    {
      if (primitive == feature.Up())
      {
        feature.SetUp(ADDON::DriverPrimitive());
        bModified = true;
      }
      else if (primitive == feature.Down())
      {
        feature.SetDown(ADDON::DriverPrimitive());
        bModified = true;
      }
      else if (primitive == feature.Right())
      {
        feature.SetRight(ADDON::DriverPrimitive());
        bModified = true;
      }
      else if (primitive == feature.Left())
      {
        feature.SetLeft(ADDON::DriverPrimitive());
        bModified = true;
      }

      if (bModified)
      {
        if (feature.Up().Type() == JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN &&
            feature.Down().Type() == JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN &&
            feature.Right().Type() == JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN &&
            feature.Left().Type() == JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN)
        {
          CLog::Log(LOGDEBUG, "Removing \"%s\" from button map due to conflict", feature.Name().c_str());
          feature.SetType(JOYSTICK_FEATURE_TYPE_UNKNOWN);
        }
      }
      break;
    }
    case JOYSTICK_FEATURE_TYPE_ACCELEROMETER:
    {
      if (primitive == feature.PositiveX() ||
          primitive == CPeripheralAddonTranslator::Opposite(feature.PositiveX()))
      {
        feature.SetPositiveX(ADDON::DriverPrimitive());
        bModified = true;
      }
      else if (primitive == feature.PositiveY() ||
               primitive == CPeripheralAddonTranslator::Opposite(feature.PositiveY()))
      {
        feature.SetPositiveY(ADDON::DriverPrimitive());
        bModified = true;
      }
      else if (primitive == feature.PositiveZ() ||
               primitive == CPeripheralAddonTranslator::Opposite(feature.PositiveZ()))
      {
        feature.SetPositiveZ(ADDON::DriverPrimitive());
        bModified = true;
      }

      if (bModified)
      {
        if (feature.PositiveX().Type() == JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN &&
            feature.PositiveY().Type() == JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN &&
            feature.PositiveZ().Type() == JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN)
        {
          CLog::Log(LOGDEBUG, "Removing \"%s\" from button map due to conflict", feature.Name().c_str());
          feature.SetType(JOYSTICK_FEATURE_TYPE_UNKNOWN);
        }
      }
      break;
    }
    default:
      break;
  }
  return bModified;
}