void display_init()
{
    TFT_Init_ILI9341_8bit( 320, 240 );
    TFT_BLED = 1;
    TFT_Set_Pen( CL_WHITE, 1 );
    TFT_Set_Brush( 1,CL_WHITE,0,0,0,0 );
    TFT_Set_Font( TFT_defaultFont, CL_BLACK, FO_HORIZONTAL );
    TFT_Fill_Screen( CL_WHITE );
    TFT_Set_Pen( CL_BLACK, 1 );
    TFT_Line(  20,  46, 300,  46 );
    TFT_Line(  20,  70, 300,  70 );
    TFT_Line(  20, 196, 300, 196 );;
    TFT_Line(  20, 220, 300, 220 );
    TFT_Set_Pen( CL_WHITE, 1 );
    TFT_Set_Font( &HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL );
    TFT_Write_Text( "RF Meter click", 95, 14 );
    TFT_Set_Font( &Tahoma15x16_Bold, CL_BLUE, FO_HORIZONTAL );
    TFT_Write_Text( "AD8318", 130, 50 );
    TFT_Set_Font( &Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL );
    TFT_Write_Text("EasyMx PRO v7 for STM32", 19, 223);
    TFT_Set_Font( &Verdana12x13_Regular, CL_RED, FO_HORIZONTAL );
    TFT_Write_Text( "www.mikroe.com", 200, 223 );
    TFT_Set_Font( &Tahoma15x16_Bold, CL_BLACK, FO_HORIZONTAL );
    TFT_Write_Text( "Current signal strength", 30, 200 );
    TFT_Set_Font( &HandelGothic_BT21x22_Regular, CL_BLACK, FO_HORIZONTAL );
    TFT_Image( 114, 100, signal_lo_bmp , 2 );
}
void Calibrate() {
  TFT_Set_Pen(CL_WHITE, 3);
  TFT_Set_Font(TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
  TFT_Write_Text("Touch selected corners for calibration", 50, 100);
  TFT_Line(315, 1, 319, 1);
  TFT_Line(310, 10, 319, 1);
  TFT_Line(319, 5, 319, 1);
  TFT_Write_Text("first here", 250, 20);

  TP_TFT_Calibrate_Min();                      // Calibration of bottom left corner
  Delay_ms(500);

  TFT_Set_Pen(CL_BLACK, 3);
  TFT_Set_Font(TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
  TFT_Line(315, 1, 319, 1);
  TFT_Line(310, 10, 319, 1);
  TFT_Line(319, 5, 319, 1);
  TFT_Write_Text("first here", 250, 20);

  TFT_Set_Pen(CL_WHITE, 3);
  TFT_Set_Font(TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
  TFT_Line(0, 239, 0, 235);
  TFT_Line(0, 239, 5, 239);
  TFT_Line(0, 239, 10, 229);
  TFT_Write_Text("now here ", 15, 200);

  TP_TFT_Calibrate_Max();                      // Calibration of bottom left corner
  Delay_ms(500);
}
void Paint(u32 X,u32 Y)
{
   extern u8 Page;
   if(Y<30)
   {
      if((X<50)&&(painted)){painted=0;Paint_Init();}
      else if(X<100)PenColor=1;
      else if(X<150)PenColor=2;
      else if(X<200)PenColor=3;
      else if(X<250)PenColor=4;
      else if(X<300)PenColor=5;
      else PenColor=6;
   }
   else if(X<50)
   {
      if(Y<100){shape=0;}
      else if(Y<150){shape=4;}
      else if(Y<200){shape=1;}
      else{shape=2;}
   }
   else if((X>60)&&(Y>55)&&(X<290)&&(Y<195))
   {  painted++;
      if(shape==0){TFT_Set_Pen(colors[PenColor],10);TFT_Circle(X,Y,1);}
      else if(shape==1){TFT_Set_Pen(colors[PenColor],3);TFT_Circle(X,Y,20);}
      else if(shape==2){TFT_Set_Pen(colors[PenColor],3); TFT_Rectangle(X,Y,X+20,Y+20);}
      else  {TFT_Set_Pen(colors[PenColor],20);TFT_Circle(X,Y,1);}
   }
   else if(Y>210 && X>270)
       {
          Page=0;
          Menu_Init();
       }
}
Пример #4
0
void Calibrate() {
  TFT_Set_Pen(CL_WHITE, 3);
  TFT_Set_Font(TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
  TFT_Write_Text("Touch selected corners for calibration", 50, 80);
  TFT_Write_Text("Touch selected corners for calibration", 50, 75);
  TFT_Line(315, 1, 319, 1);
  TFT_Line(310, 10, 319, 1);
  TFT_Line(319, 5, 319, 1);
  TFT_Write_Text("first here", 230, 20);
  TFT_Image(47, 90, logo_bmp, 1);
  /*
  DrawImage(&Image2);
  Image2.OwnerScreen     = &Screen1;
  Image2.Order           = 5;
  Image2.Left            = 47;
  Image2.Top             = 90;
  Image2.Width           = 226;
  Image2.Height          = 56;
  Image2.Picture_Type    = 0;
  Image2.Picture_Ratio   = 1;
  Image2.Picture_Name    = logo_bmp;
  Image2.Visible         = 1;
  Image2.Active          = 1;
  Image2.OnUpPtr         = 0;
  Image2.OnDownPtr       = 0;
  Image2.OnClickPtr      = 0;
  Image2.OnPressPtr      = 0;
  */

  TP_TFT_Calibrate_Min();                      // Calibration of TP minimum
  Delay_ms(500);

  TFT_Set_Pen(CL_BLACK, 3);
  TFT_Set_Font(TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
  TFT_Line(315, 1, 319, 1);
  TFT_Line(310, 10, 319, 1);
  TFT_Line(319, 5, 319, 1);
  TFT_Write_Text("first here", 230, 20);

  TFT_Set_Pen(CL_WHITE, 3);
  TFT_Set_Font(TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
  TFT_Line(0, 239, 0, 235);
  TFT_Line(0, 239, 5, 239);
  TFT_Line(0, 239, 10, 230);
  TFT_Write_Text("now here ", 15, 200);

  TP_TFT_Calibrate_Max();                       // Calibration of TP maximum
  Delay_ms(500);
}
/**************************************************************************************************
* Function ACCEL_Start()
* -------------------------------------------------------------------------------------------------
* Overview: Function Initialize I2C bus and accel module
* Input: Nothing
* Output: test status: 0 - skiped; 1 - pass; 2 - fail
**************************************************************************************************/
void ACCEL_Start(char *test)
{
  // Reset error flag
  *test = 0;
  
  // Initialize I2C communication
  I2C2_Init(250000);

  TFT_Set_Font(TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
  TFT_Set_Pen(bg_color, 1);
  TFT_Set_Brush(1, bg_color, 0, 0, 0, 0);

  TFT_Write_Text("Starting Accel test...", 90, 100);
  Delay_ms(2000);
  TFT_Rectangle(70, 70, 250, 130);
  
  // Initialize ADXL345 accelerometer
  if (ADXL345_Init() == 0)
  {
    TFT_Write_Text("Accel module initialized.", 90, 100);
    *test = 1;
    Delay_ms(2000);
  }
  else
  {
    TFT_Write_Text("Error during Accel module initialization.", 90, 100);
    *test = 2;
  }
    
  TFT_Rectangle(70, 70, 250, 130);
}
void Display_Message()
{
   TFT_Set_Pen(CL_WHITE, 10);
   TFT_Set_Brush(1, CL_WHITE, 0, 0, 0, 0);
   TFT_Rectangle(150,120,300,140);
   TFT_Write_Text(rx_buff,150,120);
}
void UI_UpdateFolderName(void)
{
  TFT_Set_Pen(MainScreen.Color, 0);
  TFT_Set_Brush(1, MainScreen.Color, 0, LEFT_TO_RIGHT, CL_WHITE, CL_WHITE);
  TFT_Rectangle(Label2.Left, Label2.Top, 240, 22);
  TFT_Set_Font(Label2.FontName, Label2.Font_Color, FO_HORIZONTAL);
  TFT_Write_Text(CurrentFolderName, Label2.Left, Label2.Top);
}
void Display_BatteryLevel()
{
   char txt[3];
   ByteToStr(batt_level,txt);
   TFT_Set_Pen(CL_WHITE, 10);
   TFT_Set_Brush(1, CL_WHITE, 0, 0, 0, 0);
   TFT_Rectangle(150,100,230,115);
   TFT_Write_Text(txt,150,100);
   TFT_Write_Char(0x25,180,100);
}
static void tft_initialize()
{
    TFT_Init_ILI9341_8bit( 320, 280 );
    TFT_BLED = 1;
    TFT_Set_Default_Mode();
    TFT_Set_Pen( CL_WHITE, 1 );
    TFT_Set_Brush( 1, CL_WHITE, 0, 0, 0, 0 );
    TFT_Set_Font( TFT_defaultFont, CL_BLACK, FO_HORIZONTAL );

    TFT_Fill_Screen( CL_WHITE );
    TFT_Set_Pen( CL_BLACK, 1 );
    TFT_Line( 20, 222, 300, 222 );
    TFT_Set_Font( &Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL );
    TFT_Write_Text( "EasyMx PRO v7 for STM32", 19, 223 );
    TFT_Set_Font( &Verdana12x13_Regular, CL_RED, FO_HORIZONTAL );
    TFT_Write_Text( "www.mikroe.com", 200, 223 );
    TFT_Image( ( 320 - 220 ) / 2, 0, rudderangle_bmp, 1 );
    TFT_Set_Font( TFT_defaultFont, CL_BLACK, FO_HORIZONTAL );
}
void UI_ResetCursorPos(void)
{
  TFT_Set_Pen(MainScreen.Color, 0);
  TFT_Set_Brush(1, MainScreen.Color, 0, LEFT_TO_RIGHT, CL_WHITE, CL_WHITE);
  TFT_Rectangle(Image3.Left, Image3.Top, (Image3.Left+Image3.Width), (Image3.Top+Image3.Height));
  Image3.Left = 10;
  Image3.Top = 28;
  DrawImage(&Image3);
  cursorPos = 0;
  filesListOffset = 0;
}
void DrawFrame() {
  TFT_Fill_Screen(CL_WHITE);
  TFT_Set_Pen(CL_BLACK, 1);
  TFT_Line(20, 220, 300, 220);
  TFT_Line(20,  46, 300,  46);
  TFT_Set_Font(&TFT_defaultFont, CL_RED, FO_HORIZONTAL);
  TFT_Write_Text("BLE2  Click  Board  Demo", 25, 14);
  TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
  TFT_Write_Text("EasyMx PRO v7", 19, 223);
  TFT_Set_Font(&TFT_defaultFont, CL_RED, FO_HORIZONTAL);
  TFT_Write_Text("www.mikroe.com", 200, 223);
  TFT_Set_Font(&TFT_defaultFont, CL_BLACK, FO_HORIZONTAL);
  TFT_Write_Text("BATTERY SERVICE", 40, 60);
  TFT_Write_Text("BATTERY LEVEL:", 40, 100);
  TFT_Write_Text("RECEIVE:", 40, 120);
}
void UI_UpdateFilesList()
{
  unsigned char i;
  for (i = 0; i < 12; i++) {
    memcpy(FileList_Labels[i]->Caption, FilesList[i+filesListOffset].Name, FilesList[i+filesListOffset].NameLength);
    FileList_Labels[i]->Caption[FilesList[i+filesListOffset].NameLength] = 0x00;
  }
  
  TFT_Set_Pen(MainScreen.Color, 0);
  TFT_Set_Brush(1, MainScreen.Color, 0, LEFT_TO_RIGHT, CL_WHITE, CL_WHITE);
  TFT_Rectangle(FileList_Labels[0]->Left, FileList_Labels[0]->Top, 240, 230);
  TFT_Set_Font(FileList_Labels[0]->FontName, FileList_Labels[0]->Font_Color, FO_HORIZONTAL);

  for (i = 0; i < 12; i++) {
    TFT_Write_Text(FileList_Labels[i]->Caption, FileList_Labels[i]->Left, FileList_Labels[i]->Top);
  }
}
Пример #13
0
/*******************************************************************************
* Function Roller_Deactivate(TRoller *Roller, unsigned int xpos, unsigned int ypos)
* ------------------------------------------------------------------------------
* Overview: Function deactivates roller and displays its value instead
* Input: pointer to roller, coordinates where it should display
* Output: Nothing
*******************************************************************************/
void Roller_Deactivate(TRoller *Roller, unsigned int xpos, unsigned int ypos){
char text[2];
  TFT_Set_Pen(Clock.Color, 0);
  TFT_Set_Brush(1, Clock.Color, 0, 0, 0, 0);
  TFT_Rectangle(Roller->Left, Roller->Top, Roller->Left + Roller->Width, Roller->Top + Roller->Height);
  text[0] = Roller->currentlevel + 48;
  text[1] = 0;
  TFT_Set_Font(Label15.FontName, CL_WHITE, FO_HORIZONTAL);
  if (Roller == &AmPm){
    if (Roller->currentlevel == 0)
      TFT_Write_Text("AM", xpos, ypos);
    else if (Roller->currentlevel == 1)
      TFT_Write_Text("PM", xpos, ypos);
  }
  else
    TFT_Write_Text(text, xpos, ypos);
}
Пример #14
0
/*******************************************************************************
* Function UpdateTime(TTime *RTCC_Time)
* ------------------------------------------------------------------------------
* Overview: Function reads Time and displays it on Home screen
* Input: Nothing
* Output: Nothing
*******************************************************************************/
void UpdateTime(TTime *RTCC_Time){
  Label19_Caption[0] = (RTCC_Time->hours / 10) + 48;
  Label19_Caption[1] = (RTCC_Time->hours % 10) + 48;
  Label19_Caption[2] = ':';
  Label19_Caption[3] = (RTCC_Time->minutes / 10) + 48;
  Label19_Caption[4] = (RTCC_Time->minutes % 10) + 48;
  Label19_Caption[5] = ' ';
  if (RTCC_Time->ampm == 0){
    Label19_Caption[6] = 'A';
    Label19_Caption[7] = 'M';
  }
  else if (RTCC_Time->ampm == 1){
    Label19_Caption[6] = 'P';
    Label19_Caption[7] = 'M';
  }
  Label19_Caption[8] = 0;
  TFT_Set_Brush(1, Home.Color, 0, 0, 0, 0);
  TFT_Set_Pen(Home.Color, 0);
  TFT_Rectangle(Label19.Left, Label19.Top, Label19.Left + 60, Label19.Top + 20);
  DrawLabel(&Label19);
}
void DrawButton(TButton *Abutton) {
  if (Abutton->Visible == 1) {
    if (object_pressed == 1) {
      object_pressed = 0;
      TFT_Set_Brush(Abutton->Transparent, Abutton->Press_Color, Abutton->Gradient, Abutton->Gradient_Orientation, Abutton->Gradient_End_Color, Abutton->Gradient_Start_Color);
    }
    else {
      TFT_Set_Brush(Abutton->Transparent, Abutton->Color, Abutton->Gradient, Abutton->Gradient_Orientation, Abutton->Gradient_Start_Color, Abutton->Gradient_End_Color);
    }
    TFT_Set_Pen(Abutton->Pen_Color, Abutton->Pen_Width);
    TFT_Rectangle(Abutton->Left, Abutton->Top, Abutton->Left + Abutton->Width - 1, Abutton->Top + Abutton->Height - 1);
    TFT_Set_Ext_Font(Abutton->FontName, Abutton->Font_Color, FO_HORIZONTAL);
    TFT_Write_Text_Return_Pos(Abutton->Caption, Abutton->Left, Abutton->Top);
    if (AButton->TextAlign == _taLeft)
      TFT_Write_Text(Abutton->Caption, Abutton->Left + 4, (Abutton->Top + ((Abutton->Height - caption_height) / 2)));
    else if (AButton->TextAlign == _taCenter)
      TFT_Write_Text(Abutton->Caption, (Abutton->Left + (Abutton->Width - caption_length) / 2), (Abutton->Top + ((Abutton->Height - caption_height) / 2)));
    else if (AButton->TextAlign == _taRight)
      TFT_Write_Text(Abutton->Caption, Abutton->Left + (Abutton->Width - caption_length - 4), (Abutton->Top + (Abutton->Height - caption_height) / 2));
  }
}
void DrawRadioButton(TRadioButton *ARadioButton) {
  int circleOffset = 0;
  if (ARadioButton->Visible == 1) {
  circleOffset = ARadioButton->Height / 5;
    TFT_Set_Pen(ARadioButton->Pen_Color, ARadioButton->Pen_Width);
    if (ARadioButton->TextAlign == _taLeft) {
             TFT_Set_Brush(ARadioButton->Transparent,ARadioButton->Background_Color,0,0,0,0);
             TFT_Circle(ARadioButton->Left + ARadioButton->Height / 2, ARadioButton->Top + ARadioButton->Height / 2, ARadioButton->Height / 2);
             if (ARadioButton->Checked == 1) {
                 if (object_pressed == 1) {
                    object_pressed = 0;
                    TFT_Set_Brush(ARadioButton->Transparent, ARadioButton->Press_Color, ARadioButton->Gradient, ARadioButton->Gradient_Orientation, ARadioButton->Gradient_End_Color, ARadioButton->Gradient_Start_Color);
                 }
                 else 
                   TFT_Set_Brush(ARadioButton->Transparent, ARadioButton->Color, ARadioButton->Gradient, ARadioButton->Gradient_Orientation, ARadioButton->Gradient_Start_Color, ARadioButton->Gradient_End_Color);
               TFT_Circle(ARadioButton->Left + ARadioButton->Height / 2 , ARadioButton->Top + ARadioButton->Height / 2, ARadioButton->Height / 2 - circleOffset);
             }
             TFT_Set_Ext_Font(ARadioButton->FontName, ARadioButton->Font_Color, FO_HORIZONTAL);
             TFT_Write_Text_Return_Pos(ARadioButton->Caption, ARadioButton->Left + ARadioButton->Height + 4, ARadioButton->Top);
             TFT_Write_Text(ARadioButton->Caption, ARadioButton->Left + ARadioButton->Height + 4, (ARadioButton->Top + ((ARadioButton->Height - caption_height) / 2)));
    }
    else if (ARadioButton->TextAlign == _taRight) {
             TFT_Set_Brush(ARadioButton->Transparent,ARadioButton->Background_Color,0,0,0,0);
             TFT_Circle(ARadioButton->Left  + ARadioButton->Width - ARadioButton->Height / 2, ARadioButton->Top + ARadioButton->Height / 2, ARadioButton->Height / 2);
             if (ARadioButton->Checked == 1) {
                 if (object_pressed == 1) {
                    object_pressed = 0;
                    TFT_Set_Brush(ARadioButton->Transparent, ARadioButton->Press_Color, ARadioButton->Gradient, ARadioButton->Gradient_Orientation, ARadioButton->Gradient_End_Color, ARadioButton->Gradient_Start_Color);
                 }
                 else 
                   TFT_Set_Brush(ARadioButton->Transparent, ARadioButton->Color, ARadioButton->Gradient, ARadioButton->Gradient_Orientation, ARadioButton->Gradient_Start_Color, ARadioButton->Gradient_End_Color);
                 TFT_Circle(ARadioButton->Left  + ARadioButton->Width - ARadioButton->Height / 2, ARadioButton->Top + ARadioButton->Height / 2, ARadioButton->Height / 2 - circleOffset);
             }
             TFT_Set_Ext_Font(ARadioButton->FontName, ARadioButton->Font_Color, FO_HORIZONTAL);
             TFT_Write_Text_Return_Pos(ARadioButton->Caption, ARadioButton->Left + 3, ARadioButton->Top);
             TFT_Write_Text(ARadioButton->Caption, ARadioButton->Left + 3, ARadioButton->Top + (ARadioButton->Height - caption_height) / 2);
    }
 }
}
Пример #17
0
void DrawRoundButton(TButton_Round *Around_button) {
unsigned int ALeft, ATop;
  if (Around_button->Visible != 0) {
    if (object_pressed == 1) {
      object_pressed = 0;
      TFT_Set_Brush(Around_button->Transparent, Around_button->Press_Color, Around_button->Gradient, Around_button->Gradient_Orientation,
                    Around_button->Gradient_End_Color, Around_button->Gradient_Start_Color);
    }
    else {
      TFT_Set_Brush(Around_button->Transparent, Around_button->Color, Around_button->Gradient, Around_button->Gradient_Orientation,
                    Around_button->Gradient_Start_Color, Around_button->Gradient_End_Color);
    }
    TFT_Set_Pen(Around_button->Pen_Color, Around_button->Pen_Width);
    TFT_Rectangle_Round_Edges(Around_button->Left + 1, Around_button->Top + 1,
      Around_button->Left + Around_button->Width - 2,
      Around_button->Top + Around_button->Height - 2, Around_button->Corner_Radius);
    if (Around_button->VerticalText != 0)
      TFT_Set_Font(Around_button->FontName, Around_button->Font_Color, FO_VERTICAL_COLUMN);
    else
      TFT_Set_Font(Around_button->FontName, Around_button->Font_Color, FO_HORIZONTAL);
    TFT_Write_Text_Return_Pos(Around_button->Caption, Around_button->Left, Around_button->Top);
    if (Around_button->TextAlign == _taLeft)
      ALeft = Around_button->Left + 4;
    else if (Around_button->TextAlign == _taCenter)
      ALeft = Around_button->Left + (Around_button->Width - caption_length) / 2;
    else if (Around_button->TextAlign == _taRight)
      ALeft = Around_button->Left + Around_button->Width - caption_length - 4;

    if (Around_button->TextAlignVertical == _tavTop)
      ATop = Around_button->Top + 3;
    else if (Around_button->TextAlignVertical == _tavMiddle)
      ATop = Around_button->Top + (Around_button->Height - caption_height) / 2;
    else if (Around_button->TextAlignVertical == _tavBottom)
      ATop  = Around_button->Top + Around_button->Height - caption_height - 4;

    TFT_Write_Text(Around_button->Caption, ALeft, ATop);
  }
}
static void tft_update()
{
    static float last_angle;
    static line_t last_line;
    float *read_angle;
    line_t current_line;
    float total = 0;
    char tmp_txt[20];
    int i;

    for( i = 0; i < 10; i++ )
    {
        read_angle = magneto_get_degrees( 1 );

        if( magneto_error() )
        {
            magneto_error_t *error = magneto_get_errors( 1 );
            TFT_Set_Font( TFT_defaultFont, CL_RED, FO_HORIZONTAL );
            TFT_Write_Text( "ERROR", 138, 25 );
        }
        total += *read_angle;
    }

    total /= 10.0f;

    TFT_Set_Font( TFT_defaultFont, CL_WHITE, FO_HORIZONTAL );
    TFT_Write_Text( "ERROR", 138, 25 );
    sprintf( tmp_txt, "%3.1f", last_angle );
    TFT_Write_Text( tmp_txt, 10, 25 );
    TFT_Set_Font( TFT_defaultFont, CL_BLACK, FO_HORIZONTAL );
    sprintf( tmp_txt, "%3.1f", total );
    TFT_Write_Text( tmp_txt, 10, 25 );

    last_angle = total;

    TFT_Set_Pen( CL_WHITE, 4 );
    TFT_Line( last_line.x1, last_line.y1, last_line.x2, last_line.y2 );
    TFT_Set_Pen( CL_RED, 4 );

    if( total <= 90.0f )
    {
        current_line.x1 = ( int )( X_CENTER + ( INNER_RADIUS * sin( 90.0f *
                                                ( PI / 180.0f ) ) ) );
        current_line.y1 = ( int )( Y_CENTER + ( INNER_RADIUS * -cos( 90.0f *
                                                ( PI  / 180.0f ) ) ) );
        current_line.x2 = ( int )( X_CENTER + ( OUTER_RADIUS * sin( 90.0f *
                                                ( PI / 180.0f ) ) ) );
        current_line.y2 = ( int )( Y_CENTER + ( OUTER_RADIUS * -cos( 90.0f *
                                                ( PI  / 180.0f ) ) ) );
    }
    else if( total >= 270.0f )
    {
        current_line.x1 = ( int )( X_CENTER + ( INNER_RADIUS * sin( 270.0f *
                                                ( PI / 180.0f ) ) ) );
        current_line.y1 = ( int )( Y_CENTER + ( INNER_RADIUS * -cos( 270.0f *
                                                ( PI  / 180.0f ) ) ) );
        current_line.x2 = ( int )( X_CENTER + ( OUTER_RADIUS * sin( 270.0f *
                                                ( PI / 180.0f ) ) ) );
        current_line.y2 = ( int )( Y_CENTER + ( OUTER_RADIUS * -cos( 270.0f *
                                                ( PI  / 180.0f ) ) ) );
    }
    else
    {
        current_line.x1 = ( int )( X_CENTER + ( INNER_RADIUS * sin( total *
                                                ( PI / 180.0f ) ) ) );
        current_line.y1 = ( int )( Y_CENTER + ( INNER_RADIUS * -cos( total *
                                                ( PI  / 180.0f ) ) ) );
        current_line.x2 = ( int )( X_CENTER + ( OUTER_RADIUS * sin( total *
                                                ( PI / 180.0f ) ) ) );
        current_line.y2 = ( int )( Y_CENTER + ( OUTER_RADIUS * -cos( total *
                                                ( PI  / 180.0f ) ) ) );
    }

    TFT_Line( current_line.x1, current_line.y1, current_line.x2,
              current_line.y2 );
    memcpy( &last_line, &current_line, sizeof( line_t ) );

    update_flag = false;
}
void UI_Handler()
{
    /* Up button */
    if (Button(&GPIO_PORTB_DATA, 0, 1, 0))
      oldstate_up = 1;
    if (oldstate_up && Button(&GPIO_PORTB_DATA, 0, 1, 1)) { // detect logical one to logical zero transition

      if (cursorPos > 0) {
        TFT_Set_Pen(MainScreen.Color, 0);
        TFT_Set_Brush(1, MainScreen.Color, 0, LEFT_TO_RIGHT, CL_WHITE, CL_WHITE);
        TFT_Rectangle(Image3.Left, Image3.Top, (Image3.Left+Image3.Width), (Image3.Top+Image3.Height));
        Image3.Top -= 16;
        DrawImage(&Image3);
        cursorPos--;
      } else if (filesListOffset > 0) {
        filesListOffset--;
        UI_UpdateFilesList();
      }
      oldstate_up = 0;
    }
    
    /* Down button */
    if (Button(&GPIO_PORTE_DATA, 5, 1, 0))
      oldstate_down = 1;
    if (oldstate_down && Button(&GPIO_PORTE_DATA, 5, 1, 1)) { // detect logical one to logical zero transition
      
      if (cursorPos < 11 && cursorPos < (FilesListCount-1)) {
        TFT_Set_Pen(MainScreen.Color, 0);
        TFT_Set_Brush(1, MainScreen.Color, 0, LEFT_TO_RIGHT, CL_WHITE, CL_WHITE);
        TFT_Rectangle(Image3.Left, Image3.Top, (Image3.Left+Image3.Width), (Image3.Top+Image3.Height));
        Image3.Top += 16;
        DrawImage(&Image3);
        cursorPos++;
      } else if ((cursorPos+filesListOffset+1) < FilesListCount) {
        filesListOffset++;
        UI_UpdateFilesList();
      }
      oldstate_down = 0;
    }
    
    /* Enter button */
    if (Button(&GPIO_PORTH_DATA, 2, 1, 0))
      oldstate_press = 1;
    if (oldstate_press && Button(&GPIO_PORTH_DATA, 2, 1, 1)) { // detect logical one to logical zero transition

      if (CurrentState == IMAGE_DISPLAY) {
        UI_ShowMainScreen();
        UI_UpdateFolderName();
        UI_UpdateFilesList();
        CurrentState = IDLE;
      } else if (CurrentState == IDLE) {
        if (FilesList[cursorPos+filesListOffset]->Type == 'A')  {
          if (DownloadMode == 0)
            PlayAudio(FilesList[cursorPos+filesListOffset]->ID);
          else if (DownloadMode == 1 && SDSave_Disabled == 0)
            SaveAudio(FilesList[cursorPos+filesListOffset]->ID, FilesList[cursorPos+filesListOffset]->Name);
        } else if (FilesList[cursorPos+filesListOffset]->Type == 'F') {
            if (CurrentFolderID == 0 || FilesList[cursorPos+filesListOffset]->ID == 0) // Only possible to enter folders if we are in the ROOT folder currently (Only 1-level deep folder tree currently supported!)
              RequestFolderContent(FilesList[cursorPos+filesListOffset]->ID, FilesList[cursorPos+filesListOffset]->Name, FilesList[cursorPos+filesListOffset]->NameLength);
        } else if (FilesList[cursorPos+filesListOffset]->Type == 'I') {
            DisplayImage(FilesList[cursorPos+filesListOffset]->ID);
        }
      } else if (CurrentState == FILE_RECEIVE) { // Stop the playback
        TerminateAudio();
        CurrentState = IDLE;
      }
      oldstate_press = 0;
    }
    
   /* Right button */
    if (Button(&GPIO_PORTE_DATA, 4, 1, 0))
      oldstate_right = 1;
    if (oldstate_right && Button(&GPIO_PORTE_DATA, 4, 1, 1)) { // detect logical one to logical zero transition
      if (SDSave_Disabled == 0) { // Enabling the SD Saving mode (right click) is only possible if SD card is inserted
        DownloadMode = ~DownloadMode;
        GPIO_PORTA_DATA6_bit = DownloadMode;
      }

      oldstate_right = 0;
    }
}
void Paint_Init(void)
{
    TFT_Fill_Screen(colors[14]);
    TFT_Set_Pen(colors[14],20);
    TFT_Rectangle(0,0,20,20);
    TFT_Write_Text("Clear",2,8);
    TFT_Set_Pen(colors[1],20);
    TFT_Rectangle(50,0,70,20);
    TFT_Set_Pen(colors[2],20);
    TFT_Rectangle(100,0,120,20);
    TFT_Set_Pen(colors[3],20);
    TFT_Rectangle(150,0,170,20);
    TFT_Set_Pen(colors[4],20);
    TFT_Rectangle(200,0,220,20);
    TFT_Set_Pen(colors[5],20);
    TFT_Rectangle(250,0,270,20);
    TFT_Set_Pen(colors[6],20);
    TFT_Rectangle(300,0,320,20);
    ///////////////////////////////////////////
    TFT_Set_Pen(colors[2],1);
    TFT_Rectangle(5,50,45,90);
    TFT_Set_Pen(colors[1],10);
    TFT_Circle(25,70,1);
    TFT_Set_Pen(colors[2],1);
    TFT_Rectangle(5,100,45,140);
    TFT_Set_Pen(colors[1],20);
    TFT_Circle(25,120,1);
    TFT_Set_Pen(colors[2],1);
    TFT_Rectangle(5,150,45,190);
    TFT_Set_Pen(colors[1],3);
    TFT_Circle(25,170,15);
    TFT_Set_Pen(colors[2],1);
    TFT_Rectangle(5,200,45,240);
    TFT_Set_Pen(colors[1],3);
    TFT_Rectangle(10,210,40,230);
    TFT_Set_Pen(colors[1],1);
    TFT_Rectangle(50,45,310,215);
    ////////////////////////////////////////////
    TFT_Write_Text("Back->",270,220);
}