2
0

LEVDisplay.cpp 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  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. #pragma once
  9. #include "StdAfx.h"
  10. #include "LEVDisplay.h"
  11. /**************************************************************************
  12. * LEVDisplay::InitializeSim
  13. *
  14. * Initialize the simulator variables
  15. *
  16. * returns: N/A
  17. *
  18. **************************************************************************/
  19. void LEVDisplay::InitializeSim()
  20. {
  21. dbDispAcumDist = 0;
  22. bPage16Enabled = TRUE;
  23. ucAckRetryCount = 0;
  24. ucMsgExpectingAck = 0;
  25. ucRxMsgCount = 0;
  26. ucDisplaySupportedAssist = 7;
  27. ucDisplaySupportedRegen = 7;
  28. // inialize values to match UI
  29. LEVData->usP16ManID = (System::Convert::ToUInt16(this->numericUpDown_P16ManID->Value));
  30. LEVData->usP16WheelCircum = (System::Convert::ToUInt16(this->numericUpDown_P16Circum->Value));
  31. LEVData->usP16WheelCircum |= 0xF000;
  32. LEVData->ucP70TxTimes = System::Convert::ToByte(this->numericUpDown_RqTxTimes->Value);
  33. LEVData->ucP70RequestedPage = LEVData->PAGE1_SPEED_SYSTEM1;
  34. //LEVData->usP16DisplayCommand = 0;
  35. LEVData->ucP16TravelMode = 0;
  36. // required common pages
  37. commonDataDisplay->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNum->Text);
  38. commonDataDisplay->ucSwVersion = System::Convert::ToByte(this->textBox_SwVersion->Text);
  39. commonDataDisplay->ucHwVersion = System::Convert::ToByte(this->textBox_HwVersion->Text);
  40. commonDataDisplay->usMfgID = System::Convert::ToUInt16(this->textBox_MfgID->Text);
  41. commonDataDisplay->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNum->Text);
  42. }
  43. /**************************************************************************
  44. * LEVDisplay::ANT_eventNotification
  45. *
  46. * Process ANT channel event
  47. *
  48. * ucEventCode_: code of ANT channel event
  49. * pucEventBuffer_: pointer to buffer containing data received from ANT,
  50. * or a pointer to the transmit buffer in the case of an EVENT_TX
  51. *
  52. * returns: N/A
  53. *
  54. **************************************************************************/
  55. void LEVDisplay::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
  56. {
  57. UCHAR ucPageNum = pucEventBuffer_[0];
  58. switch(ucEventCode_)
  59. {
  60. case EVENT_RX_ACKNOWLEDGED:
  61. case EVENT_RX_BURST_PACKET: // intentional fall thru
  62. case EVENT_RX_BROADCAST:
  63. // check if this is common page or LEV page
  64. if (ucPageNum < commonDataSensor->START_COMMON_PAGE)
  65. LEVData->Decode(pucEventBuffer_);
  66. else
  67. commonDataSensor->Decode(pucEventBuffer_);
  68. // update the UI
  69. UpdateDisplay(ucPageNum);
  70. // the first time we receive a page we want to send a common page back
  71. if (ucRxMsgCount == 0)
  72. TransmitCommonPage();
  73. // increment our count every time we receive a page
  74. ucRxMsgCount++;
  75. if ((ucRxMsgCount > 19) && (ucMsgExpectingAck != 0x10))
  76. {
  77. TransmitCommonPage(); // every 20th message, send a common page back
  78. ucRxMsgCount = 1; // reset to 1 so that the about 'first time' is only true once
  79. }
  80. break;
  81. case EVENT_TRANSFER_TX_COMPLETED:
  82. ucAckRetryCount = 0; // Reset retransmission counter
  83. ucMsgExpectingAck = 0; // Clear pending msg code
  84. UpdateDisplayAckStatus(LEVData->ACK_SUCCESS); // Tx successful
  85. break;
  86. case EVENT_TRANSFER_TX_FAILED:
  87. case EVENT_ACK_TIMEOUT: // Intentional fall thru
  88. if(ucMsgExpectingAck)
  89. {
  90. if(HandleRetransmit())
  91. UpdateDisplayAckStatus(LEVData->ACK_RETRY); // Data was retransmitted
  92. else
  93. UpdateDisplayAckStatus(LEVData->ACK_FAIL); // Maximum number of retries exceeded, Tx failed
  94. }
  95. break;
  96. case EVENT_RX_FAIL:
  97. ucRxMsgCount++; // also count the rx fails as messages
  98. break;
  99. default:
  100. break;
  101. }
  102. }
  103. /**************************************************************************
  104. * LEVDisplay::UpdateDisplay
  105. *
  106. * Updates the variables found on the GUI
  107. *
  108. * returns: N/A
  109. *
  110. **************************************************************************/
  111. void LEVDisplay::UpdateDisplay(UCHAR ucPageNum)
  112. {
  113. // update the common P1, P2, and P3 fields if we get any of those
  114. if ((ucPageNum == LEVData->PAGE1_SPEED_SYSTEM1) || (ucPageNum == LEVData->PAGE2_SPEED_DISTANCE)
  115. || (ucPageNum == LEVData->PAGE3_SPEED_SYSTEM2))
  116. {
  117. this->label_P1SpeedValue->Text = (System::Convert::ToDecimal(LEVData->usCurrentLEVSpeed) / 10).ToString("N1") + " km/h"; // speed comes in as 0.1 km / hr so multiply by 10
  118. this->label_P2SpeedVal->Text = (System::Convert::ToDecimal(LEVData->usCurrentLEVSpeed) / 10).ToString("N1"); // speed comes in as 0.1 km / hr so multiply by 10
  119. this->label_P3SpeedVal->Text = (System::Convert::ToDecimal(LEVData->usCurrentLEVSpeed) / 10).ToString("N1") + " km/h"; // speed comes in as 0.1 km / hr so multiply by 10
  120. }
  121. // update the common P1, and P3 fields if we get any of those
  122. if ((ucPageNum == LEVData->PAGE1_SPEED_SYSTEM1) || (ucPageNum == LEVData->PAGE3_SPEED_SYSTEM2))
  123. {
  124. // throttle
  125. if ((LEVData->ucSystemState & 0x10) != 0)
  126. {
  127. this->label_P1ThrottleVal->Text = "Yes";
  128. this->label_P3ThrottleVal->Text = "Yes";
  129. }
  130. else
  131. {
  132. this->label_P1ThrottleVal->Text = "No";
  133. this->label_P3ThrottleVal->Text = "No";
  134. }
  135. if ((LEVData->ucSystemState & 0x08) != 0)
  136. {
  137. this->label_P1LightValue->Text = "Light On";
  138. this->label_P3LightVal->Text = "Light On";
  139. }
  140. else
  141. {
  142. this->label_P1LightValue->Text = "Light Off";
  143. this->label_P3LightVal->Text = "Light Off";
  144. }
  145. if ((LEVData->ucSystemState & 0x04) != 0)
  146. {
  147. this->label_P1BeamValue->Text = "High Beam";
  148. this->label_P3BeamVal->Text = "High Beam";
  149. }
  150. else
  151. {
  152. this->label_P1BeamValue->Text = "Low Beam";
  153. this->label_P3BeamVal->Text = "Low Beam";
  154. }
  155. if ((LEVData->ucSystemState & 0x02) != 0)
  156. {
  157. this->label_P1LeftValue->Text = "On";
  158. this->label_P3LeftVal->Text = "On";
  159. }
  160. else
  161. {
  162. this->label_P1LeftValue->Text = "Off";
  163. this->label_P3LeftVal->Text = "Off";
  164. }
  165. if ((LEVData->ucSystemState & 0x01) != 0)
  166. {
  167. this->label_P1RightValue->Text = "On";
  168. this->label_P3RightVal->Text = "On";
  169. }
  170. else
  171. {
  172. this->label_P1RightValue->Text = "Off";
  173. this->label_P3RightVal->Text = "Off";
  174. }
  175. // clear everything but bits 3-5, then shift down to get current assist level
  176. if (((LEVData->ucTravelModeState & 0x38) >> 3) == 0)
  177. {
  178. this->label_P1AssistLevelVal->Text = "Off";
  179. this->label_P3AssistLvlVal->Text = "Off";
  180. }
  181. else
  182. MapAssistMode();
  183. // clear everything but bits 0-2 to get current regen level
  184. if ((LEVData->ucTravelModeState & 0x07) == 0)
  185. {
  186. this->label_P1RegenLevelVal->Text = "Off";
  187. this->label_P3RegenVal->Text = "Off";
  188. }
  189. else
  190. MapRegenMode();
  191. // gear exists
  192. if ((LEVData->ucGearState & 0x80) != 0)
  193. {
  194. this->label_P1GearExistVal->Text = "Yes";
  195. this->label_P3GearsExistVal->Text = "Yes";
  196. }
  197. else
  198. {
  199. this->label_P1GearExistVal->Text = "No";
  200. this->label_P3GearsExistVal->Text = "No";
  201. }
  202. // gear manual or auto
  203. if ((LEVData->ucGearState & 0x40) != 0)
  204. {
  205. this->label_P1ManAutoVal->Text = "Man";
  206. this->label_P3ManAutoVal->Text = "Man";
  207. }
  208. else
  209. {
  210. this->label_P1ManAutoVal->Text = "Auto";
  211. this->label_P3ManAutoVal->Text = "Auto";
  212. }
  213. // clear everything but bits 2-5, then shift down to get rear gear setting
  214. if (((LEVData->ucGearState & 0x3C) >> 2) == 0)
  215. {
  216. this->label_P1RearGearVal->Text = "None";
  217. this->label_P3RearGearVal->Text = "None";
  218. }
  219. else
  220. {
  221. this->label_P1RearGearVal->Text = ((LEVData->ucGearState & 0x3C) >> 2).ToString();
  222. this->label_P3RearGearVal->Text = ((LEVData->ucGearState & 0x3C) >> 2).ToString();
  223. }
  224. // clear everything but bits 0-1 to get front gear setting
  225. if ((LEVData->ucGearState & 0x03) == 0)
  226. {
  227. this->label_P1FrontGearVal->Text = "None";
  228. this->label_P3FrontGearVal->Text = "None";
  229. }
  230. else
  231. {
  232. this->label_P1FrontGearVal->Text = (LEVData->ucGearState & 0x03).ToString();
  233. this->label_P3FrontGearVal->Text = (LEVData->ucGearState & 0x03).ToString();
  234. }
  235. }
  236. //*****************************
  237. // Decode Page 1
  238. //*****************************
  239. if (ucPageNum == LEVData->PAGE1_SPEED_SYSTEM1)
  240. {
  241. if ((LEVData->ucTemperature & 0x80) != 0) // if bit 7 is high...
  242. this->label_P1MotorAlertVal->Text = "Overheating";
  243. else
  244. this->label_P1MotorAlertVal->Text = "No Alert";
  245. if ((LEVData->ucTemperature & 0x08) != 0) // if bit 3 is high...
  246. this->label_P1BattAlertVal->Text = "Overheating";
  247. else
  248. this->label_P1BattAlertVal->Text = "No Alert";
  249. // clear everything but bits 0-2 to get battery temp
  250. if ((LEVData->ucTemperature & 0x07) == 0)
  251. this->label_P1BattTempVal->Text = "Unknown";
  252. else if ((LEVData->ucTemperature & 0x07) == 1)
  253. this->label_P1BattTempVal->Text = "Cold";
  254. else if ((LEVData->ucTemperature & 0x07) == 2)
  255. this->label_P1BattTempVal->Text = "Cold/Warm";
  256. else if ((LEVData->ucTemperature & 0x07) == 3)
  257. this->label_P1BattTempVal->Text = "Warm";
  258. else if ((LEVData->ucTemperature & 0x07) == 4)
  259. this->label_P1BattTempVal->Text = "Warm/Hot";
  260. else if ((LEVData->ucTemperature & 0x07) == 5)
  261. this->label_P1BattTempVal->Text = "Hot";
  262. // clear everything but bits 4-6, then shift down to get motor temp
  263. if (((LEVData->ucTemperature & 0x70) >> 4) == 0)
  264. this->label_P1MotorTempVal->Text = "Unknown";
  265. else if (((LEVData->ucTemperature & 0x70) >> 4) == 1)
  266. this->label_P1MotorTempVal->Text = "Cold";
  267. else if (((LEVData->ucTemperature & 0x70) >> 4) == 2)
  268. this->label_P1MotorTempVal->Text = "Cold/Warm";
  269. else if (((LEVData->ucTemperature & 0x70) >> 4) == 3)
  270. this->label_P1MotorTempVal->Text = "Warm";
  271. else if (((LEVData->ucTemperature & 0x70) >> 4) == 4)
  272. this->label_P1MotorTempVal->Text = "Warm/Hot";
  273. else if (((LEVData->ucTemperature & 0x70) >> 4) == 5)
  274. this->label_P1MotorTempVal->Text = "Hot";
  275. switch (LEVData->ucErrorMessage)
  276. {
  277. case 0:
  278. this->label_P1ErrorValue->Text = "0: No Error";
  279. break;
  280. case 1:
  281. this->label_P1ErrorValue->Text = "1: Batt Error";
  282. break;
  283. case 2:
  284. this->label_P1ErrorValue->Text = "2: Train Error";
  285. break;
  286. case 3:
  287. this->label_P1ErrorValue->Text = "3: Batt EOL";
  288. break;
  289. case 4:
  290. this->label_P1ErrorValue->Text = "4: Overheat";
  291. break;
  292. default:
  293. if (LEVData->ucErrorMessage > 15)
  294. this->label_P1ErrorValue->Text = LEVData->ucErrorMessage.ToString() + ": Custom";
  295. else
  296. this->label_P1ErrorValue->Text = "Invalid Code";
  297. }
  298. }
  299. //*****************************
  300. // Decode Page 2
  301. //*****************************
  302. else if (ucPageNum == LEVData->PAGE2_SPEED_DISTANCE)
  303. {
  304. this->label_P2OdometerVal->Text = ((float)(LEVData->ulOdometer) / 100).ToString("N2");
  305. if (LEVData->usRemainingRange == 0)
  306. this->label_P2RangeVal->Text = "Unused";
  307. else
  308. this->label_P2RangeVal->Text = LEVData->usRemainingRange.ToString();
  309. }
  310. //*****************************
  311. // Decode Page 3
  312. //*****************************
  313. else if (ucPageNum == LEVData->PAGE3_SPEED_SYSTEM2)
  314. {
  315. this->label_P3PercentAssistVal->Text = LEVData->ucPercentAssist.ToString() + "%";
  316. if ((LEVData->ucBatteryCharge & 0x80) != 0) // check if bit 7 high
  317. {
  318. this->label_P3BattEmptyVal->Text = "On";
  319. this->label_P3ChargeVal->Text = (LEVData->ucBatteryCharge ^ 0x80).ToString() + "%";
  320. }
  321. else
  322. {
  323. this->label_P3BattEmptyVal->Text = "Off";
  324. this->label_P3ChargeVal->Text = LEVData->ucBatteryCharge.ToString() + "%";
  325. }
  326. }
  327. //*****************************
  328. // Decode Page 4
  329. //*****************************
  330. else if (ucPageNum == LEVData->PAGE4_BATTERY)
  331. {
  332. if (LEVData->ucBatteryVoltage == 0)
  333. this->label_P4VoltageVal->Text = "Unused";
  334. else
  335. this->label_P4VoltageVal->Text = LEVData->ucBatteryVoltage.ToString();
  336. if ((LEVData->usChargeCycleCount & 0x0FFF) == 0)
  337. this->label_P4ChargeCycleVal->Text = "Unused";
  338. else
  339. this->label_P4ChargeCycleVal->Text = LEVData->usChargeCycleCount.ToString();
  340. if (LEVData->usFuelConsumption == 0)
  341. this->label_P4FuelVal->Text = "Unused";
  342. else
  343. this->label_P4FuelVal->Text = (System::Convert::ToDecimal(LEVData->usFuelConsumption) / 10).ToString("N1") + " Wh/km"; // fuel comes in as 0.1 km / hr so multiply by 10
  344. if (LEVData->usDistanceOnCharge == 0)
  345. this->label_P4DistanceChargeVal->Text = "Unused";
  346. else
  347. this->label_P4DistanceChargeVal->Text = (System::Convert::ToDecimal(LEVData->usDistanceOnCharge) / 10).ToString("N1") + " km"; // dist on charge comes in as 0.1 km / hr so multiply by 10
  348. }
  349. //*****************************
  350. // Decode Page 5
  351. //*****************************
  352. else if (ucPageNum == LEVData->PAGE5_CAPABILITES)
  353. {
  354. // clear everything but bits 3-5, then shift down to get assist modes
  355. this->label_P5NumAssistVal->Text = ((LEVData->ucSupportedTravelModes & 0x38) >> 3).ToString();
  356. // clear everything but bits 0-2 to get regen modes
  357. this->label_P5NumRegenVal->Text = (LEVData->ucSupportedTravelModes & 0x07).ToString();
  358. if(LEVData->usWheelCircumference == 0x00)
  359. this->label_P5CircumVal->Text = "Unused";
  360. else
  361. this->label_P5CircumVal->Text = LEVData->usWheelCircumference.ToString();
  362. }
  363. else if(ucPageNum == LEVData->PAGE34_SPEED_DISTANCE)
  364. {
  365. this->label_P2OdometerVal->Text = ((float)(LEVData->ulP34Odometer) / 100).ToString("N2");
  366. if(LEVData->usP34FuelConsumption == 0x00)
  367. {
  368. this->label_P34FuelValue->Text = "Unused";
  369. this->label_P4FuelVal->Text = "Unused";
  370. }
  371. else
  372. {
  373. this->label_P34FuelValue->Text = (System::Convert::ToDecimal(LEVData->usP34FuelConsumption / 10).ToString("N1"));
  374. this->label_P4FuelVal->Text = (System::Convert::ToDecimal(LEVData->usFuelConsumption) / 10).ToString("N1") + " Wh/km"; // fuel comes in as 0.1 km / hr so multiply by 10
  375. }
  376. this->label_P2SpeedVal->Text = (System::Convert::ToDecimal(LEVData->usCurrentLEVSpeed) / 10).ToString("N1");
  377. }
  378. // update the values for the HW common data page
  379. if (commonDataSensor->usMfgID != 0)
  380. {
  381. this->label_Glb_ManfIDDisplay->Text = commonDataSensor->usMfgID.ToString();
  382. this->label_Glb_HardwareVerDisplay->Text = commonDataSensor->ucHwVersion.ToString();
  383. this->label_Glb_ModelNumDisplay->Text = commonDataSensor->usModelNum.ToString();
  384. }
  385. // update the values for the SW common data page
  386. if (commonDataSensor->ulSerialNum != 0)
  387. {
  388. if(commonDataSensor->ulSerialNum == 0xFFFFFFFF)
  389. this->label_Glb_SerialNumDisplay->Text = "N/A";
  390. else
  391. this->label_Glb_SerialNumDisplay->Text = commonDataSensor->ulSerialNum.ToString();
  392. this->label_Glb_SoftwareVerDisplay->Text = commonDataSensor->ucSwVersion.ToString();
  393. }
  394. // the tx variables will show the raw transmitted data decoded, but not scaled into proper units
  395. this->label_StatusSpeedVal->Text = LEVData->usCurrentLEVSpeed.ToString();
  396. this->label_StatusOdoVal->Text = LEVData->ulOdometer.ToString();
  397. this->label_StatusAssistVal->Text = LEVData->ucPercentAssist.ToString();
  398. }
  399. void LEVDisplay::MapAssistMode()
  400. {
  401. UCHAR AssistMode = ((LEVData->ucTravelModeState & 0x38) >> 3);
  402. if(ucDisplaySupportedAssist == 1) // Display supports 1 Assist Mode
  403. {
  404. this->label_P1AssistLevelVal->Text = "7";
  405. this->label_P3AssistLvlVal->Text = "7";
  406. }
  407. else if(ucDisplaySupportedAssist == 2) // Display supports 2 Assist Modes
  408. {
  409. if(AssistMode == 1 || AssistMode == 2 || AssistMode == 3) // map requested assist modes 1,2,3 to Display assist mode 3
  410. {
  411. this->label_P1AssistLevelVal->Text = "3";
  412. this->label_P3AssistLvlVal->Text = "3";
  413. }
  414. else // map requested assist modes 4,5,6,7 to Display assist mode 7
  415. {
  416. this->label_P1AssistLevelVal->Text = "7";
  417. this->label_P3AssistLvlVal->Text = "7";
  418. }
  419. }
  420. else if(ucDisplaySupportedAssist == 3) // Display supports 3 Assist Modes
  421. {
  422. if(AssistMode == 1 || AssistMode == 2) // map requeseted assist modes 1,2 to Display assist mode 2
  423. {
  424. this->label_P1AssistLevelVal->Text = "2";
  425. this->label_P3AssistLvlVal->Text = "2";
  426. }
  427. else if(AssistMode == 3 || AssistMode == 4) // map requested assist modes 3,4 to Display assist mode 4
  428. {
  429. this->label_P1AssistLevelVal->Text = "4";
  430. this->label_P3AssistLvlVal->Text = "4";
  431. }
  432. else // map requested assist modes 5,6,7 to Display assist mode 7
  433. {
  434. this->label_P1AssistLevelVal->Text = "7";
  435. this->label_P3AssistLvlVal->Text = "7";
  436. }
  437. }
  438. else if(ucDisplaySupportedAssist == 4) // Display supports 4 Assist Modes
  439. {
  440. if(AssistMode == 1) // No mapping required for incoming assist mode 1
  441. {
  442. this->label_P1AssistLevelVal->Text = "1";
  443. this->label_P3AssistLvlVal->Text = "1";
  444. }
  445. else if(AssistMode == 2 || AssistMode == 3) // map incoming assist modes 2,3 to Display assist mode 3
  446. {
  447. this->label_P1AssistLevelVal->Text = "3";
  448. this->label_P3AssistLvlVal->Text = "3";
  449. }
  450. else if(AssistMode == 4 || AssistMode == 5) // map incoming assist modes 4, 5 to Display assist mode 5
  451. {
  452. this->label_P1AssistLevelVal->Text = "5";
  453. this->label_P3AssistLvlVal->Text = "5";
  454. }
  455. else // map incoming assist modes 6,7 to Display assist mode 7
  456. {
  457. this->label_P1AssistLevelVal->Text = "7";
  458. this->label_P3AssistLvlVal->Text = "7";
  459. }
  460. }
  461. else if(ucDisplaySupportedAssist == 5) // Display supports 5 Assist Modes
  462. {
  463. if(AssistMode == 1 || AssistMode == 2 || AssistMode == 3) // No mapping required for incoming assist modes 1,2,3
  464. {
  465. this->label_P1AssistLevelVal->Text = ((LEVData->ucTravelModeState & 0x38) >> 3).ToString();
  466. this->label_P3AssistLvlVal->Text = ((LEVData->ucTravelModeState & 0x38) >> 3).ToString();
  467. }
  468. else if(AssistMode == 4 || AssistMode == 5) // map incoming assist modes 4,5 to Display assist mode 5
  469. {
  470. this->label_P1AssistLevelVal->Text = "5";
  471. this->label_P3AssistLvlVal->Text = "5";
  472. }
  473. else // map incoming assist modes 6,7 to Display assist mode 7
  474. {
  475. this->label_P1AssistLevelVal->Text = "7";
  476. this->label_P3AssistLvlVal->Text = "7";
  477. }
  478. }
  479. else if(ucDisplaySupportedAssist == 6) // Display supports 6 Assist Modes
  480. {
  481. if(AssistMode == 1 || AssistMode == 2 || AssistMode == 3 || AssistMode == 4 || AssistMode == 5) // No mapping required for incoming assist modes 1,2,3,4,5
  482. {
  483. this->label_P1AssistLevelVal->Text = ((LEVData->ucTravelModeState & 0x38) >> 3).ToString();
  484. this->label_P3AssistLvlVal->Text = ((LEVData->ucTravelModeState & 0x38) >> 3).ToString();
  485. }
  486. else // map incoming assist modes 6,7 to assist mode 7
  487. {
  488. this->label_P1AssistLevelVal->Text = "7";
  489. this->label_P3AssistLvlVal->Text = "7";
  490. }
  491. }
  492. else // No mapping required if all assist modes are supported
  493. {
  494. this->label_P1AssistLevelVal->Text = ((LEVData->ucTravelModeState & 0x38) >> 3).ToString();
  495. this->label_P3AssistLvlVal->Text = ((LEVData->ucTravelModeState & 0x38) >> 3).ToString();
  496. }
  497. }
  498. void LEVDisplay::MapRegenMode()
  499. {
  500. UCHAR RegenMode = (LEVData->ucTravelModeState & 0x07);
  501. if(ucDisplaySupportedRegen == 0) // Display does not support Regen Modes
  502. {
  503. this->label_P1RegenLevelVal->Text = "Off";
  504. this->label_P3RegenVal->Text = "Off";
  505. }
  506. else if(ucDisplaySupportedRegen == 1) // Display supports 1 Regen Mode
  507. {
  508. this->label_P1RegenLevelVal->Text = "7";
  509. this->label_P3RegenVal->Text = "7";
  510. }
  511. else if(ucDisplaySupportedRegen == 2) // Display supports 2 Regen Modes
  512. {
  513. if(RegenMode == 1 || RegenMode == 2 || RegenMode == 3) // map requested regen modes 1,2,3 to Display regen mode 3
  514. {
  515. this->label_P1RegenLevelVal->Text = "3";
  516. this->label_P3RegenVal->Text = "3";
  517. }
  518. else // map requested regen modes 4,5,6,7 to Display regen mode 7
  519. {
  520. this->label_P1RegenLevelVal->Text = "7";
  521. this->label_P3RegenVal->Text = "7";
  522. }
  523. }
  524. else if(ucDisplaySupportedRegen == 3) // Display supports 3 Regen Modes
  525. {
  526. if(RegenMode == 1 || RegenMode == 2) // map requeseted regen modes 1,2 to Display regen mode 2
  527. {
  528. this->label_P1RegenLevelVal->Text = "2";
  529. this->label_P3RegenVal->Text = "2";
  530. }
  531. else if(RegenMode == 3 || RegenMode == 4) // map requested regen modes 3,4 to Display regen mode 4
  532. {
  533. this->label_P1RegenLevelVal->Text = "4";
  534. this->label_P3RegenVal->Text = "4";
  535. }
  536. else // map requested regen modes 5,6,7 to Display regen mode 7
  537. {
  538. this->label_P1RegenLevelVal->Text = "7";
  539. this->label_P3RegenVal->Text = "7";
  540. }
  541. }
  542. else if(ucDisplaySupportedRegen == 4) // Display supports 4 Regen Modes
  543. {
  544. if(RegenMode == 1) // No mapping required for incoming regen mode 1
  545. {
  546. this->label_P1RegenLevelVal->Text = "1";
  547. this->label_P3RegenVal->Text = "1";
  548. }
  549. else if(RegenMode == 2 || RegenMode == 3) // map incoming regen modes 2,3 to Display regen mode 3
  550. {
  551. this->label_P1RegenLevelVal->Text = "3";
  552. this->label_P3RegenVal->Text = "3";
  553. }
  554. else if(RegenMode == 4 || RegenMode == 5) // map incoming regen modes 4, 5 to Display regen mode 5
  555. {
  556. this->label_P1RegenLevelVal->Text = "5";
  557. this->label_P3RegenVal->Text = "5";
  558. }
  559. else // map incoming regen modes 6,7 to Display regen mode 7
  560. {
  561. this->label_P1RegenLevelVal->Text = "7";
  562. this->label_P3RegenVal->Text = "7";
  563. }
  564. }
  565. else if(ucDisplaySupportedRegen == 5) // Display supports 5 Regen Modes
  566. {
  567. if(RegenMode == 1 || RegenMode == 2 || RegenMode == 3) // No mapping required for incoming regen modes 1,2,3
  568. {
  569. this->label_P1RegenLevelVal->Text = (LEVData->ucTravelModeState & 0x07).ToString();
  570. this->label_P3RegenVal->Text = (LEVData->ucTravelModeState & 0x07).ToString();
  571. }
  572. else if(RegenMode == 4 || RegenMode == 5) // map incoming regen modes 4,5 to Display regen mode 5
  573. {
  574. this->label_P1RegenLevelVal->Text = "5";
  575. this->label_P3RegenVal->Text = "5";
  576. }
  577. else // map incoming regen modes 6,7 to Display regen mode 7
  578. {
  579. this->label_P1RegenLevelVal->Text = "7";
  580. this->label_P3RegenVal->Text = "7";
  581. }
  582. }
  583. else if(ucDisplaySupportedRegen == 6) // Display supports 6 Regen Modes
  584. {
  585. if(RegenMode == 1 || RegenMode == 2 || RegenMode == 3 || RegenMode == 4 || RegenMode == 5) // No mapping required for incoming regen modes 1,2,3,4,5
  586. {
  587. this->label_P1RegenLevelVal->Text = (LEVData->ucTravelModeState & 0x07).ToString();
  588. this->label_P3RegenVal->Text = (LEVData->ucTravelModeState & 0x07).ToString();
  589. }
  590. else // map incoming regen modes 6,7 to regen mode 7
  591. {
  592. this->label_P1RegenLevelVal->Text = "7";
  593. this->label_P3RegenVal->Text = "7";
  594. }
  595. }
  596. else // No mapping required if all regen modes are supported
  597. {
  598. this->label_P1RegenLevelVal->Text = (LEVData->ucTravelModeState & 0x07).ToString();
  599. this->label_P3RegenVal->Text = (LEVData->ucTravelModeState & 0x07).ToString();
  600. }
  601. }
  602. /**************************************************************************
  603. * LEVDisplay::checkBox_P16TravelModeNotSupported_CheckedChanged
  604. *
  605. * Enables or Disables the Travel Mode field in Page 16
  606. *
  607. * returns: N/A
  608. *
  609. **************************************************************************/
  610. void LEVDisplay::checkBox_P16TravelModeNotSupported_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  611. {
  612. if (this->checkBox_P16TravelModeNotSupported->Checked == TRUE)
  613. {
  614. LEVData->ucP16TravelMode = 0xFF; // 0xFF = not supported
  615. this->comboBox_P16Assist->Enabled = FALSE;
  616. this->comboBox_P16Regen->Enabled = FALSE;
  617. }
  618. else
  619. {
  620. LEVData->ucP16TravelMode = LEVData->ucP16TravelMode & 0x3F; // Clear bits 6 and 7
  621. this->comboBox_P16Assist->Enabled = TRUE;
  622. this->comboBox_P16Regen->Enabled = TRUE;
  623. UpdateAssistMode(); // refresh values in the ucP16TravelMode variable
  624. UpdateRegenMode();
  625. }
  626. }
  627. /**************************************************************************
  628. * LEVDisplay::comboBox_P16Assist_SelectedIndexChanged
  629. *
  630. * Updates the user selected Assist Level to send to the sensor
  631. *
  632. * returns: N/A
  633. *
  634. **************************************************************************/
  635. void LEVDisplay::comboBox_P16Assist_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  636. {
  637. CheckAssistMapping();
  638. }
  639. /**************************************************************************
  640. * LEVDisplay::CheckAssistMapping
  641. *
  642. * Make sure the selected Assist Level is consistent with the supported
  643. * assist levels
  644. *
  645. * returns: N/A
  646. *
  647. **************************************************************************/
  648. void LEVDisplay::CheckAssistMapping()
  649. {
  650. UCHAR CurrentAssist = (this->LEVData->ucP16TravelMode & 0x38) >> 3;
  651. // if Assist Off is selected, set the assist level to 000
  652. if(this->comboBox_P16Assist->Text->Equals("Assist Off"))
  653. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  654. else if(ucDisplaySupportedAssist == 7)
  655. UpdateAssistMode();
  656. else
  657. {
  658. // switch number of supported assist modes
  659. switch(ucDisplaySupportedAssist)
  660. {
  661. case 0x01: // 1 assist modes supported, selecting "Assist 7" acceptable
  662. // if anything other than "Assist Off" is selected, Send a messagebox with an error message
  663. if(!(this->comboBox_P16Assist->Text->Equals("Assist 7")))
  664. {
  665. MessageBox::Show("The Display supports 1 Assist Mode. Please select Assist 7 or Off");
  666. switch(CurrentAssist)
  667. {
  668. case 0x07:
  669. this->comboBox_P16Assist->Text = "Assist 7";
  670. break;
  671. default:
  672. this->comboBox_P16Assist->Text = "Assist Off";
  673. break;
  674. }
  675. }
  676. // if "Assist Off" was selected, it would have been caught in the above if statement
  677. else
  678. UpdateAssistMode();
  679. break;
  680. case 0x02: // 2 assist modes supported, selecting "Assist 3" or "Assist 7" acceptable
  681. // if anything other than "Assist 3" or "Assist 7" is selected, send messagebox with error message
  682. if(!((this->comboBox_P16Assist->Text->Equals("Assist 3")) || (this->comboBox_P16Assist->Text->Equals("Assist 7"))))
  683. {
  684. MessageBox::Show("The Display supports 2 Assist Modes. Please select Assist 3, 7 or Off");
  685. switch(CurrentAssist)
  686. {
  687. case 0x03:
  688. this->comboBox_P16Assist->Text = "Assist 3";
  689. break;
  690. case 0x07:
  691. this->comboBox_P16Assist->Text = "Assist 7";
  692. break;
  693. default:
  694. this->comboBox_P16Assist->Text = "Assist Off";
  695. break;
  696. }
  697. }
  698. // if "Assist Off" was selected, it would have been caught in the above if statement
  699. else
  700. UpdateAssistMode();
  701. break;
  702. case 0x03: // 3 Assist modes supported, selecting "Assist 2", "Assist 4" or "Assist 7" acceptable
  703. // if anything other than "Assist 2", "Assist 4", or "Assist 7" is selected, show messagebox with an error message
  704. if(!((this->comboBox_P16Assist->Text->Equals("Assist 2")) || (this->comboBox_P16Assist->Text->Equals("Assist 4")) || (this->comboBox_P16Assist->Text->Equals("Assist 7"))))
  705. {
  706. MessageBox::Show("The Display supports 3 Assist Modes. Please select Assist 2, 4, 7, or Off");
  707. switch(CurrentAssist)
  708. {
  709. case 0x02:
  710. this->comboBox_P16Assist->Text = "Assist 2";
  711. break;
  712. case 0x04:
  713. this->comboBox_P16Assist->Text = "Assist 4";
  714. break;
  715. case 0x07:
  716. this->comboBox_P16Assist->Text = "Assist 7";
  717. break;
  718. default:
  719. this->comboBox_P16Assist->Text = "Assist Off";
  720. break;
  721. }
  722. }
  723. // if "Assist Off" was selected, it would have been caught in the above if statement
  724. else
  725. UpdateAssistMode();
  726. break;
  727. case 0x04: // 4 assist modes supported, selecting "Assist 2", "Assist 4" or "Assist 6" NOT acceptable
  728. // if "Assist 2", "Assist 4" or "Assist 6" selected, show messagebox with error message
  729. if((this->comboBox_P16Assist->Text->Equals("Assist 2")) || (this->comboBox_P16Assist->Text->Equals("Assist 4")) || (this->comboBox_P16Assist->Text->Equals("Assist 6")))
  730. {
  731. MessageBox::Show("The Display supports 4 Assist Modes. Please select Assist 1, 3, 5, 7, or Off");
  732. switch(CurrentAssist)
  733. {
  734. case 0x01:
  735. this->comboBox_P16Assist->Text = "Assist 1";
  736. break;
  737. case 0x03:
  738. this->comboBox_P16Assist->Text = "Assist 3";
  739. break;
  740. case 0x05:
  741. this->comboBox_P16Assist->Text = "Assist 5";
  742. break;
  743. case 0x07:
  744. this->comboBox_P16Assist->Text = "Assist 7";
  745. break;
  746. default:
  747. this->comboBox_P16Assist->Text = "Assist Off";
  748. break;
  749. }
  750. }
  751. // if "Assist Off" selected, it would have been caught in the above if statement
  752. else
  753. UpdateAssistMode();
  754. break;
  755. case 0x05: // 5 assist modes supported, selecting "Assist 4" or "Assist 6" NOT acceptable
  756. // if "Assist 4" or "Assist 6" selected, show messagebox with error message
  757. if((this->comboBox_P16Assist->Text->Equals("Assist 4")) || (this->comboBox_P16Assist->Text->Equals("Assist 6")))
  758. {
  759. MessageBox::Show("The Display supports 5 Assist Modes. Please select Assist 1, 2, 3, 5, 7, or Off");
  760. switch(CurrentAssist)
  761. {
  762. case 0x01:
  763. this->comboBox_P16Assist->Text = "Assist 1";
  764. break;
  765. case 0x02:
  766. this->comboBox_P16Assist->Text = "Assist 2";
  767. break;
  768. case 0x03:
  769. this->comboBox_P16Assist->Text = "Assist 3";
  770. break;
  771. case 0x05:
  772. this->comboBox_P16Assist->Text = "Assist 5";
  773. break;
  774. case 0x07:
  775. this->comboBox_P16Assist->Text = "Assist 7";
  776. break;
  777. default:
  778. this->comboBox_P16Assist->Text = "Assist Off";
  779. break;
  780. }
  781. }
  782. // if "Assist Off" selected, it would have been caught in the above if statement
  783. else
  784. UpdateAssistMode();
  785. break;
  786. case 0x06: // 6 assist modes supported, selecting "Assist 6" NOT acceptable
  787. // if "Assist 6" selected, show messagebox with error message
  788. if((this->comboBox_P16Assist->Text->Equals("Assist 6")))
  789. {
  790. MessageBox::Show("The Display supports 6 Assist Modes. Please select Assist 1, 2,3, 4, 5, 7 or Off");
  791. switch(CurrentAssist)
  792. {
  793. case 0x01:
  794. this->comboBox_P16Assist->Text = "Assist 1";
  795. break;
  796. case 0x02:
  797. this->comboBox_P16Assist->Text = "Assist 2";
  798. break;
  799. case 0x03:
  800. this->comboBox_P16Assist->Text = "Assist 3";
  801. break;
  802. case 0x04:
  803. this->comboBox_P16Assist->Text = "Assist 4";
  804. break;
  805. case 0x05:
  806. this->comboBox_P16Assist->Text = "Assist 5";
  807. break;
  808. case 0x07:
  809. this->comboBox_P16Assist->Text = "Assist 7";
  810. break;
  811. default:
  812. this->comboBox_P16Assist->Text = "Assist Off";
  813. break;
  814. }
  815. }
  816. // if "Assist Off" selected, it would have been caught in the above if statement
  817. else
  818. UpdateAssistMode();
  819. break;
  820. default:
  821. // set Assist mode to off on default
  822. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode& 0xC7);
  823. }
  824. }
  825. }
  826. /**************************************************************************
  827. * LEVDisplay::UpdateAssistMode
  828. *
  829. * Sets the Assist Level, Page 16, Byte 3, bits 3-5
  830. *
  831. * returns: N/A
  832. *
  833. **************************************************************************/
  834. void LEVDisplay::UpdateAssistMode()
  835. {
  836. if (this->comboBox_P16Assist->Text->Equals("Assist 1")) // 001 = Assist 1
  837. {
  838. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7); // clear the bits 3-5 only
  839. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x08); // set bit 3 high
  840. }
  841. else if (this->comboBox_P16Assist->Text->Equals("Assist 2")) // 010 = Assist 2
  842. {
  843. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7); // clear the bits 3-5 only
  844. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x10); // set bit 4 high
  845. }
  846. else if (this->comboBox_P16Assist->Text->Equals("Assist 3")) // 011 = Assist 3
  847. {
  848. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7); // clear the bits 3-5 only
  849. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x18); // set bits 3,4 high
  850. }
  851. else if (this->comboBox_P16Assist->Text->Equals("Assist 4")) // 100 = Assist 4
  852. {
  853. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7); // clear the bits 3-5 only
  854. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x20); // set bit 5 high
  855. }
  856. else if (this->comboBox_P16Assist->Text->Equals("Assist 5")) // 101 = Assist 5
  857. {
  858. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7); // clear the bits 3-5 only
  859. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x28); // set bits 5,3 high
  860. }
  861. else if (this->comboBox_P16Assist->Text->Equals("Assist 6")) // 110 = Assist 6
  862. {
  863. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7); // clear the bits 3-5 only
  864. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x30); // set bits 5,4 high
  865. }
  866. else if (this->comboBox_P16Assist->Text->Equals("Assist 7")) // 111 = Assist 7
  867. {
  868. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7); // clear the bits 3-5 only
  869. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x38); // set bits 5,4,3 high
  870. }
  871. }
  872. /**************************************************************************
  873. * LEVDisplay::comboBox_P16Regen_SelectedIndexChanged
  874. *
  875. * Updates the user selected Current Regen Level
  876. *
  877. * returns: N/A
  878. *
  879. **************************************************************************/
  880. void LEVDisplay::comboBox_P16Regen_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  881. {
  882. CheckRegenMapping();
  883. }
  884. /**************************************************************************
  885. * LEVDisplay::CheckRegenMapping
  886. *
  887. * Make sure the selected Regen Level is consistent with the supported
  888. * regen levels
  889. *
  890. * returns: N/A
  891. *
  892. **************************************************************************/
  893. void LEVDisplay::CheckRegenMapping()
  894. {
  895. UCHAR CurrentRegen = this->LEVData->ucP16TravelMode & 0x07;
  896. // if Regen Off is selected, set the regen level to 000
  897. if(this->comboBox_P16Regen->Text->Equals("Regenerative Off"))
  898. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  899. else if(ucDisplaySupportedRegen == 7)
  900. UpdateRegenMode();
  901. else
  902. {
  903. // switch number of supported regen modes
  904. switch(ucDisplaySupportedRegen)
  905. {
  906. case 0x00:
  907. if((!this->comboBox_P16Regen->Text->Equals("Regenerative Off")))
  908. {
  909. MessageBox::Show("The Display does not support Regenerative Modes. Please select Regenerative Off");
  910. this->comboBox_P16Regen->Text = "Regenerative Off";
  911. }
  912. break;
  913. case 0x01: // 1 regen modes supported, selecting "Regenerative 7" acceptable
  914. // if anything other than "Regenerative Off" is selected, Send a messagebox with an error message
  915. if(!(this->comboBox_P16Regen->Text->Equals("Regenerative 7")))
  916. {
  917. MessageBox::Show("The Display supports 1 Regenerative Mode. Please select Regenerative 7 or Off");
  918. switch(CurrentRegen)
  919. {
  920. case 0x07:
  921. this->comboBox_P16Regen->Text = "Regenerative 7";
  922. break;
  923. default:
  924. this->comboBox_P16Regen->Text = "Regenerative Off";
  925. break;
  926. }
  927. }
  928. // if "Regenerative Off" was selected, it would have been caught in the above if statement
  929. else
  930. UpdateRegenMode();
  931. break;
  932. case 0x02: // 2 regen modes supported, selecting "Regenerative 3" or "Regenerative 7" acceptable
  933. // if anything other than "Regenerative 3" or "Regenerative 7" is selected, send messagebox with error message
  934. if(!((this->comboBox_P16Regen->Text->Equals("Regenerative 3")) || (this->comboBox_P16Regen->Text->Equals("Regenerative 7"))))
  935. {
  936. MessageBox::Show("The Display supports 2 Regenerative Modes. Please select Regenerative 3, 7 or Off");
  937. switch(CurrentRegen)
  938. {
  939. case 0x03:
  940. this->comboBox_P16Regen->Text = "Regenerative 3";
  941. break;
  942. case 0x07:
  943. this->comboBox_P16Regen->Text = "Regenerative 7";
  944. break;
  945. default:
  946. this->comboBox_P16Regen->Text = "Regenerative Off";
  947. break;
  948. }
  949. }
  950. // if "Regenerative Off" was selected, it would have been caught in the above if statement
  951. else
  952. UpdateRegenMode();
  953. break;
  954. case 0x03: // 3 Regenerative modes supported, selecting "Regenerative 2", "Regenerative 4" or "Regenerative 7" acceptable
  955. // if anything other than "Regenerative 2", "Regenerative 4", or "Regenerative 7" is selected, show messagebox with an error message
  956. if(!((this->comboBox_P16Regen->Text->Equals("Regenerative 2")) || (this->comboBox_P16Regen->Text->Equals("Regenerative 4")) || (this->comboBox_P16Regen->Text->Equals("Regenerative 7"))))
  957. {
  958. MessageBox::Show("The Display supports 3 Regenerative Modes. Please select Regenerative 2, 4, 7, or Off");
  959. switch(CurrentRegen)
  960. {
  961. case 0x02:
  962. this->comboBox_P16Regen->Text = "Regenerative 2";
  963. break;
  964. case 0x04:
  965. this->comboBox_P16Regen->Text = "Regenerative 4";
  966. break;
  967. case 0x07:
  968. this->comboBox_P16Regen->Text = "Regenerative 7";
  969. break;
  970. default:
  971. this->comboBox_P16Regen->Text = "Regenerative Off";
  972. break;
  973. }
  974. }
  975. // if "Regenerative Off" was selected, it would have been caught in the above if statement
  976. else
  977. UpdateRegenMode();
  978. break;
  979. case 0x04: // 4 regen modes supported, selecting "Regenerative 2", "Regenerative 4" or "Regenerative 6" NOT acceptable
  980. // if "Regenerative 2", "Regenerative 4" or "Regenerative 6" selected, show messagebox with error message
  981. if((this->comboBox_P16Regen->Text->Equals("Regenerative 2")) || (this->comboBox_P16Regen->Text->Equals("Regenerative 4")) || (this->comboBox_P16Regen->Text->Equals("Regenerative 6")))
  982. {
  983. MessageBox::Show("The Display supports 4 Regenerative Modes. Please select Regenerative 1, 3, 5, 7, or Off");
  984. switch(CurrentRegen)
  985. {
  986. case 0x01:
  987. this->comboBox_P16Regen->Text = "Regenerative 1";
  988. break;
  989. case 0x03:
  990. this->comboBox_P16Regen->Text = "Regenerative 3";
  991. break;
  992. case 0x05:
  993. this->comboBox_P16Regen->Text = "Regenerative 5";
  994. break;
  995. case 0x07:
  996. this->comboBox_P16Regen->Text = "Regenerative 7";
  997. break;
  998. default:
  999. this->comboBox_P16Regen->Text = "Regenerative Off";
  1000. break;
  1001. }
  1002. }
  1003. // if "Regenerative Off" selected, it would have been caught in the above if statement
  1004. else
  1005. UpdateRegenMode();
  1006. break;
  1007. case 0x05: // 5 regen modes supported, selecting "Regenerative 4" or "Regenerative 6" NOT acceptable
  1008. // if "Regenerative 4" or "Regenerative 6" selected, show messagebox with error message
  1009. if((this->comboBox_P16Regen->Text->Equals("Regenerative 4")) || (this->comboBox_P16Regen->Text->Equals("Regenerative 6")))
  1010. {
  1011. MessageBox::Show("The Display supports 5 Regenerative Modes. Please select Regenerative 1, 2, 3, 5, 7, or Off");
  1012. switch(CurrentRegen)
  1013. {
  1014. case 0x01:
  1015. this->comboBox_P16Regen->Text = "Regenerative 1";
  1016. break;
  1017. case 0x02:
  1018. this->comboBox_P16Regen->Text = "Regenerative 2";
  1019. break;
  1020. case 0x03:
  1021. this->comboBox_P16Regen->Text = "Regenerative 3";
  1022. break;
  1023. case 0x05:
  1024. this->comboBox_P16Regen->Text = "Regenerative 5";
  1025. break;
  1026. case 0x07:
  1027. this->comboBox_P16Regen->Text = "Regenerative 7";
  1028. break;
  1029. default:
  1030. this->comboBox_P16Regen->Text = "Regenerative Off";
  1031. break;
  1032. }
  1033. }
  1034. // if "Regenerative Off" selected, it would have been caught in the above if statement
  1035. else
  1036. UpdateRegenMode();
  1037. break;
  1038. case 0x06: // 6 regen modes supported, selecting "Regenerative 6" NOT acceptable
  1039. // if "Regenerative 6" selected, show messagebox with error message
  1040. if((this->comboBox_P16Regen->Text->Equals("Regenerative 6")))
  1041. {
  1042. MessageBox::Show("The Display supports 6 Regenerative Modes. Please select Regenerative 1, 2,3, 4, 5, 7 or Off");
  1043. switch(CurrentRegen)
  1044. {
  1045. case 0x01:
  1046. this->comboBox_P16Regen->Text = "Regenerative 1";
  1047. break;
  1048. case 0x02:
  1049. this->comboBox_P16Regen->Text = "Regenerative 2";
  1050. break;
  1051. case 0x03:
  1052. this->comboBox_P16Regen->Text = "Regenerative 3";
  1053. break;
  1054. case 0x04:
  1055. this->comboBox_P16Regen->Text = "Regenerative 4";
  1056. break;
  1057. case 0x05:
  1058. this->comboBox_P16Regen->Text = "Regenerative 5";
  1059. break;
  1060. case 0x07:
  1061. this->comboBox_P16Regen->Text = "Regenerative 7";
  1062. break;
  1063. default:
  1064. this->comboBox_P16Regen->Text = "Regenerative Off";
  1065. break;
  1066. }
  1067. }
  1068. // if "Regenerative Off" selected, it would have been caught in the above if statement
  1069. else
  1070. UpdateRegenMode();
  1071. break;
  1072. default:
  1073. // set Regen mode to off on default
  1074. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode& 0xF8);
  1075. }
  1076. }
  1077. }
  1078. /**************************************************************************
  1079. * LEVDisplay::UpdateRegenMode
  1080. *
  1081. * Sets the Current Regen Level, Page 16, Byte 3, bits 0-2
  1082. *
  1083. * returns: N/A
  1084. *
  1085. **************************************************************************/
  1086. void LEVDisplay::UpdateRegenMode()
  1087. {
  1088. if (this->comboBox_P16Regen->Text->Equals("Regenerative Off")) // 000 = Regen Off
  1089. {
  1090. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1091. }
  1092. else if (this->comboBox_P16Regen->Text->Equals("Regenerative 1")) // 001 = Regen 1
  1093. {
  1094. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1095. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x01); // set bit 0 high
  1096. }
  1097. else if (this->comboBox_P16Regen->Text->Equals("Regenerative 2")) // 010 = Regen 2
  1098. {
  1099. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1100. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x02); // set bit 1 high
  1101. }
  1102. else if (this->comboBox_P16Regen->Text->Equals("Regenerative 3")) // 011 = Regen 3
  1103. {
  1104. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1105. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x03); // set bits 0,1 high
  1106. }
  1107. else if (this->comboBox_P16Regen->Text->Equals("Regenerative 4")) // 100 = Regen 4
  1108. {
  1109. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1110. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x04); // set bit 2 high
  1111. }
  1112. else if (this->comboBox_P16Regen->Text->Equals("Regenerative 5")) // 101 = Regen 5
  1113. {
  1114. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1115. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x05); // set bits 0,2 high
  1116. }
  1117. else if (this->comboBox_P16Regen->Text->Equals("Regenerative 6")) // 110 = Regen 6
  1118. {
  1119. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1120. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x06); // set bits 2,1 high
  1121. }
  1122. else if (this->comboBox_P16Regen->Text->Equals("Regenerative 7")) // 111 = Regen 7
  1123. {
  1124. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8); // clear the bits 0-2 only
  1125. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x07); // set bits 0,1,2 high
  1126. }
  1127. }
  1128. /**************************************************************************
  1129. * LEVDisplay::comboBox_P16FrontGear_SelectedIndexChanged
  1130. *
  1131. * Updates the user selected Front Gear Setting for P16
  1132. *
  1133. * returns: N/A
  1134. *
  1135. **************************************************************************/
  1136. void LEVDisplay::comboBox_P16FrontGear_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  1137. {
  1138. UpdateFrontGearState();
  1139. }
  1140. /**************************************************************************
  1141. * LEVDisplay::UpdateFrontGearState
  1142. *
  1143. * Sets the P16 Front Gear Setting, Page 16, Byte 4-5, bits 4-5
  1144. *
  1145. * returns: N/A
  1146. *
  1147. **************************************************************************/
  1148. void LEVDisplay::UpdateFrontGearState()
  1149. {
  1150. if (this->comboBox_P16FrontGear->Text->Equals("none")) // 00 = no gear
  1151. {
  1152. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFFCF); // clear the bits 4-5 only
  1153. }
  1154. else if (this->comboBox_P16FrontGear->Text->Equals("1")) // 01 = gear 1
  1155. {
  1156. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFFCF); // clear the bits 4-5 only
  1157. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | 0x10); // set bit 4 high
  1158. }
  1159. else if (this->comboBox_P16FrontGear->Text->Equals("2")) // 10 = gear 2
  1160. {
  1161. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFFCF); // clear the bits 4-5 only
  1162. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | 0x20); // set bit 5 high
  1163. }
  1164. else if (this->comboBox_P16FrontGear->Text->Equals("3")) // 11 = gear 3
  1165. {
  1166. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFFCF); // clear the bits 4-5 only
  1167. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | 0x30); // set bits 4,5 high
  1168. }
  1169. }
  1170. /**************************************************************************
  1171. * LEVDisplay::comboBox_P16RearGear_SelectedIndexChanged
  1172. *
  1173. * Updates the user selected Rear Gear Setting for P16
  1174. *
  1175. * returns: N/A
  1176. *
  1177. **************************************************************************/
  1178. void LEVDisplay::comboBox_P16RearGear_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  1179. {
  1180. UpdateRearGear();
  1181. }
  1182. /**************************************************************************
  1183. * LEVDisplay::UpdateRearGear
  1184. *
  1185. * Sets the Front Rear Setting, Page 16, Byte 4-5, bits 6-9
  1186. *
  1187. * returns: N/A
  1188. *
  1189. **************************************************************************/
  1190. void LEVDisplay::UpdateRearGear()
  1191. {
  1192. if (this->comboBox_P16RearGear->Text->Equals("none")) // 0000 = no gear
  1193. {
  1194. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1195. }
  1196. else if (this->comboBox_P16RearGear->Text->Equals("1")) // 0001 = gear 1
  1197. {
  1198. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1199. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (1 << 6)); // shift value up 6 to get into bits 6-9
  1200. }
  1201. else if (this->comboBox_P16RearGear->Text->Equals("2")) // 0010 = gear 2
  1202. {
  1203. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1204. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (2 << 6)); // shift value up 6 to get into bits 6-9
  1205. }
  1206. else if (this->comboBox_P16RearGear->Text->Equals("3")) // 0011 = gear 3
  1207. {
  1208. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1209. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (3 << 6)); // shift value up 6 to get into bits 6-9
  1210. }
  1211. else if (this->comboBox_P16RearGear->Text->Equals("4")) // 0100 = gear 4
  1212. {
  1213. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1214. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (4 << 6)); // shift value up 6 to get into bits 6-9
  1215. }
  1216. else if (this->comboBox_P16RearGear->Text->Equals("5")) // 0101 = gear 5
  1217. {
  1218. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1219. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (5 << 6)); // shift value up 6 to get into bits 6-9
  1220. }
  1221. else if (this->comboBox_P16RearGear->Text->Equals("6")) // 0110 = gear 6
  1222. {
  1223. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1224. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (6 << 6)); // shift value up 6 to get into bits 6-9
  1225. }
  1226. else if (this->comboBox_P16RearGear->Text->Equals("7")) // 0111 = gear 7
  1227. {
  1228. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1229. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (7 << 6)); // shift value up 6 to get into bits 6-9
  1230. }
  1231. else if (this->comboBox_P16RearGear->Text->Equals("8")) // 1000 = gear 8
  1232. {
  1233. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1234. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (8 << 6)); // shift value up 6 to get into bits 6-9
  1235. }
  1236. else if (this->comboBox_P16RearGear->Text->Equals("9")) // 1001 = gear 9
  1237. {
  1238. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1239. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (9 << 6)); // shift value up 6 to get into bits 6-9
  1240. }
  1241. else if (this->comboBox_P16RearGear->Text->Equals("10")) // 1010 = gear 10
  1242. {
  1243. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1244. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (10 << 6)); // shift value up 6 to get into bits 6-9
  1245. }
  1246. else if (this->comboBox_P16RearGear->Text->Equals("11")) // 1011 = gear 11
  1247. {
  1248. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1249. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (11 << 6)); // shift value up 6 to get into bits 6-9
  1250. }
  1251. else if (this->comboBox_P16RearGear->Text->Equals("12")) // 1100 = gear 12
  1252. {
  1253. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1254. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (12 << 6)); // shift value up 6 to get into bits 6-9
  1255. }
  1256. else if (this->comboBox_P16RearGear->Text->Equals("13")) // 1101 = gear 13
  1257. {
  1258. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1259. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (13 << 6)); // shift value up 6 to get into bits 6-9
  1260. }
  1261. else if (this->comboBox_P16RearGear->Text->Equals("14")) // 1110 = gear 14
  1262. {
  1263. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1264. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (14 << 6)); // shift value up 6 to get into bits 6-9
  1265. }
  1266. else if (this->comboBox_P16RearGear->Text->Equals("15")) // 1111 = gear 15
  1267. {
  1268. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand & 0xFC3F); // clear the bits 6-9 only
  1269. LEVData->usP16DisplayCommand = (LEVData->usP16DisplayCommand | (15 << 6)); // shift value up 6 to get into bits 6-9
  1270. }
  1271. }
  1272. /**************************************************************************
  1273. * LEVDisplay::checkBox_P16HighBeamOn_CheckedChanged
  1274. *
  1275. * Toggles the bit in the command bitfield for high/low beam, page 16, byte 4-5, bit 2
  1276. *
  1277. * returns: N/A
  1278. *
  1279. **************************************************************************/
  1280. void LEVDisplay::checkBox_P16HighBeamOn_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1281. {
  1282. if (this->checkBox_P16HighBeamOn->Checked == TRUE)
  1283. LEVData->usP16DisplayCommand |= 0x04; // set bit 2 to 1
  1284. else
  1285. LEVData->usP16DisplayCommand &= (UCHAR)~0x04; // set bit 2 to 0
  1286. }
  1287. /**************************************************************************
  1288. * LEVDisplay::checkBox_P16LightOn_CheckedChanged
  1289. *
  1290. * Toggles the bit in the system state bitfield for Light on/off, page 16, byte 4-5, bit 3
  1291. *
  1292. * returns: N/A
  1293. *
  1294. **************************************************************************/
  1295. void LEVDisplay::checkBox_P16LightOn_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1296. {
  1297. if (this->checkBox_P16LightOn->Checked == TRUE)
  1298. LEVData->usP16DisplayCommand |= 0x08; // set bit 3 to 1
  1299. else
  1300. LEVData->usP16DisplayCommand &= (UCHAR)~0x08; // set bit 3 to 0
  1301. }
  1302. /**************************************************************************
  1303. * LEVDisplay::checkBox_P16LeftSignalOn_CheckedChanged
  1304. *
  1305. * Toggles the bit in the system state bitfield for left signal on/off, page 16, byte 4-5, bit 1
  1306. *
  1307. * returns: N/A
  1308. *
  1309. **************************************************************************/
  1310. void LEVDisplay::checkBox_P16LeftSignalOn_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1311. {
  1312. if (this->checkBox_P16LeftSignalOn->Checked == TRUE)
  1313. LEVData->usP16DisplayCommand |= 0x02; // set bit 1 to 1
  1314. else
  1315. LEVData->usP16DisplayCommand &= (UCHAR)~0x02; // set bit 1 to 0
  1316. }
  1317. /**************************************************************************
  1318. * LEVDisplay::checkBox_P16RightSignalOn_CheckedChanged
  1319. *
  1320. * Toggles the bit in the system state bitfield for right signal on/off, page 16, byte 4-5, bit 0
  1321. *
  1322. * returns: N/A
  1323. *
  1324. **************************************************************************/
  1325. void LEVDisplay::checkBox_P16RightSignalOn_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1326. {
  1327. if (this->checkBox_P16RightSignalOn->Checked == TRUE)
  1328. LEVData->usP16DisplayCommand |= 0x01; // set bit 0 to 1
  1329. else
  1330. LEVData->usP16DisplayCommand &= (UCHAR)~0x01; // set bit 0 to 0
  1331. }
  1332. /**************************************************************************
  1333. * LEVDisplay::numericUpDown_P16ManID_ValueChanged
  1334. *
  1335. * Page 16, Byte 6-7, Selects the manufacturer ID to use. UI locks the range
  1336. *
  1337. * returns: N/A
  1338. *
  1339. **************************************************************************/
  1340. void LEVDisplay::numericUpDown_P16ManID_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1341. {
  1342. LEVData->usP16ManID = (System::Convert::ToUInt16(this->numericUpDown_P16ManID->Value));
  1343. }
  1344. /**************************************************************************
  1345. * LEVDisplay::numericUpDown_P16Circum_ValueChanged
  1346. *
  1347. * Page 16, Byte 2-3.5, Selects the wheel circumference to use. UI locks the range
  1348. *
  1349. * returns: N/A
  1350. *
  1351. **************************************************************************/
  1352. void LEVDisplay::numericUpDown_P16Circum_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1353. {
  1354. LEVData->usP16WheelCircum = (System::Convert::ToUInt16(this->numericUpDown_P16Circum->Value));
  1355. LEVData->usP16WheelCircum |= 0xF000;
  1356. }
  1357. /**************************************************************************
  1358. * LEVDisplay::button_P16Send_Click
  1359. *
  1360. * Sends Page 16 as an acknowledged message (only done on user request)
  1361. *
  1362. * returns: N/A
  1363. *
  1364. **************************************************************************/
  1365. void LEVDisplay::button_P16Send_Click(System::Object^ sender, System::EventArgs^ e)
  1366. {
  1367. this->label_AckMsgStatus->Text = "";
  1368. SendRequestMsg(LEVData->PAGE16_DISPLAY_DATA);
  1369. }
  1370. /**************************************************************************
  1371. * LEVDisplay::SendRequestMsg
  1372. *
  1373. * Sends an acknowledged Page Requset message according to the message code
  1374. *
  1375. * ucMsgCode_: message ID of the message to send
  1376. * Supported messages:
  1377. * - Page 16 Display Data
  1378. *
  1379. * returns: N/A
  1380. *
  1381. **************************************************************************/
  1382. void LEVDisplay::SendRequestMsg(UCHAR ucMsgCode_)
  1383. {
  1384. UCHAR aucAckBuffer[8] = {0,0,0,0,0,0,0,0};
  1385. //SendRequestMsg(LEVData->PAGE70_REQUEST);
  1386. switch(ucMsgCode_)
  1387. {
  1388. case LEVData->PAGE16_DISPLAY_DATA: // Page 16
  1389. LEVData->EncodeData(LEVData->PAGE16_DISPLAY_DATA, aucAckBuffer);
  1390. break;
  1391. case LEVData->PAGE70_REQUEST: // Page 70
  1392. LEVData->EncodeData(LEVData->PAGE70_REQUEST, aucAckBuffer);
  1393. break;
  1394. default:
  1395. return; // Do not transmit if unsupported message code
  1396. }
  1397. // Send acknowledged message
  1398. if(!ucMsgExpectingAck) // If this message is not a retransmission
  1399. {
  1400. ucAckRetryCount = 0; // Reset retransmission counter
  1401. ucMsgExpectingAck = ucMsgCode_; // Set code to message for which an ACK wil be expected
  1402. }
  1403. requestAckMsg(aucAckBuffer); // Send message
  1404. }
  1405. /**************************************************************************
  1406. * LEVDisplay::HandleRetransmit
  1407. *
  1408. * Retransmits request message, up to the maximum retransmission number
  1409. *
  1410. * returns: TRUE if message was retransmitted
  1411. * FALSE if maximum number of retransmissions was reached
  1412. *
  1413. **************************************************************************/
  1414. BOOL LEVDisplay::HandleRetransmit()
  1415. {
  1416. BOOL bSuccess = TRUE;
  1417. if(ucMsgExpectingAck) // Message still expecting an ack
  1418. {
  1419. if(ucAckRetryCount++ < LEVData->MAX_RETRIES)
  1420. SendRequestMsg(ucMsgExpectingAck);
  1421. else
  1422. bSuccess = FALSE;
  1423. }
  1424. return bSuccess;
  1425. }
  1426. /**************************************************************************
  1427. * LEVDisplay::UpdateDisplayAckStatus
  1428. *
  1429. * Updates display to show if acknowledged request messages were
  1430. * transmitted successfully
  1431. *
  1432. * returns: N/A
  1433. *
  1434. **************************************************************************/
  1435. void LEVDisplay::UpdateDisplayAckStatus(UCHAR ucStatus_)
  1436. {
  1437. switch(ucStatus_)
  1438. {
  1439. case LEVData->ACK_SUCCESS:
  1440. this->label_AckMsgStatus->ForeColor = System::Drawing::Color::Green;
  1441. this->label_AckMsgStatus->Text = "SENT";
  1442. break;
  1443. case LEVData->ACK_RETRY:
  1444. this->label_AckMsgStatus->ForeColor = System::Drawing::Color::Blue;
  1445. this->label_AckMsgStatus->Text = "RTRY";
  1446. break;
  1447. case LEVData->ACK_FAIL:
  1448. this->label_AckMsgStatus->ForeColor = System::Drawing::Color::Red;
  1449. this->label_AckMsgStatus->Text = "FAIL";
  1450. break;
  1451. default:
  1452. break;
  1453. }
  1454. }
  1455. /**************************************************************************
  1456. * LEVDisplay::numericUpDown_numericUpDown_RqTxTimes
  1457. *
  1458. * Request Pages, Selects the number of times to Request the sensor to broadcast requested page for
  1459. *
  1460. * returns: N/A
  1461. *
  1462. **************************************************************************/
  1463. void LEVDisplay::numericUpDown_RqTxTimes_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1464. {
  1465. LEVData->ucP70TxTimes = System::Convert::ToByte(this->numericUpDown_RqTxTimes->Value);
  1466. }
  1467. /**************************************************************************
  1468. * LEVDisplay::comboBox_PageToRequest_SelectedIndexChanged
  1469. *
  1470. * Request Pages, Selects the page to Request
  1471. *
  1472. * returns: N/A
  1473. *
  1474. **************************************************************************/
  1475. void LEVDisplay::comboBox_PageToRequest_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  1476. {
  1477. if (this->comboBox_PageToRequest->Text->Equals("Data Page 1"))
  1478. {
  1479. LEVData->ucP70RequestedPage = LEVData->PAGE1_SPEED_SYSTEM1;
  1480. }
  1481. else if (this->comboBox_PageToRequest->Text->Equals("Data Page 2"))
  1482. {
  1483. LEVData->ucP70RequestedPage = LEVData->PAGE2_SPEED_DISTANCE;
  1484. }
  1485. else if (this->comboBox_PageToRequest->Text->Equals("Data Page 3"))
  1486. {
  1487. LEVData->ucP70RequestedPage = LEVData->PAGE3_SPEED_SYSTEM2;
  1488. }
  1489. else if (this->comboBox_PageToRequest->Text->Equals("Data Page 4"))
  1490. {
  1491. LEVData->ucP70RequestedPage = LEVData->PAGE4_BATTERY;
  1492. }
  1493. else if (this->comboBox_PageToRequest->Text->Equals("Data Page 5"))
  1494. {
  1495. LEVData->ucP70RequestedPage = LEVData->PAGE5_CAPABILITES;
  1496. }
  1497. }
  1498. /**************************************************************************
  1499. * LEVDisplay::button_SendRequestClick
  1500. *
  1501. * Sends a Request Page 70 as an acknowledged message (only done on user request)
  1502. *
  1503. * returns: N/A
  1504. *
  1505. **************************************************************************/
  1506. void LEVDisplay::button_SendRequest_Click(System::Object^ sender, System::EventArgs^ e)
  1507. {
  1508. this->label_AckMsgStatus->Text = ""; //*** fix this, wrong place
  1509. SendRequestMsg(LEVData->PAGE70_REQUEST);
  1510. }
  1511. /**************************************************************************
  1512. * LEVDisplay::TransmitCommonPage
  1513. *
  1514. * Handles sending bcast common pages on the reverse channel
  1515. *
  1516. * returns: N/A
  1517. *
  1518. **************************************************************************/
  1519. void LEVDisplay::TransmitCommonPage()
  1520. {
  1521. static UCHAR ucReqCommonPatternCount = 0;
  1522. UCHAR aucTxBuffer[8];
  1523. UCHAR aucReqCommonTxPattern[4] = {commonDataDisplay->PAGE80, commonDataDisplay->PAGE81};
  1524. memset(aucTxBuffer, 8, 0x00);
  1525. // send common data pages 80 and 81
  1526. commonDataDisplay->Encode(aucReqCommonTxPattern[ucReqCommonPatternCount], aucTxBuffer);
  1527. ucReqCommonPatternCount++;
  1528. if (ucReqCommonPatternCount >= 2)
  1529. ucReqCommonPatternCount = 0;
  1530. requestBcastMsg(aucTxBuffer); // Send as broadcast message
  1531. }
  1532. /**************************************************************************
  1533. * LEVDisplay::button_CommonUpdate_Click
  1534. *
  1535. * Adjusts the global pages 80 and 81 via the GUI
  1536. *
  1537. * returns: N/A
  1538. *
  1539. **************************************************************************/
  1540. void LEVDisplay::button_CommonUpdate_Click(System::Object^ sender, System::EventArgs^ e)
  1541. {
  1542. // required common pages
  1543. //commonData->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNum->Text);
  1544. //commonData->ucSwVersion = System::Convert::ToByte(this->textBox_SwVersion->Text);
  1545. //commonData->ucHwVersion = System::Convert::ToByte(this->textBox_HwVersion->Text);
  1546. //commonData->usMfgID = System::Convert::ToUInt16(this->textBox_MfgID->Text);
  1547. //commonData->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNum->Text);
  1548. label_ErrorCommon->Visible = false;
  1549. label_ErrorCommon->Text = "Error: ";
  1550. // Convert and catch failed conversions
  1551. try{
  1552. commonDataDisplay->usMfgID = System::Convert::ToUInt16(this->textBox_MfgID->Text);
  1553. }
  1554. catch(...){
  1555. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " MFID");
  1556. label_ErrorCommon->Visible = true;
  1557. }
  1558. try{
  1559. if(this->checkBox_NoSerial->Checked)
  1560. commonDataDisplay->ulSerialNum = 0xFFFFFFFF;
  1561. else
  1562. commonDataDisplay->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNum->Text);
  1563. }
  1564. catch(...){
  1565. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " Ser#");
  1566. label_ErrorCommon->Visible = true;
  1567. }
  1568. try{
  1569. commonDataDisplay->ucHwVersion = System::Convert::ToByte(this->textBox_HwVersion->Text);
  1570. }
  1571. catch(...){
  1572. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " HWVr");
  1573. label_ErrorCommon->Visible = true;
  1574. }
  1575. try{
  1576. commonDataDisplay->ucSwVersion = System::Convert::ToByte(this->textBox_SwVersion->Text);
  1577. }
  1578. catch(...){
  1579. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " SWVr");
  1580. label_ErrorCommon->Visible = true;
  1581. }
  1582. try{
  1583. commonDataDisplay->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNum->Text);
  1584. }
  1585. catch(...){
  1586. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " Mdl#");
  1587. label_ErrorCommon->Visible = true;
  1588. }
  1589. }
  1590. /**************************************************************************
  1591. * LEVDisplay::numericUpDown_DisplayAssistModes_ValueChanged
  1592. *
  1593. * Handles change in value for supported assist modes
  1594. *
  1595. * returns: N/A
  1596. *
  1597. **************************************************************************/
  1598. void LEVDisplay::numericUpDown_DisplayAssistModes_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1599. {
  1600. ucDisplaySupportedAssist = (System::Convert::ToByte(this->numericUpDown_DisplayAssistModes->Value));
  1601. UpdateP16Assist();
  1602. }
  1603. /**************************************************************************
  1604. * LEVDisplay::UpdateP16Assist
  1605. *
  1606. * Handles Assist Mode mapping when the number of supported assist modes is changed
  1607. *
  1608. * returns: N/A
  1609. *
  1610. **************************************************************************/
  1611. void LEVDisplay::UpdateP16Assist()
  1612. {
  1613. // get the number of assist modes currently in Page 16
  1614. UCHAR AssistMode;
  1615. if(this->comboBox_P16Assist->Text->Equals("Assist Off"))
  1616. AssistMode = 0;
  1617. else if(this->comboBox_P16Assist->Text->Equals("Assist 1"))
  1618. AssistMode = 1;
  1619. else if(this->comboBox_P16Assist->Text->Equals("Assist 2"))
  1620. AssistMode = 2;
  1621. else if(this->comboBox_P16Assist->Text->Equals("Assist 3"))
  1622. AssistMode = 3;
  1623. else if(this->comboBox_P16Assist->Text->Equals("Assist 4"))
  1624. AssistMode = 4;
  1625. else if(this->comboBox_P16Assist->Text->Equals("Assist 5"))
  1626. AssistMode = 5;
  1627. else if(this->comboBox_P16Assist->Text->Equals("Assist 6"))
  1628. AssistMode = 6;
  1629. else
  1630. AssistMode = 7;
  1631. if(ucDisplaySupportedAssist == 1) // Display supports 1 AssistMode
  1632. {
  1633. switch(AssistMode)
  1634. {
  1635. case 0: // "Assist Off" is common to all mapping, nothing needs to be done
  1636. break;
  1637. default: // if the current Assist mode is not Off, change the page 16 data to Assist mode 7 and change the combobox index
  1638. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1639. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x38);
  1640. this->comboBox_P16Assist->Text = "Assist 7";
  1641. break;
  1642. }
  1643. }
  1644. else if(ucDisplaySupportedAssist == 2) // Display supports 2 AssistModes
  1645. {
  1646. switch(AssistMode)
  1647. {
  1648. case 1:
  1649. case 2:
  1650. case 3: // if Assist mode is 1, 2, or 3 ensure page 16 data is Assist mode 3 and change combobox index
  1651. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1652. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x18);
  1653. this->comboBox_P16Assist->Text = "Assist 3";
  1654. break;
  1655. case 4:
  1656. case 5:
  1657. case 6:
  1658. case 7: // if Assist mode is 4, 5, 6, or 7 ensure page 16 data is Assist mode 7 and change combobox index
  1659. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1660. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x38);
  1661. this->comboBox_P16Assist->Text = "Assist 7";
  1662. break;
  1663. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1664. break;
  1665. }
  1666. }
  1667. else if(ucDisplaySupportedAssist == 3) // Display supports 3 Assist Modes
  1668. {
  1669. switch(AssistMode)
  1670. {
  1671. case 1:
  1672. case 2: // if Assist mode is 1, or 2, ensure page 16 data is Assist mode 2 and change combobox index
  1673. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1674. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x10);
  1675. this->comboBox_P16Assist->Text = "Assist 2";
  1676. break;
  1677. case 3:
  1678. case 4: // if the current Assist mode is 3 or 4, ensure page 16 data is Assist mode 4 and change combobox index
  1679. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1680. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x20);
  1681. this->comboBox_P16Assist->Text = "Assist 4";
  1682. break;
  1683. case 5:
  1684. case 6:
  1685. case 7: // if the current Assist mode is 5, 6, or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1686. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1687. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x38);
  1688. this->comboBox_P16Assist->Text = "Assist 7";
  1689. break;
  1690. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1691. break;
  1692. }
  1693. }
  1694. else if(ucDisplaySupportedAssist == 4) // Display supports 4 Assist Modes
  1695. {
  1696. switch(AssistMode)
  1697. {
  1698. case 1: // if the current Assist mode is 1, ensure page 16 data is Assist mode 1
  1699. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1700. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x08);
  1701. break;
  1702. case 2:
  1703. case 3: // if the current Assist mode is 2 or 3, ensure page 16 data is Assist mode 3 and change combobox index
  1704. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1705. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x18);
  1706. this->comboBox_P16Assist->Text = "Assist 3";
  1707. break;
  1708. case 4:
  1709. case 5: // if the current Assist mode is 4 or 5, ensure page 16 data is Assist mode 5 and change combobox index
  1710. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1711. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x28);
  1712. this->comboBox_P16Assist->Text = "Assist 5";
  1713. break;
  1714. case 6:
  1715. case 7: // if the current Assist mode is 6 or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1716. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1717. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x38);
  1718. this->comboBox_P16Assist->Text = "Assist 7";
  1719. break;
  1720. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1721. break;
  1722. }
  1723. }
  1724. else if(ucDisplaySupportedAssist== 5) // Display supports 5 Assist Modes
  1725. {
  1726. switch(AssistMode)
  1727. {
  1728. case 1: // if the current Assist mode is 1, ensure page 16 data is Assist mode 1
  1729. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1730. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x08);
  1731. break;
  1732. case 2: // if the current Assist mode is 2, ensure page 16 data is Assist mode 2
  1733. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1734. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x10);
  1735. break;
  1736. case 3: // if the current Assist mode is 3, ensure page 16 data is Assist mode 3
  1737. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1738. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x18);
  1739. break;
  1740. case 4:
  1741. case 5: // if the current Assist mode is 4 or 5, ensure page 16 data is Assist mode 5 and change combobox index
  1742. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1743. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x28);
  1744. this->comboBox_P16Assist->Text = "Assist 5";
  1745. break;
  1746. case 6:
  1747. case 7: // if the current Assist mode is 6 or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1748. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1749. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x38);
  1750. this->comboBox_P16Assist->Text = "Assist 7";
  1751. break;
  1752. default: // "Assist Off" is common to call mapping, nothing needs to be done
  1753. break;
  1754. }
  1755. }
  1756. else if(ucDisplaySupportedAssist == 6) // Display supports 6 Assist Modes
  1757. {
  1758. switch(AssistMode)
  1759. {
  1760. case 1: // if the currentAssistmode is 1, ensure page 16 data is Assist mode 1
  1761. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1762. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x08);
  1763. break;
  1764. case 2: // if the current Assist mode is 2, ensure page 16 data is Assist mode 2
  1765. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1766. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x10);
  1767. break;
  1768. case 3: // if the current Assist mode is 3, ensure page 16 data is Assist mode 3
  1769. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1770. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x18);
  1771. break;
  1772. case 4: // if the current Assist mode is 4, ensure page 16 data is Assist mode 4
  1773. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1774. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x20);
  1775. break;
  1776. case 5: // if the current Assist mode is 5, ensure page 16 data is Assist mode 5
  1777. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1778. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x28);
  1779. break;
  1780. case 6:
  1781. case 7: // if the current Assist mode is 6 or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1782. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1783. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x38);
  1784. this->comboBox_P16Assist->Text = "Assist 7";
  1785. break;
  1786. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1787. break;
  1788. }
  1789. }
  1790. }
  1791. /**************************************************************************
  1792. * LEVDisplay::numericUpDown_DisplayRegenModes_ValueChanged
  1793. *
  1794. * Handles change in value for supported Regen modes
  1795. *
  1796. * returns: N/A
  1797. *
  1798. **************************************************************************/
  1799. void LEVDisplay::numericUpDown_DisplayRegenModes_ValueChanged(System::Object ^sender, System::EventArgs ^e)
  1800. {
  1801. ucDisplaySupportedRegen = (System::Convert::ToByte(this->numericUpDown_DisplayRegenModes->Value));
  1802. UpdateP16Regen();
  1803. }
  1804. /**************************************************************************
  1805. * LEVDisplay::UpdateP16Regen
  1806. *
  1807. * Handles Regen Mode mapping when the number of supported regen modes is changed
  1808. *
  1809. * returns: N/A
  1810. *
  1811. **************************************************************************/
  1812. void LEVDisplay::UpdateP16Regen()
  1813. {
  1814. // get the number of regen modes currently in Page 16
  1815. UCHAR RegenMode;
  1816. if(this->comboBox_P16Regen->Text->Equals("Regenerative Off"))
  1817. RegenMode = 0;
  1818. else if(this->comboBox_P16Regen->Text->Equals("Regenerative 1"))
  1819. RegenMode = 1;
  1820. else if(this->comboBox_P16Regen->Text->Equals("Regenerative 2"))
  1821. RegenMode = 2;
  1822. else if(this->comboBox_P16Regen->Text->Equals("Regenerative 3"))
  1823. RegenMode = 3;
  1824. else if(this->comboBox_P16Regen->Text->Equals("Regenerative 4"))
  1825. RegenMode = 4;
  1826. else if(this->comboBox_P16Regen->Text->Equals("Regenerative 5"))
  1827. RegenMode = 5;
  1828. else if(this->comboBox_P16Regen->Text->Equals("Regenerative 6"))
  1829. RegenMode = 6;
  1830. else
  1831. RegenMode = 7;
  1832. if(ucDisplaySupportedRegen == 0)
  1833. { // if the Display doesn't support Regen Modes, set Page 16 data to regen mode 0 and update the combobox
  1834. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1835. this->comboBox_P16Regen->Text = "Regenerative Off";
  1836. }
  1837. else if(ucDisplaySupportedRegen == 1) // Display supports 1 Regen Mode
  1838. {
  1839. switch(RegenMode)
  1840. {
  1841. case 0: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1842. break;
  1843. default: // if the current regen mode is not Off, change the page 16 data to regen mode 7 and change the combobox index
  1844. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1845. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x07);
  1846. this->comboBox_P16Regen->Text = "Regenerative 7";
  1847. break;
  1848. }
  1849. }
  1850. else if(ucDisplaySupportedRegen == 2) // Display supports 2 Regen Modes
  1851. {
  1852. switch(RegenMode)
  1853. {
  1854. case 1:
  1855. case 2:
  1856. case 3: // if regen mode is 1, 2, or 3 ensure page 16 data is regen mode 3 and change combobox index
  1857. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1858. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x03);
  1859. this->comboBox_P16Regen->Text = "Regenerative 3";
  1860. break;
  1861. case 4:
  1862. case 5:
  1863. case 6:
  1864. case 7: // if regen mode is 4, 5, 6, or 7 ensure page 16 data is regen mode 7 and change combobox index
  1865. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1866. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x07);
  1867. this->comboBox_P16Regen->Text = "Regenerative 7";
  1868. break;
  1869. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1870. break;
  1871. }
  1872. }
  1873. else if(ucDisplaySupportedRegen == 3) // Display supports 3 Regen Modes
  1874. {
  1875. switch(RegenMode)
  1876. {
  1877. case 1:
  1878. case 2: // if regen mode is 1, or 2, ensure page 16 data is regen mode 2 and change combobox index
  1879. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1880. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x02);
  1881. this->comboBox_P16Regen->Text = "Regenerative 2";
  1882. break;
  1883. case 3:
  1884. case 4: // if the current regen mode is 3 or 4, ensure page 16 data is regen mode 4 and change combobox index
  1885. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1886. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x04);
  1887. this->comboBox_P16Regen->Text = "Regenerative 4";
  1888. break;
  1889. case 5:
  1890. case 6:
  1891. case 7: // if the current regen mode is 5, 6, or 7, ensure page 16 data is regen mode 7 and change combobox index
  1892. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1893. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x07);
  1894. this->comboBox_P16Regen->Text = "Regenerative 7";
  1895. break;
  1896. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1897. break;
  1898. }
  1899. }
  1900. else if(ucDisplaySupportedRegen == 4) // Display supports 4 Regen Modes
  1901. {
  1902. switch(RegenMode)
  1903. {
  1904. case 1: // if the current regen mode is 1, ensure page 16 data is regen mode 1
  1905. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1906. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x01);
  1907. break;
  1908. case 2:
  1909. case 3: // if the current regen mode is 2 or 3, ensure page 16 data is regen mode 3 and change combobox index
  1910. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1911. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x03);
  1912. this->comboBox_P16Regen->Text = "Regenerative 3";
  1913. break;
  1914. case 4:
  1915. case 5: // if the current regen mode is 4 or 5, ensure page 16 data is regen mode 5 and change combobox index
  1916. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1917. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x05);
  1918. this->comboBox_P16Regen->Text = "Regenerative 5";
  1919. break;
  1920. case 6:
  1921. case 7: // if the current regen mode is 6 or 7, ensure page 16 data is regen mode 7 and change combobox index
  1922. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1923. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x07);
  1924. this->comboBox_P16Regen->Text = "Regenerative 7";
  1925. break;
  1926. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1927. break;
  1928. }
  1929. }
  1930. else if(ucDisplaySupportedRegen == 5) // Display supports 5 Regen Modes
  1931. {
  1932. switch(RegenMode)
  1933. {
  1934. case 1: // if the current regen mode is 1, ensure page 16 data is regen mode 1
  1935. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1936. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x01);
  1937. break;
  1938. case 2: // if the current regen mode is 2, ensure page 16 data is regen mode 2
  1939. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1940. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x02);
  1941. break;
  1942. case 3: // if the current regen mode is 3, ensure page 16 data is regen mode 3
  1943. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1944. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x03);
  1945. break;
  1946. case 4:
  1947. case 5: // if the current regen mode is 4 or 5, ensure page 16 data is regen mode 5 and change combobox index
  1948. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1949. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x05);
  1950. this->comboBox_P16Regen->Text = "Regenerative 5";
  1951. break;
  1952. case 6:
  1953. case 7: // if the current regen mode is 6 or 7, ensure page 16 data is regen mode 7 and change combobox index
  1954. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1955. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x07);
  1956. this->comboBox_P16Regen->Text = "Regenerative 7";
  1957. break;
  1958. default: // "Regenerative Off" is common to call mapping, nothing needs to be done
  1959. break;
  1960. }
  1961. }
  1962. else if(ucDisplaySupportedRegen == 6) // Display supports 6 Regen Modes
  1963. {
  1964. switch(RegenMode)
  1965. {
  1966. case 1: // if the current regen mode is 1, ensure page 16 data is regen mode 1
  1967. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1968. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x01);
  1969. break;
  1970. case 2: // if the current regen mode is 2, ensure page 16 data is regen mode 2
  1971. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1972. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x02);
  1973. break;
  1974. case 3: // if the current regen mode is 3, ensure page 16 data is regen mode 3
  1975. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1976. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x03);
  1977. break;
  1978. case 4: // if the current regen mode is 4, ensure page 16 data is regen mode 4
  1979. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1980. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x04);
  1981. break;
  1982. case 5: // if the current regen mode is 5, ensure page 16 data is regen mode 5
  1983. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1984. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x05);
  1985. break;
  1986. case 6:
  1987. case 7: // if the current regen mode is 6 or 7, ensure page 16 data is regen mode 7 and change combobox index
  1988. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xF8);
  1989. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x07);
  1990. this->comboBox_P16Regen->Text = "Regenerative 7";
  1991. break;
  1992. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1993. break;
  1994. }
  1995. }
  1996. }
  1997. /**************************************************************************
  1998. * LEVDisplay::checkBox_NoSerial_CheckedChanged
  1999. *
  2000. * Handles CheckedChanged event of the checkBox
  2001. *
  2002. * returns: N/A
  2003. *
  2004. **************************************************************************/
  2005. void LEVDisplay::checkBox_NoSerial_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  2006. {
  2007. if(this->checkBox_NoSerial->Checked)
  2008. this->textBox_SerialNum->Enabled = false;
  2009. else
  2010. this->textBox_SerialNum->Enabled = true;
  2011. }