@@ -69,8 +69,6 @@ uint16_t palette[] = {ILI9341_BLACK, // 0
69
69
0x7E3C
70
70
}; // 3
71
71
72
- int SCREEN_WIDTH = 240 ;
73
- int SCREEN_HEIGHT = 320 ;
74
72
// Limited to 4 colors due to memory constraints
75
73
int BITS_PER_PIXEL = 2 ; // 2^2 = 4 colors
76
74
@@ -122,7 +120,11 @@ int frameCount = 3;
122
120
int screenCount = 5 ;
123
121
long lastDownloadUpdate = millis();
124
122
125
- uint16_t screen = 0 ;
123
+ uint8_t screen = 0 ;
124
+ // divide screen into 4 quadrants "< top", "> bottom", " < middle "," > middle "
125
+ uint16_t dividerTop, dividerBottom, dividerMiddle;
126
+ uint8_t changeScreen (TS_Point p, uint8_t screen);
127
+
126
128
long timerPress;
127
129
bool canBtnPress;
128
130
bool sleep_mode ();
@@ -189,8 +191,6 @@ void setup() {
189
191
gfx.fillBuffer (MINI_BLACK);
190
192
gfx.commit ();
191
193
192
- connectWifi ();
193
-
194
194
Serial.println (" Initializing touch screen..." );
195
195
ts.begin ();
196
196
@@ -202,9 +202,31 @@ void setup() {
202
202
SPIFFS.format ();
203
203
}
204
204
drawProgress (100 , " Formatting done" );
205
+
206
+ /* Allow user to force a screen re-calibration */
207
+ gfx.fillBuffer (MINI_BLACK);
208
+ gfx.drawString (120 , 160 , F (" Press and hold\n to initiate touch screen\n calibration" ));
209
+ gfx.commit ();
210
+ delay (3000 );
211
+ yield ();
205
212
boolean isCalibrationAvailable = touchController.loadCalibration ();
213
+ if (ts.touched ()) {
214
+ isCalibrationAvailable = false ;
215
+ gfx.fillBuffer (MINI_YELLOW);
216
+ gfx.drawString (120 , 160 , F (" Calibration initiated\n now release screen" ));
217
+ gfx.commit ();
218
+
219
+ // Wait for release otherwise touch becomes first calibration point
220
+ while (ts.touched ()) {
221
+ delay (10 );
222
+ yield ();
223
+ }
224
+ delay (100 ); // debounce
225
+ touchController.getPoint (); // throw away last point
226
+ }
227
+
206
228
if (!isCalibrationAvailable) {
207
- Serial.println (" Calibration not available" );
229
+ Serial.println (" Calibration data not available or force calibration initiated " );
208
230
touchController.startCalibration (&calibration);
209
231
while (!touchController.isCalibrationFinished ()) {
210
232
gfx.fillBuffer (0 );
@@ -218,6 +240,12 @@ void setup() {
218
240
touchController.saveCalibration ();
219
241
}
220
242
243
+ dividerTop = 64 ;
244
+ dividerBottom = gfx.getHeight () - dividerTop;
245
+ dividerMiddle = gfx.getWidth () / 2 ;
246
+
247
+ connectWifi ();
248
+
221
249
carousel.setFrames (frames, frameCount);
222
250
carousel.disableAllIndicators ();
223
251
@@ -236,19 +264,20 @@ TS_Point points[10];
236
264
uint8_t currentTouchPoint = 0 ;
237
265
238
266
void loop () {
239
- static bool asleep = false ; // asleep used to stop screen change after touch for wake-up
267
+ static bool asleep = false ; // asleep used to stop screen change after touch for wake-up
240
268
gfx.fillBuffer (MINI_BLACK);
241
- if (touchController.isTouched (0 )) {
269
+
270
+ /* Break up the screen into 4 sections a touch in section:
271
+ * - Top changes the time format
272
+ * - Left back one page
273
+ * - Right forward one page
274
+ * - Bottom jump to page 0
275
+ */
276
+ if (touchController.isTouched (500 )) {
242
277
TS_Point p = touchController.getPoint ();
243
278
timerPress = millis ();
244
-
245
- Serial.printf (" Touch point detected at %d/%d.\n " , p.x , p.y );
246
- if (!asleep) { // no need to change screens;
247
- if (p.y < 80 ) {
248
- IS_STYLE_12HR = !IS_STYLE_12HR;
249
- } else {
250
- screen = (screen + 1 ) % screenCount;
251
- }
279
+ if (!asleep) { // no need to update or change screens;
280
+ screen = changeScreen (p, screen);
252
281
}
253
282
} // isTouched()
254
283
@@ -604,14 +633,12 @@ void drawForecastTable(uint8_t start) {
604
633
gfx.setTextAlignment (TEXT_ALIGN_CENTER);
605
634
time_t time = forecasts[i].observationTime ;
606
635
struct tm * timeinfo = localtime (&time);
607
- // Added 24hr / 12hr conversion //
608
- if (IS_STYLE_12HR){
636
+ if (IS_STYLE_12HR) {
609
637
gfx.drawString (120 , y - 15 , WDAY_NAMES[timeinfo->tm_wday ] + " " + String (make12_24 (timeinfo->tm_hour )));
610
638
} else {
611
639
gfx.drawString (120 , y - 15 , WDAY_NAMES[timeinfo->tm_wday ] + " " + String (timeinfo->tm_hour ) + " :00" );
612
640
}
613
641
614
-
615
642
gfx.drawPalettedBitmapFromPgm (0 , 5 + y, getMiniMeteoconIconFromProgmem (forecasts[i].icon ));
616
643
gfx.setTextAlignment (TEXT_ALIGN_LEFT);
617
644
gfx.setColor (MINI_YELLOW);
@@ -690,33 +717,32 @@ void calibrationCallback(int16_t x, int16_t y) {
690
717
gfx.fillCircle (x, y, 10 );
691
718
}
692
719
693
- // Added 24hr / 12hr conversion //
694
720
String getTime (time_t *timestamp) {
695
721
struct tm *timeInfo = localtime (timestamp);
696
722
697
- // char buf[6];
698
723
char buf[9 ]; // "12:34 pm\0"
699
- char ampm[3 ]; ampm[0 ]=' \0 ' ; // Ready for 24hr clock
724
+ char ampm[3 ];
725
+ ampm[0 ]=' \0 ' ; // Ready for 24hr clock
700
726
uint8_t hour = timeInfo->tm_hour ;
701
727
702
- if (IS_STYLE_12HR){
703
- if (hour > 12 ){
728
+ if (IS_STYLE_12HR) {
729
+ if (hour > 12 ) {
704
730
hour = hour - 12 ;
705
- sprintf (ampm," pm" );
731
+ sprintf (ampm, " pm" );
706
732
} else {
707
- sprintf (ampm," am" );
733
+ sprintf (ampm, " am" );
708
734
}
709
735
sprintf (buf, " %2d:%02d %s" , hour, timeInfo->tm_min , ampm);
710
- } else {
736
+ } else {
711
737
sprintf (buf, " %02d:%02d %s" , hour, timeInfo->tm_min , ampm);
712
- }
738
+ }
713
739
return String (buf);
714
740
}
715
741
716
742
/*
717
- * Convert hour from 24 hr time to 12 hr time
718
- * @return cString with 2 digit hour + am or pm
743
+ * Convert hour from 24 hr time to 12 hr time.
719
744
*
745
+ * @return cString with 2 digit hour + am or pm
720
746
*/
721
747
char * make12_24 (int hour){
722
748
static char hr[6 ];
@@ -780,3 +806,32 @@ void loadPropertiesFromSpiffs() {
780
806
Serial.println (" SPIFFS mount failed." );
781
807
}
782
808
}
809
+
810
+ /*
811
+ * Change screen based on touchpoint location.
812
+ */
813
+ uint8_t changeScreen (TS_Point p, uint8_t screen) {
814
+ uint8_t page = screen;
815
+
816
+ // Serial.printf("Touch point detected at %d/%d.\n", p.x, p.y);
817
+ // From the screen's point of view commented values for the 240 X 320 touch screen
818
+ // if (p.y < dividerTop) Serial.print(" top "); // < 80
819
+ // if (p.y > dividerBottom) Serial.print(" bottom "); // > 240
820
+ // if (p.x > dividerMiddle) Serial.print(" left "); // > 120
821
+ // if (p.x <= dividerMiddle) Serial.print(" right "); // <= 120
822
+ // Serial.println();
823
+
824
+ if (p.y < dividerTop) { // top -> change 12/24h style
825
+ IS_STYLE_12HR = !IS_STYLE_12HR;
826
+ } else if (p.y > dividerBottom) { // bottom -> go to screen 0
827
+ page = 0 ;
828
+ } else if (p.x > dividerMiddle) { // left -> previous page
829
+ if (page == 0 ) { // Note type is unsigned
830
+ page = screenCount; // Last screen is max -1
831
+ }
832
+ page--;
833
+ } else { // right -> next screen
834
+ page = (page + 1 ) % screenCount;
835
+ }
836
+ return page;
837
+ }
0 commit comments