Toto je má konečná verze maturitního projektu
Dependencies: mbed mbed-rtos UTouch_vyrobek UniGraphic
Diff: display.cpp
- Revision:
- 7:91b982ccf255
- Parent:
- 6:8b186158b2a3
- Child:
- 8:b6e7401fdcfc
diff -r 8b186158b2a3 -r 91b982ccf255 display.cpp --- a/display.cpp Sun Dec 12 10:04:44 2021 +0000 +++ b/display.cpp Sat Dec 18 14:50:58 2021 +0000 @@ -1,10 +1,17 @@ -#include "mbed.h" -#include "UTouch.h" -#include "ILI9341.h" - +#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); + } +} /* @@ -14,13 +21,15 @@ */ + void grafika(unsigned short int press = 0){ int pozadi[] = {0,0,200,320,White}; //pozadi - int pravy[] = {0,0,199,70,Blue}; - int levy[] = {0,250,199,320,Blue}; + + + //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 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}; @@ -28,16 +37,30 @@ switch(press) { case 1: - spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]);// pravy + //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.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.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);// 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.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 @@ -48,11 +71,24 @@ default: - spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]); //pozadi - spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]); //pravy - 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.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]); //stred levy spodni + 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 } @@ -87,15 +123,34 @@ -void Button(){ - int pravy[] = {0,0,200,70,Black}; //pravý čudlík - int levy[] = {0,250,200,320,Black}; //levý čudlík + + +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 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()) @@ -113,12 +168,32 @@ //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){ - spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]); i = touch.DataAvailable(); - } + } grafika(1); + Menu(m); wait(0.2); } @@ -126,26 +201,47 @@ //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){ - spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]); i = touch.DataAvailable(); } grafika(2); - wait(0.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; + //int e = 0; while (i){ - spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]); i = touch.DataAvailable(); - e++; + //e++; } - printf("%d",e); + //printf("%d",e); grafika(3); wait(0.2); } @@ -155,8 +251,13 @@ //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){ - spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]); i = touch.DataAvailable(); } grafika(4); @@ -167,6 +268,9 @@ //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]); @@ -188,6 +292,24 @@ 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 + } } @@ -197,6 +319,81 @@ + +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(); @@ -204,6 +401,8 @@ spi.background(White); spi.cls(); //spi.circle(240,320,20,Black); + //wait_us(); + grafika(); Button(); @@ -215,18 +414,6 @@ /* fail projekty - - - - - - - - - - - - //slider if ((touch_x > cudlik[0]) && (touch_x < cudlik[2]) && (touch_y > cudlik[1]) && (touch_y < cudlik[3]) && (pressure > 0)){