REVO_1_SteeringDisplay

Dependencies:   Digital_InOut KS0108 mbed

Committer:
kiran_mbed
Date:
Sat Sep 27 18:43:15 2014 +0000
Revision:
0:313541d8f8be
Steering_Display;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kiran_mbed 0:313541d8f8be 1 #include "Steering.h"
kiran_mbed 0:313541d8f8be 2
kiran_mbed 0:313541d8f8be 3 void HomeScreen()
kiran_mbed 0:313541d8f8be 4 {
kiran_mbed 0:313541d8f8be 5 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 6 ftc rcv,send;
kiran_mbed 0:313541d8f8be 7
kiran_mbed 0:313541d8f8be 8 send.FLOAT=45.4444;
kiran_mbed 0:313541d8f8be 9 Rxmsg.id=BATTERY_VOLTAGE_ID;
kiran_mbed 0:313541d8f8be 10 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 11 Rxmsg.data[i]=send.C_FLOAT[i];
kiran_mbed 0:313541d8f8be 12 display.ClearScreen();
kiran_mbed 0:313541d8f8be 13 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 14 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 15 {
kiran_mbed 0:313541d8f8be 16 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 17 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 18 if(Rxmsg.id == BATTERY_VOLTAGE_ID)
kiran_mbed 0:313541d8f8be 19 {
kiran_mbed 0:313541d8f8be 20 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 21 display.PrintString(" PV: ");
kiran_mbed 0:313541d8f8be 22 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 23 display.PrintString("V");
kiran_mbed 0:313541d8f8be 24 }
kiran_mbed 0:313541d8f8be 25 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 26 {
kiran_mbed 0:313541d8f8be 27 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 28 display.PrintString(" PP: ");
kiran_mbed 0:313541d8f8be 29 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 30 display.PrintString("KW");
kiran_mbed 0:313541d8f8be 31 }
kiran_mbed 0:313541d8f8be 32 if(Rxmsg.id == BATTERY_STATE_ID)
kiran_mbed 0:313541d8f8be 33 {
kiran_mbed 0:313541d8f8be 34 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 35 display.PrintString(" STATE: ");
kiran_mbed 0:313541d8f8be 36 display.PrintString(rcv.C_FLOAT);
kiran_mbed 0:313541d8f8be 37 }
kiran_mbed 0:313541d8f8be 38 }
kiran_mbed 0:313541d8f8be 39 wait(2);
kiran_mbed 0:313541d8f8be 40 return;
kiran_mbed 0:313541d8f8be 41 }
kiran_mbed 0:313541d8f8be 42
kiran_mbed 0:313541d8f8be 43 /*
kiran_mbed 0:313541d8f8be 44 void ShutdwnScreen()
kiran_mbed 0:313541d8f8be 45 {
kiran_mbed 0:313541d8f8be 46 screen=1;
kiran_mbed 0:313541d8f8be 47 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 48 uint16_t recv=0, temp=0, i=0;
kiran_mbed 0:313541d8f8be 49 //Test
kiran_mbed 0:313541d8f8be 50
kiran_mbed 0:313541d8f8be 51 //uint16_t Rxpoll=15;
kiran_mbed 0:313541d8f8be 52 //char Result[4]={0};
kiran_mbed 0:313541d8f8be 53 //Result[0]=(char)(Rxpoll&0x00ff);
kiran_mbed 0:313541d8f8be 54 //Result[1]=(char)((Rxpoll&0xff00)>>8);
kiran_mbed 0:313541d8f8be 55 //CANMessage Rxmsg(410,Result,sizeof(Result));
kiran_mbed 0:313541d8f8be 56
kiran_mbed 0:313541d8f8be 57 display.ClearScreen();
kiran_mbed 0:313541d8f8be 58 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 59 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 60 display.PrintString("SHTDWN SWTCH OPEN");
kiran_mbed 0:313541d8f8be 61
kiran_mbed 0:313541d8f8be 62 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 63 {
kiran_mbed 0:313541d8f8be 64 if(Rxmsg.id == SWITCH_ID)
kiran_mbed 0:313541d8f8be 65 {
kiran_mbed 0:313541d8f8be 66 recv=(((uint16_t)Rxmsg.data[1]<<8) | (0x00ff&(uint16_t)Rxmsg.data[0]));
kiran_mbed 0:313541d8f8be 67 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 68 while(i < 12)
kiran_mbed 0:313541d8f8be 69 {
kiran_mbed 0:313541d8f8be 70 temp=recv;
kiran_mbed 0:313541d8f8be 71 if(((temp & (1 << i))>>i) == 1)
kiran_mbed 0:313541d8f8be 72 {
kiran_mbed 0:313541d8f8be 73 display.GotoXY(SwitchPosition[i][0],SwitchPosition[i][1]);
kiran_mbed 0:313541d8f8be 74 display.PrintString(SwitchName[i]);
kiran_mbed 0:313541d8f8be 75 }
kiran_mbed 0:313541d8f8be 76 }
kiran_mbed 0:313541d8f8be 77 }
kiran_mbed 0:313541d8f8be 78 }
kiran_mbed 0:313541d8f8be 79 return;
kiran_mbed 0:313541d8f8be 80 }
kiran_mbed 0:313541d8f8be 81
kiran_mbed 0:313541d8f8be 82 void AMS1Screen()
kiran_mbed 0:313541d8f8be 83 {
kiran_mbed 0:313541d8f8be 84 screen=2;
kiran_mbed 0:313541d8f8be 85 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 86 ftc rcv;
kiran_mbed 0:313541d8f8be 87 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 88
kiran_mbed 0:313541d8f8be 89 display.ClearScreen();
kiran_mbed 0:313541d8f8be 90 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 91
kiran_mbed 0:313541d8f8be 92 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 93 {
kiran_mbed 0:313541d8f8be 94 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 95 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 96 if(Rxmsg.id == BATTERY_VOLTAGE_ID)
kiran_mbed 0:313541d8f8be 97 {
kiran_mbed 0:313541d8f8be 98 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 99 display.PrintString(" PV: ");
kiran_mbed 0:313541d8f8be 100 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 101 display.PrintString("V");
kiran_mbed 0:313541d8f8be 102 }
kiran_mbed 0:313541d8f8be 103 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 104 {
kiran_mbed 0:313541d8f8be 105 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 106 display.PrintString(" PV: ");
kiran_mbed 0:313541d8f8be 107 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 108 display.PrintString("KW");
kiran_mbed 0:313541d8f8be 109 }
kiran_mbed 0:313541d8f8be 110 if(Rxmsg.id == BATTERY_CURRENT_ID)
kiran_mbed 0:313541d8f8be 111 {
kiran_mbed 0:313541d8f8be 112 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 113 display.PrintString(" PC: ");
kiran_mbed 0:313541d8f8be 114 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 115 display.PrintString("KW");
kiran_mbed 0:313541d8f8be 116 }
kiran_mbed 0:313541d8f8be 117 }
kiran_mbed 0:313541d8f8be 118 }
kiran_mbed 0:313541d8f8be 119
kiran_mbed 0:313541d8f8be 120 void AMS2Screen()
kiran_mbed 0:313541d8f8be 121 {
kiran_mbed 0:313541d8f8be 122 screen=3;
kiran_mbed 0:313541d8f8be 123 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 124 ftc rcv;
kiran_mbed 0:313541d8f8be 125 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 126
kiran_mbed 0:313541d8f8be 127 display.ClearScreen();
kiran_mbed 0:313541d8f8be 128 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 129
kiran_mbed 0:313541d8f8be 130 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 131 {
kiran_mbed 0:313541d8f8be 132 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 133 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 134 if(Rxmsg.id == BATTERY_MIN_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 135 {
kiran_mbed 0:313541d8f8be 136 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 137 display.PrintString(" Min Cell V:");
kiran_mbed 0:313541d8f8be 138 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 139 display.PrintString("V");
kiran_mbed 0:313541d8f8be 140 }
kiran_mbed 0:313541d8f8be 141 if(Rxmsg.id == BATTERY_MAX_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 142 {
kiran_mbed 0:313541d8f8be 143 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 144 display.PrintString(" Max Cell V:");
kiran_mbed 0:313541d8f8be 145 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 146 display.PrintString("V");
kiran_mbed 0:313541d8f8be 147 }
kiran_mbed 0:313541d8f8be 148 if(Rxmsg.id == BATTERY_AVG_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 149 {
kiran_mbed 0:313541d8f8be 150 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 151 display.PrintString(" Max Cell V:");
kiran_mbed 0:313541d8f8be 152 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 153 display.PrintString("V");
kiran_mbed 0:313541d8f8be 154 }
kiran_mbed 0:313541d8f8be 155 }
kiran_mbed 0:313541d8f8be 156 }
kiran_mbed 0:313541d8f8be 157
kiran_mbed 0:313541d8f8be 158 void AMS3Screen()
kiran_mbed 0:313541d8f8be 159 {
kiran_mbed 0:313541d8f8be 160 screen=4;
kiran_mbed 0:313541d8f8be 161 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 162 ftc rcv;
kiran_mbed 0:313541d8f8be 163 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 164
kiran_mbed 0:313541d8f8be 165 display.ClearScreen();
kiran_mbed 0:313541d8f8be 166 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 167
kiran_mbed 0:313541d8f8be 168 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 169 {
kiran_mbed 0:313541d8f8be 170 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 171 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 172 if(Rxmsg.id == BATTERY_MIN_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 173 {
kiran_mbed 0:313541d8f8be 174 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 175 display.PrintString(" Min Cell T:");
kiran_mbed 0:313541d8f8be 176 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 177 display.PrintString("deg");
kiran_mbed 0:313541d8f8be 178 }
kiran_mbed 0:313541d8f8be 179 if(Rxmsg.id == BATTERY_MAX_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 180 {
kiran_mbed 0:313541d8f8be 181 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 182 display.PrintString(" Max Cell T:");
kiran_mbed 0:313541d8f8be 183 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 184 display.PrintString("deg");
kiran_mbed 0:313541d8f8be 185 }
kiran_mbed 0:313541d8f8be 186 if(Rxmsg.id == BATTERY_AVG_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 187 {
kiran_mbed 0:313541d8f8be 188 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 189 display.PrintString(" Avg Cell T:");
kiran_mbed 0:313541d8f8be 190 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 191 display.PrintString("deg");
kiran_mbed 0:313541d8f8be 192 }
kiran_mbed 0:313541d8f8be 193 }
kiran_mbed 0:313541d8f8be 194 }
kiran_mbed 0:313541d8f8be 195
kiran_mbed 0:313541d8f8be 196 void AMS4Screen()
kiran_mbed 0:313541d8f8be 197 {
kiran_mbed 0:313541d8f8be 198 screen =5;
kiran_mbed 0:313541d8f8be 199 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 200 ftc rcv;
kiran_mbed 0:313541d8f8be 201
kiran_mbed 0:313541d8f8be 202 display.ClearScreen();
kiran_mbed 0:313541d8f8be 203 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 204
kiran_mbed 0:313541d8f8be 205 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 206 {
kiran_mbed 0:313541d8f8be 207 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 208 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 209 if(Rxmsg.id == AMS_AIRS_ID)
kiran_mbed 0:313541d8f8be 210 {
kiran_mbed 0:313541d8f8be 211 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 212 display.PrintString(" AIRS: ");
kiran_mbed 0:313541d8f8be 213 display.PrintString(rcv.C_FLOAT);
kiran_mbed 0:313541d8f8be 214 }
kiran_mbed 0:313541d8f8be 215 if(Rxmsg.id == AMS_PRECHARGING_ID)
kiran_mbed 0:313541d8f8be 216 {
kiran_mbed 0:313541d8f8be 217 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 218 display.PrintString(" Precharging: ");
kiran_mbed 0:313541d8f8be 219 display.PrintString(rcv.C_FLOAT);
kiran_mbed 0:313541d8f8be 220 }
kiran_mbed 0:313541d8f8be 221 }
kiran_mbed 0:313541d8f8be 222 }
kiran_mbed 0:313541d8f8be 223 */
kiran_mbed 0:313541d8f8be 224 void ON()
kiran_mbed 0:313541d8f8be 225 {
kiran_mbed 0:313541d8f8be 226 char OnData[4]="ON";
kiran_mbed 0:313541d8f8be 227 CANMessage Txmsg(101,OnData,sizeof(OnData));
kiran_mbed 0:313541d8f8be 228 wait(0.1);
kiran_mbed 0:313541d8f8be 229
kiran_mbed 0:313541d8f8be 230 display.ClearScreen();
kiran_mbed 0:313541d8f8be 231 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 232 display.GotoXY(16,16);
kiran_mbed 0:313541d8f8be 233 display.PrintString(" ON INITIATED");
kiran_mbed 0:313541d8f8be 234 //screen=0;
kiran_mbed 0:313541d8f8be 235 return;
kiran_mbed 0:313541d8f8be 236 }
kiran_mbed 0:313541d8f8be 237
kiran_mbed 0:313541d8f8be 238 void ResetCommand()
kiran_mbed 0:313541d8f8be 239 {
kiran_mbed 0:313541d8f8be 240 char ResetData[4]="RES";
kiran_mbed 0:313541d8f8be 241 CANMessage Txmsg(102,ResetData,sizeof(ResetData));
kiran_mbed 0:313541d8f8be 242 wait(0.1);
kiran_mbed 0:313541d8f8be 243
kiran_mbed 0:313541d8f8be 244 display.ClearScreen();
kiran_mbed 0:313541d8f8be 245 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 246 display.GotoXY(16,16);
kiran_mbed 0:313541d8f8be 247 display.PrintString(" RESET INITIATED");
kiran_mbed 0:313541d8f8be 248 //screen=0;
kiran_mbed 0:313541d8f8be 249
kiran_mbed 0:313541d8f8be 250 return;
kiran_mbed 0:313541d8f8be 251 }
kiran_mbed 0:313541d8f8be 252
kiran_mbed 0:313541d8f8be 253 void Init()
kiran_mbed 0:313541d8f8be 254 {
kiran_mbed 0:313541d8f8be 255 pc.baud(230400);
kiran_mbed 0:313541d8f8be 256 CAN_Steering.frequency(500000);
kiran_mbed 0:313541d8f8be 257 }
kiran_mbed 0:313541d8f8be 258
kiran_mbed 0:313541d8f8be 259 int main()
kiran_mbed 0:313541d8f8be 260 {
kiran_mbed 0:313541d8f8be 261 Init();
kiran_mbed 0:313541d8f8be 262 //int flag=1;
kiran_mbed 0:313541d8f8be 263 wait(0.1);
kiran_mbed 0:313541d8f8be 264 display.GotoXY(10,16);
kiran_mbed 0:313541d8f8be 265 display.SelectFont(Arial_14,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 266 display.PrintString("Penn Electric Racing");
kiran_mbed 0:313541d8f8be 267 display.GotoXY(20,32);
kiran_mbed 0:313541d8f8be 268 display.PrintString("Live The Dream");
kiran_mbed 0:313541d8f8be 269 screen=0;
kiran_mbed 0:313541d8f8be 270 wait(2);
kiran_mbed 0:313541d8f8be 271
kiran_mbed 0:313541d8f8be 272 while(1)
kiran_mbed 0:313541d8f8be 273 {
kiran_mbed 0:313541d8f8be 274 if(biSWBL.read())
kiran_mbed 0:313541d8f8be 275 HomeScreen();
kiran_mbed 0:313541d8f8be 276
kiran_mbed 0:313541d8f8be 277 if(biSWTR.read())
kiran_mbed 0:313541d8f8be 278 ON();
kiran_mbed 0:313541d8f8be 279
kiran_mbed 0:313541d8f8be 280 if(biSWTL.read())
kiran_mbed 0:313541d8f8be 281 ResetCommand();
kiran_mbed 0:313541d8f8be 282
kiran_mbed 0:313541d8f8be 283 printf("SCreen:%d\n\r",screen);
kiran_mbed 0:313541d8f8be 284 wait(0.1);
kiran_mbed 0:313541d8f8be 285 }
kiran_mbed 0:313541d8f8be 286 }
kiran_mbed 0:313541d8f8be 287
kiran_mbed 0:313541d8f8be 288 /*
kiran_mbed 0:313541d8f8be 289 else if(screen == 1)
kiran_mbed 0:313541d8f8be 290 ShutdwnScreen();
kiran_mbed 0:313541d8f8be 291 else if(screen == 2)
kiran_mbed 0:313541d8f8be 292 AMS1Screen();
kiran_mbed 0:313541d8f8be 293 else if(screen == 3)
kiran_mbed 0:313541d8f8be 294 AMS2Screen();
kiran_mbed 0:313541d8f8be 295 else if(screen == 4)
kiran_mbed 0:313541d8f8be 296 AMS3Screen();
kiran_mbed 0:313541d8f8be 297 else if(screen == 5)
kiran_mbed 0:313541d8f8be 298 AMS4Screen();
kiran_mbed 0:313541d8f8be 299 */
kiran_mbed 0:313541d8f8be 300 /*
kiran_mbed 0:313541d8f8be 301 if(biSWBR.read())
kiran_mbed 0:313541d8f8be 302 {
kiran_mbed 0:313541d8f8be 303 if(screen == maxScreen)
kiran_mbed 0:313541d8f8be 304 screen=0;
kiran_mbed 0:313541d8f8be 305 else
kiran_mbed 0:313541d8f8be 306 ++screen;
kiran_mbed 0:313541d8f8be 307 wait(1);
kiran_mbed 0:313541d8f8be 308 }
kiran_mbed 0:313541d8f8be 309 */