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.

295 lines
8.4 KiB

  1. /*****************************************************************************
  2. *
  3. * DIHidUsg.c
  4. *
  5. * Copyright (c) 1996 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * Abstract:
  8. *
  9. * Mapping between GUIDs and HID usages.
  10. *
  11. * Contents:
  12. *
  13. * UsageToGuid
  14. *
  15. *****************************************************************************/
  16. #include "dinputpr.h"
  17. /*****************************************************************************
  18. *
  19. * The sqiffle for this file.
  20. *
  21. *****************************************************************************/
  22. #define sqfl sqflHidUsage
  23. #pragma BEGIN_CONST_DATA
  24. /*****************************************************************************
  25. *
  26. * @doc INTERNAL
  27. *
  28. * @global HIDUSAGEMAP | c_rghum[] |
  29. *
  30. * Mapping between GUIDs and HID usages for one-to-one mappings.
  31. *
  32. *****************************************************************************/
  33. #define MAKEHUM(Page, Usage, PosAxis, Guid) \
  34. { DIMAKEUSAGEDWORD(HID_USAGE_PAGE_##Page, \
  35. HID_USAGE_##Page##_##Usage), \
  36. PosAxis, \
  37. &Guid, \
  38. } \
  39. #ifndef HID_USAGE_SIMULATION
  40. #define HID_USAGE_SIMULATION_STEERING ((USAGE) 0xC8)
  41. #endif
  42. #ifndef HID_USAGE_SIMULATION_ACCELERATOR
  43. #define HID_USAGE_SIMULATION_ACCELERATOR ((USAGE) 0xC4)
  44. #endif
  45. #ifndef HID_USAGE_SIMULATION_BRAKE
  46. #define HID_USAGE_SIMULATION_BRAKE ((USAGE) 0xC5)
  47. #endif
  48. #ifndef HID_USAGE_GAME_POV
  49. #define HID_USAGE_GAME_POV ((USAGE) 0x20)
  50. #endif
  51. HIDUSAGEMAP c_rghum[] = {
  52. MAKEHUM(GENERIC, X, 0, GUID_XAxis),
  53. MAKEHUM(GENERIC, Y, 1, GUID_YAxis),
  54. MAKEHUM(GENERIC, Z, 2, GUID_ZAxis),
  55. MAKEHUM(GENERIC, WHEEL, 2, GUID_ZAxis),
  56. MAKEHUM(GENERIC, RX, 3, GUID_RxAxis),
  57. MAKEHUM(GENERIC, RY, 4, GUID_RyAxis),
  58. MAKEHUM(GENERIC, RZ, 5, GUID_RzAxis),
  59. MAKEHUM(GENERIC, HATSWITCH, 7, GUID_POV),
  60. MAKEHUM(GENERIC, SLIDER, 6, GUID_Slider),
  61. MAKEHUM(GENERIC, DIAL, 6, GUID_Slider),
  62. MAKEHUM(SIMULATION, STEERING, 0, GUID_XAxis),
  63. MAKEHUM(SIMULATION, ACCELERATOR,1, GUID_YAxis),
  64. MAKEHUM(SIMULATION, BRAKE, 5, GUID_RzAxis),
  65. MAKEHUM(SIMULATION, RUDDER, 5, GUID_RzAxis),
  66. MAKEHUM(SIMULATION, THROTTLE, 6, GUID_Slider),
  67. MAKEHUM(GAME, POV, 7, GUID_POV),
  68. };
  69. /*****************************************************************************
  70. *
  71. * @doc EXTERNAL
  72. *
  73. * @func PCGUID | UsageToUsageMap |
  74. *
  75. * Takes some HID usage and usage page information and
  76. * returns a pointer to a <t HIDUSAGEMAP> that describes
  77. * how we should treat it.
  78. *
  79. * If the type is not recognized, then <c NULL> is returned.
  80. *
  81. * @parm DWORD | dwUsage |
  82. *
  83. * Usage page and usage to convert. This should be a <t DWORD>
  84. * formed using DIMAKEUSAGEDWORD on the component <t USAGE> values.
  85. *
  86. *****************************************************************************/
  87. PHIDUSAGEMAP EXTERNAL
  88. UsageToUsageMap(DWORD dwUsage)
  89. {
  90. PHIDUSAGEMAP phum;
  91. int ihum;
  92. for (ihum = 0; ihum < cA(c_rghum); ihum++) {
  93. if (c_rghum[ihum].dwUsage == dwUsage) {
  94. phum = &c_rghum[ihum];
  95. goto done;
  96. }
  97. }
  98. phum = 0;
  99. done:;
  100. if( phum )
  101. {
  102. SquirtSqflPtszV(sqflHidUsage | sqflVerbose,
  103. TEXT("UsageToUsageMap: mapped 0x%04x:0x%04x to index %d"),
  104. HIWORD( dwUsage ), LOWORD( dwUsage ), ihum );
  105. }
  106. else
  107. {
  108. SquirtSqflPtszV(sqflHidUsage | sqflVerbose,
  109. TEXT("UsageToUsageMap: failed to map 0x%04x:0x%04x"),
  110. HIWORD( dwUsage ), LOWORD( dwUsage ) );
  111. }
  112. return phum;
  113. }
  114. /*****************************************************************************
  115. *
  116. * @doc EXTERNAL
  117. *
  118. * @func DWORD | GuidToUsage |
  119. *
  120. * Map Guid to Usage
  121. *
  122. * If the guid is not recognized, then 0 is returned.
  123. *
  124. * @parm PCGUID | pguid |
  125. *
  126. * guid to map
  127. *
  128. *****************************************************************************/
  129. DWORD EXTERNAL
  130. GuidToUsage(PCGUID pguid)
  131. {
  132. DWORD dwUsage;
  133. int ihum;
  134. for (ihum = 0; ihum < cA(c_rghum); ihum++) {
  135. if ( IsEqualGUID( c_rghum[ihum].pguid, pguid ) ) {
  136. dwUsage = c_rghum[ihum].dwUsage;
  137. goto done;
  138. }
  139. }
  140. dwUsage = 0;
  141. done:;
  142. return dwUsage;
  143. }
  144. /*****************************************************************************
  145. *
  146. * @doc INTERNAL
  147. *
  148. * @func UINT | GetHIDString |
  149. *
  150. * Given a HID usage page and usage, obtain a generic string
  151. * that describes it if we recognize it.
  152. *
  153. * @parm DWORD | Usage |
  154. *
  155. * Usage number to convert. This is a <t DWORD> instead of
  156. * a <t USAGE> because you aren't supposed to pass short types
  157. * as parameters to functions.
  158. *
  159. * @parm DWORD | UsagePage |
  160. *
  161. * Usage page to convert.
  162. *
  163. * @parm LPWSTR | pwszBuf |
  164. *
  165. * Buffer to receive string.
  166. *
  167. * @parm UINT | cwch |
  168. *
  169. * Size of buffer.
  170. *
  171. * @returns
  172. *
  173. * Returns the number of characters retrieved, or zero
  174. * if no string was obtained.
  175. *
  176. *****************************************************************************/
  177. /*
  178. * Maps usage pages to string groups. Each string group is 512 strings long.
  179. * Zero means "No string group".
  180. */
  181. UINT c_mpuiusagePage[] = {
  182. 0, /* Invalid */
  183. IDS_PAGE_GENERIC, /* HID_USAGE_PAGE_GENERIC */
  184. IDS_PAGE_VEHICLE, /* HID_USAGE_PAGE_SIMULATION */
  185. IDS_PAGE_VR, /* HID_USAGE_PAGE_VR */
  186. IDS_PAGE_SPORT, /* HID_USAGE_PAGE_SPORT */
  187. IDS_PAGE_GAME, /* HID_USAGE_PAGE_GAME */
  188. 0, /* ??????????????????????? */
  189. IDS_PAGE_KEYBOARD, /* HID_USAGE_PAGE_KEYBOARD */
  190. IDS_PAGE_LED, /* HID_USAGE_PAGE_LED */
  191. 0, /* HID_USAGE_PAGE_BUTTON */
  192. 0, /* HID_USAGE_PAGE_ORDINAL */
  193. IDS_PAGE_TELEPHONY, /* HID_USAGE_PAGE_TELEPHONY */
  194. IDS_PAGE_CONSUMER, /* HID_USAGE_PAGE_CONSUMER */
  195. IDS_PAGE_DIGITIZER, /* HID_USAGE_PAGE_DIGITIZER */
  196. 0, /* ??????????????????????? */
  197. IDS_PAGE_PID, /* HID_USAGE_PAGE_PID */
  198. };
  199. UINT EXTERNAL
  200. GetHIDString(DWORD Usage, DWORD UsagePage, LPWSTR pwszBuf, UINT cwch)
  201. {
  202. UINT uiRc;
  203. if (UsagePage < cA(c_mpuiusagePage) &&
  204. c_mpuiusagePage[UsagePage] &&
  205. Usage < 512) {
  206. uiRc = LoadStringW(g_hinst, c_mpuiusagePage[UsagePage] + Usage,
  207. pwszBuf, cwch);
  208. } else {
  209. uiRc = 0;
  210. }
  211. return uiRc;
  212. }
  213. /*****************************************************************************
  214. *
  215. * @doc INTERNAL
  216. *
  217. * @func void | InsertCollectionNumber |
  218. *
  219. * Prefix the collection number on the existing string.
  220. *
  221. * @parm UINT | icoll |
  222. *
  223. * Collection number to be prefixed.
  224. *
  225. * (Actually, it's placed wherever the string resource
  226. * tells us, to allow for localization.)
  227. *
  228. * @parm LPWSTR | pwsz |
  229. *
  230. * Output buffer assumed to be of size MAX_PATH.
  231. *
  232. *****************************************************************************/
  233. void EXTERNAL
  234. InsertCollectionNumber(UINT icoll, LPWSTR pwszBuf)
  235. {
  236. TCHAR tsz[MAX_PATH];
  237. TCHAR tszFormat[64];
  238. #ifndef UNICODE
  239. TCHAR tszOut[MAX_PATH];
  240. #endif
  241. int ctch;
  242. ctch = LoadString(g_hinst, IDS_COLLECTIONTEMPLATEFORMAT,
  243. tszFormat, cA(tszFormat));
  244. /*
  245. * Make sure the combined format and collection name
  246. * don't overflow the buffer. The maximum length of
  247. * the stringification of icoll is 65534 because we
  248. * allow only 16 bits worth of DIDFT_INSTANCEMASK.
  249. *
  250. * We also have to put it into a holding buffer because
  251. * pwszBuf is about to be smashed by the upcoming wsprintf.
  252. */
  253. UToT(tsz, cA(tsz) - ctch, pwszBuf);
  254. #ifdef UNICODE
  255. wsprintfW(pwszBuf, tszFormat, icoll, tsz);
  256. #else
  257. wsprintfA(tszOut, tszFormat, icoll, tsz);
  258. TToU(pwszBuf, MAX_PATH, tszOut);
  259. #endif
  260. }