RacquetSensor.cpp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2012
  6. All rights reserved.
  7. */
  8. #include "StdAfx.h"
  9. #include "RacquetSensor.h"
  10. /**************************************************************************
  11. * RacquetSensor::ANT_eventNotification
  12. *
  13. * Process ANT channel event
  14. *
  15. * ucEventCode_: code of ANT channel event
  16. * pucEventBuffer_: pointer to buffer containing data received from ANT,
  17. * or a pointer to the transmit buffer in the case of an EVENT_TX
  18. *
  19. * returns: N/A
  20. *
  21. **************************************************************************/
  22. void RacquetSensor::ANT_eventNotification(UCHAR ucEventCode_, UCHAR *pucEventBuffer_)
  23. {
  24. switch(ucEventCode_)
  25. {
  26. case EVENT_TX:
  27. if(startTime == System::DateTime::MinValue)
  28. startTime = System::DateTime::Now;
  29. HandleTransmit((UCHAR*) pucEventBuffer_);
  30. UpdateDisplay();
  31. break;
  32. case EVENT_RX_ACKNOWLEDGED:
  33. case EVENT_RX_BURST_PACKET:
  34. case EVENT_RX_BROADCAST:
  35. HandleReceive((UCHAR*) pucEventBuffer_);
  36. break;
  37. default:
  38. break;
  39. }
  40. }
  41. /**************************************************************************
  42. * RacquetSensor::InitializeSim
  43. *
  44. * Initializes simulator variables
  45. *
  46. * returns: N/A
  47. *
  48. **************************************************************************/
  49. void RacquetSensor::InitializeSim()
  50. {
  51. zones = gcnew array<array<USHORT>^>(AntPlusRacquet::NUMBER_OF_ZONES);
  52. for(int i = 0; i < zones->Length; i++)
  53. {
  54. zones[i] = gcnew array<USHORT> (AntPlusRacquet::NUMBER_OF_STROKE_TYPES);
  55. }
  56. startTime = System::DateTime::MinValue;
  57. lastTime = System::DateTime::Now;
  58. StrokeEvents = gcnew array<Event^>(256);
  59. // Initialize event array
  60. for(int i = 0; i < StrokeEvents->Length; i++)
  61. {
  62. StrokeEvents[i] = gcnew Event();
  63. StrokeEvents[i]->EventCount = Double::NaN;
  64. StrokeEvents[i]->EventTime = 0;
  65. StrokeEvents[i]->EventType = (UCHAR)AntPlusRacquet::StrokeTypes::NO_EVENT;
  66. StrokeEvents[i]->BallSpeed = 0;
  67. }
  68. ulTimerInterval = 250;
  69. ulTotalTime = 0;
  70. // Initialize Racquet Object data
  71. RacquetData->ucEventCount = 0x00;
  72. RacquetData->usEventTime = 0x00;
  73. RacquetData->ucEventType = (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN;
  74. RacquetData->ucRacquetZone = (UCHAR)AntPlusRacquet::RacquetZones::UNKNOWN;
  75. RacquetData->usSpeed = AntPlusRacquet::UNKNOWN;
  76. // Initialize Common Object data
  77. Common->ucHwVersion = System::Convert::ToByte(tbHardwareVer->Text);
  78. Common->usMfgID = System::Convert::ToUInt16(tbManfId->Text);
  79. Common->usModelNum = System::Convert::ToUInt16(tbModelNum->Text);
  80. Common->ulSerialNum = System::Convert::ToUInt32(tbSerialNumber->Text);
  81. Common->ucSwVersion = System::Convert::ToByte(tbSoftwareVer->Text);
  82. if(radioResolution2->Checked)
  83. Common->eTimeResolution = CommonData::TimeResolution::TWO;
  84. else
  85. Common->eTimeResolution = CommonData::TimeResolution::SIXTEEN;
  86. Common->ulOpTime = ulTotalTime / (UCHAR)Common->eTimeResolution;
  87. Common->bBattPageEnabled = true;
  88. Common->usBatVoltage256 = ((USHORT)System::Convert::ToByte(numericCoarseVoltage->Value)) << 8 | (Common->usBatVoltage256 & 0xFF);
  89. Common->usBatVoltage256 = System::Convert::ToByte(numericFractionalVoltage->Value) | (Common->usBatVoltage256 & 0xFF00);
  90. Common->eBatStatus = (CommonData::BatStatus::OK);
  91. // Initialize the first Stroke Event in the array
  92. StrokeEvents[RacquetData->ucEventCount]->EventCount = RacquetData->ucEventCount;
  93. StrokeEvents[RacquetData->ucEventCount]->EventTime = RacquetData->usEventTime;
  94. StrokeEvents[RacquetData->ucEventCount]->EventType = RacquetData->ucEventType;
  95. StrokeEvents[RacquetData->ucEventCount]->BallSpeed = RacquetData->usSpeed;
  96. cbEventCount->Items->Clear();
  97. cbEventCount->Items->Add(RacquetData->ucEventCount.ToString());
  98. time = 0;
  99. timerSession = gcnew System::Timers::Timer(1000);
  100. timerSession->Elapsed += gcnew ElapsedEventHandler(RacquetSensor::timerSession_Tick);
  101. }
  102. /**************************************************************************
  103. * RacquetSensor::HandleTransmit
  104. *
  105. * Encode data generated by simulator for transmission
  106. *
  107. * pucTxBuffer_: pointer to the transmit buffer
  108. *
  109. * returns: N/A
  110. *
  111. **************************************************************************/
  112. void RacquetSensor::HandleTransmit(UCHAR* pucTxBuffer_)
  113. {
  114. static ULONG ulMessageCount = 0;
  115. static UCHAR ucReqCommonPatternCount = 0;
  116. if (bTxRequest == true)
  117. {
  118. if (ucRequestCount == 0) // if count is zero, then reset
  119. {
  120. bTxRequest = false;
  121. goto page1;
  122. }
  123. RacquetData->Encode(Common->ucReqPageNum, pucTxBuffer_);
  124. ucRequestCount--; // subtract one from requested transmission count
  125. return; // skip the rest of the function in this case
  126. }
  127. page1:
  128. if (ulMessageCount >= 120)
  129. {
  130. ulMessageCount = 0; // reset count
  131. // send common data pages 80 and 81
  132. switch(ucReqCommonPatternCount)
  133. {
  134. case 0:
  135. Common->Encode(CommonData::PAGE80, pucTxBuffer_);
  136. break;
  137. case 1:
  138. Common->Encode(CommonData::PAGE81, pucTxBuffer_);
  139. break;
  140. case 2:
  141. Common->Encode(CommonData::PAGE82, pucTxBuffer_);
  142. break;
  143. default:
  144. break;
  145. }
  146. ucReqCommonPatternCount++;
  147. if (ucReqCommonPatternCount >= 3)
  148. ucReqCommonPatternCount = 0;
  149. }
  150. else
  151. RacquetData->Encode(AntPlusRacquet::PAGE_STROKE_EVENT, pucTxBuffer_);
  152. ulMessageCount++;
  153. static UCHAR ucTimeCount = 0;
  154. if(ucTimeCount++ == 3)
  155. {
  156. ulTotalTime++;
  157. Common->ulOpTime = ulTotalTime / (UCHAR)Common->eTimeResolution;
  158. ucTimeCount = 0;
  159. }
  160. }
  161. /**************************************************************************
  162. * RacquetSensor::UpdateDisplay
  163. *
  164. * Updates the GUI according to the current information to be displayed
  165. *
  166. * returns: N/A
  167. *
  168. **************************************************************************/
  169. void RacquetSensor::UpdateDisplay()
  170. {
  171. labelElpTime->Text = ulTotalTime.ToString();
  172. lbTime->Text = RacquetData->usEventTime.ToString();
  173. lbDisplayTime->Text = RacquetData->usEventTime.ToString();
  174. lbDisplaySpeed->Text = (RacquetData->usSpeed == AntPlusRacquet::UNKNOWN ?
  175. "Invalid" :
  176. checkMpS->Checked ?
  177. ((double)RacquetData->usSpeed / 100).ToString("F2"):
  178. (((double)RacquetData->usSpeed / 100) * ((double)36/(double)10)).ToString("F2"));
  179. lbDisplayEvent->Text = RacquetData->ucEventCount.ToString();
  180. //Session Metabolic Data
  181. lbMaxHRDisplay->Text = RacquetData->ucMaxHeartRate.ToString();
  182. lbAvgHRDisplay->Text = RacquetData->ucAvgHeartRate.ToString();
  183. lbTotCaloriesDisplay->Text = RacquetData->usTotalCalories.ToString();
  184. //Session Speed Data
  185. lbMaxRunSpdDisplay->Text = RacquetData->usMaxRunningSpeed.ToString();
  186. lbAvgRunSpdDisplay->Text = RacquetData->usAvgRunningSpeed.ToString();
  187. //Session Distance Data
  188. lbTotDistanceDisplay->Text = RacquetData->uiTotalDistance.ToString();
  189. switch(RacquetData->ucRacquetZone)
  190. {
  191. case (UCHAR)AntPlusRacquet::RacquetZones::MISS:
  192. lbDisplayZone->Text = "Miss";
  193. break;
  194. case (UCHAR)AntPlusRacquet::RacquetZones::TOP_RIGHT:
  195. lbDisplayZone->Text = "Top Right";
  196. break;
  197. case (UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_RIGHT:
  198. lbDisplayZone->Text = "Middle Right";
  199. break;
  200. case (UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_RIGHT:
  201. lbDisplayZone->Text = "Bottom Right";
  202. break;
  203. case (UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_CENTRE:
  204. lbDisplayZone->Text = "Bottom Centre";
  205. break;
  206. case (UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_LEFT:
  207. lbDisplayZone->Text = "Bottom Left";
  208. break;
  209. case (UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_CENTRE:
  210. lbDisplayZone->Text = "Middle Centre";
  211. break;
  212. case (UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_LEFT:
  213. lbDisplayZone->Text = "Middle Left";
  214. break;
  215. case (UCHAR)AntPlusRacquet::RacquetZones::TOP_CENTRE:
  216. lbDisplayZone->Text = "Top Centre";
  217. break;
  218. case (UCHAR)AntPlusRacquet::RacquetZones::TOP_LEFT:
  219. lbDisplayZone->Text = "Top Left";
  220. break;
  221. case (UCHAR)AntPlusRacquet::RacquetZones::RIM_OTHER:
  222. lbDisplayZone->Text = "Rim/Other";
  223. break;
  224. case (UCHAR)AntPlusRacquet::RacquetZones::UNKNOWN:
  225. lbDisplayZone->Text = "Unknown";
  226. break;
  227. default:
  228. lbDisplayZone->Text = "----";
  229. break;
  230. }
  231. switch(RacquetData->ucEventType)
  232. {
  233. case (UCHAR)AntPlusRacquet::StrokeTypes::NO_EVENT:
  234. lbDisplayStroke->Text = "No Event";
  235. break;
  236. case (UCHAR)AntPlusRacquet::StrokeTypes::BACKHAND:
  237. lbDisplayStroke->Text = "Backhand";
  238. break;
  239. case (UCHAR)AntPlusRacquet::StrokeTypes::FOREHAND:
  240. lbDisplayStroke->Text = "Forehand";
  241. break;
  242. case (UCHAR)AntPlusRacquet::StrokeTypes::OTHER:
  243. lbDisplayStroke->Text = "Other";
  244. break;
  245. case (UCHAR)AntPlusRacquet::StrokeTypes::SERVE:
  246. lbDisplayStroke->Text = "Serve";
  247. break;
  248. case (UCHAR)AntPlusRacquet::StrokeTypes::SMASH:
  249. lbDisplayStroke->Text = "Smash";
  250. break;
  251. case (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN:
  252. lbDisplayStroke->Text = "Unknown";
  253. break;
  254. default:
  255. lbDisplayStroke->Text = "----";
  256. break;
  257. }
  258. }
  259. /**************************************************************************
  260. * RacquetSensor::HandleReceive
  261. *
  262. * Process the data received from a receiving ANT device
  263. *
  264. * pucRxBuffer_: pointer to the receive buffer
  265. *
  266. * returns: N/A
  267. *
  268. **************************************************************************/
  269. void RacquetSensor::HandleReceive(UCHAR* pucRxBuffer_)
  270. {
  271. UCHAR ucPageNumber = pucRxBuffer_[0];
  272. USHORT count;
  273. UCHAR stroke1Index;
  274. UCHAR stroke2Index;
  275. UCHAR zone1Index;
  276. UCHAR zone2Index;
  277. AntPlusRacquet::FITSubSports oldGameMode = RacquetData->eGameMode;
  278. switch(ucPageNumber)
  279. {
  280. case Common->PAGE70:
  281. Common->Decode(pucRxBuffer_);
  282. ucRequestCount = Common->ucReqTransResp & 0x7F;
  283. bTxRequest = true;
  284. switch(Common->ucReqPageNum)
  285. {
  286. case AntPlusRacquet::PAGE_PREVIOUS_STROKE_EVENT:
  287. RacquetData->ucPreviousEventCount = Common->ucDescriptorByte1;
  288. RacquetData->ucPreviousEventType = StrokeEvents[RacquetData->ucPreviousEventCount]->EventType;
  289. RacquetData->usPreviousEventTime = StrokeEvents[RacquetData->ucPreviousEventCount]->EventTime;
  290. RacquetData->usPreviousSpeed = StrokeEvents[RacquetData->ucPreviousEventCount]->BallSpeed;
  291. RacquetData->ucPreviousRacquetZone = StrokeEvents[RacquetData->ucPreviousEventCount]->RacquetZone;
  292. break;
  293. case AntPlusRacquet::PAGE_STROKE_COUNT:
  294. count = 0;
  295. RacquetData->ucStrokeType1 = Common->ucDescriptorByte1;
  296. RacquetData->ucStrokeType2 = Common->ucDescriptorByte2;
  297. stroke1Index = (RacquetData->ucStrokeType1 == (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN ?
  298. AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1 :
  299. RacquetData->ucStrokeType1);
  300. stroke2Index = (RacquetData->ucStrokeType2 == (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN ?
  301. AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1 :
  302. RacquetData->ucStrokeType2);
  303. // Transmit unknown Stroke Counts
  304. if(cbUnknownStrokeCount->Checked)
  305. count = AntPlusRacquet::UNKNOWN;
  306. else if(RacquetData->ucStrokeType1 == (UCHAR)AntPlusRacquet::StrokeTypes::ALL_STROKES)
  307. {
  308. // All Strokes
  309. for(int i = 0; i < zones->Length; i++)
  310. for(int j = 1; j < zones[i]->Length; j++)
  311. count += zones[i][j];
  312. }
  313. else // Specific Stroke
  314. {
  315. for(int i = 0; i < zones->Length; i++)
  316. count += zones[i][stroke1Index];
  317. }
  318. RacquetData->usStrokeCount1 = count;
  319. count = 0;
  320. if(cbUnknownStrokeCount->Checked)
  321. count = AntPlusRacquet::UNKNOWN;
  322. else if(RacquetData->ucStrokeType2 == (UCHAR)AntPlusRacquet::StrokeTypes::ALL_STROKES)
  323. {
  324. // All Strokes
  325. for(int i = 0; i < zones->Length; i++)
  326. for(int j = 1; j < zones[i]->Length; j++)
  327. count += zones[i][j];
  328. }
  329. else // Specific Stroke
  330. {
  331. for(int i = 0; i < zones->Length; i++)
  332. count += zones[i][stroke2Index];
  333. }
  334. RacquetData->usStrokeCount2 = count;
  335. break;
  336. case AntPlusRacquet::PAGE_ZONE_COUNT:
  337. count = 0;
  338. RacquetData->ucType = Common->ucDescriptorByte1;
  339. RacquetData->ucZone = Common->ucDescriptorByte2;
  340. // Get array indexes to look for
  341. // If Zone is between 0 and 10 (Miss and Rim/Other), then that is the index.
  342. // If zone is 0x3F (Unknown), set index to 11
  343. zone1Index = ((RacquetData->ucZone == (UCHAR)AntPlusRacquet::RacquetZones::UNKNOWN) ?
  344. AntPlusRacquet::NUMBER_OF_ZONES - 1 :
  345. RacquetData->ucZone);
  346. // If Zone is 10 (Rim/Other)or 11 (unknown), set second index to index 11 (Unknown)
  347. zone2Index = (((RacquetData->ucZone == (UCHAR)AntPlusRacquet::RacquetZones::RIM_OTHER) || (RacquetData->ucZone == (UCHAR)AntPlusRacquet::RacquetZones::UNKNOWN)) ?
  348. AntPlusRacquet::NUMBER_OF_ZONES - 1 :
  349. RacquetData->ucZone + 1);
  350. if(cbUnknownZoneCount->Checked)
  351. {
  352. // User wishes to transmit unknown counts
  353. RacquetData->usCount = AntPlusRacquet::UNKNOWN;
  354. RacquetData->usCountPlus1 = AntPlusRacquet::UNKNOWN;
  355. break;
  356. }
  357. else if(RacquetData->ucType == (UCHAR)AntPlusRacquet::StrokeTypes::ALL_STROKES)
  358. {
  359. // Get all strokes for that particular zone
  360. for(int i = 1; i < zones[zone1Index]->Length; i++)
  361. count += zones[zone1Index][i];
  362. // Update the Count for the first zone
  363. RacquetData->usCount = count;
  364. // If the user requested Unknown zone (i.e. rollover makes zone2 index 0)
  365. // Set the count to unknown
  366. if(zone2Index == (UCHAR)AntPlusRacquet::RacquetZones::MISS)
  367. RacquetData->usCountPlus1 = AntPlusRacquet::UNKNOWN;
  368. else
  369. {
  370. // Else, get all strokes for that particular zone
  371. count = 0;
  372. for(int i = 1; i < zones[zone2Index]->Length; i++)
  373. count += zones[zone2Index][i];
  374. RacquetData->usCountPlus1 = count;
  375. }
  376. break;
  377. }
  378. else if(RacquetData->ucType == (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN)
  379. {
  380. // Get the count at the particular zone and the index for unknown stroke (6)
  381. RacquetData->usCount = zones[zone1Index][AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1];
  382. // If the user requestes Unknown zone (i.e. rollover makes zone2 index 0)
  383. // set the count for next zone to 0
  384. if(zone2Index == (UCHAR)AntPlusRacquet::RacquetZones::MISS)
  385. RacquetData->usCountPlus1 = AntPlusRacquet::UNKNOWN;
  386. else
  387. RacquetData->usCountPlus1 = zones[zone2Index][AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1];
  388. break;
  389. }
  390. else
  391. {
  392. RacquetData->usCount = zones[zone1Index][RacquetData->ucType];
  393. if(zone2Index == (UCHAR)AntPlusRacquet::RacquetZones::MISS)
  394. RacquetData->usCountPlus1 = AntPlusRacquet::UNKNOWN;
  395. else
  396. RacquetData->usCountPlus1 = zones[zone2Index][RacquetData->ucType];
  397. }
  398. break;
  399. default:
  400. break;
  401. }
  402. break;
  403. case AntPlusRacquet::PAGE_EVENT_DATA:
  404. RacquetData->Decode(pucRxBuffer_);
  405. switch(RacquetData->eEvent)
  406. {
  407. case AntPlusRacquet::FITEvents::TIMER:
  408. case AntPlusRacquet::FITEvents::SESSION:
  409. if(RacquetData->eEventType == AntPlusRacquet::FITEventTypes::START)
  410. {
  411. timerSession->Enabled = true;
  412. timerSession->Start();
  413. }
  414. else
  415. {
  416. timerSession->Stop();
  417. timerSession->Enabled = false;
  418. if(RacquetData->eEvent == AntPlusRacquet::FITEvents::SESSION)
  419. {
  420. time = 0;
  421. lbSessionTime->Text = "00:00:00";
  422. }
  423. }
  424. break;
  425. case AntPlusRacquet::FITEvents::USER_MARKER:
  426. if(RacquetData->eEventType == AntPlusRacquet::FITEventTypes::MARKER)
  427. {
  428. if(lbUserMarker->Text == "----")
  429. lbUserMarker->Text = "1";
  430. else
  431. {
  432. int i;
  433. i = System::Convert::ToInt32(lbUserMarker->Text);
  434. lbUserMarker->Text = (i + 1).ToString();
  435. }
  436. }
  437. break;
  438. case AntPlusRacquet::FITEvents::SPORT_POINT:
  439. if((RacquetData->ulEventData & 0xFFFF) == AntPlusRacquet::UNKNOWN)
  440. lbMyScore->Text = "Invalid";
  441. else
  442. lbMyScore->Text = ((USHORT)(RacquetData->ulEventData & 0xFFFF)).ToString();
  443. if(((RacquetData->ulEventData >> 16) & 0xFFFF) == AntPlusRacquet::UNKNOWN)
  444. lbOpponentScore->Text = "Invalid";
  445. else
  446. lbOpponentScore->Text = ((USHORT)(RacquetData->ulEventData >> 16) & 0xFFFF).ToString();
  447. break;
  448. default:
  449. break;
  450. }
  451. break;
  452. case AntPlusRacquet::PAGE_SESSION_DATA:
  453. RacquetData->Decode(pucRxBuffer_);
  454. if(oldGameMode != RacquetData->eGameMode)
  455. {
  456. time = 0;
  457. lbSessionTime->Text = "00:00:00";
  458. }
  459. switch(RacquetData->eGameMode)
  460. {
  461. case AntPlusRacquet::FITSubSports::WARM_UP:
  462. lbGameMode->Text = "Warm Up";
  463. lbGameModeText->Text = "Warm Up Count (Session)";
  464. break;
  465. case AntPlusRacquet::FITSubSports::MATCH:
  466. lbGameMode->Text = "Match";
  467. lbGameModeText->Text = "Match Count (Session)";
  468. break;
  469. case AntPlusRacquet::FITSubSports::EXERCISE:
  470. lbGameMode->Text = "Exercise";
  471. lbGameModeText->Text = "Exercise Count (Session)";
  472. break;
  473. case AntPlusRacquet::FITSubSports::CHALLENGE:
  474. lbGameMode->Text = "Challenge";
  475. lbGameModeText->Text = "Challenge Count (Session)";
  476. break;
  477. default:
  478. lbGameMode->Text = "Session";
  479. lbGameModeText->Text = "Session Count (Session)";
  480. break;
  481. }
  482. if(RacquetData->usMySessionsWon == AntPlusRacquet::UNKNOWN)
  483. lbMySessionsWon->Text = "Invalid";
  484. else
  485. lbMySessionsWon->Text = RacquetData->usMySessionsWon.ToString();
  486. if(RacquetData->usOpponentSessionsWon == AntPlusRacquet::UNKNOWN)
  487. lbOpponentSessionsWon->Text = "Invalid";
  488. else
  489. lbOpponentSessionsWon->Text = RacquetData->usOpponentSessionsWon.ToString();
  490. break;
  491. case AntPlusRacquet::PAGE_LAP_DATA:
  492. RacquetData->Decode(pucRxBuffer_);
  493. if(RacquetData->usMySetCount == AntPlusRacquet::UNKNOWN)
  494. lbMySetCount->Text = "Invalid";
  495. else
  496. lbMySetCount->Text = RacquetData->usMySetCount.ToString();
  497. if(RacquetData->usOpponentSetCount == AntPlusRacquet::UNKNOWN)
  498. lbOpponentSetCount->Text = "Invalid";
  499. else
  500. lbOpponentSetCount->Text = RacquetData->usOpponentSetCount.ToString();
  501. break;
  502. case AntPlusRacquet::PAGE_LENGTH_DATA:
  503. RacquetData->Decode(pucRxBuffer_);
  504. if(RacquetData->usMyGameCount == AntPlusRacquet::UNKNOWN)
  505. lbMyGameCount->Text = "Invalid";
  506. else
  507. lbMyGameCount->Text = RacquetData->usMyGameCount.ToString();
  508. if(RacquetData->usOpponentGameCount == AntPlusRacquet::UNKNOWN)
  509. lbOpponentGameCount->Text = "Invalid";
  510. else
  511. lbOpponentGameCount->Text = RacquetData->usOpponentGameCount.ToString();
  512. break;
  513. case AntPlusRacquet::PAGE_METABOLIC_DATA:
  514. case AntPlusRacquet::PAGE_SPEED_DATA:
  515. case AntPlusRacquet::PAGE_DISTANCE_DATA: //Intentional Fallthroughs
  516. RacquetData->Decode(pucRxBuffer_);
  517. UpdateDisplay();
  518. break;
  519. default:
  520. break;
  521. }
  522. }
  523. /**************************************************************************
  524. * RacquetSensor::OnTimerTock
  525. *
  526. * Required by the ISimBase interface. Currently unused for this simulator
  527. *
  528. * eventTime: current time (ms)
  529. *
  530. * returns: N/A
  531. *
  532. **************************************************************************/
  533. void RacquetSensor::onTimerTock(USHORT eventTime)
  534. {
  535. System::DateTime time = System::DateTime::Now;
  536. System::Int64 elapsedTicks = (time.Ticks - lastTime.Ticks);
  537. TimeSpan elapsedTime = TimeSpan(elapsedTicks);
  538. // 4 minutes has passed
  539. if(elapsedTime.TotalSeconds >= 240)
  540. {
  541. TimeSpan elapsedSpan = TimeSpan(time.Ticks - startTime.Ticks);
  542. lastTime = time;
  543. RacquetData->ucEventCount++;
  544. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  545. RacquetData->ucEventType = (UCHAR)AntPlusRacquet::StrokeTypes::NO_EVENT;
  546. RacquetData->ucRacquetZone = (UCHAR)AntPlusRacquet::RacquetZones::UNKNOWN;
  547. RacquetData->usSpeed = AntPlusRacquet::UNKNOWN;
  548. zones[AntPlusRacquet::NUMBER_OF_ZONES - 1][AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1]++;
  549. AddEvent();
  550. }
  551. }
  552. /**************************************************************************
  553. * RacquetSensor::zoneOne_Click
  554. *
  555. * Handles zoneOne button click event. Updates event being transmitted.
  556. *
  557. * sender: Object raising event
  558. * e: Event arguments
  559. *
  560. * returns: N/A
  561. *
  562. **************************************************************************/
  563. void RacquetSensor::zoneOne_Click(System::Object ^sender, System::EventArgs ^e)
  564. {
  565. DateTime currentTime = DateTime::Now;
  566. lastTime = currentTime;
  567. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  568. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  569. RacquetData->ucEventCount++;
  570. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  571. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  572. (UCHAR)AntPlusRacquet::UNKNOWN :
  573. (UCHAR)(this->comboType->SelectedIndex));
  574. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::TOP_RIGHT);
  575. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  576. AntPlusRacquet::UNKNOWN :
  577. (checkMpS->Checked ?
  578. (USHORT)(this->valueSpeed->Value * 100):
  579. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  580. zones[(UCHAR)AntPlusRacquet::RacquetZones::TOP_RIGHT][comboType->SelectedIndex]++;
  581. AddEvent();
  582. }
  583. /**************************************************************************
  584. * RacquetSensor::zoneTwo_Click
  585. *
  586. * Handles zoneTwo button click event. Updates event being transmitted.
  587. *
  588. * sender: Object raising event
  589. * e: Event arguments
  590. *
  591. * returns: N/A
  592. *
  593. **************************************************************************/
  594. void RacquetSensor::zoneTwo_Click(System::Object ^sender, System::EventArgs ^e)
  595. {
  596. DateTime currentTime = DateTime::Now;
  597. lastTime = currentTime;
  598. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  599. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  600. RacquetData->ucEventCount++;
  601. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  602. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  603. (UCHAR)AntPlusRacquet::UNKNOWN :
  604. (UCHAR)(this->comboType->SelectedIndex));
  605. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::MIDDLE_RIGHT);
  606. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  607. AntPlusRacquet::UNKNOWN :
  608. (checkMpS->Checked ?
  609. (USHORT)(this->valueSpeed->Value * 100):
  610. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  611. zones[(UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_RIGHT][comboType->SelectedIndex]++;
  612. AddEvent();
  613. }
  614. /**************************************************************************
  615. * RacquetSensor::zoneThree_Click
  616. *
  617. * Handles zoneThree button click event. Updates event being transmitted.
  618. *
  619. * sender: Object raising event
  620. * e: Event arguments
  621. *
  622. * returns: N/A
  623. *
  624. **************************************************************************/
  625. void RacquetSensor::zoneThree_Click(System::Object ^sender, System::EventArgs ^e)
  626. {
  627. DateTime currentTime = DateTime::Now;
  628. lastTime = currentTime;
  629. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  630. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  631. RacquetData->ucEventCount++;
  632. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  633. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  634. (UCHAR)AntPlusRacquet::UNKNOWN :
  635. (UCHAR)(this->comboType->SelectedIndex));
  636. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::BOTTOM_RIGHT);
  637. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  638. AntPlusRacquet::UNKNOWN :
  639. (checkMpS->Checked ?
  640. (USHORT)(this->valueSpeed->Value * 100):
  641. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  642. zones[(UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_RIGHT][comboType->SelectedIndex]++;
  643. AddEvent();
  644. }
  645. /**************************************************************************
  646. * RacquetSensor::zoneFour_Click
  647. *
  648. * Handles zoneFour button click event. Updates event being transmitted.
  649. *
  650. * sender: Object raising event
  651. * e: Event arguments
  652. *
  653. * returns: N/A
  654. *
  655. **************************************************************************/
  656. void RacquetSensor::zoneFour_Click(System::Object ^sender, System::EventArgs ^e)
  657. {
  658. DateTime currentTime = DateTime::Now;
  659. lastTime = currentTime;
  660. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  661. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  662. RacquetData->ucEventCount++;
  663. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  664. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  665. (UCHAR)AntPlusRacquet::UNKNOWN :
  666. (UCHAR)(this->comboType->SelectedIndex));
  667. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::BOTTOM_CENTRE);
  668. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  669. AntPlusRacquet::UNKNOWN :
  670. (checkMpS->Checked ?
  671. (USHORT)(this->valueSpeed->Value * 100):
  672. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  673. zones[(UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_CENTRE][comboType->SelectedIndex]++;
  674. AddEvent();
  675. }
  676. /**************************************************************************
  677. * RacquetSensor::zoneFive_Click
  678. *
  679. * Handles zoneFive button click event. Updates event being transmitted.
  680. *
  681. * sender: Object raising event
  682. * e: Event arguments
  683. *
  684. * returns: N/A
  685. *
  686. **************************************************************************/
  687. void RacquetSensor::zoneFive_Click(System::Object ^sender, System::EventArgs ^e)
  688. {
  689. DateTime currentTime = DateTime::Now;
  690. lastTime = currentTime;
  691. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  692. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  693. RacquetData->ucEventCount++;
  694. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  695. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  696. (UCHAR)AntPlusRacquet::UNKNOWN :
  697. (UCHAR)(this->comboType->SelectedIndex));
  698. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::BOTTOM_LEFT);
  699. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  700. AntPlusRacquet::UNKNOWN :
  701. (checkMpS->Checked ?
  702. (USHORT)(this->valueSpeed->Value * 100):
  703. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  704. zones[(UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_LEFT][comboType->SelectedIndex]++;
  705. AddEvent();
  706. }
  707. /**************************************************************************
  708. * RacquetSensor::zoneSix_Click
  709. *
  710. * Handles zoneSix button click event. Updates event being transmitted.
  711. *
  712. * sender: Object raising event
  713. * e: Event arguments
  714. *
  715. * returns: N/A
  716. *
  717. **************************************************************************/
  718. void RacquetSensor::zoneSix_Click(System::Object ^sender, System::EventArgs ^e)
  719. {
  720. DateTime currentTime = DateTime::Now;
  721. lastTime = currentTime;
  722. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  723. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  724. RacquetData->ucEventCount++;
  725. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  726. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  727. (UCHAR)AntPlusRacquet::UNKNOWN :
  728. (UCHAR)(this->comboType->SelectedIndex));
  729. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::MIDDLE_CENTRE);
  730. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  731. AntPlusRacquet::UNKNOWN :
  732. (checkMpS->Checked ?
  733. (USHORT)(this->valueSpeed->Value * 100):
  734. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  735. zones[(UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_CENTRE][comboType->SelectedIndex]++;
  736. AddEvent();
  737. }
  738. /**************************************************************************
  739. * RacquetSensor::zoneSeven_Click
  740. *
  741. * Handles zoneSeven button click event. Updates event being transmitted.
  742. *
  743. * sender: Object raising event
  744. * e: Event arguments
  745. *
  746. * returns: N/A
  747. *
  748. **************************************************************************/
  749. void RacquetSensor::zoneSeven_Click(System::Object ^sender, System::EventArgs ^e)
  750. {
  751. DateTime currentTime = DateTime::Now;
  752. lastTime = currentTime;
  753. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  754. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  755. RacquetData->ucEventCount++;
  756. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  757. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  758. (UCHAR)AntPlusRacquet::UNKNOWN :
  759. (UCHAR)(this->comboType->SelectedIndex));
  760. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::MIDDLE_LEFT);
  761. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  762. AntPlusRacquet::UNKNOWN :
  763. (checkMpS->Checked ?
  764. (USHORT)(this->valueSpeed->Value * 100):
  765. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  766. zones[(UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_LEFT][comboType->SelectedIndex]++;
  767. AddEvent();
  768. }
  769. /**************************************************************************
  770. * RacquetSensor::zoneEight_Click
  771. *
  772. * Handles zoneEight button click event. Updates event being transmitted.
  773. *
  774. * sender: Object raising event
  775. * e: Event arguments
  776. *
  777. * returns: N/A
  778. *
  779. **************************************************************************/
  780. void RacquetSensor::zoneEight_Click(System::Object ^sender, System::EventArgs ^e)
  781. {
  782. DateTime currentTime = DateTime::Now;
  783. lastTime = currentTime;
  784. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  785. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  786. RacquetData->ucEventCount++;
  787. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  788. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  789. (UCHAR)AntPlusRacquet::UNKNOWN :
  790. (UCHAR)(this->comboType->SelectedIndex));
  791. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::TOP_LEFT);
  792. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  793. AntPlusRacquet::UNKNOWN :
  794. (checkMpS->Checked ?
  795. (USHORT)(this->valueSpeed->Value * 100):
  796. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  797. zones[(UCHAR)AntPlusRacquet::RacquetZones::TOP_LEFT][comboType->SelectedIndex]++;
  798. AddEvent();
  799. }
  800. /**************************************************************************
  801. * RacquetSensor::zoneNine_Click
  802. *
  803. * Handles zoneNine button click event. Updates event being transmitted.
  804. *
  805. * sender: Object raising event
  806. * e: Event arguments
  807. *
  808. * returns: N/A
  809. *
  810. **************************************************************************/
  811. void RacquetSensor::zoneNine_Click(System::Object ^sender, System::EventArgs ^e)
  812. {
  813. DateTime currentTime = DateTime::Now;
  814. lastTime = currentTime;
  815. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  816. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  817. RacquetData->ucEventCount++;
  818. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  819. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  820. (UCHAR)AntPlusRacquet::UNKNOWN :
  821. (UCHAR)(this->comboType->SelectedIndex));
  822. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::TOP_CENTRE);
  823. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  824. AntPlusRacquet::UNKNOWN :
  825. (checkMpS->Checked ?
  826. (USHORT)(this->valueSpeed->Value * 100):
  827. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  828. zones[(UCHAR)AntPlusRacquet::RacquetZones::TOP_CENTRE][comboType->SelectedIndex]++;
  829. AddEvent();
  830. }
  831. /**************************************************************************
  832. * RacquetSensor::zoneOther_Click
  833. *
  834. * Handles zoneOther button click event. Updates event being transmitted.
  835. *
  836. * sender: Object raising event
  837. * e: Event arguments
  838. *
  839. * returns: N/A
  840. *
  841. **************************************************************************/
  842. void RacquetSensor::zoneOther_Click(System::Object ^sender, System::EventArgs ^e)
  843. {
  844. DateTime currentTime = DateTime::Now;
  845. lastTime = currentTime;
  846. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  847. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  848. RacquetData->ucEventCount++;
  849. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  850. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  851. (UCHAR)AntPlusRacquet::UNKNOWN :
  852. (UCHAR)(this->comboType->SelectedIndex));
  853. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::RIM_OTHER);
  854. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  855. AntPlusRacquet::UNKNOWN :
  856. (checkMpS->Checked ?
  857. (USHORT)(this->valueSpeed->Value * 100):
  858. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  859. zones[(UCHAR)AntPlusRacquet::RacquetZones::RIM_OTHER][comboType->SelectedIndex]++;
  860. AddEvent();
  861. }
  862. /**************************************************************************
  863. * RacquetSensor::zoneUnknown_Click
  864. *
  865. * Handles zoneUnknown button click event. Updates event being transmitted.
  866. *
  867. * sender: Object raising event
  868. * e: Event arguments
  869. *
  870. * returns: N/A
  871. *
  872. **************************************************************************/
  873. void RacquetSensor::zoneUnknown_Click(System::Object ^sender, System::EventArgs ^e)
  874. {
  875. DateTime currentTime = DateTime::Now;
  876. lastTime = currentTime;
  877. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  878. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  879. RacquetData->ucEventCount++;
  880. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  881. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  882. (UCHAR)AntPlusRacquet::UNKNOWN :
  883. (UCHAR)(this->comboType->SelectedIndex));
  884. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::UNKNOWN);
  885. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  886. AntPlusRacquet::UNKNOWN :
  887. (checkMpS->Checked ?
  888. (USHORT)(this->valueSpeed->Value * 100):
  889. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  890. zones[(UCHAR)AntPlusRacquet::NUMBER_OF_ZONES - 1][comboType->SelectedIndex]++;
  891. AddEvent();
  892. }
  893. /**************************************************************************
  894. * RacquetSensor::zoneMiss_Click
  895. *
  896. * Handles zoneMiss button click event. Updates event being transmitted.
  897. *
  898. * sender: Object raising event
  899. * e: Event arguments
  900. *
  901. * returns: N/A
  902. *
  903. **************************************************************************/
  904. void RacquetSensor::zoneMiss_Click(System::Object ^sender, System::EventArgs ^e)
  905. {
  906. DateTime currentTime = DateTime::Now;
  907. lastTime = currentTime;
  908. System::Int64 elapsedTicks = (currentTime.Ticks - startTime.Ticks);
  909. TimeSpan elapsedSpan = TimeSpan(elapsedTicks);
  910. RacquetData->ucEventCount++;
  911. RacquetData->usEventTime = (USHORT)(elapsedSpan.TotalSeconds * 256);
  912. RacquetData->ucEventType = (comboType->SelectedIndex == 6 ?
  913. (UCHAR)AntPlusRacquet::UNKNOWN :
  914. (UCHAR)(this->comboType->SelectedIndex));
  915. RacquetData->ucRacquetZone = (UCHAR)(AntPlusRacquet::RacquetZones::MISS);
  916. RacquetData->usSpeed = (ckInvalidSpeed->Checked ?
  917. AntPlusRacquet::UNKNOWN :
  918. (checkMpS->Checked ?
  919. (USHORT)(this->valueSpeed->Value * 100):
  920. (USHORT) Math::Round((valueSpeed->Value * 1000/36), System::MidpointRounding::AwayFromZero)));
  921. zones[(UCHAR)AntPlusRacquet::RacquetZones::MISS][comboType->SelectedIndex]++;
  922. AddEvent();
  923. }
  924. /**************************************************************************
  925. * RacquetSensor::AddEvent
  926. *
  927. * Adds a new stroke event to the StrokeEvent array
  928. *
  929. * returns: N/A
  930. *
  931. **************************************************************************/
  932. void RacquetSensor::AddEvent()
  933. {
  934. // Set the next element in StrokeEvent array to this event
  935. StrokeEvents[RacquetData->ucEventCount]->EventCount = RacquetData->ucEventCount;
  936. StrokeEvents[RacquetData->ucEventCount]->EventTime = RacquetData->usEventTime;
  937. StrokeEvents[RacquetData->ucEventCount]->EventType = RacquetData->ucEventType;
  938. StrokeEvents[RacquetData->ucEventCount]->BallSpeed = RacquetData->usSpeed;
  939. StrokeEvents[RacquetData->ucEventCount]->RacquetZone = RacquetData->ucRacquetZone;
  940. cbEventCount->Items->Add(RacquetData->ucEventCount.ToString());
  941. }
  942. /**************************************************************************
  943. * RacquetSensor::ckInvalidSpeed_CheckedChanged
  944. *
  945. * Handles the ckInvalidSpeed Checked Changed event. If the checkbox is
  946. * checked, don't allow the user to change the speed field. If it is not
  947. * checked, allow the user to change the speed field.
  948. *
  949. * sender: Object raising event
  950. * e: Event arguments
  951. *
  952. * returns: N/A
  953. *
  954. **************************************************************************/
  955. void RacquetSensor::ckInvalidSpeed_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  956. {
  957. if(this->ckInvalidSpeed->Checked)
  958. this->valueSpeed->Enabled = false;
  959. else
  960. this->valueSpeed->Enabled = true;
  961. }
  962. /**************************************************************************
  963. * RacquetSensor::cbEventCount_SelectedIndexChanged
  964. *
  965. * Handles cbEventCount Selected Index Changed event. Displays the previous
  966. * event data based on the event count chosen by the user in the comboBox.
  967. *
  968. * sender: Object raising event
  969. * e: Event arguments
  970. *
  971. * returns: N/A
  972. *
  973. **************************************************************************/
  974. void RacquetSensor::cbEventCount_SelectedIndexChanged(System::Object ^sender, System::EventArgs ^e)
  975. {
  976. switch(StrokeEvents[cbEventCount->SelectedIndex]->RacquetZone)
  977. {
  978. case AntPlusRacquet::RacquetZones::MISS:
  979. lbRacquetZone->Text = "Miss";
  980. break;
  981. case AntPlusRacquet::RacquetZones::TOP_RIGHT:
  982. lbRacquetZone->Text = "Top Right";
  983. break;
  984. case AntPlusRacquet::RacquetZones::MIDDLE_RIGHT:
  985. lbRacquetZone->Text = "Middle Right";
  986. break;
  987. case AntPlusRacquet::RacquetZones::BOTTOM_RIGHT:
  988. lbRacquetZone->Text = "Bottom Right";
  989. break;
  990. case AntPlusRacquet::RacquetZones::BOTTOM_CENTRE:
  991. lbRacquetZone->Text = "Bottom Center";
  992. break;
  993. case AntPlusRacquet::RacquetZones::BOTTOM_LEFT:
  994. lbRacquetZone->Text = "Botttom Left";
  995. break;
  996. case AntPlusRacquet::RacquetZones::MIDDLE_CENTRE:
  997. lbRacquetZone->Text = "Middle Center";
  998. break;
  999. case AntPlusRacquet::RacquetZones::MIDDLE_LEFT:
  1000. lbRacquetZone->Text = "Middle Left";
  1001. break;
  1002. case AntPlusRacquet::RacquetZones::TOP_LEFT:
  1003. lbRacquetZone->Text = "Top Left";
  1004. break;
  1005. case AntPlusRacquet::RacquetZones::TOP_CENTRE:
  1006. lbRacquetZone->Text = "Top Center";
  1007. break;
  1008. case AntPlusRacquet::RacquetZones::RIM_OTHER:
  1009. lbRacquetZone->Text = "Rim/Other";
  1010. break;
  1011. case AntPlusRacquet::RacquetZones::UNKNOWN:
  1012. lbRacquetZone->Text = "Unknown";
  1013. break;
  1014. default:
  1015. lbRacquetZone->Text = "----";
  1016. break;
  1017. }
  1018. switch(StrokeEvents[cbEventCount->SelectedIndex]->EventType)
  1019. {
  1020. case AntPlusRacquet::StrokeTypes::NO_EVENT:
  1021. lbStrokeType->Text = "No Event";
  1022. break;
  1023. case AntPlusRacquet::StrokeTypes::OTHER:
  1024. lbStrokeType->Text = "Other";
  1025. break;
  1026. case AntPlusRacquet::StrokeTypes::SERVE:
  1027. lbStrokeType->Text = "Serve";
  1028. break;
  1029. case AntPlusRacquet::StrokeTypes::FOREHAND:
  1030. lbStrokeType->Text = "Forehand";
  1031. break;
  1032. case AntPlusRacquet::StrokeTypes::BACKHAND:
  1033. lbStrokeType->Text = "Backhand";
  1034. break;
  1035. case AntPlusRacquet::StrokeTypes::SMASH:
  1036. lbStrokeType->Text = "Smash";
  1037. break;
  1038. case AntPlusRacquet::StrokeTypes::UNKNOWN:
  1039. lbStrokeType->Text = "Unknown";
  1040. break;
  1041. default:
  1042. lbStrokeType->Text = "----";
  1043. break;
  1044. }
  1045. lbBallSpeed->Text = (StrokeEvents[cbEventCount->SelectedIndex]->BallSpeed == AntPlusRacquet::UNKNOWN ?
  1046. "Invalid" :
  1047. ((double)StrokeEvents[cbEventCount->SelectedIndex]->BallSpeed / 100).ToString("F2") + " m/s");
  1048. lbEventTime->Text = StrokeEvents[cbEventCount->SelectedIndex]->EventTime.ToString();
  1049. }
  1050. /**************************************************************************
  1051. * RacquetSensor::cbStrokeType_SelectedIndexChanged
  1052. *
  1053. * Handles cbStrokeType Selected Index Changed event. Displays the stroke
  1054. * count based on the type of stroke selected.
  1055. *
  1056. * sender: Object raising event
  1057. * e: Event arguments
  1058. *
  1059. * returns: N/A
  1060. *
  1061. **************************************************************************/
  1062. void RacquetSensor::cbStrokeType_SelectedIndexChanged(System::Object ^sender, System::EventArgs ^e)
  1063. {
  1064. USHORT count = 0;
  1065. // All strokes
  1066. if(cbStrokeType->SelectedIndex == 0)
  1067. {
  1068. for(int i = 0; i < zones->Length; i++)
  1069. {
  1070. for(int j = 1; j < zones[i]->Length; j++)
  1071. count += zones[i][j];
  1072. }
  1073. }
  1074. else // Certain stroke
  1075. {
  1076. for(int i = 0; i < zones->Length; i++)
  1077. count += zones[i][cbStrokeType->SelectedIndex];
  1078. }
  1079. lbStrokes->Text = count.ToString();
  1080. }
  1081. /**************************************************************************
  1082. * RacquetSensor::cbRacquetZone_SelectedIndexChanged
  1083. *
  1084. * Handles cbRacquetZone Selected Index Changed event. Displays the stroke
  1085. * count based on the Racquet Zone and Stroke Type selected by the user.
  1086. *
  1087. * sender: Object raising event
  1088. * e: Event arguments
  1089. *
  1090. * returns: N/A
  1091. *
  1092. **************************************************************************/
  1093. void RacquetSensor::cbRacquetZone_SelectedIndexChanged(System::Object ^sender, System::EventArgs ^e)
  1094. {
  1095. USHORT count = 0;
  1096. if(cbZoneStrokes->SelectedIndex == 0)
  1097. {
  1098. for(int i = 0; i < zones->Length; i++)
  1099. for(int j = 1; j < zones[i]->Length; j++)
  1100. count += zones[i][j];
  1101. }
  1102. else
  1103. count = zones[cbRacquetZone->SelectedIndex][cbZoneStrokes->SelectedIndex];
  1104. lbZoneStrokes->Text = count.ToString();
  1105. }
  1106. /**************************************************************************
  1107. * RacquetSensor::cbZoneStrokes_SelectedIndexChanged
  1108. *
  1109. * Handles cbZoneStrokes Selected Index Changed event. Displays the stroke
  1110. * count based on the Racquet Zone and Stroke Type selected by the user.
  1111. *
  1112. * sender: Object raising event
  1113. * e: Event arguments
  1114. *
  1115. * returns: N/A
  1116. *
  1117. **************************************************************************/
  1118. void RacquetSensor::cbZoneStrokes_SelectedIndexChanged(System::Object ^sender, System::EventArgs ^e)
  1119. {
  1120. USHORT count = 0;
  1121. if(cbZoneStrokes->SelectedIndex == 0)
  1122. {
  1123. for(int i = 0; i < zones->Length; i++)
  1124. for(int j = 1; j < zones[i]->Length; j++)
  1125. count += zones[i][j];
  1126. }
  1127. else
  1128. count = zones[cbRacquetZone->SelectedIndex][cbZoneStrokes->SelectedIndex];
  1129. lbZoneStrokes->Text = count.ToString();
  1130. }
  1131. void RacquetSensor::btUpdateCommon_Click(System::Object ^sender, System::EventArgs ^e)
  1132. {
  1133. lbCommonError->Visible = false;
  1134. try
  1135. {
  1136. Common->ucHwVersion = System::Convert::ToByte(tbHardwareVer->Text);
  1137. Common->usMfgID = System::Convert::ToUInt16(tbManfId->Text);
  1138. Common->usModelNum = System::Convert::ToUInt16(tbModelNum->Text);
  1139. Common->ucSwVersion = System::Convert::ToByte(tbSoftwareVer->Text);
  1140. if(cbInvalidSerial->Checked)
  1141. Common->ulSerialNum = 0xFFFFFFFF;
  1142. else
  1143. Common->ulSerialNum = System::Convert::ToUInt32(tbSerialNumber->Text);
  1144. }
  1145. catch(...)
  1146. {
  1147. lbCommonError->Visible = true;
  1148. }
  1149. }
  1150. void RacquetSensor::cbInvalidSerial_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  1151. {
  1152. if(cbInvalidSerial->Checked)
  1153. tbSerialNumber->Enabled = false;
  1154. else
  1155. tbSerialNumber->Enabled = true;
  1156. }
  1157. void RacquetSensor::timerSession_Tick(System::Object ^sender, System::Timers::ElapsedEventArgs ^e)
  1158. {
  1159. time += 1;
  1160. TimeSpan t = TimeSpan::FromSeconds(time);
  1161. //If an error C2227 comes up here, it's probably because something was changed in the designer
  1162. // and this label needs to be declared as static.
  1163. // find where it is declared in RacquetSensor.h
  1164. // where it says public: System::Windows::Forms::Label^ lbSessionTime;
  1165. // change it to public: static System::Windows::Forms::Label^ lbSessionTime;
  1166. // This will get ride of the error
  1167. lbSessionTime->Text = System::String::Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds);
  1168. }
  1169. void RacquetSensor::checkMpS_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  1170. {
  1171. if(checkMpS->Checked)
  1172. {
  1173. Decimal kmphValue = valueSpeed->Value;
  1174. valueSpeed->DecimalPlaces = 2;
  1175. valueSpeed->Maximum = (Decimal)(655.34);
  1176. valueSpeed->Increment = (Decimal)(0.01);
  1177. valueSpeed->Value = Math::Round((kmphValue) * (Decimal)((Decimal)10/(Decimal)36), 2, System::MidpointRounding::AwayFromZero);
  1178. }
  1179. else
  1180. {
  1181. Decimal mpsValue = valueSpeed->Value;
  1182. valueSpeed->DecimalPlaces = 3;
  1183. valueSpeed->Maximum = (Decimal)(655.34 * 36/10);
  1184. valueSpeed->Increment = (Decimal)0.001;
  1185. valueSpeed->Value = Math::Round(((mpsValue) * (Decimal)((Decimal)36/(Decimal)10)), 3, System::MidpointRounding::AwayFromZero);
  1186. }
  1187. }
  1188. void RacquetSensor::checkANTFS_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  1189. {
  1190. if(checkANTFS->Checked)
  1191. {
  1192. RacquetData->ucANTFS = 1;
  1193. }
  1194. else
  1195. {
  1196. RacquetData->ucANTFS = 0;
  1197. }
  1198. }
  1199. void RacquetSensor::comboBoxBatStatus_SelectedIndexChanged(System::Object ^sender, System::EventArgs ^e)
  1200. {
  1201. if(comboBoxBatStatus->Text == "New")
  1202. Common->eBatStatus = CommonData::BatStatus::NEW;
  1203. if(comboBoxBatStatus->Text == "Good")
  1204. Common->eBatStatus = CommonData::BatStatus::GOOD;
  1205. if(comboBoxBatStatus->Text == "Ok")
  1206. Common->eBatStatus = CommonData::BatStatus::OK;
  1207. if(comboBoxBatStatus->Text == "Low")
  1208. Common->eBatStatus = CommonData::BatStatus::LOW;
  1209. if(comboBoxBatStatus->Text == "Critical")
  1210. Common->eBatStatus = CommonData::BatStatus::CRITICAL;
  1211. if(comboBoxBatStatus->Text == "Invalid")
  1212. Common->eBatStatus = CommonData::BatStatus::INVALID;
  1213. }
  1214. void RacquetSensor::checkBox_Bat_Voltage_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  1215. {
  1216. if(checkBox_Bat_Voltage->Checked)
  1217. {
  1218. numericCoarseVoltage->Enabled = false;
  1219. numericFractionalVoltage->Enabled = false;
  1220. Common->usBatVoltage256 = CommonData::BATTERY_VOLTAGE_INVALID;
  1221. }
  1222. else
  1223. {
  1224. numericCoarseVoltage->Enabled = true;
  1225. numericFractionalVoltage->Enabled = true;
  1226. Common->usBatVoltage256 = ((USHORT)System::Convert::ToByte(numericCoarseVoltage->Value)) << 8 | (Common->usBatVoltage256 & 0xFF);
  1227. Common->usBatVoltage256 = System::Convert::ToByte(numericFractionalVoltage->Value) | (Common->usBatVoltage256 & 0xFF00);
  1228. }
  1229. }
  1230. void RacquetSensor::numericCoarseVoltage_ValueChanged(System::Object ^sender, System::EventArgs ^e)
  1231. {
  1232. Common->usBatVoltage256 = ((USHORT)System::Convert::ToByte(numericCoarseVoltage->Value)) << 8 | (Common->usBatVoltage256 & 0xFF);
  1233. }
  1234. void RacquetSensor::numericFractionalVoltage_ValueChanged(System::Object ^sender, System::EventArgs ^e)
  1235. {
  1236. Common->usBatVoltage256 = System::Convert::ToByte(numericFractionalVoltage->Value) | (Common->usBatVoltage256 & 0xFF00);
  1237. }
  1238. void RacquetSensor::radioResolution2_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  1239. {
  1240. if(radioResolution2->Checked)
  1241. Common->eTimeResolution = CommonData::TimeResolution::TWO;
  1242. else
  1243. Common->eTimeResolution = CommonData::TimeResolution::SIXTEEN;
  1244. }
  1245. void RacquetSensor::buttonUpdateTime_Click(System::Object ^sender, System::EventArgs ^e)
  1246. {
  1247. labelTimeError->Visible = false;
  1248. try
  1249. {
  1250. ulTotalTime = System::Convert::ToUInt32(textBoxTime->Text);
  1251. }
  1252. catch (...)
  1253. {
  1254. labelTimeError->Visible = true;
  1255. return;
  1256. }
  1257. Common->ulOpTime = ulTotalTime / (UCHAR)Common->eTimeResolution;
  1258. }