Final MEMBITT Code

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed

Fork of reminder_main by Senior Design

Revision:
0:fef6b4d65600
Child:
1:29de429a7e15
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 28 18:29:23 2016 +0000
@@ -0,0 +1,115 @@
+#include "mbed.h"
+#include <string>
+#include <vector>
+
+#include "utils.h"
+
+DigitalOut myled(LED1);
+
+Serial pc(USBTX, USBRX); // tx, rx .... for testing purposes (remove later)
+
+// Global vars
+time_t ct_time;
+struct tm * timeinfo;
+
+void clock_main(struct reminder *current_reminder);
+int estimate_time(struct reminder current_reminder);
+
+enum Day {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
+
+struct schedule {
+    
+    // will be ordered by time - should do this processing on the desktop
+    vector<struct reminder> reminder_list;
+};
+
+int main() {
+    
+    
+    // in real project, we will set the time via the internet
+    set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
+    time_t clock;
+    // localtime(
+
+
+    reminder test_reminder;
+    // test_reminder.tm_time.tm_sec = 0;
+    test_reminder.tm_time.tm_min = 36;
+    test_reminder.tm_time.tm_hour = 11;
+    for (int i = 0; i < 7; i++) {
+        if (i == 1 || i == 3 || i == 4 || i == 5) test_reminder.reminder_days[i] = 1; // set MWHF
+        else test_reminder.reminder_days[i] = 0;
+    }
+    
+    
+    // test_reminder.tm_time.tm_mday = 1; // day of the month
+    // test_reminder.tm_time.tm_mon = 0; // months since January
+    // test_reminder.tm_time.tm_year = 0; // years since 1970
+    schedule myschedule;
+    myschedule.reminder_list.push_back(test_reminder);
+    
+    int flag = 0;
+    
+    Day currentDay = Wednesday;
+    int sleep_time;
+    while(1) {
+        
+        for (int i = 0; i < myschedule.reminder_list.size(); i++) {
+            timeinfo = localtime (&clock); // ct_time not set right now
+            time(&clock);
+            pc.printf("Time as a basic string = %s\n\r", ctime(&clock));
+
+            while (!flag) {
+                if (myschedule.reminder_list[i].reminder_days[currentDay] != 1) {
+                    // pc.printf("%i\n\r", myschedule.reminder_list[i].reminder_days[currentDay]);
+                    i++; // current reminder not set to go off today; go to next reminder
+                }
+                // may need to check if the current reminder is not last one, otherwise out of bounds ERROR
+                else {
+                    sleep_time = estimate_time(myschedule.reminder_list[i]);
+                    
+                    pc.printf("sleep_time is %i\n\r", sleep_time);
+                    flag = 1;
+                    // sleep(sleep_time); // try and sleep here
+                    // wait(sleep_time); // replace this wait function with a smart sleep to save power and then poll after that
+                }
+                //wait(1);
+            }
+            
+            
+            if (timeinfo->tm_min == myschedule.reminder_list[i].tm_time.tm_min && timeinfo->tm_hour == myschedule.reminder_list[i].tm_time.tm_hour) {
+                myled = true;
+            }
+            wait(1);
+        }
+        /*
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2); 
+        */
+        
+        
+    }
+}
+
+int estimate_time(struct reminder current_reminder) {
+    // estimates the remaining time until the next reminder so program can sleep till then to save battery
+    
+    int estimated_time = (60*timeinfo->tm_hour) - (60*current_reminder.tm_time.tm_hour) +
+                        (timeinfo->tm_min - current_reminder.tm_time.tm_min) + 60;
+                        // convert hours to min, find estimated time before reminder plus 1 hour (60 min)
+                        
+    return estimated_time;
+                            
+    
+    //if (current_reminder.reminder_days[currentDay] == 1) // 
+    
+}
+
+
+/*
+void clock_main(struct reminder *current_reminder) {
+    
+}
+*/
\ No newline at end of file