The Code Repository for the REV0 Steering Wheel.
Dependencies: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
Steering.cpp@39:e6aa6dcf3f75, 2015-02-08 (annotated)
- Committer:
- tmccurbin
- Date:
- Sun Feb 08 05:47:05 2015 +0000
- Revision:
- 39:e6aa6dcf3f75
- Parent:
- 38:d04a430d7fe3
- Child:
- 40:92f08fdc32df
Fixed filters. Implemented thresholds for variable updates.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kiran_mbed | 0:313541d8f8be | 1 | #include "Steering.h" |
kiran_mbed | 0:313541d8f8be | 2 | |
tmccurbin | 36:8544a8900884 | 3 | // To-Do: |
tmccurbin | 38:d04a430d7fe3 | 4 | // Look at SYS management CAN translations: shutdown switches, DCDC status, & IMD (this is a resistance, in ohms) |
tmccurbin | 38:d04a430d7fe3 | 5 | // Figure out screen/variable updating options (hardware filter), NVIC_SetPriority(CAN_IRQn,####)LPC17xx.h |
tmccurbin | 36:8544a8900884 | 6 | // Firgure out fault protocall |
tmccurbin | 36:8544a8900884 | 7 | |
tmccurbin | 36:8544a8900884 | 8 | void Init(); |
tmccurbin | 36:8544a8900884 | 9 | void ProcessButtons(void const *args); |
tmccurbin | 36:8544a8900884 | 10 | void RequestStatusChange(); |
tmccurbin | 36:8544a8900884 | 11 | void ResetSteeringWheel(); |
tmccurbin | 36:8544a8900884 | 12 | void ResetCar(); |
tmccurbin | 36:8544a8900884 | 13 | void ProcessCANMsg(CANMessage& msg); |
tmccurbin | 36:8544a8900884 | 14 | void UpdateDisplay(); |
tmccurbin | 36:8544a8900884 | 15 | void ProcessButtons(void const *args); |
tmccurbin | 36:8544a8900884 | 16 | void ConnectedStatusCANMsg(); |
tmccurbin | 36:8544a8900884 | 17 | |
tmccurbin | 36:8544a8900884 | 18 | float CANFloat; |
tmccurbin | 36:8544a8900884 | 19 | float CANFloat2; |
tmccurbin | 36:8544a8900884 | 20 | |
tmccurbin | 36:8544a8900884 | 21 | Ticker StatusMsg; |
kiran_mbed | 0:313541d8f8be | 22 | |
tmccurbin | 36:8544a8900884 | 23 | int main() |
tmccurbin | 36:8544a8900884 | 24 | { |
tmccurbin | 36:8544a8900884 | 25 | Init(); |
tmccurbin | 36:8544a8900884 | 26 | |
tmccurbin | 36:8544a8900884 | 27 | display.GotoXY(10,16); |
tmccurbin | 36:8544a8900884 | 28 | display.SelectFont(Arial_14,BLACK,ReadData); |
tmccurbin | 36:8544a8900884 | 29 | display.PrintString("Penn Electric Racing"); |
tmccurbin | 39:e6aa6dcf3f75 | 30 | wait(1); |
tmccurbin | 39:e6aa6dcf3f75 | 31 | |
tmccurbin | 39:e6aa6dcf3f75 | 32 | CANMessage Rxmsg; |
tmccurbin | 36:8544a8900884 | 33 | |
tmccurbin | 36:8544a8900884 | 34 | Thread Thread2(ProcessButtons); |
tmccurbin | 36:8544a8900884 | 35 | Thread Thread1(DisplayCurrScreen); |
tmccurbin | 36:8544a8900884 | 36 | |
tmccurbin | 36:8544a8900884 | 37 | while(1) { |
tmccurbin | 36:8544a8900884 | 38 | if (SteeringCANPort.rxRead(Rxmsg)) { |
tmccurbin | 36:8544a8900884 | 39 | ProcessCANMsg(Rxmsg); |
tmccurbin | 32:535acb159709 | 40 | } |
tmccurbin | 32:535acb159709 | 41 | } |
tmccurbin | 32:535acb159709 | 42 | } |
tmccurbin | 32:535acb159709 | 43 | |
kiran_mbed | 0:313541d8f8be | 44 | |
kiran_mbed | 0:313541d8f8be | 45 | void Init() |
kiran_mbed | 0:313541d8f8be | 46 | { |
tmccurbin | 36:8544a8900884 | 47 | StatusMsg.attach(&ConnectedStatusCANMsg,0.1); |
palimar | 23:6681a38918c6 | 48 | pc.baud(921600); |
tmccurbin | 36:8544a8900884 | 49 | BLButtonRed; |
tmccurbin | 36:8544a8900884 | 50 | BRButtonGreen; |
tmccurbin | 36:8544a8900884 | 51 | TLButtonGreen; |
tmccurbin | 36:8544a8900884 | 52 | TRButtonGreen; |
tmccurbin | 36:8544a8900884 | 53 | DriveStatus = 0; // Off |
tmccurbin | 36:8544a8900884 | 54 | //initialize screen Startup Process |
tmccurbin | 36:8544a8900884 | 55 | wait(2); |
kiran_mbed | 0:313541d8f8be | 56 | } |
kiran_mbed | 0:313541d8f8be | 57 | |
tmccurbin | 36:8544a8900884 | 58 | |
tmccurbin | 36:8544a8900884 | 59 | void ProcessButtons(void const *args) |
tmccurbin | 36:8544a8900884 | 60 | { |
tmccurbin | 36:8544a8900884 | 61 | while(1) { |
tmccurbin | 36:8544a8900884 | 62 | Thread::wait(50); |
tmccurbin | 36:8544a8900884 | 63 | if(biSWBR.read()) { |
tmccurbin | 36:8544a8900884 | 64 | Thread::wait(750); |
tmccurbin | 36:8544a8900884 | 65 | if (biSWBR.read()) { |
tmccurbin | 36:8544a8900884 | 66 | ResetCar(); |
tmccurbin | 36:8544a8900884 | 67 | } |
tmccurbin | 36:8544a8900884 | 68 | NVIC_SystemReset(); |
tmccurbin | 36:8544a8900884 | 69 | ResetSteeringWheel(); |
tmccurbin | 36:8544a8900884 | 70 | } |
tmccurbin | 36:8544a8900884 | 71 | |
tmccurbin | 36:8544a8900884 | 72 | if(biSWBL.read()) { |
tmccurbin | 36:8544a8900884 | 73 | Thread::wait(1000); |
tmccurbin | 36:8544a8900884 | 74 | if (biSWBL.read()) { |
tmccurbin | 36:8544a8900884 | 75 | RequestStatusChange(); |
palimar | 23:6681a38918c6 | 76 | } |
palimar | 21:56890c41ecf1 | 77 | } |
tmccurbin | 36:8544a8900884 | 78 | |
tmccurbin | 36:8544a8900884 | 79 | if(biSWTR.read() && CurrScreen != 5) { |
tmccurbin | 36:8544a8900884 | 80 | //If the toggle button is pressed and the screen isn't on Fault_Screen |
tmccurbin | 36:8544a8900884 | 81 | ToggleScreen(); |
tmccurbin | 36:8544a8900884 | 82 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 83 | } else if (biSWTR.read() && CurrScreen == 5) {// If the screen was on Fault, go to Home |
tmccurbin | 36:8544a8900884 | 84 | CurrScreen = 0; |
tmccurbin | 36:8544a8900884 | 85 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 86 | } |
tmccurbin | 36:8544a8900884 | 87 | |
tmccurbin | 36:8544a8900884 | 88 | if(biSWTL.read() && CurrScreen != 0) { |
tmccurbin | 36:8544a8900884 | 89 | //If the Home button is pressed and the screen isn't on Fault_Screen |
tmccurbin | 36:8544a8900884 | 90 | CurrScreen = 0; |
tmccurbin | 36:8544a8900884 | 91 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 92 | } else if (biSWTL.read() && CurrScreen == 0) {// If the screen was on Fault, go to Home |
tmccurbin | 36:8544a8900884 | 93 | CurrScreen = 5; |
tmccurbin | 36:8544a8900884 | 94 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 95 | } |
palimar | 21:56890c41ecf1 | 96 | } |
palimar | 35:b42afc973902 | 97 | } |
palimar | 21:56890c41ecf1 | 98 | |
tmccurbin | 36:8544a8900884 | 99 | |
tmccurbin | 36:8544a8900884 | 100 | void UpdateDisplay() |
tmccurbin | 36:8544a8900884 | 101 | { |
tmccurbin | 36:8544a8900884 | 102 | } |
tmccurbin | 36:8544a8900884 | 103 | |
tmccurbin | 36:8544a8900884 | 104 | |
tmccurbin | 36:8544a8900884 | 105 | void ProcessCANMsg(CANMessage& Rxmsg) |
tmccurbin | 36:8544a8900884 | 106 | { |
tmccurbin | 36:8544a8900884 | 107 | if (SteeringCANPort.rxRead(Rxmsg)) { |
tmccurbin | 39:e6aa6dcf3f75 | 108 | // Printing CAN message data: |
tmccurbin | 39:e6aa6dcf3f75 | 109 | // printf("Message ID: 0x%x len: %d hex: 0x%x float: %f\r\n", Rxmsg.id, Rxmsg.len, *((int*)((void*)(&Rxmsg.data[0]))), *((float*)((void*)(&Rxmsg.data[0])))); |
tmccurbin | 39:e6aa6dcf3f75 | 110 | // for (int i=0; i < Rxmsg.len; i++) printf("D[%d]: %x ", i, Rxmsg.data[i]); |
tmccurbin | 36:8544a8900884 | 111 | switch (Rxmsg.id) { |
palimar | 4:a4fb060e7840 | 112 | |
tmccurbin | 36:8544a8900884 | 113 | // HOME SCREEN ******************************************************************************************* |
tmccurbin | 36:8544a8900884 | 114 | case SOC_TX_ID: |
tmccurbin | 36:8544a8900884 | 115 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 116 | if (abs(CANFloat*100 - *BigBatLifeBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 117 | sprintf(BigBatLifeBuffer,"%3.2d", int(CANFloat*100)); // Big battery life percentage |
tmccurbin | 39:e6aa6dcf3f75 | 118 | display.PutString(1,40,BigBatLifeBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 119 | } |
tmccurbin | 36:8544a8900884 | 120 | break; |
tmccurbin | 36:8544a8900884 | 121 | case SYS_GLV_SOC_ID: |
tmccurbin | 36:8544a8900884 | 122 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 123 | if (abs(CANFloat*100 - *SmallBatLifeBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 124 | sprintf(SmallBatLifeBuffer,"%3.2d", int(CANFloat*100)); // Small battery life percentage |
tmccurbin | 39:e6aa6dcf3f75 | 125 | display.PutString(1,60,SmallBatLifeBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 126 | } |
tmccurbin | 36:8544a8900884 | 127 | break; |
tmccurbin | 36:8544a8900884 | 128 | case PCM_FRPM_ID: |
tmccurbin | 36:8544a8900884 | 129 | CANFloat = GetFloat; |
tmccurbin | 36:8544a8900884 | 130 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 131 | if (abs((CANFloat+CANFloat2)*WheelCircumference*30 - *CarSpdBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 132 | sprintf(CarSpdBuffer,"%3.2d", int((CANFloat+CANFloat2)*WheelCircumference*30)); // Miles per hour |
tmccurbin | 39:e6aa6dcf3f75 | 133 | display.PutString(1,108,CarSpdBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 134 | } |
tmccurbin | 39:e6aa6dcf3f75 | 135 | break; |
tmccurbin | 36:8544a8900884 | 136 | case TEMP_MMA_TX_ID_BASE2: |
tmccurbin | 36:8544a8900884 | 137 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 138 | if (abs((CANFloat*9.0/5.0)+32 - *AvgBatTBuffer) >=1) { |
tmccurbin | 39:e6aa6dcf3f75 | 139 | sprintf(AvgBatTBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // Degrees F |
tmccurbin | 39:e6aa6dcf3f75 | 140 | display.PutString(3,39,AvgBatTBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 141 | //display.PutString(5,108,AvgBatTBuffer); this is for the battery screen |
tmccurbin | 39:e6aa6dcf3f75 | 142 | } |
tmccurbin | 39:e6aa6dcf3f75 | 143 | break; |
tmccurbin | 36:8544a8900884 | 144 | case TEMP_MMA_TX_ID_BASE: |
tmccurbin | 36:8544a8900884 | 145 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 146 | if (abs((CANFloat2*9.0/5.0)+32 - *MaxBatTBuffer) >=1) { |
tmccurbin | 39:e6aa6dcf3f75 | 147 | sprintf(MaxBatTBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); // Figure out Max/Min and Figure out various screen display |
tmccurbin | 39:e6aa6dcf3f75 | 148 | display.PutString(3,103,MaxBatTBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 149 | //display.PutString(5,20,MaxBatTBuffer); this is for the battery screen |
tmccurbin | 39:e6aa6dcf3f75 | 150 | } |
tmccurbin | 36:8544a8900884 | 151 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 152 | if (abs((CANFloat*9.0/5.0)+32 - *MinBatTBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 153 | sprintf(MinBatTBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); |
tmccurbin | 39:e6aa6dcf3f75 | 154 | //display.PutString(5,67,MinBatTBuffer); this is for the battery screen |
tmccurbin | 39:e6aa6dcf3f75 | 155 | } |
tmccurbin | 39:e6aa6dcf3f75 | 156 | break; |
tmccurbin | 36:8544a8900884 | 157 | case MOC_MOTEMP_ID: |
tmccurbin | 36:8544a8900884 | 158 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 159 | if (abs((CANFloat*9.0/5.0)+32 - *LMtrTmpBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 160 | sprintf(LMtrTmpBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // We need to figure out how to handle the bytes for left and right motors |
tmccurbin | 39:e6aa6dcf3f75 | 161 | display.PutString(5,34,LMtrTmpBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 162 | // display.PutString(1,34,LMtrTmpBuffer); this is for the motor screen |
tmccurbin | 39:e6aa6dcf3f75 | 163 | } |
tmccurbin | 36:8544a8900884 | 164 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 165 | if (abs((CANFloat2*9.0/5.0)+32 - *RMtrTmpBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 166 | sprintf(RMtrTmpBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); // We need to figure out how to handle the bytes for left and right motors |
tmccurbin | 39:e6aa6dcf3f75 | 167 | display.PutString(5,34,RMtrTmpBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 168 | //display.PutString(1,98,LMtrTmpBuffer); this is for the motor screen |
tmccurbin | 39:e6aa6dcf3f75 | 169 | } |
tmccurbin | 39:e6aa6dcf3f75 | 170 | break; |
tmccurbin | 39:e6aa6dcf3f75 | 171 | |
tmccurbin | 36:8544a8900884 | 172 | // BATTERY SCREEN*********************************************************************************** |
tmccurbin | 36:8544a8900884 | 173 | case VOLTAGE_TX_ID: |
tmccurbin | 36:8544a8900884 | 174 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 175 | if (abs(CANFloat - *BigBatVoltBuffer) >= 0.1) { |
tmccurbin | 39:e6aa6dcf3f75 | 176 | sprintf(BigBatVoltBuffer,"%3.2d", int(CANFloat)); // Volts |
tmccurbin | 39:e6aa6dcf3f75 | 177 | //display.PutString(1,10,BigBatVoltBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 178 | //display.PutString(3,94,BigBatVoltBuffer); this is for the charging screen |
tmccurbin | 39:e6aa6dcf3f75 | 179 | } |
tmccurbin | 39:e6aa6dcf3f75 | 180 | break; |
tmccurbin | 36:8544a8900884 | 181 | case POWER_TX_ID: |
tmccurbin | 36:8544a8900884 | 182 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 183 | if (abs(CANFloat - *BigBatPowerBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 184 | sprintf(BigBatPowerBuffer,"%3.2d", int(CANFloat)); // Watts |
tmccurbin | 39:e6aa6dcf3f75 | 185 | //display.PutString(1,55,BigBatPowerBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 186 | } |
tmccurbin | 39:e6aa6dcf3f75 | 187 | break; |
tmccurbin | 36:8544a8900884 | 188 | case CURRENT_TX_ID: |
tmccurbin | 36:8544a8900884 | 189 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 190 | if (abs(CANFloat - *BigBatCurrentBuffer) >= 0.2) { |
tmccurbin | 39:e6aa6dcf3f75 | 191 | sprintf(BigBatCurrentBuffer,"%3.2d", int(CANFloat)); // Amps |
tmccurbin | 39:e6aa6dcf3f75 | 192 | //display.PutString(1,100,BigBatCurrentBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 193 | } |
tmccurbin | 39:e6aa6dcf3f75 | 194 | break; |
tmccurbin | 36:8544a8900884 | 195 | case CELLV_MMA_TX_ID_BASE: |
tmccurbin | 36:8544a8900884 | 196 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 197 | if (abs(CANFloat2 - *VmaxBuffer) >= 0.1) { |
tmccurbin | 39:e6aa6dcf3f75 | 198 | sprintf(VmaxBuffer,"%3.2d", int(CANFloat2)); // We need to figure out how to handle max and min |
tmccurbin | 39:e6aa6dcf3f75 | 199 | //display.PutString(3,20,VmaxBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 200 | } |
tmccurbin | 36:8544a8900884 | 201 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 202 | if (abs(CANFloat - *VminBuffer) >= 0.1) { |
tmccurbin | 39:e6aa6dcf3f75 | 203 | sprintf(VminBuffer,"%3.2d", int(CANFloat)); |
tmccurbin | 39:e6aa6dcf3f75 | 204 | //display.PutString(3,67,VminBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 205 | } |
tmccurbin | 39:e6aa6dcf3f75 | 206 | break; |
tmccurbin | 36:8544a8900884 | 207 | case CELLV_MMA_TX_ID_BASE2: |
tmccurbin | 36:8544a8900884 | 208 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 209 | if (abs(CANFloat - *VavgBuffer) >= 0.1) { |
tmccurbin | 39:e6aa6dcf3f75 | 210 | sprintf(VavgBuffer,"%3.2d", int(CANFloat)); // Volts |
tmccurbin | 39:e6aa6dcf3f75 | 211 | //display.PutString(3,108,VavgBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 212 | } |
tmccurbin | 39:e6aa6dcf3f75 | 213 | break; |
tmccurbin | 36:8544a8900884 | 214 | case BOARDTEMP_TX_ID: |
tmccurbin | 36:8544a8900884 | 215 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 216 | if (abs((CANFloat*9.0/5.0)+32 - *BoardTempBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 217 | sprintf(BoardTempBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // Degrees F |
tmccurbin | 39:e6aa6dcf3f75 | 218 | //display.PutString(7,87,BoardTempBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 219 | } |
tmccurbin | 39:e6aa6dcf3f75 | 220 | break; |
tmccurbin | 36:8544a8900884 | 221 | |
tmccurbin | 36:8544a8900884 | 222 | // MOTOR SCREEN***************************************************************** |
tmccurbin | 36:8544a8900884 | 223 | case MOC_AIRTEMP_ID: |
tmccurbin | 36:8544a8900884 | 224 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 225 | if (abs((CANFloat*9.0/5.0)+32 - *LAirTmpBuffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 226 | sprintf(LAirTmpBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // Figure out the left and the right |
tmccurbin | 36:8544a8900884 | 227 | //display.PutString(2,34,LAirTmpBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 228 | } |
tmccurbin | 36:8544a8900884 | 229 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 230 | if (abs((CANFloat2*9.0/5.0)+32 - *RAirTmpBuffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 231 | sprintf(RAirTmpBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); // Degrees F |
tmccurbin | 36:8544a8900884 | 232 | //display.PutString(2,98,RAirTmpBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 233 | } |
tmccurbin | 39:e6aa6dcf3f75 | 234 | break; |
tmccurbin | 36:8544a8900884 | 235 | case MOC_IGBTTEMP_ID: |
tmccurbin | 36:8544a8900884 | 236 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 237 | if (abs((CANFloat*9.0/5.0)+32 - *LIGBTmpBuffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 238 | sprintf(LIGBTmpBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // Figure out the left and the right |
tmccurbin | 36:8544a8900884 | 239 | //display.PutString(3,34,LIGBTmpBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 240 | } |
tmccurbin | 36:8544a8900884 | 241 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 242 | if (abs((CANFloat2*9.0/5.0)+32 - *RIGBTmpBuffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 243 | sprintf(RIGBTmpBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); // Degrees F |
tmccurbin | 36:8544a8900884 | 244 | //display.PutString(3,98,RIGBTmpBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 245 | } |
tmccurbin | 39:e6aa6dcf3f75 | 246 | break; |
tmccurbin | 36:8544a8900884 | 247 | case MOC_RPM_ID: |
tmccurbin | 36:8544a8900884 | 248 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 249 | if (abs(CANFloat - *Rpm_LBuffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 250 | sprintf(Rpm_LBuffer,"%3.2d", int(CANFloat)); // Figure out the left and the right |
tmccurbin | 36:8544a8900884 | 251 | //display.PutString(5,30,Rpm_LBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 252 | } |
tmccurbin | 36:8544a8900884 | 253 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 254 | if (abs(CANFloat2 - *Rpm_RBuffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 255 | sprintf(Rpm_RBuffer,"%3.2d", int(CANFloat2)); |
tmccurbin | 36:8544a8900884 | 256 | //display.PutString(5,107,Rpm_RBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 257 | } |
tmccurbin | 39:e6aa6dcf3f75 | 258 | break; |
tmccurbin | 36:8544a8900884 | 259 | case PCM_TORQUERQ_ID: |
tmccurbin | 36:8544a8900884 | 260 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 261 | if (abs(CANFloat*100 - *TRequestBufferL) >= 1) { |
tmccurbin | 36:8544a8900884 | 262 | sprintf(TRequestBufferL,"%3.2d", int(CANFloat*100)); // Percentage |
tmccurbin | 36:8544a8900884 | 263 | //display.PutString(7,89,TRequestBufferL); |
tmccurbin | 39:e6aa6dcf3f75 | 264 | } |
tmccurbin | 36:8544a8900884 | 265 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 266 | if (abs(CANFloat2*100 - *TRequestBufferR) >= 1) { |
tmccurbin | 36:8544a8900884 | 267 | sprintf(TRequestBufferR,"%3.2d", int(CANFloat2*100)); // Percentage |
tmccurbin | 36:8544a8900884 | 268 | //display.PutString(7,89,TRequestBufferR); |
tmccurbin | 39:e6aa6dcf3f75 | 269 | } |
tmccurbin | 39:e6aa6dcf3f75 | 270 | break; |
tmccurbin | 36:8544a8900884 | 271 | |
tmccurbin | 36:8544a8900884 | 272 | // SYSTEM MANAGEMENT SCREEN*************************************************** |
tmccurbin | 36:8544a8900884 | 273 | case SYS_GLV_CURRENT_ID: |
tmccurbin | 36:8544a8900884 | 274 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 275 | if (abs(CANFloat - *SmallBatCurrentBuffer) >= 0.2) { |
tmccurbin | 36:8544a8900884 | 276 | sprintf(SmallBatCurrentBuffer,"%3.2d", int(CANFloat)); // Amps |
tmccurbin | 36:8544a8900884 | 277 | //display.PutString(1,30,SmallBatCurrentBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 278 | } |
tmccurbin | 39:e6aa6dcf3f75 | 279 | break; |
tmccurbin | 36:8544a8900884 | 280 | case SYS_SWITCHES_ID: |
tmccurbin | 36:8544a8900884 | 281 | CANFloat = GetFloat; |
tmccurbin | 36:8544a8900884 | 282 | sprintf(ShtdSwtchBuffer,"%3.2d", int(CANFloat)); // How the heck are we interpreting this data |
tmccurbin | 36:8544a8900884 | 283 | //display.PutString(1,108,ShtdSwtchBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 284 | break; |
tmccurbin | 36:8544a8900884 | 285 | case SYS_PWM_FAN_ID: |
tmccurbin | 36:8544a8900884 | 286 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 287 | if (abs(CANFloat*100 - *Fan1Buffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 288 | sprintf(Fan1Buffer,"%3.2d", int(CANFloat*100)); // Duty Cycle. Figure out the left and the right |
tmccurbin | 36:8544a8900884 | 289 | //display.PutString(3,30,Fan1Buffer); |
tmccurbin | 39:e6aa6dcf3f75 | 290 | } |
tmccurbin | 36:8544a8900884 | 291 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 292 | if (abs(CANFloat2*100 - *Fan1Buffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 293 | sprintf(Fan2Buffer,"%3.2d", int(CANFloat2*100)); |
tmccurbin | 36:8544a8900884 | 294 | //display.PutString(3,107,Fan2Buffer); |
tmccurbin | 39:e6aa6dcf3f75 | 295 | } |
tmccurbin | 39:e6aa6dcf3f75 | 296 | break; |
tmccurbin | 36:8544a8900884 | 297 | case SYS_PWM_PUMP_ID: |
tmccurbin | 36:8544a8900884 | 298 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 299 | if (abs(CANFloat*100 - *Pump1Buffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 300 | sprintf(Pump1Buffer,"%3.2d", int(CANFloat*100)); // Duty Cycle. Figure out the left and the right |
tmccurbin | 36:8544a8900884 | 301 | //display.PutString(5,30,Pump1Buffer); |
tmccurbin | 39:e6aa6dcf3f75 | 302 | } |
tmccurbin | 36:8544a8900884 | 303 | CANFloat2 = GetFloat4; |
tmccurbin | 39:e6aa6dcf3f75 | 304 | if (abs(CANFloat2*100 - *Pump2Buffer) >= 1) { |
tmccurbin | 36:8544a8900884 | 305 | sprintf(Pump2Buffer,"%3.2d", int(CANFloat2*100)); |
tmccurbin | 36:8544a8900884 | 306 | //display.PutString(5,107,Pump2Buffer); |
tmccurbin | 39:e6aa6dcf3f75 | 307 | } |
tmccurbin | 39:e6aa6dcf3f75 | 308 | break; |
tmccurbin | 36:8544a8900884 | 309 | case SYS_DCDC_STATUS_ID: |
tmccurbin | 36:8544a8900884 | 310 | CANFloat = GetFloat; |
tmccurbin | 36:8544a8900884 | 311 | sprintf(DCDCBuffer,"%3.2d", int(CANFloat)); // How the heck are we interpreting this data |
tmccurbin | 36:8544a8900884 | 312 | //display.PutString(7,30,DCDCBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 313 | break; |
tmccurbin | 36:8544a8900884 | 314 | case SYS_IMD_RESIST_ID: |
tmccurbin | 36:8544a8900884 | 315 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 316 | if (abs(CANFloat - *IMDRBuffer) >= 1) { |
tmccurbin | 39:e6aa6dcf3f75 | 317 | sprintf(IMDRBuffer,"%3.2d", int(CANFloat)); |
tmccurbin | 36:8544a8900884 | 318 | //display.PutString(7,107,IMDRBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 319 | } |
tmccurbin | 39:e6aa6dcf3f75 | 320 | break; |
tmccurbin | 36:8544a8900884 | 321 | |
tmccurbin | 36:8544a8900884 | 322 | // CHARGER SCREEN ************************************************************* |
tmccurbin | 36:8544a8900884 | 323 | case CHARGECURR_TX_ID: |
tmccurbin | 36:8544a8900884 | 324 | CANFloat = GetFloat; |
tmccurbin | 39:e6aa6dcf3f75 | 325 | if (abs(CANFloat - *ChargeCurrBuffer) >= 0.1) { |
tmccurbin | 36:8544a8900884 | 326 | sprintf(ChargeCurrBuffer,"%3.2d", int(CANFloat)); // Amps |
tmccurbin | 36:8544a8900884 | 327 | //display.PutString(3,94,ChargeCurrBuffer); |
tmccurbin | 39:e6aa6dcf3f75 | 328 | } |
tmccurbin | 39:e6aa6dcf3f75 | 329 | break; |
tmccurbin | 39:e6aa6dcf3f75 | 330 | |
tmccurbin | 36:8544a8900884 | 331 | // OTHER ********************************************************************** |
tmccurbin | 36:8544a8900884 | 332 | case MODE_TX_ID: |
tmccurbin | 36:8544a8900884 | 333 | CANFloat = GetFloat; |
tmccurbin | 36:8544a8900884 | 334 | sprintf(&DriveStatus,"%3.2d", int(CANFloat)); //confirm that I am interpreting this correctly |
tmccurbin | 36:8544a8900884 | 335 | if (DriveStatus == 1) { |
tmccurbin | 36:8544a8900884 | 336 | BLButtonGreen; |
tmccurbin | 36:8544a8900884 | 337 | } else { |
tmccurbin | 36:8544a8900884 | 338 | BLButtonRed; |
tmccurbin | 36:8544a8900884 | 339 | } |
tmccurbin | 39:e6aa6dcf3f75 | 340 | break; |
tmccurbin | 36:8544a8900884 | 341 | default: |
tmccurbin | 36:8544a8900884 | 342 | break; |
kiran_mbed | 0:313541d8f8be | 343 | } |
tmccurbin | 36:8544a8900884 | 344 | } |
tmccurbin | 36:8544a8900884 | 345 | } |
tmccurbin | 36:8544a8900884 | 346 | |
tmccurbin | 36:8544a8900884 | 347 | void ConnectedStatusCANMsg() |
tmccurbin | 36:8544a8900884 | 348 | { |
tmccurbin | 36:8544a8900884 | 349 | CANMessage ConnectedStatus(0x600, &ConnectedStatusBuffer,1); |
tmccurbin | 36:8544a8900884 | 350 | SteeringCANPort.txWrite(ConnectedStatus); |
tmccurbin | 36:8544a8900884 | 351 | } |
tmccurbin | 36:8544a8900884 | 352 | |
palimar | 23:6681a38918c6 | 353 | |
tmccurbin | 36:8544a8900884 | 354 | void RequestStatusChange() |
tmccurbin | 36:8544a8900884 | 355 | { |
tmccurbin | 36:8544a8900884 | 356 | DriveStatusRequestBuffer = !DriveStatus; |
tmccurbin | 36:8544a8900884 | 357 | CANMessage TxDriveStatusRequest(0x601, &DriveStatusRequestBuffer,1); |
tmccurbin | 36:8544a8900884 | 358 | for (int j=0; j<10; j++) { |
tmccurbin | 36:8544a8900884 | 359 | SteeringCANPort.txWrite(TxDriveStatusRequest); |
tmccurbin | 36:8544a8900884 | 360 | } |
tmccurbin | 36:8544a8900884 | 361 | display.PutString(7,0," DRIVE REQUEST SENT "); |
tmccurbin | 36:8544a8900884 | 362 | Thread::wait(750); |
tmccurbin | 36:8544a8900884 | 363 | PrevScreen = !CurrScreen; // To force a screen update |
tmccurbin | 36:8544a8900884 | 364 | } |
tmccurbin | 36:8544a8900884 | 365 | |
tmccurbin | 36:8544a8900884 | 366 | |
tmccurbin | 36:8544a8900884 | 367 | void ResetSteeringWheel() |
tmccurbin | 36:8544a8900884 | 368 | { |
tmccurbin | 36:8544a8900884 | 369 | NVIC_SystemReset(); |
tmccurbin | 36:8544a8900884 | 370 | } |
tmccurbin | 36:8544a8900884 | 371 | |
tmccurbin | 36:8544a8900884 | 372 | |
tmccurbin | 36:8544a8900884 | 373 | void ResetCar() |
tmccurbin | 36:8544a8900884 | 374 | { |
tmccurbin | 36:8544a8900884 | 375 | CANMessage TxCarReset(0x602,&TxResetBuffer,1); |
tmccurbin | 36:8544a8900884 | 376 | for (int k=0; k<10; k++) { |
tmccurbin | 36:8544a8900884 | 377 | SteeringCANPort.txWriteDirect(TxCarReset); |
tmccurbin | 36:8544a8900884 | 378 | } |
tmccurbin | 36:8544a8900884 | 379 | } |