Skip to content

Commit

Permalink
Merge pull request #10 from AlwinEsch/Matrix-change
Browse files Browse the repository at this point in the history
[Matrix] API related update
  • Loading branch information
AlwinEsch authored Sep 7, 2020
2 parents b7a8937 + 60bdbc0 commit a6405ea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 60 deletions.
2 changes: 1 addition & 1 deletion peripheral.xarcade/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="peripheral.xarcade"
version="1.1.1"
version="1.2.0"
name="X-Arcade Tankstick Driver"
provider-name="Team Kodi">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
61 changes: 12 additions & 49 deletions src/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "xarcade/XArcadeTypes.h"
#include "xarcade/XArcadeUtils.h"

#include <kodi/addon-instance/PeripheralUtils.h>

#include <algorithm>

using namespace XARCADE;
Expand All @@ -45,19 +43,16 @@ ADDON_STATUS CPeripheralXArcade::SetSetting(const std::string& settingName, cons
return ADDON_STATUS_OK;
}

void CPeripheralXArcade::GetCapabilities(PERIPHERAL_CAPABILITIES &capabilities)
void CPeripheralXArcade::GetCapabilities(kodi::addon::PeripheralCapabilities& capabilities)
{
capabilities.provides_joysticks = true;
capabilities.provides_joystick_rumble = false;
capabilities.provides_joystick_power_off = false;
capabilities.provides_buttonmaps = false;
capabilities.SetProvidesJoysticks(true);
capabilities.SetProvidesJoystickRumble(false);
capabilities.SetProvidesJoystickPowerOff(false);
capabilities.SetProvidesButtonmaps(false);
}

PERIPHERAL_ERROR CPeripheralXArcade::PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results)
PERIPHERAL_ERROR CPeripheralXArcade::PerformDeviceScan(std::vector<std::shared_ptr<kodi::addon::Peripheral>>& scan_results)
{
if (peripheral_count == nullptr || scan_results == nullptr)
return PERIPHERAL_ERROR_INVALID_PARAMETERS;

// Close disconnected devices
m_devices.erase(std::remove_if(m_devices.begin(), m_devices.end(),
[](const DevicePtr& device)
Expand All @@ -81,50 +76,26 @@ PERIPHERAL_ERROR CPeripheralXArcade::PerformDeviceScan(unsigned int* peripheral_
// Upcast array pointers
std::vector<kodi::addon::Peripheral*> peripherals;
for (auto& joystick : joysticks)
peripherals.push_back(joystick.get());

*peripheral_count = peripherals.size();
kodi::addon::Peripherals::ToStructs(peripherals, scan_results);
scan_results.emplace_back(joystick);

return PERIPHERAL_NO_ERROR;
}

void CPeripheralXArcade::FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results)
PERIPHERAL_ERROR CPeripheralXArcade::GetEvents(std::vector<kodi::addon::PeripheralEvent>& events)
{
kodi::addon::Peripherals::FreeStructs(peripheral_count, scan_results);
}

PERIPHERAL_ERROR CPeripheralXArcade::GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events)
{
if (event_count == nullptr || events == nullptr)
return PERIPHERAL_ERROR_INVALID_PARAMETERS;

std::vector<kodi::addon::PeripheralEvent> peripheralEvents;

for (auto& device : m_devices)
device->GetEvents(peripheralEvents);

*event_count = peripheralEvents.size();
kodi::addon::PeripheralEvents::ToStructs(peripheralEvents, events);
device->GetEvents(events);

return PERIPHERAL_NO_ERROR;
}

void CPeripheralXArcade::FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events)
{
kodi::addon::PeripheralEvents::FreeStructs(event_count, events);
}

bool CPeripheralXArcade::SendEvent(const PERIPHERAL_EVENT* event)
bool CPeripheralXArcade::SendEvent(const kodi::addon::PeripheralEvent& event)
{
return false;
}

PERIPHERAL_ERROR CPeripheralXArcade::GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info)
PERIPHERAL_ERROR CPeripheralXArcade::GetJoystickInfo(unsigned int index, kodi::addon::Joystick& info)
{
if (info == nullptr)
return PERIPHERAL_ERROR_INVALID_PARAMETERS;

JoystickPtr joystick;

for (auto& device : m_devices)
Expand All @@ -139,19 +110,11 @@ PERIPHERAL_ERROR CPeripheralXArcade::GetJoystickInfo(unsigned int index, JOYSTIC

if (joystick)
{
joystick->kodi::addon::Joystick::ToStruct(*info);
info = *joystick;
return PERIPHERAL_NO_ERROR;
}

return PERIPHERAL_ERROR_NOT_CONNECTED;
}

void CPeripheralXArcade::FreeJoystickInfo(JOYSTICK_INFO* info)
{
if (!info)
return;

kodi::addon::Joystick::FreeStruct(*info);
}

ADDONCREATOR(CPeripheralXArcade) // Don't touch this!
13 changes: 5 additions & 8 deletions src/addon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ class ATTRIBUTE_HIDDEN CPeripheralXArcade
ADDON_STATUS GetStatus() override;
ADDON_STATUS SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue) override;

void GetCapabilities(PERIPHERAL_CAPABILITIES &capabilities) override;
PERIPHERAL_ERROR PerformDeviceScan(unsigned int* peripheral_count, PERIPHERAL_INFO** scan_results) override;
void FreeScanResults(unsigned int peripheral_count, PERIPHERAL_INFO* scan_results) override;
PERIPHERAL_ERROR GetEvents(unsigned int* event_count, PERIPHERAL_EVENT** events) override;
void FreeEvents(unsigned int event_count, PERIPHERAL_EVENT* events) override;
bool SendEvent(const PERIPHERAL_EVENT* event) override;
PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, JOYSTICK_INFO* info) override;
void FreeJoystickInfo(JOYSTICK_INFO* info) override;
void GetCapabilities(kodi::addon::PeripheralCapabilities& capabilities) override;
PERIPHERAL_ERROR PerformDeviceScan(std::vector<std::shared_ptr<kodi::addon::Peripheral>>& scan_results) override;
PERIPHERAL_ERROR GetEvents(std::vector<kodi::addon::PeripheralEvent>& events) override;
bool SendEvent(const kodi::addon::PeripheralEvent& event) override;
PERIPHERAL_ERROR GetJoystickInfo(unsigned int index, kodi::addon::Joystick& info) override;

private:
XARCADE::DeviceVector m_devices;
Expand Down
3 changes: 1 addition & 2 deletions src/xarcade/XArcadeDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include "XArcadeDefines.h"
#include "utils/CommonDefines.h" // for INVALID_FD

#include <kodi/addon-instance/Peripheral.h>
#include <kodi/addon-instance/PeripheralUtils.h>
#include <kodi/addon-instance/peripheral/PeripheralUtils.h>

#include <errno.h>
#include <linux/input.h>
Expand Down

0 comments on commit a6405ea

Please sign in to comment.