Skip to content

Commit

Permalink
[buttonmapper] Add joystick families from Kodi's old joystick keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
garbear committed Aug 16, 2016
1 parent 31df568 commit ce0cab7
Show file tree
Hide file tree
Showing 19 changed files with 390 additions and 72 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ set(JOYSTICK_SOURCES src/addon.cpp
src/api/PeripheralScanner.cpp
src/buttonmapper/ButtonMapper.cpp
src/buttonmapper/ButtonMapTranslator.cpp
src/buttonmapper/ControllerMapper.cpp
src/buttonmapper/ControllerModel.cpp
src/buttonmapper/ControllerTransformer.cpp
src/buttonmapper/DriverGeometry.cpp
src/buttonmapper/JoystickFamily.cpp
src/filesystem/DirectoryCache.cpp
Expand Down
133 changes: 133 additions & 0 deletions peripheral.joystick/resources/joystickfamilies/joystickfamilies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<joystickfamilies>
<joystickfamily name="Alienware Controller">
<joystick>Alienware Alienware Dual Compatible Game Pad</joystick>
</joystickfamily>
<joystickfamily name="Apple Remote">
<joystick>AppleRemote</joystick>
</joystickfamily>
<joystickfamily name="Harmony Remote">
<joystick>Harmony</joystick>
</joystickfamily>
<joystickfamily name="Interact AxisPad">
<joystick>STD AxisPad</joystick>
<joystick>Interact AxisPad</joystick>
</joystickfamily>
<joystickfamily name="Logitech RumblePad 2">
<joystick>Logitech Logitech Cordless RumblePad 2</joystick>
<joystick>Logitech Cordless RumblePad 2</joystick>
<joystick>Logitech RumblePad 2 USB</joystick>
</joystickfamily>
<joystickfamily name="Microsoft Xbox 360 Controller (xpad)">
<joystick>Microsoft X-Box 360 pad</joystick>
<joystick>Xbox 360 Wireless Receiver (XBOX)</joystick>
<joystick>Xbox 360 Wireless Receiver</joystick>
<joystick>Xbox Gamepad (userspace driver)</joystick>
<joystick>Thrustmaster Gamepad GP XID</joystick>
<joystick>Logitech Gamepad F310</joystick>
<joystick>Logitech Gamepad F510</joystick>
<joystick>Logitech Gamepad F710</joystick>
<joystick>Generic X-Box pad</joystick>
<joystick>Logitech Chillstream Controller</joystick>
<joystick>Mad Catz Wired Xbox 360 Controller</joystick>
<joystick>Mad Catz Street Fighter IV FightStick SE</joystick>
<joystick>Mad Catz Xbox 360 Controller</joystick>
<joystick>Mad Catz Street Fighter IV FightPad</joystick>
<joystick>Mad Catz Wired Xbox 360 Controller (SFIV)</joystick>
<joystick>Mad Catz Beat Pad</joystick>
<joystick>Mad Catz Xbox controller - MW2</joystick>
<joystick>Mad Catz JOYTECH NEO SE Advanced GamePad</joystick>
<joystick>Saitek Cyborg Rumble Pad - PC/Xbox 360</joystick>
<joystick>Saitek P3200 Rumble Pad - PC/Xbox 360</joystick>
<joystick>Super SFIV FightStick TE S</joystick>
<joystick>HSM3 Xbox360 dancepad</joystick>
<joystick>Afterglow AX.1 Gamepad for Xbox 360</joystick>
<joystick>Pelican PL-3601 'TSZ' Wired Xbox 360 Controller</joystick>
<joystick>Afterglow Gamepad for Xbox 360</joystick>
<joystick>Rock Candy Gamepad for Xbox 360</joystick>
<joystick>Logic3 Controller</joystick>
<joystick>Logic3 Controller</joystick>
<joystick>Hori Fighting Stick EX2</joystick>
<joystick>Hori Real Arcade Pro.EX</joystick>
<joystick>Honey Bee Xbox360 dancepad</joystick>
<joystick>PDP AFTERGLOW AX.1</joystick>
<joystick>RedOctane Guitar Hero X-plorer</joystick>
<joystick>BigBen Interactive XBOX 360 Controller</joystick>
<joystick>Razer Sabertooth</joystick>
<joystick>Power A Mini Pro Elite</joystick>
<joystick>Xbox Airflo wired controller</joystick>
<joystick>Batarang Xbox 360 controller</joystick>
<joystick>Joytech Neo-Se Take2</joystick>
<joystick>Razer Onza Tournament Edition</joystick>
<joystick>Razer Onza Classic Edition</joystick>
<joystick>Razer Sabertooth</joystick>
<joystick>Harmonix Rock Band Guitar</joystick>
<joystick>Harmonix Rock Band Drumkit</joystick>
<joystick>Mad Catz Xbox 360 Controller</joystick>
<joystick>MLG Pro Circuit Controller (Xbox)</joystick>
<joystick>Street Fighter IV FightPad</joystick>
<joystick>Street Fighter IV FightStick TE</joystick>
<joystick>Harmonix Xbox 360 Controller</joystick>
<joystick>Gamestop Xbox 360 Controller</joystick>
<joystick>Tron Xbox 360 controller</joystick>
<joystick>Razer Atrox Arcade Stick</joystick>
<joystick>PowerA MINI PROEX Controller</joystick>
<joystick>Xbox Airflo wired controller</joystick>
<joystick>Hori XBOX 360 EX 2 with Turbo</joystick>
<joystick>Hori Real Arcade Pro VX-SA</joystick>
<joystick>Hori SOULCALIBUR V Stick</joystick>
<joystick>Thrustmaster, Inc. GPX Controller</joystick>
<joystick>Thrustmaster Ferrari 458 Racing Wheel</joystick>
<joystick>Microsoft X-Box One pad</joystick>
</joystickfamily>
<joystickfamily name="Microsoft Xbox 360 Controller (Windows)">
<joystick>Afterglow Gamepad for Xbox 360 (Controller)</joystick>
<joystick>Controller (Gamepad F310)</joystick>
<joystick>Controller (Gamepad for Xbox 360)</joystick>
<joystick>Controller (Rumble Gamepad F510)</joystick>
<joystick>Controller (Wireless Gamepad F710)</joystick>
<joystick>Controller (Xbox 360 Wireless Receiver for Windows)</joystick>
<joystick>Controller (Xbox wireless receiver for windows)</joystick>
<joystick>Controller (XBOX360 GAMEPAD)</joystick>
<joystick>Controller (Batarang wired controller (XBOX))</joystick>
<joystick>Wireless Gamepad F710 (Controller)</joystick>
<joystick>XBOX 360 For Windows</joystick>
<joystick>XBOX 360 For Windows (Controller)</joystick>
<joystick>Xbox 360 Wireless Controller</joystick>
<joystick>Xbox Receiver for Windows (Wireless Controller)</joystick>
<joystick>Xbox wireless receiver for windows (Controller)</joystick>
<joystick>Gamepad F310 (Controller)</joystick>
<joystick>Razer Sabertooth Elite (Controller)</joystick>
<joystick>Controller (Razer Sabertooth Elite)</joystick>
<joystick>Controller (XBOX One For Windows)</joystick>
</joystickfamily>
<joystickfamily name="Microsoft Xbox Controller S">
<joystick>Microsoft Xbox Controller S</joystick>
<joystick>Mad Catz MicroCON</joystick>
<joystick>Logitech Xbox Cordless Controller</joystick>
<joystick>Microsoft X-Box pad (Japan)</joystick>
</joystickfamily>
<joystickfamily name="Nintendo Wii Remote">
<joystick>WiiRemote</joystick>
</joystickfamily>
<joystickfamily name="Nintendo Wii U Pro Controller">
<joystick>Nintendo Wii Remote Pro Controller</joystick>
</joystickfamily>
<joystickfamily name="Ouya Controller">
<joystick>OUYA Game Controller</joystick>
</joystickfamily>
<joystickfamily name="Sony PlayStation 3 Controller">
<joystick>PLAYSTATION(R)3 Controller</joystick>
<joystick>PS3 Controller</joystick>
<joystick>Sony Computer Entertainment Wireless Controller</joystick>
</joystickfamily>
<joystickfamily name="Sony PlayStation 3 Keyboard">
<joystick>PLAYSTATION(R)3 Remote Keyboard</joystick>
<joystick>PS3 Remote Keyboard</joystick>
<joystick>MoSart PS3 Remote Keyboard</joystick>
</joystickfamily>
<joystickfamily name="Sony PlayStation 4 Controller">
<joystick>Wireless Controller</joystick>
</joystickfamily>
</joystickfamilies>

23 changes: 22 additions & 1 deletion src/buttonmapper/ButtonMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "ButtonMapper.h"
#include "ControllerTransformer.h"
#include "storage/IDatabase.h"

#include "kodi_peripheral_utils.hpp"
Expand All @@ -38,6 +39,23 @@ CButtonMapper::~CButtonMapper()
{
}

bool CButtonMapper::Initialize(CJoystickFamilyManager& familyManager)
{
m_controllerTransformer.reset(new CControllerTransformer(familyManager));
return true;
}

void CButtonMapper::Deinitialize()
{
m_controllerTransformer.reset();
m_databases.clear();
}

IDatabaseCallbacks* CButtonMapper::GetCallbacks()
{
return m_controllerTransformer.get();
}

bool CButtonMapper::GetFeatures(const ADDON::Joystick& joystick,
const std::string& strControllerId,
FeatureVector& features)
Expand Down Expand Up @@ -121,6 +139,9 @@ bool CButtonMapper::GetFeatures(const ADDON::Joystick& joystick, ButtonMap&& but

void CButtonMapper::DeriveFeatures(const ADDON::Joystick& joystick, const std::string& toController, const ButtonMap& buttonMap, FeatureVector& transformedFeatures)
{
if (!m_controllerTransformer)
return;

// Obtain an iterator to the controller profile with the highest count of features defined
unsigned int maxFeatures = 0;
auto maxFeaturesIt = buttonMap.end();
Expand All @@ -141,7 +162,7 @@ void CButtonMapper::DeriveFeatures(const ADDON::Joystick& joystick, const std::s
const std::string& fromController = maxFeaturesIt->first;
const FeatureVector& features = maxFeaturesIt->second;

m_controllerMapper.TransformFeatures(joystick, fromController, toController, features, transformedFeatures);
m_controllerTransformer->TransformFeatures(joystick, fromController, toController, features, transformedFeatures);
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/buttonmapper/ButtonMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#pragma once

#include "ButtonMapTypes.h"
#include "ControllerMapper.h"
#include "storage/StorageTypes.h"

#include <memory>
#include <string>

namespace ADDON
Expand All @@ -33,7 +33,8 @@ namespace ADDON

namespace JOYSTICK
{
class IDatabase;
class CControllerTransformer;
class CJoystickFamilyManager;
class IDatabaseCallbacks;

class CButtonMapper
Expand All @@ -42,9 +43,12 @@ namespace JOYSTICK
CButtonMapper(ADDON::CHelper_libKODI_peripheral* peripheralLib);
~CButtonMapper();

bool GetFeatures(const ADDON::Joystick& joystick, const std::string& strDeviceId, FeatureVector& features);
bool Initialize(CJoystickFamilyManager& familyManager);
void Deinitialize();

IDatabaseCallbacks* GetCallbacks();

IDatabaseCallbacks* GetCallbacks() { return &m_controllerMapper; }
bool GetFeatures(const ADDON::Joystick& joystick, const std::string& strDeviceId, FeatureVector& features);

void RegisterDatabase(const DatabasePtr& database);
void UnregisterDatabase(const DatabasePtr& database);
Expand All @@ -57,7 +61,7 @@ namespace JOYSTICK
void DeriveFeatures(const ADDON::Joystick& joystick, const std::string& toController, const ButtonMap& buttonMap, FeatureVector& transformedFeatures);

DatabaseVector m_databases;
CControllerMapper m_controllerMapper;
std::unique_ptr<CControllerTransformer> m_controllerTransformer;

ADDON::CHelper_libKODI_peripheral* m_peripheralLib;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

#include "ControllerMapper.h"
#include "ControllerTransformer.h"
#include "storage/Device.h"

#include "kodi_peripheral_utils.hpp"
Expand All @@ -29,15 +29,26 @@

using namespace JOYSTICK;

void CControllerMapper::OnAdd(const DevicePtr& driverInfo, const ButtonMap& buttonMap)
CControllerTransformer::CControllerTransformer(CJoystickFamilyManager& familyManager) :
m_familyManager(familyManager)
{
}

CControllerTransformer::~CControllerTransformer()
{
}

void CControllerTransformer::OnAdd(const DevicePtr& driverInfo, const ButtonMap& buttonMap)
{
// Skip devices we've already encountered.
if (m_observedDevices.find(driverInfo) == m_observedDevices.end())
m_observedDevices.insert(driverInfo);
else
return;

CJoystickFamily family(driverInfo->Name(), driverInfo->Provider());
const std::string& familyName = m_familyManager.GetFamily(driverInfo->Name(), driverInfo->Provider());

CJoystickFamily family(familyName);
CDriverGeometry geometry(driverInfo->ButtonCount(),
driverInfo->HatCount(),
driverInfo->AxisCount());
Expand All @@ -58,9 +69,9 @@ void CControllerMapper::OnAdd(const DevicePtr& driverInfo, const ButtonMap& butt
}
}

bool CControllerMapper::AddControllerMap(CControllerModel& model,
const std::string& controllerFrom, const FeatureVector& featuresFrom,
const std::string& controllerTo, const FeatureVector& featuresTo)
bool CControllerTransformer::AddControllerMap(CControllerModel& model,
const std::string& controllerFrom, const FeatureVector& featuresFrom,
const std::string& controllerTo, const FeatureVector& featuresTo)
{
bool bChanged = false;

Expand Down Expand Up @@ -121,18 +132,20 @@ bool CControllerMapper::AddControllerMap(CControllerModel& model,
return bChanged;
}

void CControllerMapper::TransformFeatures(const ADDON::Joystick& driverInfo,
const std::string& fromController,
const std::string& toController,
const FeatureVector& features,
FeatureVector& transformedFeatures)
void CControllerTransformer::TransformFeatures(const ADDON::Joystick& driverInfo,
const std::string& fromController,
const std::string& toController,
const FeatureVector& features,
FeatureVector& transformedFeatures)
{
bool bSwap = (fromController >= toController);

ControllerMapItem needle = { bSwap ? toController : fromController,
bSwap ? fromController : toController };

CJoystickFamily family(driverInfo.Name(), driverInfo.Provider());
const std::string& familyName = m_familyManager.GetFamily(driverInfo.Name(), driverInfo.Provider());

CJoystickFamily family(familyName);
CDriverGeometry geometry(driverInfo.ButtonCount(),
driverInfo.HatCount(),
driverInfo.AxisCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ namespace ADDON

namespace JOYSTICK
{
class CControllerMapper : public IDatabaseCallbacks
class CJoystickFamilyManager;

class CControllerTransformer : public IDatabaseCallbacks
{
public:
CControllerMapper() = default;
virtual ~CControllerMapper() = default;
CControllerTransformer(CJoystickFamilyManager& familyManager);

virtual ~CControllerTransformer();

// implementation of IDatabaseCallbacks
virtual void OnAdd(const DevicePtr& driverInfo, const ButtonMap& buttonMap);
Expand All @@ -56,8 +59,9 @@ namespace JOYSTICK
typedef std::map<CJoystickFamily, CControllerModel> FamilyMap;
typedef std::map<CDriverGeometry, CControllerModel> GeomoetryMap;

FamilyMap m_familyModels;
GeomoetryMap m_geometryModels;
DeviceSet m_observedDevices;
FamilyMap m_familyModels;
GeomoetryMap m_geometryModels;
DeviceSet m_observedDevices;
CJoystickFamilyManager& m_familyManager;
};
}
16 changes: 9 additions & 7 deletions src/buttonmapper/JoystickFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

#include "JoystickFamily.h"
#include "storage/xml/JoystickFamiliesXml.h"
#include "storage/xml/JoystickFamilyDefinitions.h"

using namespace JOYSTICK;

// --- CJoystickFamily ---------------------------------------------------------

CJoystickFamily::CJoystickFamily(const std::string& name, const std::string& provider) :
m_familyName(CJoystickFamilyManager::Get().GetFamily(name, provider))
CJoystickFamily::CJoystickFamily(const std::string& familyName) :
m_familyName(familyName)
{
}

Expand All @@ -42,15 +43,16 @@ bool CJoystickFamily::operator<(const CJoystickFamily& other) const

// --- CJoystickFamilyManager --------------------------------------------------

CJoystickFamilyManager& CJoystickFamilyManager::Get()
bool CJoystickFamilyManager::Initialize(const std::string& addonPath)
{
static CJoystickFamilyManager instance;
return instance;
std::string path = addonPath + "/" JOYSTICK_FAMILIES_FOLDER "/" JOYSTICK_FAMILIES_RESOURCE;
return LoadFamilies(path);
}

bool CJoystickFamilyManager::Load()
bool CJoystickFamilyManager::LoadFamilies(const std::string& path)
{
m_families = CJoystickFamiliesXml::LoadFamilies();
CJoystickFamiliesXml::LoadFamilies(path, m_families);

return !m_families.empty();
}

Expand Down
Loading

0 comments on commit ce0cab7

Please sign in to comment.