/**************************************************************************************************
* 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);
}
Beispiel #2
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);
}
void updateLabel(tlabel *lbl, char *str){
  TFT_Set_Font(lbl->Fontname, Box1.Color, FO_HORIZONTAL);
  TFT_Write_Text(lbl->Caption, lbl->Left, lbl->Top);
  strcpy(lbl->Caption, str);
  TFT_Set_Font(lbl->Fontname, lbl->Font_Color, FO_HORIZONTAL);
  DrawLabel(lbl);
}
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);
}
Beispiel #6
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);
}
void main() 
{
    system_init();
    display_init();
    
    // Device initialisation
    // Must be done before usage
    rf_meter_init();
    Delay_ms( 200 );
    
    while( 1 )
    {
        // Signal strength measurement
        result = rf_meter_get_signal_strength();
        
        // Change the track value only in case of the signal strenght chaged 
        // scope to avoid the display refreshing on every single loop
        if ( result < -50.0 )
            track = 0;
        else if ( ( result < -35.0 ) && ( result >= -50.0 ) )
            track = 1;
        else if ( ( result < -20.0 ) && ( result >= -35 ) )
            track = 2;
        else
            track = 3;

        // If scope changed delete old picture and draw a new one
        if ( track != last_track )
        {
            TFT_Rectangle( 112, 98, 196, 166 );
            
            switch( track )
            {
                case 0 :
                    TFT_Image( 114, 100, signal_lo_bmp , 2 );
                    break;
                case 1 :
                    TFT_Image( 114, 100, signal_lo_m_bmp , 2 );
                    break;
                case 2 :
                    TFT_Image( 114, 100, signal_hi_m_bmp , 2 );
                    break;
                case 3 :
                    TFT_Image( 114, 100, signal_hi_bmp , 2 );
                    break;
            }
            // Replace old scope value with the new one
            last_track = track;
        }
        
        // Display signal strength
        sprintf( tmp_txt, "%5.1f    dBm", result );
        TFT_Rectangle( 198, 200, 288, 218 );
        TFT_Set_Font( &Tahoma15x16_Bold, CL_BLUE, FO_HORIZONTAL );
        TFT_Write_Text( tmp_txt, 205, 200 );
        Delay_ms( 500 );
    }
}
Beispiel #8
0
void DrawLabel(TLabel *ALabel) {
  if (ALabel->Visible != 0) {
    if (ALabel->VerticalText != 0)
      TFT_Set_Font(ALabel->FontName, ALabel->Font_Color, FO_VERTICAL_COLUMN);
    else
      TFT_Set_Font(ALabel->FontName, ALabel->Font_Color, FO_HORIZONTAL);
    TFT_Write_Text(ALabel->Caption, ALabel->Left, ALabel->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);
}
Beispiel #10
0
/*******************************************************************************
* Function Scroll_Get_One_Text_Line(char line, char *text)
* ------------------------------------------------------------------------------
* Overview: Function Gets desired Pixel Line of text and fills it in a array
* Input: desired line number, pointer to text
* Output: Nothing
*******************************************************************************/
void Scroll_Get_One_Text_Line(char line, char *text){
  memset(pix_array, 0, 165);
  current_text_column = line;
  TFT_Write_Data_Ptr =  Dummy_Write_data;
  TFT_SSD1963_Set_Address_Ptr = Dummy_Set_address;
  TFT_Set_Font(MP3_Font, _MP3_FONT_COLOR, FO_HORIZONTAL);
  TFT_Write_Text(text, _MP3_TEXT_VLINE, 0);
  TFT_SSD1963_Set_Address_Ptr = TFT_Set_Address_SSD1963II;
  //TFT_Write_Data_Ptr = TFT_Write_to_16bitPort;
}
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 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));
  }
}
Beispiel #13
0
/*******************************************************************************
* Function Scroll_Fill_Area()
* ------------------------------------------------------------------------------
* Overview:  Function fills Scroll area with text from File_List
* Input: Nothing
* Output: Nothing
*******************************************************************************/
void Scroll_Fill_Area(){
char *ptr, *dptr, i;
unsigned int temp, temp1;
  dptr = Scroll_text;
  i = 0;
  ptr = File_List[i].FileName;

  // write Text
  while (*ptr != 0xFF){
    while(*dptr++ = *ptr++)
      ;
    temp = i * (_FONT_HEIGHT + _FONT_VERTICAL_SPACING);
    ptr = File_List[i+1].FileName;
    if (temp < _SCROLL_LAST_LINE - _SCROLL_FIRST_LINE - _FONT_HEIGHT){
      if (File_List[i].FileType == 1)
        TFT_Image(_MP3_IMAGE_VLINE, _SCROLL_FIRST_LINE + temp, file_icon.Picture_Name, 1);
      if (File_List[i].FileType == 2)
        TFT_Image(_MP3_IMAGE_VLINE, _SCROLL_FIRST_LINE + temp, folder_icon.Picture_Name, 1);
      TFT_Set_Font(MP3_Font, _MP3_FONT_COLOR, FO_HORIZONTAL);
      TFT_Write_Text(Scroll_text, _MP3_TEXT_VLINE, _SCROLL_FIRST_LINE + temp);
      i ++;
      dptr = Scroll_text;
      temp1 = _SCROLL_FIRST_LINE + temp;
    }
    else{
      i ++;
      dptr = Scroll_text;
    }
  }
  Scroll_total_columns = temp + (_FONT_HEIGHT + _FONT_VERTICAL_SPACING);

  // if there is uncomplete text, write it too
  temp1 = temp1 + _FONT_HEIGHT + _FONT_VERTICAL_SPACING - 1;
  if (temp1 < _SCROLL_LAST_LINE)
    current_text_column = 1;
  if (temp1 <= temp){
    while (temp1 < _SCROLL_LAST_LINE){
      memset(pix_array, 0, 479);
      i = Scrool_Get_new_text(last_window_column / (_FONT_HEIGHT + _FONT_VERTICAL_SPACING));
      Scroll_Get_One_Text_Line(current_text_column, Scroll_text);
      
      if (File_List[i].FileType == 1)
        Scroll_Write_One_Line(temp1, &file_icon);
      if (File_List[i].FileType == 2)
        Scroll_Write_One_Line(temp1, &folder_icon);

      current_text_column ++;
      temp1 ++;
    }
  }
  
  TFT_Ext_Image(_MP3_BIGIMAGE_VLINE, _SCROLL_FIRST_LINE, mp3_player_note_bmp, 1);
}
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);
}
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);
    }
 }
}
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);
  }
}
// This function draws to the screen
static void RenderScreen(){

        TFT_Fill_Screen(bg_color);

        computeXform();    //calculate translation matrix

        drawModel();     //render polygons to LCD


        TFT_Write_Text(rotationString, 10, 240-25);   //write the rotation values

        Delay_ms(50);

        //increment the current frame number
        frame_counter++;

        //Save the settings from the previous frame
        SavePrevious(); 
}
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);
}
Beispiel #19
0
void DrawIcon (int xx, int yy) {
  int i = 0, j = 0;
  int xd = 0, yd = 0;
  int dx, dy;
  int x, y;
  
  dx = 320/4;
  dy = 240/3;

  x = dx/2;
  y = dy/2;
  
  xd = (x+xx*dx)-16;
  yd = (y+yy*dy)-16;

  for(i=0; i<32; i++) {
      for(j=0; j<32; j++) {
          TFT_Dot(xd+i, yd+j, Image_icon[j*32+i]);
      }
  }
  TFT_Write_Text(Image_text, xd-18, yd+32);
}
Beispiel #20
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);
  }
}
void BLE_Init()
{
  unsigned int line_no;
   line_no = 10;
  TFT_Write_Text("Start initialization",10,line_no);
  RN_WAKE = 1;
  while (!wait_response("CMD"));                                                //Wait to response CMD
  line_no += 20;
  Delay_ms(100);
  ble2_reset_to_factory_default(1);                                             //Reset RN4020 to factory settings
  while (!wait_response("AOK"));                                                //Wait to response AOK
  TFT_Write_Text("Factory reset",10,line_no);
  line_no += 20;
  Delay_ms(100);
  TFT_Write_Text("Set module name: BLE2_Click",10,line_no);
  ble2_set_device_name("BLE2_Click");                                           //Set name BLE2_Click
  while (!wait_response("AOK"));                                                //Wait to response AOK
  line_no += 20;
  Delay_ms(100);
  TFT_Write_Text("Configure services",10,line_no);

  /*
  Example:
  Table: 2-6 in Datasheet
  Health Thermometer + Heart Rate + Battery Services
  UART_WRite_Line("SS,F0000000");
  */

  ble2_set_server_services(40000000);                                           //Battery
  while (!wait_response("AOK"));                                                //Wait to response AOK
  line_no += 20;
  Delay_ms(100);
  TFT_Write_Text("Configure features",10,line_no);
  ble2_set_supported_features(20000000);                                        //Auto Advertise (Table: 2-5 in Datasheet)
  while (!wait_response("AOK"));                                                //wait to response AOK
  line_no += 20;
  Delay_ms(100);
  TFT_Write_Text("Reboot module",10,line_no);
  ble2_device_reboot();                                                       //reboot
  while (!wait_response("Reboot"));                                             //wait to response Reboot


}
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;
}