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@42:701df58e923a, 2015-03-23 (annotated)
- Committer:
- kiran_mbed
- Date:
- Mon Mar 23 19:36:37 2015 +0000
- Revision:
- 42:701df58e923a
- Parent:
- 41:7c5ea411fad2
- Child:
- 44:80d821b5a0e7
- Child:
- 47:5d3c6f85fa29
Removed Blocking of Start CAN Message.; Removed Sending of START Message bug
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 | 39:e6aa6dcf3f75 | 27 | CANMessage Rxmsg; |
tmccurbin | 36:8544a8900884 | 28 | |
tmccurbin | 36:8544a8900884 | 29 | Thread Thread2(ProcessButtons); |
tmccurbin | 36:8544a8900884 | 30 | Thread Thread1(DisplayCurrScreen); |
tmccurbin | 36:8544a8900884 | 31 | |
tmccurbin | 36:8544a8900884 | 32 | while(1) { |
tmccurbin | 36:8544a8900884 | 33 | if (SteeringCANPort.rxRead(Rxmsg)) { |
tmccurbin | 36:8544a8900884 | 34 | ProcessCANMsg(Rxmsg); |
tmccurbin | 32:535acb159709 | 35 | } |
tmccurbin | 32:535acb159709 | 36 | } |
tmccurbin | 32:535acb159709 | 37 | } |
tmccurbin | 32:535acb159709 | 38 | |
kiran_mbed | 0:313541d8f8be | 39 | |
kiran_mbed | 0:313541d8f8be | 40 | void Init() |
kiran_mbed | 0:313541d8f8be | 41 | { |
tmccurbin | 36:8544a8900884 | 42 | StatusMsg.attach(&ConnectedStatusCANMsg,0.1); |
palimar | 23:6681a38918c6 | 43 | pc.baud(921600); |
tmccurbin | 36:8544a8900884 | 44 | BLButtonRed; |
tmccurbin | 36:8544a8900884 | 45 | BRButtonGreen; |
tmccurbin | 36:8544a8900884 | 46 | TLButtonGreen; |
tmccurbin | 36:8544a8900884 | 47 | TRButtonGreen; |
tmccurbin | 36:8544a8900884 | 48 | //initialize screen Startup Process |
tmccurbin | 36:8544a8900884 | 49 | wait(2); |
kiran_mbed | 0:313541d8f8be | 50 | } |
kiran_mbed | 0:313541d8f8be | 51 | |
tmccurbin | 36:8544a8900884 | 52 | |
tmccurbin | 36:8544a8900884 | 53 | void ProcessButtons(void const *args) |
tmccurbin | 36:8544a8900884 | 54 | { |
tmccurbin | 36:8544a8900884 | 55 | while(1) { |
tmccurbin | 36:8544a8900884 | 56 | Thread::wait(50); |
tmccurbin | 36:8544a8900884 | 57 | if(biSWBR.read()) { |
tmccurbin | 36:8544a8900884 | 58 | Thread::wait(750); |
tmccurbin | 36:8544a8900884 | 59 | if (biSWBR.read()) { |
tmccurbin | 36:8544a8900884 | 60 | ResetCar(); |
tmccurbin | 36:8544a8900884 | 61 | } |
tmccurbin | 36:8544a8900884 | 62 | NVIC_SystemReset(); |
tmccurbin | 36:8544a8900884 | 63 | ResetSteeringWheel(); |
tmccurbin | 36:8544a8900884 | 64 | } |
tmccurbin | 36:8544a8900884 | 65 | |
tmccurbin | 36:8544a8900884 | 66 | if(biSWBL.read()) { |
tmccurbin | 36:8544a8900884 | 67 | Thread::wait(1000); |
tmccurbin | 36:8544a8900884 | 68 | if (biSWBL.read()) { |
tmccurbin | 36:8544a8900884 | 69 | RequestStatusChange(); |
palimar | 23:6681a38918c6 | 70 | } |
palimar | 21:56890c41ecf1 | 71 | } |
tmccurbin | 36:8544a8900884 | 72 | |
tmccurbin | 36:8544a8900884 | 73 | if(biSWTR.read() && CurrScreen != 5) { |
tmccurbin | 36:8544a8900884 | 74 | //If the toggle button is pressed and the screen isn't on Fault_Screen |
tmccurbin | 36:8544a8900884 | 75 | ToggleScreen(); |
tmccurbin | 36:8544a8900884 | 76 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 77 | } else if (biSWTR.read() && CurrScreen == 5) {// If the screen was on Fault, go to Home |
tmccurbin | 36:8544a8900884 | 78 | CurrScreen = 0; |
tmccurbin | 36:8544a8900884 | 79 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 80 | } |
tmccurbin | 36:8544a8900884 | 81 | |
tmccurbin | 36:8544a8900884 | 82 | if(biSWTL.read() && CurrScreen != 0) { |
tmccurbin | 36:8544a8900884 | 83 | //If the Home button is pressed and the screen isn't on Fault_Screen |
tmccurbin | 36:8544a8900884 | 84 | CurrScreen = 0; |
tmccurbin | 36:8544a8900884 | 85 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 86 | } else if (biSWTL.read() && CurrScreen == 0) {// If the screen was on Fault, go to Home |
tmccurbin | 36:8544a8900884 | 87 | CurrScreen = 5; |
tmccurbin | 36:8544a8900884 | 88 | Thread::wait(250); |
tmccurbin | 36:8544a8900884 | 89 | } |
palimar | 21:56890c41ecf1 | 90 | } |
palimar | 35:b42afc973902 | 91 | } |
palimar | 21:56890c41ecf1 | 92 | |
tmccurbin | 36:8544a8900884 | 93 | |
tmccurbin | 36:8544a8900884 | 94 | void UpdateDisplay() |
tmccurbin | 36:8544a8900884 | 95 | { |
tmccurbin | 36:8544a8900884 | 96 | } |
tmccurbin | 36:8544a8900884 | 97 | |
tmccurbin | 36:8544a8900884 | 98 | |
tmccurbin | 36:8544a8900884 | 99 | void ProcessCANMsg(CANMessage& Rxmsg) |
tmccurbin | 36:8544a8900884 | 100 | { |
tmccurbin | 36:8544a8900884 | 101 | if (SteeringCANPort.rxRead(Rxmsg)) { |
tmccurbin | 39:e6aa6dcf3f75 | 102 | // Printing CAN message data: |
tmccurbin | 39:e6aa6dcf3f75 | 103 | // 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 | 104 | // for (int i=0; i < Rxmsg.len; i++) printf("D[%d]: %x ", i, Rxmsg.data[i]); |
tmccurbin | 40:92f08fdc32df | 105 | if (Rxmsg.id == MODE_TX_ID) { |
kiran_mbed | 42:701df58e923a | 106 | if(Rxmsg.data[0] != (1<<3)) |
kiran_mbed | 42:701df58e923a | 107 | DriveStatusRequestBuffer=1; |
kiran_mbed | 42:701df58e923a | 108 | else |
kiran_mbed | 42:701df58e923a | 109 | DriveStatusRequestBuffer=0; |
tmccurbin | 40:92f08fdc32df | 110 | } |
tmccurbin | 40:92f08fdc32df | 111 | |
tmccurbin | 41:7c5ea411fad2 | 112 | if (Rxmsg.id == POWER_TX_ID) { |
tmccurbin | 41:7c5ea411fad2 | 113 | CANFloat = GetFloat; |
tmccurbin | 41:7c5ea411fad2 | 114 | LEDBar = (CANFloat/85.0)*(2.6/3.3); |
tmccurbin | 41:7c5ea411fad2 | 115 | } |
tmccurbin | 41:7c5ea411fad2 | 116 | |
tmccurbin | 40:92f08fdc32df | 117 | switch (CurrScreen) { |
tmccurbin | 40:92f08fdc32df | 118 | case HOME_SCREEN: |
tmccurbin | 40:92f08fdc32df | 119 | switch (Rxmsg.id) { |
palimar | 4:a4fb060e7840 | 120 | |
tmccurbin | 40:92f08fdc32df | 121 | // HOME SCREEN ******************************************************************************************* |
tmccurbin | 40:92f08fdc32df | 122 | // Pedal Test |
tmccurbin | 41:7c5ea411fad2 | 123 | /*case PCM_PEDALS_ID: |
tmccurbin | 41:7c5ea411fad2 | 124 | CANFloat = GetFloat; |
tmccurbin | 41:7c5ea411fad2 | 125 | if (abs(CANFloat*100 - float (*AccPedalBuffer)) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 126 | sprintf(AccPedalBuffer,"%3.2d", int(CANFloat*100)); |
tmccurbin | 41:7c5ea411fad2 | 127 | display.PutString(1,40,AccPedalBuffer); |
tmccurbin | 41:7c5ea411fad2 | 128 | } |
tmccurbin | 41:7c5ea411fad2 | 129 | CANFloat2 = GetFloat4; |
tmccurbin | 41:7c5ea411fad2 | 130 | if (abs(CANFloat2*100 - float (*BrkPedalBuffer)) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 131 | sprintf(BrkPedalBuffer,"%3.2d", int(CANFloat2*100)); |
tmccurbin | 41:7c5ea411fad2 | 132 | display.PutString(1,60,BrkPedalBuffer); |
tmccurbin | 41:7c5ea411fad2 | 133 | } |
tmccurbin | 41:7c5ea411fad2 | 134 | break;*/ |
tmccurbin | 41:7c5ea411fad2 | 135 | |
tmccurbin | 41:7c5ea411fad2 | 136 | case SOC_TX_ID: |
tmccurbin | 40:92f08fdc32df | 137 | CANFloat = GetFloat; |
tmccurbin | 41:7c5ea411fad2 | 138 | if (abs(CANFloat*100 - *BigBatLifeBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 139 | sprintf(BigBatLifeBuffer,"%3.2d", int(CANFloat*100)); // Big battery life percentage |
tmccurbin | 41:7c5ea411fad2 | 140 | display.PutString(1,40,BigBatLifeBuffer); |
tmccurbin | 40:92f08fdc32df | 141 | } |
tmccurbin | 41:7c5ea411fad2 | 142 | break; |
tmccurbin | 41:7c5ea411fad2 | 143 | case SYS_GLV_SOC_ID: |
tmccurbin | 41:7c5ea411fad2 | 144 | CANFloat = GetFloat; |
tmccurbin | 41:7c5ea411fad2 | 145 | if (abs(CANFloat*100 - *SmallBatLifeBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 146 | sprintf(SmallBatLifeBuffer,"%3.2d", int(CANFloat*100)); // Small battery life percentage |
tmccurbin | 41:7c5ea411fad2 | 147 | display.PutString(1,60,SmallBatLifeBuffer); |
tmccurbin | 41:7c5ea411fad2 | 148 | } |
tmccurbin | 41:7c5ea411fad2 | 149 | break; |
tmccurbin | 40:92f08fdc32df | 150 | case PCM_FRPM_ID: |
tmccurbin | 40:92f08fdc32df | 151 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 152 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 153 | if (abs((CANFloat+CANFloat2)*WheelCircumference*30 - *CarSpdBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 154 | sprintf(CarSpdBuffer,"%3.2d", int((CANFloat+CANFloat2)*WheelCircumference*30)); // Miles per hour |
tmccurbin | 40:92f08fdc32df | 155 | display.PutString(1,108,CarSpdBuffer); |
tmccurbin | 40:92f08fdc32df | 156 | } |
tmccurbin | 40:92f08fdc32df | 157 | break; |
tmccurbin | 40:92f08fdc32df | 158 | case TEMP_MMA_TX_ID_BASE2: |
tmccurbin | 40:92f08fdc32df | 159 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 160 | if (abs((CANFloat*9.0/5.0)+32 - *AvgBatTBuffer) >=1) { |
tmccurbin | 40:92f08fdc32df | 161 | sprintf(AvgBatTBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // Degrees F |
tmccurbin | 40:92f08fdc32df | 162 | display.PutString(3,39,AvgBatTBuffer); |
tmccurbin | 40:92f08fdc32df | 163 | } |
tmccurbin | 40:92f08fdc32df | 164 | break; |
tmccurbin | 40:92f08fdc32df | 165 | case TEMP_MMA_TX_ID_BASE: |
tmccurbin | 40:92f08fdc32df | 166 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 167 | if (abs((CANFloat2*9.0/5.0)+32 - *MaxBatTBuffer) >=1) { |
tmccurbin | 41:7c5ea411fad2 | 168 | sprintf(MaxBatTBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 169 | display.PutString(3,103,MaxBatTBuffer); |
tmccurbin | 40:92f08fdc32df | 170 | } |
tmccurbin | 40:92f08fdc32df | 171 | break; |
tmccurbin | 40:92f08fdc32df | 172 | case MOC_MOTEMP_ID: |
tmccurbin | 40:92f08fdc32df | 173 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 174 | if (abs((CANFloat*9.0/5.0)+32 - *LMtrTmpBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 175 | sprintf(LMtrTmpBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 176 | display.PutString(5,34,LMtrTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 177 | } |
tmccurbin | 40:92f08fdc32df | 178 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 179 | if (abs((CANFloat2*9.0/5.0)+32 - *RMtrTmpBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 180 | sprintf(RMtrTmpBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 181 | display.PutString(5,34,RMtrTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 182 | } |
tmccurbin | 40:92f08fdc32df | 183 | break; |
tmccurbin | 40:92f08fdc32df | 184 | default: |
tmccurbin | 40:92f08fdc32df | 185 | break; |
tmccurbin | 39:e6aa6dcf3f75 | 186 | } |
tmccurbin | 39:e6aa6dcf3f75 | 187 | break; |
tmccurbin | 40:92f08fdc32df | 188 | // BATTERY SCREEN*********************************************************************************** |
tmccurbin | 40:92f08fdc32df | 189 | case BATTERY_SCREEN: |
tmccurbin | 40:92f08fdc32df | 190 | switch (Rxmsg.id) { |
tmccurbin | 40:92f08fdc32df | 191 | case VOLTAGE_TX_ID: |
tmccurbin | 40:92f08fdc32df | 192 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 193 | if (abs(CANFloat - *BigBatVoltBuffer) >= 0.1) { |
tmccurbin | 40:92f08fdc32df | 194 | sprintf(BigBatVoltBuffer,"%3.2d", int(CANFloat)); // Volts |
tmccurbin | 40:92f08fdc32df | 195 | display.PutString(1,10,BigBatVoltBuffer); |
tmccurbin | 40:92f08fdc32df | 196 | } |
tmccurbin | 40:92f08fdc32df | 197 | break; |
tmccurbin | 40:92f08fdc32df | 198 | case POWER_TX_ID: |
tmccurbin | 40:92f08fdc32df | 199 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 200 | LEDBar = (CANFloat/85.0)*(2.6/3.3); |
tmccurbin | 40:92f08fdc32df | 201 | if (abs(CANFloat - *BigBatPowerBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 202 | sprintf(BigBatPowerBuffer,"%3.2d", int(CANFloat)); // Watts |
tmccurbin | 40:92f08fdc32df | 203 | display.PutString(1,55,BigBatPowerBuffer); |
tmccurbin | 40:92f08fdc32df | 204 | } |
tmccurbin | 40:92f08fdc32df | 205 | break; |
tmccurbin | 40:92f08fdc32df | 206 | case CURRENT_TX_ID: |
tmccurbin | 40:92f08fdc32df | 207 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 208 | if (abs(CANFloat - *BigBatCurrentBuffer) >= 0.2) { |
tmccurbin | 40:92f08fdc32df | 209 | sprintf(BigBatCurrentBuffer,"%3.2d", int(CANFloat)); // Amps |
tmccurbin | 40:92f08fdc32df | 210 | display.PutString(1,100,BigBatCurrentBuffer); |
tmccurbin | 40:92f08fdc32df | 211 | } |
tmccurbin | 40:92f08fdc32df | 212 | break; |
tmccurbin | 40:92f08fdc32df | 213 | case CELLV_MMA_TX_ID_BASE: |
tmccurbin | 40:92f08fdc32df | 214 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 215 | if (abs(CANFloat2 - *VmaxBuffer) >= 0.1) { |
tmccurbin | 41:7c5ea411fad2 | 216 | sprintf(VmaxBuffer,"%3.2d", int(CANFloat2)); |
tmccurbin | 40:92f08fdc32df | 217 | display.PutString(3,20,VmaxBuffer); |
tmccurbin | 40:92f08fdc32df | 218 | } |
tmccurbin | 40:92f08fdc32df | 219 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 220 | if (abs(CANFloat - *VminBuffer) >= 0.1) { |
tmccurbin | 40:92f08fdc32df | 221 | sprintf(VminBuffer,"%3.2d", int(CANFloat)); |
tmccurbin | 40:92f08fdc32df | 222 | display.PutString(3,67,VminBuffer); |
tmccurbin | 40:92f08fdc32df | 223 | } |
tmccurbin | 40:92f08fdc32df | 224 | break; |
tmccurbin | 40:92f08fdc32df | 225 | case CELLV_MMA_TX_ID_BASE2: |
tmccurbin | 40:92f08fdc32df | 226 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 227 | if (abs(CANFloat - *VavgBuffer) >= 0.1) { |
tmccurbin | 40:92f08fdc32df | 228 | sprintf(VavgBuffer,"%3.2d", int(CANFloat)); // Volts |
tmccurbin | 40:92f08fdc32df | 229 | display.PutString(3,108,VavgBuffer); |
tmccurbin | 40:92f08fdc32df | 230 | } |
tmccurbin | 40:92f08fdc32df | 231 | break; |
tmccurbin | 40:92f08fdc32df | 232 | case TEMP_MMA_TX_ID_BASE: |
tmccurbin | 40:92f08fdc32df | 233 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 234 | if (abs((CANFloat*9.0/5.0)+32 - *MinBatTBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 235 | sprintf(MinBatTBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 236 | display.PutString(5,67,MinBatTBuffer); |
tmccurbin | 40:92f08fdc32df | 237 | } |
tmccurbin | 40:92f08fdc32df | 238 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 239 | if (abs((CANFloat2*9.0/5.0)+32 - *MaxBatTBuffer) >=1) { |
tmccurbin | 41:7c5ea411fad2 | 240 | sprintf(MaxBatTBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 241 | display.PutString(5,20,MaxBatTBuffer); |
tmccurbin | 40:92f08fdc32df | 242 | } |
tmccurbin | 40:92f08fdc32df | 243 | break; |
tmccurbin | 40:92f08fdc32df | 244 | case TEMP_MMA_TX_ID_BASE2: |
tmccurbin | 40:92f08fdc32df | 245 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 246 | if (abs((CANFloat*9.0/5.0)+32 - *AvgBatTBuffer) >=1) { |
tmccurbin | 40:92f08fdc32df | 247 | sprintf(AvgBatTBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // Degrees F |
tmccurbin | 40:92f08fdc32df | 248 | display.PutString(5,108,AvgBatTBuffer); |
tmccurbin | 40:92f08fdc32df | 249 | } |
tmccurbin | 40:92f08fdc32df | 250 | break; |
tmccurbin | 40:92f08fdc32df | 251 | case BOARDTEMP_TX_ID: |
tmccurbin | 40:92f08fdc32df | 252 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 253 | if (abs((CANFloat*9.0/5.0)+32 - *BoardTempBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 254 | sprintf(BoardTempBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); // Degrees F |
tmccurbin | 40:92f08fdc32df | 255 | display.PutString(7,87,BoardTempBuffer); |
tmccurbin | 40:92f08fdc32df | 256 | } |
tmccurbin | 40:92f08fdc32df | 257 | break; |
tmccurbin | 40:92f08fdc32df | 258 | default: |
tmccurbin | 40:92f08fdc32df | 259 | break; |
tmccurbin | 39:e6aa6dcf3f75 | 260 | } |
tmccurbin | 39:e6aa6dcf3f75 | 261 | break; |
tmccurbin | 36:8544a8900884 | 262 | // MOTOR SCREEN***************************************************************** |
tmccurbin | 40:92f08fdc32df | 263 | case MOTOR_SCREEN: |
tmccurbin | 40:92f08fdc32df | 264 | switch (Rxmsg.id) { |
tmccurbin | 40:92f08fdc32df | 265 | case MOC_MOTEMP_ID: |
tmccurbin | 40:92f08fdc32df | 266 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 267 | if (abs((CANFloat*9.0/5.0)+32 - *LMtrTmpBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 268 | sprintf(LMtrTmpBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 269 | display.PutString(1,34,LMtrTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 270 | } |
tmccurbin | 40:92f08fdc32df | 271 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 272 | if (abs((CANFloat2*9.0/5.0)+32 - *RMtrTmpBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 273 | sprintf(RMtrTmpBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 274 | display.PutString(1,98,LMtrTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 275 | } |
tmccurbin | 40:92f08fdc32df | 276 | break; |
tmccurbin | 40:92f08fdc32df | 277 | case MOC_AIRTEMP_ID: |
tmccurbin | 40:92f08fdc32df | 278 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 279 | if (abs((CANFloat*9.0/5.0)+32 - *LAirTmpBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 280 | sprintf(LAirTmpBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 281 | display.PutString(2,34,LAirTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 282 | } |
tmccurbin | 40:92f08fdc32df | 283 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 284 | if (abs((CANFloat2*9.0/5.0)+32 - *RAirTmpBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 285 | sprintf(RAirTmpBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); // Degrees F |
tmccurbin | 40:92f08fdc32df | 286 | display.PutString(2,98,RAirTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 287 | } |
tmccurbin | 40:92f08fdc32df | 288 | break; |
tmccurbin | 40:92f08fdc32df | 289 | case MOC_IGBTTEMP_ID: |
tmccurbin | 40:92f08fdc32df | 290 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 291 | if (abs((CANFloat*9.0/5.0)+32 - *LIGBTmpBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 292 | sprintf(LIGBTmpBuffer,"%3.2d", int((CANFloat*9.0/5.0)+32)); |
tmccurbin | 40:92f08fdc32df | 293 | display.PutString(3,34,LIGBTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 294 | } |
tmccurbin | 40:92f08fdc32df | 295 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 296 | if (abs((CANFloat2*9.0/5.0)+32 - *RIGBTmpBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 297 | sprintf(RIGBTmpBuffer,"%3.2d", int((CANFloat2*9.0/5.0)+32)); // Degrees F |
tmccurbin | 40:92f08fdc32df | 298 | display.PutString(3,98,RIGBTmpBuffer); |
tmccurbin | 40:92f08fdc32df | 299 | } |
tmccurbin | 40:92f08fdc32df | 300 | break; |
tmccurbin | 40:92f08fdc32df | 301 | case MOC_RPM_ID: |
tmccurbin | 40:92f08fdc32df | 302 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 303 | if (abs(CANFloat - *Rpm_LBuffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 304 | sprintf(Rpm_LBuffer,"%3.2d", int(CANFloat)); |
tmccurbin | 40:92f08fdc32df | 305 | display.PutString(5,30,Rpm_LBuffer); |
tmccurbin | 40:92f08fdc32df | 306 | } |
tmccurbin | 40:92f08fdc32df | 307 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 308 | if (abs(CANFloat2 - *Rpm_RBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 309 | sprintf(Rpm_RBuffer,"%3.2d", int(CANFloat2)); |
tmccurbin | 40:92f08fdc32df | 310 | display.PutString(5,107,Rpm_RBuffer); |
tmccurbin | 40:92f08fdc32df | 311 | } |
tmccurbin | 40:92f08fdc32df | 312 | break; |
tmccurbin | 40:92f08fdc32df | 313 | case PCM_TORQUERQ_ID: |
tmccurbin | 40:92f08fdc32df | 314 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 315 | if (abs(CANFloat*100 - *TRequestBufferL) >= 1) { |
tmccurbin | 40:92f08fdc32df | 316 | sprintf(TRequestBufferL,"%3.2d", int(CANFloat*100)); // Percentage |
tmccurbin | 40:92f08fdc32df | 317 | display.PutString(7,89,TRequestBufferL); |
tmccurbin | 40:92f08fdc32df | 318 | } |
tmccurbin | 40:92f08fdc32df | 319 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 320 | if (abs(CANFloat2*100 - *TRequestBufferR) >= 1) { |
tmccurbin | 40:92f08fdc32df | 321 | sprintf(TRequestBufferR,"%3.2d", int(CANFloat2*100)); // Percentage |
tmccurbin | 40:92f08fdc32df | 322 | display.PutString(7,89,TRequestBufferR); |
tmccurbin | 40:92f08fdc32df | 323 | } |
tmccurbin | 40:92f08fdc32df | 324 | break; |
tmccurbin | 40:92f08fdc32df | 325 | default: |
tmccurbin | 40:92f08fdc32df | 326 | break; |
tmccurbin | 39:e6aa6dcf3f75 | 327 | } |
tmccurbin | 39:e6aa6dcf3f75 | 328 | break; |
tmccurbin | 36:8544a8900884 | 329 | |
tmccurbin | 36:8544a8900884 | 330 | // SYSTEM MANAGEMENT SCREEN*************************************************** |
tmccurbin | 40:92f08fdc32df | 331 | case SYS_MGMT_SCREEN: |
tmccurbin | 40:92f08fdc32df | 332 | switch (Rxmsg.id) { |
tmccurbin | 40:92f08fdc32df | 333 | case SYS_GLV_CURRENT_ID: |
tmccurbin | 40:92f08fdc32df | 334 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 335 | if (abs(CANFloat - *SmallBatCurrentBuffer) >= 0.2) { |
tmccurbin | 40:92f08fdc32df | 336 | sprintf(SmallBatCurrentBuffer,"%3.2d", int(CANFloat)); // Amps |
tmccurbin | 40:92f08fdc32df | 337 | display.PutString(1,30,SmallBatCurrentBuffer); |
tmccurbin | 40:92f08fdc32df | 338 | } |
tmccurbin | 40:92f08fdc32df | 339 | break; |
tmccurbin | 40:92f08fdc32df | 340 | case SYS_SWITCHES_ID: |
tmccurbin | 40:92f08fdc32df | 341 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 342 | sprintf(ShtdSwtchBuffer,"%3.2d", int(CANFloat)); // How the heck are we interpreting this data |
tmccurbin | 40:92f08fdc32df | 343 | display.PutString(1,108,ShtdSwtchBuffer); |
tmccurbin | 40:92f08fdc32df | 344 | break; |
tmccurbin | 40:92f08fdc32df | 345 | case SYS_PWM_FAN_ID: |
tmccurbin | 40:92f08fdc32df | 346 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 347 | if (abs(CANFloat*100 - *Fan1Buffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 348 | sprintf(Fan1Buffer,"%3.2d", int(CANFloat*100)); |
tmccurbin | 40:92f08fdc32df | 349 | display.PutString(3,30,Fan1Buffer); |
tmccurbin | 40:92f08fdc32df | 350 | } |
tmccurbin | 40:92f08fdc32df | 351 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 352 | if (abs(CANFloat2*100 - *Fan1Buffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 353 | sprintf(Fan2Buffer,"%3.2d", int(CANFloat2*100)); |
tmccurbin | 40:92f08fdc32df | 354 | display.PutString(3,107,Fan2Buffer); |
tmccurbin | 40:92f08fdc32df | 355 | } |
tmccurbin | 40:92f08fdc32df | 356 | break; |
tmccurbin | 40:92f08fdc32df | 357 | case SYS_PWM_PUMP_ID: |
tmccurbin | 40:92f08fdc32df | 358 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 359 | if (abs(CANFloat*100 - *Pump1Buffer) >= 1) { |
tmccurbin | 41:7c5ea411fad2 | 360 | sprintf(Pump1Buffer,"%3.2d", int(CANFloat*100)); |
tmccurbin | 40:92f08fdc32df | 361 | display.PutString(5,30,Pump1Buffer); |
tmccurbin | 40:92f08fdc32df | 362 | } |
tmccurbin | 40:92f08fdc32df | 363 | CANFloat2 = GetFloat4; |
tmccurbin | 40:92f08fdc32df | 364 | if (abs(CANFloat2*100 - *Pump2Buffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 365 | sprintf(Pump2Buffer,"%3.2d", int(CANFloat2*100)); |
tmccurbin | 40:92f08fdc32df | 366 | display.PutString(5,107,Pump2Buffer); |
tmccurbin | 40:92f08fdc32df | 367 | } |
tmccurbin | 40:92f08fdc32df | 368 | break; |
tmccurbin | 40:92f08fdc32df | 369 | case SYS_DCDC_STATUS_ID: |
tmccurbin | 40:92f08fdc32df | 370 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 371 | sprintf(DCDCBuffer,"%3.2d", int(CANFloat)); // How the heck are we interpreting this data |
tmccurbin | 40:92f08fdc32df | 372 | display.PutString(7,30,DCDCBuffer); |
tmccurbin | 40:92f08fdc32df | 373 | break; |
tmccurbin | 40:92f08fdc32df | 374 | case SYS_IMD_RESIST_ID: |
tmccurbin | 40:92f08fdc32df | 375 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 376 | if (abs(CANFloat - *IMDRBuffer) >= 1) { |
tmccurbin | 40:92f08fdc32df | 377 | sprintf(IMDRBuffer,"%3.2d", int(CANFloat)); |
tmccurbin | 40:92f08fdc32df | 378 | display.PutString(7,82,IMDRBuffer); |
tmccurbin | 40:92f08fdc32df | 379 | } |
tmccurbin | 40:92f08fdc32df | 380 | break; |
tmccurbin | 40:92f08fdc32df | 381 | default: |
tmccurbin | 40:92f08fdc32df | 382 | break; |
tmccurbin | 39:e6aa6dcf3f75 | 383 | } |
tmccurbin | 39:e6aa6dcf3f75 | 384 | break; |
tmccurbin | 36:8544a8900884 | 385 | |
tmccurbin | 40:92f08fdc32df | 386 | // CHARGE SCREEN ************************************************************* |
tmccurbin | 40:92f08fdc32df | 387 | case CHARGE_SCREEN: |
tmccurbin | 40:92f08fdc32df | 388 | switch (Rxmsg.id) { |
tmccurbin | 40:92f08fdc32df | 389 | case CHARGECURR_TX_ID: |
tmccurbin | 40:92f08fdc32df | 390 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 391 | if (abs(CANFloat - *ChargeCurrBuffer) >= 0.1) { |
tmccurbin | 40:92f08fdc32df | 392 | sprintf(ChargeCurrBuffer,"%3.2d", int(CANFloat)); // Amps |
tmccurbin | 40:92f08fdc32df | 393 | display.PutString(3,94,ChargeCurrBuffer); |
tmccurbin | 40:92f08fdc32df | 394 | } |
tmccurbin | 40:92f08fdc32df | 395 | break; |
tmccurbin | 40:92f08fdc32df | 396 | case VOLTAGE_TX_ID: |
tmccurbin | 40:92f08fdc32df | 397 | CANFloat = GetFloat; |
tmccurbin | 40:92f08fdc32df | 398 | if (abs(CANFloat - *BigBatVoltBuffer) >= 0.1) { |
tmccurbin | 40:92f08fdc32df | 399 | sprintf(BigBatVoltBuffer,"%3.2d", int(CANFloat)); // Volts |
tmccurbin | 40:92f08fdc32df | 400 | display.PutString(3,94,BigBatVoltBuffer); |
tmccurbin | 40:92f08fdc32df | 401 | } |
tmccurbin | 40:92f08fdc32df | 402 | break; |
tmccurbin | 40:92f08fdc32df | 403 | default: |
tmccurbin | 40:92f08fdc32df | 404 | break; |
tmccurbin | 36:8544a8900884 | 405 | } |
tmccurbin | 39:e6aa6dcf3f75 | 406 | break; |
tmccurbin | 36:8544a8900884 | 407 | default: |
tmccurbin | 36:8544a8900884 | 408 | break; |
kiran_mbed | 0:313541d8f8be | 409 | } |
tmccurbin | 36:8544a8900884 | 410 | } |
tmccurbin | 36:8544a8900884 | 411 | } |
tmccurbin | 36:8544a8900884 | 412 | |
tmccurbin | 36:8544a8900884 | 413 | void ConnectedStatusCANMsg() |
tmccurbin | 36:8544a8900884 | 414 | { |
tmccurbin | 36:8544a8900884 | 415 | CANMessage ConnectedStatus(0x600, &ConnectedStatusBuffer,1); |
tmccurbin | 36:8544a8900884 | 416 | SteeringCANPort.txWrite(ConnectedStatus); |
tmccurbin | 36:8544a8900884 | 417 | } |
tmccurbin | 36:8544a8900884 | 418 | |
palimar | 23:6681a38918c6 | 419 | |
tmccurbin | 36:8544a8900884 | 420 | void RequestStatusChange() |
tmccurbin | 36:8544a8900884 | 421 | { |
tmccurbin | 36:8544a8900884 | 422 | CANMessage TxDriveStatusRequest(0x601, &DriveStatusRequestBuffer,1); |
tmccurbin | 36:8544a8900884 | 423 | for (int j=0; j<10; j++) { |
tmccurbin | 36:8544a8900884 | 424 | SteeringCANPort.txWrite(TxDriveStatusRequest); |
tmccurbin | 36:8544a8900884 | 425 | } |
tmccurbin | 36:8544a8900884 | 426 | display.PutString(7,0," DRIVE REQUEST SENT "); |
tmccurbin | 36:8544a8900884 | 427 | Thread::wait(750); |
tmccurbin | 36:8544a8900884 | 428 | PrevScreen = !CurrScreen; // To force a screen update |
tmccurbin | 36:8544a8900884 | 429 | } |
tmccurbin | 36:8544a8900884 | 430 | |
tmccurbin | 36:8544a8900884 | 431 | |
tmccurbin | 36:8544a8900884 | 432 | void ResetSteeringWheel() |
tmccurbin | 36:8544a8900884 | 433 | { |
tmccurbin | 36:8544a8900884 | 434 | NVIC_SystemReset(); |
tmccurbin | 36:8544a8900884 | 435 | } |
tmccurbin | 36:8544a8900884 | 436 | |
tmccurbin | 36:8544a8900884 | 437 | |
tmccurbin | 36:8544a8900884 | 438 | void ResetCar() |
tmccurbin | 36:8544a8900884 | 439 | { |
tmccurbin | 36:8544a8900884 | 440 | CANMessage TxCarReset(0x602,&TxResetBuffer,1); |
tmccurbin | 36:8544a8900884 | 441 | for (int k=0; k<10; k++) { |
tmccurbin | 36:8544a8900884 | 442 | SteeringCANPort.txWriteDirect(TxCarReset); |
tmccurbin | 36:8544a8900884 | 443 | } |
tmccurbin | 36:8544a8900884 | 444 | } |