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@22:ab33195882e3, 2014-11-04 (annotated)
- Committer:
- tmccurbin
- Date:
- Tue Nov 04 08:12:34 2014 +0000
- Revision:
- 22:ab33195882e3
- Parent:
- 21:56890c41ecf1
- Child:
- 25:fc63a5bffffc
Implemented code to differentiate button-holding
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 | 22:ab33195882e3 | 3 | #define Reset_Threshold 32000 |
tmccurbin | 22:ab33195882e3 | 4 | #define Drive_Threshold 32000 |
tmccurbin | 22:ab33195882e3 | 5 | int BL_Button_Status = 0; |
tmccurbin | 22:ab33195882e3 | 6 | int BR_Button_Status = 0; |
tmccurbin | 22:ab33195882e3 | 7 | |
kiran_mbed | 0:313541d8f8be | 8 | void HomeScreen() |
kiran_mbed | 0:313541d8f8be | 9 | { |
palimar | 21:56890c41ecf1 | 10 | |
kiran_mbed | 0:313541d8f8be | 11 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 12 | rcv.FLOAT=0.0; |
kiran_mbed | 0:313541d8f8be | 13 | char dat[4]; |
kiran_mbed | 0:313541d8f8be | 14 | float power_ratio=0.0; |
kiran_mbed | 0:313541d8f8be | 15 | printf("Homescreen\n\r"); |
kiran_mbed | 0:313541d8f8be | 16 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 17 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 18 | display.GotoXY(0,0); |
kiran_mbed | 0:313541d8f8be | 19 | display.PrintString(" HOME SCREEN"); |
kiran_mbed | 0:313541d8f8be | 20 | while( !(biSWTL.read() || biSWTR.read() || biSWBR.read()) ) |
kiran_mbed | 0:313541d8f8be | 21 | { |
palimar | 21:56890c41ecf1 | 22 | CANMessage Rxmsg; |
palimar | 16:d2953809fb31 | 23 | if(CAN_Steering_Buffer.rxRead(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 24 | { |
kiran_mbed | 0:313541d8f8be | 25 | for(int i=0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 26 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
kiran_mbed | 0:313541d8f8be | 27 | if(Rxmsg.id == BATTERY_VOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 28 | { |
kiran_mbed | 0:313541d8f8be | 29 | display.GotoXY(0,16); |
kiran_mbed | 0:313541d8f8be | 30 | display.PrintString(" PV: "); |
kiran_mbed | 0:313541d8f8be | 31 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 32 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 33 | display.PrintString("V"); |
kiran_mbed | 0:313541d8f8be | 34 | } |
kiran_mbed | 0:313541d8f8be | 35 | if(Rxmsg.id == BATTERY_POWER_ID) |
kiran_mbed | 0:313541d8f8be | 36 | { |
kiran_mbed | 0:313541d8f8be | 37 | display.GotoXY(64,16); |
kiran_mbed | 0:313541d8f8be | 38 | display.PrintString(" PP: "); |
kiran_mbed | 0:313541d8f8be | 39 | power_ratio=rcv.FLOAT/10000; |
kiran_mbed | 0:313541d8f8be | 40 | sprintf(dat,"%2.2f",power_ratio); |
kiran_mbed | 0:313541d8f8be | 41 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 42 | display.PrintString("kW"); |
kiran_mbed | 0:313541d8f8be | 43 | } |
kiran_mbed | 0:313541d8f8be | 44 | if(Rxmsg.id == PCM_STATE_ID) |
kiran_mbed | 0:313541d8f8be | 45 | { |
kiran_mbed | 0:313541d8f8be | 46 | display.GotoXY(0,32); |
kiran_mbed | 0:313541d8f8be | 47 | display.PrintString(" STATE: "); |
kiran_mbed | 0:313541d8f8be | 48 | display.PrintNumber(rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 49 | } |
kiran_mbed | 0:313541d8f8be | 50 | } |
kiran_mbed | 0:313541d8f8be | 51 | } |
kiran_mbed | 0:313541d8f8be | 52 | return; |
kiran_mbed | 0:313541d8f8be | 53 | } |
kiran_mbed | 0:313541d8f8be | 54 | |
kiran_mbed | 0:313541d8f8be | 55 | void AMSScreen1() |
kiran_mbed | 0:313541d8f8be | 56 | { |
kiran_mbed | 0:313541d8f8be | 57 | CANMessage Rxmsg; |
kiran_mbed | 0:313541d8f8be | 58 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 59 | char dat[4]; |
kiran_mbed | 0:313541d8f8be | 60 | rcv.FLOAT=0.0; |
kiran_mbed | 0:313541d8f8be | 61 | printf("AMSScreen1"); |
kiran_mbed | 0:313541d8f8be | 62 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 63 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 64 | while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) ) |
kiran_mbed | 0:313541d8f8be | 65 | { |
kiran_mbed | 0:313541d8f8be | 66 | printf("iN LOOP1"); |
palimar | 16:d2953809fb31 | 67 | if(CAN_Steering_Buffer.rxRead(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 68 | { |
kiran_mbed | 0:313541d8f8be | 69 | for(int i=0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 70 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
kiran_mbed | 0:313541d8f8be | 71 | if(Rxmsg.id == BATTERY_VOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 72 | { |
kiran_mbed | 0:313541d8f8be | 73 | display.GotoXY(0,0); |
kiran_mbed | 0:313541d8f8be | 74 | display.PrintString(" pv: "); |
kiran_mbed | 0:313541d8f8be | 75 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 76 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 77 | } |
kiran_mbed | 0:313541d8f8be | 78 | if(Rxmsg.id == BATTERY_POWER_ID) |
kiran_mbed | 0:313541d8f8be | 79 | { |
kiran_mbed | 0:313541d8f8be | 80 | display.GotoXY(0,16); |
kiran_mbed | 0:313541d8f8be | 81 | display.PrintString(" pp: "); |
kiran_mbed | 0:313541d8f8be | 82 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 83 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 84 | } |
kiran_mbed | 0:313541d8f8be | 85 | if(Rxmsg.id == BATTERY_CURRENT_ID) |
kiran_mbed | 0:313541d8f8be | 86 | { |
kiran_mbed | 0:313541d8f8be | 87 | display.GotoXY(0,32); |
kiran_mbed | 0:313541d8f8be | 88 | display.PrintString(" pi: "); |
kiran_mbed | 0:313541d8f8be | 89 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 90 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 91 | } |
kiran_mbed | 0:313541d8f8be | 92 | |
kiran_mbed | 0:313541d8f8be | 93 | //Column 2 |
kiran_mbed | 0:313541d8f8be | 94 | if(Rxmsg.id == BATTERY_MIN_CELLVOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 95 | { |
kiran_mbed | 0:313541d8f8be | 96 | display.GotoXY(49,0); |
kiran_mbed | 0:313541d8f8be | 97 | display.PrintString(" min cell V: "); |
kiran_mbed | 0:313541d8f8be | 98 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 99 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 100 | } |
kiran_mbed | 0:313541d8f8be | 101 | if(Rxmsg.id == BATTERY_MAX_CELLVOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 102 | { |
kiran_mbed | 0:313541d8f8be | 103 | display.GotoXY(49,16); |
kiran_mbed | 0:313541d8f8be | 104 | display.PrintString(" max cell V: "); |
kiran_mbed | 0:313541d8f8be | 105 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 106 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 107 | } |
kiran_mbed | 0:313541d8f8be | 108 | if(Rxmsg.id == BATTERY_AVG_CELLVOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 109 | { |
kiran_mbed | 0:313541d8f8be | 110 | display.GotoXY(49,32); |
kiran_mbed | 0:313541d8f8be | 111 | display.PrintString(" avg cell V: "); |
kiran_mbed | 0:313541d8f8be | 112 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 113 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 114 | } |
kiran_mbed | 0:313541d8f8be | 115 | } |
kiran_mbed | 0:313541d8f8be | 116 | screen=1; |
kiran_mbed | 0:313541d8f8be | 117 | } |
kiran_mbed | 0:313541d8f8be | 118 | return; |
kiran_mbed | 0:313541d8f8be | 119 | } |
kiran_mbed | 0:313541d8f8be | 120 | |
kiran_mbed | 0:313541d8f8be | 121 | void AMSScreen2() |
kiran_mbed | 0:313541d8f8be | 122 | { |
kiran_mbed | 0:313541d8f8be | 123 | CANMessage Rxmsg; |
kiran_mbed | 0:313541d8f8be | 124 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 125 | char dat[4]; |
kiran_mbed | 0:313541d8f8be | 126 | //ftc send; |
kiran_mbed | 0:313541d8f8be | 127 | rcv.FLOAT=0.0; |
kiran_mbed | 0:313541d8f8be | 128 | //send.FLOAT=65.6432; |
kiran_mbed | 0:313541d8f8be | 129 | printf("AMSScreen2\n\r"); |
kiran_mbed | 0:313541d8f8be | 130 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 131 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 132 | while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) ) |
kiran_mbed | 0:313541d8f8be | 133 | { |
kiran_mbed | 0:313541d8f8be | 134 | printf("iN LOOP2"); |
palimar | 16:d2953809fb31 | 135 | if(CAN_Steering_Buffer.rxRead(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 136 | { |
kiran_mbed | 0:313541d8f8be | 137 | for(int i=0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 138 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
kiran_mbed | 0:313541d8f8be | 139 | if(Rxmsg.id == BATTERY_MIN_CELLTEMPERATURE_ID) |
kiran_mbed | 0:313541d8f8be | 140 | { |
kiran_mbed | 0:313541d8f8be | 141 | display.GotoXY(0,0); |
kiran_mbed | 0:313541d8f8be | 142 | display.PrintString(" mn cll T: "); |
kiran_mbed | 0:313541d8f8be | 143 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 144 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 145 | } |
kiran_mbed | 0:313541d8f8be | 146 | if(Rxmsg.id == BATTERY_MAX_CELLTEMPERATURE_ID) |
kiran_mbed | 0:313541d8f8be | 147 | { |
kiran_mbed | 0:313541d8f8be | 148 | display.GotoXY(0,16); |
kiran_mbed | 0:313541d8f8be | 149 | display.PrintString(" mx cll T: "); |
kiran_mbed | 0:313541d8f8be | 150 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 151 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 152 | } |
kiran_mbed | 0:313541d8f8be | 153 | if(Rxmsg.id == BATTERY_AVG_CELLTEMPERATURE_ID) |
kiran_mbed | 0:313541d8f8be | 154 | { |
kiran_mbed | 0:313541d8f8be | 155 | display.GotoXY(0,32); |
kiran_mbed | 0:313541d8f8be | 156 | display.PrintString(" avg cell T: "); |
kiran_mbed | 0:313541d8f8be | 157 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 158 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 159 | } |
kiran_mbed | 0:313541d8f8be | 160 | |
kiran_mbed | 0:313541d8f8be | 161 | //Column 2 |
kiran_mbed | 0:313541d8f8be | 162 | if(Rxmsg.id == AMS_BATTERY_STATE) |
kiran_mbed | 0:313541d8f8be | 163 | { |
kiran_mbed | 0:313541d8f8be | 164 | if((rcv.C_FLOAT[0] & 0xC0) == 0xC0) |
kiran_mbed | 0:313541d8f8be | 165 | { |
kiran_mbed | 0:313541d8f8be | 166 | display.GotoXY(70,0); |
kiran_mbed | 0:313541d8f8be | 167 | display.PrintString(" AIRS: "); |
kiran_mbed | 0:313541d8f8be | 168 | display.PrintString("CLOS"); |
kiran_mbed | 0:313541d8f8be | 169 | } |
kiran_mbed | 0:313541d8f8be | 170 | else |
kiran_mbed | 0:313541d8f8be | 171 | { |
kiran_mbed | 0:313541d8f8be | 172 | display.GotoXY(70,0); |
kiran_mbed | 0:313541d8f8be | 173 | display.PrintString(" AIRS: "); |
kiran_mbed | 0:313541d8f8be | 174 | display.PrintString("OPEN"); |
kiran_mbed | 0:313541d8f8be | 175 | } |
kiran_mbed | 0:313541d8f8be | 176 | |
kiran_mbed | 0:313541d8f8be | 177 | if((rcv.C_FLOAT[0] & 0x04) == 0x04) |
kiran_mbed | 0:313541d8f8be | 178 | { |
kiran_mbed | 0:313541d8f8be | 179 | display.GotoXY(70,16); |
kiran_mbed | 0:313541d8f8be | 180 | display.PrintString(" Prchrg: "); |
kiran_mbed | 0:313541d8f8be | 181 | display.PrintString("on"); |
kiran_mbed | 0:313541d8f8be | 182 | } |
kiran_mbed | 0:313541d8f8be | 183 | else |
kiran_mbed | 0:313541d8f8be | 184 | { |
kiran_mbed | 0:313541d8f8be | 185 | display.GotoXY(70,16); |
kiran_mbed | 0:313541d8f8be | 186 | display.PrintString(" Prchrg: "); |
kiran_mbed | 0:313541d8f8be | 187 | display.PrintString("off"); |
kiran_mbed | 0:313541d8f8be | 188 | } |
kiran_mbed | 0:313541d8f8be | 189 | } |
kiran_mbed | 0:313541d8f8be | 190 | if(Rxmsg.id == AMS_BATTERY_STATE) |
kiran_mbed | 0:313541d8f8be | 191 | { |
kiran_mbed | 0:313541d8f8be | 192 | display.GotoXY(70,16); |
kiran_mbed | 0:313541d8f8be | 193 | display.PrintString(" Prchrg: "); |
kiran_mbed | 0:313541d8f8be | 194 | display.PrintString("off"); |
kiran_mbed | 0:313541d8f8be | 195 | } |
kiran_mbed | 0:313541d8f8be | 196 | } |
kiran_mbed | 0:313541d8f8be | 197 | screen=0; |
kiran_mbed | 0:313541d8f8be | 198 | } |
kiran_mbed | 0:313541d8f8be | 199 | return; |
kiran_mbed | 0:313541d8f8be | 200 | } |
kiran_mbed | 0:313541d8f8be | 201 | |
palimar | 6:99e754ac888f | 202 | void display_speed_data(void const *args) { |
palimar | 6:99e754ac888f | 203 | while (true) { |
palimar | 6:99e754ac888f | 204 | display.GotoXY(10,16); |
palimar | 6:99e754ac888f | 205 | display.SelectFont(Arial_14,BLACK,ReadData); |
palimar | 6:99e754ac888f | 206 | char buf[10]; |
palimar | 6:99e754ac888f | 207 | int a = rand()%100; |
palimar | 6:99e754ac888f | 208 | sprintf(buf, "%d", a); |
palimar | 6:99e754ac888f | 209 | display.PrintString("Speed: "); |
palimar | 6:99e754ac888f | 210 | display.PrintString(buf); |
palimar | 6:99e754ac888f | 211 | display.PrintString("mph"); |
palimar | 6:99e754ac888f | 212 | } |
palimar | 6:99e754ac888f | 213 | } |
palimar | 6:99e754ac888f | 214 | |
palimar | 6:99e754ac888f | 215 | |
tmccurbin | 22:ab33195882e3 | 216 | void Drive_Request() |
kiran_mbed | 0:313541d8f8be | 217 | { |
palimar | 13:1f05dcd9ae0e | 218 | |
palimar | 13:1f05dcd9ae0e | 219 | char drive_status_request = !drive_status; |
palimar | 13:1f05dcd9ae0e | 220 | char * status_string; |
palimar | 9:e946cafa3cae | 221 | |
palimar | 13:1f05dcd9ae0e | 222 | if(drive_status_request){ |
palimar | 13:1f05dcd9ae0e | 223 | status_string = "ON"; |
palimar | 13:1f05dcd9ae0e | 224 | } |
palimar | 13:1f05dcd9ae0e | 225 | else{ |
palimar | 13:1f05dcd9ae0e | 226 | status_string = "OFF"; |
palimar | 13:1f05dcd9ae0e | 227 | } |
palimar | 13:1f05dcd9ae0e | 228 | |
palimar | 13:1f05dcd9ae0e | 229 | for(int i = 0; i < 10; i++){ |
palimar | 16:d2953809fb31 | 230 | CAN_Steering_Buffer.txWrite(Txmsg_drive_status_request); |
palimar | 13:1f05dcd9ae0e | 231 | } |
palimar | 6:99e754ac888f | 232 | |
tmccurbin | 22:ab33195882e3 | 233 | //Button Press code |
tmccurbin | 22:ab33195882e3 | 234 | if (BL_Button_Status == 0) |
tmccurbin | 22:ab33195882e3 | 235 | { |
tmccurbin | 22:ab33195882e3 | 236 | display.ClearScreen(); |
tmccurbin | 22:ab33195882e3 | 237 | display.SelectFont(Arial12,BLACK,ReadData); |
tmccurbin | 22:ab33195882e3 | 238 | display.GotoXY(26,16); |
tmccurbin | 22:ab33195882e3 | 239 | display.PrintString("Drive Initiated"); |
tmccurbin | 22:ab33195882e3 | 240 | printf("Drive Initiated\n\r"); |
tmccurbin | 22:ab33195882e3 | 241 | BL_Button_Status = BL_Button_Status + 1; |
tmccurbin | 22:ab33195882e3 | 242 | } |
tmccurbin | 22:ab33195882e3 | 243 | else |
tmccurbin | 22:ab33195882e3 | 244 | { |
tmccurbin | 22:ab33195882e3 | 245 | BL_Button_Status = BL_Button_Status + 1; |
tmccurbin | 22:ab33195882e3 | 246 | } |
palimar | 9:e946cafa3cae | 247 | |
palimar | 21:56890c41ecf1 | 248 | printf("%s\n\r", status_string); |
kiran_mbed | 0:313541d8f8be | 249 | return; |
kiran_mbed | 0:313541d8f8be | 250 | } |
kiran_mbed | 0:313541d8f8be | 251 | |
palimar | 9:e946cafa3cae | 252 | void reset() |
kiran_mbed | 0:313541d8f8be | 253 | { |
tmccurbin | 22:ab33195882e3 | 254 | if (BR_Button_Status == 0) |
tmccurbin | 22:ab33195882e3 | 255 | { |
tmccurbin | 22:ab33195882e3 | 256 | display.ClearScreen(); |
tmccurbin | 22:ab33195882e3 | 257 | display.SelectFont(Arial12,BLACK,ReadData); |
tmccurbin | 22:ab33195882e3 | 258 | display.GotoXY(16,16); |
tmccurbin | 22:ab33195882e3 | 259 | display.PrintString("Hold To Reset"); |
tmccurbin | 22:ab33195882e3 | 260 | printf("Hold to reset\n\r"); |
tmccurbin | 22:ab33195882e3 | 261 | BR_Button_Status = BR_Button_Status + 1; |
tmccurbin | 22:ab33195882e3 | 262 | } |
tmccurbin | 22:ab33195882e3 | 263 | else if (BR_Button_Status < Reset_Threshold) |
tmccurbin | 22:ab33195882e3 | 264 | { |
tmccurbin | 22:ab33195882e3 | 265 | BR_Button_Status = BR_Button_Status + 1; |
tmccurbin | 22:ab33195882e3 | 266 | } |
tmccurbin | 22:ab33195882e3 | 267 | else if (BR_Button_Status >= Reset_Threshold) |
tmccurbin | 22:ab33195882e3 | 268 | { |
tmccurbin | 22:ab33195882e3 | 269 | for (int i = 0; i < 10; i ++) |
tmccurbin | 22:ab33195882e3 | 270 | { |
tmccurbin | 22:ab33195882e3 | 271 | CAN_Steering_Buffer.txWriteDirect(Txmsg_reset); |
tmccurbin | 22:ab33195882e3 | 272 | printf("Reset Initiated\n\r"); |
tmccurbin | 22:ab33195882e3 | 273 | } |
tmccurbin | 22:ab33195882e3 | 274 | BR_Button_Status = BR_Button_Status + 1; |
tmccurbin | 22:ab33195882e3 | 275 | mbed_reset(); |
tmccurbin | 22:ab33195882e3 | 276 | } |
kiran_mbed | 0:313541d8f8be | 277 | } |
kiran_mbed | 0:313541d8f8be | 278 | |
kiran_mbed | 0:313541d8f8be | 279 | void Powerstream() |
kiran_mbed | 0:313541d8f8be | 280 | { |
kiran_mbed | 0:313541d8f8be | 281 | CANMessage Rxmsg; |
kiran_mbed | 0:313541d8f8be | 282 | float power_ratio; |
kiran_mbed | 0:313541d8f8be | 283 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 284 | rcv.FLOAT=0.0; |
palimar | 16:d2953809fb31 | 285 | if(CAN_Steering_Buffer.rxRead(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 286 | { |
kiran_mbed | 0:313541d8f8be | 287 | if(Rxmsg.id == BATTERY_POWER_ID) |
kiran_mbed | 0:313541d8f8be | 288 | { |
palimar | 6:99e754ac888f | 289 | for(int i=0; i<4; i++){ |
kiran_mbed | 0:313541d8f8be | 290 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
palimar | 6:99e754ac888f | 291 | } |
kiran_mbed | 0:313541d8f8be | 292 | power_ratio=rcv.FLOAT/80000; |
kiran_mbed | 0:313541d8f8be | 293 | ledstream.write(power_ratio); |
kiran_mbed | 0:313541d8f8be | 294 | } |
kiran_mbed | 0:313541d8f8be | 295 | } |
kiran_mbed | 0:313541d8f8be | 296 | } |
kiran_mbed | 0:313541d8f8be | 297 | |
kiran_mbed | 0:313541d8f8be | 298 | void Init() |
kiran_mbed | 0:313541d8f8be | 299 | { |
kiran_mbed | 0:313541d8f8be | 300 | pc.baud(230400); |
palimar | 9:e946cafa3cae | 301 | drive_status = 0; |
palimar | 13:1f05dcd9ae0e | 302 | drive_status_request = 1; |
palimar | 9:e946cafa3cae | 303 | reset_body = 0; |
kiran_mbed | 0:313541d8f8be | 304 | ledstream.write(0); |
kiran_mbed | 0:313541d8f8be | 305 | call_ledstream.attach(&Powerstream,0.1); |
kiran_mbed | 0:313541d8f8be | 306 | } |
kiran_mbed | 0:313541d8f8be | 307 | |
palimar | 21:56890c41ecf1 | 308 | void update_vars(void const *args) { |
palimar | 21:56890c41ecf1 | 309 | while (true) { |
palimar | 21:56890c41ecf1 | 310 | CANMessage Rxmsg; |
palimar | 21:56890c41ecf1 | 311 | if(CAN_Steering_Buffer.rxRead(Rxmsg)){ |
palimar | 21:56890c41ecf1 | 312 | if(Rxmsg.id == PCM_STATE_ID){ |
palimar | 21:56890c41ecf1 | 313 | ds_mutex.lock(); |
palimar | 21:56890c41ecf1 | 314 | drive_status = Rxmsg.data[0]; |
palimar | 21:56890c41ecf1 | 315 | ds_mutex.unlock(); |
palimar | 21:56890c41ecf1 | 316 | } |
palimar | 21:56890c41ecf1 | 317 | } |
palimar | 21:56890c41ecf1 | 318 | } |
palimar | 21:56890c41ecf1 | 319 | } |
palimar | 21:56890c41ecf1 | 320 | |
kiran_mbed | 0:313541d8f8be | 321 | int main() |
kiran_mbed | 0:313541d8f8be | 322 | { |
palimar | 4:a4fb060e7840 | 323 | // Init all |
kiran_mbed | 0:313541d8f8be | 324 | Init(); |
kiran_mbed | 0:313541d8f8be | 325 | wait(0.1); |
palimar | 4:a4fb060e7840 | 326 | |
palimar | 4:a4fb060e7840 | 327 | //Init Display |
kiran_mbed | 0:313541d8f8be | 328 | display.GotoXY(10,16); |
kiran_mbed | 0:313541d8f8be | 329 | display.SelectFont(Arial_14,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 330 | display.PrintString("Penn Electric Racing"); |
palimar | 6:99e754ac888f | 331 | |
palimar | 21:56890c41ecf1 | 332 | Thread update_thread(update_vars); |
palimar | 21:56890c41ecf1 | 333 | |
palimar | 6:99e754ac888f | 334 | wait(1); |
palimar | 4:a4fb060e7840 | 335 | |
palimar | 4:a4fb060e7840 | 336 | // Start to read buttons on main thread |
kiran_mbed | 0:313541d8f8be | 337 | |
kiran_mbed | 0:313541d8f8be | 338 | while(1) |
kiran_mbed | 0:313541d8f8be | 339 | { |
kiran_mbed | 0:313541d8f8be | 340 | if(biSWBL.read()) |
kiran_mbed | 0:313541d8f8be | 341 | { |
tmccurbin | 22:ab33195882e3 | 342 | Drive_Request; |
kiran_mbed | 0:313541d8f8be | 343 | } |
tmccurbin | 22:ab33195882e3 | 344 | else if(biSWBR.read()) |
kiran_mbed | 0:313541d8f8be | 345 | { |
palimar | 9:e946cafa3cae | 346 | reset(); |
kiran_mbed | 0:313541d8f8be | 347 | } |
tmccurbin | 22:ab33195882e3 | 348 | else |
tmccurbin | 22:ab33195882e3 | 349 | { |
tmccurbin | 22:ab33195882e3 | 350 | BR_Button_Status = 0; |
tmccurbin | 22:ab33195882e3 | 351 | BL_Button_Status = 0; |
tmccurbin | 22:ab33195882e3 | 352 | } |
tmccurbin | 22:ab33195882e3 | 353 | printf("BL %d BR %d \n", 'BL_Button_Status', 'BR_Button_Status'); |
kiran_mbed | 0:313541d8f8be | 354 | } |
kiran_mbed | 0:313541d8f8be | 355 | } |