run this here

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351

Files at this revision

API Documentation at this revision

Comitter:
trhackett
Date:
Thu Jun 14 19:39:23 2018 +0000
Parent:
3:f34bbdea0786
Commit message:
current time mbed post comp arch

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
timeHelp.h Show annotated file Show diff for this revision Revisions of this file
diff -r f34bbdea0786 -r 1ae9f76749b9 main.cpp
--- a/main.cpp	Tue Jun 12 00:27:26 2018 +0000
+++ b/main.cpp	Thu Jun 14 19:39:23 2018 +0000
@@ -20,7 +20,7 @@
 const float interval = 0.1;
 int numTicks = 0;
 int prevNumTicks = 0;
-float timingError = 0.0;
+float intervalError = 0.0;
 
 char prevTime[11] = "00:00:00.0";
 char displayTime[11] = "00:00:00.0";
@@ -42,7 +42,6 @@
 EventQueue receiveTimeQueue;
 
 int main() {    
-//    pc.printf("main started!!\r\n");
     
     kw40z_device.attach_alert(&AlertReceived);
     
@@ -140,12 +139,13 @@
 // time and hopefully it will be more accurate.
 void updateError() {
     
-    float secsToAdd = interval * prevNumTicks + timingError;
+    // 
+    float secsToAdd = prevNumTicks * (interval + intervalError);
     
     float T1 = currTimeSecs(displayTime);
     float T0 = currTimeSecs(prevTime);
     
-    timingError += (T1 - (T0+secsToAdd)) / prevNumTicks;
+    intervalError = (T1 - (T0+secsToAdd)) / prevNumTicks;
 }
 
 int numPrints = 20;
@@ -156,7 +156,7 @@
 void updateDisplayString() {
     numTicks++;
     
-    float offset = interval * numTicks + timingError;
+    float offset = numTicks * (interval + intervalError);
     
     addSecondsToCurrentTime(prevTime, displayTime, offset);
     
diff -r f34bbdea0786 -r 1ae9f76749b9 timeHelp.h
--- a/timeHelp.h	Tue Jun 12 00:27:26 2018 +0000
+++ b/timeHelp.h	Thu Jun 14 19:39:23 2018 +0000
@@ -5,6 +5,7 @@
 #include <string>
 
 // return true is seconds is even, false if not
+// currTime is in the form HH:MM:SS.s
 bool secondsAreEven(char currTime[]) {
     char seconds[3];
     seconds[0] = currTime[6];
@@ -16,9 +17,10 @@
     return (secondsInt % 2) == 0;
 }
 
-// given a starting time and a number of seconds, add the seconds to that time
-// and put the resulting string into resultTime ... both startTime and resultTime
-// must be character arrays of length 10
+// given a starting time (starttime) in the form HH:MM:SS.s
+// and a number of seconds (secsToAdd), add the seconds to that
+// time and put the resulting string into resultTime ... both
+// startTime and resultTime must be character arrays of length 10
 void addSecondsToCurrentTime(char startTime[], char resultTime[], float secsToAdd) {
 
     int decsToAdd=0,newSecsToAdd=0,minutesToAdd=0,hoursToAdd=0;
@@ -102,7 +104,8 @@
 }
 
 // given the current time in the form HH:MM:SS.S
-// give me back the number of seconds in that number
+// give me back the number of seconds from 00:00:00.0
+// at that time
 float currTimeSecs(char currentTime[]) {
     // hours
     char hours[3];