Files
itgmania212121/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp
T

161 lines
4.3 KiB
C++
Raw Normal View History

2003-02-16 04:02:21 +00:00
#include "global.h"
2003-02-16 01:16:25 +00:00
#include "InputHandler_Win32_Pump.h"
2003-07-14 06:26:09 +00:00
#include "PrefsManager.h"
2003-02-16 01:16:25 +00:00
#include "RageLog.h"
2003-10-11 04:05:43 +00:00
#include "RageUtil.h"
2003-02-16 01:16:25 +00:00
#include "RageInputDevice.h"
2003-03-19 20:34:40 +00:00
#include "archutils/Win32/USB.h"
2003-02-16 01:16:25 +00:00
2003-02-16 02:25:22 +00:00
InputHandler_Win32_Pump::InputHandler_Win32_Pump()
2003-02-16 01:16:25 +00:00
{
2005-05-25 22:39:56 +00:00
m_bShutdown = false;
2003-02-16 01:16:25 +00:00
const int pump_usb_vid = 0x0d2f, pump_usb_pid = 0x0001;
2005-05-25 22:39:56 +00:00
m_pDevice = new USBDevice[NUM_PUMPS];
2005-05-25 22:39:56 +00:00
bool bFoundOnePad = false;
for( int i = 0; i < NUM_PUMPS; ++i )
2003-02-16 01:16:25 +00:00
{
2005-05-25 22:39:56 +00:00
if( m_pDevice[i].Open(pump_usb_vid, pump_usb_pid, sizeof(long), i) )
{
2005-05-25 22:39:56 +00:00
bFoundOnePad = true;
LOG->Info( "Found Pump pad %i", i );
}
2003-02-16 01:16:25 +00:00
}
2003-07-14 06:26:09 +00:00
/* Don't start a thread if we have no pads. */
2005-05-25 22:39:56 +00:00
if( bFoundOnePad && PREFSMAN->m_bThreadedInput )
2003-08-05 01:32:51 +00:00
{
2005-05-25 22:39:56 +00:00
InputThread.SetName( "Pump thread" );
2003-08-05 01:32:51 +00:00
InputThread.Create( InputThread_Start, this );
}
2003-02-16 01:16:25 +00:00
}
2003-02-16 02:25:22 +00:00
InputHandler_Win32_Pump::~InputHandler_Win32_Pump()
2003-02-16 01:16:25 +00:00
{
2003-08-05 01:32:51 +00:00
if( InputThread.IsCreated() )
2003-07-14 06:26:09 +00:00
{
2005-05-25 22:39:56 +00:00
m_bShutdown = true;
LOG->Trace( "Shutting down Pump thread ..." );
2003-08-05 01:32:51 +00:00
InputThread.Wait();
2005-05-25 22:39:56 +00:00
LOG->Trace( "Pump thread shut down." );
2003-07-14 06:26:09 +00:00
}
2005-05-25 22:39:56 +00:00
delete[] m_pDevice;
2003-02-16 01:16:25 +00:00
}
2005-05-25 22:39:56 +00:00
void InputHandler_Win32_Pump::HandleInput( int iDevice, int iEvent )
2003-02-16 01:16:25 +00:00
{
2003-05-28 04:21:12 +00:00
static const int bits[NUM_PUMP_PAD_BUTTONS] = {
2003-02-16 01:16:25 +00:00
/* P1 */ (1<<9), (1<<12), (1<<13), (1<<11), (1<<10),
/* ESC */ (1<<16),
/* P1 */ (1<<17), (1<<20), (1<<21), (1<<19), (1<<18),
};
2005-05-25 22:39:56 +00:00
InputDevice id = InputDevice( DEVICE_PUMP1 + iDevice );
2003-07-14 06:26:09 +00:00
2005-05-25 22:39:56 +00:00
for( int iButton = 0; iButton < NUM_PUMP_PAD_BUTTONS; ++iButton )
2003-02-16 01:16:25 +00:00
{
2005-05-25 22:39:56 +00:00
DeviceInput di( id, iButton );
2003-07-14 06:26:09 +00:00
/* If we're in a thread, our timestamp is accurate. */
2003-08-05 01:32:51 +00:00
if( InputThread.IsCreated() )
2003-12-17 09:32:56 +00:00
di.ts.Touch();
2003-02-16 01:16:25 +00:00
2005-05-25 22:39:56 +00:00
ButtonPressed( di, !(iEvent & bits[iButton]) );
2003-02-16 01:16:25 +00:00
}
}
2003-05-28 02:35:05 +00:00
void InputHandler_Win32_Pump::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
{
for(int i = 0; i < NUM_PUMPS; ++i)
{
2005-05-25 22:39:56 +00:00
if( m_pDevice[i].IsOpen() )
2003-05-28 02:35:05 +00:00
{
vDevicesOut.push_back( InputDevice(DEVICE_PUMP1+i) );
vDescriptionsOut.push_back( "Pump USB" );
}
}
}
2003-07-14 06:26:09 +00:00
int InputHandler_Win32_Pump::InputThread_Start( void *p )
{
2003-08-05 01:32:51 +00:00
((InputHandler_Win32_Pump *) p)->InputThreadMain();
2003-07-14 06:26:09 +00:00
return 0;
}
2003-08-05 01:32:51 +00:00
void InputHandler_Win32_Pump::InputThreadMain()
2003-07-14 06:26:09 +00:00
{
2005-05-25 22:39:56 +00:00
if( !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST) )
LOG->Warn( werr_ssprintf(GetLastError(), "Failed to set Pump thread priority") );
2003-10-11 00:15:19 +00:00
/* Enable priority boosting. */
SetThreadPriorityBoost( GetCurrentThread(), FALSE );
2005-05-25 22:39:56 +00:00
vector<WindowsFileIO *> apSources;
2004-09-25 05:10:10 +00:00
for( int i = 0; i < NUM_PUMPS; ++i )
2003-07-14 06:26:09 +00:00
{
2005-11-23 22:43:17 +00:00
if( m_pDevice[i].m_IO.IsOpen() )
apSources.push_back( &m_pDevice[i].m_IO );
2003-07-14 06:26:09 +00:00
}
2005-05-25 22:39:56 +00:00
while( !m_bShutdown )
2003-07-14 06:26:09 +00:00
{
2003-08-05 01:32:51 +00:00
CHECKPOINT;
2005-05-25 22:39:56 +00:00
int iActual = 0, iVal = 0;
int iRet = WindowsFileIO::read_several( apSources, &iVal, iActual, 0.100f );
2003-07-14 06:26:09 +00:00
2003-08-05 01:32:51 +00:00
CHECKPOINT;
2005-05-25 22:39:56 +00:00
if( iRet <= 0 )
2003-07-14 06:26:09 +00:00
continue; /* no event */
2005-05-25 22:39:56 +00:00
HandleInput( iActual, iVal );
2003-07-14 06:26:09 +00:00
InputHandler::UpdateTimer();
}
2003-08-05 01:32:51 +00:00
CHECKPOINT;
2003-07-14 06:26:09 +00:00
}
2005-05-25 22:39:56 +00:00
void InputHandler_Win32_Pump::Update( float fDeltaTime )
2003-07-14 06:26:09 +00:00
{
2003-08-05 01:32:51 +00:00
if( !InputThread.IsCreated() )
2003-07-14 06:26:09 +00:00
{
2005-05-25 22:39:56 +00:00
for( int i = 0; i < NUM_PUMPS; ++i )
2003-07-14 06:26:09 +00:00
{
2005-05-25 22:39:56 +00:00
int iRet = m_pDevice[i].GetPadEvent();
2003-07-14 06:26:09 +00:00
2005-05-25 22:39:56 +00:00
if( iRet == -1 )
2003-07-14 06:26:09 +00:00
continue; /* no event */
2005-05-25 22:39:56 +00:00
HandleInput( i, iRet );
2003-07-14 06:26:09 +00:00
}
InputHandler::UpdateTimer();
}
}
2003-03-19 20:34:40 +00:00
/*
2004-05-15 22:07:41 +00:00
* (c) 2002-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.
*/