Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1256 lines
34 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dihid.h
  6. * Content: DirectInput internal include file for HID
  7. *
  8. ***************************************************************************/
  9. #ifndef _DIHID_H
  10. #define _DIHID_H
  11. /*
  12. * Defines that should be in hidusage.h but are not yet
  13. */
  14. #ifndef HID_USAGE_PAGE_PID
  15. #define HID_USAGE_PAGE_PID ( (USAGE) 0x0000f )
  16. #endif
  17. #ifndef HID_USAGE_PAGE_VENDOR
  18. #define HID_USAGE_PAGE_VENDOR ( (USAGE) 0xff00 )
  19. #endif
  20. #ifndef HID_USAGE_SIMULATION_RUDDER
  21. #define HID_USAGE_SIMULATION_RUDDER ((USAGE) 0xBA)
  22. #endif
  23. #ifndef HID_USAGE_SIMULATION_THROTTLE
  24. #define HID_USAGE_SIMULATION_THROTTLE ((USAGE) 0xBB)
  25. #endif
  26. #ifndef HID_USAGE_SIMULATION_ACCELERATOR
  27. #define HID_USAGE_SIMULATION_ACCELERATOR ((USAGE) 0xC4)
  28. #endif
  29. #ifndef HID_USAGE_SIMULATION_BRAKE
  30. #define HID_USAGE_SIMULATION_BRAKE ((USAGE) 0xC5)
  31. #endif
  32. #ifndef HID_USAGE_SIMULATION_CLUTCH
  33. #define HID_USAGE_SIMULATION_CLUTCH ((USAGE) 0xC6)
  34. #endif
  35. #ifndef HID_USAGE_SIMULATION_SHIFTER
  36. #define HID_USAGE_SIMULATION_SHIFTER ((USAGE) 0xC7)
  37. #endif
  38. #ifndef HID_USAGE_SIMULATION_STEERING
  39. #define HID_USAGE_SIMULATION_STEERING ((USAGE) 0xC8)
  40. #endif
  41. #ifndef HID_USAGE_GAME_POV
  42. #define HID_USAGE_GAME_POV ((USAGE) 0x20)
  43. #endif
  44. /*****************************************************************************
  45. *
  46. * @doc INTERNAL
  47. *
  48. * @struct HIDDEVICEINFO |
  49. *
  50. * Records information about a single hid device.
  51. *
  52. * @field DIOBJECTSTATICDATA | osd |
  53. *
  54. * Standard information that identifies the device crudely.
  55. *
  56. * The <e DIOBJECTSTATICDATA.dwDevType> field contains the
  57. * device type code, used by
  58. * <f CDIDEnum_Next>.
  59. *
  60. * If the device is a HID mouse, then the remaining fields
  61. * are commandeered as follows:
  62. *
  63. * The <e DIOBJECTSTATICDATA.pcguid> field is the number
  64. * of buttons on the mouse.
  65. *
  66. * The <e DIOBJECTSTATICDATA.CreateDcb> field is the number
  67. * of axes on the mouse.
  68. *
  69. * See <f DIHid_ProbeMouse> for an explanation of why we
  70. * need to do this.
  71. *
  72. * @field PSP_DEVICE_INTERFACE_DETAIL_DATA | pdidd |
  73. *
  74. * Pointer to name for device to be used in <f CreateFile>.
  75. *
  76. * @field HKEY | hk |
  77. *
  78. * Registry key that contains configuration information.
  79. * Sadly, we must keep it open because there is no way to
  80. * obtain the name of the key, and the only way to open the
  81. * key is inside an enumeration.
  82. *
  83. * @field HKEY | hkOld |
  84. *
  85. * Registry key that contains configuration information.
  86. * This key originally pointed to the registry used in Win2k Gold.
  87. * It is to maintain compatibiltiy with Win2k Gold.
  88. *
  89. * @field LPTSTR | ptszId |
  90. *
  91. * Cached device ID that allows us to access other information
  92. * about the device.
  93. *
  94. * @field GUID | guid |
  95. *
  96. * The instance GUID for the device.
  97. *
  98. * @field GUID | guidProduct |
  99. *
  100. * The product GUID for the device.
  101. *
  102. * @field WORD | ProductID |
  103. *
  104. * The PID for the device
  105. *
  106. * @field WORD | VendorID |
  107. *
  108. * The VID for the device
  109. *
  110. *
  111. *****************************************************************************/
  112. typedef struct HIDDEVICEINFO
  113. {
  114. DIOBJECTSTATICDATA osd;
  115. PSP_DEVICE_INTERFACE_DETAIL_DATA pdidd;
  116. HKEY hk;
  117. HKEY hkOld;
  118. LPTSTR ptszId;
  119. GUID guid;
  120. GUID guidProduct;
  121. int idJoy;
  122. WORD ProductID;
  123. WORD VendorID;
  124. BOOL fAttached;
  125. } HIDDEVICEINFO, *PHIDDEVICEINFO;
  126. /*****************************************************************************
  127. *
  128. * @doc INTERNAL
  129. *
  130. * @struct HIDDEVICELIST |
  131. *
  132. * Records information about all the HID devices.
  133. *
  134. * @field int | chdi |
  135. *
  136. * Number of items in the list that are in use.
  137. *
  138. * @field int | chdiAlloc |
  139. *
  140. * Number of items allocated in the list.
  141. *
  142. * @field HIDDEVICEINFO | rghdi[0] |
  143. *
  144. * Variable-size array of device information structures.
  145. *
  146. *****************************************************************************/
  147. typedef struct HIDDEVICELIST
  148. {
  149. int chdi;
  150. int chdiAlloc;
  151. int idMaxJoy;
  152. HIDDEVICEINFO rghdi[0];
  153. } HIDDEVICELIST, *PHIDDEVICELIST;
  154. extern PHIDDEVICELIST g_phdl;
  155. #define cbHdlChdi(chdi) FIELD_OFFSET(HIDDEVICELIST, rghdi[chdi])
  156. /*
  157. * We choose our starting point at 64 devices, since
  158. * that's the maximum number of USB devices supported. This
  159. * avoids needless reallocs.
  160. */
  161. #define chdiMax 64
  162. #define chdiInit 16
  163. /*
  164. * Tag for unused translation of object instance
  165. */
  166. #define NOREGTRANSLATION (0x80000000)
  167. /*
  168. * VID/PID definitions used to handle analog devices
  169. */
  170. #define MSFT_SYSTEM_VID (0x45E)
  171. #define MSFT_SYSTEM_PID (0x100)
  172. #define ANALOG_ID_ROOT TEXT("VID_045E&PID_01")
  173. /*
  174. * VID/PID template so that upper case hex is always used
  175. */
  176. #define VID_PID_TEMPLATE TEXT("VID_%04X&PID_%04X")
  177. /*
  178. * Size of string in characters generated using VID_PID_TEMPLATE
  179. */
  180. #define cbszVIDPID cA( VID_PID_TEMPLATE )
  181. /*****************************************************************************
  182. *
  183. * dihidenm.c - HID enumeration functions.
  184. *
  185. *****************************************************************************/
  186. extern TCHAR g_tszIdLastRemoved[MAX_PATH]; //in dihidenm.c
  187. extern DWORD g_tmLastRemoved; //in dihinenm.c
  188. STDMETHODIMP hresFindHIDInstanceGUID(PCGUID pguid, CREATEDCB *pcdcb);
  189. STDMETHODIMP hresFindHIDDeviceInterface(LPCTSTR ptszPath, LPGUID pguidOut);
  190. PHIDDEVICEINFO EXTERNAL phdiFindHIDInstanceGUID(PCGUID pguid);
  191. PHIDDEVICEINFO EXTERNAL phdiFindHIDDeviceInterface(LPCTSTR ptszPath);
  192. void EXTERNAL DIHid_BuildHidList(BOOL fForce);
  193. void EXTERNAL DIHid_EmptyHidList(void);
  194. BOOL EXTERNAL
  195. DIHid_GetDevicePath(HDEVINFO hdev,
  196. PSP_DEVICE_INTERFACE_DATA pdid,
  197. PSP_DEVICE_INTERFACE_DETAIL_DATA *ppdidd,
  198. PSP_DEVINFO_DATA pdinf);
  199. BOOL EXTERNAL
  200. DIHid_GetDeviceInstanceId(HDEVINFO hdev,
  201. PSP_DEVINFO_DATA pdinf,
  202. LPTSTR *pptszId);
  203. BOOL EXTERNAL
  204. DIHid_GetInstanceGUID(HKEY hk, LPGUID pguid);
  205. /*****************************************************************************
  206. *
  207. * diguid.c - GUID generation
  208. *
  209. *****************************************************************************/
  210. void EXTERNAL DICreateGuid(LPGUID pguid);
  211. void EXTERNAL DICreateStaticGuid(LPGUID pguid, WORD pid, WORD vid);
  212. /*****************************************************************************
  213. *
  214. * dihid.c
  215. *
  216. *****************************************************************************/
  217. /*****************************************************************************
  218. *
  219. * We will just use the HID item index as our DirectInput
  220. * internal ID number, which is in turn an index into the
  221. * <t DIOBJECTDATAFORMAT> array.
  222. *
  223. * Keyboard support requires a translation table.
  224. * Other devices also a translation table so that the external
  225. * instance numbers can be made compatible with legacy ones and
  226. * so that secondary aliases can be separated from primary ones.
  227. *
  228. * Since HID restarts the item index counter at zero for
  229. * each of input, feature, and output, we need to do some
  230. * adjustment so there aren't any collisions. So we
  231. * shift the features to start after the inputs, and the
  232. * outputs to start after the features.
  233. *
  234. * The <e CHid.rgdwBase> array contains the amount by which
  235. * each group of HID item indexes has been shifted.
  236. *
  237. *****************************************************************************/
  238. /*****************************************************************************
  239. *
  240. * @doc INTERNAL
  241. *
  242. * @func BOOL | HidP_IsValidReportType |
  243. *
  244. * For debugging only. Check if a value is a valid
  245. * <t HIDP_REPORT_TYPE>.
  246. *
  247. * Note that we also create a "fake" report type in which
  248. * to record our collections.
  249. *
  250. * @field HIDP_REPORT_TYPE | type |
  251. *
  252. * One of the values
  253. * <c HidP_Input>,
  254. * <c HidP_Output>,
  255. * or
  256. * <c HidP_Feature>. Hopefully.
  257. *
  258. *****************************************************************************/
  259. #define HidP_Max (HidP_Feature + 1)
  260. #define HidP_Coll HidP_Max
  261. #define HidP_MaxColl (HidP_Coll + 1)
  262. BOOL INLINE
  263. HidP_IsValidReportType(HIDP_REPORT_TYPE type)
  264. {
  265. CAssertF(HidP_Input == 0);
  266. CAssertF(HidP_Output == 1);
  267. CAssertF(HidP_Feature == 2);
  268. return type < HidP_Max;
  269. }
  270. /*****************************************************************************
  271. *
  272. * There are three (overlapping) classes of HID reports.
  273. *
  274. * InputLike - HidP_Input and HidP_Feature
  275. * OutputLike - HidP_Output and HidP_Feature
  276. * NothingLike - HidP_Coll
  277. *
  278. *****************************************************************************/
  279. BOOL INLINE
  280. HidP_IsInputLike(HIDP_REPORT_TYPE type)
  281. {
  282. return type == HidP_Input || type == HidP_Feature;
  283. }
  284. BOOL INLINE
  285. HidP_IsOutputLike(HIDP_REPORT_TYPE type)
  286. {
  287. return type == HidP_Output || type == HidP_Feature;
  288. }
  289. /*****************************************************************************
  290. *
  291. * @doc INTERNAL
  292. *
  293. * @struct LMINMAX |
  294. *
  295. * Min and max, that's all. These are kept in structures
  296. * to make logical-to-physical and physical-to-logical
  297. * translations less gross.
  298. *
  299. * @field LONG | Min |
  300. *
  301. * The minimum value.
  302. *
  303. * @field LONG | Max |
  304. *
  305. * The maximum value.
  306. *
  307. *****************************************************************************/
  308. typedef struct LMINMAX
  309. {
  310. LONG Min;
  311. LONG Max;
  312. } LMINMAX, *PLMINMAX;
  313. typedef const LMINMAX *PCLMINMAX;
  314. /*****************************************************************************
  315. *
  316. * @doc INTERNAL
  317. *
  318. * @struct HIDGROUPCAPS |
  319. *
  320. * This structure unifies the various HID caps structures
  321. * <t HIDP_BUTTON_CAPS> and
  322. * <t HIDP_VALUE_CAPS>.
  323. *
  324. * @field HIDP_REPORT_TYPE | type |
  325. *
  326. * One of the values
  327. * <c HidP_Input>,
  328. * <c HidP_Output>,
  329. * or
  330. * <c HidP_Feature>.
  331. *
  332. * @field UINT | cObj |
  333. *
  334. * Number of objects in this group.
  335. *
  336. * @field USAGE | UsagePage |
  337. *
  338. * Usage page for all usages in the group.
  339. *
  340. * @field USAGE | UsageMin |
  341. *
  342. * First usage described by this group. The remaining
  343. * items are numbered consecutively starting from
  344. * this value.
  345. *
  346. * @field USHORT | StringMin |
  347. *
  348. * String for first usage described by this group.
  349. * The remaining strings are numbered consecutively
  350. * starting from this value, unless the string maximum
  351. * is reached, in which case all subsequent objects
  352. * share that last string.
  353. *
  354. * @field USHORT | StringMax |
  355. *
  356. * Last string.
  357. *
  358. * @field USHORT | DesignatorMin |
  359. *
  360. * Designator for first usage described by this group.
  361. * The remaining designators are numbered consecutively
  362. * starting from this value, unless the designator maximum
  363. * is reached, in which case all subsequent objects
  364. * share that last designator.
  365. *
  366. * @field USHORT | DesignatorMax |
  367. *
  368. * Last designator.
  369. *
  370. * @field USHORT | DataIndexMin |
  371. *
  372. * Data index for the first usage described by this group.
  373. * The remaining data index values are numbered consecutively
  374. * starting from this value.
  375. *
  376. * @field USHORT | usGranularity |
  377. *
  378. * If object is a POV or wheel, then contains device granularity.
  379. *
  380. * @field LONG | lMask |
  381. *
  382. * Mask bits used for sign extension. For example, if the
  383. * value is 8-bits, the mask will be 0xFFFFFF80, indicating
  384. * that bit 7 (0x00000080) is extended to fill the remainder
  385. * of the value.
  386. *
  387. * This field is used only by values.
  388. *
  389. * @field USHORT | BitSize |
  390. *
  391. * Number of bits devoted to this value, including the sign bit.
  392. *
  393. * ISSUE-2001/03/29-timgill structure field probably not used anywhere.
  394. *
  395. * @field USHORT | LinkCollection |
  396. *
  397. * HID link collection number.
  398. *
  399. * @field LMINMAX | Logical |
  400. *
  401. * Logical minimum and maximum values.
  402. * These are the extremes of raw values
  403. * that can validly be received from the device.
  404. *
  405. * This field is used only by values.
  406. *
  407. * @field LMINMAX | Physical |
  408. *
  409. * Physical minimum and maximum values.
  410. * This is the "actual" value
  411. * that the logical minimum and maximum value corresponds to.
  412. *
  413. * This field is used only by values, and is consulted
  414. * only when converting between DirectInput calibration
  415. * (which uses logical values) and VJOYD calibration
  416. * (which uses physical values).
  417. *
  418. * @field LONG | Null |
  419. *
  420. * The null value to be used for output.
  421. *
  422. * This field is used only by values.
  423. *
  424. * @field ULONG | Units |
  425. *
  426. * The HID units descriptor, if any.
  427. *
  428. * @field WORD | Exponent |
  429. *
  430. * The HID unit exponent, if any.
  431. *
  432. * @field WORD | wReportId |
  433. *
  434. * HID report Id
  435. *
  436. * @field BOOL | IsAbsolute |
  437. *
  438. * Nonzero if the group describes absolute axes.
  439. *
  440. * This field is used only by values.
  441. *
  442. * @field BOOL | IsValue |
  443. *
  444. * Nonzero if the group describes a HID value.
  445. *
  446. * Note that an analog pushbutton is reported by
  447. * DirectInput as a <c DIDFT_BUTTON>, but is
  448. * handled internally as a HID value.
  449. *
  450. * @field BOOL | IsAlias |
  451. *
  452. * Nonzero if the group describes an alias.
  453. *
  454. * @field BOOL | IsSigned |
  455. *
  456. * The return data is signed.
  457. *
  458. * @field BOOL | IsPolledPOV |
  459. *
  460. * TRUE if axis is a polled POV.
  461. *
  462. * @devnote New for DX6.1a
  463. *
  464. *****************************************************************************/
  465. #define HIDGROUPCAPS_SIGNATURE 0x47444948 /* HIDG */
  466. typedef struct HIDGROUPCAPS
  467. {
  468. D(DWORD dwSignature;)
  469. HIDP_REPORT_TYPE type;
  470. UINT cObj;
  471. USAGE UsagePage;
  472. USAGE UsageMin;
  473. USHORT StringMin, StringMax;
  474. USHORT DesignatorMin, DesignatorMax;
  475. USHORT DataIndexMin;
  476. USHORT usGranularity;
  477. LONG lMask;
  478. USHORT BitSize;
  479. USHORT LinkCollection;
  480. LMINMAX Logical;
  481. LMINMAX Physical;
  482. LONG Null;
  483. ULONG Units;
  484. WORD Exponent;
  485. WORD wReportId;
  486. BOOL fReportDisabled;
  487. BOOL Reserved;
  488. BOOL IsAbsolute;
  489. BOOL IsValue;
  490. BOOL IsAlias;
  491. BOOL IsSigned;
  492. #ifdef WINNT
  493. BOOL IsPolledPOV;
  494. #endif
  495. } HIDGROUPCAPS, *PHIDGROUPCAPS;
  496. /*****************************************************************************
  497. *
  498. * @doc INTERNAL
  499. *
  500. * @struct HIDOBJCAPS |
  501. *
  502. * This structure contains various cached pointers for each
  503. * object on the device, allowing us to get at things like
  504. * the group caps and the calibration information.
  505. *
  506. * @field PHIDGROUPCAPS | pcaps |
  507. *
  508. * The <t PHIDGROUPCAPS> for the group the object belongs to.
  509. *
  510. * @field PJOYRANGECONVERT | pjrc |
  511. *
  512. * If non-NULL, then points to the range conversion information
  513. * for the object.
  514. *
  515. * @field int | idata |
  516. *
  517. * Index into the <t HIDP_DATA> array for the corresponding
  518. * output/feature report,
  519. * or <c -1> if the item is not in the output/feature report.
  520. *
  521. *****************************************************************************/
  522. typedef struct HIDOBJCAPS
  523. {
  524. PHIDGROUPCAPS pcaps;
  525. PJOYRANGECONVERT pjrc;
  526. int idata;
  527. } HIDOBJCAPS, *PHIDOBJCAPS;
  528. /*****************************************************************************
  529. *
  530. * @doc INTERNAL
  531. *
  532. * @struct HIDREPORTINFO |
  533. *
  534. * This structure contains information that is used for
  535. * parsing HID reports.
  536. *
  537. * @field PHIDP_DATA | rgdata |
  538. *
  539. * Array used when parsing reports via
  540. * <f HidP_GetData> or <f HidP_SetData>. This MUST be aligned
  541. * correctly on some architechtures.
  542. *
  543. * @field PV | pvReport |
  544. *
  545. * The report itself.
  546. *
  547. * @field int | cdataMax |
  548. *
  549. * Number of elements in the <e HIDREPORTINFO.rgdata> array.
  550. *
  551. * @field int | cdataUsed |
  552. *
  553. * Number of elements in the <e HIDREPORTINFO.rgdata> array
  554. * that are actually in use.
  555. *
  556. * @field ULONG | cbReport |
  557. *
  558. * Number of bytes in the report.
  559. *
  560. * @field BOOL | fNeedClear |
  561. *
  562. * Nonzero if the report needs to be zero'd out because we
  563. * deleted something (most likely a button) from it.
  564. * The only way to delete an item from a report is to zero
  565. * out the entire report and then re-add everything back in.
  566. *
  567. * @field BOOL | fChanged |
  568. *
  569. * Nonzero if an element in the report has changed.
  570. *
  571. *****************************************************************************/
  572. typedef struct HIDREPORTINFO
  573. {
  574. PHIDP_DATA rgdata;
  575. PV pvReport;
  576. int cdataMax;
  577. int cdataUsed;
  578. ULONG cbReport;
  579. BOOL fNeedClear;
  580. BOOL fChanged;
  581. } HIDREPORTINFO, *PHIDREPORTINFO;
  582. /*****************************************************************************
  583. *
  584. * @doc INTERNAL
  585. *
  586. * @struct CHid |
  587. *
  588. * The <i IDirectInputDeviceCallback> object for HID devices.
  589. *
  590. * @field IDirectInputDeviceCalllback | didc |
  591. *
  592. * The object (containing vtbl).
  593. *
  594. * @field PV | pvGroup2 |
  595. *
  596. * Pointer to group 2 memory. This field is a union with the
  597. * pointer to the first chunk of memory in the second memory group.
  598. *
  599. * @field HIDREPORTINFO | hriIn |
  600. *
  601. * HID input report parsing and state.
  602. *
  603. * This memory is the first chunk of group 2.
  604. *
  605. * @field HIDREPORTINFO | hriOut |
  606. *
  607. * HID output report parsing and state.
  608. *
  609. * @field HIDREPORTINFO | hriFea |
  610. *
  611. * HID feature report parsing and state.
  612. *
  613. * @field PV | pvPhys |
  614. *
  615. * Pointer to physical device status information updated
  616. * asynchronously by the data collection thread.
  617. *
  618. * @field PV | pvStage |
  619. *
  620. * Staging area used when the HID report is parsed.
  621. *
  622. * This memory is the last chunk of group 2.
  623. *
  624. * @field DWORD | cbPhys |
  625. *
  626. * Size of the physical device state.
  627. *
  628. * @field VXDINSTANCE * | pvi |
  629. *
  630. * The DirectInput instance handle.
  631. *
  632. * HID devices always run through ring 3, which is misleadingly
  633. * called "emulation".
  634. *
  635. * @field DWORD | dwDevType |
  636. *
  637. * Device type code.
  638. *
  639. * @field LPTSTR | ptszId |
  640. *
  641. * Setupapi device instance ID. Used to obtain things
  642. * like manufacturer name.
  643. *
  644. * @field LPTSTR | ptszPath |
  645. *
  646. * Path to the device, for <f CreateFile>.
  647. *
  648. * @field UINT | dwAxes |
  649. *
  650. * Number of axes on the device.
  651. *
  652. * @field UINT | dwButtons |
  653. *
  654. * Number of buttons on the device.
  655. *
  656. * @field UINT | dwPOVs |
  657. *
  658. * Number of POV controllers on the device.
  659. *
  660. * @field HANDLE | hdev |
  661. *
  662. * Handle to the device itself. This field is valid only
  663. * while the device is acquired.
  664. *
  665. * @field HANDLE | hdevEm |
  666. *
  667. * <f DuplicateHandle> of the <e CHid.hdev> which is used
  668. * by the worker thread. We need to keep this separate from
  669. * the main copy to avoid race conditions between the main
  670. * thread and the worker thread.
  671. *
  672. * @field HKEY | hkInstType |
  673. *
  674. * Per-instance registry key that contains additional configuration
  675. * information, equivalent to the joystick Type key.
  676. *
  677. * @field DWORD | rgdwBase[HidP_MaxColl] |
  678. *
  679. * Array of base indices for the three HID usage classes:
  680. * <c HidP_Input>, <c HidP_Output>, and <c HidP_Feature>.
  681. * We hide the <c HidP_Collection> base index here, too.
  682. *
  683. * @field PHIDOBJCAPS | rghoc |
  684. *
  685. * Pointer to array of
  686. * <t PHIDOBJCAPS>, one for each object on the device,
  687. * each of which in turn contains info about a single object.
  688. *
  689. * This memory is allocated as part of the
  690. * df.rgodf in the <t DIDATAFORMAT> structure
  691. * hence should not be freed separately.
  692. *
  693. * @field DIDATAFORMAT | df |
  694. *
  695. * The dynamically-generated data format based on the
  696. * usages on the HID device.
  697. *
  698. * @field DWORD | ibButtonData |
  699. *
  700. * The location of the button data inside the data format.
  701. *
  702. * @field DWORD | cbButtonData |
  703. *
  704. * The number of bytes of button data inside the data format.
  705. *
  706. * @field PBYTE * | rgpbButtonMasks |
  707. *
  708. * Pointer to a an array of pointers to byte strings to mask
  709. * the buttons relevant to a report.
  710. *
  711. * @field PHIDP_PREPARSED_DATA | ppd |
  712. *
  713. * Preparsed data generated by the HID subsystem.
  714. *
  715. * @field PHIDGROUPCAPS | rgcaps |
  716. *
  717. * Array of <t HIDGROUPCAPS> structures used to keep
  718. * track of the various buttons, groups, and collections.
  719. *
  720. * @field UINT | ccaps |
  721. *
  722. * Number of caps structures in the <e CHid.rgcaps> array.
  723. *
  724. * @field HIDP_CAPS | caps |
  725. *
  726. * Cached HID caps.
  727. *
  728. * @field OVERLAPPED | o |
  729. *
  730. * Overlapped I/O structure used by worker thread
  731. * for reading.
  732. *
  733. *
  734. * @field PJOYRANGECONVERT | pjrcNext |
  735. *
  736. * Pointer to the first <t JOYRANGECONVERT> structure
  737. * (in a preallocated array) which has
  738. * yet to be used.
  739. * This structure is used for logical-to-physical
  740. * range conversion (a.k.a. calibration).
  741. *
  742. * This memory is allocated as part of the
  743. * df.rgodf in the <t DIDATAFORMAT> structure
  744. * hence should not be freed separately.
  745. *
  746. * This field is used during device initialization to
  747. * parcel out the <t JOYRANGECONVERT>s. Afterwards,
  748. * the field is <c NULL> if we did not create any
  749. * conversion structures (hence do not need to subclass
  750. * the cooperative window to catch recalibrations).
  751. *
  752. * @field PBYTE | rgbaxissemflags |
  753. *
  754. * This points to an array which maps DirectInput axis
  755. * instance values to default semantic map flags.
  756. *
  757. * @field PINT | rgiobj |
  758. *
  759. * This points to an array which maps DirectInput instance
  760. * values (DIDFT_GETINSTANCE) into object indices.
  761. *
  762. * @field PINT | rgipov |
  763. *
  764. * If we are not a keyboard, then this is the first element in
  765. * the above array which maps povs.
  766. *
  767. * @field PINT | rgiaxis |
  768. *
  769. * If we are not a keyboard, then this is the first element in
  770. * the above array which maps axes.
  771. *
  772. * @field PINT | rgicoll |
  773. *
  774. * If we are not a keyboard, then this is the first element in
  775. * the above array which maps collections.
  776. * //ISSUE-2001/03/29-timgill need to document keyboard case behaviour
  777. *
  778. * @field UINT | uiInstanceMax |
  779. *
  780. * The number of elements in the above
  781. * <f rgiobj> array.
  782. *
  783. * @field int | idJoy |
  784. *
  785. * Joystick identifier for <f joyGetPosEx> and friends for
  786. * legacy access.
  787. *
  788. * This value starts out as -1, to meant that
  789. * the corresponding legacy joystick is unknown.
  790. * If we do something that requires the matched legacy
  791. * joystick to be found, we check if the current value
  792. * is still valid. If not (either it is -1 or the cached
  793. * value is stale), then we go hunt for the correct value.
  794. *
  795. * @field HKEY | hkType |
  796. *
  797. * The joystick type key opened with <c MAXIMUM_ALLOWED> access.
  798. * This is not per-instance; multiple instances of the same
  799. * hardware share this key.
  800. *
  801. * @field USHORT | VendorID |
  802. *
  803. * HID vendor ID for this device.
  804. *
  805. * @field USHORT | ProductID |
  806. *
  807. * HID product ID for this device.
  808. *
  809. * @field HWND | hwnd |
  810. *
  811. * The window which we have subclassed in order to watch
  812. * for recalibration messages.
  813. *
  814. * @field BOOL | IsPolledInput |
  815. *
  816. * Nonzero if the device has to be polled for Input data.
  817. *
  818. * @field BOOL | fPIDdevice |
  819. *
  820. * Set to true if the device is found to support PID.
  821. *
  822. * @field WORD | wMaxReportId |
  823. *
  824. * The maximum (number) of ReportId used by the HID device.
  825. *
  826. * @field PUCHAR | pEnableReportId |
  827. *
  828. * Pointer to (wMaxReportId) bytes. If a reportID needs to be
  829. * polled in order to get features / set Output, then that element
  830. * of this array is set to 0x1.
  831. *
  832. * @field HKEY | hkProp |
  833. *
  834. * Extended properties for device type. Currently we keep dwFlags2 and
  835. * OEMMapFile under this key.
  836. *
  837. * @field BOOL | fEnableInputReport |
  838. *
  839. * True if Input report should be enabled for this device.
  840. *
  841. * @field BOOL | fFlags2Checked |
  842. *
  843. * True after we check the registry for Flags2 for disabling
  844. * input reports.
  845. *
  846. * @comm
  847. *
  848. * It is the caller's responsibility to serialize access as
  849. * necessary.
  850. *
  851. *****************************************************************************/
  852. typedef struct CHid
  853. {
  854. /* Supported interfaces */
  855. IDirectInputDeviceCallback dcb;
  856. union
  857. {
  858. PV pvGroup2;
  859. HIDREPORTINFO hriIn;
  860. };
  861. HIDREPORTINFO hriOut;
  862. HIDREPORTINFO hriFea;
  863. PV pvPhys;
  864. PV pvStage;
  865. DWORD cbPhys;
  866. VXDINSTANCE *pvi;
  867. DWORD dwDevType;
  868. UINT dwAxes;
  869. UINT dwButtons;
  870. UINT dwPOVs;
  871. UINT dwCollections;
  872. HANDLE hdev;
  873. HANDLE hdevEm;
  874. DWORD rgdwBase[HidP_MaxColl];
  875. PHIDOBJCAPS rghoc;
  876. DIDATAFORMAT df;
  877. DWORD ibButtonData;
  878. DWORD cbButtonData;
  879. PBYTE *rgpbButtonMasks;
  880. PHIDP_PREPARSED_DATA ppd;
  881. PHIDGROUPCAPS rgcaps;
  882. PJOYRANGECONVERT pjrcNext;
  883. HIDP_CAPS caps;
  884. ED ed;
  885. OVERLAPPED o;
  886. DWORD dwStartRead;
  887. DWORD dwStopRead;
  888. PBYTE rgbaxissemflags;
  889. PINT rgiobj;
  890. PINT rgipov;
  891. PINT rgiaxis;
  892. PINT rgicoll;
  893. UINT uiInstanceMax;
  894. LPTSTR ptszId;
  895. LPTSTR ptszPath;
  896. HKEY hkInstType;
  897. UINT ccaps;
  898. int idJoy;
  899. HKEY hkType;
  900. USHORT VendorID;
  901. USHORT ProductID;
  902. #define FAILED_POLL_THRESHOLD (0x4)
  903. HWND hwnd;
  904. BOOL IsPolledInput;
  905. BOOL fPIDdevice;
  906. WORD wMaxReportId[HidP_Max];
  907. PUCHAR pEnableReportId[HidP_Max];
  908. DWORD dwVersion;
  909. DIAPPHACKS diHacks;
  910. HKEY hkProp;
  911. BOOL fEnableInputReport;
  912. BOOL fFlags2Checked;
  913. } CHid, CHID, *PCHID;
  914. /*****************************************************************************
  915. *
  916. * @doc INTERNAL
  917. *
  918. * @func PCHID | pchidFromPo |
  919. *
  920. * Given an interior pointer to an <t OVERLAPPED>, retrieve
  921. * a pointer to the parent <t CHid>.
  922. *
  923. * @parm LPOVERLAPPED | po |
  924. *
  925. * The pointer to convert.
  926. *
  927. *****************************************************************************/
  928. PCHID INLINE
  929. pchidFromPo(LPOVERLAPPED po)
  930. {
  931. return pvSubPvCb(po, FIELD_OFFSET(CHid, o));
  932. }
  933. /*****************************************************************************
  934. *
  935. * @doc INTERNAL
  936. *
  937. * @func PCHID | pchidFromPed |
  938. *
  939. * Given an interior pointer to a <t CEd>, retrieve
  940. * a pointer to the parent <t CHid>.
  941. *
  942. * @parm PED | ped |
  943. *
  944. * The pointer to convert.
  945. *
  946. *****************************************************************************/
  947. PCHID INLINE
  948. pchidFromPed(PED ped)
  949. {
  950. return pvSubPvCb(ped, FIELD_OFFSET(CHid, ed));
  951. }
  952. /*****************************************************************************
  953. *
  954. * @doc INTERNAL
  955. *
  956. * @func PCHID | pchidFromPem |
  957. *
  958. * Given a <t CEm>, wander back to the
  959. * <t CHid> that spawned it.
  960. *
  961. * @parm PEM | pem |
  962. *
  963. * The pointer at which to start.
  964. *
  965. *****************************************************************************/
  966. PCHID INLINE
  967. pchidFromPem(PEM pem)
  968. {
  969. PCHID pchid = pchidFromPed(pem->ped);
  970. AssertF(pemFromPvi(pchid->pvi) == pem);
  971. return pchid;
  972. }
  973. /*****************************************************************************
  974. *
  975. * @doc INTERNAL
  976. *
  977. * @method UINT | CHid | ObjFromType |
  978. *
  979. * Given a <p dwType>, extract the instance number
  980. * and (if necessary) convert it to an object index.
  981. * Note, the instance number will always be of the primary instance
  982. * not an alias.
  983. *
  984. * @parm PCHID | this |
  985. *
  986. * HID device object.
  987. *
  988. * @parm DWORD | dwType |
  989. *
  990. * The type code to convert.
  991. *
  992. * @returns
  993. *
  994. * The object index, or an out-of-range value.
  995. *
  996. *****************************************************************************/
  997. UINT INLINE
  998. CHid_ObjFromType(PCHID this, DWORD dwType)
  999. {
  1000. UINT uiObj = DIDFT_GETINSTANCE(dwType);
  1001. // ISSUE-2001/03/29-timgill Range checks may be unnecessary
  1002. // MarcAnd can we ever get the out of range value?
  1003. // if so, can we really run with it?
  1004. // if not, can these range checks be converted into Asserts?
  1005. /*
  1006. * The range checking makes use of the fact that the translation
  1007. * tables are taken from a contiguous memory allocation and that
  1008. * aliased collections are not distinguished.
  1009. */
  1010. if(this->rgiobj)
  1011. {
  1012. switch( DIDFT_GETTYPE(dwType) )
  1013. {
  1014. case DIDFT_RELAXIS:
  1015. case DIDFT_ABSAXIS:
  1016. if( &this->rgiaxis[uiObj] < this->rgicoll )
  1017. {
  1018. uiObj = this->rgiaxis[uiObj];
  1019. } else
  1020. {
  1021. uiObj = 0xFFFFFFFF;
  1022. }
  1023. break;
  1024. case DIDFT_PSHBUTTON:
  1025. case DIDFT_TGLBUTTON:
  1026. /*
  1027. * If it is keyboard, this->rgiobj == this->rgipov (see CHid_MungeKeyboard).
  1028. * So, we can't test &this->rgiobj[uiObj] < this->rgipov.
  1029. */
  1030. if( (GET_DIDEVICE_TYPE(this->dwDevType) == DI8DEVTYPE_KEYBOARD &&
  1031. uiObj < this->uiInstanceMax ) ||
  1032. &this->rgiobj[uiObj] < this->rgipov )
  1033. {
  1034. uiObj = this->rgiobj[uiObj];
  1035. } else
  1036. {
  1037. uiObj = 0xFFFFFFFF;
  1038. }
  1039. break;
  1040. case DIDFT_POV:
  1041. if( &this->rgipov[uiObj] < this->rgiaxis )
  1042. {
  1043. uiObj = this->rgipov[uiObj];
  1044. } else
  1045. {
  1046. uiObj = 0xFFFFFFFF;
  1047. }
  1048. break;
  1049. case (DIDFT_COLLECTION | DIDFT_NODATA):
  1050. if( &this->rgicoll[uiObj] <= &this->rgiobj[this->uiInstanceMax] )
  1051. {
  1052. uiObj = this->rgicoll[uiObj];
  1053. } else
  1054. {
  1055. uiObj = 0xFFFFFFFF;
  1056. }
  1057. break;
  1058. case DIDFT_NODATA:
  1059. /*
  1060. * So far, this TYPE only shows up on Keyboard (HID_USAGE_PAGE_LED).
  1061. */
  1062. if( GET_DIDEVICE_TYPE(this->dwDevType) == DI8DEVTYPE_KEYBOARD &&
  1063. uiObj < this->uiInstanceMax )
  1064. {
  1065. uiObj = this->rgiobj[uiObj];
  1066. }
  1067. break;
  1068. default:
  1069. /*
  1070. * Hopefully this is just a vendor defined object but squirt
  1071. * in debug as these may cause problems.
  1072. */
  1073. SquirtSqflPtszV(sqflHidParse | sqflVerbose,
  1074. TEXT("CHid_ObjFromType: dwType 0x%08x not converted"),
  1075. dwType );
  1076. break;
  1077. }
  1078. }
  1079. else
  1080. {
  1081. SquirtSqflPtszV(sqflHidParse | sqflError,
  1082. TEXT("CHid_ObjFromType: Translation array missing") );
  1083. }
  1084. return uiObj;
  1085. }
  1086. LONG EXTERNAL
  1087. CHid_CoordinateTransform(PLMINMAX Dst, PLMINMAX Src, LONG lVal);
  1088. #ifndef WINNT
  1089. void EXTERNAL
  1090. CHid_UpdateVjoydCalibration(PCHID this, UINT iobj);
  1091. void EXTERNAL
  1092. CHid_UpdateCalibrationFromVjoyd(PCHID this, UINT iobj, LPDIOBJECTCALIBRATION pCal);
  1093. #endif
  1094. /*****************************************************************************
  1095. *
  1096. * dihidini.c - Device callback initialization stuff
  1097. *
  1098. *****************************************************************************/
  1099. #define INITBUTTONFLAG 0x10000000
  1100. HRESULT EXTERNAL CHid_InitParseData(PCHID this);
  1101. HRESULT EXTERNAL CHid_Init(PCHID this, REFGUID rguid);
  1102. HANDLE EXTERNAL CHid_OpenDevicePath(PCHID this, DWORD dwAttributes );
  1103. UINT EXTERNAL CHid_LoadCalibrations(PCHID this);
  1104. BOOL EXTERNAL CHid_IsPolledDevice( HANDLE hdev );
  1105. /*****************************************************************************
  1106. *
  1107. * dihiddat.c - HID data parsing/management
  1108. *
  1109. *****************************************************************************/
  1110. typedef HRESULT (FAR PASCAL * SENDHIDREPORT)(PCHID this, PHIDREPORTINFO phri);
  1111. void EXTERNAL CHid_ResetDeviceData(PCHID this, PHIDREPORTINFO phri,
  1112. HIDP_REPORT_TYPE type);
  1113. HRESULT EXTERNAL CHid_AddDeviceData(PCHID this, UINT uiObj, DWORD dwData);
  1114. STDMETHODIMP CHid_PrepareDeviceData(PCHID this, PHIDREPORTINFO phri);
  1115. STDMETHODIMP CHid_SendHIDReport(PCHID this, PHIDREPORTINFO phri,
  1116. HIDP_REPORT_TYPE type, SENDHIDREPORT SendHIDReport);
  1117. NTSTATUS EXTERNAL
  1118. CHid_ParseData(PCHID this, HIDP_REPORT_TYPE type, PHIDREPORTINFO phri);
  1119. HRESULT EXTERNAL
  1120. DIHid_GetRegistryProperty(LPTSTR ptszId, DWORD dwProperty, LPDIPROPHEADER pdiph);
  1121. DWORD EXTERNAL DIHid_DetectHideAndRevealFlags( PCHID this );
  1122. /*****************************************************************************
  1123. *
  1124. * diemh.c - HID "emulation"
  1125. *
  1126. *****************************************************************************/
  1127. void EXTERNAL CEm_HID_Sync(PLLTHREADSTATE plts, PEM pem);
  1128. BOOL EXTERNAL CEm_HID_IssueRead( PCHID pchid );
  1129. #endif /* _DIHID_H */