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.

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