From 945441d0f811be27c833640e33d327277652bd4b Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 17 Dec 2003 09:33:39 +0000 Subject: [PATCH] add Para input handler (not quite working yet) --- stepmania/src/RageInputDevice.h | 16 +++ .../InputHandler/InputHandler_Win32_Para.cpp | 125 ++++++++++++++++++ .../InputHandler/InputHandler_Win32_Para.h | 32 +++++ stepmania/src/arch/arch.cpp | 5 +- stepmania/src/arch/arch_Win32.h | 2 +- 5 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 stepmania/src/arch/InputHandler/InputHandler_Win32_Para.cpp create mode 100644 stepmania/src/arch/InputHandler/InputHandler_Win32_Para.h diff --git a/stepmania/src/RageInputDevice.h b/stepmania/src/RageInputDevice.h index 3e5b305fe3..6f06501097 100644 --- a/stepmania/src/RageInputDevice.h +++ b/stepmania/src/RageInputDevice.h @@ -8,6 +8,7 @@ const int NUM_KEYBOARD_BUTTONS = SDLK_LAST; const int NUM_JOYSTICKS = 6; const int NUM_JOYSTICK_HATS = 1; const int NUM_PUMPS = 2; +const int NUM_PARAS = 2; enum InputDevice { DEVICE_KEYBOARD = 0, @@ -19,6 +20,7 @@ enum InputDevice { DEVICE_JOY6, DEVICE_PUMP1, DEVICE_PUMP2, + DEVICE_PARA, NUM_INPUT_DEVICES, // leave this at the end DEVICE_NONE // means this is NULL }; @@ -56,6 +58,19 @@ enum PumpButton { NUM_PUMP_PAD_BUTTONS // leave this at the end }; +enum ParaButton { + PARA_L, + PARA_UL, + PARA_U, + PARA_UR, + PARA_R, + PARA_SELECT, + PARA_START, + PARA_MENU_LEFT, + PARA_MENU_RIGHT, + NUM_PARA_PAD_BUTTONS // leave this at the end +}; + const int NUM_DEVICE_BUTTONS[NUM_INPUT_DEVICES] = { @@ -68,6 +83,7 @@ const int NUM_DEVICE_BUTTONS[NUM_INPUT_DEVICES] = NUM_JOYSTICK_BUTTONS, // DEVICE_JOY6 NUM_PUMP_PAD_BUTTONS, // DEVICE_PUMP1 NUM_PUMP_PAD_BUTTONS, // DEVICE_PUMP2 + NUM_PARA_PAD_BUTTONS, // DEVICE_PARA }; const int MAX_DEVICE_BUTTONS = NUM_KEYBOARD_BUTTONS; diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Para.cpp b/stepmania/src/arch/InputHandler/InputHandler_Win32_Para.cpp new file mode 100644 index 0000000000..c784917f84 --- /dev/null +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Para.cpp @@ -0,0 +1,125 @@ +#include "global.h" +#include "InputHandler_Win32_Para.h" + +#include "PrefsManager.h" +#include "RageLog.h" +#include "RageUtil.h" +#include "RageInputDevice.h" +#include "archutils/Win32/USB.h" + +InputHandler_Win32_Para::InputHandler_Win32_Para() +{ + shutdown = false; + const int para_usb_vid = 0x0507, para_usb_pid = 0x0409; + + dev = new USBDevice; + + bool FoundOnePad = false; + if( dev->Open(para_usb_vid, para_usb_pid, sizeof(long), 0) ) + { + FoundOnePad = true; + LOG->Info("Found Para controller"); + } + + /* Don't start a thread if we have no pads. */ + if( FoundOnePad && PREFSMAN->m_bThreadedInput ) + { + InputThread.SetName("Para thread"); + InputThread.Create( InputThread_Start, this ); + } +} + +InputHandler_Win32_Para::~InputHandler_Win32_Para() +{ + if( InputThread.IsCreated() ) + { + shutdown = true; + LOG->Trace("Shutting down Para thread ..."); + InputThread.Wait(); + LOG->Trace("Para thread shut down."); + } + + delete dev; +} + +void InputHandler_Win32_Para::HandleInput( int devno, int event ) +{ + static const int bits[NUM_PARA_PAD_BUTTONS] = { + /* sensors */ (1<<9), (1<<12), (1<<13), (1<<11), (1<<10), + /* buttons */ (1<<16),(1<<17), (1<<20), (1<<21), + }; + + InputDevice id = DEVICE_PARA; + + for (int butno = 0 ; butno < NUM_PARA_PAD_BUTTONS ; butno++) + { + DeviceInput di(id, butno); + + /* If we're in a thread, our timestamp is accurate. */ + if( InputThread.IsCreated() ) + di.ts.Touch(); + + ButtonPressed(di, !(event & bits[butno])); + } +} + +void InputHandler_Win32_Para::GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut) +{ + if( dev->IsOpen() ) + { + vDevicesOut.push_back( DEVICE_PARA ); + vDescriptionsOut.push_back( "Para USB" ); + } +} + +int InputHandler_Win32_Para::InputThread_Start( void *p ) +{ + ((InputHandler_Win32_Para *) p)->InputThreadMain(); + return 0; +} + +void InputHandler_Win32_Para::InputThreadMain() +{ + if(!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)) + LOG->Warn(werr_ssprintf(GetLastError(), "Failed to set Para thread priority")); + + vector sources; + if( dev->io.IsOpen() ) + sources.push_back( &dev->io ); + + while(!shutdown) + { + CHECKPOINT; + int actual = 0, val = 0; + int ret = WindowsFileIO::read_several(sources, &val, actual, 0.100f); + + CHECKPOINT; + if(ret <= 0) + continue; /* no event */ + + HandleInput( actual, val ); + InputHandler::UpdateTimer(); + } + CHECKPOINT; +} + +void InputHandler_Win32_Para::Update(float fDeltaTime) +{ + if( !InputThread.IsCreated() ) + { + int ret = dev->GetPadEvent(); + + if(ret == -1) + return; + + HandleInput( 0, ret ); + InputHandler::UpdateTimer(); + } +} + +/* +----------------------------------------------------------------------------- + Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved. + Glenn Maynard +----------------------------------------------------------------------------- +*/ diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Para.h b/stepmania/src/arch/InputHandler/InputHandler_Win32_Para.h new file mode 100644 index 0000000000..86bf6c3485 --- /dev/null +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Para.h @@ -0,0 +1,32 @@ +#ifndef INPUT_HANDLER_WIN32_PARA_H +#define INPUT_HANDLER_WIN32_PARA_H 1 + +#include "InputHandler.h" +#include "RageThreads.h" + +class USBDevice; +class InputHandler_Win32_Para: public InputHandler +{ + USBDevice *dev; + RageThread InputThread; + bool shutdown; + + static int InputThread_Start( void *p ); + void InputThreadMain(); + void HandleInput( int devno, int event ); + + +public: + void Update(float fDeltaTime); + InputHandler_Win32_Para(); + ~InputHandler_Win32_Para(); + void GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut); +}; + +#endif +/* +----------------------------------------------------------------------------- + Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved. + Glenn Maynard +----------------------------------------------------------------------------- +*/ diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index b89b703377..ac09f8f8ca 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -77,7 +77,7 @@ void MakeInputHandlers(vector &Add) #if defined(_WINDOWS) Add.push_back(new InputHandler_DInput); Add.push_back(new InputHandler_Win32_Pump); -// Add.push_back(new InputHandler_Win32_Para); + Add.push_back(new InputHandler_Win32_Para); #elif defined(_XBOX) // Add.push_back(new InputHandler_DInput); #endif @@ -156,8 +156,7 @@ LightsDriver *MakeLightsDriver(CString driver) if(!driver.CompareNoCase("Serial")) ret = new LightsDriver_LinuxSerial; #endif if(!driver.CompareNoCase("SystemMessage")) ret = new LightsDriver_SystemMessage; - if(!driver.CompareNoCase("Null")) ret = new LightsDriver_Null; - if( !ret ) + if(!driver.CompareNoCase("Null") || !ret ) { LOG->Warn("Unknown lights driver name: %s", driver.c_str()); ret = new LightsDriver_Null; diff --git a/stepmania/src/arch/arch_Win32.h b/stepmania/src/arch/arch_Win32.h index 31127ff7c4..06825dab34 100644 --- a/stepmania/src/arch/arch_Win32.h +++ b/stepmania/src/arch/arch_Win32.h @@ -7,7 +7,7 @@ #include "InputHandler/InputHandler_DirectInput.h" #include "InputHandler/InputHandler_Win32_Pump.h" -// #include "InputHandler/InputHandler_Win32_Para.h" +#include "InputHandler/InputHandler_Win32_Para.h" #include "Sound/RageSoundDriver_DSound.h" #include "Sound/RageSoundDriver_DSound_Software.h"