LEVSensor.cpp 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564
  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 "LEVSensor.h"
  11. /**************************************************************************
  12. * LEVSensor::ANT_eventNotification
  13. *
  14. * Process ANT channel event
  15. *
  16. * ucEventCode_: code of ANT channel event
  17. * pucEventBuffer_: pointer to buffer containing data received from ANT,
  18. * or a pointer to the transmit buffer in the case of an EVENT_TX
  19. *
  20. * returns: N/A
  21. *
  22. **************************************************************************/
  23. void LEVSensor::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
  24. {
  25. switch(ucEventCode_)
  26. {
  27. case EVENT_TX:
  28. HandleTransmit((UCHAR*) pucEventBuffer_);
  29. UpdateDisplay();
  30. break;
  31. case EVENT_RX_ACKNOWLEDGED: // for receiving page 16 commands
  32. case EVENT_RX_BURST_PACKET: // intentional fall thru
  33. case EVENT_RX_BROADCAST: // for receiving common pages broadcast
  34. HandleReceive((UCHAR*) pucEventBuffer_);
  35. break;
  36. /*case EVENT_TRANSFER_TX_COMPLETED: // For sending ACK request replies
  37. ucAckRetryCount = 0; // Reset retransmission counter
  38. ucMsgExpectingAck = 0; // Clear pending msg code
  39. break;
  40. case EVENT_TRANSFER_TX_FAILED:
  41. case EVENT_ACK_TIMEOUT: // Intentional fall thru
  42. if(ucMsgExpectingAck)
  43. HandleRetransmit(); // resend if it failed
  44. break;*/
  45. default:
  46. break;
  47. }
  48. }
  49. /**************************************************************************
  50. * LEVSensor::InitializeSim
  51. *
  52. * Initializes simulator variables
  53. *
  54. * returns: N/A
  55. *
  56. **************************************************************************/
  57. void LEVSensor::InitializeSim()
  58. {
  59. ulTimerInterval = 250; // in ms - simulates the sensor sending the most relevant information every message period
  60. dbDispAcumDist = 0;
  61. bPage16Supported = TRUE; // default to support this page, matching UI
  62. ucRequestPage = 1; // the page to transmit
  63. ucRequestCount = 1; // the number of times to re-transmit
  64. bTxRequestFlag = FALSE;
  65. bTxPage34 = FALSE;
  66. // required common pages
  67. commonDataSensor->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNum->Text);
  68. commonDataSensor->ucSwVersion = System::Convert::ToByte(this->textBox_SwVersion->Text);
  69. commonDataSensor->ucHwVersion = System::Convert::ToByte(this->textBox_HwVersion->Text);
  70. commonDataSensor->usMfgID = System::Convert::ToUInt16(this->textBox_MfgID->Text);
  71. commonDataSensor->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNum->Text);
  72. // Initialize variables to match the UI
  73. LEVData->ucSupportedTravelModes = System::Convert::ToByte(this->numericUpDown_P5RegenModes->Value);
  74. LEVData->ucSupportedTravelModes = (LEVData->ucSupportedTravelModes | (System::Convert::ToByte(this->numericUpDwn_P5AssistModes->Value) << 3));
  75. LEVData->usCurrentLEVSpeed = System::Convert::ToUInt16(this->numericUpDown_P2Speed->Value * 10);
  76. LEVData->usCurrentLEVSpeed |= 0xF000;
  77. LEVData->usSpeed = System::Convert::ToUInt16(this->numericUpDown_P2Speed->Value * 10);
  78. LEVData->usSpeed |= 0xF000;
  79. //LEVData->ucTravelModeState = 0 (Off is already default)
  80. //LEVData->ucSystemState = 0 (UI is all off / 0)
  81. //LEVData->ucGearState = 0 (UI is all off / 0)
  82. //LEVData->ucErrorMessage = 0 (UI defaults to 0)
  83. //LEVData->ucTemperature = 0 (UI defaults to 0)
  84. LEVData->ucPercentAssist = (System::Convert::ToByte(this->numericUpDown_P3PercentAssist->Value));
  85. LEVData->ucBatteryCharge = (System::Convert::ToByte(this->numericUpDown_P3Charge->Value));
  86. LEVData->ucBatteryVoltage = (System::Convert::ToByte(this->numericUpDown_P4Voltage->Value));
  87. LEVData->usRemainingRange = (System::Convert::ToUInt16(this->numericUpDown_P2Range->Value));
  88. LEVData->usRemainingRange |= 0xF000;
  89. LEVData->usChargeCycleCount = System::Convert::ToUInt16(this->numericUpDown_P4ChargeCycle->Value);
  90. LEVData->usFuelConsumption = System::Convert::ToUInt16(this->numericUpDown_P4FuelConsumption->Value * 10);
  91. LEVData->usP34FuelConsumption = System::Convert::ToUInt16(this->numericUpDown_P4FuelConsumption->Value * 10);
  92. LEVData->usDistanceOnCharge = System::Convert::ToUInt16(this->numericUpDown_P4DistanceOnCharge->Value * 10);
  93. LEVData->usWheelCircumference = System::Convert::ToUInt16(this->numericUpDown_P5Circum->Value);
  94. LEVData->usWheelCircumference |= 0xF000;
  95. //LEVData->ulOdometer = 0 (UI defaults to 0)
  96. }
  97. /**************************************************************************
  98. * LEVSensor::HandleTransmit
  99. *
  100. * Encode data generated by simulator for transmission
  101. *
  102. * pucTxBuffer_: pointer to the transmit buffer
  103. *
  104. * returns: N/A
  105. *
  106. **************************************************************************/
  107. void LEVSensor::HandleTransmit(UCHAR* pucTxBuffer_)
  108. {
  109. static ULONG ulMessageCount = 1;
  110. static UCHAR ucLevPatternCount = 0;
  111. static UCHAR ucReqCommonPatternCount = 0;
  112. static UCHAR ucLevSlot4Count = 0;
  113. static UCHAR ucLevSlot2Count = 0;
  114. UCHAR aucLevTxPattern[4] = {LEVData->PAGE1_SPEED_SYSTEM1,LEVData->PAGE2_SPEED_DISTANCE,LEVData->PAGE3_SPEED_SYSTEM2,LEVData->PAGE4_BATTERY}; // this is the required pattern
  115. UCHAR aucReqCommonTxPattern[2] = {commonDataSensor->PAGE80, commonDataSensor->PAGE81}; // defines the order of the common pages every 20 msgs
  116. UCHAR aucLevSlot4TxPatter[2] = {LEVData->PAGE4_BATTERY, LEVData->PAGE5_CAPABILITES}; // defines an alternating, P4, P5 pattern for slot 4
  117. UCHAR aucLevSlot2TxPattern[2] = {LEVData->PAGE2_SPEED_DISTANCE, LEVData->PAGE34_SPEED_DISTANCE}; //defines an alternating, P2, P34 page rotiation for slot 2 (if page 34 requested)
  118. // Request pages only on request. This takes priority over all other messages.
  119. if (bTxRequestFlag == TRUE)
  120. {
  121. LEVData->EncodeData(ucRequestPage, pucTxBuffer_);
  122. ucRequestCount--; // subtract one from the resend count
  123. if (ucRequestCount == 0) // if count is zero, then reset
  124. {
  125. bTxRequestFlag = FALSE;
  126. //also restart the LEV pattern back at page 1
  127. ucLevPatternCount = 0;
  128. ulMessageCount = 1;
  129. }
  130. ulMessageCount++; // keep incrementing this
  131. return; // skip the rest of the function in this case
  132. }
  133. // send LEV data pages
  134. switch (aucLevTxPattern[ucLevPatternCount])
  135. {
  136. case LEVData->PAGE1_SPEED_SYSTEM1:
  137. LEVData->EncodeData(LEVData->PAGE1_SPEED_SYSTEM1, pucTxBuffer_);
  138. break;
  139. case LEVData->PAGE2_SPEED_DISTANCE:
  140. if(bTxPage34)
  141. {
  142. LEVData->EncodeData(aucLevSlot2TxPattern[ucLevSlot2Count], pucTxBuffer_);
  143. ucLevSlot2Count++;
  144. if(ucLevSlot2Count >=2)
  145. ucLevSlot2Count = 0;
  146. }
  147. else
  148. LEVData->EncodeData(LEVData->PAGE2_SPEED_DISTANCE, pucTxBuffer_);
  149. break;
  150. case LEVData->PAGE3_SPEED_SYSTEM2:
  151. LEVData->EncodeData(LEVData->PAGE3_SPEED_SYSTEM2, pucTxBuffer_);
  152. break;
  153. case LEVData->PAGE4_BATTERY:
  154. if (ulMessageCount >= 20)
  155. {
  156. ulMessageCount = 1; // reset count
  157. // send common data pages 80 and 81
  158. commonDataSensor->Encode(aucReqCommonTxPattern[ucReqCommonPatternCount], pucTxBuffer_);
  159. ucReqCommonPatternCount++;
  160. if (ucReqCommonPatternCount >= 2)
  161. ucReqCommonPatternCount = 0;
  162. }
  163. else
  164. {
  165. LEVData->EncodeData(aucLevSlot4TxPatter[ucLevSlot4Count], pucTxBuffer_);
  166. ucLevSlot4Count++;
  167. if (ucLevSlot4Count >= 2)
  168. ucLevSlot4Count = 0;
  169. }
  170. break;
  171. default:
  172. break;
  173. }
  174. ucLevPatternCount++;
  175. if (ucLevPatternCount >= 4)
  176. ucLevPatternCount = 0; // reset the message count at the end
  177. ulMessageCount++;
  178. }
  179. /**************************************************************************
  180. * LEVSensor::HandleReceive
  181. *
  182. * Decode incoming transmissions, specifically data requests
  183. *
  184. * returns: N/A
  185. *
  186. **************************************************************************/
  187. void LEVSensor::HandleReceive(UCHAR* pucRxBuffer_)
  188. {
  189. UCHAR ucPageNum = pucRxBuffer_[0];
  190. switch(ucPageNum)
  191. {
  192. case LEVData->PAGE16_DISPLAY_DATA:
  193. {
  194. // only process if supported
  195. if (bPage16Supported == TRUE)
  196. {
  197. // decode P16, loading the P16 variables
  198. LEVData->Decode(pucRxBuffer_);
  199. // now we need to decode that into the Page 1 and Page 2 variables to "set" these paramaters
  200. if (LEVData->ucP16TravelMode != 0xFF)// if not set to "not supported"
  201. {
  202. MapAssistModes();
  203. MapRegenModes();
  204. }
  205. // bits 0-5 of P1 gear state match up to bits 4-9 of the P16 command
  206. LEVData->ucGearState = (LEVData->ucGearState & 0xC0); // clear bits 0-5 of current value
  207. LEVData->ucGearState = LEVData->ucGearState | ((LEVData->usP16DisplayCommand & 0x03F0) >> 4); // clear everything but bits 4-9 and shift down
  208. // bits 0-3 of P1 system state match up to bits 0-3 of the P16 command
  209. LEVData->ucSystemState = (LEVData->ucSystemState & 0xF0); // clear bits 0-3 of current value
  210. LEVData->ucSystemState = LEVData->ucSystemState | (LEVData->usP16DisplayCommand & 0x000F); // clear everything but bits 0-3
  211. // *** DO UI HERE? or move out?
  212. // clear everything but bits 3-5, then shift down to get current assist level
  213. this->comboBox_P1AssistLevel->SelectedIndex = ((LEVData->ucTravelModeState & 0x38) >> 3);
  214. // clear everything but bits 0-2 to get current regen level
  215. this->comboBox_P1RegenLevel->SelectedIndex = (LEVData->ucTravelModeState & 0x07);
  216. // clear everything but bits 2-5, then shift down to get rear gear setting
  217. this->comboBox_P1FrontGear->SelectedIndex = (LEVData->ucGearState & 0x03);
  218. // clear everything but bits 0-1 to get front gear setting
  219. this->comboBox_P1RearGear->SelectedIndex = ((LEVData->ucGearState & 0x3C) >> 2);
  220. if ((LEVData->ucSystemState & 0x04) != 0)
  221. this->checkBox_P1HighBeam->Checked = TRUE;
  222. else
  223. this->checkBox_P1HighBeam->Checked = FALSE;
  224. if ((LEVData->ucSystemState & 0x08) != 0)
  225. this->checkBox_P1LightOn->Checked = TRUE;
  226. else
  227. this->checkBox_P1LightOn->Checked = FALSE;
  228. if ((LEVData->ucSystemState & 0x02) != 0)
  229. this->checkBox_P1LeftSignalOn->Checked = TRUE;
  230. else
  231. this->checkBox_P1LeftSignalOn->Checked = FALSE;
  232. if ((LEVData->ucSystemState & 0x01) != 0)
  233. this->checkBox_P1RightSignalOn->Checked = TRUE;
  234. else
  235. this->checkBox_P1RightSignalOn->Checked = FALSE;
  236. // manufacturer ID
  237. this->label_P16ManIDValue->Text = LEVData->usP16ManID.ToString();
  238. // wheel circumference
  239. if ((LEVData->usP16WheelCircum > 1) && (LEVData->usP16WheelCircum < 4096) && !(this->checkBox_P5WheelCircum->Checked))
  240. this->numericUpDown_P5Circum->Value = LEVData->usP16WheelCircum;
  241. }
  242. break;
  243. }
  244. case LEVData->PAGE70_REQUEST:
  245. {
  246. ucRequestPage = pucRxBuffer_[6]; // save the page to transmit
  247. ucRequestCount = pucRxBuffer_[5]; // save the number of times to re-transmit
  248. bTxRequestFlag = TRUE; // flag to tell the tx function to send the requested page
  249. break;
  250. }
  251. case commonDataDisplay->PAGE80:
  252. {
  253. commonDataDisplay->Decode(pucRxBuffer_);
  254. this->label_Glb_ManfIDDisplay->Text = commonDataDisplay->usMfgID.ToString();
  255. this->label_Glb_HardwareVerDisplay->Text = commonDataDisplay->ucHwVersion.ToString();
  256. this->label_Glb_ModelNumDisplay->Text = commonDataDisplay->usModelNum.ToString();
  257. break;
  258. }
  259. case commonDataDisplay->PAGE81:
  260. {
  261. commonDataDisplay->Decode(pucRxBuffer_);
  262. if(commonDataDisplay->ulSerialNum == 0xFFFFFFFF)
  263. this->label_Glb_SerialNumDisplay->Text = "N/A";
  264. else
  265. this->label_Glb_SerialNumDisplay->Text = commonDataDisplay->ulSerialNum.ToString();
  266. this->label_Glb_SoftwareVerDisplay->Text = commonDataDisplay->ucSwVersion.ToString();
  267. break;
  268. }
  269. }
  270. }
  271. /**************************************************************************
  272. * LEVSensor::onTimerTock
  273. *
  274. * Simulates a sensor event, updating simulator data based on this event
  275. * Modifications to the timer interval are applied immediately after this
  276. * at ANTChannel
  277. *
  278. * usEventTime_: current time (ms)
  279. *
  280. * returns: N/A
  281. *
  282. **************************************************************************/
  283. void LEVSensor::onTimerTock(USHORT eventTime_)
  284. {
  285. USHORT usCurrentSpeed = LEVData->usCurrentLEVSpeed & 0x0FFF;
  286. dbDispAcumDist += (double) (usCurrentSpeed * ulTimerInterval) / 36000000;
  287. if (dbDispAcumDist > 167772) // check for rollover
  288. dbDispAcumDist = 0;
  289. // distance is transmitted in 0.01 km intervals
  290. LEVData->ulOdometer = System::Convert::ToUInt32(dbDispAcumDist * 100);
  291. LEVData->ulP34Odometer = System::Convert::ToUInt32(dbDispAcumDist * 100);
  292. }
  293. /***************************************************************************
  294. * LEVSensor::UpdateDisplay
  295. *
  296. * Updates displayed simulator data on GUI
  297. *
  298. * returns: N/A
  299. *
  300. **************************************************************************/
  301. void LEVSensor::UpdateDisplay()
  302. {
  303. this->label_P2TotDistDisplay->Text = dbDispAcumDist.ToString("N2"); // Update the accumulated distance label
  304. // the tx variables will show the raw transmitted data decoded, but not scaled into proper units
  305. USHORT usCurrentSpeed = LEVData->usCurrentLEVSpeed & 0x0FFF;
  306. this->label_StatusSpeedVal->Text = usCurrentSpeed.ToString();
  307. this->label_StatusOdoVal->Text = LEVData->ulOdometer.ToString();
  308. this->label_StatusAssistVal->Text = LEVData->ucPercentAssist.ToString();
  309. }
  310. /**************************************************************************
  311. * LEVSensor::comboBox_P1BattTemp_SelectedIndexChanged
  312. *
  313. * Updates the user selected battery temperature setting
  314. *
  315. * returns: N/A
  316. *
  317. **************************************************************************/
  318. void LEVSensor::comboBox_P1BattTemp_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  319. {
  320. UpdateBatteryTemp();
  321. }
  322. /**************************************************************************
  323. * LEVSensor::UpdateBatteryTemp
  324. *
  325. * Sets the Battery temperature, Page 3, Byte 3, bits 0-2
  326. *
  327. * returns: N/A
  328. *
  329. **************************************************************************/
  330. void LEVSensor::UpdateBatteryTemp()
  331. {
  332. if (this->comboBox_P1BattTemp->Text->Equals("Unknown")) // 000 = unknown
  333. {
  334. LEVData->ucTemperature = (LEVData->ucTemperature & 0xF8); // clear the bits 0-2 only
  335. }
  336. else if (this->comboBox_P1BattTemp->Text->Equals("Cold")) // 001 = cold
  337. {
  338. LEVData->ucTemperature = (LEVData->ucTemperature & 0xF8); // clear the bits 0-2 only
  339. LEVData->ucTemperature = (LEVData->ucTemperature | 0x01); // set bit 0 high
  340. }
  341. else if (this->comboBox_P1BattTemp->Text->Equals("Cold/Warm")) // 010 = cold/warm
  342. {
  343. LEVData->ucTemperature = (LEVData->ucTemperature & 0xF8); // clear the bits 0-2 only
  344. LEVData->ucTemperature = (LEVData->ucTemperature | 0x02); // set bit 1 high
  345. }
  346. else if (this->comboBox_P1BattTemp->Text->Equals("Warm")) // 011 = warm
  347. {
  348. LEVData->ucTemperature = (LEVData->ucTemperature & 0xF8); // clear the bits 0-2 only
  349. LEVData->ucTemperature = (LEVData->ucTemperature | 0x03); // set bits 0,1 high
  350. }
  351. else if (this->comboBox_P1BattTemp->Text->Equals("Warm/Hot")) // 100 = warm/hot
  352. {
  353. LEVData->ucTemperature = (LEVData->ucTemperature & 0xF8); // clear the bits 0-2 only
  354. LEVData->ucTemperature = (LEVData->ucTemperature | 0x04); // set bit 2 high
  355. }
  356. else if (this->comboBox_P1BattTemp->Text->Equals("Hot")) // 101 = hot
  357. {
  358. LEVData->ucTemperature = (LEVData->ucTemperature & 0xF8); // clear the bits 0-2 only
  359. LEVData->ucTemperature = (LEVData->ucTemperature | 0x05); // set bits 0,2 high
  360. }
  361. }
  362. /**************************************************************************
  363. * LEVSensor::comboBox_P1MotorTemp_SelectedIndexChanged
  364. *
  365. * Updates the user selected battery motor setting
  366. *
  367. * returns: N/A
  368. *
  369. **************************************************************************/
  370. void LEVSensor::comboBox_P1MotorTemp_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  371. {
  372. UpdateMotorTemp();
  373. }
  374. /**************************************************************************
  375. * LEVSensor::UpdateMotorTemp
  376. *
  377. * Sets the Battery temperature, Page 3, Byte 3, bits 4-6
  378. *
  379. * returns: N/A
  380. *
  381. **************************************************************************/
  382. void LEVSensor::UpdateMotorTemp()
  383. {
  384. if (this->comboBox_P1MotorTemp->Text->Equals("Unknown")) // 000 = unknown
  385. {
  386. LEVData->ucTemperature = (LEVData->ucTemperature & 0x8F); // clear the bits 4-6 only
  387. }
  388. else if (this->comboBox_P1MotorTemp->Text->Equals("Cold")) // 001 = cold
  389. {
  390. LEVData->ucTemperature = (LEVData->ucTemperature & 0x8F); // clear the bits 4-6 only
  391. LEVData->ucTemperature = (LEVData->ucTemperature | (1 << 4)); // shift value up 4 to get into bits 4-6
  392. }
  393. else if (this->comboBox_P1MotorTemp->Text->Equals("Cold/Warm")) // 010 = cold/warm
  394. {
  395. LEVData->ucTemperature = (LEVData->ucTemperature & 0x8F); // clear the bits 4-6 only
  396. LEVData->ucTemperature = (LEVData->ucTemperature | (2 << 4)); // shift value up 4 to get into bits 4-6
  397. }
  398. else if (this->comboBox_P1MotorTemp->Text->Equals("Warm")) // 011 = warm
  399. {
  400. LEVData->ucTemperature = (LEVData->ucTemperature & 0x8F); // clear the bits 4-6 only
  401. LEVData->ucTemperature = (LEVData->ucTemperature | (3 << 4)); // shift value up 4 to get into bits 4-6
  402. }
  403. else if (this->comboBox_P1MotorTemp->Text->Equals("Warm/Hot")) // 100 = warm/hot
  404. {
  405. LEVData->ucTemperature = (LEVData->ucTemperature & 0x8F); // clear the bits 4-6 only
  406. LEVData->ucTemperature = (LEVData->ucTemperature | (4 << 4)); // shift value up 4 to get into bits 4-6
  407. }
  408. else if (this->comboBox_P1MotorTemp->Text->Equals("Hot")) // 101 = hot
  409. {
  410. LEVData->ucTemperature = (LEVData->ucTemperature & 0x8F); // clear the bits 4-6 only
  411. LEVData->ucTemperature = (LEVData->ucTemperature | (5 << 4)); // shift value up 4 to get into bits 4-6
  412. }
  413. }
  414. /**************************************************************************
  415. * LEVSensor::checkBox_P1BattOverheat_CheckedChanged
  416. *
  417. * Sets the battery overheat alert, Page 3, Byte 3, bit 3
  418. *
  419. * returns: N/A
  420. *
  421. **************************************************************************/
  422. void LEVSensor::checkBox_P1BattOverheat_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  423. {
  424. if (this->checkBox_P1BattOverheat->Checked == TRUE)
  425. LEVData->ucTemperature |= 0x08; // set bit 3 to 1
  426. else
  427. LEVData->ucTemperature &= (UCHAR)~0x08; // set bit 3 to 0
  428. }
  429. /**************************************************************************
  430. * LEVSensor::checkBox_P1MotorOverheat_CheckedChanged
  431. *
  432. * Sets the battery overheat alert, Page 3, Byte 3, bit 7
  433. *
  434. * returns: N/A
  435. *
  436. **************************************************************************/
  437. void LEVSensor::checkBox_P1MotorOverheat_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  438. {
  439. if (this->checkBox_P1MotorOverheat->Checked == TRUE)
  440. LEVData->ucTemperature |= 0x80; // set bit 7 to 1
  441. else
  442. LEVData->ucTemperature &= (UCHAR)~0x80; // set bit 7 to 0
  443. }
  444. /**************************************************************************
  445. * LEVSensor::checkBox_P1TempUnused_CheckedChanged
  446. *
  447. * Sets the temperature to "unused"
  448. * Page 3, Byte 3
  449. *
  450. * returns: N/A
  451. *
  452. **************************************************************************/
  453. void LEVSensor::checkBox_P1TempUnused_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  454. {
  455. if (this->checkBox_P1TempUnused->Checked == TRUE)
  456. {
  457. LEVData->ucTemperature = 0x00;
  458. comboBox_P1BattTemp->Enabled = FALSE;
  459. comboBox_P1MotorTemp->Enabled = FALSE;
  460. checkBox_P1BattOverheat->Enabled = FALSE;
  461. checkBox_P1MotorOverheat->Enabled = FALSE;
  462. }
  463. else
  464. {
  465. comboBox_P1BattTemp->Enabled = TRUE;
  466. comboBox_P1MotorTemp->Enabled = TRUE;
  467. checkBox_P1BattOverheat->Enabled = TRUE;
  468. checkBox_P1MotorOverheat->Enabled = TRUE;
  469. // recreate the byte based on UI
  470. UpdateMotorTemp();
  471. UpdateBatteryTemp();
  472. if (this->checkBox_P1MotorOverheat->Checked == TRUE)
  473. LEVData->ucTemperature |= 0x80; // set bit 7 to 1
  474. else
  475. LEVData->ucTemperature &= (UCHAR)~0x80; // set bit 7 to 0
  476. if (this->checkBox_P1BattOverheat->Checked == TRUE)
  477. LEVData->ucTemperature |= 0x08; // set bit 3 to 1
  478. else
  479. LEVData->ucTemperature &= (UCHAR)~0x08; // set bit 3 to 0
  480. }
  481. }
  482. /**************************************************************************
  483. * LEVSensor::comboBox_P1AssistLevel_SelectedIndexChanged
  484. *
  485. * Updates the user selected Current Assist Level
  486. *
  487. * returns: N/A
  488. *
  489. **************************************************************************/
  490. void LEVSensor::comboBox_P1AssistLevel_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  491. {
  492. CheckAssistMapping();
  493. }
  494. /**************************************************************************
  495. * LEVSensor::CheckAssistMapping
  496. *
  497. * Checks if the current Assist Level is consistent with the number of
  498. * supported Assist modes
  499. *
  500. * returns: N/A
  501. *
  502. **************************************************************************/
  503. void LEVSensor::CheckAssistMapping()
  504. {
  505. // Get the number of supported Assist Modes
  506. UCHAR SupportedAssistModes = ((LEVData->ucSupportedTravelModes & 0x38) >> 3);
  507. UCHAR CurrentAssistMode = ((LEVData->ucTravelModeState & 0x38) >> 3);
  508. // if Assist Off is selected, set the assist level to 000
  509. if(this->comboBox_P1AssistLevel->Text->Equals("Assist Off"))
  510. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  511. else if(SupportedAssistModes == 7)
  512. UpdateAssistModeState();
  513. else
  514. {
  515. // switch number of supported assist modes
  516. switch(SupportedAssistModes)
  517. {
  518. case 0x01: // 1 assist modes supported, selecting "Assist 7" acceptable
  519. // if anything other than "Assist Off" is selected, Send a messagebox with an error message
  520. if(!(this->comboBox_P1AssistLevel->Text->Equals("Assist 7")))
  521. {
  522. MessageBox::Show("The LEV supports 1 Assist Mode. Please select Assist 7 or Off");
  523. switch(CurrentAssistMode)
  524. {
  525. case 0x07:
  526. this->comboBox_P1AssistLevel->Text = "Assist 7";
  527. break;
  528. default:
  529. this->comboBox_P1AssistLevel->Text = "Assist Off";
  530. break;
  531. }
  532. }
  533. // if "Assist Off" was selected, it would have been caught in the above if statement
  534. else
  535. UpdateAssistModeState();
  536. break;
  537. case 0x02: // 2 assist modes supported, selecting "Assist 3" or "Assist 7" acceptable
  538. // if anything other than "Assist 3" or "Assist 7" is selected, send messagebox with error message
  539. if(!((this->comboBox_P1AssistLevel->Text->Equals("Assist 3")) || (this->comboBox_P1AssistLevel->Text->Equals("Assist 7"))))
  540. {
  541. MessageBox::Show("The LEV supports 2 Assist Modes. Please select Assist 3, 7 or Off");
  542. switch(CurrentAssistMode)
  543. {
  544. case 0x03:
  545. this->comboBox_P1AssistLevel->Text = "Assist 3";
  546. break;
  547. case 0x07:
  548. this->comboBox_P1AssistLevel->Text = "Assist 7";
  549. break;
  550. default:
  551. this->comboBox_P1AssistLevel->Text = "Assist Off";
  552. break;
  553. }
  554. }
  555. // if "Assist Off" was selected, it would have been caught in the above if statement
  556. else
  557. UpdateAssistModeState();
  558. break;
  559. case 0x03: // 3 Assist modes supported, selecting "Assist 2", "Assist 4" or "Assist 7" acceptable
  560. // if anything other than "Assist 2", "Assist 4", or "Assist 7" is selected, show messagebox with an error message
  561. if(!((this->comboBox_P1AssistLevel->Text->Equals("Assist 2")) || (this->comboBox_P1AssistLevel->Text->Equals("Assist 4")) || (this->comboBox_P1AssistLevel->Text->Equals("Assist 7"))))
  562. {
  563. MessageBox::Show("The LEV supports 3 Assist Modes. Please select Assist 2, 4, 7, or Off");
  564. switch(CurrentAssistMode)
  565. {
  566. case 0x02:
  567. this->comboBox_P1AssistLevel->Text = "Assist 2";
  568. break;
  569. case 0x04:
  570. this->comboBox_P1AssistLevel->Text = "Assist 4";
  571. break;
  572. case 0x07:
  573. this->comboBox_P1AssistLevel->Text = "Assist 7";
  574. break;
  575. default:
  576. this->comboBox_P1AssistLevel->Text = "Assist Off";
  577. break;
  578. }
  579. }
  580. // if "Assist Off" was selected, it would have been caught in the above if statement
  581. else
  582. UpdateAssistModeState();
  583. break;
  584. case 0x04: // 4 assist modes supported, selecting "Assist 2", "Assist 4" or "Assist 6" NOT acceptable
  585. // if "Assist 2", "Assist 4" or "Assist 6" selected, show messagebox with error message
  586. if((this->comboBox_P1AssistLevel->Text->Equals("Assist 2")) || (this->comboBox_P1AssistLevel->Text->Equals("Assist 4")) || (this->comboBox_P1AssistLevel->Text->Equals("Assist 6")))
  587. {
  588. MessageBox::Show("The LEV supports 4 Assist Modes. Please select Assist 1, 3, 5, 7, or Off");
  589. switch(CurrentAssistMode)
  590. {
  591. case 0x01:
  592. this->comboBox_P1AssistLevel->Text = "Assist 1";
  593. break;
  594. case 0x03:
  595. this->comboBox_P1AssistLevel->Text = "Assist 3";
  596. break;
  597. case 0x05:
  598. this->comboBox_P1AssistLevel->Text = "Assist 5";
  599. break;
  600. case 0x07:
  601. this->comboBox_P1AssistLevel->Text = "Assist 7";
  602. break;
  603. default:
  604. this->comboBox_P1AssistLevel->Text = "Assist Off";
  605. break;
  606. }
  607. }
  608. // if "Assist Off" selected, it would have been caught in the above if statement
  609. else
  610. UpdateAssistModeState();
  611. break;
  612. case 0x05: // 5 assist modes supported, selecting "Assist 4" or "Assist 6" NOT acceptable
  613. // if "Assist 4" or "Assist 6" selected, show messagebox with error message
  614. if((this->comboBox_P1AssistLevel->Text->Equals("Assist 4")) || (this->comboBox_P1AssistLevel->Text->Equals("Assist 6")))
  615. {
  616. MessageBox::Show("The LEV supports 5 Assist Modes. Please select Assist 1, 2, 3, 5, 7, or Off");
  617. switch(CurrentAssistMode)
  618. {
  619. case 0x01:
  620. this->comboBox_P1AssistLevel->Text = "Assist 1";
  621. break;
  622. case 0x02:
  623. this->comboBox_P1AssistLevel->Text = "Assist 2";
  624. break;
  625. case 0x03:
  626. this->comboBox_P1AssistLevel->Text = "Assist 3";
  627. break;
  628. case 0x05:
  629. this->comboBox_P1AssistLevel->Text = "Assist 5";
  630. break;
  631. case 0x07:
  632. this->comboBox_P1AssistLevel->Text = "Assist 7";
  633. break;
  634. default:
  635. this->comboBox_P1AssistLevel->Text = "Assist Off";
  636. break;
  637. }
  638. }
  639. // if "Assist Off" selected, it would have been caught in the above if statement
  640. else
  641. UpdateAssistModeState();
  642. break;
  643. case 0x06: // 6 assist modes supported, selecting "Assist 6" NOT acceptable
  644. // if "Assist 6" selected, show messagebox with error message
  645. if((this->comboBox_P1AssistLevel->Text->Equals("Assist 6")))
  646. {
  647. MessageBox::Show("The LEV supports 6 Assist Modes. Please select Assist 1, 2, 3, 4, 5, 7 or Off");
  648. switch(CurrentAssistMode)
  649. {
  650. case 0x01:
  651. this->comboBox_P1AssistLevel->Text = "Assist 1";
  652. break;
  653. case 0x02:
  654. this->comboBox_P1AssistLevel->Text = "Assist 2";
  655. break;
  656. case 0x03:
  657. this->comboBox_P1AssistLevel->Text = "Assist 3";
  658. break;
  659. case 0x04:
  660. this->comboBox_P1AssistLevel->Text = "Assist 4";
  661. break;
  662. case 0x05:
  663. this->comboBox_P1AssistLevel->Text = "Assist 5";
  664. break;
  665. case 0x07:
  666. this->comboBox_P1AssistLevel->Text = "Assist 7";
  667. break;
  668. default:
  669. this->comboBox_P1AssistLevel->Text = "Assist Off";
  670. break;
  671. }
  672. }
  673. // if "Assist Off" selected, it would have been caught in the above if statement
  674. else
  675. UpdateAssistModeState();
  676. break;
  677. default:
  678. // set Assist mode to off on default
  679. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  680. }
  681. }
  682. }
  683. /**************************************************************************
  684. * LEVSensor::UpdateAssistModeState
  685. *
  686. * Sets the Current Assist Level, Page 1, Byte 2, bits 3-5
  687. *
  688. * returns: N/A
  689. *
  690. **************************************************************************/
  691. void LEVSensor::UpdateAssistModeState()
  692. {
  693. if (this->comboBox_P1AssistLevel->Text->Equals("Assist 1")) // 001 = Assist 1
  694. {
  695. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear the bits 3-5 only
  696. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x08); // set bit 3 high
  697. }
  698. else if (this->comboBox_P1AssistLevel->Text->Equals("Assist 2")) // 010 = Assist 2
  699. {
  700. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear the bits 3-5 only
  701. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x10); // set bit 4 high
  702. }
  703. else if (this->comboBox_P1AssistLevel->Text->Equals("Assist 3")) // 011 = Assist 3
  704. {
  705. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear the bits 3-5 only
  706. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x18); // set bits 3,4 high
  707. }
  708. else if (this->comboBox_P1AssistLevel->Text->Equals("Assist 4")) // 100 = Assist 4
  709. {
  710. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear the bits 3-5 only
  711. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x20); // set bit 5 high
  712. }
  713. else if (this->comboBox_P1AssistLevel->Text->Equals("Assist 5")) // 101 = Assist 5
  714. {
  715. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear the bits 3-5 only
  716. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x28); // set bits 5,3 high
  717. }
  718. else if (this->comboBox_P1AssistLevel->Text->Equals("Assist 6")) // 110 = Assist 6
  719. {
  720. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear the bits 3-5 only
  721. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x30); // set bits 5,4 high
  722. }
  723. else if (this->comboBox_P1AssistLevel->Text->Equals("Assist 7")) // 111 = Assist 7
  724. {
  725. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear the bits 3-5 only
  726. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38); // set bits 5,4,3 high
  727. }
  728. }
  729. /**************************************************************************
  730. * LEVSensor::comboBox_P1RegenLevel_SelectedIndexChanged
  731. *
  732. * Updates the user selected Current Regen Level
  733. *
  734. * returns: N/A
  735. *
  736. **************************************************************************/
  737. void LEVSensor::comboBox_P1RegenLevel_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  738. {
  739. CheckRegenMapping();
  740. }
  741. /**************************************************************************
  742. * LEVSensor::CheckRegenMapping
  743. *
  744. * Checks if the current user selected Regen Level is consistent with the
  745. * number of supported Regen modes
  746. *
  747. * returns: N/A
  748. *
  749. **************************************************************************/
  750. void LEVSensor::CheckRegenMapping()
  751. {
  752. // Get the number of supported Regen Modes
  753. UCHAR SupportedRegenModes = (LEVData->ucSupportedTravelModes & 0x07);
  754. UCHAR CurrentRegen = (LEVData->ucTravelModeState & 0x07);
  755. // If Regen Off is selected, set the regen level to 000
  756. if(this->comboBox_P1RegenLevel->Text->Equals("Regenerative Off"))
  757. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  758. // If the number of supported Regen Modes is 7, there is no need to check Regen Mapping
  759. else if(SupportedRegenModes == 7)
  760. UpdateRegenModeState();
  761. else
  762. {
  763. // switch number of supported regen modes
  764. switch(SupportedRegenModes)
  765. {
  766. case 0x00: // No regen modes supported, only selecting "Regen Off" is acceptable
  767. // if anything other than "Regen Off" is selected, Send a messagebox with an error message
  768. if(!(this->comboBox_P1RegenLevel->Text->Equals("Regenerative Off")))
  769. {
  770. MessageBox::Show("The LEV does not support any Regenerative Modes. Please Select Regenerative Off");
  771. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  772. }
  773. // if "Regen Off" was selected, it would have been caught in the above if statement
  774. break;
  775. case 0x01: // 1 regen mode supported, selecting "Regen Off" or "Regen 7" acceptable
  776. // if anything other than "Regen 7" is selected, send messagebox with an error message
  777. if(!(this->comboBox_P1RegenLevel->Text->Equals("Regenerative 7")))
  778. {
  779. MessageBox::Show("The LEV supports 1 Regenerative Mode. Please select Regenerative 7 or Off");
  780. switch(CurrentRegen)
  781. {
  782. case 0x07:
  783. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  784. break;
  785. default:
  786. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  787. break;
  788. }
  789. }
  790. // update the regen mode, "Regen Off" case is caught in the above if statement
  791. else
  792. UpdateRegenModeState();
  793. break;
  794. case 0x02: // 2 regen modes supported, selecting "Regen Off", "Regen 3" or "Regen 7" acceptable
  795. // if anything other than "Regen 3" or "Regen 7" is selected, send messagebox with an error message
  796. if(!((this->comboBox_P1RegenLevel->Text->Equals("Regenerative 3")) || (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 7"))))
  797. {
  798. MessageBox::Show("The LEV supports 2 Regenerative Modes. Please select Regenerative 3, 7 or Off");
  799. switch(CurrentRegen)
  800. {
  801. case 0x03:
  802. this->comboBox_P1RegenLevel->Text = "Regenerative 3";
  803. break;
  804. case 0x07:
  805. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  806. break;
  807. default:
  808. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  809. break;
  810. }
  811. }
  812. // update the regen mode, "Regen Off" case is caught in the above if statement
  813. else
  814. UpdateRegenModeState();
  815. break;
  816. case 0x03: // 3 regen modes supported, selecting "Regen Off", "Regen 2", "Regen 4" or "Regen 7" acceptable
  817. // if anything other than "Regen 2", "Regen 4", or "Regen 7" is selected, send messagebox with an error message
  818. if(!((this->comboBox_P1RegenLevel->Text->Equals("Regenerative 2")) || (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 4")) || (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 7"))))
  819. {
  820. MessageBox::Show("The LEV supports 3 Regenerative Modes. Please select Regenerative 2, 4, 7, or Off");
  821. switch(CurrentRegen)
  822. {
  823. case 0x02:
  824. this->comboBox_P1RegenLevel->Text = "Regenerative 2";
  825. break;
  826. case 0x04:
  827. this->comboBox_P1RegenLevel->Text = "Regenerative 4";
  828. break;
  829. case 0x07:
  830. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  831. break;
  832. default:
  833. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  834. break;
  835. }
  836. }
  837. // update the regen mode, "Regen Off" case is caught in the above else if statement
  838. else
  839. UpdateRegenModeState();
  840. break;
  841. case 0x04: // 4 regen modes supported, selecting "Regen 2", "Regen 4", or "Regen 6" is NOT acceptable
  842. // if "Regen 2", "Regen 4" or "Regen 6" is selected, send messagebox with an errore message
  843. if((this->comboBox_P1RegenLevel->Text->Equals("Regenerative 2")) || (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 4")) || (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 6")))
  844. {
  845. MessageBox::Show("The LEV supports 4 Regenerative Modes. Please select Regenerative 1, 3, 5, 7, or Off");
  846. switch(CurrentRegen)
  847. {
  848. case 0x01:
  849. this->comboBox_P1RegenLevel->Text = "Regenerative 1";
  850. break;
  851. case 0x03:
  852. this->comboBox_P1RegenLevel->Text = "Regenerative 3";
  853. break;
  854. case 0x05:
  855. this->comboBox_P1RegenLevel->Text = "Regenerative 5";
  856. break;
  857. case 0x07:
  858. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  859. break;
  860. default:
  861. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  862. break;
  863. }
  864. }
  865. // update the regen mode, "Regen Off" case is caught in the above if statement
  866. else
  867. UpdateRegenModeState();
  868. break;
  869. case 0x05: // 5 regen modes supported, selecting "Regen 4" or "Regen 6" is NOT acceptable
  870. // if "Regen 4" or "Regen 6" is selected, send messagebox with an error message
  871. if((this->comboBox_P1RegenLevel->Text->Equals("Regenerative 4")) || (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 6")))
  872. {
  873. MessageBox::Show("The LEV supports 5 Regenerative Modes. Please select Regenerative 1, 2, 3, 5, 7, or Off");
  874. switch(CurrentRegen)
  875. {
  876. case 0x01:
  877. this->comboBox_P1RegenLevel->Text = "Regenerative 1";
  878. break;
  879. case 0x02:
  880. this->comboBox_P1RegenLevel->Text = "Regenerative 2";
  881. break;
  882. case 0x03:
  883. this->comboBox_P1RegenLevel->Text = "Regenerative 3";
  884. break;
  885. case 0x05:
  886. this->comboBox_P1RegenLevel->Text = "Regenerative 5";
  887. break;
  888. case 0x07:
  889. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  890. break;
  891. default:
  892. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  893. break;
  894. }
  895. }
  896. // update the regen mode, "Regen Off" is caught in the above if statement
  897. else
  898. UpdateRegenModeState();
  899. break;
  900. case 0x06: // 6 regen modes supported, selecting "Regen 6" is NOT acceptable
  901. // if "Regen 6" is selected, send messagebox with an error message
  902. if((this->comboBox_P1RegenLevel->Text->Equals("Regenerative 6")))
  903. {
  904. MessageBox::Show("The LEV supports 6 Regenerative Modes. Please select Regenerative 1, 2, 3, 4, 5, 7 or Off");
  905. switch(CurrentRegen)
  906. {
  907. case 0x01:
  908. this->comboBox_P1RegenLevel->Text = "Regenerative 1";
  909. break;
  910. case 0x02:
  911. this->comboBox_P1RegenLevel->Text = "Regenerative 2";
  912. break;
  913. case 0x03:
  914. this->comboBox_P1RegenLevel->Text = "Regenerative 3";
  915. break;
  916. case 0x04:
  917. this->comboBox_P1RegenLevel->Text = "Regenerative 4";
  918. break;
  919. case 0x05:
  920. this->comboBox_P1RegenLevel->Text = "Regenerative 5";
  921. break;
  922. case 0x07:
  923. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  924. break;
  925. default:
  926. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  927. break;
  928. }
  929. }
  930. // update the regen mode, "Regen Off" is caught in the above if statement
  931. else
  932. UpdateRegenModeState();
  933. break;
  934. default:
  935. // by default set TravelMode to 0
  936. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  937. }
  938. }
  939. }
  940. /**************************************************************************
  941. * LEVSensor::UpdateRegenModeState
  942. *
  943. * Sets the Current Regen Level, Page 1, Byte 2, bits 0-2
  944. *
  945. * returns: N/A
  946. *
  947. **************************************************************************/
  948. void LEVSensor::UpdateRegenModeState()
  949. {
  950. if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative Off")) // 000 = Regen Off
  951. {
  952. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  953. }
  954. else if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 1")) // 001 = Regen 1
  955. {
  956. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  957. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x01); // set bit 0 high
  958. }
  959. else if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 2")) // 010 = Regen 2
  960. {
  961. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  962. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x02); // set bit 1 high
  963. }
  964. else if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 3")) // 011 = Regen 3
  965. {
  966. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  967. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x03); // set bits 0,1 high
  968. }
  969. else if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 4")) // 100 = Regen 4
  970. {
  971. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  972. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x04); // set bit 2 high
  973. }
  974. else if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 5")) // 101 = Regen 5
  975. {
  976. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  977. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x05); // set bits 0,2 high
  978. }
  979. else if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 6")) // 110 = Regen 6
  980. {
  981. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  982. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x06); // set bits 2,1 high
  983. }
  984. else if (this->comboBox_P1RegenLevel->Text->Equals("Regenerative 7")) // 111 = Regen 7
  985. {
  986. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear the bits 0-2 only
  987. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07); // set bits 0,1,2 high
  988. }
  989. }
  990. /**************************************************************************
  991. * LEVSensor::checkBox_P1HighBeam_CheckedChanged
  992. *
  993. * Toggles the bit in the system state bitfield for high/low beam, page 1, byte 3, bit 2
  994. *
  995. * returns: N/A
  996. *
  997. **************************************************************************/
  998. void LEVSensor::checkBox_P1HighBeam_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  999. {
  1000. if (this->checkBox_P1HighBeam->Checked == TRUE)
  1001. LEVData->ucSystemState |= 0x04; // set bit 2 to 1
  1002. else
  1003. LEVData->ucSystemState &= (UCHAR)~0x04; // set bit 2 to 0
  1004. }
  1005. /**************************************************************************
  1006. * LEVSensor::checkBox_P1LightOn_CheckedChanged
  1007. *
  1008. * Toggles the bit in the system state bitfield for Light on/off, page 1, byte 3, bit 3
  1009. *
  1010. * returns: N/A
  1011. *
  1012. **************************************************************************/
  1013. void LEVSensor::checkBox_P1LightOn_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1014. {
  1015. if (this->checkBox_P1LightOn->Checked == TRUE)
  1016. LEVData->ucSystemState |= 0x08; // set bit 3 to 1
  1017. else
  1018. LEVData->ucSystemState &= (UCHAR)~0x08; // set bit 3 to 0
  1019. }
  1020. /**************************************************************************
  1021. * LEVSensor::checkBox_P1LeftSignalOn_CheckedChanged
  1022. *
  1023. * Toggles the bit in the system state bitfield for left signal on/off, page 1, byte 3, bit 1
  1024. *
  1025. * returns: N/A
  1026. *
  1027. **************************************************************************/
  1028. void LEVSensor::checkBox_P1LeftSignalOn_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1029. {
  1030. if (this->checkBox_P1LeftSignalOn->Checked == TRUE)
  1031. LEVData->ucSystemState |= 0x02; // set bit 1 to 1
  1032. else
  1033. LEVData->ucSystemState &= (UCHAR)~0x02; // set bit 1 to 0
  1034. }
  1035. /**************************************************************************
  1036. * LEVSensor::checkBox_P1RightSignalOn_CheckedChanged
  1037. *
  1038. * Toggles the bit in the system state bitfield for right signal on/off, page 1, byte 3, bit 0
  1039. *
  1040. * returns: N/A
  1041. *
  1042. **************************************************************************/
  1043. void LEVSensor::checkBox_P1RightSignalOn_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1044. {
  1045. if (this->checkBox_P1RightSignalOn->Checked == TRUE)
  1046. LEVData->ucSystemState |= 0x01; // set bit 0 to 1
  1047. else
  1048. LEVData->ucSystemState &= (UCHAR)~0x01; // set bit 0 to 0
  1049. }
  1050. /**************************************************************************
  1051. * LEVSensor::checkBox_P1Throttle_CheckedChanged
  1052. *
  1053. * Toggles the bit in the system state bitfield for right signal on/off, page 1, byte 3, bit 0
  1054. *
  1055. * returns: N/A
  1056. *
  1057. **************************************************************************/
  1058. void LEVSensor::checkBox_P1Throttle_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1059. {
  1060. if (this->checkBox_P1Throttle->Checked == TRUE)
  1061. LEVData->ucSystemState |= 0x10; // set bit 4 to 1
  1062. else
  1063. LEVData->ucSystemState &= (UCHAR)~0x10; // set bit 4 to 0
  1064. }
  1065. /**************************************************************************
  1066. * LEVSensor::comboBox_P1FrontGear_SelectedIndexChanged
  1067. *
  1068. * Updates the user selected Front Gear Setting
  1069. *
  1070. * returns: N/A
  1071. *
  1072. **************************************************************************/
  1073. void LEVSensor::comboBox_P1FrontGear_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  1074. {
  1075. UpdateFrontGearState();
  1076. }
  1077. /**************************************************************************
  1078. * LEVSensor::UpdateFrontGearState
  1079. *
  1080. * Sets the Front Gear Setting, Page 1, Byte 4, bits 0-1
  1081. *
  1082. * returns: N/A
  1083. *
  1084. **************************************************************************/
  1085. void LEVSensor::UpdateFrontGearState()
  1086. {
  1087. if (this->comboBox_P1FrontGear->Text->Equals("none")) // 00 = no gear
  1088. {
  1089. LEVData->ucGearState = (LEVData->ucGearState & 0xFC); // clear the bits 0-1 only
  1090. }
  1091. else if (this->comboBox_P1FrontGear->Text->Equals("1")) // 01 = gear 1
  1092. {
  1093. LEVData->ucGearState = (LEVData->ucGearState & 0xFC); // clear the bits 0-1 only
  1094. LEVData->ucGearState = (LEVData->ucGearState | 0x01); // set bit 0 high
  1095. }
  1096. else if (this->comboBox_P1FrontGear->Text->Equals("2")) // 10 = gear 2
  1097. {
  1098. LEVData->ucGearState = (LEVData->ucGearState & 0xFC); // clear the bits 0-1 only
  1099. LEVData->ucGearState = (LEVData->ucGearState | 0x02); // set bit 1 high
  1100. }
  1101. else if (this->comboBox_P1FrontGear->Text->Equals("3")) // 11 = gear 3
  1102. {
  1103. LEVData->ucGearState = (LEVData->ucGearState & 0xFC); // clear the bits 0-1 only
  1104. LEVData->ucGearState = (LEVData->ucGearState | 0x03); // set bits 0,1 high
  1105. }
  1106. }
  1107. /**************************************************************************
  1108. * LEVSensor::comboBox_P1RearGear_SelectedIndexChanged
  1109. *
  1110. * Updates the user selected Rear Gear Setting
  1111. *
  1112. * returns: N/A
  1113. *
  1114. **************************************************************************/
  1115. void LEVSensor::comboBox_P1RearGear_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  1116. {
  1117. UpdateRearGearState();
  1118. }
  1119. /**************************************************************************
  1120. * LEVSensor::UpdateRearGearState
  1121. *
  1122. * Sets the Front Rear Setting, Page 1, Byte 4, bits 2-5
  1123. *
  1124. * returns: N/A
  1125. *
  1126. **************************************************************************/
  1127. void LEVSensor::UpdateRearGearState()
  1128. {
  1129. if (this->comboBox_P1RearGear->Text->Equals("none")) // 0000 = no gear
  1130. {
  1131. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1132. }
  1133. else if (this->comboBox_P1RearGear->Text->Equals("1")) // 0001 = gear 1
  1134. {
  1135. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1136. LEVData->ucGearState = (LEVData->ucGearState | (1 << 2)); // shift value up 2 to get into bits 2-5
  1137. }
  1138. else if (this->comboBox_P1RearGear->Text->Equals("2")) // 0010 = gear 2
  1139. {
  1140. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1141. LEVData->ucGearState = (LEVData->ucGearState | (2 << 2)); // shift value up 2 to get into bits 2-5
  1142. }
  1143. else if (this->comboBox_P1RearGear->Text->Equals("3")) // 0011 = gear 3
  1144. {
  1145. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1146. LEVData->ucGearState = (LEVData->ucGearState | (3 << 2)); // shift value up 2 to get into bits 2-5
  1147. }
  1148. else if (this->comboBox_P1RearGear->Text->Equals("4")) // 0100 = gear 4
  1149. {
  1150. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1151. LEVData->ucGearState = (LEVData->ucGearState | (4 << 2)); // shift value up 2 to get into bits 2-5
  1152. }
  1153. else if (this->comboBox_P1RearGear->Text->Equals("5")) // 0101 = gear 5
  1154. {
  1155. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1156. LEVData->ucGearState = (LEVData->ucGearState | (5 << 2)); // shift value up 2 to get into bits 2-5
  1157. }
  1158. else if (this->comboBox_P1RearGear->Text->Equals("6")) // 0110 = gear 6
  1159. {
  1160. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1161. LEVData->ucGearState = (LEVData->ucGearState | (6 << 2)); // shift value up 2 to get into bits 2-5
  1162. }
  1163. else if (this->comboBox_P1RearGear->Text->Equals("7")) // 0111 = gear 7
  1164. {
  1165. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1166. LEVData->ucGearState = (LEVData->ucGearState | (7 << 2)); // shift value up 2 to get into bits 2-5
  1167. }
  1168. else if (this->comboBox_P1RearGear->Text->Equals("8")) // 1000 = gear 8
  1169. {
  1170. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1171. LEVData->ucGearState = (LEVData->ucGearState | (8 << 2)); // shift value up 2 to get into bits 2-5
  1172. }
  1173. else if (this->comboBox_P1RearGear->Text->Equals("9")) // 1001 = gear 9
  1174. {
  1175. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1176. LEVData->ucGearState = (LEVData->ucGearState | (9 << 2)); // shift value up 2 to get into bits 2-5
  1177. }
  1178. else if (this->comboBox_P1RearGear->Text->Equals("10")) // 1010 = gear 10
  1179. {
  1180. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1181. LEVData->ucGearState = (LEVData->ucGearState | (10 << 2)); // shift value up 2 to get into bits 2-5
  1182. }
  1183. else if (this->comboBox_P1RearGear->Text->Equals("11")) // 1011 = gear 11
  1184. {
  1185. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1186. LEVData->ucGearState = (LEVData->ucGearState | (11 << 2)); // shift value up 2 to get into bits 2-5
  1187. }
  1188. else if (this->comboBox_P1RearGear->Text->Equals("12")) // 1100 = gear 12
  1189. {
  1190. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1191. LEVData->ucGearState = (LEVData->ucGearState | (12 << 2)); // shift value up 2 to get into bits 2-5
  1192. }
  1193. else if (this->comboBox_P1RearGear->Text->Equals("13")) // 1101 = gear 13
  1194. {
  1195. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1196. LEVData->ucGearState = (LEVData->ucGearState | (13 << 2)); // shift value up 2 to get into bits 2-5
  1197. }
  1198. else if (this->comboBox_P1RearGear->Text->Equals("14")) // 1110 = gear 14
  1199. {
  1200. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1201. LEVData->ucGearState = (LEVData->ucGearState | (14 << 2)); // shift value up 2 to get into bits 2-5
  1202. }
  1203. else if (this->comboBox_P1RearGear->Text->Equals("15")) // 1111 = gear 15
  1204. {
  1205. LEVData->ucGearState = (LEVData->ucGearState & 0xC3); // clear the bits 2-5 only
  1206. LEVData->ucGearState = (LEVData->ucGearState | (15 << 2)); // shift value up 2 to get into bits 2-5
  1207. }
  1208. }
  1209. /**************************************************************************
  1210. * LEVSensor::checkBox_P1GearsExist_CheckedChanged
  1211. *
  1212. * Toggles the bit in the gear state bitfield for selecting whether gears exist or not
  1213. * Page 1, Byte 4, bit 7
  1214. *
  1215. * returns: N/A
  1216. *
  1217. **************************************************************************/
  1218. void LEVSensor::checkBox_P1GearsExist_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1219. {
  1220. if (this->checkBox_P1GearsExist->Checked == TRUE)
  1221. LEVData->ucGearState |= 0x80; // set bit 7 to 1
  1222. else
  1223. LEVData->ucGearState &= (UCHAR)~0x80; // set bit 7 to 0
  1224. }
  1225. /**************************************************************************
  1226. * LEVSensor::checkBox_P1ManualGears_CheckedChanged
  1227. *
  1228. * Toggles the bit in the gear state bitfield for selecting whether gear control is auto or manual
  1229. * Page 1, Byte 4, bit 6
  1230. *
  1231. * returns: N/A
  1232. *
  1233. **************************************************************************/
  1234. void LEVSensor::checkBox_P1ManualGears_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1235. {
  1236. if (this->checkBox_P1ManualGears->Checked == TRUE)
  1237. LEVData->ucGearState |= 0x40; // set bit 6 to 1
  1238. else
  1239. LEVData->ucGearState &= (UCHAR)~0x40; // set bit 6 to 0
  1240. }
  1241. /**************************************************************************
  1242. * LEVSensor::radioButton_CheckedChanged
  1243. *
  1244. * Single event handler for all of the radio buttons on the error page
  1245. * Changes the error field to the appropriate value, Pgae 1, Byte 5
  1246. *
  1247. * returns: N/A
  1248. *
  1249. **************************************************************************/
  1250. void LEVSensor::radioButton_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1251. {
  1252. if (radioButton_P1NoError->Checked == TRUE)
  1253. {
  1254. numericUpDown_P1CustomError->Enabled = FALSE;
  1255. LEVData->ucErrorMessage = 0x00;
  1256. }
  1257. else if (radioButton_P1BatteryError->Checked == TRUE)
  1258. {
  1259. numericUpDown_P1CustomError->Enabled = FALSE;
  1260. LEVData->ucErrorMessage = 0x01;
  1261. }
  1262. else if (radioButton_P1TrainError->Checked == TRUE)
  1263. {
  1264. numericUpDown_P1CustomError->Enabled = FALSE;
  1265. LEVData->ucErrorMessage = 0x02;
  1266. }
  1267. else if (radioButton_P1EndLife->Checked == TRUE)
  1268. {
  1269. numericUpDown_P1CustomError->Enabled = FALSE;
  1270. LEVData->ucErrorMessage = 0x03;
  1271. }
  1272. else if (radioButton_P1Overheat->Checked == TRUE)
  1273. {
  1274. numericUpDown_P1CustomError->Enabled = FALSE;
  1275. LEVData->ucErrorMessage = 0x04;
  1276. }
  1277. else if (radioButton_P1CustomError->Checked == TRUE)
  1278. {
  1279. numericUpDown_P1CustomError->Enabled = TRUE;
  1280. LEVData->ucErrorMessage = System::Convert::ToByte(this->numericUpDown_P1CustomError->Value);
  1281. }
  1282. }
  1283. /**************************************************************************
  1284. * LEVSensor::numericUpDown_P1CustomError_ValueChanged
  1285. *
  1286. * Page 1, Byte 5, Selects a custom error code to use. UI locks the range
  1287. *
  1288. * returns: N/A
  1289. *
  1290. **************************************************************************/
  1291. void LEVSensor::numericUpDown_P1CustomError_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1292. {
  1293. LEVData->ucErrorMessage = (System::Convert::ToByte(this->numericUpDown_P1CustomError->Value));
  1294. }
  1295. /**************************************************************************
  1296. * LEVSensor::numericUpDown_P1Speed_ValueChanged
  1297. *
  1298. * Page 1, Byte 6 and 7. Changes to the user selected LEV speed
  1299. * This value is shared by page 1 and page 2, so both must be changed
  1300. *
  1301. * returns: N/A
  1302. *
  1303. **************************************************************************/
  1304. void LEVSensor::numericUpDown_P1Speed_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1305. {
  1306. // UI locks the range to valid numbers only
  1307. LEVData->usCurrentLEVSpeed = System::Convert::ToUInt16(this->numericUpDown_P1Speed->Value * 10);
  1308. LEVData->usCurrentLEVSpeed |= 0xF000;
  1309. LEVData->usSpeed = System::Convert::ToUInt16(this->numericUpDown_P1Speed->Value * 10);
  1310. LEVData->usSpeed |= 0xF000;
  1311. // update the Page 2 UI (note the other event handler fires if they are diffent)
  1312. numericUpDown_P2Speed->Value = numericUpDown_P1Speed->Value;
  1313. }
  1314. /**************************************************************************
  1315. * LEVSensor::numericUpDown_P2Speed_ValueChanged
  1316. *
  1317. * Page 2, Byte 6 and 7. Changes to the user selected LEV speed
  1318. * This value is shared by page 1 and page 2, so both must be changed
  1319. *
  1320. * returns: N/A
  1321. *
  1322. **************************************************************************/
  1323. void LEVSensor::numericUpDown_P2Speed_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1324. {
  1325. // UI locks the range to valid numbers only
  1326. LEVData->usCurrentLEVSpeed = System::Convert::ToUInt16(this->numericUpDown_P2Speed->Value * 10);
  1327. LEVData->usCurrentLEVSpeed |= 0xF000;
  1328. LEVData->usSpeed = System::Convert::ToUInt16(this->numericUpDown_P1Speed->Value * 10);
  1329. LEVData->usSpeed |= 0xF000;
  1330. // update the Page 1 UI (note the other event handler fires if they are diffent)
  1331. numericUpDown_P1Speed->Value = numericUpDown_P2Speed->Value;
  1332. //MessageBox::Show("usCurrentLEVSpeed " + LEVData->usCurrentLEVSpeed.ToString(), "Speed Error", MessageBoxButtons::OK,MessageBoxIcon::Error, MessageBoxDefaultButton::Button1);
  1333. //MessageBox::Show("ulNewSpeed " + ulNewSpeed.ToString(), "Speed Error", MessageBoxButtons::OK,MessageBoxIcon::Error, MessageBoxDefaultButton::Button1);
  1334. }
  1335. /**************************************************************************
  1336. * LEVSensor::button_P2UpdateDist_Click
  1337. *
  1338. * Validates and updates cumulative distance, from user input (GUI)
  1339. *
  1340. * returns: N/A
  1341. *
  1342. **************************************************************************/
  1343. void LEVSensor::button_P2UpdateDist_Click(System::Object^ sender, System::EventArgs^ e)
  1344. {
  1345. this->label_P2UpdateError->Visible = false;
  1346. //convert and catch failed conversions
  1347. try{
  1348. //LEVData->ulOdometer = (ULONG) System::Convert::ToInt32(this->textBox_P2TotDistChange->Text);
  1349. //dbDispAcumDist = System::Convert::ToDouble(this->textBox_P2TotDistChange->Text);
  1350. LEVData->ulOdometer = System::Convert::ToInt32(this->numericUpDown_P2Distance->Value);
  1351. LEVData->ulP34Odometer = System::Convert::ToInt32(this->numericUpDown_P2Distance->Value);
  1352. dbDispAcumDist = System::Convert::ToDouble(numericUpDown_P2Distance->Value);
  1353. this->label_P2TotDistDisplay->Text = System::Convert::ToString(this->numericUpDown_P2Distance->Value);
  1354. }
  1355. catch(...){
  1356. this->label_P2UpdateError->Text = "Error: Dist";
  1357. this->label_P2UpdateError->Visible = true;
  1358. }
  1359. }
  1360. /**************************************************************************
  1361. * LEVSensor::numericUpDown_P2Range_ValueChanged
  1362. *
  1363. * Page 3, Byte 6,7. Changes the user selected battery range, range locked by UI
  1364. *
  1365. * returns: N/A
  1366. *
  1367. **************************************************************************/
  1368. void LEVSensor::numericUpDown_P2Range_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1369. {
  1370. LEVData->usRemainingRange = (System::Convert::ToUInt16(this->numericUpDown_P2Range->Value));
  1371. LEVData->usRemainingRange |= 0xF000;
  1372. }
  1373. /**************************************************************************
  1374. * LEVSensor::checkBox_P2RangeUnused_CheckedChanged
  1375. *
  1376. * Sets the temperature to "unused"
  1377. * Page 3, Byte 3
  1378. *
  1379. * returns: N/A
  1380. *
  1381. **************************************************************************/
  1382. void LEVSensor::checkBox_P2RangeUnused_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1383. {
  1384. if (this->checkBox_P2RangeUnused->Checked == TRUE)
  1385. {
  1386. LEVData->usRemainingRange = 0xF000;
  1387. numericUpDown_P2Range->Enabled = FALSE;
  1388. }
  1389. else
  1390. {
  1391. numericUpDown_P2Range->Enabled = TRUE;
  1392. LEVData->usRemainingRange = (System::Convert::ToUInt16(this->numericUpDown_P2Range->Value));
  1393. LEVData->usRemainingRange |= 0xF000;
  1394. }
  1395. }
  1396. /**************************************************************************
  1397. * LEVSensor::numericUpDown_P3PercentAssist_ValueChanged
  1398. *
  1399. * Page 2, Byte 2. Changes the user selected % assist (0-100%)
  1400. *
  1401. * returns: N/A
  1402. *
  1403. **************************************************************************/
  1404. void LEVSensor::numericUpDown_P3PercentAssist_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1405. {
  1406. LEVData->ucPercentAssist = (System::Convert::ToByte(this->numericUpDown_P3PercentAssist->Value));
  1407. }
  1408. /**************************************************************************
  1409. * LEVSensor::numericUpDown_P3Charge_ValueChanged
  1410. *
  1411. * Page 3, Byte 4. Changes the user selected battery charge, range locked by UI
  1412. *
  1413. * returns: N/A
  1414. *
  1415. **************************************************************************/
  1416. void LEVSensor::numericUpDown_P3Charge_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1417. {
  1418. // preserve bit 7
  1419. if ((LEVData->ucBatteryCharge & 0x80) != 0) // check if bit 7 high
  1420. {
  1421. LEVData->ucBatteryCharge = (System::Convert::ToByte(this->numericUpDown_P3Charge->Value));
  1422. LEVData->ucBatteryCharge |= 0x80; // set bit 7 to 1
  1423. }
  1424. else
  1425. LEVData->ucBatteryCharge = (System::Convert::ToByte(this->numericUpDown_P3Charge->Value));
  1426. }
  1427. /**************************************************************************
  1428. * LEVSensor::checkBox_P3BattEmpty_CheckedChanged
  1429. *
  1430. * Sets the temperature to "unused"
  1431. * Page 3, Byte 3
  1432. *
  1433. * returns: N/A
  1434. *
  1435. **************************************************************************/
  1436. void LEVSensor::checkBox_P3BattEmpty_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1437. {
  1438. if (this->checkBox_P3BattEmpty->Checked == TRUE)
  1439. LEVData->ucBatteryCharge |= 0x80; // set bit 7 to 1
  1440. else
  1441. LEVData->ucBatteryCharge &= (UCHAR)~0x80; // set bit 7 to 0
  1442. }
  1443. /**************************************************************************
  1444. * LEVSensor::numericUpDown_P4Voltage_ValueChanged
  1445. *
  1446. * Page 3, Byte 5. Changes the user selected battery voltage, range locked by UI
  1447. *
  1448. * returns: N/A
  1449. *
  1450. **************************************************************************/
  1451. void LEVSensor::numericUpDown_P4Voltage_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1452. {
  1453. LEVData->ucBatteryVoltage = (System::Convert::ToByte(this->numericUpDown_P4Voltage->Value));
  1454. }
  1455. /**************************************************************************
  1456. * LEVSensor::checkBox_P4VoltUnused_CheckedChanged
  1457. *
  1458. * Sets the temperature to "unused"
  1459. * Page 3, Byte 3
  1460. *
  1461. * returns: N/A
  1462. *
  1463. **************************************************************************/
  1464. void LEVSensor::checkBox_P4VoltUnused_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1465. {
  1466. if (this->checkBox_P4VoltUnused->Checked == TRUE)
  1467. {
  1468. LEVData->ucBatteryVoltage = 0x00;
  1469. numericUpDown_P4Voltage->Enabled = FALSE;
  1470. }
  1471. else
  1472. {
  1473. numericUpDown_P4Voltage->Enabled = TRUE;
  1474. LEVData->ucBatteryVoltage = (System::Convert::ToByte(this->numericUpDown_P4Voltage->Value));
  1475. }
  1476. }
  1477. /**************************************************************************
  1478. * LEVSensor::numericUpDown_P4DistanceOnCharge_ValueChanged
  1479. *
  1480. * Page 4, Bytes 6-7. Changes the distance on charge value, range locked by UI
  1481. *
  1482. * returns: N/A
  1483. *
  1484. **************************************************************************/
  1485. void LEVSensor::numericUpDown_P4DistanceOnCharge_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1486. {
  1487. LEVData->usDistanceOnCharge = System::Convert::ToUInt16(this->numericUpDown_P4DistanceOnCharge->Value * 10);
  1488. }
  1489. /**************************************************************************
  1490. * LEVSensor::checkBox_P4DistanceOnChargeUnused_CheckChanged
  1491. *
  1492. * Page 4, Bytes 6-7 Updates if Distance on Current Charge is used or note
  1493. *
  1494. * returns: N/A
  1495. *
  1496. **************************************************************************/
  1497. void LEVSensor::checkBox_P4DistanceOnChargeUnused_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1498. {
  1499. if(this->checkBox_P4DistanceOnChargeUnused->Checked == TRUE)
  1500. {
  1501. this->numericUpDown_P4DistanceOnCharge->Enabled = FALSE;
  1502. LEVData->usDistanceOnCharge &= 0x0000;
  1503. }
  1504. else
  1505. {
  1506. this->numericUpDown_P4DistanceOnCharge->Enabled = TRUE;
  1507. LEVData->usDistanceOnCharge = System::Convert::ToUInt16(this->numericUpDown_P4DistanceOnCharge->Value * 10);
  1508. }
  1509. }
  1510. /**************************************************************************
  1511. * LEVSensor::numericUpDown_P4FuelConsumption_ValueChanged
  1512. *
  1513. * Page 4, Bytes 3.5-4 Changes the fuel consumption value, range locked by UI
  1514. *
  1515. * returns: N/A
  1516. *
  1517. **************************************************************************/
  1518. void LEVSensor::numericUpDown_P4FuelConsumption_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1519. {
  1520. LEVData->usFuelConsumption = System::Convert::ToUInt16(this->numericUpDown_P4FuelConsumption->Value * 10);
  1521. LEVData->usP34FuelConsumption = System::Convert::ToUInt16(this->numericUpDown_P4FuelConsumption->Value * 10);
  1522. }
  1523. /**************************************************************************
  1524. * LEVSensor::checkBox_P4FuelConsumptionUnused_CheckChanged
  1525. *
  1526. * Page 4, Bytes 3.5-4 Updates if Fuel Consumption is used or not
  1527. *
  1528. * returns: N/A
  1529. *
  1530. **************************************************************************/
  1531. void LEVSensor::checkBox_P4FuelConsumptionUnused_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1532. {
  1533. if(this->checkBox_P4FuelConsumptionUnused->Checked == TRUE)
  1534. {
  1535. this->numericUpDown_P4FuelConsumption->Enabled = FALSE;
  1536. LEVData->usFuelConsumption &= 0xF000;
  1537. LEVData->usP34FuelConsumption &= 0xF000;
  1538. }
  1539. else
  1540. {
  1541. this->numericUpDown_P4FuelConsumption->Enabled = TRUE;
  1542. LEVData->usFuelConsumption |= System::Convert::ToUInt16(this->numericUpDown_P4FuelConsumption->Value * 10);
  1543. LEVData->usP34FuelConsumption |= System::Convert::ToUInt16(this->numericUpDown_P4FuelConsumption->Value * 10);
  1544. }
  1545. }
  1546. /**************************************************************************
  1547. * LEVSensor::numericUpDown_P4ChargeCycle_ValueChanged
  1548. *
  1549. * Page 4, Bytes 2-3.5 Changes the number of Charge cycles, range is locked by UI
  1550. *
  1551. * returns: N/A
  1552. *
  1553. **************************************************************************/
  1554. void LEVSensor::numericUpDown_P4ChargeCycle_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1555. {
  1556. LEVData->usChargeCycleCount = System::Convert::ToUInt16(this->numericUpDown_P4ChargeCycle->Value);
  1557. }
  1558. /**************************************************************************
  1559. * LEVSensor::checkBox_P4ChargeCycleUnused_CheckedChanged
  1560. *
  1561. * Page 4, Byte 2-3.5 Updates if Charge Cycle is Used or Not
  1562. *
  1563. * returns: N/A
  1564. *
  1565. **************************************************************************/
  1566. void LEVSensor::checkBox_P4ChargeCycleUnused_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1567. {
  1568. if(this->checkBox_P4ChargeCycleUnused->Checked == TRUE)
  1569. {
  1570. this->numericUpDown_P4ChargeCycle->Enabled = FALSE;
  1571. LEVData->usChargeCycleCount &= 0xF000;
  1572. }
  1573. else
  1574. {
  1575. this->numericUpDown_P4ChargeCycle->Enabled = TRUE;
  1576. LEVData->usChargeCycleCount |= System::Convert::ToUInt16(this->numericUpDown_P4ChargeCycle->Value);
  1577. }
  1578. }
  1579. /**************************************************************************
  1580. * LEVSensor::numericUpDwn_P5AssistModes_ValueChanged
  1581. *
  1582. * Page 1, Byte 1, Bits 3-5. Changes the number of Assist Modes Supported (0-7)
  1583. * in the Travel Modes Supported Byte
  1584. *
  1585. * returns: N/A
  1586. *
  1587. **************************************************************************/
  1588. void LEVSensor::numericUpDwn_P5AssistModes_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1589. {
  1590. UCHAR tempHolder;
  1591. // shift the number to the left 3 times to put into bits 3-5
  1592. tempHolder = (System::Convert::ToByte(this->numericUpDwn_P5AssistModes->Value) << 3);
  1593. LEVData->ucSupportedTravelModes = (LEVData->ucSupportedTravelModes & 0xC7); // first need to clear the bits 3-5 only
  1594. LEVData->ucSupportedTravelModes = (LEVData->ucSupportedTravelModes | tempHolder); // then combine with what is already be present in the full variable
  1595. UpdateP1Assist();
  1596. }
  1597. /**************************************************************************
  1598. * LEVSensor::UpdateP1Assist
  1599. *
  1600. * Handles Assist Mode mapping when the number of supported assist modes is changed
  1601. *
  1602. * returns: N/A
  1603. *
  1604. **************************************************************************/
  1605. void LEVSensor::UpdateP1Assist()
  1606. {
  1607. // get the number of assist modes currently in Page 5
  1608. UCHAR SupportedAssist = ((LEVData->ucSupportedTravelModes & 0x38) >> 3);
  1609. UCHAR CurrentAssist = ((LEVData->ucTravelModeState & 0x38) >> 3);
  1610. if(SupportedAssist == 1) // LEV supports 1 AssistMode
  1611. {
  1612. switch(CurrentAssist)
  1613. {
  1614. case 0: // "Assist Off" is common to all mapping, nothing needs to be done
  1615. break;
  1616. default: // if the current Assist mode is not Off, change the page 16 data to Assist mode 7 and change the combobox index
  1617. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1618. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38);
  1619. this->comboBox_P1AssistLevel->Text = "Assist 7";
  1620. break;
  1621. }
  1622. }
  1623. else if(SupportedAssist == 2) // LEV supports 2 AssistModes
  1624. {
  1625. switch(CurrentAssist)
  1626. {
  1627. case 1:
  1628. case 2:
  1629. case 3: // if Assist mode is 1, 2, or 3 ensure page 16 data is Assist mode 3 and change combobox index
  1630. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1631. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x18);
  1632. this->comboBox_P1AssistLevel->Text = "Assist 3";
  1633. break;
  1634. case 4:
  1635. case 5:
  1636. case 6:
  1637. case 7: // if Assist mode is 4, 5, 6, or 7 ensure page 16 data is Assist mode 7 and change combobox index
  1638. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1639. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38);
  1640. this->comboBox_P1AssistLevel->Text = "Assist 7";
  1641. break;
  1642. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1643. break;
  1644. }
  1645. }
  1646. else if(SupportedAssist == 3) // LEV supports 3 Assist Modes
  1647. {
  1648. switch(CurrentAssist)
  1649. {
  1650. case 1:
  1651. case 2: // if Assist mode is 1, or 2, ensure page 16 data is Assist mode 2 and change combobox index
  1652. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1653. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x10);
  1654. this->comboBox_P1AssistLevel->Text = "Assist 2";
  1655. break;
  1656. case 3:
  1657. case 4: // if the current Assist mode is 3 or 4, ensure page 16 data is Assist mode 4 and change combobox index
  1658. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1659. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x20);
  1660. this->comboBox_P1AssistLevel->Text = "Assist 4";
  1661. break;
  1662. case 5:
  1663. case 6:
  1664. case 7: // if the current Assist mode is 5, 6, or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1665. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1666. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38);
  1667. this->comboBox_P1AssistLevel->Text = "Assist 7";
  1668. break;
  1669. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1670. break;
  1671. }
  1672. }
  1673. else if(SupportedAssist == 4) // LEV supports 4 Assist Modes
  1674. {
  1675. switch(CurrentAssist)
  1676. {
  1677. case 1: // if the current Assist mode is 1, ensure page 16 data is Assist mode 1
  1678. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1679. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x08);
  1680. break;
  1681. case 2:
  1682. case 3: // if the current Assist mode is 2 or 3, ensure page 16 data is Assist mode 3 and change combobox index
  1683. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1684. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x18);
  1685. this->comboBox_P1AssistLevel->Text = "Assist 3";
  1686. break;
  1687. case 4:
  1688. case 5: // if the current Assist mode is 4 or 5, ensure page 16 data is Assist mode 5 and change combobox index
  1689. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1690. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x28);
  1691. this->comboBox_P1AssistLevel->Text = "Assist 5";
  1692. break;
  1693. case 6:
  1694. case 7: // if the current Assist mode is 6 or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1695. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1696. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38);
  1697. this->comboBox_P1AssistLevel->Text = "Assist 7";
  1698. break;
  1699. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1700. break;
  1701. }
  1702. }
  1703. else if(SupportedAssist== 5) // LEV supports 5 Assist Modes
  1704. {
  1705. switch(CurrentAssist)
  1706. {
  1707. case 1: // if the current Assist mode is 1, ensure page 16 data is Assist mode 1
  1708. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1709. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x08);
  1710. break;
  1711. case 2: // if the current Assist mode is 2, ensure page 16 data is Assist mode 2
  1712. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1713. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x10);
  1714. break;
  1715. case 3: // if the current Assist mode is 3, ensure page 16 data is Assist mode 3
  1716. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode & 0xC7);
  1717. LEVData->ucP16TravelMode = (LEVData->ucP16TravelMode | 0x18);
  1718. break;
  1719. case 4:
  1720. case 5: // if the current Assist mode is 4 or 5, ensure page 16 data is Assist mode 5 and change combobox index
  1721. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1722. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x28);
  1723. this->comboBox_P1AssistLevel->Text = "Assist 5";
  1724. break;
  1725. case 6:
  1726. case 7: // if the current Assist mode is 6 or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1727. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1728. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38);
  1729. this->comboBox_P1AssistLevel->Text = "Assist 7";
  1730. break;
  1731. default: // "Assist Off" is common to call mapping, nothing needs to be done
  1732. break;
  1733. }
  1734. }
  1735. else if(SupportedAssist == 6) // LEV supports 6 Assist Modes
  1736. {
  1737. switch(CurrentAssist)
  1738. {
  1739. case 1: // if the currentAssistmode is 1, ensure page 16 data is Assist mode 1
  1740. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1741. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x08);
  1742. break;
  1743. case 2: // if the current Assist mode is 2, ensure page 16 data is Assist mode 2
  1744. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1745. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x10);
  1746. break;
  1747. case 3: // if the current Assist mode is 3, ensure page 16 data is Assist mode 3
  1748. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1749. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x18);
  1750. break;
  1751. case 4: // if the current Assist mode is 4, ensure page 16 data is Assist mode 4
  1752. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1753. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x20);
  1754. break;
  1755. case 5: // if the current Assist mode is 5, ensure page 16 data is Assist mode 5
  1756. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1757. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x28);
  1758. break;
  1759. case 6:
  1760. case 7: // if the current Assist mode is 6 or 7, ensure page 16 data is Assist mode 7 and change combobox index
  1761. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7);
  1762. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38);
  1763. this->comboBox_P1AssistLevel->Text = "Assist 7";
  1764. break;
  1765. default: // "Assist Off" is common to all mapping, nothing needs to be done
  1766. break;
  1767. }
  1768. }
  1769. }
  1770. /**************************************************************************
  1771. * LEVSensor::numericUpDown_P5RegenModes_ValueChanged
  1772. *
  1773. * Page 1, Byte 1, Bits 0-2. Changes the number of Regen Modes Supported (0-7)
  1774. * in the Travel Modes Supported Byte
  1775. *
  1776. * returns: N/A
  1777. *
  1778. **************************************************************************/
  1779. void LEVSensor::numericUpDown_P5RegenModes_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1780. {
  1781. UCHAR tempHolder;
  1782. tempHolder = System::Convert::ToByte(this->numericUpDown_P5RegenModes->Value);
  1783. LEVData->ucSupportedTravelModes = (LEVData->ucSupportedTravelModes & 0xF8); // first need to clear the bits 0-2 only
  1784. LEVData->ucSupportedTravelModes = (LEVData->ucSupportedTravelModes | tempHolder); // then combine with what is already be present in the full variable
  1785. UpdateP1Regen();
  1786. }
  1787. /**************************************************************************
  1788. * LEVSensor::UpdateP1Regen
  1789. *
  1790. * Handles Regen Mode mapping when the number of supported regen modes is changed
  1791. *
  1792. * returns: N/A
  1793. *
  1794. **************************************************************************/
  1795. void LEVSensor::UpdateP1Regen()
  1796. {
  1797. // get the number of Regen modes currently in Page 5
  1798. UCHAR SupportedRegen = LEVData->ucSupportedTravelModes & 0x07;
  1799. UCHAR CurrentRegen = LEVData->ucTravelModeState & 0x07;
  1800. if(SupportedRegen == 0)
  1801. { // if the LEV doesn't support Regen Modes, set Page 16 data to regen mode 0 and update the combobox
  1802. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1803. this->comboBox_P1RegenLevel->Text = "Regenerative Off";
  1804. }
  1805. else if(SupportedRegen == 1) // LEV supports 1 Regen Mode
  1806. {
  1807. switch(CurrentRegen)
  1808. {
  1809. case 0: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1810. break;
  1811. default: // if the current regen mode is not Off, change the page 16 data to regen mode 7 and change the combobox index
  1812. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1813. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07);
  1814. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  1815. break;
  1816. }
  1817. }
  1818. else if(SupportedRegen == 2) // LEV supports 2 Regen Modes
  1819. {
  1820. switch(CurrentRegen)
  1821. {
  1822. case 1:
  1823. case 2:
  1824. case 3: // if regen mode is 1, 2, or 3 ensure page 16 data is regen mode 3 and change combobox index
  1825. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1826. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x03);
  1827. this->comboBox_P1RegenLevel->Text = "Regenerative 3";
  1828. break;
  1829. case 4:
  1830. case 5:
  1831. case 6:
  1832. case 7: // if regen mode is 4, 5, 6, or 7 ensure page 16 data is regen mode 7 and change combobox index
  1833. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1834. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07);
  1835. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  1836. break;
  1837. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1838. break;
  1839. }
  1840. }
  1841. else if(SupportedRegen == 3) // LEV supports 3 Regen Modes
  1842. {
  1843. switch(CurrentRegen)
  1844. {
  1845. case 1:
  1846. case 2: // if regen mode is 1, or 2, ensure page 16 data is regen mode 2 and change combobox index
  1847. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1848. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x02);
  1849. this->comboBox_P1RegenLevel->Text = "Regenerative 2";
  1850. break;
  1851. case 3:
  1852. case 4: // if the current regen mode is 3 or 4, ensure page 16 data is regen mode 4 and change combobox index
  1853. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1854. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x04);
  1855. this->comboBox_P1RegenLevel->Text = "Regenerative 4";
  1856. break;
  1857. case 5:
  1858. case 6:
  1859. case 7: // if the current regen mode is 5, 6, or 7, ensure page 16 data is regen mode 7 and change combobox index
  1860. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1861. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07);
  1862. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  1863. break;
  1864. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1865. break;
  1866. }
  1867. }
  1868. else if(SupportedRegen == 4) // LEV supports 4 Regen Modes
  1869. {
  1870. switch(CurrentRegen)
  1871. {
  1872. case 1: // if the current regen mode is 1, ensure page 16 data is regen mode 1
  1873. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1874. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x01);
  1875. break;
  1876. case 2:
  1877. case 3: // if the current regen mode is 2 or 3, ensure page 16 data is regen mode 3 and change combobox index
  1878. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1879. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x03);
  1880. this->comboBox_P1RegenLevel->Text = "Regenerative 3";
  1881. break;
  1882. case 4:
  1883. case 5: // if the current regen mode is 4 or 5, ensure page 16 data is regen mode 5 and change combobox index
  1884. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1885. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x05);
  1886. this->comboBox_P1RegenLevel->Text = "Regenerative 5";
  1887. break;
  1888. case 6:
  1889. case 7: // if the current regen mode is 6 or 7, ensure page 16 data is regen mode 7 and change combobox index
  1890. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1891. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07);
  1892. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  1893. break;
  1894. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1895. break;
  1896. }
  1897. }
  1898. else if(SupportedRegen == 5) // LEV supports 5 Regen Modes
  1899. {
  1900. switch(CurrentRegen)
  1901. {
  1902. case 1: // if the current regen mode is 1, ensure page 16 data is regen mode 1
  1903. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1904. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x01);
  1905. break;
  1906. case 2: // if the current regen mode is 2, ensure page 16 data is regen mode 2
  1907. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1908. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x02);
  1909. break;
  1910. case 3: // if the current regen mode is 3, ensure page 16 data is regen mode 3
  1911. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1912. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x03);
  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->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1917. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x05);
  1918. this->comboBox_P1RegenLevel->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->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1923. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07);
  1924. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  1925. break;
  1926. default: // "Regenerative Off" is common to call mapping, nothing needs to be done
  1927. break;
  1928. }
  1929. }
  1930. else if(SupportedRegen == 6) // LEV supports 6 Regen Modes
  1931. {
  1932. switch(CurrentRegen)
  1933. {
  1934. case 1: // if the current regen mode is 1, ensure page 16 data is regen mode 1
  1935. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1936. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x01);
  1937. break;
  1938. case 2: // if the current regen mode is 2, ensure page 16 data is regen mode 2
  1939. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1940. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x02);
  1941. break;
  1942. case 3: // if the current regen mode is 3, ensure page 16 data is regen mode 3
  1943. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1944. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x03);
  1945. break;
  1946. case 4: // if the current regen mode is 4, ensure page 16 data is regen mode 4
  1947. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1948. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x04);
  1949. break;
  1950. case 5: // if the current regen mode is 5, ensure page 16 data is regen mode 5
  1951. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1952. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x05);
  1953. break;
  1954. case 6:
  1955. case 7: // if the current regen mode is 6 or 7, ensure page 16 data is regen mode 7 and change combobox index
  1956. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8);
  1957. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07);
  1958. this->comboBox_P1RegenLevel->Text = "Regenerative 7";
  1959. break;
  1960. default: // "Regenerative Off" is common to all mapping, nothing needs to be done
  1961. break;
  1962. }
  1963. }
  1964. }
  1965. /**************************************************************************
  1966. * LEVSensor::numericUpDown_P5Circum_ValueChanged
  1967. *
  1968. * Page 5, Bytes 3-4.5 Changes the wheel circumference value, range is locked by UI
  1969. *
  1970. * returns: N/A
  1971. *
  1972. **************************************************************************/
  1973. void LEVSensor::numericUpDown_P5Circum_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  1974. {
  1975. LEVData->usWheelCircumference = System::Convert::ToUInt16(this->numericUpDown_P5Circum->Value);
  1976. LEVData->usWheelCircumference |= 0xF000;
  1977. }
  1978. /**************************************************************************
  1979. * LEVSensor::checkBox_P16Supported_CheckedChanged
  1980. *
  1981. * Selects whether incoming P16s should be processed or not
  1982. *
  1983. * returns: N/A
  1984. *
  1985. **************************************************************************/
  1986. void LEVSensor::checkBox_P16Supported_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  1987. {
  1988. if (this->checkBox_P16Supported->Checked == TRUE)
  1989. bPage16Supported = TRUE;
  1990. else
  1991. bPage16Supported = FALSE;
  1992. }
  1993. /**************************************************************************
  1994. * LEVSensor::button_CommonUpdate_Click
  1995. *
  1996. * Adjusts the global pages 80 and 81 via the GUI
  1997. *
  1998. * returns: N/A
  1999. *
  2000. **************************************************************************/
  2001. void LEVSensor::button_CommonUpdate_Click(System::Object^ sender, System::EventArgs^ e)
  2002. {
  2003. // required common pages
  2004. //commonData->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNum->Text);
  2005. //commonData->ucSwVersion = System::Convert::ToByte(this->textBox_SwVersion->Text);
  2006. //commonData->ucHwVersion = System::Convert::ToByte(this->textBox_HwVersion->Text);
  2007. //commonData->usMfgID = System::Convert::ToUInt16(this->textBox_MfgID->Text);
  2008. //commonData->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNum->Text);
  2009. label_ErrorCommon->Visible = false;
  2010. label_ErrorCommon->Text = "Error: ";
  2011. // Convert and catch failed conversions
  2012. try{
  2013. commonDataSensor->usMfgID = System::Convert::ToUInt16(this->textBox_MfgID->Text);
  2014. }
  2015. catch(...){
  2016. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " MFID");
  2017. label_ErrorCommon->Visible = true;
  2018. }
  2019. try{
  2020. if(this->checkBox_NoSerial->Checked)
  2021. commonDataSensor->ulSerialNum = 0xFFFFFFFF;
  2022. else
  2023. commonDataSensor->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNum->Text);
  2024. }
  2025. catch(...){
  2026. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " Ser#");
  2027. label_ErrorCommon->Visible = true;
  2028. }
  2029. try{
  2030. commonDataSensor->ucHwVersion = System::Convert::ToByte(this->textBox_HwVersion->Text);
  2031. }
  2032. catch(...){
  2033. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " HWVr");
  2034. label_ErrorCommon->Visible = true;
  2035. }
  2036. try{
  2037. commonDataSensor->ucSwVersion = System::Convert::ToByte(this->textBox_SwVersion->Text);
  2038. }
  2039. catch(...){
  2040. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " SWVr");
  2041. label_ErrorCommon->Visible = true;
  2042. }
  2043. try{
  2044. commonDataSensor->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNum->Text);
  2045. }
  2046. catch(...){
  2047. label_ErrorCommon->Text = System::String::Concat(label_ErrorCommon->Text, " Mdl#");
  2048. label_ErrorCommon->Visible = true;
  2049. }
  2050. }
  2051. /**************************************************************************
  2052. * LEVSensor::checkBox_P5WheelCircum_CheckChanged
  2053. *
  2054. * Page 5 Bytes 3-4.5 Updates if Wheel Circumference is used or not
  2055. *
  2056. * returns: N/A
  2057. *
  2058. **************************************************************************/
  2059. void LEVSensor::checkBox_P5WheelCircum_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  2060. {
  2061. if(this->checkBox_P5WheelCircum->Checked == TRUE)
  2062. {
  2063. this->numericUpDown_P5Circum->Enabled = FALSE;
  2064. LEVData->usWheelCircumference &= 0xF000; // set wheel circumference to 0 to indicate unused
  2065. }
  2066. else
  2067. {
  2068. this->numericUpDown_P5Circum->Enabled = TRUE;
  2069. LEVData->usWheelCircumference = System::Convert::ToUInt16(this->numericUpDown_P5Circum->Value);
  2070. LEVData->usWheelCircumference |= 0xF000;
  2071. }
  2072. }
  2073. //MessageBox::Show("ucSystemState " + LEVData->ucSystemState.ToString(), "Speed Error", MessageBoxButtons::OK,MessageBoxIcon::Error, MessageBoxDefaultButton::Button1);
  2074. //MessageBox::Show("ucSupportedTravelModes " + LEVData->ucSupportedTravelModes.ToString() + " tempHolder" + tempHolder.ToString(), "Speed Error", MessageBoxButtons::OK,MessageBoxIcon::Error, MessageBoxDefaultButton::Button1);
  2075. //LEVData->ucSupportedTravelModes = System::Convert::ToByte(this->numericUpDwn_P5AssistModes->Value);
  2076. /**************************************************************************
  2077. * LEVSensor::MapAssistModes
  2078. *
  2079. * Adjusts the Assist Mode received in page 16 depending on the number of Modes supported on page 5
  2080. *
  2081. * returns: N/A
  2082. *
  2083. **************************************************************************/
  2084. void LEVSensor::MapAssistModes()
  2085. {
  2086. //Get the number of Assist Modes requested/set by Display in Page 16
  2087. UCHAR AssistMode = ((LEVData->ucP16TravelMode & 0x38) >> 3);
  2088. //Get the number of Assist Modes Supported by the LEV
  2089. UCHAR SupportedModes = ((LEVData->ucSupportedTravelModes & 0x38) >> 3);
  2090. if(SupportedModes == 1) // LEV supports 1 Assist Mode
  2091. {
  2092. if(AssistMode) // map requested assist modes 1,2,3,4,5,6,7 to LEV assist mode 7
  2093. {
  2094. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2095. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38); // set bits 3-5 high (xx 111 xxx)
  2096. }
  2097. else // No mapping required for incoming assist mode 0
  2098. LEVData->ucTravelModeState &= 0xC7; // set bits 3-5 low (xx 000 xxx)
  2099. }
  2100. else if(SupportedModes == 2) // LEV supports 2 Assist Modes
  2101. {
  2102. if(AssistMode == 1 || AssistMode == 2 || AssistMode == 3) // map requested assist modes 1,2,3 to LEV assist mode 3
  2103. {
  2104. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2105. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x18); // set bits 3-4 high (xx 011 xxx)
  2106. }
  2107. else if(AssistMode == 0) // No mapping required for incoming assist mode 0
  2108. {
  2109. LEVData->ucTravelModeState &= 0xC7; // set bits 3-5 low (xx 000 xxx)
  2110. }
  2111. else // map requested assist modes 4,5,6,7 to LEV assist mode 7
  2112. {
  2113. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2114. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38); // set bits 3-5 high (xx 111 xxx)
  2115. }
  2116. }
  2117. else if(SupportedModes == 3) // LEV supports 3 Assist Modes
  2118. {
  2119. if(AssistMode == 1 || AssistMode == 2) // map requeseted assist modes 1,2 to LEV assist mode 2
  2120. {
  2121. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2122. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x10); // set bit 4 high (xx 010 xxx)
  2123. }
  2124. else if(AssistMode == 3 || AssistMode == 4) // map requested assist modes 3,4 to LEV assist mode 4
  2125. {
  2126. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2127. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x20); // set bit 5 high (xx 100 xxx)
  2128. }
  2129. else if(AssistMode == 0) // No mapping required for incoming assist mode 0
  2130. {
  2131. LEVData->ucTravelModeState &= 0xC7; // set bits 3-5 low (xx 000 xxx)
  2132. }
  2133. else // map requested assist modes 5,6,7 to LEV assist mode 7
  2134. {
  2135. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2136. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38); // set bits 3-5 high (xx 111 xxx)
  2137. }
  2138. }
  2139. else if(SupportedModes == 4) // LEV supports 4 Assist Modes
  2140. {
  2141. if(AssistMode == 0 || AssistMode == 1) // No mapping required for incoming assist modes 0, 1
  2142. {
  2143. LEVData->ucTravelModeState &= 0xC7; // set bits 3-5 low (xx 000 xxx)
  2144. if(AssistMode == 1) // if assist mode 1
  2145. LEVData->ucTravelModeState |= 0x08; // set bit 3 high (xx 001 xxx)
  2146. }
  2147. else if(AssistMode == 2 || AssistMode == 3) // map incoming assist modes 2,3 to LEV assist mode 3
  2148. {
  2149. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2150. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x18); // set bits 3-4 high (xx 011 xxx)
  2151. }
  2152. else if(AssistMode == 4 || AssistMode == 5) // map incoming assist modes 4, 5 to LEV assist mode 5
  2153. {
  2154. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2155. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x28); // set bits 3 and 5 high (xx 101 xxx)
  2156. }
  2157. else // map incoming assist modes 6,7 to LEV assist mode 7
  2158. {
  2159. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2160. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38); // set bits 3-5 high (xx 111 xxx)
  2161. }
  2162. }
  2163. else if(SupportedModes == 5) // LEV supports 5 Assist Modes
  2164. {
  2165. if(AssistMode == 0 || AssistMode == 1 || AssistMode == 2 || AssistMode == 3) // No mapping required for incoming assist modes 0,1,2,3
  2166. {
  2167. LEVData->ucTravelModeState &= 0xC7; // set bits 3-5 low (xx 000 xxx)
  2168. if(AssistMode == 1) // if assist mode 1
  2169. LEVData->ucTravelModeState |= 0x08; // set bit 3 high (xx 001 xxx)
  2170. else if(AssistMode == 2) // if assist mode 2
  2171. LEVData->ucTravelModeState |= 0x10; // set bit 4 high (xx 010 xxx)
  2172. else if(AssistMode == 3) // if assist mode 3
  2173. LEVData->ucTravelModeState |= 0x18; // set bits 3-4 high (xx 011 xxx)
  2174. }
  2175. else if(AssistMode == 4 || AssistMode == 5) // map incoming assist modes 4,5 to LEV assist mode 5
  2176. {
  2177. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2178. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x28); // set bits 3 and 5 high (xx 101 xxx)
  2179. }
  2180. else // map incoming assist modes 6,7 to LEV assist mode 7
  2181. {
  2182. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2183. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38); // set bits 3-5 high (xx 111 xxx)
  2184. }
  2185. }
  2186. else if(SupportedModes == 6) // LEV supports 6 Assist Modes
  2187. {
  2188. if(AssistMode == 0 || AssistMode == 1 || AssistMode == 2 || AssistMode == 3 || AssistMode == 4 || AssistMode == 5) // No mapping required for incoming assist modes 0,1,2,3,4,5
  2189. {
  2190. LEVData->ucTravelModeState &= 0xC7; // set bits 3-5 low (xx 000 xxx)
  2191. if(AssistMode == 1) // if assist mode 1
  2192. LEVData->ucTravelModeState |= 0x08; // set bit 3 high (xx 001 xxx)
  2193. else if(AssistMode == 2) // if assist mode 2
  2194. LEVData->ucTravelModeState |= 0x10; // set bit 4 high (xx 010 xxx)
  2195. else if(AssistMode == 3) // if assist mode 3
  2196. LEVData->ucTravelModeState |= 0x18; // set bits 3-4 high (xx 011 xxx)
  2197. else if(AssistMode == 4) // if assist mode 4
  2198. LEVData->ucTravelModeState |= 0x20; // set bit 5 high (xx 100 xxx)
  2199. else if(AssistMode == 5) // if assist mode 5
  2200. LEVData->ucTravelModeState |= 0x28; // set bits 3 and 5 high (xx 101 xxx)
  2201. }
  2202. else // map incoming assist modes 6,7 to assist mode 7
  2203. {
  2204. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xC7); // clear bits 3-5
  2205. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x38); // set bits 3-5 high (xx 111 xxx)
  2206. }
  2207. }
  2208. else
  2209. {
  2210. LEVData->ucTravelModeState &= 0xC7; // set bits 3-5 low (xx 000 xxx)
  2211. if(AssistMode == 1) // if assist mode 1
  2212. LEVData->ucTravelModeState |= 0x08; // set bit 3 high (xx 001 xxx)
  2213. else if(AssistMode == 2) // if assist mode 2
  2214. LEVData->ucTravelModeState |= 0x10; // set bit 4 high (xx 010 xxx)
  2215. else if(AssistMode == 3) // if assist mode 3
  2216. LEVData->ucTravelModeState |= 0x18; // set bits 3-4 high (xx 011 xxx)
  2217. else if(AssistMode == 4) // if assist mode 4
  2218. LEVData->ucTravelModeState |= 0x20; // set bit 5 high (xx 100 xxx)
  2219. else if(AssistMode == 5) // if assist mode 5
  2220. LEVData->ucTravelModeState |= 0x28; // set bits 3 and 5 high (xx 101 xxx)
  2221. else if(AssistMode == 6) // if assist mode 6
  2222. LEVData->ucTravelModeState |= 0x30; // set bits 4 and 5 high (xx 110 xxx)
  2223. else if(AssistMode == 7) // if assist mode 7
  2224. LEVData->ucTravelModeState |= 0x38; // set bits 3-5 high (xx 111 xxx)
  2225. }
  2226. }
  2227. /**************************************************************************
  2228. * LEVSensor::MapRegenModes
  2229. *
  2230. * Adjusts the Regen Mode received in page 16 depending on the number of Modes supported on page 5
  2231. *
  2232. * returns: N/A
  2233. *
  2234. **************************************************************************/
  2235. void LEVSensor::MapRegenModes()
  2236. {
  2237. //Get the number of Regen Modes requested/set by Display in Page 16
  2238. UCHAR RegenMode = (LEVData->ucP16TravelMode & 0x07);
  2239. //Get the number of Regen Modes Supported by the LEV
  2240. UCHAR SupportedModes = LEVData->ucSupportedTravelModes & 0x07;
  2241. if(SupportedModes == 0) // No Regen Modes are Supported
  2242. {
  2243. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // All incoming modes map to 0
  2244. }
  2245. else if(SupportedModes == 1) // LEV supports 1 Regen Mode
  2246. {
  2247. if(RegenMode) // map requested regen modes 1,2,3,4,5,6,7 to regen mode 7
  2248. {
  2249. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2250. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07); // set bits 0-2 high ( xx xxx 111)
  2251. }
  2252. else // No mapping required for incoming assist mode 0
  2253. LEVData->ucTravelModeState = LEVData->ucP16TravelMode; // these match exactly in this case
  2254. }
  2255. else if(SupportedModes == 2) // LEV supports 2 Regen Modes
  2256. {
  2257. if(RegenMode == 1 || RegenMode == 2 || RegenMode == 3) // map requested regen modes 1,2,3 to LEV regen mode 3
  2258. {
  2259. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2260. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x03); // set bits 0-1 high (xx xxx 011)
  2261. }
  2262. else if(RegenMode == 0) // No mapping required for incoming regen mode 0
  2263. {
  2264. LEVData->ucTravelModeState = LEVData->ucP16TravelMode; // these match exactly in this case
  2265. }
  2266. else // map requested regen modes 4,5,6,7 to LEV regen mode 7
  2267. {
  2268. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2269. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07); // set bits 0-2 high (xx xxx 111)
  2270. }
  2271. }
  2272. else if(SupportedModes == 3) // LEV supports 3 Regen Modes
  2273. {
  2274. if(RegenMode == 1 || RegenMode == 2) // map requeseted regen modes 1,2 to LEV regen mode 2
  2275. {
  2276. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2277. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x02); // set bit 1 high (xx xxx 010)
  2278. }
  2279. else if(RegenMode == 3 || RegenMode == 4) // map requested regen modes 3,4 to LEV regen mode 4
  2280. {
  2281. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2282. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x04); // set bit 2 high (xx xxx 100)
  2283. }
  2284. else if(RegenMode == 0) // No mapping required for incoming regen mode 0
  2285. {
  2286. LEVData->ucTravelModeState = LEVData->ucP16TravelMode; //these match exactly in this case
  2287. }
  2288. else // map requested regen modes 5,6,7 to LEV regen mode 7
  2289. {
  2290. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2291. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07); // set bits 0-2 high (xx xxx 111)
  2292. }
  2293. }
  2294. else if(SupportedModes == 4) // LEV supports 4 Regen Modes
  2295. {
  2296. if(RegenMode == 0 || RegenMode == 1) // No mapping required for incoming regen modes 0, 1
  2297. {
  2298. LEVData->ucTravelModeState &= 0xF8; // set bits 0-2 low (xx xxx 000)
  2299. if(RegenMode == 1) // if regen mode 1
  2300. LEVData->ucTravelModeState |= 0x01; // set bit 0 high (xx xxx 001)
  2301. }
  2302. else if(RegenMode == 2 || RegenMode == 3) // map incoming regen modes 2,3 to LEV regen mode 3
  2303. {
  2304. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2305. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x03); // set bits 0-1 high (xx xxx 011)
  2306. }
  2307. else if(RegenMode == 4 || RegenMode == 5) // map incoming regen modes 4, 5 to LEV regen mode 5
  2308. {
  2309. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2310. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x05); // set bits 0 and 2 high (xx xxx 101)
  2311. }
  2312. else // map incoming regen modes 6,7 to LEV regen mode 7
  2313. {
  2314. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2315. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07); // set bits 0-2 high (xx xxx 111)
  2316. }
  2317. }
  2318. else if(SupportedModes == 5) // LEV supports 5 Regen Modes
  2319. {
  2320. if(RegenMode == 0 || RegenMode == 1 || RegenMode == 2 || RegenMode == 3) // No mapping required for incoming regen modes 0,1,2,3
  2321. {
  2322. LEVData->ucTravelModeState &= 0xF8; // set bits 0-2 low (xx xxx 000)
  2323. if(RegenMode == 1) // if regen mode 1
  2324. LEVData->ucTravelModeState |= 0x01; // set bit 0 high (xx xxx 001)
  2325. else if(RegenMode == 2) // if regen mode 2
  2326. LEVData->ucTravelModeState |= 0x02; // set bit 1 high (xx xxx 010)
  2327. else if(RegenMode == 3) // if regen mode 3
  2328. LEVData->ucTravelModeState |= 0x03; // set bits 0-1 high (xx xxx 011)
  2329. }
  2330. else if(RegenMode == 4 || RegenMode == 5) // map incoming regen modes 4,5 to LEV regen mode 5
  2331. {
  2332. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2333. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x05); // set bits 0 and 2 high (xx xxx 101)
  2334. }
  2335. else // map incoming regen modes 6,7 to LEV regen mode 7
  2336. {
  2337. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2338. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07); // set bits 0-2 high (xx xxx 111)
  2339. }
  2340. }
  2341. else if(SupportedModes == 6) // LEV supports 6 Regen Modes
  2342. {
  2343. if(RegenMode == 0 || RegenMode == 1 || RegenMode == 2 || RegenMode == 3 || RegenMode == 4 || RegenMode == 5) // No mapping required for incoming regen modes 0,1,2,3,4,5
  2344. {
  2345. LEVData->ucTravelModeState &= 0xF8; // set bits 0-2 low (xx xxx 000)
  2346. if(RegenMode == 1) // if regen mode 1
  2347. LEVData->ucTravelModeState |= 0x01; // set bit 0 high (xx xxx 001)
  2348. else if(RegenMode == 2) // if regen mode 2
  2349. LEVData->ucTravelModeState |= 0x02; // set bit 1 high (xx xxx 010)
  2350. else if(RegenMode == 3) // if regen mode 3
  2351. LEVData->ucTravelModeState |= 0x03; // set bits 0-1 high (xx xxx 011)
  2352. else if(RegenMode == 4) // if regen mode 4
  2353. LEVData->ucTravelModeState |= 0x04; // set bit 2 high (xx xxx 100)
  2354. else if(RegenMode == 5) // if regen mode 5
  2355. LEVData->ucTravelModeState |= 0x05; // set bits 0 and 2 high (xx xxx 101)
  2356. }
  2357. else // map incoming regen modes 6,7 to regen mode 7
  2358. {
  2359. LEVData->ucTravelModeState = (LEVData->ucTravelModeState & 0xF8); // clear bits 0-2
  2360. LEVData->ucTravelModeState = (LEVData->ucTravelModeState | 0x07); // set bits 0-2 high (xx xxx 111)
  2361. }
  2362. }
  2363. else
  2364. {
  2365. LEVData->ucTravelModeState &= 0xF8; // set bits 0-2 low (xx xxx 000)
  2366. if(RegenMode == 1) // if regen mode 1
  2367. LEVData->ucTravelModeState |= 0x01; // set bit 0 high (xx xxx 001)
  2368. else if(RegenMode == 2) // if regen mode 2
  2369. LEVData->ucTravelModeState |= 0x02; // set bit 1 high (xx xxx 010)
  2370. else if(RegenMode == 3) // if regen mode 3
  2371. LEVData->ucTravelModeState |= 0x03; // set bits 0-1 high (xx xxx 011)
  2372. else if(RegenMode == 4) // if regen mode 4
  2373. LEVData->ucTravelModeState |= 0x04; // set bit 2 high (xx xxx 100)
  2374. else if(RegenMode == 5) // if regen mode 5
  2375. LEVData->ucTravelModeState |= 0x05; // set bits 0 and 2 high (xx xxx 101)
  2376. else if(RegenMode == 6) // if regen mode 6
  2377. LEVData->ucTravelModeState |= 0x06; // set bits 1 and 2 high (xx xxx 110)
  2378. else if(RegenMode == 7) // if regen mode 7
  2379. LEVData->ucTravelModeState |= 0x07; // set bits 0-2 high (xx xxx 111)
  2380. }
  2381. }
  2382. void LEVSensor::checkBox_UsePage34_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  2383. {
  2384. if(this->checkBox_UsePage34->Checked)
  2385. bTxPage34 = TRUE;
  2386. else
  2387. bTxPage34 = FALSE;
  2388. }
  2389. void LEVSensor::checkBox_NoSerial_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  2390. {
  2391. if(this->checkBox_NoSerial->Checked)
  2392. this->textBox_SerialNum->Enabled = false;
  2393. else
  2394. this->textBox_SerialNum->Enabled = true;
  2395. }