ControllerBox directs electromechanical equipment in restaurants to display information.

Dependencies:   TextLCD MbedJSONValue libMotiv picojson mbed-rtos mbed

Fork of Mbed_MotiVControllerBox by Tim Wöstemeier

Revision:
9:11d0c72fef0d
Parent:
7:dd5bf173b5e6
Child:
10:f03c1cb12f45
--- a/main.cpp	Tue Jan 06 23:03:53 2015 +0000
+++ b/main.cpp	Thu Jan 08 01:58:52 2015 +0000
@@ -2,10 +2,12 @@
 //the library "TextLCD.h" was slightly altered to work with the GDM2004D LCD
 #include "TextLCD/TextLCD.h"
 #include "Controller.h"
-#include "picojson.h"
-#include "EthernetInterface.h"
+//#include "picojson.h"
+//#include "MbedJSONValue.h"
+//#include "EthernetInterface.h"
 //#include "HTTPClient.h"
 //#include "SDFileSystem.h" Needed if config files are going to be implemented
+#include "libMotiv.h"
 #include <string>
 
 /*****************
@@ -14,6 +16,10 @@
 //the object "lcd" is initialized to act as a TextLCD with 20x4 characters
 TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);
 
+//Timer for keeping track of intervals
+Timer tim;
+int intervalSec = 10;
+
 
 //inputs
 DigitalIn Up(p8);
@@ -27,9 +33,9 @@
 Serial rfd(p9, p10); //tx, rx
 
 //TODO: Should be the responsibility of Controller
-EthernetInterface eth; //Doeesn't want to initialize in the objects Controller->mAPI
-HTTPClient http;
-char str[1024];
+//EthernetInterface eth; //Doeesn't want to initialize in the objects Controller->mAPI
+//HTTPClient http;
+//char str[1024];
 
 //Storage
 //SD card
@@ -42,7 +48,7 @@
 
 
 //Controller mainly directs the program. It directs data and also controls the lcd output.
-Controller c(&lcd/*, &eth*/);
+Controller c(&lcd, &rfd/*, &eth*/);
 
 /**********************
     Declare functions
@@ -50,6 +56,7 @@
 
 void setup(); //Called once to setup
 void runProgram(); //Program with loop
+void runController(); //Controller loop
 
 
 /****************
@@ -57,14 +64,16 @@
 *****************/
 int main()
 {
-    eth.init();
-    eth.connect();
+//    eth.init();
+//    eth.connect();
     printf("int main()\r\n");
-//    c.init();
-    c.printCommandList();
-//    c.testRequest();
-//    setup();
+    c.init();
+    setup();
+
+    runController();
+
 //
+
 //    pc.printf("Entering loop\r\n");
 //
 //    //the endless loop keeps mbed in low power mode
@@ -84,6 +93,38 @@
     wait_ms(200);
 }
 
+
+/*
+void    start ()
+    Start the timer.
+void    stop ()
+    Stop the timer.
+void    reset ()
+    Reset the timer to 0.
+float   read ()
+    Get the time passed in seconds.
+int     read_ms ()
+    Get the time passed in mili-seconds.
+int     read_us ()
+    Get the time passed in micro-seconds. */
+
+void runController()
+{
+    int count;
+    tim.start();
+    while(1) {
+        if(tim.read() > intervalSec) { //polling interval passed, update tables
+            printf("*%f seconds passed, reset timer*\r\n", tim.read());
+            tim.reset();
+            c.update();
+        }
+        c.sendCommands(&tim, intervalSec);
+        //send 1 command if available, else do nothing
+    }
+}
+
+
+
 void runProgram()
 {
 
@@ -103,25 +144,10 @@
 //    {
 //      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
 //    }
-//
-//    picojson::value jsonVal;
-//    char *json = (char*) malloc(strlen(str)+1);
-//    strcpy(json, str);
-//    string err = picojson::parse(jsonVal, json, json + strlen(json));
-//    printf("res error? %s\r\n", err.c_str());
-//    
-//    string code = jsonVal.get("table").get("code").get<string>();
-//    
-//    
-//    int dinner_stat = json["table"];
-//    string code = table["code"];
-//    
-//    printf("The status of the dinner is: %d\r\n", dinner_stat);
-//    printf("Code: %s\r\n", code); 
-    
+
     c.setStatus(Controller::READY);
     pc.printf("Controller ready\r\n");
-    
+
     c.printCommandList();
     //Reset flower
     rfd.putc(2);