Toto je má konečná verze maturitního projektu

Dependencies:   mbed mbed-rtos UTouch_vyrobek UniGraphic

display.cpp

Committer:
smejky
Date:
2021-12-27
Revision:
8:b6e7401fdcfc
Parent:
7:91b982ccf255
Child:
9:d1385f7171af

File content as of revision 8:b6e7401fdcfc:

#include "display.h"
#include "rtos.h"

UTouch touch(D4,D9,D3,D2,D5);//clk,chip_select,MOSI,miso,irq(pripojeno je ale nevim co to dela)
ILI9341 spi(SPI_8,320000000,PTD2,PTD3,PTD1,PTC12, PTC3, PTC2, "TFT",240,320);// mosi, miso, sclk, chip_select, reset, dc
DigitalOut my_green(LED2);
DigitalOut my_red(LED4);
DigitalOut my_blue(LED3);
DigitalOut led2(LED2);
Thread thread;

void led2_thread()
{
    while (true) {
        led2 = !led2;
        Thread::wait(1000);
    }
}


/*
 v ILI9341.cpp zmeneny framerate ze 70 na 100, toto pomohlo problemu blikání displeje
 velikost fotky pro čudlik 180x70
x0 = od leveho horniho rohu(240max) y=0 od leveho horniho rohu x1 = od pravého spodniho rohu(240max) mel by byt vetsi nez x0 y1 = od pravého spodniho rohu mel by byt vetsi nez y0

*/


void grafika(unsigned short int press = 0){  
    //int levy[] = {34,274,165,320,Blue};
   // int cudlik[] = {20,80,38,130,Red};
    //int spodni_levy[] = {200,240,240,320,Green};
    //int stredni_levy[] = {200,159,240,239,Red};
    int stredni_pravy[] = {200,78,240,158,Purple};
    int spodni_pravy[] = {200,0,240,77,Yellow};
      
      
     switch(press)
{
    case 1:
        //spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]);// pravy
        
        spi.Bitmap(34,0,38,46,(unsigned char*)gImage_vrch);
        spi.Bitmap(72,0,42,46,(unsigned char*)gImage_cudlik);// pravy
        spi.Bitmap(114,0,26,46,(unsigned char*)gImage_spodek);
        spi.Bitmap(140,0,26,46,(unsigned char*)gImage_spodek);
        
        break;
    case 2:
        //spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]);// levy
        spi.Bitmap(34,274,38,46,(unsigned char*)gImage_vrch);
        spi.Bitmap(72,274,42,46,(unsigned char*)gImage_cudlik_otoc);// levy
        spi.Bitmap(114,274,26,46,(unsigned char*)gImage_spodek);
        spi.Bitmap(140,274,26,46,(unsigned char*)gImage_spodek);
        break;
    case 3:
        spi.Bitmap(200,240,40,80,(unsigned char*)gImage_spodni_levy);// levy kraj spodni
        
        //spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]);// levy kraj spodni
        break;
    case 4:
        //spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]);// stred levy spodni
        spi.Bitmap(200,160,40,80,(unsigned char*)gImage_stredni_levy);
        
        break;        
    case 5:
        spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]);//stred pravy spodni
        break;        
    case 6:
        spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]);                //pravy kraj spodni
        break;           
        
        
    default:
    spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi);
    
    spi.Bitmap(0,0,36,46,(unsigned char*)gImage_vypln);
    spi.Bitmap(165,0,36,46,(unsigned char*)gImage_vypln);
    spi.Bitmap(0,274,36,46,(unsigned char*)gImage_vypln);
    spi.Bitmap(165,274,36,46,(unsigned char*)gImage_vypln);
    
        spi.Bitmap(34,0,38,46,(unsigned char*)gImage_vrch);
        spi.Bitmap(72,0,42,46,(unsigned char*)gImage_cudlik);             // pravy
        spi.Bitmap(114,0,26,46,(unsigned char*)gImage_spodek);
        spi.Bitmap(140,0,26,46,(unsigned char*)gImage_spodek);           //pravy   
        
        spi.Bitmap(34,274,38,46,(unsigned char*)gImage_vrch);
        spi.Bitmap(72,274,42,46,(unsigned char*)gImage_cudlik_otoc);// levy
        spi.Bitmap(114,274,26,46,(unsigned char*)gImage_spodek);
        spi.Bitmap(140,274,26,46,(unsigned char*)gImage_spodek);
                                            
    spi.Bitmap(200,240,40,80,(unsigned char*)gImage_spodni_levy);
    spi.Bitmap(200,160,40,80,(unsigned char*)gImage_stredni_levy);


    spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]);           //stred pravy spodni
    spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]);                //pravy kraj spodni
}  
}

void malovani(){
    
    while(1==1)
    {
      if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         unsigned short int touch_y = touch.GetX();
         unsigned short int  touch_x = touch.GetY();
         touch_x = touch_x - 10;
         touch_y = touch_y + 10;
         spi.pixel(touch_x,touch_y,Blue);           
        }
     }
    }
}

/*
else if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy [1])){
              R_is_pressed = 1;
              spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]);
               wait(0.1);   
            } 

*/





void Button(int strana = 0){
    int pravy[] = {34,0,165,46}; //pravý čudlík
    int levy[] = {34,274,165,320,Black}; //levý čudlík
    //int cudlik[] = {20,80,42,130,Orange}; //slider    nepovedeny projekt
    //int stred_cudliku[] = {30,105,Blue};  //střed čudliku
    int spodni_levy[] = {200,240,240,320,Red}; // levy spodni cudlik
    int stredni_levy[] = {200,159,240,239,Green}; //stred levy spodni cudlik
    int stredni_pravy[] = {200,78,240,158,Yellow}; //stred pravy spodni cudlik
    int spodni_pravy[] = {200,0,240,77,Purple}; // pravy spodni cudlik
    
    int cudlik_1[] = {10,213,58,260};
    int cudlik_2[] = {10,137,58,184};



      
    switch(strana){
    case 0:
        printf("default");
    break;           
    case 1:
        spodni_levy[4] = Purple;
        stredni_levy[4] = Red;
        stredni_pravy[4] = Green;
        spodni_pravy[4] = Yellow;
    break;  
    default:
            printf("default");
       }      
    while(1)
    {
      if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         
         
         unsigned short int touch_y = touch.GetX();  // 0-320
         unsigned short int  touch_x = touch.GetY(); // 0-240
         touch_x = touch_x - 5;
         touch_y = touch_y + 10;
         //spi.pixel(touch_x,touch_y,Blue);
         //printf("x %d ,y %d\r\n",touch_x,touch_y);
         
            //pravý čudlik
            if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){
            int m = strana;   
    switch(strana){
            case 0:
                m++;
            break;
            case 1:
                m++;
            break;
            default:
            m = 0;
   }
            int i = touch.DataAvailable();
            //GRAFIKA**************************************************
            spi.Bitmap(34,0,38,46,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(72,0,42,46,(unsigned char*)gImage_cudlik_stred_s);
            spi.Bitmap(114,0,26,46,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(140,0,26,46,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            while (i){
              i = touch.DataAvailable();
            }
              grafika(1);
              Menu(m);
               wait(0.2); 
            }
                   
            //pravý čudlik
            
            //levý čudlik 
            if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
            int m = strana;   
    switch(strana){
            case 1:
                m--;
            break;
            default:
            m = 1;       
   }
            //GRAFIKA**************************************************
            spi.Bitmap(34,274,38,46,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(72,274,42,46,(unsigned char*)gImage_stred_otoc_s);
            spi.Bitmap(114,274,26,46,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(140,274,26,46,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            
            int i = touch.DataAvailable();
            while (i){
              i = touch.DataAvailable();
              }
              grafika(2);
              wait(0.2);
              Menu(m);
            }  
            //levý čudlik

            //levý spodni čudlik
            if ((touch_x > spodni_levy[0]) && (touch_x < spodni_levy[2]) && (touch_y < spodni_levy[3]) && (touch_y > spodni_levy[1])){
            spi.Bitmap(200,240,40,80,(unsigned char*)gImage_spodni_levy_s);
            
            
            
            int i = touch.DataAvailable();
            //int e = 0;
            while (i){
              i = touch.DataAvailable();
              //e++;
              }
              //printf("%d",e);
              grafika(3);
               wait(0.2);
            }  
            //levý spodni čudlik
            
            
            //stred levy spodni cudlik
            if ((touch_x > stredni_levy[0]) && (touch_x < stredni_levy[2]) && (touch_y < stredni_levy[3]) && (touch_y > stredni_levy[1])){
            int i = touch.DataAvailable();
            
            spi.Bitmap(200,160,40,80,(unsigned char*)gImage_stredni_levy_s);
            
            
            thread.start(led2_thread);
            
            while (i){
              i = touch.DataAvailable();
              }
              grafika(4);
               wait(0.2);
            }
            //stred levy spodni cudlik

                        
            //stred pravy spodni cudlik
            if ((touch_x > stredni_pravy[0]) && (touch_x < stredni_pravy[2]) && (touch_y < stredni_pravy[3]) && (touch_y > stredni_pravy[1])){
            
            thread.terminate();    
            
            int i = touch.DataAvailable();
            while (i){
              spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]);
              i = touch.DataAvailable();
              }
              grafika(5);
               wait(0.2);
            }  
            //stred pravy spodni cudlik

            //kraj pravy spodni cudlik
            if ((touch_x > spodni_pravy[0]) && (touch_x < spodni_pravy[2]) && (touch_y < spodni_pravy[3]) && (touch_y > spodni_pravy[1])){
               int i = touch.DataAvailable();
            while (i){
              spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]);
              i = touch.DataAvailable();
              }
              grafika(6);
               wait(0.2);
            } 
            //kraj pravy spodni cudlik
          
//MENU CUDLIKY**********************************************************************************************************************************************************************************
            //prvni
            if ((touch_x > cudlik_1[0]) && (touch_x < cudlik_1[2]) && (touch_y < cudlik_1[3]) && (touch_y > cudlik_1[1]) && (strana == 1)){
            spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1s_vrch);
            spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1s_spodek);
            int i = touch.DataAvailable();
            while (i){
              i = touch.DataAvailable();
              }
            spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1_vrch);
            spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1_spodek);
               wait(0.2);
            Static();
            } 

            
            //prvni
          //druhy
            if ((touch_x > cudlik_2[0]) && (touch_x < cudlik_2[2]) && (touch_y < cudlik_2[3]) && (touch_y > cudlik_2[1]) && (strana == 1)){
            spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1s_vrch);
            spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1s_spodek);
            int i = touch.DataAvailable();
            while (i){
              i = touch.DataAvailable();
              }
            spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1_vrch);
            spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1_spodek);
               wait(0.2);
           
            } 

            
            //druhy
                      
        }
      }
    }    
}





void Menu(int strana = 0){   
    switch(strana)
{
    case 1:
    spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi);
    
    
    //CUDLIKY*******************************************************************************
    //prvni rada
    spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(10,137,24,47,(unsigned char*)gImage_cudlik2_vrch);
    spi.Bitmap(34,137,24,47,(unsigned char*)gImage_cudlik2_spodek);

    spi.Bitmap(10,60,24,47,(unsigned char*)gImage_cudlik3_vrch);
    spi.Bitmap(34,60,24,47,(unsigned char*)gImage_cudlik3_spodek);
    //prvni rada
    
    //druha rada
    spi.Bitmap(76,213,24,47,(unsigned char*)gImage_cudlik4_vrch);
    spi.Bitmap(100,213,24,47,(unsigned char*)gImage_cudlik4_spodek);
    
    spi.Bitmap(76,137,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(100,137,24,47,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(76,60,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(100,60,24,47,(unsigned char*)gImage_cudlik1_spodek);
    // druha rada
    
    //treti rada
    spi.Bitmap(142,213,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(166,213,24,47,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(142,137,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(166,137,24,47,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(142,60,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(166,60,24,47,(unsigned char*)gImage_cudlik1_spodek);
    // treti rada
    
    //CUDLIKY*******************************************************************************

    strana = 1;
    Button(strana);
                
        break;
    default:
    spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi);
    strana = 0;
    Button(strana);
} 
    }

void Static(){
    int red[] = {76,213,124,260};
    int green[] = {76,137,124,184};
    int blue[] = {76,60,124,107};
    

    int pravy[] = {34,0,165,46}; //pravý čudlík
    int levy[] = {34,274,165,320}; //levý čudlík
    
    spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi);
    spi.fillrect(red[0],red[1],red[2],red[3],Red); 
    spi.fillrect(green[0],green[1],green[2],green[3],Green);
    spi.fillrect(blue[0],blue[1],blue[2],blue[3],Blue); 
    
    
    int r = 1;
    int g = 1;
    int b = 1;
    while(1)
    {
      if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         unsigned short int touch_y = touch.GetX();  // 0-320
         unsigned short int  touch_x = touch.GetY(); // 0-240
         
          //pravý čudlik
            if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){
            int i = touch.DataAvailable();
            //GRAFIKA**************************************************
            spi.Bitmap(34,0,38,46,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(72,0,42,46,(unsigned char*)gImage_cudlik_stred_s);
            spi.Bitmap(114,0,26,46,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(140,0,26,46,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            while (i){
              i = touch.DataAvailable();
            }
            my_red = r;
            my_green = g;
            my_blue = b;
              grafika(1);
              Menu();
            wait(0.2); 
            }       
            //pravý čudlik
            
            //levý čudlik 
            if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
            //GRAFIKA**************************************************
            spi.Bitmap(34,274,38,46,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(72,274,42,46,(unsigned char*)gImage_stred_otoc_s);
            spi.Bitmap(114,274,26,46,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(140,274,26,46,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            
            int i = touch.DataAvailable();
            while (i){
              i = touch.DataAvailable();
              }
              grafika(2);
              wait(0.2);
              Menu();
            }  
            //levý čudlik
          
if((touch_x > red[0]) && (touch_x < red[2]) && (touch_y < red[3]) && (touch_y > red[1])){   
            r = !r;
            printf("%d",r); 
            wait(0.2);     
}

if((touch_x > green[0]) && (touch_x < green[2]) && (touch_y < green[3]) && (touch_y > green[1])){   
            g = !g;
            printf("%d",g); 
            wait(0.2);     
}

if((touch_x > blue[0]) && (touch_x < blue[2]) && (touch_y < blue[3]) && (touch_y > blue[1])){   
            b = !b;
            printf("%d",b); 
            wait(0.2);     
}

         }
    } 
  }

}

void hodiny(){
    set_time(971208480);
    spi.set_font((unsigned char*)Arial19x19);
    while(1){
        time_t seconds = time(NULL);
        seconds = seconds + 7200;
        char buffer[32];
        strftime(buffer, 32, "%R", localtime(&seconds));
        spi.set_orientation(3);
        spi.locate(255,210);
        spi.printf("%s",buffer);
        spi.set_orientation(0);
        wait_ms(1000);
        }
    }

main(){
my_red = 1;
my_green = 1;
my_blue = 1;

    spi.FastWindow(true);
    touch.InitTouch();
    touch.SetPrecision(PREC_EXTREME);
    spi.background(Black);
    spi.foreground(White);
    spi.cls();
    //spi.circle(240,320,20,Black);
    //wait_us();

    grafika();
    thread.start(hodiny);
    Button();

    
}




/*  fail projekty
          //slider  
            if ((touch_x > cudlik[0]) && (touch_x < cudlik[2]) && (touch_y > cudlik[1]) && (touch_y < cudlik[3]) && (pressure > 0)){
            
            
        //if je udelany tady pro nastavení minima a maxima
           if ((touch_x > 25) && (touch_x < 140)){           
            
            unsigned short int y0 = cudlik[1];
            unsigned short int y1 = cudlik[3];      
            unsigned short int x_zadelavani_chyby = cudlik[0];
            unsigned short int x0 = x_zadelavani_chyby - 8;
              
              //printf("%d\r\n",touch_x);                  
              stred_cudliku[0] = touch_x;
              
              cudlik[0] = stred_cudliku[0] - 10;
              cudlik[1] = stred_cudliku[1] - 25;
              cudlik[2] = stred_cudliku[0] + 10;
              cudlik[3] = stred_cudliku[1] + 25;
              
                              
               
          if (touch_x > 34){    
              x0 = x_zadelavani_chyby + 8;
                spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green);
              
              }else{
spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black);
                  }
              
         if (touch_x < 34){    
              spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black);
              
              }else{
                x0 = x_zadelavani_chyby + 8;
                spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green);
                  }     
              spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]);
              
              
              
              }
            } 
            
            //slider */