PageRenderTime 72ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/GiiMote/Classic.h

https://code.google.com/p/giimote/
C Header | 1101 lines | 550 code | 37 blank | 514 comment | 59 complexity | 2959c6398e62431a2d6a4144fa788813 MD5 | raw file
Possible License(s): AGPL-3.0, CC-BY-SA-3.0, GPL-3.0, LGPL-3.0
  1. // Classic.h - Contains functions that deal with the Classic Controller.
  2. // Copyright 2007 Sam Whited
  3. //
  4. // This file is part of GiiMote.
  5. //
  6. // GiiMote is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Lesser General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GiiMote is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Lesser General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Lesser General Public License
  17. // along with GiiMote. If not, see <http://www.gnu.org/licenses/>.
  18. /// <summary>Checks the state of a button</summary>
  19. /// <param name="key_code">
  20. /// The button to check
  21. /// <list type="bullet">
  22. /// <listheader>
  23. /// <term>Key Code</term>
  24. /// <description>Button</description>
  25. /// </listheader>
  26. /// <item>
  27. /// <term>btnA</term>
  28. /// <description>A Button</description>
  29. /// </item>
  30. /// <item>
  31. /// <term>btnB</term>
  32. /// <description>B Button</description>
  33. /// </item>
  34. /// <item>
  35. /// <term>btnUp</term>
  36. /// <description>D-Pad Up</description>
  37. /// </item>
  38. /// <item>
  39. /// <term>btnDown</term>
  40. /// <description>D-Pad Down</description>
  41. /// </item>
  42. /// <item>
  43. /// <term>btnRight</term>
  44. /// <description>D-Pad Right</description>
  45. /// </item>
  46. /// <item>
  47. /// <term>btnLeft</term>
  48. /// <description>D-Pad Left</description>
  49. /// </item>
  50. /// <item>
  51. /// <term>btnX</term>
  52. /// <description>X Button</description>
  53. /// </item>
  54. /// <item>
  55. /// <term>btnY</term>
  56. /// <description>Y Button</description>
  57. /// </item>
  58. /// <item>
  59. /// <term>btnMinus</term>
  60. /// <description>Minus Button</description>
  61. /// </item>
  62. /// <item>
  63. /// <term>btnPlus</term>
  64. /// <description>Plus Button</description>
  65. /// </item>
  66. /// <item>
  67. /// <term>btnHome</term>
  68. /// <description>Home Button</description>
  69. /// </item>
  70. /// <item>
  71. /// <term>btnL</term>
  72. /// <description>Left Trigger</description>
  73. /// </item>
  74. /// <item>
  75. /// <term>btnR</term>
  76. /// <description>Right Trigger</description>
  77. /// </item>
  78. /// <item>
  79. /// <term>btnZL</term>
  80. /// <description>ZL Button</description>
  81. /// </item>
  82. /// <item>
  83. /// <term>btnZR</term>
  84. /// <description>ZR Button</description>
  85. /// </item>
  86. /// </list>
  87. /// </param>
  88. /// <returns>Button pressed</returns>
  89. double wm_classic_check_button(double key_code)
  90. {
  91. bool is_pressed = 0;
  92. switch ((int)key_code)
  93. {
  94. case btnA:
  95. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.A;
  96. break;
  97. case btnB:
  98. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.B;
  99. break;
  100. case btnUp:
  101. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Up;
  102. break;
  103. case btnDown:
  104. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Down;
  105. break;
  106. case btnRight:
  107. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Right;
  108. break;
  109. case btnLeft:
  110. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Left;
  111. break;
  112. case btnX:
  113. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.X;
  114. break;
  115. case btnY:
  116. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Y;
  117. break;
  118. case btnPlus:
  119. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Plus;
  120. break;
  121. case btnMinus:
  122. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Minus;
  123. break;
  124. case btnHome:
  125. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.Home;
  126. break;
  127. case btnL:
  128. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.TriggerL;
  129. break;
  130. case btnR:
  131. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.TriggerR;
  132. break;
  133. case btnZL:
  134. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.ZL;
  135. break;
  136. case btnZR:
  137. is_pressed = GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.ButtonState.ZR;
  138. break;
  139. default:
  140. is_pressed = false;
  141. break;
  142. }
  143. return ((double)is_pressed);
  144. }
  145. ////////////////////////////////////////////
  146. // Triggers
  147. ////////////////////////////////////////////
  148. /// <summary>Sets the dead-zone value</summary>
  149. /// <remarks>Domain: [0.0,1.0]</remarks>
  150. /// <param name="val">The dead-zone value</param>
  151. /// <returns>1</returns>
  152. double wm_set_trigger_dead_zone(double val)
  153. {
  154. GiiMote::gm->trigger_dead_zone[GiiMote::gm->wmIndex] = in_domain(val, 0, 1);
  155. return ( 1 );
  156. }
  157. /// <summary>Gets the dead-zone value</summary>
  158. /// <returns>Trigger dead-zone value</returns>
  159. double wm_get_trigger_dead_zone()
  160. {
  161. return ( GiiMote::gm->trigger_dead_zone[GiiMote::gm->wmIndex] );
  162. }
  163. // Normalized Functions
  164. /// <summary>
  165. /// Normalized trigger pressure
  166. /// </summary>
  167. /// <remarks>
  168. /// Domain: [0.0,1.0]
  169. /// </remarks>
  170. /// <param name="trigger">
  171. /// The trigger to check:
  172. /// <list type="bullet">
  173. /// <listheader>
  174. /// <term>Key Code</term>
  175. /// <description>Button</description>
  176. /// </listheader>
  177. /// <item>
  178. /// <term>btnL</term>
  179. /// <description>Left Trigger</description>
  180. /// </item>
  181. /// <item>
  182. /// <term>btnR</term>
  183. /// <description>Right Trigger</description>
  184. /// </item>
  185. /// </list>
  186. /// </param>
  187. /// <returns>Normalized trigger pressure</returns>
  188. double wm_classic_trigger_pressure(double trigger)
  189. {
  190. double val = -1;
  191. if (trigger == btnL || trigger == 0)
  192. {
  193. // Left
  194. val = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.TriggerL;
  195. }
  196. if (trigger == btnR || trigger == 1)
  197. {
  198. // Right
  199. val = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.TriggerR;
  200. }
  201. if (val < GiiMote::gm->trigger_dead_zone[GiiMote::gm->wmIndex] && val != -1)
  202. {
  203. val = 0;
  204. }
  205. if (val > (1 - GiiMote::gm->trigger_dead_zone[GiiMote::gm->wmIndex]) )
  206. {
  207. val = 1;
  208. }
  209. return ( val );
  210. }
  211. // Raw Functions
  212. /// <summary>Raw trigger pressure</summary>
  213. /// <remarks>Domain: [0,255]</remarks>
  214. /// <param name="trigger">
  215. /// The trigger to check:
  216. /// <list type="bullet">
  217. /// <listheader>
  218. /// <term>Key Code</term>
  219. /// <description>Button</description>
  220. /// </listheader>
  221. /// <item>
  222. /// <term>btnL</term>
  223. /// <description>Left Trigger</description>
  224. /// </item>
  225. /// <item>
  226. /// <term>btnR</term>
  227. /// <description>Right Trigger</description>
  228. /// </item>
  229. /// </list>
  230. /// </param>
  231. /// <returns>Raw trigger pressure</returns>
  232. double wm_classic_trigger_raw(double trigger)
  233. {
  234. if (trigger == btnL || trigger == 0)
  235. {
  236. // Left
  237. return( (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.RawTriggerL );
  238. }
  239. if (trigger == btnR || trigger == 1)
  240. {
  241. // Right
  242. return( (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.RawTriggerR );
  243. }
  244. return ( -1 );
  245. }
  246. // Normalized Functions
  247. /// <summary>Normalized joystick position</summary>
  248. /// <remarks>Domain: [-0.5,0.5]</remarks>
  249. /// <returns>The normalized X-position of the joystick</returns>
  250. double wm_classic_xpos(double stick)
  251. {
  252. double xx;
  253. try
  254. {
  255. switch ((int)stick)
  256. {
  257. case joyL:
  258. xx = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.JoystickL.X;
  259. break;
  260. case joyR:
  261. xx = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.JoystickR.X;
  262. break;
  263. default:
  264. throw (-1);
  265. break;
  266. }
  267. }
  268. catch(...)
  269. {
  270. return ( -1 );
  271. }
  272. if ( System::Math::Abs(xx) < (GiiMote::gm->joystick_dead_zone[GiiMote::gm->wmIndex]) )
  273. {
  274. xx = 0;
  275. }
  276. return ( xx );
  277. }
  278. /// <summary>Normalized joystick position</summary>
  279. /// <remarks>Domain: [-0.5,0.5]</remarks>
  280. /// <returns>The normalized Y-position of the joystick</returns>
  281. double wm_classic_ypos(double stick)
  282. {
  283. double yy;
  284. try
  285. {
  286. switch ((int)stick)
  287. {
  288. case joyL:
  289. yy = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.JoystickL.Y;
  290. break;
  291. case joyR:
  292. yy = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.JoystickR.Y;
  293. break;
  294. default:
  295. throw (-1);
  296. break;
  297. }
  298. }
  299. catch(...)
  300. {
  301. return ( -1 );
  302. }
  303. if ( System::Math::Abs(yy) < (GiiMote::gm->joystick_dead_zone[GiiMote::gm->wmIndex]) )
  304. {
  305. yy = 0;
  306. }
  307. return ( yy );
  308. }
  309. // Raw Functions
  310. /// <summary>Raw joystick X-position</summary>
  311. /// <remarks>Domain: [0,255]</remarks>
  312. /// <returns>Raw joystick X-position</returns>
  313. double wm_classic_rawx(double stick)
  314. {
  315. double rawX;
  316. try
  317. {
  318. switch ((int)stick)
  319. {
  320. case joyL:
  321. rawX = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.RawJoystickL.X;
  322. break;
  323. case joyR:
  324. rawX = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.RawJoystickR.X;
  325. break;
  326. default:
  327. throw (-1);
  328. break;
  329. }
  330. }
  331. catch(...)
  332. {
  333. return ( -1 );
  334. }
  335. return (rawX);
  336. }
  337. /// <summary>Raw joystick Y-position</summary>
  338. /// <remarks>Domain: [0,255]</remarks>
  339. /// <returns>Raw joystick Y-position</returns>
  340. double wm_classic_rawy(double stick)
  341. {
  342. double rawY;
  343. try
  344. {
  345. switch ((int)stick)
  346. {
  347. case joyL:
  348. rawY = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.RawJoystickL.Y;
  349. break;
  350. case joyR:
  351. rawY = (double)GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.RawJoystickR.Y;
  352. break;
  353. default:
  354. throw (-1);
  355. break;
  356. }
  357. }
  358. catch (...)
  359. {
  360. return ( -1 );
  361. }
  362. return (rawY);
  363. }
  364. /// <summary>Joystick direction</summary>
  365. /// <returns>The direction of the joystick in degrees</returns>
  366. double wm_classic_direction(double stick)
  367. {
  368. double xx, yy;
  369. if (stick == joyR || stick == joyL)
  370. {
  371. xx = wm_classic_xpos(stick);
  372. yy = wm_classic_ypos(stick);
  373. if (xx != -1 && yy != -1)
  374. {
  375. return ( joystick_direction(xx,yy) );
  376. }
  377. }
  378. return ( -1 );
  379. }
  380. /// <summary>Joystick pressure</summary>
  381. /// <returns>The pressure on the joystick</returns>
  382. double wm_classic_pressure(double stick)
  383. {
  384. double xx, yy;
  385. if (stick == joyR || stick == joyL)
  386. {
  387. xx = wm_classic_xpos(stick);
  388. yy = wm_classic_ypos(stick);
  389. if (xx != -1 && yy != -1)
  390. {
  391. return ( joystick_pressure(xx,yy) );
  392. }
  393. }
  394. return ( -1 );
  395. }
  396. ////////////////////////////////////////////
  397. // Calibration
  398. ////////////////////////////////////////////
  399. // Get Calibration
  400. /// <summary>
  401. /// Gets trigger calibration data
  402. /// </summary>
  403. /// <param name="trigger">
  404. /// The analog trigger to get calibration data for:
  405. /// <list type="bullet">
  406. /// <listheader>
  407. /// <term>Key Code</term>
  408. /// <description>Button</description>
  409. /// </listheader>
  410. /// <item>
  411. /// <term>btnL</term>
  412. /// <description>Left Trigger</description>
  413. /// </item>
  414. /// <item>
  415. /// <term>btnR</term>
  416. /// <description>Right Trigger</description>
  417. /// </item>
  418. /// </list>
  419. /// </param>
  420. /// <returns>Normalized calibration data</returns>
  421. double wm_classic_get_calibration_maxtrigger(double trigger)
  422. {
  423. double returnValue = -1;
  424. switch ((int)trigger)
  425. {
  426. case btnL:
  427. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxTriggerL);
  428. break;
  429. case btnR:
  430. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxTriggerR);
  431. break;
  432. default:
  433. break;
  434. }
  435. return (returnValue);
  436. }
  437. /// <summary>
  438. /// Gets trigger calibration data
  439. /// </summary>
  440. /// <param name="trigger">
  441. /// The analog trigger to get calibration data for:
  442. /// <list type="bullet">
  443. /// <listheader>
  444. /// <term>Key Code</term>
  445. /// <description>Button</description>
  446. /// </listheader>
  447. /// <item>
  448. /// <term>btnL</term>
  449. /// <description>Left Trigger</description>
  450. /// </item>
  451. /// <item>
  452. /// <term>btnR</term>
  453. /// <description>Right Trigger</description>
  454. /// </item>
  455. /// </list>
  456. /// </param>
  457. /// <returns>Normalized calibration data</returns>
  458. double wm_classic_get_calibration_mintrigger(double trigger)
  459. {
  460. double returnValue = -1;
  461. switch ((int)trigger)
  462. {
  463. case btnL:
  464. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinTriggerL);
  465. break;
  466. case btnR:
  467. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinTriggerR);
  468. break;
  469. default:
  470. break;
  471. }
  472. return (returnValue);
  473. }
  474. /// <summary>
  475. /// Gets X-axis joystick Calibration data
  476. /// </summary>
  477. /// <param name="joystick">
  478. /// The joystick to get calibration data for:
  479. /// <list type="bullet">
  480. /// <listheader>
  481. /// <term>Key Code</term>
  482. /// <description>Button</description>
  483. /// </listheader>
  484. /// <item>
  485. /// <term>joyL</term>
  486. /// <description>Left Joystick</description>
  487. /// </item>
  488. /// <item>
  489. /// <term>joyR</term>
  490. /// <description>Right Joystick</description>
  491. /// </item>
  492. /// </list>
  493. /// </param>
  494. /// <returns>Normalized calibration data</returns>
  495. double wm_classic_get_calibration_maxx(double joystick)
  496. {
  497. double returnValue = -1;
  498. switch ((int)joystick)
  499. {
  500. case joyL:
  501. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxXL);
  502. break;
  503. case joyR:
  504. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxXR);
  505. break;
  506. default:
  507. break;
  508. }
  509. return (returnValue);
  510. }
  511. /// <summary>
  512. /// Gets X-axis joystick Calibration data
  513. /// </summary>
  514. /// <param name="joystick">
  515. /// The joystick to get calibration data for:
  516. /// <list type="bullet">
  517. /// <listheader>
  518. /// <term>Key Code</term>
  519. /// <description>Button</description>
  520. /// </listheader>
  521. /// <item>
  522. /// <term>joyL</term>
  523. /// <description>Left Joystick</description>
  524. /// </item>
  525. /// <item>
  526. /// <term>joyR</term>
  527. /// <description>Right Joystick</description>
  528. /// </item>
  529. /// </list>
  530. /// </param>
  531. /// <returns>Normalized calibration data</returns>
  532. double wm_classic_get_calibration_minx(double joystick)
  533. {
  534. double returnValue = -1;
  535. switch ((int)joystick)
  536. {
  537. case joyL:
  538. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinXL);
  539. break;
  540. case joyR:
  541. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinXR);
  542. break;
  543. default:
  544. break;
  545. }
  546. return (returnValue);
  547. }
  548. /// <summary>
  549. /// Gets X-axis joystick Calibration data
  550. /// </summary>
  551. /// <param name="joystick">
  552. /// The joystick to get calibration data for:
  553. /// <list type="bullet">
  554. /// <listheader>
  555. /// <term>Key Code</term>
  556. /// <description>Button</description>
  557. /// </listheader>
  558. /// <item>
  559. /// <term>joyL</term>
  560. /// <description>Left Joystick</description>
  561. /// </item>
  562. /// <item>
  563. /// <term>joyR</term>
  564. /// <description>Right Joystick</description>
  565. /// </item>
  566. /// </list>
  567. /// </param>
  568. /// <returns>Normalized calibration data</returns>
  569. double wm_classic_get_calibration_midx(double joystick)
  570. {
  571. double returnValue = -1;
  572. switch ((int)joystick)
  573. {
  574. case joyL:
  575. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidXL);
  576. break;
  577. case joyR:
  578. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidXR);
  579. break;
  580. default:
  581. break;
  582. }
  583. return (returnValue);
  584. }
  585. /// <summary>
  586. /// Gets Y-axis joystick Calibration data
  587. /// </summary>
  588. /// <param name="joystick">
  589. /// The joystick to get calibration data for:
  590. /// <list type="bullet">
  591. /// <listheader>
  592. /// <term>Key Code</term>
  593. /// <description>Button</description>
  594. /// </listheader>
  595. /// <item>
  596. /// <term>joyL</term>
  597. /// <description>Left Joystick</description>
  598. /// </item>
  599. /// <item>
  600. /// <term>joyR</term>
  601. /// <description>Right Joystick</description>
  602. /// </item>
  603. /// </list>
  604. /// </param>
  605. /// <returns>Normalized calibration data</returns>
  606. double wm_classic_get_calibration_midy(double joystick)
  607. {
  608. double returnValue = -1;
  609. switch ((int)joystick)
  610. {
  611. case joyL:
  612. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidYL);
  613. break;
  614. case joyR:
  615. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidYR);
  616. break;
  617. default:
  618. break;
  619. }
  620. return (returnValue);
  621. }
  622. /// <summary>
  623. /// Gets Y-axis joystick Calibration data
  624. /// </summary>
  625. /// <param name="joystick">
  626. /// The joystick to get calibration data for:
  627. /// <list type="bullet">
  628. /// <listheader>
  629. /// <term>Key Code</term>
  630. /// <description>Button</description>
  631. /// </listheader>
  632. /// <item>
  633. /// <term>joyL</term>
  634. /// <description>Left Joystick</description>
  635. /// </item>
  636. /// <item>
  637. /// <term>joyR</term>
  638. /// <description>Right Joystick</description>
  639. /// </item>
  640. /// </list>
  641. /// </param>
  642. /// <returns>Normalized calibration data</returns>
  643. double wm_classic_get_calibration_maxy(double joystick)
  644. {
  645. double returnValue = -1;
  646. switch ((int)joystick)
  647. {
  648. case joyL:
  649. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxYL);
  650. break;
  651. case joyR:
  652. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxYR);
  653. break;
  654. default:
  655. break;
  656. }
  657. return (returnValue);
  658. }
  659. /// <summary>
  660. /// Gets Y-axis joystick Calibration data
  661. /// </summary>
  662. /// <param name="joystick">
  663. /// The joystick to get calibration data for:
  664. /// <list type="bullet">
  665. /// <listheader>
  666. /// <term>Key Code</term>
  667. /// <description>Button</description>
  668. /// </listheader>
  669. /// <item>
  670. /// <term>joyL</term>
  671. /// <description>Left Joystick</description>
  672. /// </item>
  673. /// <item>
  674. /// <term>joyR</term>
  675. /// <description>Right Joystick</description>
  676. /// </item>
  677. /// </list>
  678. /// </param>
  679. /// <returns>Normalized calibration data</returns>
  680. double wm_classic_get_calibration_miny(double joystick)
  681. {
  682. double returnValue = -1;
  683. switch ((int)joystick)
  684. {
  685. case joyL:
  686. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinYL);
  687. break;
  688. case joyR:
  689. returnValue = double(GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinYR);
  690. break;
  691. default:
  692. break;
  693. }
  694. return (returnValue);
  695. }
  696. // Set Calibration
  697. /// <summary>
  698. /// Sets trigger calibration data
  699. /// </summary>
  700. /// <param name="trigger">
  701. /// The analog trigger to calibrate:
  702. /// <list type="bullet">
  703. /// <listheader>
  704. /// <term>Key Code</term>
  705. /// <description>Button</description>
  706. /// </listheader>
  707. /// <item>
  708. /// <term>btnL</term>
  709. /// <description>Left Trigger</description>
  710. /// </item>
  711. /// <item>
  712. /// <term>btnR</term>
  713. /// <description>Right Trigger</description>
  714. /// </item>
  715. /// </list>
  716. /// </param>
  717. /// <param name="val">The calibration value</param>
  718. /// <returns>Success</returns>
  719. double wm_classic_set_calibration_maxtrigger(double trigger, double val)
  720. {
  721. unsigned char calData = (unsigned char)val;
  722. try
  723. {
  724. switch ((int)trigger)
  725. {
  726. case btnL:
  727. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxTriggerL = calData;
  728. break;
  729. case btnR:
  730. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxTriggerR = calData;
  731. break;
  732. default:
  733. throw 1;
  734. break;
  735. }
  736. }
  737. catch(...)
  738. {
  739. return ( 0 );
  740. }
  741. return ( 1 );
  742. }
  743. /// <summary>
  744. /// Sets trigger calibration data
  745. /// </summary>
  746. /// <param name="trigger">
  747. /// The analog trigger to calibrate:
  748. /// <list type="bullet">
  749. /// <listheader>
  750. /// <term>Key Code</term>
  751. /// <description>Button</description>
  752. /// </listheader>
  753. /// <item>
  754. /// <term>btnL</term>
  755. /// <description>Left Trigger</description>
  756. /// </item>
  757. /// <item>
  758. /// <term>btnR</term>
  759. /// <description>Right Trigger</description>
  760. /// </item>
  761. /// </list>
  762. /// </param>
  763. /// <param name="val">The calibration value</param>
  764. /// <returns>Success</returns>
  765. double wm_classic_set_calibration_mintrigger(double trigger, double val)
  766. {
  767. unsigned char calData = (unsigned char)val;
  768. try
  769. {
  770. switch ((int)trigger)
  771. {
  772. case btnL:
  773. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinTriggerL = calData;
  774. break;
  775. case btnR:
  776. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinTriggerR = calData;
  777. break;
  778. default:
  779. throw 1;
  780. break;
  781. }
  782. }
  783. catch(...)
  784. {
  785. return ( 0 );
  786. }
  787. return ( 1 );
  788. }
  789. /// <summary>
  790. /// Sets X-axis joystick calibration data
  791. /// </summary>
  792. /// <param name="joystick">
  793. /// The joystick to calibrate:
  794. /// <list type="bullet">
  795. /// <listheader>
  796. /// <term>Key Code</term>
  797. /// <description>Button</description>
  798. /// </listheader>
  799. /// <item>
  800. /// <term>joyL</term>
  801. /// <description>Left Joystick</description>
  802. /// </item>
  803. /// <item>
  804. /// <term>joyR</term>
  805. /// <description>Right Joystick</description>
  806. /// </item>
  807. /// </list>
  808. /// </param>
  809. /// <param name="val">MaxX value</param>
  810. /// <returns>Success</returns>
  811. double wm_classic_set_calibration_maxx(double joystick, double val)
  812. {
  813. unsigned char calData = (unsigned char)val;
  814. try
  815. {
  816. switch ((int)joystick)
  817. {
  818. case joyL:
  819. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxXL = calData;
  820. break;
  821. case joyR:
  822. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxXR = calData;
  823. break;
  824. default:
  825. throw 1;
  826. break;
  827. }
  828. }
  829. catch(...)
  830. {
  831. return ( 0 );
  832. }
  833. return ( 1 );
  834. }
  835. /// <summary>
  836. /// Sets X-axis joystick calibration data
  837. /// </summary>
  838. /// <param name="joystick">
  839. /// The joystick to calibrate:
  840. /// <list type="bullet">
  841. /// <listheader>
  842. /// <term>Key Code</term>
  843. /// <description>Button</description>
  844. /// </listheader>
  845. /// <item>
  846. /// <term>joyL</term>
  847. /// <description>Left Joystick</description>
  848. /// </item>
  849. /// <item>
  850. /// <term>joyR</term>
  851. /// <description>Right Joystick</description>
  852. /// </item>
  853. /// </list>
  854. /// </param>
  855. /// <param name="val">MinX value</param>
  856. /// <returns>Success</returns>
  857. double wm_classic_set_calibration_minx(double joystick, double val)
  858. {
  859. unsigned char calData = (unsigned char)val;
  860. try
  861. {
  862. switch ((int)joystick)
  863. {
  864. case joyL:
  865. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinXL = calData;
  866. break;
  867. case joyR:
  868. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinXR = calData;
  869. break;
  870. default:
  871. throw 1;
  872. break;
  873. }
  874. }
  875. catch(...)
  876. {
  877. return ( 0 );
  878. }
  879. return ( 1 );
  880. }
  881. /// <summary>
  882. /// Sets X-axis joystick calibration data
  883. /// </summary>
  884. /// <param name="joystick">
  885. /// The joystick to calibrate:
  886. /// <list type="bullet">
  887. /// <listheader>
  888. /// <term>Key Code</term>
  889. /// <description>Button</description>
  890. /// </listheader>
  891. /// <item>
  892. /// <term>joyL</term>
  893. /// <description>Left Joystick</description>
  894. /// </item>
  895. /// <item>
  896. /// <term>joyR</term>
  897. /// <description>Right Joystick</description>
  898. /// </item>
  899. /// </list>
  900. /// </param>
  901. /// <param name="val">MidX value</param>
  902. /// <returns>Success</returns>
  903. double wm_classic_set_calibration_midx(double joystick, double val)
  904. {
  905. unsigned char calData = (unsigned char)val;
  906. try
  907. {
  908. switch ((int)joystick)
  909. {
  910. case joyL:
  911. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidXL = calData;
  912. break;
  913. case joyR:
  914. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidXR = calData;
  915. break;
  916. default:
  917. throw 1;
  918. break;
  919. }
  920. }
  921. catch(...)
  922. {
  923. return ( 0 );
  924. }
  925. return ( 1 );
  926. }
  927. /// <summary>
  928. /// Sets Y-axis joystick calibration data
  929. /// </summary>
  930. /// <param name="joystick">
  931. /// The joystick to calibrate:
  932. /// <list type="bullet">
  933. /// <listheader>
  934. /// <term>Key Code</term>
  935. /// <description>Button</description>
  936. /// </listheader>
  937. /// <item>
  938. /// <term>joyL</term>
  939. /// <description>Left Joystick</description>
  940. /// </item>
  941. /// <item>
  942. /// <term>joyR</term>
  943. /// <description>Right Joystick</description>
  944. /// </item>
  945. /// </list>
  946. /// </param>
  947. /// <param name="val">MidY value</param>
  948. /// <returns>Success</returns>
  949. double wm_classic_set_calibration_midy(double joystick, double val)
  950. {
  951. unsigned char calData = (unsigned char)val;
  952. try
  953. {
  954. switch ((int)joystick)
  955. {
  956. case joyL:
  957. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidYL = calData;
  958. break;
  959. case joyR:
  960. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MidYR = calData;
  961. break;
  962. default:
  963. throw 1;
  964. break;
  965. }
  966. }
  967. catch(...)
  968. {
  969. return ( 0 );
  970. }
  971. return ( 1 );
  972. }
  973. /// <summary>
  974. /// Sets Y-axis joystick calibration data
  975. /// </summary>
  976. /// <param name="joystick">
  977. /// The joystick to calibrate:
  978. /// <list type="bullet">
  979. /// <listheader>
  980. /// <term>Key Code</term>
  981. /// <description>Button</description>
  982. /// </listheader>
  983. /// <item>
  984. /// <term>joyL</term>
  985. /// <description>Left Joystick</description>
  986. /// </item>
  987. /// <item>
  988. /// <term>joyR</term>
  989. /// <description>Right Joystick</description>
  990. /// </item>
  991. /// </list>
  992. /// </param>
  993. /// <param name="val">MaxY value</param>
  994. /// <returns>Success</returns>
  995. double wm_classic_set_calibration_maxy(double joystick, double val)
  996. {
  997. unsigned char calData = (unsigned char)val;
  998. try
  999. {
  1000. switch ((int)joystick)
  1001. {
  1002. case joyL:
  1003. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxYL = calData;
  1004. break;
  1005. case joyR:
  1006. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MaxYR = calData;
  1007. break;
  1008. default:
  1009. throw 1;
  1010. break;
  1011. }
  1012. }
  1013. catch(...)
  1014. {
  1015. return ( 0 );
  1016. }
  1017. return ( 1 );
  1018. }
  1019. /// <summary>
  1020. /// Sets Y-axis joystick calibration data
  1021. /// </summary>
  1022. /// <param name="joystick">
  1023. /// The joystick to calibrate:
  1024. /// <list type="bullet">
  1025. /// <listheader>
  1026. /// <term>Key Code</term>
  1027. /// <description>Button</description>
  1028. /// </listheader>
  1029. /// <item>
  1030. /// <term>joyL</term>
  1031. /// <description>Left Joystick</description>
  1032. /// </item>
  1033. /// <item>
  1034. /// <term>joyR</term>
  1035. /// <description>Right Joystick</description>
  1036. /// </item>
  1037. /// </list>
  1038. /// </param>
  1039. /// <param name="val">MinY value</param>
  1040. /// <returns>Success</returns>
  1041. double wm_classic_set_calibration_miny(double joystick, double val)
  1042. {
  1043. unsigned char calData = (unsigned char)val;
  1044. try
  1045. {
  1046. switch ((int)joystick)
  1047. {
  1048. case joyL:
  1049. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinYL = calData;
  1050. break;
  1051. case joyR:
  1052. GiiMote::gm->wc[GiiMote::gm->wmIndex]->WiimoteState->ClassicControllerState.CalibrationInfo.MinYR = calData;
  1053. break;
  1054. default:
  1055. throw 1;
  1056. break;
  1057. }
  1058. }
  1059. catch(...)
  1060. {
  1061. return ( 0 );
  1062. }
  1063. return ( 1 );
  1064. }