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

Files at this revision

API Documentation at this revision

Comitter:
TimWoo
Date:
Thu Jan 08 01:58:52 2015 +0000
Parent:
8:d21d3b67fbb2
Child:
10:f03c1cb12f45
Commit message:
-Coded main program loop with a timer. This way data is pulled from the API with a regular interval. Sending messages is interrupted for the API call.

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
HTTPClient_KVplus.lib Show diff for this revision Revisions of this file
RTC.lib Show annotated file Show diff for this revision Revisions of this file
libMotiv.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
picojson.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Tue Jan 06 23:03:53 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#d1ccbed7687a
--- a/HTTPClient_KVplus.lib	Tue Jan 06 23:03:53 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/TimWoo/code/HTTPClient_KVplus/#89ad63c03f10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC.lib	Thu Jan 08 01:58:52 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Sissors/code/RTC/#be9d058ee5c7
--- a/libMotiv.lib	Tue Jan 06 23:03:53 2015 +0000
+++ b/libMotiv.lib	Thu Jan 08 01:58:52 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/TimWoo/code/libMotiv/#14bf6c650b55
+http://developer.mbed.org/users/TimWoo/code/libMotiv/#1e30f5031770
--- 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);
--- a/picojson.lib	Tue Jan 06 23:03:53 2015 +0000
+++ b/picojson.lib	Thu Jan 08 01:58:52 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/mimil/code/picojson/#2bb500b021e2
+http://mbed.org/users/mimil/code/picojson/#2bb500b021e2