Nenad Djalovic / Mbed 2 deprecated IntegrationCAN_7jul_copy

Dependencies:   mbed LCD_DISCO_F469NIa SD_DISCO_F469NI BSP_DISCO_F469NIa EEPROM_DISCO_F469NI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers draw_print_library.cpp Source File

draw_print_library.cpp

00001 #include "draw_print_library.h"
00002 #include "gears.h"
00003 #include "font100.h"
00004 #include "font50.h"
00005 
00006 extern LCD_DISCO_F469NI lcd;
00007 extern SD_DISCO_F469NI sd;
00008 extern Serial pc;
00009 
00010 extern uint8_t lvdtref;
00011 extern int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref;
00012 extern uint8_t Acc_Temperature[],Acc_Temperature0[];
00013 
00014 //Gears 
00015 GEAR Idle{'0',256,384,idleBitmap};
00016 GEAR Gear1{'1',256,384,gear1Bitmap};
00017 GEAR Gear2{'2',256,384,gear2Bitmap};
00018 GEAR Gear3{'3',256,384,gear3Bitmap};
00019 GEAR Gear4{'4',256,384,gear4Bitmap};
00020 GEAR Gear5{'5',256,384,gear5Bitmap};
00021 GEAR Gear6{'6',256,384,gear6Bitmap};
00022 CHAR LogoSmallEA{'logosmallea',174,64,logosmallea};
00023 GEAR *Gears[7]={&Idle,&Gear1,&Gear2,&Gear3,&Gear4,&Gear5,&Gear6};       //Gears array
00024 IMAGE LogoBig{800,480,LOGOBIG_START_ADDR};                              //Big Logo 
00025 IMAGE LogoSmall{160,64,LOGOSMALL_START_ADDR};                           //Small Logo
00026 IMAGE Branko{250,480,1576960};                                          //Branko
00027 IMAGE NewYearCongat{800,480,NEW_YEAR_CONGAT_START_ADDR};
00028 //IMAGE Miljana[250,480,---};
00029 
00030 void DrawSpeedMeter(){
00031     uint16_t x1,y1,x2,y2,x3,y3,x4,y4;
00032     double THETA1=PHI,THETA2;
00033     
00034     //Set starting point for drawing
00035     x1=(int)(400-530*cos(THETA1));
00036     y1=(int)(550-530*sin(THETA1));
00037     x2=(int)(400-500*cos(THETA1));
00038     y2=(int)(550-500*sin(THETA1));
00039     
00040     lcd.SetTextColor(LCD_COLOR_BLACK);
00041     for (int V=0;V<=150;V++){                   //Draw from 0 to 150
00042         //Set angle for next speed scale value
00043         THETA2=THETA1+ALPHA/Vmax;               
00044         x3=(int)(400-530*cos(THETA2));
00045         y3=(int)(550-530*sin(THETA2));
00046         x4=(int)(400-500*cos(THETA2));
00047         y4=(int)(550-500*sin(THETA2));
00048         if(V<150){                              //Draw arch section
00049             lcd.DrawLine(x1,y1,x3,y3);
00050             lcd.DrawLine(x2,y2,x4,y4);
00051         };
00052         lcd.SetFont(&Font20);
00053         if(V%10==0){                            //Print round values (0,10,20,...)
00054             lcd.DrawLine(x1,y1,x2,y2);          //Draw round scale value
00055             char Vchar[3];
00056             sprintf(Vchar,"%d",(int)V);
00057             uint16_t xnum=x2,ynum=y2;
00058             if (V==0 | V==10 | V==20 | V==30){  //Position of printed value
00059                 xnum=x2,ynum=y2+5;
00060             }else if (V==40 | V==50 | V==60){
00061                 xnum=x2-3,ynum=y2+5;
00062             }else if (V==70 | V==80){
00063                 xnum=x2-14,ynum=y2+5;
00064             }else if (V==90){
00065                 xnum=x2-20,ynum=y2+5;
00066             }else if (V==100 | V==110 | V==120) {
00067                 xnum=x2-35,ynum=y2+4;
00068             }else if (V==130 | V==140 | V==150){
00069                 xnum=x2-35,ynum=y2+5;
00070             };
00071             lcd.DisplayStringAt(xnum,ynum,(uint8_t*)Vchar,LEFT_MODE);
00072         };
00073         x1=x3,y1=y3,x2=x4,y2=y4;            //Increment position
00074         THETA1=THETA2;
00075     };
00076 };
00077 
00078 void PrintChar(CHAR Char,uint16_t StartXPos,uint16_t StartYPos,uint32_t TextColor){
00079     uint16_t width=Char.width;
00080     uint16_t height=Char.height;
00081     uint16_t horpos,vertpos;
00082     uint16_t bitloc;
00083     uint32_t DrawColor;
00084     char pos[9];
00085     //uint8_t dbg[50];
00086     for(horpos=0;horpos<width;horpos++){                                //Bitmaps are row after row
00087         for(vertpos=0;vertpos<height/8;vertpos++){
00088             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
00089             //pc.printf("%d. %s\n",horpos*height/8+vertpos,pos);
00090             for(bitloc=0;bitloc<8;bitloc++) {
00091                 if (pos[bitloc]=='1') {
00092                     DrawColor=TextColor;
00093                 }
00094                 else{
00095                     DrawColor=lcd.GetBackColor();
00096                 };
00097                 lcd.DrawPixel(StartXPos+horpos,StartYPos+vertpos*8+bitloc,DrawColor);
00098                     //pc.printf("%d,%d\n",StartXPos+horpos,StartYPos+vertpos*8+bitloc);                   
00099             }
00100         }
00101     }
00102     lcd.SetTextColor(LCD_COLOR_BLACK);
00103 };
00104 
00105 void PrintString(char str[],int font,uint16_t StartXPos,uint16_t StartYPos,uint32_t TextColor){
00106     //pc.printf("Function activated.\n");
00107     char *a=str;
00108     int p=0;
00109     while(a[p]){
00110         //pc.printf("Searching char: %c\n",a[p]);
00111         for(int k=0;k<68;k++){
00112             //pc.printf("Character %c\n",(*font50[k]).name);
00113             if((*font50[k]).name==a[p]){
00114           //      pc.printf("Found!\n");
00115                 PrintChar(*font50[k],StartXPos,StartYPos,TextColor);
00116                 StartXPos+=(*font50[k]).width;
00117                 k=100;
00118             };
00119         };
00120         //pc.printf("End.\n");
00121         p++;
00122     };
00123 };
00124                     
00125                                         
00126 
00127 
00128 void ChangeNumber(int num,int num0,int Font,uint16_t StartXPos,uint16_t StartYPos, int digits, int dec_point, int sign){
00129     //Function only changes the decimals that change. If number changes from 146 to 147, it only changes 6 to 7.
00130     int digit[digits],digit0[digits];
00131     int sum=0,sum0=0,k,aux=0;
00132     CHAR **font;
00133     if(abs(num)<pow(float(10),digits)){
00134         digit[0]=abs(num)/pow((float)10,(float)(digits-1));
00135         digit0[0]=abs(num0)/pow((float)10,(float)(digits-1));
00136         for(k=1;k<digits;k++){
00137             sum=(sum+digit[k-1])*10;
00138             digit[k]=abs(num)/pow((float)10,(float)(digits-1-k))-sum;
00139             sum0=(sum0+digit0[k-1])*10;
00140             digit0[k]=abs(num0)/pow(10,(float)(digits-1-k))-sum0;
00141         };
00142     
00143         if (Font==50){
00144             font=font50;
00145         }else if (Font==100){
00146             font=font100;
00147         };
00148     
00149         lcd.SetTextColor(LCD_COLOR_BLACK);
00150         uint8_t char_width=(*font[0]).width;
00151         
00152         if (sign==1){
00153             if(num<0 & num0>=0){                                                //Print minus if number lower than 0
00154                 PrintChar(*font[10],StartXPos,StartYPos,lcd.GetTextColor());
00155             }else if(num>=0 & num0<0){                                          //Print blank if number lower than 0 
00156                 lcd.SetTextColor(LCD_COLOR_WHITE);
00157                 lcd.FillRect(StartXPos,StartYPos,(*font[10]).width,(*font[10]).height);
00158                 lcd.SetTextColor(LCD_COLOR_BLACK);
00159             };
00160             aux+=(*font[10]).width;
00161         };
00162            
00163         for(k=0;k<digits;k++){
00164             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
00165                 PrintChar(Chardot_50,StartXPos+dec_point*char_width,StartYPos,lcd.GetTextColor());
00166                 aux+=Chardot_50.width;
00167             };
00168             if(digit[k]!=digit0[k]){
00169                 PrintChar(*font[digit[k]],StartXPos+k*char_width+aux,StartYPos,lcd.GetTextColor());
00170             };
00171         };   
00172     };
00173 };
00174 
00175 void SetNumber(int num,int Font,uint16_t StartXPos,uint16_t StartYPos, int digits, int dec_point, int sign){
00176     int digit[3],sum=0,k,aux=0;
00177     CHAR **font;
00178     
00179     if (Font==50){
00180         font=font50;
00181     }else if (Font==100){
00182         font=font100;
00183     };
00184     
00185     lcd.SetTextColor(LCD_COLOR_BLACK);
00186     uint8_t char_width=(*font[0]).width;
00187     
00188     if(num<pow(float(10),digits)){
00189         digit[0]=abs(num)/pow((float)10,(float)(digits-1));
00190         for(k=1;k<digits;k++){
00191             sum=(sum+digit[k-1])*10;
00192             digit[k]=abs(num)/pow((float)10,(float)(digits-1-k))-sum;
00193         };
00194         
00195         if(sign==1){
00196             if(num<0){                                                          //Print minus if number lower than 0
00197                 PrintChar(*font[10],StartXPos,StartYPos,lcd.GetTextColor());
00198             }else if(num>=0){                                                   //Print blank if number lower than 0 
00199                 lcd.SetTextColor(LCD_COLOR_WHITE);
00200                 lcd.FillRect(StartXPos,StartYPos,(*font[10]).width,(*font[10]).height);
00201                 lcd.SetTextColor(LCD_COLOR_BLACK);
00202             };
00203             aux+=(*font[10]).width;
00204         };
00205               
00206         for(k=0;k<digits;k++){
00207             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
00208                 PrintChar(Chardot_50,StartXPos+dec_point*char_width,StartYPos,lcd.GetTextColor());
00209                 aux+=Chardot_50.width;
00210             };
00211             PrintChar(*font[digit[k]],StartXPos+k*char_width+aux,StartYPos,lcd.GetTextColor());
00212         };
00213     };   
00214 };   
00215 
00216 void DrawRGBImage(IMAGE Image,uint16_t StartXPos,uint16_t StartYPos){
00217     uint32_t p,q;
00218     uint32_t BlockBuffer[128];
00219     uint16_t xpos=0,ypos=0;
00220     for(p=0;p<Image.width*Image.height/128;p++){
00221         sd.ReadBlocks(BlockBuffer,Image.START_ADDR+p*512,1,SD_DATATIMEOUT);
00222         for(q=0;q<128;q++){
00223             if(ypos<Image.height){
00224                lcd.DrawPixel(StartXPos+xpos,StartYPos+ypos,BlockBuffer[q]);
00225             }
00226             else{
00227                 xpos++;
00228                 ypos=0;
00229                 lcd.DrawPixel(StartXPos+xpos,StartYPos+ypos,BlockBuffer[q]);
00230             }
00231             ypos++;
00232         };
00233     };
00234 };  
00235 
00236 
00237 void UpdateSpeedMeter(int V, int dV){
00238    //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.
00239    //Kada bi se samo brisala stara i crtala nova vrednost na baru ukupno bi morali da obradimo 55+57=112 umesto samo 2 bara.
00240    uint32_t OldColor,RewriteColor;
00241    double THETA1,THETA2;
00242    uint16_t x1,y1,x2,y2,x3,y3,x4,y4;
00243    uint16_t startx,starty,leftupx,rightupx,leftdownx,rightdownx,ypos;
00244 
00245     //Obradjivanje polje po polje. Svako polje prestavlja odredjenu vrednost kmh.  
00246     for(int k=1;k<=abs(dV);k++){
00247         //Uokviravanje polja koje se trenutno obradjuje. Granice su crne kako bi se jasno razgranicilo polje od ostatka bara.
00248         lcd.SetTextColor(LCD_COLOR_BLACK);
00249         THETA1=PHI+((double)V)*ALPHA/Vmax;
00250         x1=(int)(400-530*cos(THETA1));
00251         y1=(int)(550-530*sin(THETA1));
00252         x2=(int)(400-500*cos(THETA1));
00253         y2=(int)(550-500*sin(THETA1));
00254         THETA2=PHI+((double)(V+dV/abs(dV)))*ALPHA/Vmax;
00255         x3=(int)(400-530*cos(THETA2));
00256         y3=(int)(550-530*sin(THETA2));
00257         x4=(int)(400-500*cos(THETA2));
00258         y4=(int)(550-500*sin(THETA2));
00259         lcd.DrawLine(x1,y1,x2,y2);
00260         lcd.DrawLine(x3,y3,x4,y4);
00261         lcd.DrawLine(x1,y1,x3,y3);
00262         lcd.DrawLine(x2,y2,x4,y4);
00263         
00264         //Odredjivanje pocetnih koordinata i kojom bojom ce se polje bojiti.
00265         if(dV>0){
00266             startx=(x2+x3)/2;
00267             starty=(y2+y3)/2;
00268             if(V+1<=50){
00269                 RewriteColor=LCD_COLOR_GREEN;
00270             }else if (V+1>50 & V+1<=100){
00271                 RewriteColor=LCD_COLOR_BLUE;
00272             }else{
00273                 RewriteColor=LCD_COLOR_RED;
00274             };
00275             OldColor=LCD_COLOR_WHITE;
00276         }else{
00277             startx=(x1+x4)/2;
00278             starty=(y1+y4)/2;
00279             if(V<=50){
00280                 OldColor=LCD_COLOR_GREEN;
00281             }else if (V>50 & V<=100){
00282                 OldColor=LCD_COLOR_BLUE;
00283             }else{
00284                 OldColor=LCD_COLOR_RED;
00285             };
00286             RewriteColor=LCD_COLOR_WHITE;
00287         };
00288         lcd.SetTextColor(RewriteColor);
00289         
00290         //Odredjivanje pocetnog piksela odakle ce bojenje poceti. Kako bi se svaki piksel obojio pocetni se postavlja u centru polja i krece se najpre
00291         //na gore pa zatim od sredine na dole.
00292         leftupx=startx;
00293         rightupx=startx+1;
00294         ypos=starty; 
00295         while(leftupx<rightupx){
00296             
00297             ypos--;
00298             if(lcd.ReadPixel(leftupx,ypos)==LCD_COLOR_BLACK){
00299                 while(lcd.ReadPixel(leftupx,ypos)==LCD_COLOR_BLACK){
00300                     leftupx++;
00301                 }
00302             } else {
00303                 while(lcd.ReadPixel(leftupx,ypos)==OldColor){
00304                     leftupx--;
00305                 };
00306                 leftupx++;
00307             };
00308             if(lcd.ReadPixel(rightupx,ypos)==LCD_COLOR_BLACK){
00309                 while(lcd.ReadPixel(rightupx,ypos)==LCD_COLOR_BLACK){
00310                     rightupx--;
00311                 }
00312             } else {
00313                 while(lcd.ReadPixel(rightupx,ypos)==OldColor){
00314                     rightupx++;
00315                 };
00316                 rightupx--;
00317             };
00318             
00319             if (leftupx<=rightupx){
00320                 lcd.DrawLine(leftupx,ypos,rightupx,ypos);
00321             };   
00322         };
00323         
00324         leftdownx=startx;
00325         rightdownx=startx+1;
00326         ypos=starty-1; 
00327         while(leftdownx<rightdownx){
00328             ypos++;
00329             if(lcd.ReadPixel(leftdownx,ypos)==LCD_COLOR_BLACK){
00330                 while(lcd.ReadPixel(leftdownx,ypos)==LCD_COLOR_BLACK){
00331                     leftdownx++;
00332                 }
00333             } else {
00334                 while(lcd.ReadPixel(leftdownx,ypos)==OldColor){
00335                     leftdownx--;
00336                 };
00337                 leftdownx++;
00338             };
00339             if(lcd.ReadPixel(rightdownx,ypos)==LCD_COLOR_BLACK){
00340                 while(lcd.ReadPixel(rightdownx,ypos)==LCD_COLOR_BLACK){
00341                     rightdownx--;
00342                 }
00343             } else {
00344                 while(lcd.ReadPixel(rightdownx,ypos)==OldColor){
00345                     rightdownx++;
00346                 };
00347                 rightdownx--;
00348             };
00349             
00350             if (leftdownx<=rightdownx){
00351                 lcd.DrawLine(leftdownx,ypos,rightdownx,ypos);
00352             };   
00353         };
00354         
00355         //Brisanje granicnika. Vodi se racuna ako je granica neki od dekadnih podeoka koji treba da ostane crn.
00356         if(V%10!=0){
00357             lcd.DrawLine(x1,y1,x2,y2);
00358             if (dV<0){
00359                 lcd.DrawPixel(x1,y1,LCD_COLOR_BLACK);
00360                 lcd.DrawPixel(x2,y2,LCD_COLOR_BLACK);
00361             };
00362         };
00363         V+=dV/abs(dV);
00364     };
00365 };
00366 
00367 void ChangeCrank(int Crank){
00368     PrintString("     ",50,350,400,LCD_COLOR_GREEN);
00369     if (Crank){
00370         PrintString("ERROR",50,CrankXPos,CrankYPos,LCD_COLOR_RED);
00371         lcd.SetTextColor(LCD_COLOR_BLACK);
00372     } else {
00373         PrintString("OK",50,CrankXPos,CrankYPos,LCD_COLOR_GREEN);
00374         lcd.SetTextColor(LCD_COLOR_BLACK);
00375     };  
00376 };
00377 
00378 int UpdateCapBar(int H, int H0, uint16_t StartXPos, uint16_t StartYPos){
00379     uint16_t BarWidth = 200, BarHeight = 300;
00380     int YPos = StartYPos + BarHeight;
00381     int percent = 3;
00382     int dH = abs(H-H0);
00383     int Hmax = 100;
00384     
00385     if(dH > 0){
00386         lcd.SetTextColor(LCD_COLOR_GREEN);
00387         lcd.FillRect(StartXPos,StartYPos + (Hmax-H)*percent,BarWidth,dH*percent);
00388     }else{
00389         lcd.SetTextColor(LCD_COLOR_WHITE);
00390         lcd.FillRect(StartXPos,StartYPos + (Hmax-H0)*percent,BarWidth,dH*percent);
00391     };
00392     lcd.SetTextColor(LCD_COLOR_BLACK);
00393 };        
00394 
00395 int UpdateLVDTScale(int H,int H0, uint16_t StartXPos, uint16_t StartYPos){
00396     uint16_t BarWidth=80,BarHeight=8;
00397     int YPos;
00398     int D,D0,dD;
00399 
00400     switch( ((H>=0)<<1)+(H0>0)){
00401         case(0):
00402             D=5-abs(H)/20;
00403             D0=5-abs(H0)/20;
00404             break;
00405         case(1):
00406             D=5-abs(H)/20;
00407             D0=H0/20+5;
00408             break;
00409         case(2):
00410             D=H/20+5;
00411             D0=5-abs(H0)/20;
00412             break;             
00413         case(3):
00414             D=H/20+5;
00415             D0=H0/20+5;
00416             break;
00417     };
00418     dD=D-D0;
00419     
00420     if (dD>0){
00421         lcd.SetTextColor(LCD_COLOR_BLACK);
00422         YPos=StartYPos-10*(D0+1);
00423     }else{
00424         lcd.SetTextColor(LCD_COLOR_WHITE);
00425         YPos=StartYPos-D0*10;
00426     };
00427     for (int k=1;k<=abs(dD);k++){
00428         lcd.FillRect(StartXPos,YPos,BarWidth,BarHeight);
00429         YPos-=10*(dD/abs(dD));
00430     };
00431     lcd.SetTextColor(LCD_COLOR_BLACK);
00432     return 1;
00433 };
00434     
00435 
00436 void BrakeSignal(uint16_t brake){
00437     if (brake!=0){
00438         lcd.SetTextColor(LCD_COLOR_RED);
00439         lcd.SetBackColor(LCD_COLOR_RED);
00440         lcd.FillRect(560,340,230,68);
00441         PrintString("BRAKE",50,575,350,LCD_COLOR_BLACK);
00442     }else {
00443         lcd.SetTextColor(LCD_COLOR_DARKRED);
00444         lcd.SetBackColor(LCD_COLOR_DARKRED);
00445         lcd.FillRect(560,340,230,68);
00446         PrintString("BRAKE",50,575,350,LCD_COLOR_BLACK);
00447     };
00448     lcd.SetBackColor(LCD_COLOR_WHITE);
00449 };
00450         
00451 
00452 void TestFont(){
00453     uint16_t XPos=0,YPos=120;
00454     for(int k=0;k<68;k++){
00455         PrintChar(*font50[k],XPos,YPos,lcd.GetTextColor());
00456         XPos=XPos+(*font50[k]).width;
00457         wait(0.1);
00458         //pc.printf("%d",k);
00459     };
00460 };
00461 
00462 void DrawBatTempMap(){
00463     
00464     uint8_t segment_num = 5;
00465     uint8_t segment_distance = 20;
00466     uint8_t StartXPos = 20, StartYPos = 20;
00467     uint8_t column_num = 2;
00468     uint8_t row_num = 7;
00469     uint8_t cell_width = 60;
00470     uint8_t cell_height = 50;
00471     uint16_t x1,y1,x2,y2;
00472     uint32_t color;
00473     uint16_t R,G,B;
00474     uint16_t BarXPos = 720, BarYPos = 20, ColorBar_width = 20, ColorBar_height = 6;
00475     
00476     lcd.SetTextColor(LCD_COLOR_BLACK);
00477     PrintString("S1",50,50,380,LCD_COLOR_BLACK);
00478     PrintString("S2",50,190,380,LCD_COLOR_BLACK);
00479     PrintString("S3",50,330,380,LCD_COLOR_BLACK);
00480     PrintString("S4",50,470,380,LCD_COLOR_BLACK);
00481     PrintString("S5",50,610,380,LCD_COLOR_BLACK);
00482     
00483     for (uint8_t p = 0 ; p < segment_num ; p++){
00484         x1 = StartXPos+p*(segment_distance+2*cell_width);
00485         y1 = StartYPos;
00486         x2 = x1;
00487         y2 = StartYPos+row_num*cell_height;
00488         lcd.DrawLine(x1,y1,x2,y2);
00489         x1 = x1 + cell_width;
00490         x2 = x1;
00491         lcd.DrawLine(x1,y1,x2,y2);
00492         x1 = x1 + cell_width;
00493         x2 = x1;
00494         lcd.DrawLine(x1,y1,x2,y2);
00495         x1 = StartXPos+p*(segment_distance+2*cell_width);
00496         x2 = x1 + 2*cell_width;
00497         y1 = StartYPos;
00498         y2 = y1;
00499         
00500         for(uint8_t q = 0 ; q <= row_num ; q++){
00501             y1 = StartYPos + q*cell_height;
00502             y2 = y1;
00503             lcd.DrawLine(x1,y1,x2,y2);
00504         };
00505     };
00506     
00507     for(uint8_t temp = 10 ; temp <=70; temp++){
00508         lcd.SetTextColor(TempColor(temp));
00509         x1 = BarXPos;
00510         y1 = BarYPos + 360 - (temp-10)*ColorBar_height;
00511         lcd.FillRect(x1,y1,ColorBar_width,ColorBar_height);
00512         //pc.printf("%d %d %d %d\n",x1,y1,x2,y2);
00513     };
00514     lcd.SetTextColor(LCD_COLOR_BLACK);
00515     lcd.DisplayStringAt(BarXPos+25,BarYPos,(uint8_t*)"70",LEFT_MODE);
00516     lcd.DisplayStringAt(BarXPos+25,BarYPos+60,(uint8_t*)"60",LEFT_MODE);
00517     lcd.DisplayStringAt(BarXPos+25,BarYPos+120,(uint8_t*)"50",LEFT_MODE);
00518     lcd.DisplayStringAt(BarXPos+25,BarYPos+180,(uint8_t*)"40",LEFT_MODE);
00519     lcd.DisplayStringAt(BarXPos+25,BarYPos+240,(uint8_t*)"30",LEFT_MODE);
00520     lcd.DisplayStringAt(BarXPos+25,BarYPos+300,(uint8_t*)"20",LEFT_MODE);
00521     lcd.DisplayStringAt(BarXPos+25,BarYPos+360,(uint8_t*)"10",LEFT_MODE);
00522     
00523 };
00524 
00525 void UpdateBatTempMap(){
00526     uint8_t column,row;
00527     
00528     for (uint8_t cell = 1 ; cell <= 70 ; cell++ ){
00529         if (Acc_Temperature[cell] != Acc_Temperature0[cell]){
00530             column = cell/7 + 1;
00531             row = cell%7;
00532             if (row == 0){
00533                 column = column - 1;
00534                 row = 7;
00535             };
00536             pc.printf("column %d row %d \n",column,row);
00537             UpdateCellTemp(column,row,Acc_Temperature[cell]);
00538             Acc_Temperature0[cell] = Acc_Temperature[cell];
00539         };
00540     };
00541 };
00542 
00543 uint32_t TempColor(uint8_t temperature){
00544     //tmin = 10 tmax = 70
00545     uint8_t tmin = 10, tmax = 70;
00546     uint32_t k = temperature - 10;
00547     uint32_t R,G,B;
00548     uint32_t color;
00549     
00550     if (k < 20){
00551         R = 0;
00552         G = 0xFF;
00553         B = 0xFF*k/20;
00554         if (k< 0){
00555             B = 0;
00556         };
00557     }
00558     else if(k < 40){
00559         R = 0xFF*(k-20)/20;
00560         G = 0xFF*(40-k)/20;
00561         B = 0xFF;
00562     }
00563     else if(k<60){
00564         R = 0xFF;
00565         G = 0;
00566         B = 0xFF*(60-k)/20;
00567     }
00568     else{
00569         R = 0xFF;
00570         G = 0;
00571         B = 0;
00572     };
00573     color = (0xFF << 24) + (R << 16) + (G << 8) + B;
00574     //color = 0xFF000000 + R*65536 + G*256 + B;
00575     return color;
00576 };
00577 
00578 void UpdateCellTemp(uint8_t column, uint8_t row, uint8_t temp){
00579     uint8_t segment_num = 5;
00580     uint8_t segment_distance = 20;
00581     uint8_t StartXPos = 20, StartYPos = 20;
00582     uint8_t column_num = 2;
00583     uint8_t row_num = 7;
00584     uint8_t cell_width = 60;
00585     uint8_t cell_height = 50;
00586     uint16_t x,y;
00587      
00588     switch(column){
00589         case (1):
00590             x = StartXPos; 
00591             break;
00592         case (2):
00593             x = StartXPos + cell_width;
00594             break;
00595         case (3):
00596             x = StartXPos + 2*cell_width + segment_distance;
00597             break;
00598         case (4):
00599             x = StartXPos + 3*cell_width + segment_distance;
00600             break;
00601         case (5):
00602             x = StartXPos + 4*cell_width + 2*segment_distance;
00603             break;
00604         case (6):
00605             x = StartXPos + 5*cell_width + 2*segment_distance;
00606             break;
00607         case (7):
00608             x = StartXPos + 6*cell_width + 3*segment_distance;
00609             break;
00610         case (8):
00611             x = StartXPos + 7*cell_width + 3*segment_distance;
00612             break;
00613         case (9):
00614             x = StartXPos + 8*cell_width + 4*segment_distance;
00615             break;
00616         case (10):
00617             x = StartXPos + 9*cell_width + 4*segment_distance;
00618             break;
00619     };
00620     y = StartYPos + (row - 1)*cell_height;
00621     lcd.SetTextColor(TempColor(temp));
00622     lcd.FillRect(x+1, y+1, cell_width - 2, cell_height - 2);
00623 };
00624 
00625 void SetFixedAccTemp(){
00626     Acc_Temperature[1] = 28;
00627     Acc_Temperature[2] = 28;
00628     Acc_Temperature[3] = 29;
00629     Acc_Temperature[4] = 28;
00630     Acc_Temperature[5] = 29;
00631     Acc_Temperature[6] = 30;
00632     Acc_Temperature[7] = 28;
00633     Acc_Temperature[8] = 28;
00634     Acc_Temperature[9] = 29;
00635     Acc_Temperature[10] = 30;
00636     Acc_Temperature[11] = 30;
00637     Acc_Temperature[12] = 32;
00638     Acc_Temperature[13] = 30;
00639     Acc_Temperature[14] = 29;
00640     Acc_Temperature[15] = 29;
00641     Acc_Temperature[16] = 31;
00642     Acc_Temperature[17] = 30;
00643     Acc_Temperature[18] = 31;
00644     Acc_Temperature[19] = 30;
00645     Acc_Temperature[20] = 33;
00646     Acc_Temperature[21] = 30;
00647     Acc_Temperature[22] = 31;
00648     Acc_Temperature[23] = 32;
00649     Acc_Temperature[24] = 33;
00650     Acc_Temperature[25] = 33;
00651     Acc_Temperature[26] = 35;
00652     Acc_Temperature[27] = 34;
00653     Acc_Temperature[28] = 34;
00654     Acc_Temperature[29] = 32;
00655     Acc_Temperature[30] = 33;
00656     Acc_Temperature[31] = 33;
00657     Acc_Temperature[32] = 35;
00658     Acc_Temperature[33] = 34;
00659     Acc_Temperature[34] = 32;
00660     Acc_Temperature[35] = 33;
00661     Acc_Temperature[36] = 36;
00662     Acc_Temperature[37] = 36;
00663     Acc_Temperature[38] = 38;
00664     Acc_Temperature[39] = 39;
00665     Acc_Temperature[40] = 39;
00666     Acc_Temperature[41] = 38;
00667     Acc_Temperature[42] = 37;
00668     Acc_Temperature[43] = 33;
00669     Acc_Temperature[44] = 34;
00670     Acc_Temperature[45] = 33;
00671     Acc_Temperature[46] = 33;
00672     Acc_Temperature[47] = 32;
00673     Acc_Temperature[48] = 33;
00674     Acc_Temperature[49] = 34;
00675     Acc_Temperature[50] = 34;
00676     Acc_Temperature[51] = 35;
00677     Acc_Temperature[52] = 33;
00678     Acc_Temperature[53] = 34;
00679     Acc_Temperature[54] = 34;
00680     Acc_Temperature[55] = 35;
00681     Acc_Temperature[56] = 35;
00682     Acc_Temperature[57] = 33;
00683     Acc_Temperature[58] = 33;
00684     Acc_Temperature[59] = 37;
00685     Acc_Temperature[60] = 32;
00686     Acc_Temperature[61] = 34;
00687     Acc_Temperature[62] = 34;
00688     Acc_Temperature[63] = 33;
00689     Acc_Temperature[64] = 34;
00690     Acc_Temperature[65] = 36;
00691     Acc_Temperature[66] = 35;
00692     Acc_Temperature[67] = 35;
00693     Acc_Temperature[68] = 35;
00694     Acc_Temperature[69] = 34;
00695     Acc_Temperature[70] = 34;
00696     
00697 };