Konacan kod

Dependencies:   BSP_DISCO_F469NIa LCD_DISCO_F469NIa SD_DISCO_F469NI mbed

Committer:
formulas
Date:
Wed May 16 14:55:13 2018 +0000
Revision:
1:ed6a402be3e3
Parent:
0:38c3afd99aeb
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
formulas 0:38c3afd99aeb 1 /*#include "mbed.h"
formulas 0:38c3afd99aeb 2 #include "functions.h"
formulas 0:38c3afd99aeb 3
formulas 0:38c3afd99aeb 4 LCD_DISCO_F469NI lcd;
formulas 0:38c3afd99aeb 5 SD_DISCO_F469NI sd;
formulas 0:38c3afd99aeb 6 Serial pc(USBTX, USBRX);
formulas 0:38c3afd99aeb 7 CAN can(PB_5, PB_13);
formulas 0:38c3afd99aeb 8 DigitalIn changescreen_command(D0);
formulas 0:38c3afd99aeb 9
formulas 0:38c3afd99aeb 10 int can_data;
formulas 0:38c3afd99aeb 11 int RPM;
formulas 0:38c3afd99aeb 12 extern GEAR *Gears;
formulas 0:38c3afd99aeb 13 extern IMAGE LogoBig,LogoSmall,Branko;
formulas 0:38c3afd99aeb 14
formulas 0:38c3afd99aeb 15 void MainScreen();
formulas 0:38c3afd99aeb 16 void FirstAuxScreen();
formulas 0:38c3afd99aeb 17 void SecondAuxScreen();
formulas 0:38c3afd99aeb 18
formulas 0:38c3afd99aeb 19 int main(){
formulas 0:38c3afd99aeb 20 DrawRGBImage(LogoBig,0,0);
formulas 0:38c3afd99aeb 21 wait(0.5);
formulas 0:38c3afd99aeb 22 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 23 lcd.FillRect(0,0,800,480);
formulas 0:38c3afd99aeb 24 MainScreen();
formulas 0:38c3afd99aeb 25 };
formulas 0:38c3afd99aeb 26
formulas 0:38c3afd99aeb 27
formulas 0:38c3afd99aeb 28 void MainScreen(){
formulas 0:38c3afd99aeb 29 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 30 DrawSpeedMeter();
formulas 0:38c3afd99aeb 31 DrawRGBImage(LogoSmall,LogoSmallXPos,LogoSmallYPos);
formulas 0:38c3afd99aeb 32 lcd.SetFont(&Font24);
formulas 0:38c3afd99aeb 33 lcd.DisplayStringAt(30,170,(uint8_t*)"Oil Temp",LEFT_MODE);
formulas 0:38c3afd99aeb 34 lcd.DisplayStringAt(30,320,(uint8_t*)"Water Temp",LEFT_MODE);
formulas 0:38c3afd99aeb 35 lcd.DisplayStringAt(584,170,(uint8_t*)"TPS",LEFT_MODE);
formulas 0:38c3afd99aeb 36 lcd.SetTextColor(LCD_COLOR_DARKRED);
formulas 0:38c3afd99aeb 37 lcd.FillRect(560,340,230,68);
formulas 0:38c3afd99aeb 38 lcd.SetBackColor(LCD_COLOR_DARKRED);
formulas 0:38c3afd99aeb 39 PrintString("BRAKE",50,575,350,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 40 lcd.SetBackColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 41
formulas 0:38c3afd99aeb 42 int Vin,V0=0,OilTemp,OilTemp0=0,WaterTemp,WaterTemp0=0,TPS,TPS0=0,Brake,Brake0=0,Gear,Gear0;
formulas 0:38c3afd99aeb 43
formulas 0:38c3afd99aeb 44 CANMessage msg;
formulas 0:38c3afd99aeb 45
formulas 0:38c3afd99aeb 46 //inicijalne vrednosti prikazane na ekranu
formulas 0:38c3afd99aeb 47 PrintChar(Gears[0],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 48 ChangeNumber(0,111,100,OilTempXPos,OilTempYPos);
formulas 0:38c3afd99aeb 49 ChangeNumber(0,111,100,WaterTempXPos,WaterTempYPos);
formulas 0:38c3afd99aeb 50 ChangeNumber(0,111,100,TPSXPos,TPSYPos);
formulas 0:38c3afd99aeb 51 BrakeSignal(0,1);
formulas 0:38c3afd99aeb 52 wait(1);
formulas 0:38c3afd99aeb 53 while(changescreen_command.read()==0){
formulas 0:38c3afd99aeb 54 if(can.read(msg)){
formulas 0:38c3afd99aeb 55 can_data=msg.data[0];
formulas 0:38c3afd99aeb 56 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 57 if (msg.id==SPEED_ID){
formulas 0:38c3afd99aeb 58 Vin=(int)can_data;
formulas 0:38c3afd99aeb 59 UpdateSpeedMeter(V0,Vin-V0);
formulas 0:38c3afd99aeb 60 V0=Vin;
formulas 0:38c3afd99aeb 61 }else if (msg.id==GEAR_ID){
formulas 0:38c3afd99aeb 62 Gear=can_data;
formulas 0:38c3afd99aeb 63 if(Gear!=Gear0){
formulas 0:38c3afd99aeb 64 Gear=can_data;
formulas 0:38c3afd99aeb 65 printf("%d\n",Gear);
formulas 0:38c3afd99aeb 66 PrintChar(Gears[Gear],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 67 Gear0=Gear;
formulas 0:38c3afd99aeb 68 };
formulas 0:38c3afd99aeb 69 }else if (msg.id==OIL_TEMP_ID){
formulas 0:38c3afd99aeb 70 OilTemp=can_data;
formulas 0:38c3afd99aeb 71 ChangeNumber(OilTemp,OilTemp0,100,OilTempXPos,OilTempYPos);
formulas 0:38c3afd99aeb 72 OilTemp0=OilTemp;
formulas 0:38c3afd99aeb 73 }else if (msg.id==WATER_TEMP_ID){
formulas 0:38c3afd99aeb 74 WaterTemp=can_data;
formulas 0:38c3afd99aeb 75 ChangeNumber(WaterTemp,WaterTemp0,100,WaterTempXPos,WaterTempYPos);
formulas 0:38c3afd99aeb 76 WaterTemp0=WaterTemp;
formulas 0:38c3afd99aeb 77 }else if (msg.id==TPS_ID){
formulas 0:38c3afd99aeb 78 TPS=can_data;
formulas 0:38c3afd99aeb 79 ChangeNumber(TPS,TPS0,100,TPSXPos,TPSYPos);
formulas 0:38c3afd99aeb 80 TPS0=TPS;
formulas 0:38c3afd99aeb 81 }else if (msg.id==BRAKE_ID){
formulas 0:38c3afd99aeb 82 Brake=can_data;
formulas 0:38c3afd99aeb 83 BrakeSignal(Brake,Brake0);
formulas 0:38c3afd99aeb 84 Brake0=Brake;
formulas 0:38c3afd99aeb 85 };
formulas 0:38c3afd99aeb 86 };
formulas 0:38c3afd99aeb 87 };
formulas 0:38c3afd99aeb 88 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 89 lcd.FillRect(0,0,800,480);
formulas 0:38c3afd99aeb 90 FirstAuxScreen();
formulas 0:38c3afd99aeb 91 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 92 };
formulas 0:38c3afd99aeb 93
formulas 0:38c3afd99aeb 94 void FirstAuxScreen(){
formulas 0:38c3afd99aeb 95 PrintString("Oil P",50,20,25,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 96 PrintString("MAP",50,20,100,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 97 PrintString("Air Temp",50,20,175,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 98 PrintString("Lambda",50,20,250,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 99 PrintString("Volts",50,20,325,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 100 PrintString("Crank",50,20,400,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 101 PrintString("kPa",50,470,25,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 102 PrintString("kPa",50,470,100,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 103 PrintString("C",50,470,175,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 104 PrintString("Ratio",50,470,250,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 105 PrintString("V",50,470,325,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 106 DrawRGBImage(LogoSmall,LogoSmallXPos,LogoSmallYPos);
formulas 0:38c3afd99aeb 107
formulas 0:38c3afd99aeb 108 uint8_t OilP,OilP0=0,MAP,MAP0=0,AirTemp,AirTemp0=0,Lambda,Lambda0=0,Volts,Volts0=0,Crank,Crank0=1;
formulas 0:38c3afd99aeb 109
formulas 0:38c3afd99aeb 110 CANMessage msg;
formulas 0:38c3afd99aeb 111
formulas 0:38c3afd99aeb 112 ChangeNumber(0,111,50,OilPXPos,OilPYPos);
formulas 0:38c3afd99aeb 113 ChangeNumber(0,111,50,MAPXPos,MAPYPos);
formulas 0:38c3afd99aeb 114 ChangeNumber(0,111,50,AirTempXPos,AirTempYPos);
formulas 0:38c3afd99aeb 115 ChangeNumber(0,111,50,LambdaXPos,LambdaYPos);
formulas 0:38c3afd99aeb 116 ChangeNumber(0,111,50,VoltsXPos,VoltsYPos);
formulas 0:38c3afd99aeb 117
formulas 0:38c3afd99aeb 118 while(changescreen_command.read()==0){
formulas 0:38c3afd99aeb 119 if(can.read(msg)){
formulas 0:38c3afd99aeb 120 can_data=msg.data[0];
formulas 0:38c3afd99aeb 121 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 122 if (msg.id==OIL_P_ID){
formulas 0:38c3afd99aeb 123 OilP=can_data;
formulas 0:38c3afd99aeb 124 ChangeNumber(OilP,OilP0,100,OilPXPos,OilPYPos);
formulas 0:38c3afd99aeb 125 OilP0=OilP;
formulas 0:38c3afd99aeb 126 }else if (msg.id==MAP_ID){
formulas 0:38c3afd99aeb 127 MAP=can_data;
formulas 0:38c3afd99aeb 128 ChangeNumber(MAP,MAP0,100,MAPXPos,MAPYPos);
formulas 0:38c3afd99aeb 129 MAP0=MAP;
formulas 0:38c3afd99aeb 130 }else if (msg.id==AIR_TEMP_ID){
formulas 0:38c3afd99aeb 131 AirTemp=can_data;
formulas 0:38c3afd99aeb 132 ChangeNumber(AirTemp,AirTemp0,100,AirTempXPos,AirTempYPos);
formulas 0:38c3afd99aeb 133 AirTemp0=AirTemp;
formulas 0:38c3afd99aeb 134 }else if (msg.id==LAMBDA_ID){
formulas 0:38c3afd99aeb 135 Lambda=can_data;
formulas 0:38c3afd99aeb 136 ChangeNumber(Lambda,Lambda0,100,LambdaXPos,LambdaYPos);
formulas 0:38c3afd99aeb 137 Lambda0=Lambda;
formulas 0:38c3afd99aeb 138 }else if (msg.id==VOLTS_ID){
formulas 0:38c3afd99aeb 139 Volts=can_data;
formulas 0:38c3afd99aeb 140 ChangeNumber(Volts,Volts0,100,VoltsXPos,VoltsYPos);
formulas 0:38c3afd99aeb 141 Volts0=Volts;
formulas 0:38c3afd99aeb 142 }else if (msg.id==CRANK_ID){
formulas 0:38c3afd99aeb 143 Crank=can_data;
formulas 0:38c3afd99aeb 144 if(Crank!=Crank0){
formulas 0:38c3afd99aeb 145 if(Crank==1){
formulas 0:38c3afd99aeb 146 PrintString("ERROR",50,CrankXPos,CrankYPos,LCD_COLOR_RED);
formulas 0:38c3afd99aeb 147 }else if(Crank==0){
formulas 0:38c3afd99aeb 148 PrintString("OK",50,CrankXPos,CrankYPos,LCD_COLOR_RED);
formulas 0:38c3afd99aeb 149 };
formulas 0:38c3afd99aeb 150 };
formulas 0:38c3afd99aeb 151 Crank0=Crank;
formulas 0:38c3afd99aeb 152 };
formulas 0:38c3afd99aeb 153 };
formulas 0:38c3afd99aeb 154 };
formulas 0:38c3afd99aeb 155 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 156 lcd.FillRect(0,0,800,480);
formulas 0:38c3afd99aeb 157 SecondAuxScreen();
formulas 0:38c3afd99aeb 158
formulas 0:38c3afd99aeb 159 };
formulas 0:38c3afd99aeb 160
formulas 0:38c3afd99aeb 161 void SecondAuxScreen(){
formulas 0:38c3afd99aeb 162 PrintString("LVDT Sensors",50,200,20,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 163 DrawRGBImage(LogoSmall,LogoSmallXPos,LogoSmallYPos);
formulas 0:38c3afd99aeb 164 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 165 lcd.SetFont(&Font24);
formulas 0:38c3afd99aeb 166 lcd.DisplayStringAt(FLLVDTBarXPos+25,FLLVDTBarYPos,(uint8_t*)"FL",LEFT_MODE);
formulas 0:38c3afd99aeb 167 lcd.DisplayStringAt(FRLVDTBarXPos+25,FRLVDTBarYPos,(uint8_t*)"FR",LEFT_MODE);
formulas 0:38c3afd99aeb 168 lcd.DisplayStringAt(BLLVDTBarXPos+25,BLLVDTBarYPos,(uint8_t*)"BL",LEFT_MODE);
formulas 0:38c3afd99aeb 169 lcd.DisplayStringAt(BRLVDTBarXPos+25,BRLVDTBarYPos,(uint8_t*)"BR",LEFT_MODE);
formulas 0:38c3afd99aeb 170
formulas 0:38c3afd99aeb 171 uint8_t FLLVDT,FLLVDT0=0,FRLVDT,FRLVDT0=0,BLLVDT,BLLVDT0=0,BRLVDT,BRLVDT0=0;
formulas 0:38c3afd99aeb 172
formulas 0:38c3afd99aeb 173 CANMessage msg;
formulas 0:38c3afd99aeb 174
formulas 0:38c3afd99aeb 175 ChangeNumber(0,111,100,FLLVDTXPos,FLLVDTYPos);
formulas 0:38c3afd99aeb 176 ChangeNumber(0,111,100,FRLVDTXPos,FRLVDTYPos);
formulas 0:38c3afd99aeb 177 ChangeNumber(0,111,100,BLLVDTXPos,BLLVDTYPos);
formulas 0:38c3afd99aeb 178 ChangeNumber(0,111,100,BRLVDTXPos,BRLVDTYPos);
formulas 0:38c3afd99aeb 179
formulas 0:38c3afd99aeb 180 while(changescreen_command.read()==0){
formulas 0:38c3afd99aeb 181 if(can.read(msg)){
formulas 0:38c3afd99aeb 182 can_data=msg.data[0];
formulas 0:38c3afd99aeb 183 if(msg.id==FL_LVDT_ID){
formulas 0:38c3afd99aeb 184 FLLVDT=can_data;
formulas 0:38c3afd99aeb 185 ChangeNumber(FLLVDT,FLLVDT0,100,FLLVDTXPos,FLLVDTYPos);
formulas 0:38c3afd99aeb 186 UpdateLVDTScale(FLLVDT,FLLVDT0,FLLVDTBarXPos,FLLVDTBarYPos);
formulas 0:38c3afd99aeb 187 FLLVDT0=FLLVDT;
formulas 0:38c3afd99aeb 188 }else if(msg.id==FR_LVDT_ID){
formulas 0:38c3afd99aeb 189 FRLVDT=can_data;
formulas 0:38c3afd99aeb 190 ChangeNumber(FRLVDT,FRLVDT0,100,FRLVDTXPos,FRLVDTYPos);
formulas 0:38c3afd99aeb 191 UpdateLVDTScale(FRLVDT,FRLVDT0,FRLVDTBarXPos,FRLVDTBarYPos);
formulas 0:38c3afd99aeb 192 FRLVDT0=FRLVDT;
formulas 0:38c3afd99aeb 193 }else if(msg.id==BL_LVDT_ID){
formulas 0:38c3afd99aeb 194 BLLVDT=can_data;
formulas 0:38c3afd99aeb 195 ChangeNumber(BLLVDT,BLLVDT0,100,BLLVDTXPos,BLLVDTYPos);
formulas 0:38c3afd99aeb 196 UpdateLVDTScale(BLLVDT,BLLVDT0,BLLVDTBarXPos,BLLVDTBarYPos);
formulas 0:38c3afd99aeb 197 BLLVDT0=BLLVDT;
formulas 0:38c3afd99aeb 198 }else if(msg.id==BR_LVDT_ID){
formulas 0:38c3afd99aeb 199 BRLVDT=can_data;
formulas 0:38c3afd99aeb 200 ChangeNumber(BRLVDT,BRLVDT0,100,BRLVDTXPos,BRLVDTYPos);
formulas 0:38c3afd99aeb 201 UpdateLVDTScale(BRLVDT,BRLVDT0,BRLVDTBarXPos,BRLVDTBarYPos);
formulas 0:38c3afd99aeb 202 BRLVDT0=BRLVDT;
formulas 0:38c3afd99aeb 203 };
formulas 0:38c3afd99aeb 204 };
formulas 0:38c3afd99aeb 205 };
formulas 0:38c3afd99aeb 206 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 207 lcd.FillRect(0,0,800,480);
formulas 0:38c3afd99aeb 208 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 209 MainScreen();
formulas 0:38c3afd99aeb 210 };*/