Contains the main execution of the clock uses headers to import functions
Dependencies: RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor
Fork of TFT_Mikroelectronika_IL9341_sketchpad by
Revision 28:53a5429976e4, committed 2017-05-25
- Comitter:
- Owenmatthewmcgowan
- Date:
- Thu May 25 12:57:32 2017 +0000
- Parent:
- 27:a895a2c9acb8
- Child:
- 29:684e2a3e17b5
- Commit message:
- wrote settings page
Changed in this revision
settings.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/settings.h Thu May 25 12:37:32 2017 +0000 +++ b/settings.h Thu May 25 12:57:32 2017 +0000 @@ -1,74 +1,56 @@ -int setting_press(){ +int setting_press() +{ int x = readX(); int y = readY(); if (touching == 1) { - if (x > 0 && x < 50 && y > 0 & y < 100) // side button 1 (set) - { - //set desired state to 1 + if (x > 0 && x < 50 && y > 0 & y < 100) { // side button 1 (set) + //set desired state to 1 return 1; - } - else if (x > 0 && x < 50 && y > 100 & y < 200) //side button 2 (cancel) - { - //set desired state to 2 + } else if (x > 0 && x < 50 && y > 100 & y < 200) { //side button 2 (cancel) + //set desired state to 2 return 2; - } - else if (x > 0 && x < 50 && y > 200 && y < 240) // button home - { + } else if (x > 0 && x < 50 && y > 200 && y < 240) { // button home //set desired state to 0 return 0; - } - else if (x > 50 && x < 185 && y > 0 && y < 100) // Alarm Hour - { + } else if (x > 50 && x < 185 && y > 0 && y < 100) { // Alarm Hour return 11; - } - else if (x > 185 && x < 320 && y > 0 && y < 100) // Alarm Min - { + } else if (x > 185 && x < 320 && y > 0 && y < 100) { // Alarm Min return 12; - } - else if (x > 50 && x < 185 && y > 100 && y < 200) //Time Hour - { + } else if (x > 50 && x < 185 && y > 100 && y < 200) { //Time Hour return 13; + } else if (x > 185 && x < 320 && y > 100 && y < 200) { //Time Min + return 14; + } else if (x > 50 && x < 140 && y > 200 && y < 300) { //Time Date + return 15; + } else if (x > 140 && x < 230 && y > 200 && y < 300) { //Time Month + return 16; + } else if (x > 230 && x < 320 && y > 200 && y < 300) { //Time Year + return 17; } - else if (x > 185 && x < 320 && y > 100 && y < 200)//Time Min - { - return 14; - } - else if (x > 50 && x < 140 && y > 200 && y < 300)//Time Date - { - return 15; - } - else if (x > 140 && x < 230 && y > 200 && y < 300)//Time Month - { - return 16; - } - else if (x > 230 && x < 320 && y > 200 && y < 300) //Time Year - { - return 17; - } } return -1; } void drawsettingback() //Navigation Buttons { - TFT.fillrect(0,0,50,100,Blue); //set alarm button + TFT.fillrect(0,0,50,100,Blue); //set alarm button TFT.fillrect(0,100,50,200,White); //set time button - + TFT.rect(0,0,50,100,Blue); //outlines TFT.rect(0,100,50,200,White); //outlines TFT.rect(0,200,50,240,White); //outlines - + //alarm/time colons - int tx,ty = 0; - ty = 50; - tx = 185; - TFT.fillcircle(tx, ty - 10, 2, White); - TFT.fillcircle(tx, ty + 10, 2, White); - ty = 150; - TFT.fillcircle(tx, ty - 10, 2, White); - TFT.fillcircle(tx, ty + 10, 2, White); - TFT.rect(50,0,320,100,Blue); //set alarm box + int tx,ty = 0; + ty = 50; + tx = 185; + TFT.fillcircle(tx, ty - 10, 2, White); + TFT.fillcircle(tx, ty + 10, 2, White); + ty = 150; + TFT.fillcircle(tx, ty - 10, 2, White); + TFT.fillcircle(tx, ty + 10, 2, White); + TFT.rect(50,0,320,100,Blue); //set alarm box TFT.rect(50,100,320,200,White); //set time box TFT.rect(50,200,320,240,White); //set date box @@ -78,8 +60,8 @@ TFT.set_font((unsigned char*) Arial12x12); //set time title TFT.locate(157,108); TFT.printf("Set Time"); - //Cancel button - TFT.set_font((unsigned char*) Arial12x12); + //Cancel button + TFT.set_font((unsigned char*) Arial12x12); TFT.locate(62,20); TFT.set_orientation(0); TFT.background(White); @@ -90,139 +72,172 @@ TFT.set_orientation(1); //Set New button (used to set new alarm/time/date) - + TFT.locate(161,20); TFT.set_orientation(0); TFT.background(Blue); TFT.printf("Set New"); TFT.background(Black); TFT.set_orientation(1); - //home button + //home button TFT.locate(5,217); TFT.foreground(Blue); TFT.printf("Home"); TFT.foreground(White); } -void drawsettinganimate() //draw alarm, time, date +void drawsettinganimate(int a_h, int a_m, int t_h, int t_m, int t_d, int t_mo, int t_y) //draw alarm, time, date { - + TFT.set_font((unsigned char*) Arial28x28); //set alarm hour TFT.locate(90,40); - - TFT.printf("AH");//Alarm_Hour - //set alarm mins + TFT.printf("%d",a_h); // print Alarm hour TFT.locate(230,40); - TFT.printf("AM");//Alarm_Min + TFT.printf("%d",a_m);//Alarm_Min TFT.set_font((unsigned char*) Arial28x28); //set time hour TFT.locate(90,140); - TFT.printf("TH"); // Time_hour - - //set time mins + TFT.printf("%d",t_h); // Time_hour TFT.locate(230,140); - TFT.printf("TM");//Time Min - - //set date day + TFT.printf("%d",t_m);//Time Min TFT.set_font((unsigned char*) Arial12x12); TFT.locate(60,215); - TFT.printf("day"); - - //set date month + TFT.printf("%d",t_d); //print date TFT.locate(150,215); - TFT.printf("month"); - - //set date year + TFT.printf("%d",t_mo); //print month TFT.locate(265,215); - TFT.printf("year"); + TFT.printf("%d",t_y); //print year - + + - } -void settings() { +void settings() +{ int a_h, a_m, t_h, t_m,t_d,t_mo,t_y = 0; + a_h = tm_a_hr; + a_m = tm_a_m; + t_h = tm_c.hour; + t_m = tm_c.min; + t_d = tm_c.date; + t_mo = tm_c.month; + t_y = tm_c.year; int multiplier = 8 int o_setting = 11; - while (true) + while (true){ int option = setting_press(); - if (option == 0) break; - switch (option) - { - case (11): o_setting = 11; break; //Alarm Hour - case (12): o_setting = 12; break; //Alarm Min - case (13): o_setting = 13; break; // - case (14): o_setting = 14; break; // - case (15): o_setting = 15; break; // - case (16): o_setting = 16; break; // - case (17): o_setting = 17; break; // + if (option == 0 || option == 2) break; + switch (option) { + case (11): + o_setting = 11; + break; //Alarm Hour + case (12): + o_setting = 12; + break; //Alarm Min + case (13): + o_setting = 13; + break; // + case (14): + o_setting = 14; + break; // + case (15): + o_setting = 15; + break; // + case (16): + o_setting = 16; + break; // + case (17): + o_setting = 17; + break; // } - switch (o_setting) - { + switch (o_setting) { case(11): newval = a_h + tsi.d() * multiplier; - while (newval < 0) {newval += 24;} + while (newval < 0) { + newval += 24; + } a_h = newval % 25; TFT.fillrect(70, 40, 150, 80, Black); TFT.set_font((unsigned char*) Arial28x28); //set alarm hour TFT.locate(90,40); TFT.foreground(Red); - TFT.printf("%d", a_h);//Alarm_Hour + TFT.printf("%d", a_h);//Alarm_Hour + break; case(12): newval = a_m + tsi.d() * multiplier; - while (newval < 0) {newval += 60;} + while (newval < 0) { + newval += 60; + } a_m = newval % 60; TFT.fillrect(200, 40, 300, 80, Black); TFT.set_font((unsigned char*) Arial28x28); //set alarm min TFT.locate(230,40); TFT.foreground(Red); TFT.printf("%d", a_m);//Alarm_Min + break; case(13): //set time hour - newval = a_h + tsi.d() * multiplier; + newval = t_h + tsi.d() * multiplier; if (newval < 0) newval += 24; - a_h = newval % 25; - TFT.fillrect(90, 40, 150, 80, Black); - TFT.set_font((unsigned char*) Arial28x28); - TFT.locate(90,40); + t_h = newval % 25; + TFT.fillrect(90, 140, 150, 180, Black); + TFT.set_font((unsigned char*) Arial28x28); TFT.foreground(Red); - TFT.printf("%d", a_h); + TFT.locate(90,140); + TFT.printf("%d",t_h); // Time_hour + break; case(14): //set time min - newval = a_h + tsi.d() * multiplier; + newval = t_m + tsi.d() * multiplier; if (newval < 0) newval += 60; - a_h = newval % 60; - TFT.fillrect(90, 40, 150, 80, Black); + t_m = newval % 60; + TFT.fillrect(200, 140, 300, 180, Black); TFT.set_font((unsigned char*) Arial28x28); - TFT.locate(90,40); TFT.foreground(Red); - TFT.printf("%d", a_h); + TFT.locate(230,140); + TFT.printf("%d",t_m);//Time Min + break; case(15): // set time date - newval = a_h + tsi.d() * multiplier; + newval = t_d + tsi.d() * multiplier; if (newval < 0) newval += 31; - a_h = newval % 32; - TFT.fillrect(90, 40, 150, 80, Black); - TFT.set_font((unsigned char*) Arial28x28); - TFT.locate(90,40); + t_d = newval % 32; + TFT.fillrect(55, 202, 148, 238, Black); TFT.foreground(Red); - TFT.printf("%d", a_h); + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(60,215); + TFT.printf("%d",t_d); //print date + break; case(16): // set time month newval = a_h + tsi.d() * multiplier; if (newval < 0) newval += 12; a_h = newval % 13; - TFT.fillrect(90, 40, 150, 80, Black); - TFT.set_font((unsigned char*) Arial28x28); - TFT.locate(90,40); + TFT.fillrect(148, 202, 263, 238, Black); TFT.foreground(Red); - TFT.printf("%d", a_h); + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(150,215); + TFT.printf("%d",t_mo); //print month + break; case(17): //set time year newval = a_h + tsi.d() * multiplier; if (newval > 1970 && newval < 2700) a_h = newval; - TFT.fillrect(90, 40, 150, 80, Black); - TFT.set_font((unsigned char*) Arial28x28); - TFT.locate(90,40); + TFT.fillrect(263, 202, 310, 238, Black); TFT.foreground(Red); - TFT.printf("%d", a_h);//Alarm_Hour - - + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(265,215); + TFT.printf("%d",t_y); //print year + break; + } + TFT.foreground(White); + if (option == 1) { + tm_a_hr = a_h; + tm_a_min == a_m; + &tm_c.min = t_m; + &tm_c.hour = t_h; + &tm_c.date = t_d; + &tm_c.month = t_mo; + &tm_c.year = t_y; + break; + } + } + f_state = 1; } \ No newline at end of file