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

Dependencies:   mbed mbed-rtos UTouch_vyrobek UniGraphic

display.cpp

Committer:
smejky
Date:
2021-12-18
Revision:
7:91b982ccf255
Parent:
6:8b186158b2a3
Child:
8:b6e7401fdcfc

File content as of revision 7:91b982ccf255:

#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 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 pozadi[] = {0,0,200,320,White}; //pozadi
    
      
    //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.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]);//pozadi
    
    
        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.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]);                   //levy
    //spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]);                     //levy kraj spodni
    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_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]);                //stred levy spodni
    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};

      
    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;
            case 2:
                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;
            case 2:
                m--;
            break;
            default:
            m = 2;       
   }
            //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 == 2)){
            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);
            } 

            
            //prvni
          
                      
        }
      }
    }    
}





void Menu(int strana = 0){
    int pozadi[] = {0,46,199,273,White}; //pozadi
    
    switch(strana)
{
    case 1:
    pozadi[4] = Green;
    //spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]);                //pozadi
    spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi);
    spi.Bitmap(0,0,34,46,(unsigned char*)gImage_vypln);
    spi.Bitmap(165,0,34,46,(unsigned char*)gImage_vypln);
    spi.Bitmap(0,274,34,46,(unsigned char*)gImage_vypln);
    spi.Bitmap(165,274,34,46,(unsigned char*)gImage_vypln);
    
    strana = 1;
    Button(strana);            
        break;
        
        
    case 2:
    pozadi[4] = Orange;
    spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]);                //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_cudlik1_vrch);
    spi.Bitmap(34,137,24,47,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(10,60,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(34,60,24,47,(unsigned char*)gImage_cudlik1_spodek);
    //prvni rada
    
    //druha rada
    spi.Bitmap(76,213,24,47,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(100,213,24,47,(unsigned char*)gImage_cudlik1_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 = 2;
    Button(strana);            
        break; 
        
             
    default:
    spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]);
    strana = 0;
    Button(strana);
} 
    }


main(){
    spi.FastWindow(true);
    touch.InitTouch();
    touch.SetPrecision(PREC_EXTREME);
    spi.background(White);
    spi.cls();
    //spi.circle(240,320,20,Black);
    //wait_us();
    
    
    grafika();
    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 */