diff --git a/src/LightsManager.cpp b/src/LightsManager.cpp index e2d2c4083a..986f901452 100644 --- a/src/LightsManager.cpp +++ b/src/LightsManager.cpp @@ -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 g_sLightsDriver( "LightsDriver", "" ); // "" == DEFAULT_LIGHTS_DRIVER Preference g_fLightsFalloffSeconds( "LightsFalloffSeconds", 0.1f ); Preference g_fLightsAheadSeconds( "LightsAheadSeconds", 0.05f ); diff --git a/src/Makefile.am b/src/Makefile.am index 4e9f54d274..350a5b6f90 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/RageInputDevice.cpp b/src/RageInputDevice.cpp index 96fbd205b4..207221df62 100644 --- a/src/RageInputDevice.cpp +++ b/src/RageInputDevice.cpp @@ -231,6 +231,7 @@ static const char *InputDeviceNames[] = { "Pump2", "Midi", "Mouse", + "PIUIO", }; XToString( InputDevice ); StringToX( InputDevice ); diff --git a/src/RageInputDevice.h b/src/RageInputDevice.h index 58d0212fdb..6bf4d498a9 100644 --- a/src/RageInputDevice.h +++ b/src/RageInputDevice.h @@ -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 }; diff --git a/src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp b/src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp new file mode 100644 index 0000000000..c57e7dd4d6 --- /dev/null +++ b/src/arch/InputHandler/InputHandler_Linux_PIUIO.cpp @@ -0,0 +1,134 @@ +#include "global.h" +#include "InputHandler_Linux_PIUIO.h" +#include "RageLog.h" +#include "RageUtil.h" + +#include +#include +#include + +#include +#include +#include + +#include + +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& 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. + */ diff --git a/src/arch/InputHandler/InputHandler_Linux_PIUIO.h b/src/arch/InputHandler/InputHandler_Linux_PIUIO.h new file mode 100644 index 0000000000..7cdf2154be --- /dev/null +++ b/src/arch/InputHandler/InputHandler_Linux_PIUIO.h @@ -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& 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. + */ diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO.cpp b/src/arch/Lights/LightsDriver_Linux_PIUIO.cpp new file mode 100644 index 0000000000..5174da7fdc --- /dev/null +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO.cpp @@ -0,0 +1,80 @@ +#include "global.h" +#include +#include +#include +#include +#include +#include +#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. + */ diff --git a/src/arch/Lights/LightsDriver_Linux_PIUIO.h b/src/arch/Lights/LightsDriver_Linux_PIUIO.h new file mode 100644 index 0000000000..f9bde4feff --- /dev/null +++ b/src/arch/Lights/LightsDriver_Linux_PIUIO.h @@ -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. + */ diff --git a/src/arch/arch.cpp b/src/arch/arch.cpp index 7816b1c771..be0e2e3e65 100644 --- a/src/arch/arch.cpp +++ b/src/arch/arch.cpp @@ -31,6 +31,9 @@ void MakeInputHandlers( const RString &drivers, vector &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 &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 diff --git a/src/arch/arch_default.h b/src/arch/arch_default.h index 88e863fcfb..57193912d5 100644 --- a/src/arch/arch_default.h +++ b/src/arch/arch_default.h @@ -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