Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux pac drive #1479

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/CMakeData-arch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,16 @@ if(NOT APPLE)
"arch/Lights/LightsDriver_Linux_PIUIO_Leds.cpp"
"arch/Lights/LightsDriver_LinuxWeedTech.cpp"
"arch/Lights/LightsDriver_LinuxParallel.cpp"
"arch/Lights/LightsDriver_LinuxPacDrive.cpp"
"io/PacDrive.cpp"
)
list(APPEND SMDATA_ARCH_LIGHTS_HPP
"arch/Lights/LightsDriver_Linux_PIUIO.h"
"arch/Lights/LightsDriver_Linux_PIUIO_Leds.h"
"arch/Lights/LightsDriver_LinuxWeedTech.h"
"arch/Lights/LightsDriver_LinuxParallel.h"
"arch/Lights/LightsDriver_LinuxPacDrive.h"
"io/PacDrive.h"
)
if (WITH_PARALLEL_PORT)
list(APPEND SMDATA_ARCH_LIGHTS_SRC
Expand Down
7 changes: 7 additions & 0 deletions src/CMakeData-os.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ else()
"archutils/Unix/SignalHandler.cpp"
"archutils/Unix/SpecialDirs.cpp"
"archutils/Unix/StackCheck.cpp"
"io/USBDriver.cpp"
"arch/USB/USBDriver_Impl.cpp"
"arch/USB/USBDriver_Impl_Libusb.cpp"
)
list(APPEND SMDATA_OS_HPP
"archutils/Unix/arch_setup.h"
Expand All @@ -107,6 +110,10 @@ else()
"archutils/Unix/SignalHandler.h"
"archutils/Unix/SpecialDirs.h"
"archutils/Common/gcc_byte_swaps.h"
"io/USBDriver.h"
"arch/USB/USBDriver_Impl.h"
"arch/USB/USBDriver_Impl_Libusb.h"
"arch/USB/USBDriver_Macros.h"
)
if(X11_FOUND)
list(APPEND SMDATA_OS_SRC
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ list(APPEND SMDATA_LINK_LIB
"glew"
"jpeg"
"rage"
"usb"
)
include(../extern/CMakeProject-mmmagic.cmake)

Expand Down
90 changes: 90 additions & 0 deletions src/arch/Lights/LightsDriver_LinuxPacDrive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Cross-platform, libusb-based driver for outputting lights
// via a PacDrive (http://www.ultimarc.com/pacdrive.html)

#include "global.h"
#include "RageLog.h"
#include "io/PacDrive.h"
#include "LightsDriver_LinuxPacDrive.h"

REGISTER_LIGHTS_DRIVER_CLASS( LinuxPacDrive );

LightsDriver_LinuxPacDrive::LightsDriver_LinuxPacDrive()
{
m_bHasDevice = Board.Open();

if( m_bHasDevice == false )
{
LOG->Warn( "Could not establish a connection with PacDrive." );
return;
}

// clear all lights
Board.Write( 0 );
}

LightsDriver_LinuxPacDrive::~LightsDriver_LinuxPacDrive()
{
if( !m_bHasDevice )
return;

// clear all lights and close the connection
Board.Write( 0 );
Board.Close();
}

void LightsDriver_LinuxPacDrive::Set( const LightsState *ls )
{
if( !m_bHasDevice )
return;

uint16_t outb = 0;

if (ls->m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT]) outb|=BIT(0);
if (ls->m_bCabinetLights[LIGHT_MARQUEE_UP_RIGHT]) outb|=BIT(1);
if (ls->m_bCabinetLights[LIGHT_MARQUEE_LR_LEFT]) outb|=BIT(2);
if (ls->m_bCabinetLights[LIGHT_MARQUEE_LR_RIGHT]) outb|=BIT(3);
if (ls->m_bCabinetLights[LIGHT_BASS_LEFT] || ls->m_bCabinetLights[LIGHT_BASS_RIGHT]) outb|=BIT(4);
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_LEFT]) outb|=BIT(5);
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_RIGHT]) outb|=BIT(6);
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_UP]) outb|=BIT(7);
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_DOWN]) outb|=BIT(8);
if (ls->m_bGameButtonLights[GameController_1][GAME_BUTTON_START]) outb|=BIT(9);
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_LEFT]) outb|=BIT(10);
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_RIGHT]) outb|=BIT(11);
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_UP]) outb|=BIT(12);
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_DOWN]) outb|=BIT(13);
if (ls->m_bGameButtonLights[GameController_2][GAME_BUTTON_START]) outb|=BIT(14);


// write the data - if it fails, stop updating
if( !Board.Write(outb) )
{
LOG->Warn( "Lost connection with PacDrive." );
m_bHasDevice = false;
}
}

/*
* Copyright (c) 2008 BoXoRRoXoRs
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
48 changes: 48 additions & 0 deletions src/arch/Lights/LightsDriver_LinuxPacDrive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef LIGHTSDRIVER_LINUXPACDRIVE_H
#define LIGHTSDRIVER_LINUXPACDRIVE_H

#include "LightsDriver.h"
#include "io/PacDrive.h"

#define BIT(i) (1<<(i))

class LightsDriver_LinuxPacDrive: public LightsDriver
{
public:
LightsDriver_LinuxPacDrive();
~LightsDriver_LinuxPacDrive();

void Set( const LightsState *ls );
private:


PacDrive Board;
bool m_bHasDevice;
};

#endif // LIGHTSDRIVER_LINUXPACDRIVE_H

/*
* Copyright (c) 2008 BoXoRRoXoRs
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
34 changes: 34 additions & 0 deletions src/arch/USB/USBDriver_Impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "global.h"
#include "USBDriver_Impl.h"
#include "arch/arch_default.h"

#include "arch/USB/USBDriver_Impl_Libusb.h"

USBDriver_Impl::USBDriver_Impl()
{
/* no-op */
}

USBDriver_Impl::~USBDriver_Impl()
{
/* no-op */
}

/* libusb has working implementations on the three major systems - Linux,
* Mac, and Windows - but they may not perform as well as the native APIs.
* If we have a different API, prefer that first. */

USBDriver_Impl* USBDriver_Impl::Create()
{
#if defined(HAS_USBDRIVER_IMPL_LIBUSB)
return new USBDriver_Impl_Libusb;
#endif
}

/* XXX: can we do this better? */
bool USBDriver_Impl::DeviceExists( uint16_t iVendorID, uint16_t iProductID )
{
#if defined(HAS_USBDRIVER_IMPL_LIBUSB)
return USBDriver_Impl_Libusb::DeviceExists( iVendorID, iProductID );
#endif
}
38 changes: 38 additions & 0 deletions src/arch/USB/USBDriver_Impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef USB_DRIVER_IMPL_H
#define USB_DRIVER_IMPL_H

#include "USBDriver_Macros.h"

class USBDriver_Impl
{
public:
static USBDriver_Impl* Create();

/* returns true if a USB device exists with this VID/PID */
static bool DeviceExists( uint16_t iVendorID, uint16_t iProductID );

USBDriver_Impl();
virtual ~USBDriver_Impl();

virtual bool Open( int iVendorID, int iProductID ) = 0;
virtual void Close() = 0;

virtual int ControlMessage( int iType, int iRequest, int iValue, int iIndex, char *pData, int iSize, int iTimeout ) = 0;

virtual int BulkRead( int iEndpoint, char *pData, int iSize, int iTimeout ) = 0;
virtual int BulkWrite( int iEndpoint, char *pData, int iSize, int iTimeout ) = 0;

virtual int InterruptRead( int iEndpoint, char *pData, int iSize, int iTimeout ) = 0;
virtual int InterruptWrite( int iEndpoint, char *pData, int iSize, int iTimeout ) = 0;

/* if something fails, return a string describing the error */
virtual const char *GetError() const = 0;

protected:
virtual bool SetConfiguration( int iConfig ) = 0;

virtual bool ClaimInterface( int iInterface ) = 0;
virtual bool ReleaseInterface( int iInterface ) = 0;
};

#endif // USB_DRIVER_IMPL_H