ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

joystick.c
Go to the documentation of this file.
00001 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
00002 /*
00003  * joystick functions
00004  *
00005  * Copyright 1997 Andreas Mohr
00006  *       2000 Wolfgang Schwotzer
00007  *                Eric Pouech
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00022  */
00023 
00024 #include "config.h"
00025 
00026 #ifdef HAVE_UNISTD_H
00027 # include <unistd.h>
00028 #endif
00029 #include <stdarg.h>
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <fcntl.h>
00034 #ifdef HAVE_SYS_IOCTL_H
00035 #include <sys/ioctl.h>
00036 #endif
00037 
00038 #include "winemm.h"
00039 #include "windef.h"
00040 #include "winbase.h"
00041 #include "mmsystem.h"
00042 #include "wingdi.h"
00043 #include "winuser.h"
00044 #include "winnls.h"
00045 
00046 #include "mmddk.h"
00047 
00048 #include "wine/debug.h"
00049 
00050 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
00051 
00052 #define MAXJOYSTICK (JOYSTICKID2 + 30)
00053 #define JOY_PERIOD_MIN  (10)    /* min Capture time period */
00054 #define JOY_PERIOD_MAX  (1000)  /* max Capture time period */
00055 
00056 typedef struct tagWINE_JOYSTICK {
00057     JOYINFO ji;
00058     HWND    hCapture;
00059     UINT    wTimer;
00060     DWORD   threshold;
00061     BOOL    bChanged;
00062     HDRVR   hDriver;
00063 } WINE_JOYSTICK;
00064 
00065 static  WINE_JOYSTICK   JOY_Sticks[MAXJOYSTICK];
00066 
00067 /**************************************************************************
00068  *              JOY_LoadDriver      [internal]
00069  */
00070 static  BOOL JOY_LoadDriver(DWORD dwJoyID)
00071 {
00072     if (dwJoyID >= MAXJOYSTICK)
00073     return FALSE;
00074     if (JOY_Sticks[dwJoyID].hDriver)
00075     return TRUE;
00076 
00077     JOY_Sticks[dwJoyID].hDriver = OpenDriverA("winejoystick.drv", 0, dwJoyID);
00078     return (JOY_Sticks[dwJoyID].hDriver != 0);
00079 }
00080 
00081 /**************************************************************************
00082  *              JOY_Timer       [internal]
00083  */
00084 static  void    CALLBACK    JOY_Timer(HWND hWnd, UINT wMsg, UINT_PTR wTimer, DWORD dwTime)
00085 {
00086     int         i;
00087     WINE_JOYSTICK*  joy;
00088     JOYINFO     ji;
00089     LONG        pos;
00090     unsigned        buttonChange;
00091 
00092     for (i = 0; i < MAXJOYSTICK; i++) {
00093     joy = &JOY_Sticks[i];
00094 
00095     if (joy->hCapture != hWnd) continue;
00096 
00097     joyGetPos(i, &ji);
00098     pos = MAKELONG(ji.wXpos, ji.wYpos);
00099 
00100     if (!joy->bChanged ||
00101         abs(joy->ji.wXpos - ji.wXpos) > joy->threshold ||
00102         abs(joy->ji.wYpos - ji.wYpos) > joy->threshold) {
00103         SendMessageA(joy->hCapture, MM_JOY1MOVE + i, ji.wButtons, pos);
00104         joy->ji.wXpos = ji.wXpos;
00105         joy->ji.wYpos = ji.wYpos;
00106     }
00107     if (!joy->bChanged ||
00108         abs(joy->ji.wZpos - ji.wZpos) > joy->threshold) {
00109         SendMessageA(joy->hCapture, MM_JOY1ZMOVE + i, ji.wButtons, pos);
00110         joy->ji.wZpos = ji.wZpos;
00111     }
00112     if ((buttonChange = joy->ji.wButtons ^ ji.wButtons) != 0) {
00113         if (ji.wButtons & buttonChange)
00114         SendMessageA(joy->hCapture, MM_JOY1BUTTONDOWN + i,
00115                  (buttonChange << 8) | (ji.wButtons & buttonChange), pos);
00116         if (joy->ji.wButtons & buttonChange)
00117         SendMessageA(joy->hCapture, MM_JOY1BUTTONUP + i,
00118                  (buttonChange << 8) | (joy->ji.wButtons & buttonChange), pos);
00119         joy->ji.wButtons = ji.wButtons;
00120     }
00121     }
00122 }
00123 
00124 /**************************************************************************
00125  *                              joyConfigChanged        [WINMM.@]
00126  */
00127 MMRESULT WINAPI joyConfigChanged(DWORD flags)
00128 {
00129     FIXME("(%x) - stub\n", flags);
00130 
00131     if (flags)
00132     return JOYERR_PARMS;
00133 
00134     return JOYERR_NOERROR;
00135 }
00136 
00137 /**************************************************************************
00138  *              joyGetNumDevs       [WINMM.@]
00139  */
00140 UINT WINAPI joyGetNumDevs(void)
00141 {
00142     UINT    ret = 0;
00143     int     i;
00144 
00145     for (i = 0; i < MAXJOYSTICK; i++) {
00146     if (JOY_LoadDriver(i)) {
00147             ret += SendDriverMessage(JOY_Sticks[i].hDriver, JDD_GETNUMDEVS, 0, 0);
00148     }
00149     }
00150     return ret;
00151 }
00152 
00153 /**************************************************************************
00154  *              joyGetDevCapsW      [WINMM.@]
00155  */
00156 MMRESULT WINAPI joyGetDevCapsW(UINT_PTR wID, LPJOYCAPSW lpCaps, UINT wSize)
00157 {
00158     if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
00159     if (!JOY_LoadDriver(wID))   return MMSYSERR_NODRIVER;
00160 
00161     lpCaps->wPeriodMin = JOY_PERIOD_MIN; /* FIXME */
00162     lpCaps->wPeriodMax = JOY_PERIOD_MAX; /* FIXME (same as MS Joystick Driver) */
00163 
00164     return SendDriverMessage(JOY_Sticks[wID].hDriver, JDD_GETDEVCAPS, (LPARAM)lpCaps, wSize);
00165 }
00166 
00167 /**************************************************************************
00168  *              joyGetDevCapsA      [WINMM.@]
00169  */
00170 MMRESULT WINAPI joyGetDevCapsA(UINT_PTR wID, LPJOYCAPSA lpCaps, UINT wSize)
00171 {
00172     JOYCAPSW    jcw;
00173     MMRESULT    ret;
00174 
00175     if (lpCaps == NULL) return MMSYSERR_INVALPARAM;
00176 
00177     ret = joyGetDevCapsW(wID, &jcw, sizeof(jcw));
00178 
00179     if (ret == JOYERR_NOERROR)
00180     {
00181         lpCaps->wMid = jcw.wMid;
00182         lpCaps->wPid = jcw.wPid;
00183         WideCharToMultiByte( CP_ACP, 0, jcw.szPname, -1, lpCaps->szPname,
00184                              sizeof(lpCaps->szPname), NULL, NULL );
00185         lpCaps->wXmin = jcw.wXmin;
00186         lpCaps->wXmax = jcw.wXmax;
00187         lpCaps->wYmin = jcw.wYmin;
00188         lpCaps->wYmax = jcw.wYmax;
00189         lpCaps->wZmin = jcw.wZmin;
00190         lpCaps->wZmax = jcw.wZmax;
00191         lpCaps->wNumButtons = jcw.wNumButtons;
00192         lpCaps->wPeriodMin = jcw.wPeriodMin;
00193         lpCaps->wPeriodMax = jcw.wPeriodMax;
00194 
00195         if (wSize >= sizeof(JOYCAPSA)) { /* Win95 extensions ? */
00196             lpCaps->wRmin = jcw.wRmin;
00197             lpCaps->wRmax = jcw.wRmax;
00198             lpCaps->wUmin = jcw.wUmin;
00199             lpCaps->wUmax = jcw.wUmax;
00200             lpCaps->wVmin = jcw.wVmin;
00201             lpCaps->wVmax = jcw.wVmax;
00202             lpCaps->wCaps = jcw.wCaps;
00203             lpCaps->wMaxAxes = jcw.wMaxAxes;
00204             lpCaps->wNumAxes = jcw.wNumAxes;
00205             lpCaps->wMaxButtons = jcw.wMaxButtons;
00206             WideCharToMultiByte( CP_ACP, 0, jcw.szRegKey, -1, lpCaps->szRegKey,
00207                                  sizeof(lpCaps->szRegKey), NULL, NULL );
00208             WideCharToMultiByte( CP_ACP, 0, jcw.szOEMVxD, -1, lpCaps->szOEMVxD,
00209                                  sizeof(lpCaps->szOEMVxD), NULL, NULL );
00210         }
00211     }
00212 
00213     return ret;
00214 }
00215 
00216 /**************************************************************************
00217  *                              joyGetPosEx             [WINMM.@]
00218  */
00219 MMRESULT WINAPI joyGetPosEx(UINT wID, LPJOYINFOEX lpInfo)
00220 {
00221     TRACE("(%d, %p);\n", wID, lpInfo);
00222 
00223     if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
00224     if (!JOY_LoadDriver(wID))   return MMSYSERR_NODRIVER;
00225 
00226     lpInfo->dwXpos = 0;
00227     lpInfo->dwYpos = 0;
00228     lpInfo->dwZpos = 0;
00229     lpInfo->dwRpos = 0;
00230     lpInfo->dwUpos = 0;
00231     lpInfo->dwVpos = 0;
00232     lpInfo->dwButtons = 0;
00233     lpInfo->dwButtonNumber = 0;
00234     lpInfo->dwPOV = 0;
00235     lpInfo->dwReserved1 = 0;
00236     lpInfo->dwReserved2 = 0;
00237 
00238     return SendDriverMessage(JOY_Sticks[wID].hDriver, JDD_GETPOSEX, (LPARAM)lpInfo, 0);
00239 }
00240 
00241 /**************************************************************************
00242  *              joyGetPos           [WINMM.@]
00243  */
00244 MMRESULT WINAPI joyGetPos(UINT wID, LPJOYINFO lpInfo)
00245 {
00246     TRACE("(%d, %p);\n", wID, lpInfo);
00247 
00248     if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
00249     if (!JOY_LoadDriver(wID))   return MMSYSERR_NODRIVER;
00250 
00251     lpInfo->wXpos = 0;
00252     lpInfo->wYpos = 0;
00253     lpInfo->wZpos = 0;
00254     lpInfo->wButtons = 0;
00255 
00256     return SendDriverMessage(JOY_Sticks[wID].hDriver, JDD_GETPOS, (LPARAM)lpInfo, 0);
00257 }
00258 
00259 /**************************************************************************
00260  *              joyGetThreshold     [WINMM.@]
00261  */
00262 MMRESULT WINAPI joyGetThreshold(UINT wID, LPUINT lpThreshold)
00263 {
00264     TRACE("(%04X, %p);\n", wID, lpThreshold);
00265 
00266     if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
00267 
00268     *lpThreshold = JOY_Sticks[wID].threshold;
00269     return JOYERR_NOERROR;
00270 }
00271 
00272 /**************************************************************************
00273  *              joyReleaseCapture   [WINMM.@]
00274  */
00275 MMRESULT WINAPI joyReleaseCapture(UINT wID)
00276 {
00277     TRACE("(%04X);\n", wID);
00278 
00279     if (wID >= MAXJOYSTICK)     return JOYERR_PARMS;
00280     if (!JOY_LoadDriver(wID))       return MMSYSERR_NODRIVER;
00281     if (!JOY_Sticks[wID].hCapture)  return JOYERR_NOCANDO;
00282 
00283     KillTimer(JOY_Sticks[wID].hCapture, JOY_Sticks[wID].wTimer);
00284     JOY_Sticks[wID].hCapture = 0;
00285     JOY_Sticks[wID].wTimer = 0;
00286 
00287     return JOYERR_NOERROR;
00288 }
00289 
00290 /**************************************************************************
00291  *              joySetCapture       [WINMM.@]
00292  */
00293 MMRESULT WINAPI joySetCapture(HWND hWnd, UINT wID, UINT wPeriod, BOOL bChanged)
00294 {
00295     TRACE("(%p, %04X, %d, %d);\n",  hWnd, wID, wPeriod, bChanged);
00296 
00297     if (wID >= MAXJOYSTICK || hWnd == 0) return JOYERR_PARMS;
00298     if (wPeriod<JOY_PERIOD_MIN || wPeriod>JOY_PERIOD_MAX) return JOYERR_PARMS;
00299     if (!JOY_LoadDriver(wID)) return MMSYSERR_NODRIVER;
00300 
00301     if (JOY_Sticks[wID].hCapture || !IsWindow(hWnd))
00302     return JOYERR_NOCANDO; /* FIXME: what should be returned ? */
00303 
00304     if (joyGetPos(wID, &JOY_Sticks[wID].ji) != JOYERR_NOERROR)
00305     return JOYERR_UNPLUGGED;
00306 
00307     if ((JOY_Sticks[wID].wTimer = SetTimer(hWnd, 0, wPeriod, JOY_Timer)) == 0)
00308     return JOYERR_NOCANDO;
00309 
00310     JOY_Sticks[wID].hCapture = hWnd;
00311     JOY_Sticks[wID].bChanged = bChanged;
00312 
00313     return JOYERR_NOERROR;
00314 }
00315 
00316 /**************************************************************************
00317  *              joySetThreshold     [WINMM.@]
00318  */
00319 MMRESULT WINAPI joySetThreshold(UINT wID, UINT wThreshold)
00320 {
00321     TRACE("(%04X, %d);\n", wID, wThreshold);
00322 
00323     if (wID >= MAXJOYSTICK) return MMSYSERR_INVALPARAM;
00324 
00325     JOY_Sticks[wID].threshold = wThreshold;
00326 
00327     return JOYERR_NOERROR;
00328 }

Generated on Fri May 25 2012 04:24:59 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.