Ejemplo n.º 1
0
static void dojoy(void)
{
#ifdef _WIN32
  static UINT max[2]={0,0};
  static UINT min[2]={0xffffffff,0xffffffff},center[2];
  MMRESULT res;
  JOYINFO joy;

  res=joyGetPos(JOYSTICKID1,&joy);

  if(res==JOYERR_NOERROR) {
    joyavailable=1;

    if(max[0]<joy.wXpos)
      max[0]=joy.wXpos;
    if(min[0]>joy.wXpos)
      min[0]=joy.wXpos;
    center[0]=(max[0]+min[0])/2;

    if(max[1]<joy.wYpos)
      max[1]=joy.wYpos;
    if(min[1]>joy.wYpos)
      min[1]=joy.wYpos;
    center[1]=(max[1]+min[1])/2;

    if(joyactive) {
      if(fabs(center[0]-(float)joy.wXpos)>0.1*(max[0]-min[0]))
	alpha-=2.0*(center[0]-(float)joy.wXpos)/(max[0]-min[0]);
      if(fabs(center[1]-(float)joy.wYpos)>0.1*(max[1]-min[1]))
	beta+=2.0*(center[1]-(float)joy.wYpos)/(max[1]-min[1]);

      if(joy.wButtons & JOY_BUTTON1)
	v+=0.01;
      if(joy.wButtons & JOY_BUTTON2)
	v-=0.01;
    }
  } else
    joyavailable=0;
#endif
}
Ejemplo n.º 2
0
float GUIContext::CheckInputControllerZ(int Controller)
{
#ifdef _WIN32
UINT JoyID = 0;
JOYINFO JoyData;
long JoyCentered;

if (Controller == 1) JoyID = JOYSTICKID1;
if (Controller == 2) JoyID = JOYSTICKID2;
if (joyGetPos(JoyID, &JoyData) == JOYERR_NOERROR)
	{
	JoyCentered = JoyData.wZpos - JoyCenterZ[Controller - 1];
	if (JoyCentered > 0)
		return(((float)JoyCentered / (float)(JoyMaxZ[Controller - 1] - JoyCenterZ[Controller - 1])));
	else
		return(((float)JoyCentered / (float)(JoyMinZ[Controller - 1] - JoyCenterZ[Controller - 1])));
	} // if
#endif // _WIN32

return(0.f);

} // GUIContext::CheckInputControllerZ
Ejemplo n.º 3
0
/**************************************************************************
 * 				joySetCapture		[WINMM.@]
 */
MMRESULT WINAPI joySetCapture(HWND hWnd, UINT wID, UINT wPeriod, BOOL bChanged)
{
    TRACE("(%p, %04X, %d, %d);\n",  hWnd, wID, wPeriod, bChanged);

    if (wID >= MAXJOYSTICK || hWnd == 0) return JOYERR_PARMS;
    if (wPeriod<JOY_PERIOD_MIN || wPeriod>JOY_PERIOD_MAX) return JOYERR_PARMS;
    if (!JOY_LoadDriver(wID)) return MMSYSERR_NODRIVER;

    if (JOY_Sticks[wID].hCapture || !IsWindow(hWnd))
	return JOYERR_NOCANDO; /* FIXME: what should be returned ? */

    if (joyGetPos(wID, &JOY_Sticks[wID].ji) != JOYERR_NOERROR)
	return JOYERR_UNPLUGGED;

    if ((JOY_Sticks[wID].wTimer = SetTimer(hWnd, 0, wPeriod, JOY_Timer)) == 0)
	return JOYERR_NOCANDO;

    JOY_Sticks[wID].hCapture = hWnd;
    JOY_Sticks[wID].bChanged = bChanged;

    return JOYERR_NOERROR;
}
Ejemplo n.º 4
0
/**************************************************************************
 * 				JOY_Timer		[internal]
 */
static	void	CALLBACK	JOY_Timer(HWND hWnd, UINT wMsg, UINT_PTR wTimer, DWORD dwTime)
{
    int			i;
    WINE_JOYSTICK*	joy;
    JOYINFO		ji;
    LONG		pos;
    unsigned 		buttonChange;

    for (i = 0; i < MAXJOYSTICK; i++) {
	joy = &JOY_Sticks[i];

	if (joy->hCapture != hWnd) continue;

	joyGetPos(i, &ji);
	pos = MAKELONG(ji.wXpos, ji.wYpos);

	if (!joy->bChanged ||
	    abs(joy->ji.wXpos - ji.wXpos) > joy->threshold ||
	    abs(joy->ji.wYpos - ji.wYpos) > joy->threshold) {
	    SendMessageA(joy->hCapture, MM_JOY1MOVE + i, ji.wButtons, pos);
	    joy->ji.wXpos = ji.wXpos;
	    joy->ji.wYpos = ji.wYpos;
	}
	if (!joy->bChanged ||
	    abs(joy->ji.wZpos - ji.wZpos) > joy->threshold) {
	    SendMessageA(joy->hCapture, MM_JOY1ZMOVE + i, ji.wButtons, pos);
	    joy->ji.wZpos = ji.wZpos;
	}
	if ((buttonChange = joy->ji.wButtons ^ ji.wButtons) != 0) {
	    if (ji.wButtons & buttonChange)
		SendMessageA(joy->hCapture, MM_JOY1BUTTONDOWN + i,
			     (buttonChange << 8) | (ji.wButtons & buttonChange), pos);
	    if (joy->ji.wButtons & buttonChange)
		SendMessageA(joy->hCapture, MM_JOY1BUTTONUP + i,
			     (buttonChange << 8) | (joy->ji.wButtons & buttonChange), pos);
	    joy->ji.wButtons = ji.wButtons;
	}
    }
}
Ejemplo n.º 5
0
/*
 * Class:     Joystick
 * Method:    getButton
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_Joystick_getButtons(
JNIEnv	*env,
jobject	obj,
jint	id)
{
	JOYINFO	info;
	
	if (joyGetPos(id + JOYSTICKID1, &info) != JOYERR_NOERROR)
		return 0;

	int button = 0;
	if (info.wButtons & JOY_BUTTON1)
		button |= Joystick_BUTTON1;
	if (info.wButtons & JOY_BUTTON2)
		button |= Joystick_BUTTON2;
	if (info.wButtons & JOY_BUTTON3)
		button |= Joystick_BUTTON3;
	if (info.wButtons & JOY_BUTTON4)
		button |= Joystick_BUTTON4;

	return button;
}
Ejemplo n.º 6
0
bool joystick_load(int id)
{
	JOYINFO joyinfo; 
	UINT wNumDevs; 
	BOOL bDevAttached; 
 
    if((wNumDevs = joyGetNumDevs()) == 0) 
        return false; 
		
    if (joySetCapture(enigma::hWnd, JOYSTICKID1 + id, NULL, FALSE)) 
    { 
        MessageBeep(MB_ICONEXCLAMATION); 
        MessageBox(enigma::hWnd, "Couldn't capture the joystick.", NULL, 
            MB_OK | MB_ICONEXCLAMATION); 
        return false;
    } 
	
	bDevAttached = joyGetPos(JOYSTICKID1 + id, &joyinfo) != JOYERR_UNPLUGGED; 
    if (!bDevAttached) 
        return false;
		
	return true;
}
Ejemplo n.º 7
0
unsigned long GUIContext::CheckInputControllerButtons(int Controller, unsigned long ButtonMask)
{
unsigned long rval = 0;

#ifdef _WIN32
UINT JoyID = 0;
JOYINFO JoyData;
unsigned long ButtonCodes = 0;

if (Controller == 1) JoyID = JOYSTICKID1;
if (Controller == 2) JoyID = JOYSTICKID2;
if (joyGetPos(JoyID, &JoyData) == JOYERR_NOERROR)
	{
	if (JoyData.wButtons & JOY_BUTTON1) ButtonCodes |= 0x01;
	if (JoyData.wButtons & JOY_BUTTON2) ButtonCodes |= 0x02;
	if (JoyData.wButtons & JOY_BUTTON3) ButtonCodes |= 0x04;
	if (JoyData.wButtons & JOY_BUTTON4) ButtonCodes |= 0x08;
	} // if
rval = ButtonCodes & ButtonMask;
#endif // _WIN32

return(rval);

} // GUIContext::CheckInputControllerButtons
Ejemplo n.º 8
0
/**
    [email protected] 2002-08-20:
    Now returns only valid, functioning
    joysticks, counting from the first
    available and upwards.
*/
wxJoystick::wxJoystick(int joystick)
{
    JOYINFO joyInfo;
    int i, maxsticks;

    maxsticks = joyGetNumDevs();
    for( i=0; i<maxsticks; i++ )
    {
        if( joyGetPos(i, & joyInfo) == JOYERR_NOERROR )
        {
            if( !joystick )
            {
                /* Found the one we want, store actual OS id and return */
                m_joystick = i;
                return;
            }
            joystick --;
        }
    }

    /* No such joystick, return ID 0 */
    m_joystick = 0;
    return;
}
Ejemplo n.º 9
0
void joy_Update()
{
	JOYINFO ji;
	int result;

	if (!joy_initd) return;
	for (int i=0; i<4; i++)
	{
		if (!sticks[i].active) continue;
		if (result = joyGetPos(joy_sticks[i], &ji) != JOYERR_NOERROR)
			return; // some error,

		sticks[i].left  = (ji.wXpos < sticks[i].range_left);
		sticks[i].right = (ji.wXpos > sticks[i].range_right);
		sticks[i].up    = (ji.wYpos < sticks[i].range_up);
		sticks[i].down  = (ji.wYpos > sticks[i].range_down);

		sticks[i].analog_x = (ji.wXpos * 2000 / sticks[i].xrange) - 1000;
		sticks[i].analog_y = (ji.wYpos * 2000 / sticks[i].yrange) - 1000;

		for (int b=0; b<32; b++)
			sticks[i].button[b] = (ji.wButtons & buttonmask[b]);
	}
}
void ArJoyHandler::getData(void)
{
  int x, y, z;
  if (!myFirstData && myLastDataGathered.mSecSince() < 5)
    return;

  myFirstData = false;
  myLastDataGathered.setToNow();
  MMRESULT joyResult = joyGetPos(myJoyID,&myJoyInfo);

  if (joyResult == JOYERR_NOERROR) 
  {
    // KMC: I don't understand this logic... The spec says that 
    // getAxis returns a number between -1 and 1; the getAxis method
    // multiplies the contents of myAxes by 128.  The logic below
    // however seems to double everything... 
/**/
    x = (int)(myJoyInfo.wXpos*256.0/myPhysMax)-128;
    y = (int)-((myJoyInfo.wYpos*256.0/myPhysMax)-128);
    z = (int)-((myJoyInfo.wZpos*256.0/myPhysMax)-128);

/***/
/***
    x = (int) 128 * ((2.0 * (double) myJoyInfo.wXpos / (double) myPhysMax) - 1);
    y = (int)-128 * ((2.0 * (double) myJoyInfo.wYpos / (double) myPhysMax) - 1);
    z = (int)-128 * ((2.0 * (double) myJoyInfo.wZpos / (double) myPhysMax) - 1);
**/

    if (myLastZ != z)
      myHaveZ = true;
    if (x > myMaxX)
      myMaxX = x;
    if (x < myMinX)
      myMinX = x;
    if (y > myMaxY)
      myMaxY = y;
    if (y < myMinY)
      myMinY = y;

    myAxes[1] = x;
    myAxes[2] = y;
    myAxes[3] = z;
	
    myLastZ = z;
	
    myButtons[1] = (myJoyInfo.wButtons & 1);
    myButtons[2] = (myJoyInfo.wButtons & 2);
    myButtons[3] = (myJoyInfo.wButtons & 4);
    myButtons[4] = (myJoyInfo.wButtons & 8);
  }
  else //(joyResult == JOYERR_UNPLUGGED) 
  {
    myAxes[1] = 0;
    myAxes[2] = 0;
    myAxes[3] = 0;
    myButtons[1] = 0;
    myButtons[2] = 0;
    myButtons[3] = 0;
    myButtons[4] = 0;
	
	// Reset the initialized flag so that the joystick button in the GUI
	// will be disabled.
    myInitialized = false;
  } 
}
Ejemplo n.º 11
0
JOYCAPS *
QuaJoystickManager::GetJoyCaps(int32 *nJoyP)
{
	JOYINFO joyinfo; 
	uint32	nJoy;
//	uint32	wDeviceID; 
	bool	dev1Attached, dev2Attached; 
	 
	if((nJoy = joyGetNumDevs()) == 0) {
		*nJoyP = 0;
		return nullptr; 
	}
	fprintf(stderr, "%d total joysticks\n", nJoy);
	dev1Attached = joyGetPos(JOYSTICKID1,&joyinfo) != JOYERR_UNPLUGGED; 
	dev2Attached = (nJoy == 2) && joyGetPos(JOYSTICKID2,&joyinfo) != 
		JOYERR_UNPLUGGED; 
	if(!(dev1Attached || dev2Attached)) {   // decide which joystick to use 
		*nJoyP = 0;
		return nullptr;
	}
	JOYCAPS	*caps;
	int		nc = 0;
	/*
	caps = new JOYCAPS[(dev1Attached && dev2Attached)?2:1];
	if (dev1Attached) {
		MMRESULT	err = joyGetDevCaps(
							JOYSTICKID1, 
							&caps[nc],    
							sizeof(JOYCAPS));
		nc++;
	}
	if (dev2Attached) {
		MMRESULT	err = joyGetDevCaps(
							JOYSTICKID2, 
							&caps[nc],    
							sizeof(JOYCAPS));
		nc++;
	}
	*nJoyP = nc;

	*/
	JOYCAPS	c;
	int		i, n=0;
	for (i=0; i<nJoy; i++) {
		MMRESULT	err = joyGetDevCaps(
							i, 
							&c,    
							sizeof(JOYCAPS));
		if (c.wNumAxes == 0 && c.wNumButtons == 0) {
			break;
		}
		n++;
	}
	nJoy = n;
	caps = new JOYCAPS[nJoy];
	for (i=0; i<nJoy; i++) {
		MMRESULT	err = joyGetDevCaps(
							i, 
							&caps[i],    
							sizeof(JOYCAPS));
	}
	*nJoyP = nJoy;

	return caps;
}
Ejemplo n.º 12
0
/**
    [email protected] 2002-08-20:
    The old code returned true if there were any
    joystick capable drivers loaded (=always).
*/
bool wxJoystick::IsOk() const
{
    JOYINFO joyInfo;
    return (joyGetPos(m_joystick, & joyInfo) == JOYERR_NOERROR);
}
JNIEXPORT jint JNICALL Java_org_lwjgl_system_windows_Mmsystem_njoyGetPos(JNIEnv *__env, jclass clazz, jint joyID, jlong jiAddress) {
	LPJOYINFO ji = (LPJOYINFO)(intptr_t)jiAddress;
	UNUSED_PARAMS(__env, clazz)
	return (jint)joyGetPos(joyID, ji);
}
Ejemplo n.º 14
0
bool ScreenCamView::OnCreate( wxDocument* doc, /* TYPENOTE: Correct */ long flags )
{
	// Construct the (C++) child windows.
PORTNOTE("other","ScreenCamView::OnCreate - Removed scroller / ruler usage")
#ifndef EXCLUDE_FROM_XARALX
	RenderWindow = new CRenderWnd;

	HScrollBar = new CWinScroller(TRUE);
	VScrollBar = new CWinScroller(FALSE);
	Corner = new CScrollerCorner;
// WEBSTER - markn 15/1/97
// No rulers in Webster
#ifndef WEBSTER
	HRuler = new OILHorizontalRuler;
	VRuler = new OILVerticalRuler;
	OGadget = new OriginGadget;
#endif //webster	
	if (!RenderWindow || !HScrollBar || !VScrollBar || !Corner 
#ifndef WEBSTER
		||!HRuler ||!VRuler	||!OGadget
#endif //webster
		)
	{
		Error::SetError(_R(IDE_CREATE_VIEW_FAILED), 0);
		InformError();
		return -1;
	} 
#endif
	// Get base class to call CView functions, and get a document for this view.
	if( !CCamView::OnCreate( doc, flags ) )
		// Something went wrong - pass error back.
		return false;

PORTNOTE("other","ScreenCamView::OnCreate - Removed scroller usage")
	// Now get Windows to do its side of the construction.  The stated sizes and
	// positions of the windows here will be changed very soon.
#ifndef EXCLUDE_FROM_XARALX
	const CRect rcARect(-100,-100,-90,-90);
	if (!RenderWindow->Create("", "", 0, rcARect, this, 1) ||
		!HScrollBar->Create(0, rcARect, this, 2) ||
		!VScrollBar->Create(0, rcARect, this, 3) ||
		!Corner->Create("", "", 0, rcARect, this, 4)
// WEBSTER - markn 15/1/97
// No rulers in Webster
#ifndef WEBSTER
		|| !OGadget->Create(this)
		|| !HRuler->Create(this)
		|| !VRuler->Create(this)
#endif //webster
		)
	{
		Error::SetError(_R(IDE_CREATE_VIEW_FAILED), 0);
		InformError();
		return -1;
	}
#endif
	CreateNewDocView();

// WEBSTER - markn 15/1/97
// No rulers in Webster
#ifndef WEBSTER

	// init the kernel rulers and establish pointer links to them
PORTNOTE("other","ScreenCamView::OnCreate - Removed ruler usage")
#ifndef EXCLUDE_FROM_XARALX
	RulerPair* pRulers=pDocView->GetpRulerPair();
	pRulers->Init(pDocView,HRuler,VRuler,OGadget);
	HRuler->LinkToKernel(pRulers->GetpHorizontalRuler());
	VRuler->LinkToKernel(pRulers->GetpVerticalRuler());
#endif
#endif //webster
	ENSURE(pDocView != 0, "ScreenView::ScreenView can't get a new DocView!");
	pDocView->ConnectToOilView(this);
	
	// find the last view so we can use some of it's settings to create the new
//	DocView * LastView = DocView::GetSelected();

	// Link this and the DocView to the ViewState object.
	pDocView->SetViewState(Status);

////////////////////////////////////////////////////////////////////////////////
	
	wxScreenDC dc;
	wxSize pixsize=OSRenderRegion::GetFixedDCPPI(dc);

PORTNOTE("other","ScreenCamView::OnCreate - Removed scroller usage")
#ifndef EXCLUDE_FROM_XARALX
	// Set the logical pixel size accordingly (measured in millipoints).  Take the
	// opportunity to pass the values into the scrollers and the OIL -> Windows coordinate
	// transform system.
	HScrollBar->SetGranularity(72000L / pixwidth);
	VScrollBar->SetGranularity(72000L / pixheight);
#endif

	// Tell DocView how big the pixel size is.
	FIXED16 PixelWidth  = FIXED16(72000.0/pixsize.x);
	FIXED16 PixelHeight = FIXED16(72000.0/pixsize.y);
	ERROR3IF(PixelWidth != PixelHeight, "Luke says non-square pixels are not supported");
	pDocView->SetPixelSize(PixelWidth, PixelHeight);

	// Make our DocView the current DocView
	pDocView->SetCurrent();

	GetCanvas()->SetScrollRate(1,1);

	if (GetFrame())
		GetFrame()->GetClientSize(&CurrentSize.width,&CurrentSize.height);
	// Now the scrollers have all their information, we can set their appearance.
	// Make sure that they are invisible until the rest of the frame is ready
/*	XLONG x1 = CurrentSize.GetWidth () * PixelWidth;
	XLONG x2 = CurrentSize.GetHeight() * PixelHeight;
	GetFrame()->SetScrollbar(wxHORIZONTAL,0,x1,Status->WorkAreaExtent.hi.x-Status->WorkAreaExtent.lo.x,false);
	GetFrame()->SetScrollbar(  wxVERTICAL,0,x2,Status->WorkAreaExtent.hi.y-Status->WorkAreaExtent.lo.y,false);
*/
	SetScrollerStyle(ScrollerStyle = PropScrollersOn);
 	
 	ShowScrollers(DefaultScrollersState);
	ShowRulers(DefaultRulersState);

///////////////////////////////////////////////////////////////////////////////
	
	// Register for WM_DROPFILES messages
//	DragAcceptFiles(TRUE);

// WEBSTER - markn 12/2/97	
#if (_OLE_VER >= 0x200)
	// Register with OLE as a drop target.
	m_DropTarget.Register(this);
#endif

///////////////////////////////////////////////////////////////////////////////

	// now that the ScreenView (and hence DocView) is stable, broadcast a message to let everyone know
	BROADCAST_TO_ALL(DocViewMsg(pDocView,DocViewMsg::NEWANDSTABLE));

// ****************** BODGE **************************
// This code will tell windows to send us messages when
// the joystick gets waggled about.
// We should really release the joystick at some point later,
// but it gets released automatically when this ScreenView is
// destroyed, so it will do for now.

// The messages get passed to 'OnJoystickMove' member of this
// class.
	
#ifdef WIN32

PORTNOTE("other","ScreenCamView::OnCreate - Removed joystick usage")
#ifndef EXCLUDE_FROM_XARALX
	JOYINFO joyinfo;
	UINT32 wNumDevs, wDeviceID;
	BOOL bDev1Attached, bDev2Attached;

	// Are there any Joysticks available ?
    if((wNumDevs = joyGetNumDevs()) == 0)
        return 0;	// Nope.

	// Are there One or Two of them ?
    bDev1Attached = joyGetPos(JOYSTICKID1,&joyinfo) != JOYERR_UNPLUGGED;
    bDev2Attached = wNumDevs == 2 &&
                     joyGetPos(JOYSTICKID2,&joyinfo) != JOYERR_UNPLUGGED;

    if(bDev1Attached || bDev2Attached)		// Decide which joystick to use
        wDeviceID = bDev1Attached ? JOYSTICKID1 : JOYSTICKID2;
    else
        return 0;

	// Grab those Messages !!
	MMRESULT JoyResult = joySetCapture(m_hWnd, wDeviceID, NULL, TRUE);
#endif

#endif

// ****************** BODGE **************************

	// Return success!
	return true;
}
AREXPORT bool ArJoyHandler::init(void)
{

  myPhysMax = 1;
  myLastZ = 0;

  // first see if we can talk to the first joystick
  if (joyGetDevCaps(JOYSTICKID1,&myJoyCaps,sizeof(myJoyCaps)) == 
      JOYERR_NOERROR &&
      joyGetPos(JOYSTICKID1,&myJoyInfo) != JOYERR_UNPLUGGED) 
  {
    myJoyID = JOYSTICKID1;

    // So far, it seems that the x range is the same as that of y and
    // z, so only one is used
    myPhysMax  = myJoyCaps.wXmax - myJoyCaps.wXmin;
	/*
	ArLog::log(ArLog::Normal, "caps 0x%x numAxes %d maxAxes %d %s",
			myJoyCaps.wCaps, myJoyCaps.wNumAxes, myJoyCaps.wMaxAxes, myJoyCaps.szPname);
	ArLog::log(ArLog::Normal, 
		"xMin %d xMax %d yMin %d yMax %d zMin %d zMax %d rMin %d rMax %d uMin %d uMax %d",
			myJoyCaps.wXmin, myJoyCaps.wXmax, myJoyCaps.wYmin, myJoyCaps.wYmax, 
			myJoyCaps.wRmin, myJoyCaps.wRmax, myJoyCaps.wZmin, 
			myJoyCaps.wZmax, myJoyCaps.wUmin, myJoyCaps.wUmax); 
	*/
    myInitialized = true;
    startCal();
    endCal();
    return true;
  } 
  // we couldn't talk to the first one so try the second one
  else if (joyGetDevCaps(JOYSTICKID2,&myJoyCaps,sizeof(myJoyCaps)) == 
      JOYERR_NOERROR &&
      joyGetPos(JOYSTICKID2,&myJoyInfo) != JOYERR_UNPLUGGED) 
  {
    myJoyID = JOYSTICKID2;

    // So far, it seems that the x range is the same as that of y and
    // z, so only one is used
    myPhysMax = myJoyCaps.wXmax - myJoyCaps.wXmin;
	/*
	ArLog::log(ArLog::Normal, "2 caps 0x%x numAxes %d maxAxes %d %s",
			myJoyCaps.wCaps, myJoyCaps.wNumAxes, myJoyCaps.wMaxAxes, myJoyCaps.szPname);
	ArLog::log(ArLog::Normal, 
		"2 xMin %d xMax %d yMin %d yMax %d zMin %d zMax %d rMin %d rMax %d uMin %d uMax %d",
			myJoyCaps.wXmin, myJoyCaps.wXmax, myJoyCaps.wYmin, myJoyCaps.wYmax, 
			myJoyCaps.wRmin, myJoyCaps.wRmax, myJoyCaps.wZmin, 
			myJoyCaps.wZmax, myJoyCaps.wUmin, myJoyCaps.wUmax); 
    */
    myInitialized = true;
    startCal();
    endCal();
    return true;
  } 
  // we couldn't talk to either one
  else
  {
    myInitialized = false;
    return false;
  }

  // Just to prevent any possible divide-by-zeros...
  if (myPhysMax == 0) {
    myPhysMax = 1;
  }

  getData();
}
Ejemplo n.º 16
0
int main(int argc, char **argv)
{
	int i;
	int midi_out_number = MIDI_MAPPER;
	int channel_number = 0;
	int use_joystick_1 = 0;
	int controller_number_x1 = -1;
	int controller_number_y1 = -1;
	int controller_number_z1 = -1;
	int controller_number_a1 = -1;
	int controller_number_b1 = -1;
	int controller_number_c1 = -1;
	int controller_number_d1 = -1;
	int last_value_x1 = -1;
	int last_value_y1 = -1;
	int last_value_z1 = -1;
	int last_value_a1 = -1;
	int last_value_b1 = -1;
	int last_value_c1 = -1;
	int last_value_d1 = -1;
	int use_joystick_2 = 0;
	int controller_number_x2 = -1;
	int controller_number_y2 = -1;
	int controller_number_z2 = -1;
	int controller_number_a2 = -1;
	int controller_number_b2 = -1;
	int controller_number_c2 = -1;
	int controller_number_d2 = -1;
	int last_value_x2 = -1;
	int last_value_y2 = -1;
	int last_value_z2 = -1;
	int last_value_a2 = -1;
	int last_value_b2 = -1;
	int last_value_c2 = -1;
	int last_value_d2 = -1;
	JOYINFO joy_info;
	JOYCAPS joy_caps_1;
	JOYCAPS joy_caps_2;

	for (i = 1; i < argc; i++)
	{
		if (strcmp(argv[i], "--out") == 0)
		{
			if (++i == argc) usage(argv[0]);
			sscanf(argv[i], "%d", &midi_out_number);
		}
		else if (strcmp(argv[i], "--channel") == 0)
		{
			if (++i == argc) usage(argv[0]);
			sscanf(argv[i], "%d", &channel_number);
		}
		else if (strcmp(argv[i], "--x1") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_1 = 1;
			sscanf(argv[i], "%d", &controller_number_x1);
		}
		else if (strcmp(argv[i], "--y1") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_1 = 1;
			sscanf(argv[i], "%d", &controller_number_y1);
		}
		else if (strcmp(argv[i], "--z1") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_1 = 1;
			sscanf(argv[i], "%d", &controller_number_z1);
		}
		else if (strcmp(argv[i], "--a1") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_1 = 1;
			sscanf(argv[i], "%d", &controller_number_a1);
		}
		else if (strcmp(argv[i], "--b1") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_1 = 1;
			sscanf(argv[i], "%d", &controller_number_b1);
		}
		else if (strcmp(argv[i], "--c1") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_1 = 1;
			sscanf(argv[i], "%d", &controller_number_c1);
		}
		else if (strcmp(argv[i], "--d1") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_1 = 1;
			sscanf(argv[i], "%d", &controller_number_d1);
		}
		else if (strcmp(argv[i], "--x2") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_2 = 1;
			sscanf(argv[i], "%d", &controller_number_x2);
		}
		else if (strcmp(argv[i], "--y2") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_2 = 1;
			sscanf(argv[i], "%d", &controller_number_y2);
		}
		else if (strcmp(argv[i], "--z2") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_2 = 1;
			sscanf(argv[i], "%d", &controller_number_z2);
		}
		else if (strcmp(argv[i], "--a2") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_2 = 1;
			sscanf(argv[i], "%d", &controller_number_a2);
		}
		else if (strcmp(argv[i], "--b2") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_2 = 1;
			sscanf(argv[i], "%d", &controller_number_b2);
		}
		else if (strcmp(argv[i], "--c2") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_2 = 1;
			sscanf(argv[i], "%d", &controller_number_c2);
		}
		else if (strcmp(argv[i], "--d2") == 0)
		{
			if (++i == argc) usage(argv[0]);
			use_joystick_2 = 1;
			sscanf(argv[i], "%d", &controller_number_d2);
		}
		else
		{
			usage(argv[0]);
		}
	}

	if (!use_joystick_1 && !use_joystick_2)
	{
		fprintf(stderr, "Error:  You must assign a controller to at least one joystick axis or button.\n");
		exit(1);
	}

	if (use_joystick_1)
	{
		if (joyGetPos(JOYSTICKID1, &joy_info) != JOYERR_NOERROR)
		{
			fprintf(stderr, "Error:  Cannot access joystick #1.\n");
			exit(1);
		}

		joyGetDevCaps(JOYSTICKID1, &joy_caps_1, sizeof(JOYCAPS));
	}

	if (use_joystick_2)
	{
		if (joyGetPos(JOYSTICKID2, &joy_info) != JOYERR_NOERROR)
		{
			fprintf(stderr, "Error:  Cannot access joystick #2.\n");
			exit(1);
		}

		joyGetDevCaps(JOYSTICKID2, &joy_caps_2, sizeof(JOYCAPS));
	}

	if (midiOutOpen(&midi_out, midi_out_number, 0, 0, 0) != MMSYSERR_NOERROR)
	{
		fprintf(stderr, "Error:  Cannot open MIDI output port #%d.\n", midi_out_number);
		exit(1);
	}

	SetConsoleCtrlHandler(control_handler, TRUE);

	while (1)
	{
		if ((use_joystick_1) && (joyGetPos(JOYSTICKID1, &joy_info) == JOYERR_NOERROR))
		{
			if (controller_number_x1 >= 0)
			{
				int value = (joy_info.wXpos - joy_caps_1.wXmin) * 128 / (joy_caps_1.wXmax - joy_caps_1.wXmin);

				if (value != last_value_x1)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_x1, value);
					last_value_x1 = value;
				}
			}

			if (controller_number_y1 >= 0)
			{
				int value = (joy_info.wYpos - joy_caps_1.wYmin) * 128 / (joy_caps_1.wYmax - joy_caps_1.wYmin);

				if (value != last_value_y1)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_y1, value);
					last_value_y1 = value;
				}
			}

			if (controller_number_z1 >= 0)
			{
				int value = (joy_info.wZpos - joy_caps_1.wZmin) * 128 / (joy_caps_1.wZmax - joy_caps_1.wZmin);

				if (value != last_value_z1)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_z1, value);
					last_value_z1 = value;
				}
			}

			if (controller_number_a1 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON1) == JOY_BUTTON1) ? 127 : 0;

				if (value != last_value_a1)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_a1, value);
					last_value_a1 = value;
				}
			}

			if (controller_number_b1 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON2) == JOY_BUTTON2) ? 127 : 0;

				if (value != last_value_b1)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_b1, value);
					last_value_b1 = value;
				}
			}

			if (controller_number_c1 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON3) == JOY_BUTTON3) ? 127 : 0;

				if (value != last_value_c1)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_c1, value);
					last_value_c1 = value;
				}
			}

			if (controller_number_d1 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON4) == JOY_BUTTON4) ? 127 : 0;

				if (value != last_value_d1)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_d1, value);
					last_value_d1 = value;
				}
			}
		}

		if ((use_joystick_2) && (joyGetPos(JOYSTICKID2, &joy_info) == JOYERR_NOERROR))
		{
			if (controller_number_x2 >= 0)
			{
				int value = (joy_info.wXpos - joy_caps_2.wXmin) * 128 / (joy_caps_2.wXmax - joy_caps_2.wXmin);

				if (value != last_value_x2)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_x2, value);
					last_value_x2 = value;
				}
			}

			if (controller_number_y2 >= 0)
			{
				int value = (joy_info.wYpos - joy_caps_2.wYmin) * 128 / (joy_caps_2.wYmax - joy_caps_2.wYmin);

				if (value != last_value_y2)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_y2, value);
					last_value_y2 = value;
				}
			}

			if (controller_number_z2 >= 0)
			{
				int value = (joy_info.wZpos - joy_caps_2.wZmin) * 128 / (joy_caps_2.wZmax - joy_caps_2.wZmin);

				if (value != last_value_z2)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_z2, value);
					last_value_z2 = value;
				}
			}

			if (controller_number_a2 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON1) == JOY_BUTTON1) ? 127 : 0;

				if (value != last_value_a2)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_a2, value);
					last_value_a2 = value;
				}
			}

			if (controller_number_b2 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON2) == JOY_BUTTON2) ? 127 : 0;

				if (value != last_value_b2)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_b2, value);
					last_value_b2 = value;
				}
			}

			if (controller_number_c2 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON3) == JOY_BUTTON3) ? 127 : 0;

				if (value != last_value_c2)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_c2, value);
					last_value_c2 = value;
				}
			}

			if (controller_number_d2 >= 0)
			{
				int value = ((joy_info.wButtons & JOY_BUTTON4) == JOY_BUTTON4) ? 127 : 0;

				if (value != last_value_d2)
				{
					send_midi_control_change(midi_out, channel_number, controller_number_d2, value);
					last_value_d2 = value;
				}
			}
		}

		Sleep(5);
	}

	midiOutClose(midi_out);
	return 0;
}
Ejemplo n.º 17
0
        bool JoystickImpl::isConnected(Uint8 id)
        {
            JOYINFO joyInfo;

            return joyGetPos(id, &joyInfo) == JOYERR_NOERROR;
        }