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 Oxford CWM Team

Committer:
Owenmatthewmcgowan
Date:
Fri May 26 09:37:06 2017 +0000
Revision:
49:243b5e826228
Parent:
48:76ac309a2bd9
merge;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Owenmatthewmcgowan 28:53a5429976e4 1 int setting_press()
Owenmatthewmcgowan 28:53a5429976e4 2 {
Owenmatthewmcgowan 24:93e1474d6d8b 3 int x = readX();
Owenmatthewmcgowan 24:93e1474d6d8b 4 int y = readY();
Owenmatthewmcgowan 24:93e1474d6d8b 5 if (touching == 1) {
Owenmatthewmcgowan 28:53a5429976e4 6 if (x > 0 && x < 50 && y > 0 & y < 100) { // side button 1 (set)
Owenmatthewmcgowan 28:53a5429976e4 7 //set desired state to 1
Owenmatthewmcgowan 24:93e1474d6d8b 8 return 1;
Owenmatthewmcgowan 28:53a5429976e4 9 } else if (x > 0 && x < 50 && y > 100 & y < 200) { //side button 2 (cancel)
Owenmatthewmcgowan 28:53a5429976e4 10 //set desired state to 2
Owenmatthewmcgowan 24:93e1474d6d8b 11 return 2;
Owenmatthewmcgowan 28:53a5429976e4 12 } else if (x > 0 && x < 50 && y > 200 && y < 240) { // button home
Owenmatthewmcgowan 24:93e1474d6d8b 13 //set desired state to 0
Owenmatthewmcgowan 24:93e1474d6d8b 14 return 0;
Owenmatthewmcgowan 28:53a5429976e4 15 } else if (x > 50 && x < 185 && y > 0 && y < 100) { // Alarm Hour
Owenmatthewmcgowan 24:93e1474d6d8b 16 return 11;
Owenmatthewmcgowan 28:53a5429976e4 17 } else if (x > 185 && x < 320 && y > 0 && y < 100) { // Alarm Min
Owenmatthewmcgowan 24:93e1474d6d8b 18 return 12;
Owenmatthewmcgowan 28:53a5429976e4 19 } else if (x > 50 && x < 185 && y > 100 && y < 200) { //Time Hour
Owenmatthewmcgowan 24:93e1474d6d8b 20 return 13;
Owenmatthewmcgowan 28:53a5429976e4 21 } else if (x > 185 && x < 320 && y > 100 && y < 200) { //Time Min
Owenmatthewmcgowan 28:53a5429976e4 22 return 14;
Owenmatthewmcgowan 28:53a5429976e4 23 } else if (x > 50 && x < 140 && y > 200 && y < 300) { //Time Date
Owenmatthewmcgowan 28:53a5429976e4 24 return 15;
Owenmatthewmcgowan 28:53a5429976e4 25 } else if (x > 140 && x < 230 && y > 200 && y < 300) { //Time Month
Owenmatthewmcgowan 28:53a5429976e4 26 return 16;
Owenmatthewmcgowan 28:53a5429976e4 27 } else if (x > 230 && x < 320 && y > 200 && y < 300) { //Time Year
Owenmatthewmcgowan 28:53a5429976e4 28 return 17;
Owenmatthewmcgowan 24:93e1474d6d8b 29 }
Owenmatthewmcgowan 24:93e1474d6d8b 30 }
Owenmatthewmcgowan 24:93e1474d6d8b 31 return -1;
Owenmatthewmcgowan 24:93e1474d6d8b 32 }
Owenmatthewmcgowan 12:50289d0ac834 33
Owenmatthewmcgowan 15:796e17680825 34 void drawsettingback() //Navigation Buttons
Owenmatthewmcgowan 12:50289d0ac834 35 {
Owenmatthewmcgowan 30:af38c80391cb 36 TFT.cls();
Owenmatthewmcgowan 28:53a5429976e4 37 TFT.fillrect(0,0,50,100,Blue); //set alarm button
Owenmatthewmcgowan 12:50289d0ac834 38 TFT.fillrect(0,100,50,200,White); //set time button
Owenmatthewmcgowan 12:50289d0ac834 39
Owenmatthewmcgowan 28:53a5429976e4 40
Owenmatthewmcgowan 12:50289d0ac834 41 TFT.rect(0,0,50,100,Blue); //outlines
Owenmatthewmcgowan 12:50289d0ac834 42 TFT.rect(0,100,50,200,White); //outlines
Owenmatthewmcgowan 12:50289d0ac834 43 TFT.rect(0,200,50,240,White); //outlines
Owenmatthewmcgowan 28:53a5429976e4 44
Owenmatthewmcgowan 15:796e17680825 45 //alarm/time colons
Owenmatthewmcgowan 28:53a5429976e4 46 int tx,ty = 0;
Owenmatthewmcgowan 28:53a5429976e4 47 ty = 50;
Owenmatthewmcgowan 28:53a5429976e4 48 tx = 185;
Owenmatthewmcgowan 28:53a5429976e4 49 TFT.fillcircle(tx, ty - 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 50 TFT.fillcircle(tx, ty + 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 51 ty = 150;
Owenmatthewmcgowan 28:53a5429976e4 52 TFT.fillcircle(tx, ty - 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 53 TFT.fillcircle(tx, ty + 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 54 TFT.rect(50,0,320,100,Blue); //set alarm box
Owenmatthewmcgowan 12:50289d0ac834 55 TFT.rect(50,100,320,200,White); //set time box
Owenmatthewmcgowan 12:50289d0ac834 56 TFT.rect(50,200,320,240,White); //set date box
Owenmatthewmcgowan 13:e74e09de81e4 57
Owenmatthewmcgowan 12:50289d0ac834 58 TFT.set_font((unsigned char*) Arial12x12); //set alarm title
Owenmatthewmcgowan 15:796e17680825 59 TFT.locate(157,8);
Owenmatthewmcgowan 12:50289d0ac834 60 TFT.printf("Set Alarm");
Owenmatthewmcgowan 27:a895a2c9acb8 61 TFT.set_font((unsigned char*) Arial12x12); //set time title
Owenmatthewmcgowan 27:a895a2c9acb8 62 TFT.locate(157,108);
Owenmatthewmcgowan 27:a895a2c9acb8 63 TFT.printf("Set Time");
Owenmatthewmcgowan 28:53a5429976e4 64 //Cancel button
Owenmatthewmcgowan 28:53a5429976e4 65 TFT.set_font((unsigned char*) Arial12x12);
mlin 25:ff73360cd038 66 TFT.locate(62,20);
mlin 25:ff73360cd038 67 TFT.set_orientation(0);
mlin 25:ff73360cd038 68 TFT.background(White);
mlin 25:ff73360cd038 69 TFT.foreground(Black);
mlin 25:ff73360cd038 70 TFT.printf("Cancel");
mlin 25:ff73360cd038 71 TFT.background(Black);
mlin 25:ff73360cd038 72 TFT.foreground(White);
mlin 25:ff73360cd038 73 TFT.set_orientation(1);
mlin 25:ff73360cd038 74
mlin 25:ff73360cd038 75 //Set New button (used to set new alarm/time/date)
Owenmatthewmcgowan 28:53a5429976e4 76
mlin 25:ff73360cd038 77 TFT.locate(161,20);
mlin 25:ff73360cd038 78 TFT.set_orientation(0);
mlin 25:ff73360cd038 79 TFT.background(Blue);
mlin 25:ff73360cd038 80 TFT.printf("Set New");
mlin 25:ff73360cd038 81 TFT.background(Black);
mlin 25:ff73360cd038 82 TFT.set_orientation(1);
Owenmatthewmcgowan 28:53a5429976e4 83 //home button
mlin 25:ff73360cd038 84 TFT.locate(5,217);
mlin 25:ff73360cd038 85 TFT.foreground(Blue);
mlin 25:ff73360cd038 86 TFT.printf("Home");
mlin 25:ff73360cd038 87 TFT.foreground(White);
mlin 25:ff73360cd038 88 }
mlin 25:ff73360cd038 89
Owenmatthewmcgowan 28:53a5429976e4 90 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
mlin 25:ff73360cd038 91 {
Owenmatthewmcgowan 28:53a5429976e4 92
Owenmatthewmcgowan 12:50289d0ac834 93
mlin 18:02667782b06f 94
Owenmatthewmcgowan 12:50289d0ac834 95 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour
mlin 18:02667782b06f 96
Owenmatthewmcgowan 15:796e17680825 97 TFT.locate(90,40);
Owenmatthewmcgowan 28:53a5429976e4 98 TFT.printf("%d",a_h); // print Alarm hour
Owenmatthewmcgowan 15:796e17680825 99 TFT.locate(230,40);
Owenmatthewmcgowan 28:53a5429976e4 100 TFT.printf("%d",a_m);//Alarm_Min
Owenmatthewmcgowan 12:50289d0ac834 101 TFT.set_font((unsigned char*) Arial28x28); //set time hour
Owenmatthewmcgowan 15:796e17680825 102 TFT.locate(90,140);
Owenmatthewmcgowan 28:53a5429976e4 103 TFT.printf("%d",t_h); // Time_hour
Owenmatthewmcgowan 15:796e17680825 104 TFT.locate(230,140);
Owenmatthewmcgowan 28:53a5429976e4 105 TFT.printf("%d",t_m);//Time Min
Owenmatthewmcgowan 15:796e17680825 106 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 15:796e17680825 107 TFT.locate(60,215);
Owenmatthewmcgowan 28:53a5429976e4 108 TFT.printf("%d",t_d); //print date
Owenmatthewmcgowan 15:796e17680825 109 TFT.locate(150,215);
Owenmatthewmcgowan 28:53a5429976e4 110 TFT.printf("%d",t_mo); //print month
Owenmatthewmcgowan 15:796e17680825 111 TFT.locate(265,215);
Owenmatthewmcgowan 28:53a5429976e4 112 TFT.printf("%d",t_y); //print year
Owenmatthewmcgowan 12:50289d0ac834 113
Owenmatthewmcgowan 28:53a5429976e4 114
Owenmatthewmcgowan 28:53a5429976e4 115
Owenmatthewmcgowan 15:796e17680825 116
mlin 16:3cb9b1fbc039 117 }
Owenmatthewmcgowan 28:53a5429976e4 118 void settings()
Owenmatthewmcgowan 28:53a5429976e4 119 {
mlin 25:ff73360cd038 120 int a_h, a_m, t_h, t_m,t_d,t_mo,t_y = 0;
Owenmatthewmcgowan 28:53a5429976e4 121 a_h = tm_a_hr;
Owenmatthewmcgowan 29:684e2a3e17b5 122 a_m = tm_a_min;
Owenmatthewmcgowan 28:53a5429976e4 123 t_h = tm_c.hour;
Owenmatthewmcgowan 28:53a5429976e4 124 t_m = tm_c.min;
Owenmatthewmcgowan 28:53a5429976e4 125 t_d = tm_c.date;
Owenmatthewmcgowan 29:684e2a3e17b5 126 t_mo = tm_c.mon;
Owenmatthewmcgowan 28:53a5429976e4 127 t_y = tm_c.year;
Owenmatthewmcgowan 29:684e2a3e17b5 128 int multiplier = 8;
Owenmatthewmcgowan 26:47271cf8d6b2 129 int o_setting = 11;
Owenmatthewmcgowan 29:684e2a3e17b5 130 drawsettingback();
Owenmatthewmcgowan 30:af38c80391cb 131 int option = 0;
mlin 31:3255668e6b08 132 float tsi_current, tsi_last;
Owenmatthewmcgowan 28:53a5429976e4 133 while (true){
Owenmatthewmcgowan 29:684e2a3e17b5 134 drawsettinganimate(a_h, a_m,t_h,t_m,t_d,t_mo,t_y);
Owenmatthewmcgowan 30:af38c80391cb 135 option = setting_press();
Owenmatthewmcgowan 29:684e2a3e17b5 136 int newval = 0;
mlin 31:3255668e6b08 137 if (option == 0 || option == 2) {
mlin 31:3255668e6b08 138 pc.printf("exiting");
mlin 31:3255668e6b08 139 break;
mlin 31:3255668e6b08 140 }
Owenmatthewmcgowan 28:53a5429976e4 141 switch (option) {
Owenmatthewmcgowan 28:53a5429976e4 142 case (11):
Owenmatthewmcgowan 28:53a5429976e4 143 o_setting = 11;
Owenmatthewmcgowan 28:53a5429976e4 144 break; //Alarm Hour
Owenmatthewmcgowan 28:53a5429976e4 145 case (12):
Owenmatthewmcgowan 28:53a5429976e4 146 o_setting = 12;
Owenmatthewmcgowan 28:53a5429976e4 147 break; //Alarm Min
Owenmatthewmcgowan 28:53a5429976e4 148 case (13):
Owenmatthewmcgowan 28:53a5429976e4 149 o_setting = 13;
Owenmatthewmcgowan 28:53a5429976e4 150 break; //
Owenmatthewmcgowan 28:53a5429976e4 151 case (14):
Owenmatthewmcgowan 28:53a5429976e4 152 o_setting = 14;
Owenmatthewmcgowan 28:53a5429976e4 153 break; //
Owenmatthewmcgowan 28:53a5429976e4 154 case (15):
Owenmatthewmcgowan 28:53a5429976e4 155 o_setting = 15;
Owenmatthewmcgowan 28:53a5429976e4 156 break; //
Owenmatthewmcgowan 28:53a5429976e4 157 case (16):
Owenmatthewmcgowan 28:53a5429976e4 158 o_setting = 16;
Owenmatthewmcgowan 28:53a5429976e4 159 break; //
Owenmatthewmcgowan 28:53a5429976e4 160 case (17):
Owenmatthewmcgowan 28:53a5429976e4 161 o_setting = 17;
Owenmatthewmcgowan 28:53a5429976e4 162 break; //
Owenmatthewmcgowan 26:47271cf8d6b2 163 }
mlin 31:3255668e6b08 164
mlin 31:3255668e6b08 165 tsi_current = tsi.readPercentage();
mlin 31:3255668e6b08 166 float change = 0;
mlin 31:3255668e6b08 167
mlin 31:3255668e6b08 168 if (tsi_current != 0 && tsi_last != 0) {change = tsi_current - tsi_last;}
mlin 31:3255668e6b08 169 else {change = 0;}
mlin 31:3255668e6b08 170 tsi_last = tsi_current;
mlin 31:3255668e6b08 171 int delta = change * multiplier;
mlin 31:3255668e6b08 172 pc.printf("change in slider:%f, change in total:%f",change,delta);
Owenmatthewmcgowan 28:53a5429976e4 173 switch (o_setting) {
Owenmatthewmcgowan 26:47271cf8d6b2 174 case(11):
mlin 31:3255668e6b08 175
mlin 31:3255668e6b08 176 newval = a_h + delta ;
Owenmatthewmcgowan 28:53a5429976e4 177 while (newval < 0) {
Owenmatthewmcgowan 28:53a5429976e4 178 newval += 24;
Owenmatthewmcgowan 28:53a5429976e4 179 }
Owenmatthewmcgowan 27:a895a2c9acb8 180 a_h = newval % 25;
Owenmatthewmcgowan 27:a895a2c9acb8 181 TFT.fillrect(70, 40, 150, 80, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 182 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour
Owenmatthewmcgowan 27:a895a2c9acb8 183 TFT.locate(90,40);
Owenmatthewmcgowan 27:a895a2c9acb8 184 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 185 TFT.printf("%d", a_h);//Alarm_Hour
Owenmatthewmcgowan 28:53a5429976e4 186 break;
Owenmatthewmcgowan 27:a895a2c9acb8 187 case(12):
mlin 31:3255668e6b08 188 newval = a_m + delta ;
Owenmatthewmcgowan 28:53a5429976e4 189 while (newval < 0) {
Owenmatthewmcgowan 28:53a5429976e4 190 newval += 60;
Owenmatthewmcgowan 28:53a5429976e4 191 }
Owenmatthewmcgowan 27:a895a2c9acb8 192 a_m = newval % 60;
Owenmatthewmcgowan 27:a895a2c9acb8 193 TFT.fillrect(200, 40, 300, 80, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 194 TFT.set_font((unsigned char*) Arial28x28); //set alarm min
Owenmatthewmcgowan 27:a895a2c9acb8 195 TFT.locate(230,40);
Owenmatthewmcgowan 27:a895a2c9acb8 196 TFT.foreground(Red);
Owenmatthewmcgowan 27:a895a2c9acb8 197 TFT.printf("%d", a_m);//Alarm_Min
Owenmatthewmcgowan 28:53a5429976e4 198 break;
Owenmatthewmcgowan 27:a895a2c9acb8 199 case(13): //set time hour
mlin 31:3255668e6b08 200 newval = t_h + delta ;
Owenmatthewmcgowan 26:47271cf8d6b2 201 if (newval < 0) newval += 24;
Owenmatthewmcgowan 48:76ac309a2bd9 202 t_h = newval % 24;
Owenmatthewmcgowan 28:53a5429976e4 203 TFT.fillrect(90, 140, 150, 180, Black);
Owenmatthewmcgowan 28:53a5429976e4 204 TFT.set_font((unsigned char*) Arial28x28);
Owenmatthewmcgowan 27:a895a2c9acb8 205 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 206 TFT.locate(90,140);
Owenmatthewmcgowan 28:53a5429976e4 207 TFT.printf("%d",t_h); // Time_hour
Owenmatthewmcgowan 28:53a5429976e4 208 break;
Owenmatthewmcgowan 27:a895a2c9acb8 209 case(14): //set time min
mlin 31:3255668e6b08 210 newval = t_m + delta ;
Owenmatthewmcgowan 27:a895a2c9acb8 211 if (newval < 0) newval += 60;
Owenmatthewmcgowan 28:53a5429976e4 212 t_m = newval % 60;
Owenmatthewmcgowan 28:53a5429976e4 213 TFT.fillrect(200, 140, 300, 180, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 214 TFT.set_font((unsigned char*) Arial28x28);
Owenmatthewmcgowan 27:a895a2c9acb8 215 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 216 TFT.locate(230,140);
Owenmatthewmcgowan 28:53a5429976e4 217 TFT.printf("%d",t_m);//Time Min
Owenmatthewmcgowan 28:53a5429976e4 218 break;
Owenmatthewmcgowan 27:a895a2c9acb8 219 case(15): // set time date
mlin 31:3255668e6b08 220 newval = t_d + delta ;
mlin 31:3255668e6b08 221 if (newval < 1) newval += 31;
Owenmatthewmcgowan 28:53a5429976e4 222 t_d = newval % 32;
Owenmatthewmcgowan 28:53a5429976e4 223 TFT.fillrect(55, 202, 148, 238, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 224 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 225 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 226 TFT.locate(60,215);
Owenmatthewmcgowan 28:53a5429976e4 227 TFT.printf("%d",t_d); //print date
Owenmatthewmcgowan 28:53a5429976e4 228 break;
Owenmatthewmcgowan 27:a895a2c9acb8 229 case(16): // set time month
mlin 31:3255668e6b08 230 newval = t_mo + delta ;
mlin 31:3255668e6b08 231 if (newval < 1) newval += 12;
mlin 31:3255668e6b08 232 t_mo = newval % 13 ;
mlin 31:3255668e6b08 233
Owenmatthewmcgowan 28:53a5429976e4 234 TFT.fillrect(148, 202, 263, 238, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 235 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 236 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 237 TFT.locate(150,215);
Owenmatthewmcgowan 28:53a5429976e4 238 TFT.printf("%d",t_mo); //print month
Owenmatthewmcgowan 28:53a5429976e4 239 break;
Owenmatthewmcgowan 27:a895a2c9acb8 240 case(17): //set time year
mlin 31:3255668e6b08 241 newval = t_y + delta ;
mlin 31:3255668e6b08 242 if (newval > 1970 && newval < 2700) t_y = newval;
Owenmatthewmcgowan 28:53a5429976e4 243 TFT.fillrect(263, 202, 310, 238, Black);
Owenmatthewmcgowan 26:47271cf8d6b2 244 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 245 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 246 TFT.locate(265,215);
Owenmatthewmcgowan 28:53a5429976e4 247 TFT.printf("%d",t_y); //print year
Owenmatthewmcgowan 28:53a5429976e4 248 break;
Owenmatthewmcgowan 28:53a5429976e4 249 }
Owenmatthewmcgowan 28:53a5429976e4 250 TFT.foreground(White);
Owenmatthewmcgowan 28:53a5429976e4 251 if (option == 1) {
Owenmatthewmcgowan 28:53a5429976e4 252 tm_a_hr = a_h;
Owenmatthewmcgowan 29:684e2a3e17b5 253 tm_a_min = a_m;
Owenmatthewmcgowan 29:684e2a3e17b5 254 tm_c.min = t_m;
Owenmatthewmcgowan 29:684e2a3e17b5 255 tm_c.hour = t_h;
Owenmatthewmcgowan 29:684e2a3e17b5 256 tm_c.date = t_d;
Owenmatthewmcgowan 29:684e2a3e17b5 257 tm_c.mon = t_mo;
Owenmatthewmcgowan 29:684e2a3e17b5 258 tm_c.year = t_y;
mlin 38:3fe3bafbf0c7 259 tm_c.wday = date2day(tm_c.date, tm_c.mon, tm_c.year);
Owenmatthewmcgowan 29:684e2a3e17b5 260 while (!rtc.setTime(tm_c, true, false)) { //set the Time in RTC Param : ( Time container, Start Clock, Twelve Hour Clock)
Owenmatthewmcgowan 29:684e2a3e17b5 261 // n++;
Owenmatthewmcgowan 29:684e2a3e17b5 262 }
Owenmatthewmcgowan 29:684e2a3e17b5 263 // pc.printf("Tried to write %d times\n\r",n);
Owenmatthewmcgowan 28:53a5429976e4 264 break;
Owenmatthewmcgowan 28:53a5429976e4 265 }
Owenmatthewmcgowan 28:53a5429976e4 266 }
Owenmatthewmcgowan 28:53a5429976e4 267 f_state = 1;
mlin 25:ff73360cd038 268 }