Pinky and the Brain / Mbed OS Clock

Dependencies:   SPI_TFT_ILI9341 TFT_fonts Adafruit_RTCLib RTC-DS1307 TSI

Revision:
11:80a6facfd9f1
Parent:
10:e5bcd9088d5d
Child:
12:dd5d8eea2e47
diff -r e5bcd9088d5d -r 80a6facfd9f1 main.cpp
--- a/main.cpp	Wed May 24 09:07:13 2017 +0000
+++ b/main.cpp	Wed May 24 09:53:03 2017 +0000
@@ -9,6 +9,7 @@
 // The main program global states
 StateClass *programState = NULL;
 TimeClass *programTime = NULL;
+TimeClass *programPrevTime = NULL;
 TimeClass *programAlarm = NULL;
 DateClass *programDate = NULL;
 WeatherClass *programWeather = NULL;
@@ -23,10 +24,12 @@
     //pc_io.baud(115200);
     //LOG("OK");
     programTime = new TimeClass(11, 0, 0);
+    programPrevTime = new TimeClass(11, 0, 0);
     programDate = new DateClass(11, 11, 1918, 1);
     programWeather = new WeatherClass();
     //LOG("MOK");
-    programState = new StateClass(programTime, programWeather, programDate, programAlarm);
+    programState = new StateClass(programTime, programPrevTime, programWeather, programDate, programAlarm);
+    programState->screenState = 0;
 }
 
 void refresh_and_inc()
@@ -34,20 +37,21 @@
     //led1 = !led1;
     //LOG("In Inc: %f\r\n", programTime->second);
     // Increment Time
+    programTime->inc(programPrevTime, REFRESH_PERIOD);
     if (programState->screenState == 0)
-    screen.drawClock(programTime, true);
+        screen.drawClock(programTime, false, programPrevTime);
     else if (programState->screenState == 1)
-        screen.drawClockBig(programTime, true);
+        screen.drawClockBig(programTime, false, programPrevTime);
         
-    programTime->inc(REFRESH_PERIOD);
+    
     //printf("HAH");
     //pc_io.printf("After Inc: %d\r\n", programTime->second);
     
     // Refresh Display
-    if (programState->screenState == 0)
+    /*if (programState->screenState == 0)
         screen.drawClock(programTime, false);
     else if (programState->screenState == 1)
-        screen.drawClockBig(programTime, false);
+        screen.drawClockBig(programTime, false);*/
     //screen.drawAll(programState);   
     //LOG ("OUT YEAH!\r\n");    
 }
@@ -65,10 +69,13 @@
         programTime->hour = h;
         programTime->minute = m;
         programTime->second = s;
-        //clockTimer.detach();
-        //clockTimer.attach(&refresh_and_inc, REFRESH_PERIOD);
+        programPrevTime->hour = h;
+        programPrevTime->minute = m;
+        programPrevTime->second = s;
+        clockTimer.detach();
+        clockTimer.attach(&refresh_and_inc, REFRESH_PERIOD);
     }
-    screen.drawAll(programState);
+    screen.drawAll(programState, false);
     //LOG("Fetch happened\r\n");
 }
 
@@ -78,7 +85,7 @@
     init_state_hw();
     //LOG("AFTER\r\n");
     //printf("OI OI");
-    screen.drawAll(programState);
+    screen.drawAll(programState, true);
     //screen.drawDate(programDate);
     // Timer initializations
     clockTimer.attach(&refresh_and_inc, REFRESH_PERIOD);