/**************************************************************************************************
* 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 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 );
    }
}
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();
       }
}
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);
}
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 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);
  }
}
예제 #9
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);
}
예제 #10
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 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);
}