IoT Ox / Mbed 2 deprecated MainSketch Featured

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor

Fork of TFT_Mikroelectronika_IL9341_sketchpad by Oxford CWM Team

Committer:
Owenmatthewmcgowan
Date:
Thu May 25 12:57:32 2017 +0000
Revision:
28:53a5429976e4
Parent:
27:a895a2c9acb8
Child:
29:684e2a3e17b5
wrote settings page

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 28:53a5429976e4 36 TFT.fillrect(0,0,50,100,Blue); //set alarm button
Owenmatthewmcgowan 12:50289d0ac834 37 TFT.fillrect(0,100,50,200,White); //set time button
Owenmatthewmcgowan 12:50289d0ac834 38
Owenmatthewmcgowan 28:53a5429976e4 39
Owenmatthewmcgowan 12:50289d0ac834 40 TFT.rect(0,0,50,100,Blue); //outlines
Owenmatthewmcgowan 12:50289d0ac834 41 TFT.rect(0,100,50,200,White); //outlines
Owenmatthewmcgowan 12:50289d0ac834 42 TFT.rect(0,200,50,240,White); //outlines
Owenmatthewmcgowan 28:53a5429976e4 43
Owenmatthewmcgowan 15:796e17680825 44 //alarm/time colons
Owenmatthewmcgowan 28:53a5429976e4 45 int tx,ty = 0;
Owenmatthewmcgowan 28:53a5429976e4 46 ty = 50;
Owenmatthewmcgowan 28:53a5429976e4 47 tx = 185;
Owenmatthewmcgowan 28:53a5429976e4 48 TFT.fillcircle(tx, ty - 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 49 TFT.fillcircle(tx, ty + 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 50 ty = 150;
Owenmatthewmcgowan 28:53a5429976e4 51 TFT.fillcircle(tx, ty - 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 52 TFT.fillcircle(tx, ty + 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 53 TFT.rect(50,0,320,100,Blue); //set alarm box
Owenmatthewmcgowan 12:50289d0ac834 54 TFT.rect(50,100,320,200,White); //set time box
Owenmatthewmcgowan 12:50289d0ac834 55 TFT.rect(50,200,320,240,White); //set date box
Owenmatthewmcgowan 13:e74e09de81e4 56
Owenmatthewmcgowan 12:50289d0ac834 57 TFT.set_font((unsigned char*) Arial12x12); //set alarm title
Owenmatthewmcgowan 15:796e17680825 58 TFT.locate(157,8);
Owenmatthewmcgowan 12:50289d0ac834 59 TFT.printf("Set Alarm");
Owenmatthewmcgowan 27:a895a2c9acb8 60 TFT.set_font((unsigned char*) Arial12x12); //set time title
Owenmatthewmcgowan 27:a895a2c9acb8 61 TFT.locate(157,108);
Owenmatthewmcgowan 27:a895a2c9acb8 62 TFT.printf("Set Time");
Owenmatthewmcgowan 28:53a5429976e4 63 //Cancel button
Owenmatthewmcgowan 28:53a5429976e4 64 TFT.set_font((unsigned char*) Arial12x12);
mlin 25:ff73360cd038 65 TFT.locate(62,20);
mlin 25:ff73360cd038 66 TFT.set_orientation(0);
mlin 25:ff73360cd038 67 TFT.background(White);
mlin 25:ff73360cd038 68 TFT.foreground(Black);
mlin 25:ff73360cd038 69 TFT.printf("Cancel");
mlin 25:ff73360cd038 70 TFT.background(Black);
mlin 25:ff73360cd038 71 TFT.foreground(White);
mlin 25:ff73360cd038 72 TFT.set_orientation(1);
mlin 25:ff73360cd038 73
mlin 25:ff73360cd038 74 //Set New button (used to set new alarm/time/date)
Owenmatthewmcgowan 28:53a5429976e4 75
mlin 25:ff73360cd038 76 TFT.locate(161,20);
mlin 25:ff73360cd038 77 TFT.set_orientation(0);
mlin 25:ff73360cd038 78 TFT.background(Blue);
mlin 25:ff73360cd038 79 TFT.printf("Set New");
mlin 25:ff73360cd038 80 TFT.background(Black);
mlin 25:ff73360cd038 81 TFT.set_orientation(1);
Owenmatthewmcgowan 28:53a5429976e4 82 //home button
mlin 25:ff73360cd038 83 TFT.locate(5,217);
mlin 25:ff73360cd038 84 TFT.foreground(Blue);
mlin 25:ff73360cd038 85 TFT.printf("Home");
mlin 25:ff73360cd038 86 TFT.foreground(White);
mlin 25:ff73360cd038 87 }
mlin 25:ff73360cd038 88
Owenmatthewmcgowan 28:53a5429976e4 89 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 90 {
Owenmatthewmcgowan 28:53a5429976e4 91
Owenmatthewmcgowan 12:50289d0ac834 92
mlin 18:02667782b06f 93
Owenmatthewmcgowan 12:50289d0ac834 94 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour
mlin 18:02667782b06f 95
Owenmatthewmcgowan 15:796e17680825 96 TFT.locate(90,40);
Owenmatthewmcgowan 28:53a5429976e4 97 TFT.printf("%d",a_h); // print Alarm hour
Owenmatthewmcgowan 15:796e17680825 98 TFT.locate(230,40);
Owenmatthewmcgowan 28:53a5429976e4 99 TFT.printf("%d",a_m);//Alarm_Min
Owenmatthewmcgowan 12:50289d0ac834 100 TFT.set_font((unsigned char*) Arial28x28); //set time hour
Owenmatthewmcgowan 15:796e17680825 101 TFT.locate(90,140);
Owenmatthewmcgowan 28:53a5429976e4 102 TFT.printf("%d",t_h); // Time_hour
Owenmatthewmcgowan 15:796e17680825 103 TFT.locate(230,140);
Owenmatthewmcgowan 28:53a5429976e4 104 TFT.printf("%d",t_m);//Time Min
Owenmatthewmcgowan 15:796e17680825 105 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 15:796e17680825 106 TFT.locate(60,215);
Owenmatthewmcgowan 28:53a5429976e4 107 TFT.printf("%d",t_d); //print date
Owenmatthewmcgowan 15:796e17680825 108 TFT.locate(150,215);
Owenmatthewmcgowan 28:53a5429976e4 109 TFT.printf("%d",t_mo); //print month
Owenmatthewmcgowan 15:796e17680825 110 TFT.locate(265,215);
Owenmatthewmcgowan 28:53a5429976e4 111 TFT.printf("%d",t_y); //print year
Owenmatthewmcgowan 12:50289d0ac834 112
Owenmatthewmcgowan 28:53a5429976e4 113
Owenmatthewmcgowan 28:53a5429976e4 114
Owenmatthewmcgowan 15:796e17680825 115
mlin 16:3cb9b1fbc039 116 }
Owenmatthewmcgowan 28:53a5429976e4 117 void settings()
Owenmatthewmcgowan 28:53a5429976e4 118 {
mlin 25:ff73360cd038 119 int a_h, a_m, t_h, t_m,t_d,t_mo,t_y = 0;
Owenmatthewmcgowan 28:53a5429976e4 120 a_h = tm_a_hr;
Owenmatthewmcgowan 28:53a5429976e4 121 a_m = tm_a_m;
Owenmatthewmcgowan 28:53a5429976e4 122 t_h = tm_c.hour;
Owenmatthewmcgowan 28:53a5429976e4 123 t_m = tm_c.min;
Owenmatthewmcgowan 28:53a5429976e4 124 t_d = tm_c.date;
Owenmatthewmcgowan 28:53a5429976e4 125 t_mo = tm_c.month;
Owenmatthewmcgowan 28:53a5429976e4 126 t_y = tm_c.year;
Owenmatthewmcgowan 26:47271cf8d6b2 127 int multiplier = 8
Owenmatthewmcgowan 26:47271cf8d6b2 128 int o_setting = 11;
Owenmatthewmcgowan 28:53a5429976e4 129 while (true){
Owenmatthewmcgowan 26:47271cf8d6b2 130 int option = setting_press();
Owenmatthewmcgowan 28:53a5429976e4 131 if (option == 0 || option == 2) break;
Owenmatthewmcgowan 28:53a5429976e4 132 switch (option) {
Owenmatthewmcgowan 28:53a5429976e4 133 case (11):
Owenmatthewmcgowan 28:53a5429976e4 134 o_setting = 11;
Owenmatthewmcgowan 28:53a5429976e4 135 break; //Alarm Hour
Owenmatthewmcgowan 28:53a5429976e4 136 case (12):
Owenmatthewmcgowan 28:53a5429976e4 137 o_setting = 12;
Owenmatthewmcgowan 28:53a5429976e4 138 break; //Alarm Min
Owenmatthewmcgowan 28:53a5429976e4 139 case (13):
Owenmatthewmcgowan 28:53a5429976e4 140 o_setting = 13;
Owenmatthewmcgowan 28:53a5429976e4 141 break; //
Owenmatthewmcgowan 28:53a5429976e4 142 case (14):
Owenmatthewmcgowan 28:53a5429976e4 143 o_setting = 14;
Owenmatthewmcgowan 28:53a5429976e4 144 break; //
Owenmatthewmcgowan 28:53a5429976e4 145 case (15):
Owenmatthewmcgowan 28:53a5429976e4 146 o_setting = 15;
Owenmatthewmcgowan 28:53a5429976e4 147 break; //
Owenmatthewmcgowan 28:53a5429976e4 148 case (16):
Owenmatthewmcgowan 28:53a5429976e4 149 o_setting = 16;
Owenmatthewmcgowan 28:53a5429976e4 150 break; //
Owenmatthewmcgowan 28:53a5429976e4 151 case (17):
Owenmatthewmcgowan 28:53a5429976e4 152 o_setting = 17;
Owenmatthewmcgowan 28:53a5429976e4 153 break; //
Owenmatthewmcgowan 26:47271cf8d6b2 154 }
Owenmatthewmcgowan 28:53a5429976e4 155 switch (o_setting) {
Owenmatthewmcgowan 26:47271cf8d6b2 156 case(11):
Owenmatthewmcgowan 26:47271cf8d6b2 157 newval = a_h + tsi.d() * multiplier;
Owenmatthewmcgowan 28:53a5429976e4 158 while (newval < 0) {
Owenmatthewmcgowan 28:53a5429976e4 159 newval += 24;
Owenmatthewmcgowan 28:53a5429976e4 160 }
Owenmatthewmcgowan 27:a895a2c9acb8 161 a_h = newval % 25;
Owenmatthewmcgowan 27:a895a2c9acb8 162 TFT.fillrect(70, 40, 150, 80, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 163 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour
Owenmatthewmcgowan 27:a895a2c9acb8 164 TFT.locate(90,40);
Owenmatthewmcgowan 27:a895a2c9acb8 165 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 166 TFT.printf("%d", a_h);//Alarm_Hour
Owenmatthewmcgowan 28:53a5429976e4 167 break;
Owenmatthewmcgowan 27:a895a2c9acb8 168 case(12):
Owenmatthewmcgowan 27:a895a2c9acb8 169 newval = a_m + tsi.d() * multiplier;
Owenmatthewmcgowan 28:53a5429976e4 170 while (newval < 0) {
Owenmatthewmcgowan 28:53a5429976e4 171 newval += 60;
Owenmatthewmcgowan 28:53a5429976e4 172 }
Owenmatthewmcgowan 27:a895a2c9acb8 173 a_m = newval % 60;
Owenmatthewmcgowan 27:a895a2c9acb8 174 TFT.fillrect(200, 40, 300, 80, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 175 TFT.set_font((unsigned char*) Arial28x28); //set alarm min
Owenmatthewmcgowan 27:a895a2c9acb8 176 TFT.locate(230,40);
Owenmatthewmcgowan 27:a895a2c9acb8 177 TFT.foreground(Red);
Owenmatthewmcgowan 27:a895a2c9acb8 178 TFT.printf("%d", a_m);//Alarm_Min
Owenmatthewmcgowan 28:53a5429976e4 179 break;
Owenmatthewmcgowan 27:a895a2c9acb8 180 case(13): //set time hour
Owenmatthewmcgowan 28:53a5429976e4 181 newval = t_h + tsi.d() * multiplier;
Owenmatthewmcgowan 26:47271cf8d6b2 182 if (newval < 0) newval += 24;
Owenmatthewmcgowan 28:53a5429976e4 183 t_h = newval % 25;
Owenmatthewmcgowan 28:53a5429976e4 184 TFT.fillrect(90, 140, 150, 180, Black);
Owenmatthewmcgowan 28:53a5429976e4 185 TFT.set_font((unsigned char*) Arial28x28);
Owenmatthewmcgowan 27:a895a2c9acb8 186 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 187 TFT.locate(90,140);
Owenmatthewmcgowan 28:53a5429976e4 188 TFT.printf("%d",t_h); // Time_hour
Owenmatthewmcgowan 28:53a5429976e4 189 break;
Owenmatthewmcgowan 27:a895a2c9acb8 190 case(14): //set time min
Owenmatthewmcgowan 28:53a5429976e4 191 newval = t_m + tsi.d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 192 if (newval < 0) newval += 60;
Owenmatthewmcgowan 28:53a5429976e4 193 t_m = newval % 60;
Owenmatthewmcgowan 28:53a5429976e4 194 TFT.fillrect(200, 140, 300, 180, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 195 TFT.set_font((unsigned char*) Arial28x28);
Owenmatthewmcgowan 27:a895a2c9acb8 196 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 197 TFT.locate(230,140);
Owenmatthewmcgowan 28:53a5429976e4 198 TFT.printf("%d",t_m);//Time Min
Owenmatthewmcgowan 28:53a5429976e4 199 break;
Owenmatthewmcgowan 27:a895a2c9acb8 200 case(15): // set time date
Owenmatthewmcgowan 28:53a5429976e4 201 newval = t_d + tsi.d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 202 if (newval < 0) newval += 31;
Owenmatthewmcgowan 28:53a5429976e4 203 t_d = newval % 32;
Owenmatthewmcgowan 28:53a5429976e4 204 TFT.fillrect(55, 202, 148, 238, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 205 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 206 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 207 TFT.locate(60,215);
Owenmatthewmcgowan 28:53a5429976e4 208 TFT.printf("%d",t_d); //print date
Owenmatthewmcgowan 28:53a5429976e4 209 break;
Owenmatthewmcgowan 27:a895a2c9acb8 210 case(16): // set time month
Owenmatthewmcgowan 27:a895a2c9acb8 211 newval = a_h + tsi.d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 212 if (newval < 0) newval += 12;
Owenmatthewmcgowan 27:a895a2c9acb8 213 a_h = newval % 13;
Owenmatthewmcgowan 28:53a5429976e4 214 TFT.fillrect(148, 202, 263, 238, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 215 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 216 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 217 TFT.locate(150,215);
Owenmatthewmcgowan 28:53a5429976e4 218 TFT.printf("%d",t_mo); //print month
Owenmatthewmcgowan 28:53a5429976e4 219 break;
Owenmatthewmcgowan 27:a895a2c9acb8 220 case(17): //set time year
Owenmatthewmcgowan 27:a895a2c9acb8 221 newval = a_h + tsi.d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 222 if (newval > 1970 && newval < 2700) a_h = newval;
Owenmatthewmcgowan 28:53a5429976e4 223 TFT.fillrect(263, 202, 310, 238, Black);
Owenmatthewmcgowan 26:47271cf8d6b2 224 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 225 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 226 TFT.locate(265,215);
Owenmatthewmcgowan 28:53a5429976e4 227 TFT.printf("%d",t_y); //print year
Owenmatthewmcgowan 28:53a5429976e4 228 break;
Owenmatthewmcgowan 28:53a5429976e4 229 }
Owenmatthewmcgowan 28:53a5429976e4 230 TFT.foreground(White);
Owenmatthewmcgowan 28:53a5429976e4 231 if (option == 1) {
Owenmatthewmcgowan 28:53a5429976e4 232 tm_a_hr = a_h;
Owenmatthewmcgowan 28:53a5429976e4 233 tm_a_min == a_m;
Owenmatthewmcgowan 28:53a5429976e4 234 &tm_c.min = t_m;
Owenmatthewmcgowan 28:53a5429976e4 235 &tm_c.hour = t_h;
Owenmatthewmcgowan 28:53a5429976e4 236 &tm_c.date = t_d;
Owenmatthewmcgowan 28:53a5429976e4 237 &tm_c.month = t_mo;
Owenmatthewmcgowan 28:53a5429976e4 238 &tm_c.year = t_y;
Owenmatthewmcgowan 28:53a5429976e4 239 break;
Owenmatthewmcgowan 28:53a5429976e4 240 }
Owenmatthewmcgowan 28:53a5429976e4 241 }
Owenmatthewmcgowan 28:53a5429976e4 242 f_state = 1;
mlin 25:ff73360cd038 243 }