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;
kiran_mbed 0:313541d8f8be 7 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 8 char dat[4];
kiran_mbed 0:313541d8f8be 9 float power_ratio=0.0;
kiran_mbed 0:313541d8f8be 10 printf("Homescreen\n\r");
kiran_mbed 0:313541d8f8be 11 display.ClearScreen();
kiran_mbed 0:313541d8f8be 12 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 13 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 14 display.PrintString(" HOME SCREEN");
kiran_mbed 0:313541d8f8be 15 while( !(biSWTL.read() || biSWTR.read() || biSWBR.read()) )
kiran_mbed 0:313541d8f8be 16 {
kiran_mbed 0:313541d8f8be 17 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 18 {
kiran_mbed 0:313541d8f8be 19 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 20 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 21 if(Rxmsg.id == BATTERY_VOLTAGE_ID)
kiran_mbed 0:313541d8f8be 22 {
kiran_mbed 0:313541d8f8be 23 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 24 display.PrintString(" PV: ");
kiran_mbed 0:313541d8f8be 25 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 26 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 27 display.PrintString("V");
kiran_mbed 0:313541d8f8be 28 }
kiran_mbed 0:313541d8f8be 29 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 30 {
kiran_mbed 0:313541d8f8be 31 display.GotoXY(64,16);
kiran_mbed 0:313541d8f8be 32 display.PrintString(" PP: ");
kiran_mbed 0:313541d8f8be 33 power_ratio=rcv.FLOAT/10000;
kiran_mbed 0:313541d8f8be 34 sprintf(dat,"%2.2f",power_ratio);
kiran_mbed 0:313541d8f8be 35 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 36 display.PrintString("kW");
kiran_mbed 0:313541d8f8be 37 }
kiran_mbed 0:313541d8f8be 38 if(Rxmsg.id == PCM_STATE_ID)
kiran_mbed 0:313541d8f8be 39 {
kiran_mbed 0:313541d8f8be 40 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 41 display.PrintString(" STATE: ");
kiran_mbed 0:313541d8f8be 42 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 43 }
kiran_mbed 0:313541d8f8be 44 }
kiran_mbed 0:313541d8f8be 45 }
kiran_mbed 0:313541d8f8be 46 return;
kiran_mbed 0:313541d8f8be 47 }
kiran_mbed 0:313541d8f8be 48
kiran_mbed 0:313541d8f8be 49 void AMSScreen1()
kiran_mbed 0:313541d8f8be 50 {
kiran_mbed 0:313541d8f8be 51 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 52 ftc rcv;
kiran_mbed 0:313541d8f8be 53 char dat[4];
kiran_mbed 0:313541d8f8be 54 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 55 printf("AMSScreen1");
kiran_mbed 0:313541d8f8be 56 display.ClearScreen();
kiran_mbed 0:313541d8f8be 57 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 58 while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
kiran_mbed 0:313541d8f8be 59 {
kiran_mbed 0:313541d8f8be 60 printf("iN LOOP1");
kiran_mbed 0:313541d8f8be 61 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 62 {
kiran_mbed 0:313541d8f8be 63 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 64 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 65 if(Rxmsg.id == BATTERY_VOLTAGE_ID)
kiran_mbed 0:313541d8f8be 66 {
kiran_mbed 0:313541d8f8be 67 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 68 display.PrintString(" pv: ");
kiran_mbed 0:313541d8f8be 69 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 70 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 71 }
kiran_mbed 0:313541d8f8be 72 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 73 {
kiran_mbed 0:313541d8f8be 74 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 75 display.PrintString(" pp: ");
kiran_mbed 0:313541d8f8be 76 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 77 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 78 }
kiran_mbed 0:313541d8f8be 79 if(Rxmsg.id == BATTERY_CURRENT_ID)
kiran_mbed 0:313541d8f8be 80 {
kiran_mbed 0:313541d8f8be 81 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 82 display.PrintString(" pi: ");
kiran_mbed 0:313541d8f8be 83 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 84 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 85 }
kiran_mbed 0:313541d8f8be 86
kiran_mbed 0:313541d8f8be 87 //Column 2
kiran_mbed 0:313541d8f8be 88 if(Rxmsg.id == BATTERY_MIN_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 89 {
kiran_mbed 0:313541d8f8be 90 display.GotoXY(49,0);
kiran_mbed 0:313541d8f8be 91 display.PrintString(" min cell V: ");
kiran_mbed 0:313541d8f8be 92 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 93 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 94 }
kiran_mbed 0:313541d8f8be 95 if(Rxmsg.id == BATTERY_MAX_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 96 {
kiran_mbed 0:313541d8f8be 97 display.GotoXY(49,16);
kiran_mbed 0:313541d8f8be 98 display.PrintString(" max cell V: ");
kiran_mbed 0:313541d8f8be 99 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 100 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 101 }
kiran_mbed 0:313541d8f8be 102 if(Rxmsg.id == BATTERY_AVG_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 103 {
kiran_mbed 0:313541d8f8be 104 display.GotoXY(49,32);
kiran_mbed 0:313541d8f8be 105 display.PrintString(" avg cell V: ");
kiran_mbed 0:313541d8f8be 106 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 107 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 108 }
kiran_mbed 0:313541d8f8be 109 }
kiran_mbed 0:313541d8f8be 110 screen=1;
kiran_mbed 0:313541d8f8be 111 }
kiran_mbed 0:313541d8f8be 112 return;
kiran_mbed 0:313541d8f8be 113 }
kiran_mbed 0:313541d8f8be 114
kiran_mbed 0:313541d8f8be 115 void AMSScreen2()
kiran_mbed 0:313541d8f8be 116 {
kiran_mbed 0:313541d8f8be 117 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 118 ftc rcv;
kiran_mbed 0:313541d8f8be 119 char dat[4];
kiran_mbed 0:313541d8f8be 120 //ftc send;
kiran_mbed 0:313541d8f8be 121 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 122 //send.FLOAT=65.6432;
kiran_mbed 0:313541d8f8be 123 printf("AMSScreen2\n\r");
kiran_mbed 0:313541d8f8be 124 display.ClearScreen();
kiran_mbed 0:313541d8f8be 125 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 126 while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
kiran_mbed 0:313541d8f8be 127 {
kiran_mbed 0:313541d8f8be 128 printf("iN LOOP2");
kiran_mbed 0:313541d8f8be 129 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 130 {
kiran_mbed 0:313541d8f8be 131 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 132 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 133 if(Rxmsg.id == BATTERY_MIN_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 134 {
kiran_mbed 0:313541d8f8be 135 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 136 display.PrintString(" mn cll T: ");
kiran_mbed 0:313541d8f8be 137 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 138 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 139 }
kiran_mbed 0:313541d8f8be 140 if(Rxmsg.id == BATTERY_MAX_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 141 {
kiran_mbed 0:313541d8f8be 142 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 143 display.PrintString(" mx cll T: ");
kiran_mbed 0:313541d8f8be 144 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 145 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 146 }
kiran_mbed 0:313541d8f8be 147 if(Rxmsg.id == BATTERY_AVG_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 148 {
kiran_mbed 0:313541d8f8be 149 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 150 display.PrintString(" avg cell T: ");
kiran_mbed 0:313541d8f8be 151 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 152 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 153 }
kiran_mbed 0:313541d8f8be 154
kiran_mbed 0:313541d8f8be 155 //Column 2
kiran_mbed 0:313541d8f8be 156 if(Rxmsg.id == AMS_BATTERY_STATE)
kiran_mbed 0:313541d8f8be 157 {
kiran_mbed 0:313541d8f8be 158 if((rcv.C_FLOAT[0] & 0xC0) == 0xC0)
kiran_mbed 0:313541d8f8be 159 {
kiran_mbed 0:313541d8f8be 160 display.GotoXY(70,0);
kiran_mbed 0:313541d8f8be 161 display.PrintString(" AIRS: ");
kiran_mbed 0:313541d8f8be 162 display.PrintString("CLOS");
kiran_mbed 0:313541d8f8be 163 }
kiran_mbed 0:313541d8f8be 164 else
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("OPEN");
kiran_mbed 0:313541d8f8be 169 }
kiran_mbed 0:313541d8f8be 170
kiran_mbed 0:313541d8f8be 171 if((rcv.C_FLOAT[0] & 0x04) == 0x04)
kiran_mbed 0:313541d8f8be 172 {
kiran_mbed 0:313541d8f8be 173 display.GotoXY(70,16);
kiran_mbed 0:313541d8f8be 174 display.PrintString(" Prchrg: ");
kiran_mbed 0:313541d8f8be 175 display.PrintString("on");
kiran_mbed 0:313541d8f8be 176 }
kiran_mbed 0:313541d8f8be 177 else
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("off");
kiran_mbed 0:313541d8f8be 182 }
kiran_mbed 0:313541d8f8be 183 }
kiran_mbed 0:313541d8f8be 184 if(Rxmsg.id == AMS_BATTERY_STATE)
kiran_mbed 0:313541d8f8be 185 {
kiran_mbed 0:313541d8f8be 186 display.GotoXY(70,16);
kiran_mbed 0:313541d8f8be 187 display.PrintString(" Prchrg: ");
kiran_mbed 0:313541d8f8be 188 display.PrintString("off");
kiran_mbed 0:313541d8f8be 189 }
kiran_mbed 0:313541d8f8be 190 }
kiran_mbed 0:313541d8f8be 191 screen=0;
kiran_mbed 0:313541d8f8be 192 }
kiran_mbed 0:313541d8f8be 193 return;
kiran_mbed 0:313541d8f8be 194 }
kiran_mbed 0:313541d8f8be 195
kiran_mbed 0:313541d8f8be 196 void ON()
kiran_mbed 0:313541d8f8be 197 {
kiran_mbed 0:313541d8f8be 198 Txmsg_Drive.data[0]|=(1<<0);
kiran_mbed 0:313541d8f8be 199 wait(0.1);
kiran_mbed 0:313541d8f8be 200
kiran_mbed 0:313541d8f8be 201 display.ClearScreen();
kiran_mbed 0:313541d8f8be 202 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 203 display.GotoXY(26,16);
kiran_mbed 0:313541d8f8be 204 display.PrintString(" ON INITIATED");
kiran_mbed 0:313541d8f8be 205 printf("ON Initiated\n\r");
kiran_mbed 0:313541d8f8be 206 //screen=0;
kiran_mbed 0:313541d8f8be 207 return;
kiran_mbed 0:313541d8f8be 208 }
kiran_mbed 0:313541d8f8be 209
kiran_mbed 0:313541d8f8be 210 void ResetCommand()
kiran_mbed 0:313541d8f8be 211 {
kiran_mbed 0:313541d8f8be 212 Txmsg_Drive.data[0]&=~(1<<0);
kiran_mbed 0:313541d8f8be 213 wait(0.1);
kiran_mbed 0:313541d8f8be 214
kiran_mbed 0:313541d8f8be 215 display.ClearScreen();
kiran_mbed 0:313541d8f8be 216 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 217 display.GotoXY(16,16);
kiran_mbed 0:313541d8f8be 218 display.PrintString(" RESET INITIATED");
kiran_mbed 0:313541d8f8be 219 printf("Reset Initiated\n\r");
kiran_mbed 0:313541d8f8be 220 //screen=0;
kiran_mbed 0:313541d8f8be 221
kiran_mbed 0:313541d8f8be 222 return;
kiran_mbed 0:313541d8f8be 223 }
kiran_mbed 0:313541d8f8be 224
kiran_mbed 0:313541d8f8be 225 void Powerstream()
kiran_mbed 0:313541d8f8be 226 {
kiran_mbed 0:313541d8f8be 227 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 228 float power_ratio;
kiran_mbed 0:313541d8f8be 229 ftc rcv;
kiran_mbed 0:313541d8f8be 230 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 231 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 232 {
kiran_mbed 0:313541d8f8be 233 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 234 {
kiran_mbed 0:313541d8f8be 235 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 236 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 237 power_ratio=rcv.FLOAT/80000;
kiran_mbed 0:313541d8f8be 238 ledstream.write(power_ratio);
kiran_mbed 0:313541d8f8be 239 }
kiran_mbed 0:313541d8f8be 240 }
kiran_mbed 0:313541d8f8be 241 }
kiran_mbed 0:313541d8f8be 242
kiran_mbed 0:313541d8f8be 243 void Init()
kiran_mbed 0:313541d8f8be 244 {
kiran_mbed 0:313541d8f8be 245 pc.baud(230400);
kiran_mbed 0:313541d8f8be 246 CAN_Steering.frequency(500000);
kiran_mbed 0:313541d8f8be 247 for(int i = 0; i<4; i++)
kiran_mbed 0:313541d8f8be 248 drive[i] = (0x00);
kiran_mbed 0:313541d8f8be 249 ledstream.write(0);
kiran_mbed 0:313541d8f8be 250 call_ledstream.attach(&Powerstream,0.1);
kiran_mbed 0:313541d8f8be 251 }
kiran_mbed 0:313541d8f8be 252
kiran_mbed 0:313541d8f8be 253 int main()
kiran_mbed 0:313541d8f8be 254 {
kiran_mbed 0:313541d8f8be 255 Init();
kiran_mbed 0:313541d8f8be 256 //int flag=1;
kiran_mbed 0:313541d8f8be 257 wait(0.1);
kiran_mbed 0:313541d8f8be 258 display.GotoXY(10,16);
kiran_mbed 0:313541d8f8be 259 display.SelectFont(Arial_14,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 260 display.PrintString("Penn Electric Racing");
kiran_mbed 0:313541d8f8be 261 display.GotoXY(20,32);
kiran_mbed 0:313541d8f8be 262 display.PrintString("Live The Dream");
kiran_mbed 0:313541d8f8be 263 screen=0;
kiran_mbed 0:313541d8f8be 264 wait(1);
kiran_mbed 0:313541d8f8be 265
kiran_mbed 0:313541d8f8be 266 while(1)
kiran_mbed 0:313541d8f8be 267 {
kiran_mbed 0:313541d8f8be 268 if(biSWBL.read())
kiran_mbed 0:313541d8f8be 269 HomeScreen();
kiran_mbed 0:313541d8f8be 270
kiran_mbed 0:313541d8f8be 271 if(biSWTR.read())
kiran_mbed 0:313541d8f8be 272 {
kiran_mbed 0:313541d8f8be 273 ON();
kiran_mbed 0:313541d8f8be 274 wait(1);
kiran_mbed 0:313541d8f8be 275 HomeScreen();
kiran_mbed 0:313541d8f8be 276 }
kiran_mbed 0:313541d8f8be 277 if(biSWTL.read())
kiran_mbed 0:313541d8f8be 278 {
kiran_mbed 0:313541d8f8be 279 ResetCommand();
kiran_mbed 0:313541d8f8be 280 wait(1);
kiran_mbed 0:313541d8f8be 281 HomeScreen();
kiran_mbed 0:313541d8f8be 282 }
kiran_mbed 0:313541d8f8be 283 if(biSWBR.read())
kiran_mbed 0:313541d8f8be 284 {
kiran_mbed 0:313541d8f8be 285 if(screen)
kiran_mbed 0:313541d8f8be 286 AMSScreen2();
kiran_mbed 0:313541d8f8be 287 else
kiran_mbed 0:313541d8f8be 288 AMSScreen1();
kiran_mbed 0:313541d8f8be 289 }
kiran_mbed 0:313541d8f8be 290 CAN_Steering.write(Txmsg_Drive);
kiran_mbed 0:313541d8f8be 291 wait(0.3);
kiran_mbed 0:313541d8f8be 292 }
kiran_mbed 0:313541d8f8be 293 }