CircleOS  1
draw.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2013 KEOLABS S.A.S. ********************/
13 /******************************************************************************/
14 
15 /* Includes ------------------------------------------------------------------*/
16 #include "circle.h"
17 
19 
20 /* Private define ------------------------------------------------------------*/
21 #define ROTATE_DIVIDER 127
22 
23 #define abs(X) ( ( (X) < 0 ) ? -(X) : (X) )
24 #define sgn(X) ( ( (X) < 0 ) ? -1 : 1 )
25 
26 
27 /* Private variables ---------------------------------------------------------*/
28 mag_t CharMagniCoeff = 1; // !< Current character magnify coefficient
29 color_t BGndColor = RGB_WHITE; // !< Current background color
30 color_t TextColor = RGB_BLACK; // !< Current text color
31 
32 coord_t PosCurX = 0; // !< Current cursor X position
33 coord_t PosCurY = 0; // !< Current cursor Y position
34 
35 coord_t LeftMarginX = 0; // !< Current left margin in X
36 coord_t RightMarginX = APP_SCREEN_WIDTH; // !< Current right margin in X
37 coord_t HighMarginY = APP_SCREEN_HEIGHT; // !< Current high margin in Y
38 coord_t LowMarginY = 0; // !< Current low margin in Y
39 
40 bool fDisplayTime = 0;
41 u16 BatState;
42 u16 OldBatState;
43 s16 OldTemp = -1; // Stores current temperature
44 
45 coord_t xBat;
46 coord_t yBat;
47 coord_t widthBat;
48 coord_t heightBat;
49 
50 divider_t divider_coord = 0;
51 
52 /* Screen orientation management*/
53 divider_t rotate_counter = 0;
54 
55 /*Initialise the direction to +4 at reset (that forces a redraw)*/
56 Rotate_H12_V_Match_TypeDef previous_orient = V12;
57 Rotate_H12_V_Match_TypeDef previous_previous_orient = V12;
58 Rotate_H12_V_Match_TypeDef new_orient = V12;
59 Rotate_H12_V_Match_TypeDef CurrentScreenOrientation = V12;
60 bool CurrentRotateScreen = 1;
61 
62 /* Extern variables ----------------------------------------------------------*/
63 extern coord_t XInit;
64 extern coord_t YInit;
65 
66 /* Private functions ---------------------------------------------------------*/
67 void DRAW_Clear_Text( coord_t x, coord_t y, len_t len, bool mode );
68 
69 /*******************************************************************************
70 *
71 * DRAW_Clear_Text
72 *
73 *******************************************************************************/
90 /******************************************************************************/
91 void DRAW_Clear_Text( coord_t x, coord_t y, len_t len, bool mode )
92 {
93  len_t i;
94  coord_t ref_x = x;
95 
96  /* Display each character on LCD */
97  for ( i = 0 ; i < len ; i++ )
98  {
99  /* Display one character on LCD */
100  LCD_DisplayChar( ref_x, y, ' ', mode ? BGndColor : TextColor, mode ? TextColor : BGndColor, CharMagniCoeff );
101 
102  /* Increment the column position by character width */
103  ref_x += ( Char_Width * CharMagniCoeff );
104  }
105 }
106 
107 
108 /* Public functions for CircleOS ---------------------------------------------*/
109 
110 /*******************************************************************************
111 *
112 * DRAW_Init
113 *
114 *******************************************************************************/
122 /******************************************************************************/
123 NODEBUG void DRAW_Init( void )
124 {
125 
126 #if MEMS_POINTER // Not necessary if no MEMS menu handling
127  MEMS_GetRotation( &CurrentScreenOrientation );
128 #endif
129 
130  LCD_SetScreenOrientation( CurrentScreenOrientation );
131 
132  xBat = Screen_Width - 30;
133  yBat = 3;
134  OldBatState = 10;
135  PosCurY = Screen_Height - Char_Height;
136  RightMarginX = Screen_Width;
137  HighMarginY = Screen_Height;
138 
139  /* Clear LCD and draw black and white logo*/
141  DRAW_Clear();
142  LCD_Batt( xBat, yBat, fDisplayTime, BatState, &OldBatState, divider_coord, &widthBat, &heightBat );
143  POINTER_Init();
144 }
145 
146 /*******************************************************************************
147 *
148 * DRAW_Handler
149 *
150 *******************************************************************************/
158 /******************************************************************************/
159 void DRAW_Handler( void )
160 {
161 
162  BatState = UTIL_GetBat();
163  LCD_Batt( xBat, yBat, fDisplayTime, BatState, &OldBatState, divider_coord, &widthBat, &heightBat );
164 
165 #if MEMS_POINTER // Not necessary if no MEMS menu handling
166  /* Rotate LCD screen*/
167  if ( LCD_GetRotateScreen() )
168  {
169  rotate_counter++;
170 
171  if ( rotate_counter == ROTATE_DIVIDER )
172  {
173  MEMS_GetRotation( &new_orient );
174 
175  if ( new_orient != previous_previous_orient )
176  {
177  if ( ( new_orient == previous_orient ) && ( new_orient != CurrentScreenOrientation ) )
178  {
179  CurrentScreenOrientation = new_orient;
180  LCD_SetScreenOrientation( CurrentScreenOrientation );
181  MEMS_GetPosition( &XInit, &YInit );
182 #if TOUCHSCREEN_AVAIL
183  TOOLBAR_RedrawToolbar( TOOLBAR_REDRAW );
184  TOOLBAR_Handler();
185 #endif
186  DRAW_Clear();
187  if ( CurrentMenu != 0 )
188  {
189  MENU_Set( CurrentMenu );
190  }
191  }
192  }
193 
194  previous_previous_orient = previous_orient;
195  previous_orient = new_orient;
196  rotate_counter = 0;
197  }
198  }
199 #endif
200 
201 #if DMA2D_AVAIL
202  DMA_LCD_UpdateScreen();
203 #endif
204 
205 }
206 
207 /*******************************************************************************
208 *
209 * DRAW_Batt
210 *
211 *******************************************************************************/
217 /******************************************************************************/
218 NODEBUG2 void DRAW_Batt( void )
219 {
220  widthBat = 24;
221  heightBat = 8;
222 
223  LCD_FillRect_Circle( xBat, yBat, widthBat, heightBat, RGB_BLUE );
224  LCD_FillRect_Circle( xBat + 1 , yBat + 1 , widthBat - 2 , heightBat - 2 , RGB_WHITE );
225 
226  widthBat = 2;
227  heightBat = 4;
228 
229  LCD_FillRect_Circle( xBat - 2 , yBat + 2 , widthBat , heightBat, RGB_BLUE );
230  LCD_FillRect_Circle( xBat - 1 , yBat + 3 , widthBat - 1 , heightBat - 2 , RGB_WHITE );
231 }
232 
233 
234 /*******************************************************************************
235 *
236 * DRAW_Line_Circle
237 *
238 *******************************************************************************/
252 /******************************************************************************/
253 NODEBUG2 void DRAW_Line_Circle( coord_t x1, coord_t y1, coord_t x2, coord_t y2, color_t color )
254 {
255  s16 i;
256  coord_t dx, dy;
257  coord_t dxabs, dyabs;
258  coord_t sdx, sdy;
259  coord_t x, y;
260  coord_t px, py;
261 
262  dx = x2 - x1; /* the horizontal distance of the line */
263 
264  if ( dx == 0 ) /* Vertical Line*/
265  {
266  if ( y1 > y2 ) /* We assume y2>y1 and invert if not*/
267  {
268  i = y2;
269  y2 = y1;
270  y1 = i;
271  }
272  LCD_FillRect_Circle( x1, y1, 1, y2 - y1 + 1, color );
273  return;
274  }
275 
276  dy = y2 - y1; /* the vertical distance of the line */
277 
278  if ( dy == 0 ) /* Horizontal Line*/
279  {
280  if ( x1 > x2 ) /* We assume x2>x1 and we swap them if not*/
281  {
282  i = x2;
283  x2 = x1;
284  x1 = i;
285  }
286  LCD_FillRect_Circle( x1, y1, x2 - x1 + 1, 1, color );
287  return;
288  }
289 
290  dxabs = abs( dx );
291  dyabs = abs( dy );
292  sdx = sgn( dx );
293  sdy = sgn( dy );
294  x = dyabs >> 1;
295  y = dxabs >> 1;
296  px = x1;
297  py = y1;
298 
299  if ( dxabs >= dyabs ) /* the line is more horizontal than vertical */
300  {
301  for ( i = 0; i < dxabs; i++ )
302  {
303  y += dyabs;
304  if ( y >= dxabs )
305  {
306  y -= dxabs;
307  py += sdy;
308  }
309  px += sdx;
310  LCD_DrawPixel( px, py, color );
311  }
312  }
313  else /* the line is more vertical than horizontal */
314  {
315  for ( i = 0; i < dyabs; i++ )
316  {
317  x += dxabs;
318  if ( x >= dyabs )
319  {
320  x -= dyabs;
321  px += sdx;
322  }
323  py += sdy;
324  LCD_DrawPixel( px, py, color );
325  }
326  }
327 }
328 
329 /******************************************************************************
330 *
331 * DRAW_RestoreCharMagniCoeff
332 *
333 *******************************************************************************/
339 /******************************************************************************/
340 NODEBUG2 void DRAW_RestoreCharMagniCoeff( void )
341 {
342 #if LCD_HIGH_DEF
344 #else
346 #endif
347 }
348 
349 /*******************************************************************************
350 *
351 * DRAW_Cross_Absolute
352 *
353 *******************************************************************************/
361 /******************************************************************************/
362 NODEBUG2 void DRAW_Cross_Absolute( coord_t x1, coord_t y1, color_t color, u16 CrossSize )
363 {
364  DRAW_Line( x1 - CrossSize, y1, x1 + CrossSize, y1, color );
365  DRAW_Line( x1, y1 - CrossSize, x1, y1 + CrossSize, color );
366 }
367 
368 /*******************************************************************************
369 *
370 * DRAW_DisplayTemp
371 *
372 *******************************************************************************/
386 /******************************************************************************/
387 NODEBUG2 void DRAW_DisplayTemp( coord_t x, coord_t y )
388 {
389  s16 Temp;
390  u8 c;
391  u16 r = 0;
392  char TempTextBuffer[6];
393  bool firstTime = 0;
394 
395  if ( OldTemp == -1 )
396  {
397  /* Get the intial value */
398  Temp = OldTemp = UTIL_GetTemp();
399  firstTime = 1;
400  }
401  else
402  {
403  /* Get Time and filter it with the previous value*/
404  Temp = ( UTIL_GetTemp() + OldTemp * 7 ) / 8;
405  OldTemp = Temp;
406  }
407 
408  // Display value if changed or first call
409  if ( ( Temp != OldTemp ) || firstTime )
410  {
411  // Display modified temperature
412  /* 1 000 digit*/
413  c = ( ( Temp - r ) / 100 );
414  r = r + ( c * 100 );
415  TempTextBuffer[0] = c + 0x30;
416 
417  /* 100 digit*/
418  c = ( ( Temp - r ) / 10 );
419  r = r + ( c * 10 );
420  TempTextBuffer[1] = c + 0x30;
421 
422  /* Dot*/
423  TempTextBuffer[2] = '.';
424 
425  /* 10 digit*/
426  c = ( ( Temp - r ) );
427  TempTextBuffer[3] = c + 0x30;
428 
429  /* Volt*/
430  TempTextBuffer[4] = fTemperatureInFahrenheit ? 'F' : 'C';
431  TempTextBuffer[5] = 0;
432 
433  DRAW_DisplayString( x, y, TempTextBuffer, 5 );
434  }
435 }
436 
437 /*******************************************************************************
438 *
439 * DRAW_GetIndexedColorBMP
440 *
441 *******************************************************************************/
452 /******************************************************************************/
453 NODEBUG2 color_t DRAW_GetIndexedColorBMP( u8* color_table, u16 i )
454 {
455  color_t color;
456  color = ( color_table[i] & 0x1c ) << 11; //green (low)
457  color |= ( color_table[i + 1] & 0xf8 ) << 5; //blue
458  color |= ( color_table[i + 3] & 0xf8 ); //red
459  color |= ( color_table[i] & 0xe0 ) >> 5; //green (high)
460  return color;
461 }
462 
463 
465 
466 /* Public functions ----------------------------------------------------------*/
467 
468 /*******************************************************************************
469 *
470 * DRAW_SetCharMagniCoeff
471 *
472 *******************************************************************************/
480 /******************************************************************************/
481 void DRAW_SetCharMagniCoeff( mag_t Coeff )
482 {
483  CharMagniCoeff = Coeff;
484 }
485 
486 /******************************************************************************
487 *
488 * DRAW_GetCharMagniCoeff
489 *
490 *******************************************************************************/
498 /******************************************************************************/
500 {
501  return CharMagniCoeff;
502 }
503 
504 /******************************************************************************
505 *
506 * DRAW_GetTextColor
507 *
508 *******************************************************************************/
516 /******************************************************************************/
517 color_t DRAW_GetTextColor( void )
518 {
519  return TextColor;
520 }
521 
522 /*******************************************************************************
523 *
524 * DRAW_SetTextColor
525 *
526 *******************************************************************************/
534 /******************************************************************************/
535 void DRAW_SetTextColor( color_t Color )
536 {
537  TextColor = Color ;
538 }
539 
540 /*******************************************************************************
541 *
542 * DRAW_GetBGndColor
543 *
544 *******************************************************************************/
552 /******************************************************************************/
553 color_t DRAW_GetBGndColor( void )
554 {
555  return BGndColor;
556 }
557 
558 /*******************************************************************************
559 *
560 * DRAW_SetBGndColor
561 *
562 *******************************************************************************/
570 /******************************************************************************/
571 void DRAW_SetBGndColor( color_t Color )
572 {
573  BGndColor = Color;
574 }
575 
576 /*******************************************************************************
577 *
578 * DRAW_Clear
579 *
580 *******************************************************************************/
586 /******************************************************************************/
587 void DRAW_Clear( void )
588 {
589  enum POINTER_mode ptr_bak = POINTER_GetMode() ;
590 
592  if ( ( LCD_GetScreenOrientation() % 2 ) == 1 )
593  LCD_FillRect_Circle( 0, 0, Screen_Height, Screen_Width, BGndColor );
594  else
595  LCD_FillRect_Circle( 0, 0, Screen_Width, Screen_Height, BGndColor );
596 
597  if ( ( CurrentMenu == 0 ) && ( CurrentCommand == 0 )
599  {
601  DRAW_SetLogoBW();
602  LCD_Clear( xBat, yBat );
603 
604  OldBatState = 10;
605  OldTemp = -1;
606  fDisplayTime = 1;
607  }
608 
609  POINTER_SetMode( ptr_bak );
610 }
611 
612 /*******************************************************************************
613 *
614 * DRAW_SetLogoBW
615 *
616 *******************************************************************************/
622 /******************************************************************************/
623 void DRAW_SetLogoBW( void )
624 {
625  LCD_SetLogoBW();
626 }
627 
628 /*******************************************************************************
629 *
630 * DRAW_SetImage
631 *
632 *******************************************************************************/
648 /******************************************************************************/
649 void DRAW_SetImage( const color_t* imageptr, coord_t x, coord_t y, coord_t width, coord_t height )
650 {
651  DRAW_SetImageSel( imageptr, x, y, width, height, 0xFFFF, 0xFFFF );
652 }
653 
654 /*******************************************************************************
655 *
656 * DRAW_SetImageSel
657 *
658 *******************************************************************************/
677 /******************************************************************************/
678 void DRAW_SetImageSel( const color_t* imageptr, coord_t x, coord_t y, coord_t width, coord_t height, color_t oldBgndColor, color_t newBgndColor )
679 {
680  s32 j;
681  coord_t i, k;
682  color_t color;
683  color_t* imagetemp;
684  u8* color_table;
685  Rotate_H12_V_Match_TypeDef OrientationSave;
686 
687  if ( imageptr )
688  {
689  j = width * height; // pixel counter
690  //TODO ASSERT((u32)width * height < 0xFFFF); // Ensure i can be a short
691 
692  // BMP header test
693  if ( ( imageptr[0] == 0x424D ) && ( imageptr[3] == 0 ) )
694  {
695  // Regular BMP file
696  OrientationSave = LCD_GetScreenOrientation();
697  imagetemp = ( color_t* )( imageptr ) + ( imageptr[5] >> 9 ) + ( ( imageptr[5] & 0xff ) << 7 ) ; // Offset of the image (header size)
698 
699  LCD_SetScreenOrientation( OrientationSave + 4 ); // Change to V*BMP orientation
700  LCD_SetRect_For_Cmd( x, y, width, height );
701  LCD_SendLCDCmd_RAM_Access();
702 
703  switch ( ( ( imageptr[14] >> 8 ) + ( imageptr[15] & 0xff00 ) ) ) // colour depth + compression methode
704  {
705  case 0x0010: // 16 bits and no compression
706  case 0x0310:
707  imageptr += 0x36;
708  for ( i = 0; i < j ; i++ )
709  {
710  if ( imageptr[i] != oldBgndColor )
711  {
712  LCD_SendLCDData( imageptr[i] & 0xff );
713  LCD_SendLCDData( ( imageptr[i] >> 8 ) & 0xff );
714  }
715  else
716  {
717  LCD_SendLCDData( newBgndColor & 0xff );
718  LCD_SendLCDData( ( newBgndColor >> 8 ) & 0xff );
719  }
720  }
721  break;
722 
723  case 0x0008: // 8 bits (256 colors) and no compression
724  color_table = ( u8* )imageptr + 0x36;
725  for ( i = 0; ( 2 * i ) < j ; i++ )
726  {
727  color = DRAW_GetIndexedColorBMP( color_table, 4 * ( imagetemp[i] >> 8 ) );
728  if ( color == oldBgndColor )
729  color = newBgndColor;
730  LCD_SendLCDData( color & 0xff );
731  LCD_SendLCDData( ( color >> 8 ) & 0xff );
732  color = DRAW_GetIndexedColorBMP( color_table, 4 * ( imagetemp[i] & 0xff ) );
733  LCD_SendLCDData( color & 0xff );
734  LCD_SendLCDData( ( color >> 8 ) & 0xff );
735  }
736  break;
737 
738  case 0x0108: // 8 bits (256 colors) and RLE compression
739  color_table = ( u8* )imageptr + 0x36;
740  i = 0; // file cursor (in words)
741  while ( j > 0 ) // while there is still pixels to write (j : amount of remaining pixels)
742  {
743 
744  if ( ( imagetemp[i] >> 8 ) == 0 )
745  {
746  k = imagetemp[i] & 0xff;
747  i++; // move the file cursor
748 
749  if ( k == 0 ) // End of line
750  {
751  color = newBgndColor;
752  while ( ( j % width ) != 0 ) // fill with the background color to the end of line
753  {
754  j--; // remove each pixel from the pixel counter
755  LCD_SendLCDData( color & 0xff );
756  LCD_SendLCDData( ( color >> 8 ) & 0xff );
757  }
758  }
759 
760  else if ( k == 1 ) // End of file
761  break;
762  else
763  {
764  // If not either end of file or end of line : streak of single values
765  // in this case k is the length of the streak
766  j -= k ; // remove the streak length from the pixel counter
767  while ( k > 0 )
768  {
769  color = DRAW_GetIndexedColorBMP( color_table , 4 * ( imagetemp[i] >> 8 ) );
770  LCD_SendLCDData( color & 0xff );
771  LCD_SendLCDData( ( color >> 8 ) & 0xff );
772  k--;
773  if ( k > 0 )
774  {
775  color = DRAW_GetIndexedColorBMP( color_table , 4 * ( imagetemp[i] & 0xff ) );
776  if ( color == oldBgndColor ) // if the color should be replaced
777  color = newBgndColor;
778  LCD_SendLCDData( color & 0xff );
779  LCD_SendLCDData( ( color >> 8 ) & 0xff );
780  k--;
781  }
782  i++; // move the file cursor
783  }
784  }
785  } // End of : if ( (imagetemp[i]>>8) == 0 )
786  else
787  {
788  // Streak of same values
789  color = DRAW_GetIndexedColorBMP( color_table , 4 * ( imagetemp[i] & 0xff ) );
790  if ( color == oldBgndColor ) // if the color should be replaced
791  color = newBgndColor;
792  k = imagetemp[i] >> 8; // length of the streak
793  j -= k; // remove the streak length from the pixel counter
794  for ( ; k > 0 ; k-- )
795  {
796  LCD_SendLCDData( color & 0xff );
797  LCD_SendLCDData( ( color >> 8 ) & 0xff );
798  }
799  i++; // move the file cursor
800  }
801  } // End of : while ( j > 0 )
802  break;
803 
804  } // End of : switch( ((imageptr[14]>>8) + (imageptr[15]&0xff00)) )
805 
806  /* End of select screen area to access.*/
807  LCD_SendLCDCmd_RAM_Access_End();
808 
809  LCD_SetScreenOrientation( OrientationSave );
810  }
811  else
812  // Non regular BMP file (old Primer format)
813  {
814  /* Select screen area to access.*/
815  LCD_SetRect_For_Cmd( x, y, width, height );
816  LCD_SendLCDCmd_RAM_Access();
817 
818  for ( i = 0; i < j ; i++ )
819  {
820  if ( imageptr[i] != oldBgndColor )
821  {
822  LCD_SendLCDData( imageptr[i] & 0xff );
823  LCD_SendLCDData( ( imageptr[i] >> 8 ) & 0xff );
824  }
825  else
826  {
827  LCD_SendLCDData( newBgndColor & 0xff );
828  LCD_SendLCDData( ( newBgndColor >> 8 ) & 0xff );
829  }
830  }
831  /* End of select screen area to access.*/
832  LCD_SendLCDCmd_RAM_Access_End();
833  }
834  }
835 }
836 
837 /*******************************************************************************
838 *
839 * DRAW_SetImageBW
840 *
841 *******************************************************************************/
858 /******************************************************************************/
859 void DRAW_SetImageBW( const u8* imageptr, coord_t x, coord_t y, coord_t width, coord_t height )
860 {
861  coord_t i, j, k;
862 
863  k = ( width * height ) >> 3;
864 
865  /* Select screen area to access.*/
866  LCD_SetRect_For_Cmd( x, y, width, height );
867 
868  /* Send command to write data on the LCD screen.*/
869  LCD_SendLCDCmd_RAM_Access();
870 
871  /* Loop on all bitmap bytes.*/
872  for ( i = 0; i < k; i++ )
873  {
874  /* Loop on all byte bits.*/
875  for ( j = 0; j < 8; j++ )
876  {
877  /* Bit set: draw pixel with text color.*/
878  if ( imageptr && ( ( ( imageptr[i] ) >> ( 7 - j ) ) & 1 ) )
879  {
880  LCD_SendLCDData( TextColor & 0xff );
881  LCD_SendLCDData( ( TextColor >> 8 ) & 0xff );
882  }
883  else
884  {
885  /* Bit not set: draw pixel with background color.*/
886  LCD_SendLCDData( BGndColor & 0xff );
887  LCD_SendLCDData( ( BGndColor >> 8 ) & 0xff );
888  }
889  }
890  }
891 
892  /* End of select screen area to access.*/
893  LCD_SendLCDCmd_RAM_Access_End();
894 }
895 
896 /*******************************************************************************
897 *
898 * DRAW_DisplayVbat
899 *
900 *******************************************************************************/
911 /******************************************************************************/
912 void DRAW_DisplayVbat( coord_t x, coord_t y )
913 {
914  char text[17];
915  char* p = text;
916  u16 vbat = UTIL_GetBat();
917 
918  *p++ = 'B';
919  *p++ = 'A';
920  *p++ = 'T';
921  *p++ = '=';
922 
923  /* Translate vbat into p.*/
924  vbattoa( p, vbat );
925 
926  /* Display text at the provided coordinates.*/
927  DRAW_DisplayString( x, y, text, 10 );
928 }
929 
930 /*******************************************************************************
931 *
932 * DRAW_DisplayTime
933 *
934 *******************************************************************************/
945 /******************************************************************************/
946 void DRAW_DisplayTime( coord_t x, coord_t y )
947 {
948  u8 THH;
949  u8 TMM;
950  u8 TSS;
951  static u8 OldTHH = 100;
952  static u8 OldTMM = 100;
953  static u8 OldTSS = 100;
954 
955  static char TimeTextBuffer[9]; // Trailing '\0' is NOT included
956 
957  /* Get Time*/
958  RTC_GetTime( &THH, &TMM, &TSS );
959 
960  /* Update time display if seconds have changed */
961  if ( THH != OldTHH )
962  {
963  OldTHH = THH;
964  UTIL_uint2str( &TimeTextBuffer[0], OldTHH, 2, 1 );
965  TimeTextBuffer[2] = ':';
966  }
967  if ( TMM != OldTMM )
968  {
969  OldTMM = TMM;
970  UTIL_uint2str( &TimeTextBuffer[3], OldTMM, 2, 1 );
971  TimeTextBuffer[5] = ':';
972  }
973  if ( TSS != OldTSS )
974  {
975  OldTSS = TSS;
976  UTIL_uint2str( &TimeTextBuffer[6], OldTSS, 2, 1 );
977  TimeTextBuffer[8] = '\0';
978  DRAW_DisplayString( x , y, TimeTextBuffer, 8 );
979  }
980 }
981 
982 /*******************************************************************************
983 *
984 * DRAW_DisplayStringWithMode
985 *
986 *******************************************************************************/
1010 /******************************************************************************/
1011 void DRAW_DisplayStringWithMode( coord_t x, coord_t y, char* ptr, len_t len, bool mode, enumset_t align )
1012 {
1013  coord_t ref_x;
1014  coord_t lx;
1015  len_t i;
1016  len_t lgc;
1017  u8 CharWidth;
1018  u16 Display_Width;
1019 
1020  // Swap the max coordinates according to the orientation
1021  if ( ( LCD_GetScreenOrientation() % 2 ) == 1 )
1022  {
1023  Display_Width = Screen_Height;
1024  }
1025  else
1026  {
1027  Display_Width = Screen_Width;
1028  }
1029 
1030  // Check the length validity
1031  if ( len == 0 )
1032  len = my_strlen( ptr );
1033  if ( len == ALL_SCREEN )
1034  len = Display_Width / ( Char_Width * CharMagniCoeff );
1035 
1036  // Check and limit the length of the string to display
1037  CharWidth = Char_Width * CharMagniCoeff;
1038  lx = x + ( len * CharWidth );
1039  if ( lx > Display_Width )
1040  {
1041  if ( ( ( lx - Display_Width ) % CharWidth ) == 0 )
1042  len -= ( ( lx - Display_Width ) / CharWidth );
1043  else
1044  len -= ( ( ( lx - Display_Width ) / CharWidth ) + 1 );
1045  }
1046 
1047  // Clear the area
1048  if ( ( Transparency == 0 ) || ( CharMagniCoeff > 3 ) )
1049  DRAW_Clear_Text( x, y, len, mode );
1050 
1051  // Locate the string into the area
1052  ref_x = x;
1053  lgc = my_strlen( ptr );
1054 //YRT130214 move to below
1055 // if ( lgc > len )
1056 // lgc = len;
1057 
1058  switch ( align )
1059  {
1060  case CENTER:
1061  ref_x += (( len - lgc ) * CharWidth ) / 2;
1062  break;
1063  case RIGHT:
1064  if (lgc > len)
1065  {
1066  // YRT130214 : left truncation
1067  for (i = 0 ; i < (lgc - len); i++)
1068  ptr++;
1069  }
1070  else
1071  ref_x += ( len - lgc ) * CharWidth;
1072  break;
1073  case LEFT:
1074  default:
1075  break;
1076  }
1077 
1078  if ( lgc > len )
1079  lgc = len;
1080 
1081  /* Display each character on LCD */
1082  for ( i = 0 ; i < lgc; i++ )
1083  {
1084  /* Display one character on LCD */
1085  LCD_DisplayChar( ref_x, y, *ptr++, mode ? BGndColor : TextColor, mode ? TextColor : BGndColor, CharMagniCoeff );
1086 
1087  /* Increment the column position by CharWidth pixels */
1088  ref_x += CharWidth;
1089  }
1090 }
1091 
1092 /*******************************************************************************
1093 *
1094 * DRAW_DisplayString
1095 *
1096 *******************************************************************************/
1112 /******************************************************************************/
1113 void DRAW_DisplayString( coord_t x, coord_t y, char* ptr, len_t len )
1114 {
1115  DRAW_DisplayStringWithMode( x, y, ptr, len, NORMAL_TEXT, LEFT );
1116 }
1117 
1118 /*******************************************************************************
1119 *
1120 * DRAW_DisplayStringInverted
1121 *
1122 *******************************************************************************/
1138 /******************************************************************************/
1139 void DRAW_DisplayStringInverted( coord_t x, coord_t y, char* ptr, len_t len )
1140 {
1141  //BackGround and Text Colors are inverted
1142  DRAW_DisplayStringWithMode( x, y, ptr, len, INVERTED_TEXT, LEFT );
1143 }
1144 
1145 /*******************************************************************************
1146 *
1147 * DRAW_SetDefaultColor
1148 *
1149 *******************************************************************************/
1155 /******************************************************************************/
1157 {
1158  BGndColor = RGB_WHITE;
1159  TextColor = RGB_BLACK;
1160 }
1161 
1162 
1163 /*******************************************************************************
1164 *
1165 * DRAW_Line
1166 *
1167 *******************************************************************************/
1181 /******************************************************************************/
1182 void DRAW_Line( coord_t x1, coord_t y1, coord_t x2, coord_t y2, color_t color )
1183 {
1184  /* Check the x parameters*/
1185  if ( x1 < 0 )
1186  x1 = 0;
1187  if ( x2 < 0 )
1188  x2 = 0;
1189 
1190  if ( x1 > Screen_Width - 1 )
1191  x1 = Screen_Width - 1;
1192  if ( x2 > Screen_Width - 1 )
1193  x2 = Screen_Width - 1;
1194 
1195  /* Check the y parameters*/
1196  if ( y1 < 0 )
1197  y1 = 0;
1198  if ( y2 < 0 )
1199  y2 = 0;
1200 
1201  if ( y1 > Screen_Height - 1 )
1202  y1 = Screen_Height - 1;
1203  if ( y2 > Screen_Height - 1 )
1204  y2 = Screen_Height - 1;
1205 
1206  /* Call the native function*/
1207  DRAW_Line_Circle( x1, y1, x2, y2, color );
1208 }
1209 
1210 /*******************************************************************************
1211 *
1212 * DRAW_Putc
1213 *
1214 *******************************************************************************/
1229 /******************************************************************************/
1230 void DRAW_Putc( u8 Ascii )
1231 {
1232  u16 Char_Y = Char_Height * CharMagniCoeff;
1233 
1234  /* CRLF ? */
1235  if ( ( Ascii == '\n' ) )
1236  {
1237  PosCurX = LeftMarginX;
1238  if ( PosCurY >= LowMarginY )
1239  {
1240  PosCurY -= Char_Y;
1241  }
1242  return;
1243  }
1244 
1245  /* Line change, if end of line reached*/
1246  if ( ( PosCurX + ( Char_Width * CharMagniCoeff ) ) > RightMarginX )
1247  {
1248  PosCurX = LeftMarginX;
1249  PosCurY -= Char_Y;
1250  }
1251 
1252  /* Normal print if end of screen not reached*/
1253  if ( PosCurY >= LowMarginY )
1254  {
1255  /* Display the selected bitmap according to the provided ASCII character.*/
1256  LCD_DisplayChar( PosCurX, PosCurY, Ascii, TextColor, BGndColor, CharMagniCoeff );
1257  }
1258  else
1259  {
1260  LCD_Scroll( Ascii, PosCurX, &PosCurY, RightMarginX, LeftMarginX, HighMarginY, LowMarginY, BGndColor, TextColor, CharMagniCoeff );
1261  }
1262 
1263  PosCurX += ( Char_Width * CharMagniCoeff );
1264 }
1265 
1266 /*******************************************************************************
1267 *
1268 * DRAW_Puts
1269 *
1270 *******************************************************************************/
1287 /******************************************************************************/
1288 void DRAW_Puts( const u8* ptr )
1289 {
1290  /* Display each character on LCD */
1291  while ( *ptr != 0 )
1292  {
1293  /* Display the character on LCD */
1294  DRAW_Putc( *ptr );
1295 
1296  /* Point to the next character */
1297  ptr++;
1298  }
1299 }
1300 
1301 /*******************************************************************************
1302 *
1303 * DRAW_SetCursorPos
1304 *
1305 *******************************************************************************/
1317 /******************************************************************************/
1318 void DRAW_SetCursorPos( coord_t x, coord_t y )
1319 {
1320  if ( x < LeftMarginX )
1321  x = LeftMarginX;
1322  else if ( x > RightMarginX )
1323  x = RightMarginX;
1324  PosCurX = x;
1325 
1326  if ( y < LowMarginY )
1327  y = LowMarginY;
1328  else if ( y > HighMarginY - ( Char_Height * CharMagniCoeff ) )
1329  y = HighMarginY - ( Char_Height * CharMagniCoeff );
1330  PosCurY = y;
1331 }
1332 
1333 /*******************************************************************************
1334 *
1335 * DRAW_GetCursorPos
1336 *
1337 *******************************************************************************/
1347 /******************************************************************************/
1348 ret_t DRAW_GetCursorPos( void )
1349 {
1350  return ( PosCurX | ( PosCurY << 8 ) );
1351 }
1352 
1353 /*******************************************************************************
1354 *
1355 * DRAW_SetCursorMargin
1356 *
1357 *******************************************************************************/
1371 /******************************************************************************/
1372 void DRAW_SetCursorMargin( coord_t lx, coord_t rx, coord_t hy, coord_t ly )
1373 {
1374  if ( lx < 0 )
1375  lx = 0;
1376 
1377  if ( rx > Screen_Width )
1378  rx = Screen_Width;
1379  else if ( lx > rx ) // else-if necessary in case lx==rx==Screen_Width
1380  lx = rx - 1;
1381 
1382  LeftMarginX = lx;
1383  RightMarginX = rx;
1384 
1385  if ( ly < 0 )
1386  ly = 0;
1387 
1388  if ( hy > Screen_Height )
1389  hy = Screen_Height;
1390  else if ( ly > hy )
1391  ly = hy - 1;
1392 
1393  HighMarginY = hy;
1394  LowMarginY = ly;
1395 }
1396 
1397 /*******************************************************************************
1398 *
1399 * DRAW_GetCursorMargin
1400 *
1401 *******************************************************************************/
1415 /******************************************************************************/
1416 void DRAW_GetCursorMargin( coord_t* lx, coord_t* rx, coord_t* hy, coord_t* ly )
1417 {
1418  if ( lx )
1419  *lx = LeftMarginX;
1420 
1421  if ( rx )
1422  *rx = RightMarginX;
1423 
1424  if ( hy )
1425  *hy = HighMarginY;
1426 
1427  if ( ly )
1428  *ly = LowMarginY;
1429 }
1430 
1431 /*******************************************************************************
1432 *
1433 * DRAW_Circle
1434 *
1435 *******************************************************************************/
1449 void DRAW_Circle( coord_t CENTER_x, coord_t CENTER_y, coord_t RADIUS_r, color_t Color, color_t Fill_Color, bool Fill, bool Circle )
1450 {
1451  int Error = 1 - RADIUS_r;
1452  int ddF_x = 0;
1453  int ddF_y = -2 * RADIUS_r;
1454  int x = 0;
1455  int y = RADIUS_r;
1456 
1457  /* Check the x parameters*/
1458  if ( CENTER_x - RADIUS_r < 0 )
1459  CENTER_x = RADIUS_r;
1460 
1461  if ( CENTER_x + RADIUS_r > Screen_Width - 1 )
1462  CENTER_x = Screen_Width - RADIUS_r - 1;
1463 
1464  /* Check the y parameters*/
1465  if ( CENTER_y - RADIUS_r < 0 )
1466  CENTER_y = RADIUS_r;
1467 
1468  if ( CENTER_y + RADIUS_r > Screen_Height - 1 )
1469  CENTER_y = Screen_Height - RADIUS_r - 1;
1470 
1471  if ( Fill )
1472  {
1473  if ( Circle )
1474  {
1475  Fill = 0;
1476  DRAW_Circle( CENTER_x, CENTER_y, RADIUS_r, Color, Fill_Color, 1, 0 );
1477  }
1478  }
1479 
1480  if ( Fill )
1481  {
1482  DRAW_Line( CENTER_x + RADIUS_r, CENTER_y, CENTER_x - RADIUS_r, CENTER_y, Fill_Color );
1483  DRAW_Line( CENTER_x , CENTER_y - RADIUS_r, CENTER_x, CENTER_y + RADIUS_r, Fill_Color );
1484  }
1485 
1486  if ( Circle )
1487  {
1488  LCD_DrawPixel( CENTER_x, CENTER_y + RADIUS_r, Color );
1489  LCD_DrawPixel( CENTER_x, CENTER_y - RADIUS_r, Color );
1490  LCD_DrawPixel( CENTER_x + RADIUS_r, CENTER_y, Color );
1491  LCD_DrawPixel( CENTER_x - RADIUS_r, CENTER_y, Color );
1492  }
1493 
1494  while ( x < y )
1495  {
1496  if ( Error >= 0 )
1497  {
1498  y--;
1499  ddF_y += 2;
1500  Error += ddF_y;
1501  }
1502  x++;
1503  ddF_x += 2;
1504  Error += ddF_x + 1;
1505  if ( Fill )
1506  {
1507  DRAW_Line( CENTER_x + x, CENTER_y + y, CENTER_x + x, CENTER_y - y, Fill_Color );
1508  DRAW_Line( CENTER_x - x, CENTER_y + y, CENTER_x - x, CENTER_y - y, Fill_Color );
1509  DRAW_Line( CENTER_x + y, CENTER_y + x, CENTER_x + y, CENTER_y - x, Fill_Color );
1510  DRAW_Line( CENTER_x - y, CENTER_y + x, CENTER_x - y, CENTER_y - x, Fill_Color );
1511  }
1512 
1513  if ( Circle )
1514  {
1515  LCD_DrawPixel( CENTER_x + x, CENTER_y + y, Color );
1516  LCD_DrawPixel( CENTER_x - x, CENTER_y + y, Color );
1517  LCD_DrawPixel( CENTER_x + x, CENTER_y - y, Color );
1518  LCD_DrawPixel( CENTER_x - x, CENTER_y - y, Color );
1519  LCD_DrawPixel( CENTER_x + y, CENTER_y + x, Color );
1520  LCD_DrawPixel( CENTER_x - y, CENTER_y + x, Color );
1521  LCD_DrawPixel( CENTER_x + y, CENTER_y - x, Color );
1522  LCD_DrawPixel( CENTER_x - y, CENTER_y - x, Color );
1523  }
1524  }
1525 }
1526 
1527 /*******************************************************************************
1528 *
1529 * DRAW_Ellipse
1530 *
1531 *******************************************************************************/
1546 void DRAW_Ellipse( coord_t CENTER_x, coord_t CENTER_y, coord_t RADIUS_a, coord_t RADIUS_b, color_t Color, color_t Fill_Color, bool Fill, bool Ellipse )
1547 {
1548  int X, Y;
1549  int XChange, YChange;
1550  int EllipseError;
1551  int TwoASquare, TwoBSquare;
1552  int StoppingX, StoppingY;
1553  TwoASquare = 2 * RADIUS_a * RADIUS_a;
1554  TwoBSquare = 2 * RADIUS_b * RADIUS_b;
1555  X = RADIUS_a;
1556  Y = 0;
1557  XChange = RADIUS_b * RADIUS_b * ( 1 - 2 * RADIUS_a );
1558  YChange = RADIUS_a * RADIUS_a;
1559  EllipseError = 0;
1560  StoppingX = TwoBSquare * RADIUS_a;
1561  StoppingY = 0;
1562 
1563  /* Check the x parameters*/
1564  if ( CENTER_x - RADIUS_a < 0 )
1565  CENTER_x = RADIUS_a;
1566 
1567  if ( CENTER_x + RADIUS_a > Screen_Width - 1 )
1568  CENTER_x = Screen_Width - RADIUS_a - 1;
1569 
1570  /* Check the y parameters*/
1571  if ( CENTER_y - RADIUS_b < 0 )
1572  CENTER_y = RADIUS_b;
1573 
1574  if ( CENTER_y + RADIUS_b > Screen_Height - 1 )
1575  CENTER_y = Screen_Height - RADIUS_b - 1;
1576 
1577  if ( Fill )
1578  {
1579  if ( Ellipse )
1580  {
1581  Fill = 0;
1582  DRAW_Ellipse( CENTER_x, CENTER_y, RADIUS_a, RADIUS_b, Color, Fill_Color, 1, 0 );
1583  }
1584  }
1585 
1586  while ( StoppingX >= StoppingY )
1587  {
1588  if ( Fill )
1589  {
1590  DRAW_Line( CENTER_x + X, CENTER_y + Y, CENTER_x - X , CENTER_y + Y, Fill_Color );
1591  DRAW_Line( CENTER_x - X, CENTER_y - Y, CENTER_x + X , CENTER_y - Y, Fill_Color );
1592  }
1593 
1594  if ( Ellipse )
1595  {
1596  LCD_DrawPixel( CENTER_x + X, CENTER_y + Y, Color );
1597  LCD_DrawPixel( CENTER_x - X, CENTER_y + Y, Color );
1598  LCD_DrawPixel( CENTER_x - X, CENTER_y - Y, Color );
1599  LCD_DrawPixel( CENTER_x + X, CENTER_y - Y, Color );
1600  }
1601  Y++;
1602  StoppingY += TwoASquare;
1603  EllipseError += YChange;
1604  YChange += TwoASquare;
1605  if ( ( 2 * EllipseError + XChange ) > 0 )
1606  {
1607  X--;
1608  StoppingX -= TwoBSquare;
1609  EllipseError += XChange;
1610  XChange += TwoBSquare;
1611  }
1612 
1613  } // While (StoppingX >= StoppingY)
1614 
1615  X = 0;
1616  Y = RADIUS_b;
1617  XChange = RADIUS_b * RADIUS_b;
1618  YChange = RADIUS_a * RADIUS_a * ( 1 - 2 * RADIUS_b );
1619  EllipseError = 0;
1620  StoppingX = 0;
1621  StoppingY = TwoASquare * RADIUS_b;
1622 
1623  while ( StoppingX <= StoppingY )
1624  {
1625  if ( Fill )
1626  {
1627  DRAW_Line( CENTER_x + X, CENTER_y + Y, CENTER_x - X , CENTER_y + Y, Fill_Color );
1628  DRAW_Line( CENTER_x - X, CENTER_y - Y, CENTER_x + X , CENTER_y - Y, Fill_Color );
1629  }
1630 
1631  if ( Ellipse )
1632  {
1633  LCD_DrawPixel( CENTER_x + X, CENTER_y + Y, Color );
1634  LCD_DrawPixel( CENTER_x - X, CENTER_y + Y, Color );
1635  LCD_DrawPixel( CENTER_x - X, CENTER_y - Y, Color );
1636  LCD_DrawPixel( CENTER_x + X, CENTER_y - Y, Color );
1637  }
1638 
1639  X++;
1640  StoppingX += TwoBSquare;
1641  EllipseError += XChange;
1642  XChange += TwoBSquare;
1643 
1644  if ( ( 2 * EllipseError + YChange ) > 0 )
1645  {
1646  Y--;
1647  StoppingY -= TwoASquare;
1648  EllipseError += YChange;
1649  YChange += TwoASquare;
1650  }
1651 
1652  } // While (StoppingX <= StoppingY)
1653 }
1654 
1655 
1656 /*******************************************************************************
1657 *
1658 * DRAW_Polygon
1659 *
1660 *******************************************************************************/
1670 void DRAW_Polygon( coord_t* points, u16 NUM_Points, color_t Line_Color )
1671 {
1672  int i = 1;
1673 
1674  if ( points )
1675  {
1676  for ( i = 1; i < NUM_Points >> 1 ; i++ )
1677  {
1678  DRAW_Line( points[( i - 1 ) * 2], points[1 + ( i - 1 ) * 2], points[( i ) * 2], points[1 + ( i ) * 2], Line_Color );
1679  }
1680  }
1681 }
1682 
1683