Add support for PIUIO Linux kernel driver, courtesy of djpohly.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include "CommonMetrics.h"
|
||||
#include "Style.h"
|
||||
|
||||
const RString DEFAULT_LIGHTS_DRIVER = "SystemMessage,Export";
|
||||
const RString DEFAULT_LIGHTS_DRIVER = "PIUIO,SystemMessage,Export";
|
||||
static Preference<RString> g_sLightsDriver( "LightsDriver", "" ); // "" == DEFAULT_LIGHTS_DRIVER
|
||||
Preference<float> g_fLightsFalloffSeconds( "LightsFalloffSeconds", 0.1f );
|
||||
Preference<float> g_fLightsAheadSeconds( "LightsAheadSeconds", 0.05f );
|
||||
|
||||
+4
-2
@@ -241,7 +241,8 @@ ArchHooks = arch/ArchHooks/ArchHooks.cpp arch/ArchHooks/ArchHooks.h \
|
||||
arch/ArchHooks/ArchHooksUtil.cpp
|
||||
|
||||
InputHandler = arch/InputHandler/InputHandler.cpp arch/InputHandler/InputHandler.h \
|
||||
arch/InputHandler/InputHandler_MonkeyKeyboard.cpp arch/InputHandler/InputHandler_MonkeyKeyboard.h
|
||||
arch/InputHandler/InputHandler_MonkeyKeyboard.cpp arch/InputHandler/InputHandler_MonkeyKeyboard.h \
|
||||
arch/InputHandler/InputHandler_Linux_PIUIO.cpp arch/InputHandler/InputHandler_Linux_PIUIO.h
|
||||
|
||||
MovieTexture = arch/MovieTexture/MovieTexture.cpp arch/MovieTexture/MovieTexture.h \
|
||||
arch/MovieTexture/MovieTexture_Generic.cpp arch/MovieTexture/MovieTexture_Generic.h \
|
||||
@@ -277,7 +278,8 @@ if UNIX
|
||||
ArchHooks += arch/ArchHooks/ArchHooks_Unix.cpp arch/ArchHooks/ArchHooks_Unix.h
|
||||
Threads += arch/Threads/Threads_Pthreads.cpp arch/Threads/Threads_Pthreads.h
|
||||
if LINUX
|
||||
Lights += arch/Lights/LightsDriver_LinuxWeedTech.cpp arch/Lights/LightsDriver_LinuxWeedTech.h
|
||||
Lights += arch/Lights/LightsDriver_LinuxWeedTech.cpp arch/Lights/LightsDriver_LinuxWeedTech.h \
|
||||
arch/Lights/LightsDriver_Linux_PIUIO.cpp arch/Lights/LightsDriver_Linux_PIUIO.h
|
||||
if HAVE_PARALLEL_PORT
|
||||
Lights += arch/Lights/LightsDriver_LinuxParallel.cpp arch/Lights/LightsDriver_LinuxParallel.h
|
||||
endif
|
||||
|
||||
@@ -231,6 +231,7 @@ static const char *InputDeviceNames[] = {
|
||||
"Pump2",
|
||||
"Midi",
|
||||
"Mouse",
|
||||
"PIUIO",
|
||||
};
|
||||
XToString( InputDevice );
|
||||
StringToX( InputDevice );
|
||||
|
||||
@@ -47,6 +47,7 @@ enum InputDevice
|
||||
DEVICE_PUMP2,
|
||||
DEVICE_MIDI,
|
||||
DEVICE_MOUSE,
|
||||
DEVICE_PIUIO,
|
||||
NUM_InputDevice, // leave this at the end
|
||||
InputDevice_Invalid // means this is NULL
|
||||
};
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
#include "global.h"
|
||||
#include "InputHandler_Linux_PIUIO.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageUtil.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
REGISTER_INPUT_HANDLER_CLASS2( PIUIO, Linux_PIUIO );
|
||||
|
||||
InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO()
|
||||
{
|
||||
LOG->Trace( "InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO" );
|
||||
|
||||
fd = open( "/dev/piuio0", O_RDONLY );
|
||||
if( fd < 0 )
|
||||
{
|
||||
LOG->Warn( "Couldn't open PIUIO device: %s", strerror(errno) );
|
||||
return;
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if( fstat( fd, &st ) == -1 )
|
||||
{
|
||||
LOG->Warn( "Couldn't stat PIUIO device: %s", strerror(errno) );
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if( !S_ISCHR( st.st_mode ) )
|
||||
{
|
||||
LOG->Warn( "Ignoring /dev/piuio0: not a character device" );
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG->Info("Opened PIUIO device for input");
|
||||
|
||||
m_bShutdown = false;
|
||||
|
||||
m_InputThread.SetName( "PIUIO thread" );
|
||||
m_InputThread.Create( InputThread_Start, this );
|
||||
}
|
||||
|
||||
InputHandler_Linux_PIUIO::~InputHandler_Linux_PIUIO()
|
||||
{
|
||||
if( m_InputThread.IsCreated() )
|
||||
{
|
||||
m_bShutdown = true;
|
||||
LOG->Trace( "Shutting down PIUIO thread ..." );
|
||||
m_InputThread.Wait();
|
||||
LOG->Trace( "PIUIO thread shut down." );
|
||||
}
|
||||
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int InputHandler_Linux_PIUIO::InputThread_Start( void *p )
|
||||
{
|
||||
((InputHandler_Linux_PIUIO *) p)->InputThread();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InputHandler_Linux_PIUIO::InputThread()
|
||||
{
|
||||
unsigned char inputs[32];
|
||||
while( !m_bShutdown )
|
||||
{
|
||||
int ret = read(fd, &inputs, sizeof(inputs));
|
||||
if (ret != sizeof(inputs))
|
||||
{
|
||||
LOG->Warn("Unexpected packet (size %i != %i) from PIUIO", ret, (int)sizeof(inputs));
|
||||
continue;
|
||||
}
|
||||
RageTimer now;
|
||||
|
||||
InputDevice id = InputDevice(DEVICE_JOY1);
|
||||
|
||||
int i;
|
||||
for (i = 8; i < 32; i++)
|
||||
inputs[i % 8] &= inputs[i];
|
||||
for (i = 0; i < 8; i++)
|
||||
lastInputs[i] ^= inputs[i];
|
||||
for (i = 0; i < 64; i++)
|
||||
if (lastInputs[i / 8] & (128 >> (i % 8)))
|
||||
ButtonPressed(DeviceInput(id, enum_add2(JOY_BUTTON_1, i),
|
||||
!(inputs[i / 8] & (128 >> (i % 8))), now));
|
||||
for (i = 0; i < 8; i++)
|
||||
lastInputs[i] = inputs[i];
|
||||
}
|
||||
|
||||
InputHandler::UpdateTimer();
|
||||
}
|
||||
|
||||
void InputHandler_Linux_PIUIO::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut )
|
||||
{
|
||||
vDevicesOut.push_back( InputDeviceInfo(InputDevice(DEVICE_PIUIO), "PIUIO") );
|
||||
}
|
||||
|
||||
/*
|
||||
* Written by Devin J. Pohly, 2012. Based on code from Input_Linux_Joystick,
|
||||
* the copyright and license for which is reproduced below.
|
||||
*
|
||||
* (c) 2003-2004 Glenn Maynard
|
||||
* 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.
|
||||
*/
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef INPUT_HANDLER_LINUX_PIUIO_H
|
||||
#define INPUT_HANDLER_LINUX_PIUIO_H 1
|
||||
|
||||
#include "InputHandler.h"
|
||||
#include "RageThreads.h"
|
||||
|
||||
|
||||
class InputHandler_Linux_PIUIO: public InputHandler
|
||||
{
|
||||
public:
|
||||
InputHandler_Linux_PIUIO();
|
||||
~InputHandler_Linux_PIUIO();
|
||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut );
|
||||
|
||||
private:
|
||||
static int InputThread_Start( void *p );
|
||||
void InputThread();
|
||||
|
||||
int fd;
|
||||
unsigned char lastInputs[8];
|
||||
RageThread m_InputThread;
|
||||
bool m_bShutdown;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Written by Devin J. Pohly, 2012. Based on code from Input_Linux_Joystick,
|
||||
* the copyright and license for which is reproduced below.
|
||||
*
|
||||
* (c) 2003-2004 Glenn Maynard
|
||||
* 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.
|
||||
*/
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "global.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "LightsDriver_Linux_PIUIO.h"
|
||||
#include "RageLog.h"
|
||||
|
||||
REGISTER_SOUND_DRIVER_CLASS2(PIUIO, Linux_PIUIO);
|
||||
|
||||
LightsDriver_Linux_PIUIO::LightsDriver_Linux_PIUIO()
|
||||
{
|
||||
// Open port
|
||||
fd = open("/dev/piuio0", O_WRONLY);
|
||||
if( fd < 0 )
|
||||
{
|
||||
LOG->Warn( "Error opening serial port for lights. Error:: %d %s", errno, strerror(errno) );
|
||||
return;
|
||||
}
|
||||
LOG->Info("Opened PIUIO device for lights");
|
||||
}
|
||||
|
||||
LightsDriver_Linux_PIUIO::~LightsDriver_Linux_PIUIO()
|
||||
{
|
||||
if( fd >= 0 )
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void LightsDriver_Linux_PIUIO::Set( const LightsState *ls )
|
||||
{
|
||||
unsigned char buf[8] = { 0, 0, 0, 0x08, 0x37, 0, 0, 0 };
|
||||
static unsigned char oldbuf[8] = { 0, 0, 0, 0x08, 0x37, 0, 0, 0 };
|
||||
|
||||
if (ls->m_bCabinetLights[LIGHT_MARQUEE_UP_LEFT]) buf[2] |= 0x80;
|
||||
if (ls->m_bCabinetLights[LIGHT_MARQUEE_UP_RIGHT]) buf[3] |= 0x04;
|
||||
if (ls->m_bCabinetLights[LIGHT_MARQUEE_LR_LEFT]) buf[3] |= 0x02;
|
||||
if (ls->m_bCabinetLights[LIGHT_MARQUEE_LR_RIGHT]) buf[3] |= 0x01;
|
||||
if (ls->m_bCabinetLights[LIGHT_BASS_LEFT] || ls->m_bCabinetLights[LIGHT_BASS_RIGHT]) buf[1] |= 0x04;
|
||||
|
||||
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_LEFT]) buf[2] |= 0x10;
|
||||
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_RIGHT]) buf[2] |= 0x20;
|
||||
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_UP]) buf[2] |= 0x04;
|
||||
if (ls->m_bGameButtonLights[GameController_1][DANCE_BUTTON_DOWN]) buf[2] |= 0x08;
|
||||
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_LEFT]) buf[0] |= 0x10;
|
||||
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_RIGHT]) buf[0] |= 0x20;
|
||||
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_UP]) buf[0] |= 0x04;
|
||||
if (ls->m_bGameButtonLights[GameController_2][DANCE_BUTTON_DOWN]) buf[0] |= 0x08;
|
||||
if (!memcmp(buf, oldbuf, 8))
|
||||
return;
|
||||
memcpy(oldbuf, buf, 8);
|
||||
|
||||
write(fd, buf, 8);
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2012 Devin J. Pohly
|
||||
* 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.
|
||||
*/
|
||||
@@ -0,0 +1,44 @@
|
||||
/* LightsDriver_Linux_PIUIO: Control lights via PIUIO kernel driver */
|
||||
|
||||
#ifndef LightsDriver_Linux_PIUIO_H
|
||||
#define LightsDriver_Linux_PIUIO_H
|
||||
|
||||
#include "arch/Lights/LightsDriver.h"
|
||||
|
||||
class LightsDriver_Linux_PIUIO : public LightsDriver
|
||||
{
|
||||
public:
|
||||
LightsDriver_Linux_PIUIO();
|
||||
virtual ~LightsDriver_Linux_PIUIO();
|
||||
|
||||
virtual void Set( const LightsState *ls );
|
||||
private:
|
||||
int fd;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2012 Devin J. Pohly
|
||||
* 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.
|
||||
*/
|
||||
@@ -31,6 +31,9 @@ void MakeInputHandlers( const RString &drivers, vector<InputHandler *> &Add )
|
||||
#ifdef USE_INPUT_HANDLER_DIRECTINPUT
|
||||
if( !s->CompareNoCase("DirectInput") ) ret = new InputHandler_DInput;
|
||||
#endif
|
||||
#ifdef USE_INPUT_HANDLER_PIUIO
|
||||
if( !s->CompareNoCase("PIUIO") ) ret = new InputHandler_Linux_PIUIO;
|
||||
#endif
|
||||
#ifdef USE_INPUT_HANDLER_LINUX_JOYSTICK
|
||||
if( !s->CompareNoCase("Joystick") ) ret = new InputHandler_Linux_Joystick;
|
||||
#endif
|
||||
@@ -74,6 +77,9 @@ void MakeLightsDrivers( const RString &driver, vector<LightsDriver *> &Add )
|
||||
|
||||
LightsDriver *ret = NULL;
|
||||
|
||||
#ifdef USE_LIGHTS_DRIVER_LINUX_PIUIO
|
||||
if( !driver.CompareNoCase("PIUIO") ) ret = new LightsDriver_Linux_PIUIO;
|
||||
#endif
|
||||
#ifdef USE_LIGHTS_DRIVER_LINUX_PARALLEL
|
||||
if( !driver.CompareNoCase("LinuxParallel") ) ret = new LightsDriver_LinuxParallel;
|
||||
#endif
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "LoadingWindow/LoadingWindow_Gtk.h"
|
||||
#endif
|
||||
#if defined(LINUX)
|
||||
#define DEFAULT_INPUT_DRIVER_LIST "X11,Event,Joystick"
|
||||
#define DEFAULT_INPUT_DRIVER_LIST "PIUIO,X11,Event,Joystick"
|
||||
#else
|
||||
#define DEFAULT_INPUT_DRIVER_LIST "X11"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user