15.02.2019. revision

Dependencies:   mbed LCD_DISCO_F469NIa SD_DISCO_F469NI BSP_DISCO_F469NIa EEPROM_DISCO_F469NI

Committer:
Stefan_Sofijanic
Date:
Fri Feb 15 21:01:16 2019 +0000
Revision:
6:15433396d657
Parent:
4:0e8413277df8
15.02.2019. revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
formulas 0:38c3afd99aeb 1 #include "draw_print_library.h"
formulas 0:38c3afd99aeb 2 #include "gears.h"
formulas 0:38c3afd99aeb 3 #include "font100.h"
formulas 0:38c3afd99aeb 4 #include "font50.h"
formulas 0:38c3afd99aeb 5
formulas 0:38c3afd99aeb 6 extern LCD_DISCO_F469NI lcd;
formulas 0:38c3afd99aeb 7 extern SD_DISCO_F469NI sd;
formulas 0:38c3afd99aeb 8 extern Serial pc;
formulas 0:38c3afd99aeb 9
formulas 0:38c3afd99aeb 10 extern uint8_t lvdtref;
formulas 0:38c3afd99aeb 11 extern int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref;
formulas 0:38c3afd99aeb 12
formulas 0:38c3afd99aeb 13 //Gears
formulas 0:38c3afd99aeb 14 GEAR Idle{'0',256,384,idleBitmap};
formulas 0:38c3afd99aeb 15 GEAR Gear1{'1',256,384,gear1Bitmap};
formulas 0:38c3afd99aeb 16 GEAR Gear2{'2',256,384,gear2Bitmap};
formulas 0:38c3afd99aeb 17 GEAR Gear3{'3',256,384,gear3Bitmap};
formulas 0:38c3afd99aeb 18 GEAR Gear4{'4',256,384,gear4Bitmap};
formulas 0:38c3afd99aeb 19 GEAR Gear5{'5',256,384,gear5Bitmap};
formulas 0:38c3afd99aeb 20 GEAR Gear6{'6',256,384,gear6Bitmap};
formulas 0:38c3afd99aeb 21 GEAR *Gears[7]={&Idle,&Gear1,&Gear2,&Gear3,&Gear4,&Gear5,&Gear6}; //Gears array
formulas 0:38c3afd99aeb 22 IMAGE LogoBig{800,480,LOGOBIG_START_ADDR}; //Big Logo
formulas 0:38c3afd99aeb 23 IMAGE LogoSmall{160,64,LOGOSMALL_START_ADDR}; //Small Logo
formulas 0:38c3afd99aeb 24 IMAGE Branko{250,480,1576960}; //Branko
formulas 0:38c3afd99aeb 25 IMAGE NewYearCongat{800,480,NEW_YEAR_CONGAT_START_ADDR};
formulas 0:38c3afd99aeb 26 //IMAGE Miljana[250,480,---};
formulas 0:38c3afd99aeb 27
formulas 0:38c3afd99aeb 28 void DrawSpeedMeter(){
formulas 0:38c3afd99aeb 29 uint16_t x1,y1,x2,y2,x3,y3,x4,y4;
formulas 0:38c3afd99aeb 30 double THETA1=PHI,THETA2;
formulas 0:38c3afd99aeb 31
formulas 0:38c3afd99aeb 32 //Set starting point for drawing
formulas 0:38c3afd99aeb 33 x1=(int)(400-530*cos(THETA1));
formulas 0:38c3afd99aeb 34 y1=(int)(550-530*sin(THETA1));
formulas 0:38c3afd99aeb 35 x2=(int)(400-500*cos(THETA1));
formulas 0:38c3afd99aeb 36 y2=(int)(550-500*sin(THETA1));
formulas 0:38c3afd99aeb 37
formulas 0:38c3afd99aeb 38 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 39 for (int V=0;V<=150;V++){ //Draw from 0 to 150
formulas 0:38c3afd99aeb 40 //Set angle for next speed scale value
formulas 0:38c3afd99aeb 41 THETA2=THETA1+ALPHA/Vmax;
formulas 0:38c3afd99aeb 42 x3=(int)(400-530*cos(THETA2));
formulas 0:38c3afd99aeb 43 y3=(int)(550-530*sin(THETA2));
formulas 0:38c3afd99aeb 44 x4=(int)(400-500*cos(THETA2));
formulas 0:38c3afd99aeb 45 y4=(int)(550-500*sin(THETA2));
formulas 0:38c3afd99aeb 46 if(V<150){ //Draw arch section
formulas 0:38c3afd99aeb 47 lcd.DrawLine(x1,y1,x3,y3);
formulas 0:38c3afd99aeb 48 lcd.DrawLine(x2,y2,x4,y4);
formulas 0:38c3afd99aeb 49 };
formulas 0:38c3afd99aeb 50 lcd.SetFont(&Font20);
formulas 0:38c3afd99aeb 51 if(V%10==0){ //Print round values (0,10,20,...)
formulas 0:38c3afd99aeb 52 lcd.DrawLine(x1,y1,x2,y2); //Draw round scale value
formulas 0:38c3afd99aeb 53 char Vchar[3];
formulas 0:38c3afd99aeb 54 sprintf(Vchar,"%d",(int)V);
formulas 0:38c3afd99aeb 55 uint16_t xnum=x2,ynum=y2;
formulas 0:38c3afd99aeb 56 if (V==0 | V==10 | V==20 | V==30){ //Position of printed value
formulas 0:38c3afd99aeb 57 xnum=x2,ynum=y2+5;
formulas 0:38c3afd99aeb 58 }else if (V==40 | V==50 | V==60){
formulas 0:38c3afd99aeb 59 xnum=x2-3,ynum=y2+5;
formulas 0:38c3afd99aeb 60 }else if (V==70 | V==80){
formulas 0:38c3afd99aeb 61 xnum=x2-14,ynum=y2+5;
formulas 0:38c3afd99aeb 62 }else if (V==90){
formulas 0:38c3afd99aeb 63 xnum=x2-20,ynum=y2+5;
formulas 0:38c3afd99aeb 64 }else if (V==100 | V==110 | V==120) {
formulas 0:38c3afd99aeb 65 xnum=x2-35,ynum=y2+4;
formulas 0:38c3afd99aeb 66 }else if (V==130 | V==140 | V==150){
formulas 0:38c3afd99aeb 67 xnum=x2-35,ynum=y2+5;
formulas 0:38c3afd99aeb 68 };
formulas 0:38c3afd99aeb 69 lcd.DisplayStringAt(xnum,ynum,(uint8_t*)Vchar,LEFT_MODE);
formulas 0:38c3afd99aeb 70 };
formulas 0:38c3afd99aeb 71 x1=x3,y1=y3,x2=x4,y2=y4; //Increment position
formulas 0:38c3afd99aeb 72 THETA1=THETA2;
formulas 0:38c3afd99aeb 73 };
formulas 0:38c3afd99aeb 74 };
formulas 0:38c3afd99aeb 75
formulas 0:38c3afd99aeb 76 void PrintChar(CHAR Char,uint16_t StartXPos,uint16_t StartYPos,uint32_t TextColor){
formulas 0:38c3afd99aeb 77 uint16_t width=Char.width;
formulas 0:38c3afd99aeb 78 uint16_t height=Char.height;
formulas 0:38c3afd99aeb 79 uint16_t horpos,vertpos;
formulas 0:38c3afd99aeb 80 uint16_t bitloc;
formulas 0:38c3afd99aeb 81 uint32_t DrawColor;
formulas 0:38c3afd99aeb 82 char pos[9];
formulas 0:38c3afd99aeb 83 //uint8_t dbg[50];
formulas 0:38c3afd99aeb 84 for(horpos=0;horpos<width;horpos++){ //Bitmaps are row after row
formulas 0:38c3afd99aeb 85 for(vertpos=0;vertpos<height/8;vertpos++){
formulas 0:38c3afd99aeb 86 sprintf(pos,BYTE_TO_BINARY_PATTERN,BYTE_TO_BINARY(Char.bitmap[horpos*height/8+vertpos])); //Convert uint8_t from hex to binary. 1 to fill, 0 to skip
formulas 0:38c3afd99aeb 87 //pc.printf("%d. %s\n",horpos*height/8+vertpos,pos);
formulas 0:38c3afd99aeb 88 for(bitloc=0;bitloc<8;bitloc++) {
formulas 0:38c3afd99aeb 89 if (pos[bitloc]=='1') {
formulas 0:38c3afd99aeb 90 DrawColor=TextColor;
formulas 0:38c3afd99aeb 91 }
formulas 0:38c3afd99aeb 92 else{
formulas 0:38c3afd99aeb 93 DrawColor=lcd.GetBackColor();
formulas 0:38c3afd99aeb 94 };
formulas 0:38c3afd99aeb 95 lcd.DrawPixel(StartXPos+horpos,StartYPos+vertpos*8+bitloc,DrawColor);
formulas 0:38c3afd99aeb 96 //pc.printf("%d,%d\n",StartXPos+horpos,StartYPos+vertpos*8+bitloc);
formulas 0:38c3afd99aeb 97 }
formulas 0:38c3afd99aeb 98 }
formulas 0:38c3afd99aeb 99 }
formulas 0:38c3afd99aeb 100 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 101 };
formulas 0:38c3afd99aeb 102
formulas 0:38c3afd99aeb 103 void PrintString(char str[],int font,uint16_t StartXPos,uint16_t StartYPos,uint32_t TextColor){
formulas 0:38c3afd99aeb 104 //pc.printf("Function activated.\n");
formulas 0:38c3afd99aeb 105 char *a=str;
formulas 0:38c3afd99aeb 106 int p=0;
formulas 0:38c3afd99aeb 107 while(a[p]){
formulas 0:38c3afd99aeb 108 //pc.printf("Searching char: %c\n",a[p]);
formulas 0:38c3afd99aeb 109 for(int k=0;k<68;k++){
formulas 0:38c3afd99aeb 110 //pc.printf("Character %c\n",(*font50[k]).name);
formulas 0:38c3afd99aeb 111 if((*font50[k]).name==a[p]){
formulas 0:38c3afd99aeb 112 // pc.printf("Found!\n");
formulas 0:38c3afd99aeb 113 PrintChar(*font50[k],StartXPos,StartYPos,TextColor);
formulas 0:38c3afd99aeb 114 StartXPos+=(*font50[k]).width;
formulas 0:38c3afd99aeb 115 k=100;
formulas 0:38c3afd99aeb 116 };
formulas 0:38c3afd99aeb 117 };
formulas 0:38c3afd99aeb 118 //pc.printf("End.\n");
formulas 0:38c3afd99aeb 119 p++;
formulas 0:38c3afd99aeb 120 };
formulas 0:38c3afd99aeb 121 };
formulas 0:38c3afd99aeb 122
formulas 0:38c3afd99aeb 123
formulas 0:38c3afd99aeb 124
formulas 0:38c3afd99aeb 125
formulas 0:38c3afd99aeb 126 void ChangeNumber(int num,int num0,int Font,uint16_t StartXPos,uint16_t StartYPos, int digits, int dec_point, int sign){
formulas 0:38c3afd99aeb 127 //Function only changes the decimals that change. If number changes from 146 to 147, it only changes 6 to 7.
formulas 0:38c3afd99aeb 128 int digit[digits],digit0[digits];
formulas 0:38c3afd99aeb 129 int sum=0,sum0=0,k,aux=0;
formulas 0:38c3afd99aeb 130 CHAR **font;
formulas 0:38c3afd99aeb 131 if(abs(num)<pow(float(10),digits)){
formulas 0:38c3afd99aeb 132 digit[0]=abs(num)/pow((float)10,(float)(digits-1));
formulas 0:38c3afd99aeb 133 digit0[0]=abs(num0)/pow((float)10,(float)(digits-1));
formulas 0:38c3afd99aeb 134 for(k=1;k<digits;k++){
formulas 0:38c3afd99aeb 135 sum=(sum+digit[k-1])*10;
formulas 0:38c3afd99aeb 136 digit[k]=abs(num)/pow((float)10,(float)(digits-1-k))-sum;
formulas 0:38c3afd99aeb 137 sum0=(sum0+digit0[k-1])*10;
formulas 0:38c3afd99aeb 138 digit0[k]=abs(num0)/pow(10,(float)(digits-1-k))-sum0;
formulas 0:38c3afd99aeb 139 };
formulas 0:38c3afd99aeb 140
formulas 0:38c3afd99aeb 141 if (Font==50){
formulas 0:38c3afd99aeb 142 font=font50;
formulas 0:38c3afd99aeb 143 }else if (Font==100){
formulas 0:38c3afd99aeb 144 font=font100;
formulas 0:38c3afd99aeb 145 };
formulas 0:38c3afd99aeb 146
formulas 0:38c3afd99aeb 147 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 148 uint8_t char_width=(*font[0]).width;
formulas 0:38c3afd99aeb 149
formulas 0:38c3afd99aeb 150 if (sign==1){
formulas 0:38c3afd99aeb 151 if(num<0 & num0>=0){ //Print minus if number lower than 0
formulas 0:38c3afd99aeb 152 PrintChar(*font[10],StartXPos,StartYPos,lcd.GetTextColor());
formulas 0:38c3afd99aeb 153 }else if(num>=0 & num0<0){ //Print blank if number lower than 0
formulas 0:38c3afd99aeb 154 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 155 lcd.FillRect(StartXPos,StartYPos,(*font[10]).width,(*font[10]).height);
formulas 0:38c3afd99aeb 156 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 157 };
formulas 0:38c3afd99aeb 158 aux+=(*font[10]).width;
formulas 0:38c3afd99aeb 159 };
formulas 0:38c3afd99aeb 160
formulas 0:38c3afd99aeb 161 for(k=0;k<digits;k++){
formulas 0:38c3afd99aeb 162 if(dec_point==k & dec_point>0){ //Default is for font50. This is not an universal solution, but it is in use because all font 100 infos are integers
formulas 0:38c3afd99aeb 163 PrintChar(Chardot_50,StartXPos+dec_point*char_width,StartYPos,lcd.GetTextColor());
formulas 0:38c3afd99aeb 164 aux+=Chardot_50.width;
formulas 0:38c3afd99aeb 165 };
formulas 0:38c3afd99aeb 166 if(digit[k]!=digit0[k]){
formulas 0:38c3afd99aeb 167 PrintChar(*font[digit[k]],StartXPos+k*char_width+aux,StartYPos,lcd.GetTextColor());
formulas 0:38c3afd99aeb 168 };
formulas 0:38c3afd99aeb 169 };
formulas 0:38c3afd99aeb 170 };
formulas 0:38c3afd99aeb 171 };
formulas 0:38c3afd99aeb 172
formulas 0:38c3afd99aeb 173 void SetNumber(int num,int Font,uint16_t StartXPos,uint16_t StartYPos, int digits, int dec_point, int sign){
formulas 0:38c3afd99aeb 174 int digit[3],sum=0,k,aux=0;
formulas 0:38c3afd99aeb 175 CHAR **font;
formulas 0:38c3afd99aeb 176
formulas 0:38c3afd99aeb 177 if (Font==50){
formulas 0:38c3afd99aeb 178 font=font50;
formulas 0:38c3afd99aeb 179 }else if (Font==100){
formulas 0:38c3afd99aeb 180 font=font100;
formulas 0:38c3afd99aeb 181 };
formulas 0:38c3afd99aeb 182
formulas 0:38c3afd99aeb 183 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 184 uint8_t char_width=(*font[0]).width;
formulas 0:38c3afd99aeb 185
formulas 0:38c3afd99aeb 186 if(num<pow(float(10),digits)){
formulas 0:38c3afd99aeb 187 digit[0]=abs(num)/pow((float)10,(float)(digits-1));
formulas 0:38c3afd99aeb 188 for(k=1;k<digits;k++){
formulas 0:38c3afd99aeb 189 sum=(sum+digit[k-1])*10;
formulas 0:38c3afd99aeb 190 digit[k]=abs(num)/pow((float)10,(float)(digits-1-k))-sum;
formulas 0:38c3afd99aeb 191 };
formulas 0:38c3afd99aeb 192
formulas 0:38c3afd99aeb 193 if(sign==1){
formulas 0:38c3afd99aeb 194 if(num<0){ //Print minus if number lower than 0
formulas 0:38c3afd99aeb 195 PrintChar(*font[10],StartXPos,StartYPos,lcd.GetTextColor());
formulas 0:38c3afd99aeb 196 }else if(num>=0){ //Print blank if number lower than 0
formulas 0:38c3afd99aeb 197 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 198 lcd.FillRect(StartXPos,StartYPos,(*font[10]).width,(*font[10]).height);
formulas 0:38c3afd99aeb 199 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 200 };
formulas 0:38c3afd99aeb 201 aux+=(*font[10]).width;
formulas 0:38c3afd99aeb 202 };
formulas 0:38c3afd99aeb 203
formulas 0:38c3afd99aeb 204 for(k=0;k<digits;k++){
formulas 0:38c3afd99aeb 205 if(dec_point==k & dec_point>0){ //Default is for font50. This is not an universal solution, but it is in use because all font 100 infos are integers
formulas 0:38c3afd99aeb 206 PrintChar(Chardot_50,StartXPos+dec_point*char_width,StartYPos,lcd.GetTextColor());
formulas 0:38c3afd99aeb 207 aux+=Chardot_50.width;
formulas 0:38c3afd99aeb 208 };
formulas 0:38c3afd99aeb 209 PrintChar(*font[digit[k]],StartXPos+k*char_width+aux,StartYPos,lcd.GetTextColor());
formulas 0:38c3afd99aeb 210 };
formulas 0:38c3afd99aeb 211 };
formulas 0:38c3afd99aeb 212 };
formulas 0:38c3afd99aeb 213
formulas 0:38c3afd99aeb 214 void DrawRGBImage(IMAGE Image,uint16_t StartXPos,uint16_t StartYPos){
formulas 0:38c3afd99aeb 215 uint32_t p,q;
formulas 0:38c3afd99aeb 216 uint32_t BlockBuffer[128];
formulas 0:38c3afd99aeb 217 uint16_t xpos=0,ypos=0;
formulas 0:38c3afd99aeb 218 for(p=0;p<Image.width*Image.height/128;p++){
formulas 0:38c3afd99aeb 219 sd.ReadBlocks(BlockBuffer,Image.START_ADDR+p*512,1,SD_DATATIMEOUT);
formulas 0:38c3afd99aeb 220 for(q=0;q<128;q++){
formulas 0:38c3afd99aeb 221 if(ypos<Image.height){
formulas 0:38c3afd99aeb 222 lcd.DrawPixel(StartXPos+xpos,StartYPos+ypos,BlockBuffer[q]);
formulas 0:38c3afd99aeb 223 }
formulas 0:38c3afd99aeb 224 else{
formulas 0:38c3afd99aeb 225 xpos++;
formulas 0:38c3afd99aeb 226 ypos=0;
formulas 0:38c3afd99aeb 227 lcd.DrawPixel(StartXPos+xpos,StartYPos+ypos,BlockBuffer[q]);
formulas 0:38c3afd99aeb 228 }
formulas 0:38c3afd99aeb 229 ypos++;
formulas 0:38c3afd99aeb 230 };
formulas 0:38c3afd99aeb 231 };
formulas 0:38c3afd99aeb 232 };
formulas 0:38c3afd99aeb 233
formulas 0:38c3afd99aeb 234
formulas 0:38c3afd99aeb 235 void UpdateSpeedMeter(int V, int dV){
formulas 0:38c3afd99aeb 236 //Prednost koda je sto se docrtava samo onaj deo koji se menja. Tako ako sa 55 kmh prelazimo na 57 khm on obradjuje samo polja 55 i 56.
formulas 0:38c3afd99aeb 237 //Kada bi se samo brisala stara i crtala nova vrednost na baru ukupno bi morali da obradimo 55+57=112 umesto samo 2 bara.
formulas 0:38c3afd99aeb 238 uint32_t OldColor,RewriteColor;
formulas 0:38c3afd99aeb 239 double THETA1,THETA2;
formulas 0:38c3afd99aeb 240 uint16_t x1,y1,x2,y2,x3,y3,x4,y4;
formulas 0:38c3afd99aeb 241 uint16_t startx,starty,leftupx,rightupx,leftdownx,rightdownx,ypos;
formulas 0:38c3afd99aeb 242
formulas 0:38c3afd99aeb 243 //Obradjivanje polje po polje. Svako polje prestavlja odredjenu vrednost kmh.
formulas 0:38c3afd99aeb 244 for(int k=1;k<=abs(dV);k++){
formulas 0:38c3afd99aeb 245 //Uokviravanje polja koje se trenutno obradjuje. Granice su crne kako bi se jasno razgranicilo polje od ostatka bara.
formulas 0:38c3afd99aeb 246 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 247 THETA1=PHI+((double)V)*ALPHA/Vmax;
formulas 0:38c3afd99aeb 248 x1=(int)(400-530*cos(THETA1));
formulas 0:38c3afd99aeb 249 y1=(int)(550-530*sin(THETA1));
formulas 0:38c3afd99aeb 250 x2=(int)(400-500*cos(THETA1));
formulas 0:38c3afd99aeb 251 y2=(int)(550-500*sin(THETA1));
formulas 0:38c3afd99aeb 252 THETA2=PHI+((double)(V+dV/abs(dV)))*ALPHA/Vmax;
formulas 0:38c3afd99aeb 253 x3=(int)(400-530*cos(THETA2));
formulas 0:38c3afd99aeb 254 y3=(int)(550-530*sin(THETA2));
formulas 0:38c3afd99aeb 255 x4=(int)(400-500*cos(THETA2));
formulas 0:38c3afd99aeb 256 y4=(int)(550-500*sin(THETA2));
formulas 0:38c3afd99aeb 257 lcd.DrawLine(x1,y1,x2,y2);
formulas 0:38c3afd99aeb 258 lcd.DrawLine(x3,y3,x4,y4);
formulas 0:38c3afd99aeb 259 lcd.DrawLine(x1,y1,x3,y3);
formulas 0:38c3afd99aeb 260 lcd.DrawLine(x2,y2,x4,y4);
formulas 0:38c3afd99aeb 261
formulas 0:38c3afd99aeb 262 //Odredjivanje pocetnih koordinata i kojom bojom ce se polje bojiti.
formulas 0:38c3afd99aeb 263 if(dV>0){
formulas 0:38c3afd99aeb 264 startx=(x2+x3)/2;
formulas 0:38c3afd99aeb 265 starty=(y2+y3)/2;
formulas 0:38c3afd99aeb 266 if(V+1<=50){
formulas 0:38c3afd99aeb 267 RewriteColor=LCD_COLOR_GREEN;
formulas 0:38c3afd99aeb 268 }else if (V+1>50 & V+1<=100){
formulas 0:38c3afd99aeb 269 RewriteColor=LCD_COLOR_BLUE;
formulas 0:38c3afd99aeb 270 }else{
formulas 0:38c3afd99aeb 271 RewriteColor=LCD_COLOR_RED;
formulas 0:38c3afd99aeb 272 };
formulas 0:38c3afd99aeb 273 OldColor=LCD_COLOR_WHITE;
formulas 0:38c3afd99aeb 274 }else{
formulas 0:38c3afd99aeb 275 startx=(x1+x4)/2;
formulas 0:38c3afd99aeb 276 starty=(y1+y4)/2;
formulas 0:38c3afd99aeb 277 if(V<=50){
formulas 0:38c3afd99aeb 278 OldColor=LCD_COLOR_GREEN;
formulas 0:38c3afd99aeb 279 }else if (V>50 & V<=100){
formulas 0:38c3afd99aeb 280 OldColor=LCD_COLOR_BLUE;
formulas 0:38c3afd99aeb 281 }else{
formulas 0:38c3afd99aeb 282 OldColor=LCD_COLOR_RED;
formulas 0:38c3afd99aeb 283 };
formulas 0:38c3afd99aeb 284 RewriteColor=LCD_COLOR_WHITE;
formulas 0:38c3afd99aeb 285 };
formulas 0:38c3afd99aeb 286 lcd.SetTextColor(RewriteColor);
formulas 0:38c3afd99aeb 287
formulas 0:38c3afd99aeb 288 //Odredjivanje pocetnog piksela odakle ce bojenje poceti. Kako bi se svaki piksel obojio pocetni se postavlja u centru polja i krece se najpre
formulas 0:38c3afd99aeb 289 //na gore pa zatim od sredine na dole.
formulas 0:38c3afd99aeb 290 leftupx=startx;
formulas 0:38c3afd99aeb 291 rightupx=startx+1;
formulas 0:38c3afd99aeb 292 ypos=starty;
formulas 0:38c3afd99aeb 293 while(leftupx<rightupx){
formulas 0:38c3afd99aeb 294
formulas 0:38c3afd99aeb 295 ypos--;
formulas 0:38c3afd99aeb 296 if(lcd.ReadPixel(leftupx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 297 while(lcd.ReadPixel(leftupx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 298 leftupx++;
formulas 0:38c3afd99aeb 299 }
formulas 0:38c3afd99aeb 300 } else {
formulas 0:38c3afd99aeb 301 while(lcd.ReadPixel(leftupx,ypos)==OldColor){
formulas 0:38c3afd99aeb 302 leftupx--;
formulas 0:38c3afd99aeb 303 };
formulas 0:38c3afd99aeb 304 leftupx++;
formulas 0:38c3afd99aeb 305 };
formulas 0:38c3afd99aeb 306 if(lcd.ReadPixel(rightupx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 307 while(lcd.ReadPixel(rightupx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 308 rightupx--;
formulas 0:38c3afd99aeb 309 }
formulas 0:38c3afd99aeb 310 } else {
formulas 0:38c3afd99aeb 311 while(lcd.ReadPixel(rightupx,ypos)==OldColor){
formulas 0:38c3afd99aeb 312 rightupx++;
formulas 0:38c3afd99aeb 313 };
formulas 0:38c3afd99aeb 314 rightupx--;
formulas 0:38c3afd99aeb 315 };
formulas 0:38c3afd99aeb 316
formulas 0:38c3afd99aeb 317 if (leftupx<=rightupx){
formulas 0:38c3afd99aeb 318 lcd.DrawLine(leftupx,ypos,rightupx,ypos);
formulas 0:38c3afd99aeb 319 };
formulas 0:38c3afd99aeb 320 };
formulas 0:38c3afd99aeb 321
formulas 0:38c3afd99aeb 322 leftdownx=startx;
formulas 0:38c3afd99aeb 323 rightdownx=startx+1;
formulas 0:38c3afd99aeb 324 ypos=starty-1;
formulas 0:38c3afd99aeb 325 while(leftdownx<rightdownx){
formulas 0:38c3afd99aeb 326 ypos++;
formulas 0:38c3afd99aeb 327 if(lcd.ReadPixel(leftdownx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 328 while(lcd.ReadPixel(leftdownx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 329 leftdownx++;
formulas 0:38c3afd99aeb 330 }
formulas 0:38c3afd99aeb 331 } else {
formulas 0:38c3afd99aeb 332 while(lcd.ReadPixel(leftdownx,ypos)==OldColor){
formulas 0:38c3afd99aeb 333 leftdownx--;
formulas 0:38c3afd99aeb 334 };
formulas 0:38c3afd99aeb 335 leftdownx++;
formulas 0:38c3afd99aeb 336 };
formulas 0:38c3afd99aeb 337 if(lcd.ReadPixel(rightdownx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 338 while(lcd.ReadPixel(rightdownx,ypos)==LCD_COLOR_BLACK){
formulas 0:38c3afd99aeb 339 rightdownx--;
formulas 0:38c3afd99aeb 340 }
formulas 0:38c3afd99aeb 341 } else {
formulas 0:38c3afd99aeb 342 while(lcd.ReadPixel(rightdownx,ypos)==OldColor){
formulas 0:38c3afd99aeb 343 rightdownx++;
formulas 0:38c3afd99aeb 344 };
formulas 0:38c3afd99aeb 345 rightdownx--;
formulas 0:38c3afd99aeb 346 };
formulas 0:38c3afd99aeb 347
formulas 0:38c3afd99aeb 348 if (leftdownx<=rightdownx){
formulas 0:38c3afd99aeb 349 lcd.DrawLine(leftdownx,ypos,rightdownx,ypos);
formulas 0:38c3afd99aeb 350 };
formulas 0:38c3afd99aeb 351 };
formulas 0:38c3afd99aeb 352
formulas 0:38c3afd99aeb 353 //Brisanje granicnika. Vodi se racuna ako je granica neki od dekadnih podeoka koji treba da ostane crn.
formulas 0:38c3afd99aeb 354 if(V%10!=0){
formulas 0:38c3afd99aeb 355 lcd.DrawLine(x1,y1,x2,y2);
formulas 0:38c3afd99aeb 356 if (dV<0){
formulas 0:38c3afd99aeb 357 lcd.DrawPixel(x1,y1,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 358 lcd.DrawPixel(x2,y2,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 359 };
formulas 0:38c3afd99aeb 360 };
formulas 0:38c3afd99aeb 361 V+=dV/abs(dV);
formulas 0:38c3afd99aeb 362 };
formulas 0:38c3afd99aeb 363 };
formulas 0:38c3afd99aeb 364
formulas 0:38c3afd99aeb 365 void ChangeCrank(int Crank){
formulas 2:f54f01527ebb 366 PrintString(" ",50,350,400,LCD_COLOR_GREEN);
formulas 0:38c3afd99aeb 367 if (Crank){
formulas 0:38c3afd99aeb 368 PrintString("ERROR",50,CrankXPos,CrankYPos,LCD_COLOR_RED);
formulas 0:38c3afd99aeb 369 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 370 } else {
formulas 0:38c3afd99aeb 371 PrintString("OK",50,CrankXPos,CrankYPos,LCD_COLOR_GREEN);
formulas 0:38c3afd99aeb 372 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 373 };
formulas 0:38c3afd99aeb 374 };
formulas 0:38c3afd99aeb 375
formulas 0:38c3afd99aeb 376 int UpdateLVDTScale(int H,int H0, uint16_t StartXPos, uint16_t StartYPos){
formulas 0:38c3afd99aeb 377 uint16_t BarWidth=80,BarHeight=8;
formulas 0:38c3afd99aeb 378 int YPos;
formulas 0:38c3afd99aeb 379 int D,D0,dD;
formulas 0:38c3afd99aeb 380
formulas 0:38c3afd99aeb 381 switch( ((H>=0)<<1)+(H0>0)){
formulas 0:38c3afd99aeb 382 case(0):
formulas 0:38c3afd99aeb 383 D=5-abs(H)/20;
formulas 0:38c3afd99aeb 384 D0=5-abs(H0)/20;
formulas 0:38c3afd99aeb 385 break;
formulas 0:38c3afd99aeb 386 case(1):
formulas 0:38c3afd99aeb 387 D=5-abs(H)/20;
formulas 0:38c3afd99aeb 388 D0=H0/20+5;
formulas 0:38c3afd99aeb 389 break;
formulas 0:38c3afd99aeb 390 case(2):
formulas 0:38c3afd99aeb 391 D=H/20+5;
formulas 0:38c3afd99aeb 392 D0=5-abs(H0)/20;
formulas 0:38c3afd99aeb 393 break;
formulas 0:38c3afd99aeb 394 case(3):
formulas 0:38c3afd99aeb 395 D=H/20+5;
formulas 0:38c3afd99aeb 396 D0=H0/20+5;
formulas 0:38c3afd99aeb 397 break;
formulas 0:38c3afd99aeb 398 };
formulas 0:38c3afd99aeb 399 dD=D-D0;
formulas 0:38c3afd99aeb 400
formulas 0:38c3afd99aeb 401 if (dD>0){
formulas 0:38c3afd99aeb 402 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 403 YPos=StartYPos-10*(D0+1);
formulas 0:38c3afd99aeb 404 }else{
formulas 0:38c3afd99aeb 405 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 406 YPos=StartYPos-D0*10;
formulas 0:38c3afd99aeb 407 };
formulas 0:38c3afd99aeb 408 for (int k=1;k<=abs(dD);k++){
formulas 0:38c3afd99aeb 409 lcd.FillRect(StartXPos,YPos,BarWidth,BarHeight);
formulas 0:38c3afd99aeb 410 YPos-=10*(dD/abs(dD));
formulas 0:38c3afd99aeb 411 };
formulas 0:38c3afd99aeb 412 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 413 return 1;
formulas 0:38c3afd99aeb 414 };
formulas 0:38c3afd99aeb 415
formulas 0:38c3afd99aeb 416
formulas 4:0e8413277df8 417 void BrakeSignal(uint16_t brake){
formulas 4:0e8413277df8 418 if (brake!=0){
formulas 0:38c3afd99aeb 419 lcd.SetTextColor(LCD_COLOR_RED);
formulas 0:38c3afd99aeb 420 lcd.SetBackColor(LCD_COLOR_RED);
formulas 0:38c3afd99aeb 421 lcd.FillRect(560,340,230,68);
formulas 0:38c3afd99aeb 422 PrintString("BRAKE",50,575,350,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 423 }else {
formulas 0:38c3afd99aeb 424 lcd.SetTextColor(LCD_COLOR_DARKRED);
formulas 0:38c3afd99aeb 425 lcd.SetBackColor(LCD_COLOR_DARKRED);
formulas 0:38c3afd99aeb 426 lcd.FillRect(560,340,230,68);
formulas 0:38c3afd99aeb 427 PrintString("BRAKE",50,575,350,LCD_COLOR_BLACK);
formulas 0:38c3afd99aeb 428 };
formulas 0:38c3afd99aeb 429 lcd.SetBackColor(LCD_COLOR_WHITE);
formulas 0:38c3afd99aeb 430 };
formulas 0:38c3afd99aeb 431
formulas 0:38c3afd99aeb 432
formulas 0:38c3afd99aeb 433 void TestFont(){
formulas 0:38c3afd99aeb 434 uint16_t XPos=0,YPos=120;
formulas 0:38c3afd99aeb 435 for(int k=0;k<68;k++){
formulas 0:38c3afd99aeb 436 PrintChar(*font50[k],XPos,YPos,lcd.GetTextColor());
formulas 0:38c3afd99aeb 437 XPos=XPos+(*font50[k]).width;
formulas 0:38c3afd99aeb 438 wait(0.1);
formulas 0:38c3afd99aeb 439 //pc.printf("%d",k);
formulas 0:38c3afd99aeb 440 };
formulas 0:38c3afd99aeb 441 };