Kiran George Vetteth / Mbed 2 deprecated Steering_Display

Dependencies:   Digital_InOut KS0108 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Steering.cpp Source File

Steering.cpp

00001 #include "Steering.h"
00002 
00003 void HomeScreen()
00004 {
00005     CANMessage Rxmsg;
00006     ftc rcv;
00007     rcv.FLOAT=0.0;
00008     char dat[4];
00009     float power_ratio=0.0;
00010     printf("Homescreen\n\r");
00011     display.ClearScreen();
00012     display.SelectFont(Arial12,BLACK,ReadData);
00013     display.GotoXY(0,0);
00014     display.PrintString(" HOME SCREEN");
00015     while( !(biSWTL.read() || biSWTR.read() || biSWBR.read()) )
00016     {
00017         if(CAN_Steering.read(Rxmsg))
00018         {
00019             for(int i=0; i<4; i++)
00020                 rcv.C_FLOAT[i]=Rxmsg.data[i];
00021             if(Rxmsg.id == BATTERY_VOLTAGE_ID)
00022             {
00023                 display.GotoXY(0,16);
00024                 display.PrintString(" PV: ");     
00025                 sprintf(dat,"%2.2f",rcv.FLOAT);
00026                 display.PrintString(dat);
00027                 display.PrintString("V");
00028             }
00029             if(Rxmsg.id == BATTERY_POWER_ID)
00030             {
00031                 display.GotoXY(64,16);
00032                 display.PrintString(" PP: ");
00033                 power_ratio=rcv.FLOAT/10000;        
00034                 sprintf(dat,"%2.2f",power_ratio);
00035                 display.PrintString(dat);
00036                 display.PrintString("kW");
00037             }
00038             if(Rxmsg.id == PCM_STATE_ID)
00039             {
00040                 display.GotoXY(0,32);
00041                 display.PrintString(" STATE: ");      
00042                 display.PrintNumber(rcv.FLOAT);
00043             }
00044         }
00045     }    
00046     return;    
00047 }
00048 
00049 void AMSScreen1()
00050 {
00051     CANMessage Rxmsg;
00052     ftc rcv;
00053     char dat[4];
00054     rcv.FLOAT=0.0;
00055     printf("AMSScreen1");
00056     display.ClearScreen();
00057     display.SelectFont(Arial12,BLACK,ReadData);
00058     while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
00059     {
00060         printf("iN LOOP1");
00061         if(CAN_Steering.read(Rxmsg))
00062         {
00063             for(int i=0; i<4; i++)
00064                 rcv.C_FLOAT[i]=Rxmsg.data[i];
00065             if(Rxmsg.id == BATTERY_VOLTAGE_ID)
00066             {
00067                 display.GotoXY(0,0);
00068                 display.PrintString(" pv: ");
00069                 sprintf(dat,"%2.2f",rcv.FLOAT);
00070                 display.PrintString(dat);
00071             }
00072             if(Rxmsg.id == BATTERY_POWER_ID)
00073             {
00074                 display.GotoXY(0,16);
00075                 display.PrintString(" pp: ");
00076                 sprintf(dat,"%2.2f",rcv.FLOAT);
00077                 display.PrintString(dat);
00078             }
00079             if(Rxmsg.id == BATTERY_CURRENT_ID)
00080             {
00081                 display.GotoXY(0,32);
00082                 display.PrintString(" pi: ");
00083                 sprintf(dat,"%2.2f",rcv.FLOAT);
00084                 display.PrintString(dat);
00085             }
00086             
00087             //Column 2
00088             if(Rxmsg.id == BATTERY_MIN_CELLVOLTAGE_ID)
00089             {
00090                 display.GotoXY(49,0);
00091                 display.PrintString(" min cell V: ");
00092                 sprintf(dat,"%2.2f",rcv.FLOAT);
00093                 display.PrintString(dat);
00094             }
00095             if(Rxmsg.id == BATTERY_MAX_CELLVOLTAGE_ID)
00096             {
00097                 display.GotoXY(49,16);
00098                 display.PrintString(" max cell V: ");
00099                 sprintf(dat,"%2.2f",rcv.FLOAT);
00100                 display.PrintString(dat);
00101             }
00102             if(Rxmsg.id == BATTERY_AVG_CELLVOLTAGE_ID)
00103             {
00104                 display.GotoXY(49,32);
00105                 display.PrintString(" avg cell V: ");
00106                 sprintf(dat,"%2.2f",rcv.FLOAT);
00107                 display.PrintString(dat);
00108             }
00109         }
00110         screen=1;                 
00111     }   
00112     return;   
00113 }    
00114 
00115 void AMSScreen2()
00116 {
00117     CANMessage Rxmsg;
00118     ftc rcv;
00119     char dat[4];
00120     //ftc send;
00121     rcv.FLOAT=0.0;
00122     //send.FLOAT=65.6432;
00123     printf("AMSScreen2\n\r");
00124     display.ClearScreen();
00125     display.SelectFont(Arial12,BLACK,ReadData);
00126     while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
00127     {
00128         printf("iN LOOP2");
00129         if(CAN_Steering.read(Rxmsg))
00130         {
00131             for(int i=0; i<4; i++)
00132                 rcv.C_FLOAT[i]=Rxmsg.data[i];
00133             if(Rxmsg.id == BATTERY_MIN_CELLTEMPERATURE_ID)
00134             {
00135                 display.GotoXY(0,0);
00136                 display.PrintString(" mn cll T: ");
00137                 sprintf(dat,"%2.2f",rcv.FLOAT);
00138                 display.PrintString(dat);
00139             }
00140             if(Rxmsg.id == BATTERY_MAX_CELLTEMPERATURE_ID)
00141             {
00142                 display.GotoXY(0,16);
00143                 display.PrintString(" mx cll T: ");
00144                 sprintf(dat,"%2.2f",rcv.FLOAT);
00145                 display.PrintString(dat);
00146             }
00147             if(Rxmsg.id == BATTERY_AVG_CELLTEMPERATURE_ID)
00148             {
00149                 display.GotoXY(0,32);
00150                 display.PrintString(" avg cell T: ");
00151                 sprintf(dat,"%2.2f",rcv.FLOAT);
00152                 display.PrintString(dat);
00153             }
00154             
00155             //Column 2
00156             if(Rxmsg.id == AMS_BATTERY_STATE)
00157             {
00158                 if((rcv.C_FLOAT[0] & 0xC0) == 0xC0)
00159                 {
00160                     display.GotoXY(70,0);
00161                     display.PrintString(" AIRS: ");
00162                     display.PrintString("CLOS");
00163                 }
00164                 else
00165                 {
00166                     display.GotoXY(70,0);
00167                     display.PrintString(" AIRS: ");
00168                     display.PrintString("OPEN");
00169                 }
00170                 
00171                 if((rcv.C_FLOAT[0] & 0x04) == 0x04)
00172                 {
00173                     display.GotoXY(70,16);
00174                     display.PrintString(" Prchrg: ");
00175                     display.PrintString("on");
00176                 }
00177                 else
00178                 {
00179                     display.GotoXY(70,16);
00180                     display.PrintString(" Prchrg: ");
00181                     display.PrintString("off");
00182                 }                
00183             }
00184             if(Rxmsg.id == AMS_BATTERY_STATE)
00185             {
00186                 display.GotoXY(70,16);
00187                 display.PrintString(" Prchrg: ");
00188                 display.PrintString("off");
00189             }
00190         }
00191         screen=0;         
00192     }
00193     return;        
00194 }
00195 
00196 void ON()
00197 {
00198     Txmsg_Drive.data[0]|=(1<<0);   
00199     wait(0.1);
00200     
00201     display.ClearScreen();
00202     display.SelectFont(Arial12,BLACK,ReadData);
00203     display.GotoXY(26,16);
00204     display.PrintString(" ON    INITIATED");
00205     printf("ON Initiated\n\r");
00206     //screen=0;
00207     return;
00208 }
00209 
00210 void ResetCommand()
00211 {
00212     Txmsg_Drive.data[0]&=~(1<<0);
00213     wait(0.1);
00214     
00215     display.ClearScreen();
00216     display.SelectFont(Arial12,BLACK,ReadData);
00217     display.GotoXY(16,16);
00218     display.PrintString(" RESET INITIATED");
00219     printf("Reset Initiated\n\r");
00220     //screen=0;
00221     
00222     return;
00223 }    
00224 
00225 void Powerstream()
00226 {
00227     CANMessage Rxmsg;
00228     float power_ratio;
00229     ftc rcv;
00230     rcv.FLOAT=0.0;
00231     if(CAN_Steering.read(Rxmsg))
00232     {   
00233         if(Rxmsg.id == BATTERY_POWER_ID)
00234         {
00235             for(int i=0; i<4; i++)
00236                 rcv.C_FLOAT[i]=Rxmsg.data[i];
00237             power_ratio=rcv.FLOAT/80000;
00238             ledstream.write(power_ratio);
00239         }
00240     }   
00241 }
00242 
00243 void Init()
00244 {
00245     pc.baud(230400);
00246     CAN_Steering.frequency(500000);
00247     for(int i = 0; i<4; i++)
00248         drive[i] = (0x00);
00249     ledstream.write(0);
00250     call_ledstream.attach(&Powerstream,0.1);
00251 }
00252 
00253 int main()
00254 {
00255     Init();
00256     //int flag=1;
00257     wait(0.1);
00258     display.GotoXY(10,16);
00259     display.SelectFont(Arial_14,BLACK,ReadData);
00260     display.PrintString("Penn Electric Racing");
00261     display.GotoXY(20,32); 
00262     display.PrintString("Live The Dream");
00263     screen=0;
00264     wait(1);
00265     
00266     while(1)
00267     {
00268         if(biSWBL.read())
00269             HomeScreen();
00270         
00271         if(biSWTR.read())
00272         {
00273             ON();
00274             wait(1);
00275             HomeScreen();
00276         }
00277         if(biSWTL.read())
00278         {
00279             ResetCommand();
00280             wait(1);
00281             HomeScreen();
00282         }
00283         if(biSWBR.read())
00284         { 
00285             if(screen)
00286                 AMSScreen2();
00287             else
00288                 AMSScreen1();   
00289         }
00290         CAN_Steering.write(Txmsg_Drive);        
00291         wait(0.3);    
00292     }        
00293 }