Toto je má konečná verze maturitního projektu
Dependencies: mbed mbed-rtos UTouch_vyrobek UniGraphic
Diff: display.cpp
- Revision:
- 10:0176705be216
- Parent:
- 9:d1385f7171af
- Child:
- 11:4ca8388080c6
--- a/display.cpp Sat Jan 08 10:54:51 2022 +0000 +++ b/display.cpp Sun Jan 16 12:06:03 2022 +0000 @@ -8,25 +8,38 @@ DigitalOut my_blue(LED3); DigitalOut led2(LED2); Thread thread; -PwmOut br(D9); +PwmOut br(D10); +float lcd_jas = 0.50f; +int jas[] = {Green,Red}; +int jas_s = 2; +int jazyk_s = 0; +int cas_hodiny = 0; +int cas_minuty = 0; int cas_nastavit = 1037059200; +int time_on = 1037074920; +int time_off = 1037075100; int lang = 0; +char minutka[32]; +char hodinka[32]; char buffer[32]; -char jazyk [3][20] = { +char jazyk [4][150] = { "Czech", "English", - " Set Time" + " Set Time", + "Brightness" }; -char en[3][20] = { +char en[4][150] = { "Czech", "English", - " Set Time" + " Set Time", + "Brightness" }; -char cz[3][20] = { +char cz[4][150] = { "Cestina", "Anglictina", - "Nastavit cas" + "Nastavit cas", + " Jas" }; @@ -54,6 +67,9 @@ 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 +4x doprava jas pro cudliky v menu + + */ @@ -78,15 +94,15 @@ break; case 7: //zrusit spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch); - spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit);// levy + spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit); spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek); spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek); break; case 9: //potvrdit spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch); - spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit); // pravy + spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit); spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek); - spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek); //pravy + spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek); break; case 3: spi.Bitmap(0,200,80,40,(unsigned char*)gImage_spodni_levy); @@ -308,7 +324,9 @@ hold(); spi.Bitmap(60,10,48,24,(unsigned char*)gImage_cudlik1_vrch); spi.Bitmap(60,34,48,24,(unsigned char*)gImage_cudlik1_spodek); - wait(0.2); + wait(0.2); + grafika(7); + grafika(9); Static(); } @@ -429,7 +447,7 @@ //GRAFIKA************************************************** spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch_s); - spi.Bitmap(274,72,46,42,(unsigned char*)gImage_cudlik_otoc_s); + spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit_s); spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek_s); spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek_s); //GRAFIKA************************************************** @@ -438,6 +456,7 @@ my_green = g; my_blue = b; grafika(1); + grafika(2); Menu(); wait(0.2); } @@ -447,13 +466,14 @@ if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){ //GRAFIKA************************************************** spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch_s); - spi.Bitmap(0,72,46,42,(unsigned char*)gImage_cudlik_s);// levy + spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit_s);// levy spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek_s); spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek_s); //GRAFIKA************************************************** hold(); grafika(2); + grafika(1); wait(0.2); Menu(); } @@ -490,27 +510,27 @@ int pravy[] = {34,0,165,46}; //pravý čudlík int levy[] = {34,274,165,320}; //levý čudlík int i = 0; - int jazyk_s = 0; + spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi); int check1[] = {66,10,96,40}; int check2[] = {66,56,96,86}; - int prvni[] = {46,0,273,46}; //pravý čudlík - int druhy[] = {46,46,273,92}; //pravý čudlík - int treti[] = {46,92,273,138}; //pravý čudlík + int prvni[] = {46,0,273,46}; //prvni čudlík + int druhy[] = {46,46,273,92}; //druhy čudlík + int treti[] = {46,92,273,138}; //treti čudlík + int ctvrty[] = {46,138,273,184}; //treti čudlík + spi.background(MojeSeda); spi.fillrect(prvni[0],prvni[1],prvni[2],prvni[3],MojeSeda); //prvni spi.rect(prvni[0],prvni[1],prvni[2],prvni[3],White); //prvni - //spi.fillrect(check1[0],check1[1],check1[2],check1[3],Red); spi.set_font((unsigned char*) Arial28x28); spi.locate(140,14); spi.printf(jazyk[0]); spi.fillrect(druhy[0],druhy[1],druhy[2],druhy[3],MojeSeda); //druhy spi.rect(druhy[0],druhy[1],druhy[2],druhy[3],White); //druhy - // spi.fillrect(check2[0],check2[1],check2[2],check2[3],Red); spi.locate(140,60); spi.printf(jazyk[1]); @@ -530,7 +550,13 @@ spi.rect(treti[0],treti[1],treti[2],treti[3],White); //treti spi.locate(90,106); spi.printf(jazyk[2]); - + + spi.fillrect(ctvrty[0],ctvrty[1],ctvrty[2],ctvrty[3],MojeSeda); //ctvrty + spi.rect(ctvrty[0],ctvrty[1],ctvrty[2],ctvrty[3],White); //ctvrty + spi.locate(95,152); + spi.printf(jazyk[3]); + + while(1){ if (touch.DataAvailable()) { @@ -552,13 +578,13 @@ switch(jazyk_s) { case 1: - while(i < 3){ + while(i < 4){ strcpy(jazyk[i], cz[i]); i++; } break; default: - while(i < 3){ + while(i < 4){ strcpy(jazyk[i], en[i]); i++; } @@ -609,7 +635,10 @@ hold(); nastavit_hodiny(); } - +if((touch_x > ctvrty[1]) && (touch_x < ctvrty[3]) && (touch_y < ctvrty[2]) && (touch_y > ctvrty[0])){ + hold(); + brightness(); +} } @@ -618,28 +647,65 @@ } -void nastavit_hodiny(){ + +void brightness(){ + spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi); int pravy[] = {34,0,165,46}; //pravý čudlík int levy[] = {34,274,165,320}; //levý čudlík - - int green1[] = {180,65,249,134}; - int blue1[] = {71,65,140,134}; -/* - int nahoru1[] = {71,34,140,57}; - int dolu1[] = {71,142,140,165}; + int p10t[] = {229,52,264,147}; + int p30t[] = {186,52,221,147}; + int p50t[] = {143,52,178,147}; + int p70t[] = {100,52,135,147}; + int p90t[] = {57,52,92,147}; + + int p10[] = {57,52,92,147}; + int p30[] = {100,52,135,147}; + int p50[] = {143,52,178,147}; + int p70[] = {186,52,221,147}; + int p90[] = {229,52,264,147}; + + switch(jas_s){ + case 0: + spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]); + spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[1]); + spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[1]); + spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[1]); + spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]); + break; + case 1: + spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]); + spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]); + spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[1]); + spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[1]); + spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]); + break; + case 2: + spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]); + spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]); + spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[0]); + spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[1]); + spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]); + break; + case 3: + spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]); + spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]); + spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[0]); + spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[0]); + spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]); + break; + case 4: + spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]); + spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]); + spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[0]); + spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[0]); + spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[0]); + break; + default: + printf("err"); - int nahoru2[] = {}; - int dolu2[] = {}; - */ -spi.Bitmap(71,34,69,23,(unsigned char*)gImage_nahoru); - - //spi.fillrect(nahoru1[0],nahoru1[1],nahoru1[2],nahoru1[3],Green); - //spi.fillrect(dolu1[0],dolu1[1],dolu1[2],dolu1[3],Green); - spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi); + } - spi.fillrect(green1[0],green1[1],green1[2],green1[3],Green); - spi.fillrect(blue1[0],blue1[1],blue1[2],blue1[3],Blue); while(1){ if (touch.DataAvailable()) { @@ -660,6 +726,7 @@ hold(); grafika(9); + br.write(lcd_jas); nastaveni(); wait(0.2); } @@ -675,12 +742,263 @@ //GRAFIKA************************************************** hold(); + lcd_jas = 0.00f; grafika(7); nastaveni(); wait(0.2); } //levý čudlik +if((touch_x > p10t[1]) && (touch_x < p10t[3]) && (touch_y < p10t[2]) && (touch_y > p10t[0])){ + hold(); + jas_s = 0; + lcd_jas = 0.10f; + brightness(); + +} + +if((touch_x > p30t[1]) && (touch_x < p30t[3]) && (touch_y < p30t[2]) && (touch_y > p30t[0])){ + hold(); + jas_s = 1; + lcd_jas = 0.30f; + brightness(); +} +if((touch_x > p50t[1]) && (touch_x < p50t[3]) && (touch_y < p50t[2]) && (touch_y > p50t[0])){ + hold(); + jas_s = 2; + lcd_jas = 0.50f; + brightness(); + +} +if((touch_x > p70t[1]) && (touch_x < p70t[3]) && (touch_y < p70t[2]) && (touch_y > p70t[0])){ + hold(); + jas_s = 3; + lcd_jas = 0.70f; + brightness(); +} +if((touch_x > p90t[1]) && (touch_x < p90t[3]) && (touch_y < p90t[2]) && (touch_y > p90t[0])){ + hold(); + jas_s = 4; + lcd_jas = 0.90f; + brightness(); +} + + + } +} +} +} + + + +void nastavit_hodiny(){ + int pravy[] = {34,0,165,46}; //pravý čudlík + int levy[] = {34,274,165,320}; //levý čudlík + + int up1[] = {172,28,258,57}; + int down1[] = {172,142,258,171}; + + int up2[] = {62,28,148,57}; + int down2[] = {62,142,148,171}; + + cas_hodiny = atoi(hodinka); + cas_minuty = atoi(minutka); + + + int h1 = cas_hodiny / 10; + int h2 = cas_hodiny % 10; + + char cisla[10][3] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9" + }; + + int m1 = cas_minuty / 10; + int m2 = cas_minuty % 10; + + int blue1[] = {71,65,249,134}; + + spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi); + spi.Bitmap(62,28,86,29,(unsigned char*)gImage_nahoru); + spi.Bitmap(62,142,86,29,(unsigned char*)gImage_dolu); + + spi.Bitmap(172,28,86,29,(unsigned char*)gImage_nahoru); + spi.Bitmap(172,142,86,29,(unsigned char*)gImage_dolu); + + + + spi.fillrect(blue1[0],blue1[1],blue1[2],blue1[3],MojeSeda); + + spi.set_font((unsigned char*) Arial48x47); + spi.background(MojeSeda); + spi.locate(80,80); + spi.printf(cisla[h1]); + spi.locate(110,80); + spi.printf(cisla[h2]); + spi.locate(155,80); + spi.printf(":"); + spi.locate(189,80); + spi.printf(cisla[m1]); + spi.locate(219,80); + spi.printf(cisla[m2]); + + + 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])){ + + //GRAFIKA************************************************** + spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch_s); + spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit_s); + spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek_s); + spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek_s); + //GRAFIKA************************************************** + hold(); + thread.terminate(); + cas_nastavit = 1037059200 + (cas_hodiny * 3600) + (cas_minuty * 60); + thread.start(hodiny); + grafika(9); + nastaveni(); + 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(0,34,46,38,(unsigned char*)gImage_vrch_s); + spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit_s);// levy + spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek_s); + spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek_s); + //GRAFIKA************************************************** + + hold(); + + + + grafika(7); + nastaveni(); + wait(0.2); + } + //levý čudlik +if((touch_x > up1[1]) && (touch_x < up1[3]) && (touch_y < up1[2]) && (touch_y > up1[0])){ + spi.Bitmap(62,28,86,29,(unsigned char*)gImage_nahoru_s); + while ((touch.DataAvailable()) && (h2 < 10)){ + h2++; + cas_hodiny++; + if(cas_hodiny == 24){ + cas_hodiny = 0; + } + if(h2 == 10){ + h2 = 0; + h1++; + } + if((h1 == 2)&&(h2 == 4)){ + h2 = 0; + h1 = 0; + } + + spi.locate(80,80); + spi.printf(cisla[h1]); + spi.locate(110,80); + spi.printf(cisla[h2]); + + + wait(0.1); + } + spi.Bitmap(62,28,86,29,(unsigned char*)gImage_nahoru); +} +if((touch_x > down1[1]) && (touch_x < down1[3]) && (touch_y < down1[2]) && (touch_y > down1[0])){ + spi.Bitmap(62,142,86,29,(unsigned char*)gImage_dolu_s); + while ((touch.DataAvailable()) && (h2 < 10)){ + h2--; + if((h2 < 0)&&(h1 == 0)){ + h2 = 3; + h1 = 2; + } + if(h2 < 0){ + h2 = 9; + h1--; + } + cas_hodiny--; + if(cas_hodiny < 0){ + cas_hodiny = 23; + } + spi.locate(80,80); + spi.printf(cisla[h1]); + spi.locate(110,80); + spi.printf(cisla[h2]); + wait(0.1); + } + spi.Bitmap(62,142,86,29,(unsigned char*)gImage_dolu); +} +if((touch_x > up2[1]) && (touch_x < up2[3]) && (touch_y < up2[2]) && (touch_y > up2[0])){ + spi.Bitmap(172,28,86,29,(unsigned char*)gImage_nahoru_s); + while ((touch.DataAvailable()) && (m2 < 10)){ + m2++; + cas_minuty++; + if(cas_minuty == 60){ + cas_minuty = 0; + } + if((m1 == 5)&&(m2 == 10)){ + m2 = 0; + m1 = 0; + } + if(m2 == 10){ + m2 = 0; + m1++; + } + + spi.locate(189,80); + spi.printf(cisla[m1]); + spi.locate(219,80); + spi.printf(cisla[m2]); + wait(0.1); + } + + spi.Bitmap(172,28,86,29,(unsigned char*)gImage_nahoru); +} +if((touch_x > down2[1]) && (touch_x < down2[3]) && (touch_y < down2[2]) && (touch_y > down2[0])){ + spi.Bitmap(172,142,86,29,(unsigned char*)gImage_dolu_s); + while ((touch.DataAvailable()) && (m2 < 10)){ + m2--; + if((m2 < 0)&&(m1 == 0)){ + m2 = 9; + m1 = 5; + } + if(m2 < 0){ + m2 = 9; + m1--; + } + cas_minuty--; + if(cas_minuty < 0){ + cas_minuty = 59; + } + spi.locate(189,80); + spi.printf(cisla[m1]); + spi.locate(219,80); + spi.printf(cisla[m2]); + wait(0.1); + } + + spi.Bitmap(172,142,86,29,(unsigned char*)gImage_dolu); +} + } } @@ -688,12 +1006,23 @@ } + + void hodiny(){ set_time(cas_nastavit); while(1){ time_t seconds = time(NULL); //seconds = seconds + 7200; + if(seconds == time_on){ + printf("ON\r\n"); + } + if(seconds == time_off){ + printf("OFF\r\n"); + } strftime(buffer, 32, "%R", localtime(&seconds)); + strftime(hodinka, 32, "%H", localtime(&seconds)); + strftime(minutka, 32, "%M", localtime(&seconds)); + printf("%s\r\n",buffer); Thread::wait(1000); } } @@ -715,25 +1044,11 @@ grafika(); br.period_us(1000); - br.write(0.50f); - /* wait_ms(3000); + br.write(lcd_jas); + - br.write(0.25f); - wait_ms(3000); - br.write(0.0f); - wait_ms(3000); - br.write(0.25f); - wait_ms(3000); - br.write(0.50f); - wait_ms(5000); - br.write(0.80f); - */ - - grafika(7); - grafika(9); - //nastaveni(); - nastavit_hodiny(); - thread.start(hodiny); + /* nastavit_hodiny(); + thread.start(hodiny);*/ Button();