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:
Sat Nov 15 13:04:09 2014 +0000
Parent:
0:2279181caaa1
Child:
2:ad4509a9d051
Commit message:
Dirty testing stage. Testing ethernet/internet connection

Changed in this revision

Controller.cpp Show diff for this revision Revisions of this file
Controller.h Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.lib Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
devices/Device.cpp Show diff for this revision Revisions of this file
devices/Device.h Show diff for this revision Revisions of this file
devices/Flower.cpp Show diff for this revision Revisions of this file
devices/Flower.h Show diff for this revision Revisions of this file
library/Controller.cpp Show annotated file Show diff for this revision Revisions of this file
library/Controller.h Show annotated file Show diff for this revision Revisions of this file
library/Device.cpp Show annotated file Show diff for this revision Revisions of this file
library/Device.h Show annotated file Show diff for this revision Revisions of this file
library/Flower.cpp Show annotated file Show diff for this revision Revisions of this file
library/Flower.h Show annotated file Show diff for this revision Revisions of this file
library/MotiVAPI.cpp Show annotated file Show diff for this revision Revisions of this file
library/MotiVAPI.h Show annotated file Show diff for this revision Revisions of this file
library/Table.cpp Show annotated file Show diff for this revision Revisions of this file
library/Table.h 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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/Controller.cpp	Sat Oct 25 00:11:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-#include <string>
-#include "TextLCD.h"
-#include "Controller.h"
-
-Controller::Controller(TextLCD *lcd):
-    _status(WAITING)
-{
-    _lcd = lcd;
-    //setStatus(WAITING);
-    displayStatus();
-}
-
-Controller::cStatus Controller::getStatus()
-{
-    return _status;
-}
-
-string Controller::statusString()
-{
-    switch(_status) {
-        case READY:
-            return "ready";
-
-        case WAITING:
-            return "waiting";
-
-        case BUSY:
-            return "busy";
-
-        case ERROR:
-            return "error";
-
-        default:
-            return "unknown";
-    }
-}
-
-void Controller::setStatus(cStatus status)
-{
-    _status = status;
-    displayStatus();
-}
-
-void Controller::displayStatus()
-{
-    _lcd->locate(0,0);
-    _lcd->clearLine();
-    _lcd->locate(0,0);
-    _lcd->printf("Status: %s", statusString());
-}
-
-void Controller::displWriteLine(int row, char c)
-{
-    _lcd->locate(0,row);
-    _lcd->printf("%c", c);
-}
\ No newline at end of file
--- a/Controller.h	Sat Oct 25 00:11:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-#ifndef MOTIV_CONTROLLER_H
-#define MOTIV_CONTROLLER_H
-
-//Controller
-#include <string>
-#include "mbed.h"
-
-class Controller {
-public:
-    enum cStatus {
-        READY,
-        WAITING,
-        BUSY,
-        ERROR
-    };
-    Controller(TextLCD *lcd);
-    cStatus getStatus();
-    string statusString();
-    void setStatus(cStatus);
-    void displayStatus();
-    
-    void displWriteLine(int row, char c);
-    
-    TextLCD *_lcd;
-    
-private:
-    cStatus _status;
-
-
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/EthernetInterface/#de796e2a5e98
--- a/MODSERIAL.lib	Sat Oct 25 00:11:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/mbed/code/SDFileSystem/#7b35d1709458
--- a/TextLCD.lib	Sat Oct 25 00:11:12 2014 +0000
+++ b/TextLCD.lib	Sat Nov 15 13:04:09 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/simon/code/TextLCD/#542cee91de4b
+http://mbed.org/users/simon/code/TextLCD/#bad15f71a5d9
--- a/devices/Device.cpp	Sat Oct 25 00:11:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#include "Device.h"
-#include "../MODSERIAL/MODSERIAL.h"
-
-using namespace AjK;
-
-Device::Device(MODSERIAL* ms)
-    :_ms(ms),
-     _msg(0)
-{
-
-}
-
-Device::~Device()
-{
-    delete _ms;
-}
-
-void Device::sendMessage()
-{
-    if(sizeof(_msg)) {
-        _ms->printf("%s;", _msg);
-    }
-}
\ No newline at end of file
--- a/devices/Device.h	Sat Oct 25 00:11:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#ifndef MOTIV_DEVICE_H
-#define MOTIV_DEVICE_H
-
-#include "../MODSERIAL/MODSERIAL.h"
-#include <string>
-
-class Device
-{
-public:
-    Device(MODSERIAL* ms);
-    ~Device();
-
-    void sendMessage();
-
-protected:
-    MODSERIAL* _ms;
-    string _msg;
-};
-
-#endif
\ No newline at end of file
--- a/devices/Flower.cpp	Sat Oct 25 00:11:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#include "Flower.h"
-#include "../MODSERIAL/MODSERIAL.h"
-//#include <cstdlib>
-
-
-Flower::Flower(MODSERIAL* ms)
-{
-    
-}
-
-Flower::~Flower()
-{
-    
-}
-
-void Flower::setLed(int state)
-{
-//    _msg = 
-}
\ No newline at end of file
--- a/devices/Flower.h	Sat Oct 25 00:11:12 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef MOTIV_FLOWER_H
-#define MOTIV_FLOWER_H
-
-#include "../MODSERIAL/MODSERIAL.h"
-#include "Device.h"
-
-class Flower : public Device
-{
-public:
-    Flower(MODSERIAL* ms);
-    ~Flower();
-
-    int id; //Id needed to control the right flower
-    void setLed(int state); //Set THE LED to state. 0=off, 1=on
-
-private:
-    enum COMMANDS {
-        SET_LED = 6
-    };
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Controller.cpp	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,114 @@
+#include <string>
+#include <stdlib.h>
+#include "TextLCD.h"
+#include "Controller.h"
+#include "Device.h"
+#include "Table.h"
+#include "Flower.h"
+//#include "MotiVAPI.h"
+
+//Test endpoint: http://demo.motiv.jvanbaarsen.com/demo/test
+using namespace std;
+
+Controller::Controller(TextLCD *lcd):
+    status(WAITING)
+{
+    this->lcd = lcd;
+    //setStatus(WAITING);
+//    _mapi = new MotiVAPI("http://demo.motiv.jvanbaarsen.com/demo/test");
+    displayStatus();
+//    devices.push_back(new <Device>Flower(1));
+//    devices.append(new Flower(2));
+//    devices.append(new Flower(3));
+
+//    tables.append(new Table(1));
+//    tables.append(new Table(2));
+//    tables.append(new Table(3));
+
+    flower = new Flower(1);
+    commandList.push_back(flower->makeCommand(flower->fRESET, 0));
+    commandList.push_back(flower->makeCommand(flower->fPETAL_SPD, 50));
+    commandList.push_back(flower->makeCommand(flower->fPETAL_POS, 50));
+    commandList.push_back(flower->makeCommand(flower->fDEMO1, 1));
+    printDesc(commandList[1].cmd);
+}
+
+void Controller::printDesc(int c)
+{
+    string desc = flower->getCommandDesc(c);
+    lcdWriteLine(2, desc);
+}
+
+Controller::cStatus Controller::getStatus()
+{
+    return this->status;
+}
+
+string Controller::statusString()
+{
+    switch(status) {
+        case READY:
+            return "ready";
+
+        case WAITING:
+            return "waiting";
+
+        case BUSY:
+            return "busy";
+
+        case ERROR:
+            return "error";
+
+        case INIT:
+            return "intializing";
+
+        default:
+            return "unknown";
+    }
+}
+
+void Controller::setStatus(cStatus status)
+{
+    this->status = status;
+    displayStatus();
+}
+
+void Controller::displayStatus()
+{
+    this->lcd->locate(0,0);
+    this->lcd->clearLine();
+    this->lcd->locate(0,0);
+    this->lcd->printf("Status: %s", statusString());
+}
+
+
+void Controller::lcdWriteLine(int row, string str)
+{
+    this->lcd->locate(0,row);
+    this->lcd->clearLine();
+    this->lcd->locate(0,row);
+    this->lcd->printf("%s", str);
+}
+
+void Controller::nextCommand()
+{
+    std::vector<Device::mCommand>::iterator it;
+    it = commandList.begin();
+    it = commandList.insert(it, commandList.back());
+    it = commandList.begin();
+    commandList.pop_back();
+    it = commandList.begin();
+    Flower::mCommand command = *it;
+    printDesc(command.cmd);
+}
+    
+void Controller::prevCommand()
+{
+    
+    }
+    
+void Controller::sendCommandDem()
+{
+    
+    }
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Controller.h	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,54 @@
+#ifndef MOTIV_CONTROLLER_H
+#define MOTIV_CONTROLLER_H
+
+//Controller
+#include <string>
+#include "mbed.h"
+#include "MotiVAPI.h"
+#include "Device.h"
+#include "Flower.h"
+#include "Table.h"
+#include <stdlib.h>
+#include <vector>
+
+class Controller {
+public:
+    enum cStatus {
+        READY,
+        WAITING,
+        BUSY,
+        ERROR,
+        INIT
+    };
+    Controller(TextLCD *lcd);
+    cStatus getStatus();
+    string statusString();
+    void setStatus(cStatus);
+    void displayStatus();
+    
+    void lcdWriteLine(int row, string str);
+    void printDesc(int c);
+    
+    //DEMO PURPOSES
+    void nextCommand(); 
+    void prevCommand();
+    void sendCommandDem();
+    
+    /**
+        sendCommand() gets the first command from the command list and sends the command to the devices.
+    */
+    void sendCommand();
+    
+    TextLCD *lcd;
+//    MotiVAPI *mapi;
+    
+private:
+    cStatus status;
+    
+    Flower* flower;
+//    std::vector<Device*> devices;
+//    vector <Table>tables
+    vector <Device::mCommand>commandList;
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Device.cpp	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,43 @@
+#include "Device.h"
+#include <stdlib.h>
+
+
+
+using namespace std;
+
+Device::Device()
+    :id(0) {}
+
+Device::Device(int id)
+    :id(id) {}
+
+Device::~Device()
+{
+
+}
+
+Device::Device(const Device& d)
+{
+    id = d.id;
+}
+
+Device& Device::operator=(const Device& d)
+{
+    id = d.id;
+    return *this;
+}
+
+int Device::getId() const
+{
+    return id;
+    }
+    
+Device::mCommand Device::makeCommand(int cmd, int value)
+{
+    mCommand rc;
+    rc.id = id;
+    rc.cmd = cmd;
+    rc.val = value;
+    rc.delim = DELIMITER;
+    return rc;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Device.h	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,42 @@
+#ifndef MOTIV_DEVICE_H
+#define MOTIV_DEVICE_H
+
+#include <string>
+
+#define DELIMITER ';'
+
+//a default constructor that takes no arguments
+//a copy constructor ex: book(const &book b);
+//an overloaded assignment operato
+
+class Device
+{
+public:
+    Device();
+    Device(int id);
+    ~Device();
+
+    Device(const Device& d);
+    Device& operator=(const Device& d);
+    
+    int getId() const;
+
+//private: 
+    struct mCommand { //3 chars to be sent to the hardware
+        char id; //device id
+        char cmd; //command number
+        char val; //command specific value
+        char delim; //delimiter
+    };
+    mCommand makeCommand(int cmdId, int value);
+    
+protected:
+    
+    int id;
+
+private:
+
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Flower.cpp	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,88 @@
+#include "Flower.h"
+#include <string>
+//#include <cstdlib>
+
+
+Flower::Flower()
+    :Device(0) {}
+
+Flower::Flower(int id)
+    :Device(id) {}
+
+Flower::~Flower()
+{
+
+}
+
+Flower::Flower(const Flower& f)
+{
+    id = f.getId();
+}
+
+Flower& Flower::operator=(const Flower& f)
+{
+    id = f.getId();
+    return *this;
+}
+
+void Flower::setLed(int state)
+{}
+
+//This can be in config file later on
+//Also, functions with a variable value should be settable
+
+std::string Flower::getCommandDesc(int c)
+{
+    switch(c) {
+        case fRESET:
+            return "reset";
+            break;
+        case fPETAL_SPD:
+            return "set petal speed";
+            break;
+        case fBLINK_SPD:
+            return "set blink speed";
+            break;
+//        fBLINK_PERIOD = 3,
+//        fLED_INTENSITY = 4,
+//        fPETAL_POS = 10,
+//        fLED_TABLE_FREE = 20,
+//        fLED_TABLE_RES = 21,
+//        fLED_FOOD = 22,
+//        fLED_DRINK = 23,
+//        fLED_SERVICE = 24,
+//        fLED_CLR = 29
+            /*        Flower version 2 commands n/a for now.
+            //        fPISTIL_SPD = 3,
+            //        fPETAL1_POS = 11,
+            //        fPETAL2_POS = 12,
+            //        fPETAL3_POS = 13,
+            //        fPETAL4_POS = 14,
+            //        fPETAL5_POS = 15,
+            //        fPETAL6_POS = 16,
+            //        fPISTIL_POS_FOOD = 30,
+            //        fPISTIL_POS_DRINKS = 31,
+            //        fPISTIL_POS_SERVICE = 32 */
+        case fTABLE_FREE:
+            return "table free";
+            break;
+        case fTABLE_ACTIVE:
+            return "table active";
+            break;
+        case fTABLE_RES:
+            return "table reserved";
+            break;
+//        fTABLE_END = 53,
+        case fFOOD_ORDERED:
+            return "food ordered";
+            break;
+            //fDRINKS_ORDERED = 55,
+//        fSERVICE_REQ = 56,
+//        fPETALS_CLOSE = 60,
+//        fLAMP_ACT = 100,
+        case fDEMO1:
+            return "demo program 1";
+            break;
+//        fDEMO2 = 102
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Flower.h	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,139 @@
+/*
+
+Flower commands
+
+Command# - Values - description
+0* 0 Reset (Zet alle waarden terug naar default)
+---
+1* 0 – 100 Zet bewegingssnelheid van de bladeren
+---
+2 0 – 100 Zet knippersnelheid van de verlichting
+3 0 – 100 Zet bewegingssnelheid van de stampers (Niet beschikbaar in bloem versie 1)
+4 0 – 255 Zet tijd
+10* 0 – 100 Zet de positie van de bloembladeren (0 open, 100 dicht)
+11 – 16 0 – 100 Zet de positie van (max. 6) individuele bloembladeren (0 open, 100 dicht) (Niet beschikbaar in bloem versie 1)
+20* 0 … 1 Zet led “tafel vrij”
+21* 0 … 1 Zet led “tafel gereserveerd”
+22* 0 … 1 Zet led F(ood)
+23* 0 … 1 Zet led D(rink)
+24* 0 … 1 Zet led S(ervice)
+29 0 … 1 Zet led verlichting (standaard wit)
+30 0 – 100 Zet hoogte van stamper F(ood) (Niet beschikbaar in bloem versie 1)
+31 0 – 100 Zet hoogte van stamper D(rink) (Niet beschikbaar in bloem versie 1)
+32 0 – 100 Zet hoogte van stamper S(ervice) (Niet beschikbaar in bloem versie 1)
+Complexe functies
+100* 1 Zet bloem naar stand “Tafel vrij” (groen)
+101* 1 Zet bloem naar stand “Tafel gereserveerd” (rood)
+102* 0 – 100 Zet bloem naar stand “Eten besteld” met x% bestelstatus
+103* 0 – 100 Zet bloem naar stand “Drank besteld” met x% bestelstatus
+104* 0 – 100 Zet bloem naar stand “Bediening gevraagd” met x% bestelstatus
+110 1 Bloem sluit al naar gelang de ingestelde tijd
+111 1 Zet bloem naar stand “zittingstijd om”. (“Gereserveerd rood knipperen”)
+200 1 Lampfunctie (Bloem opent een klein beetje en fungeert als lamp)
+201 1 Demostand 1 (Bloem gaat continu open en dicht en alle leds wisselen)
+202 0 – 100 Demostand 2 (Bloem opent naar stand X en statusleds wisselen)
+*/
+
+
+/*
+Flower commands v2
+Functie Waarde(n) Doel
+
+Primaire functies
+
+0* 0 Reset (Zet alle waarden terug naar default)
+1* 0 – 100 Zet bewegingssnelheid van de bladeren (0 langzaam, 100 snel)
+2 0 – 100 Zet knippersnelheid van de verlichting (in %)
+3 0 – 255 Zet knipperlengte van de verlichting (in sec)
+4 0 – 100 Zet de lichtintensiteit van de LEDstrip (0 – 100 %)
+5 0 – 100 Zet bewegingssnelheid van de stampers (Niet beschikbaar in bloem versie 1)
+6 0 – 255 Zet tijd
+10* 0 – 100 Zet de positie van de bloembladeren (0 dicht, 100 open)
+11 – 18 0 – 100 Zet de positie van (max. 8) individuele bloembladeren (0 dicht, 100 open) (Niet beschikbaar in bloem versie 1)
+20* 0 … 1 Zet led “tafel vrij”
+21* 0 … 1 Zet led “tafel gereserveerd”
+22* 0 … 1 Zet led F(ood)
+23* 0 … 1 Zet led D(rink)
+24* 0 … 1 Zet led S(ervice)
+29 0 … 1 Zet led verlichting (standaard wit)
+30 0 – 100 Zet hoogte van stamper F(ood) (Niet beschikbaar in bloem versie 1)
+31 0 – 100 Zet hoogte van stamper D(rink) (Niet beschikbaar in bloem versie 1)
+32 0 – 100 Zet hoogte van stamper S(ervice) (Niet beschikbaar in bloem versie 1)
+Complexe functies
+50* 1 Zet bloem naar stand “Tafel vrij” (Gesloten groen)
+51* 1 Zet bloem naar stand “Tafel in gebruik” (Open groen)
+52* 1 Zet bloem naar stand “Tafel gereserveerd” (Gesloten rood)
+53* 1 Zet bloem naar stand “Zittingstijd om” (Open rood)
+54* 0 – 100 Zet bloem naar stand “Eten besteld” met x% bestelstatus
+55* 0 – 100 Zet bloem naar stand “Drank besteld” met x% bestelstatus
+56* 0 – 100 Zet bloem naar stand “Bediening gevraagd” met x% bestelstatus
+60 1 Bloem sluit al naar gelang de ingestelde tijd
+61 1 Zet bloem naar status “zittingstijd om”. (“Gereserveerd rood knipperen”)
+100 1 Lampfunctie (Bloem opent een klein beetje en fungeert als lamp)
+101 1 Demostand 1 (Bloem gaat continu open en dicht en alle leds wisselen)
+102 0 – 100 Demostand 2 (Bloem opent naar stand X en statusleds wisselen)
+
+*/
+
+
+#ifndef MOTIV_FLOWER_H
+#define MOTIV_FLOWER_H
+
+#include "Device.h"
+#include <string>
+
+class Flower : public Device
+{
+public:
+    Flower();
+    Flower(int id);
+    ~Flower();
+
+    Flower(const Flower& f);
+    Flower& operator=(const Flower& f);
+    
+    enum fCOMMANDS {
+        fRESET = 0,
+        fPETAL_SPD = 1,
+        fBLINK_SPD = 2,
+        fBLINK_PERIOD = 3,
+        fLED_INTENSITY = 4,
+        fPETAL_POS = 10,
+        fLED_TABLE_FREE = 20,
+        fLED_TABLE_RES = 21,
+        fLED_FOOD = 22,
+        fLED_DRINK = 23,
+        fLED_SERVICE = 24,
+        fLED_CLR = 29,
+//        Flower version 2 commands n/a for now.
+//        fPISTIL_SPD = 3,
+//        fPETAL1_POS = 11,
+//        fPETAL2_POS = 12,
+//        fPETAL3_POS = 13,
+//        fPETAL4_POS = 14,
+//        fPETAL5_POS = 15,
+//        fPETAL6_POS = 16,
+//        fPISTIL_POS_FOOD = 30,
+//        fPISTIL_POS_DRINKS = 31,
+//        fPISTIL_POS_SERVICE = 32
+        fTABLE_FREE = 50,
+        fTABLE_ACTIVE = 51,
+        fTABLE_RES = 52,
+        fTABLE_END = 53,
+        fFOOD_ORDERED = 54,
+        fDRINKS_ORDERED = 55,
+        fSERVICE_REQ = 56,
+        fPETALS_CLOSE = 60,
+        fLAMP_ACT = 100,
+        fDEMO1 = 101,
+        fDEMO2 = 102
+    };
+private:
+
+
+public:
+    void setLed(int state); //Set THE LED to state. 0=off, 1=on
+    std::string getCommandDesc(int c);
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/MotiVAPI.cpp	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,21 @@
+//#include "MotiVAPI.h"
+//#include "EthernetInterface.h"
+//#include <string.h>
+//
+//MotiVAPI::MotiVAPI(std::string url)
+//    ://_eni(),
+//     _url(url)
+//{
+//    _eth.init();
+//}
+//
+//MotiVAPI::~MotiVAPI()
+//{
+//
+//}
+//
+//bool MotiVAPI::connectAPI()
+//{
+//
+//    return false;
+//}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/MotiVAPI.h	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,28 @@
+//#ifndef MOTIV_API_H
+//#define MOTIV_API_H
+//
+//#include "EthernetInterface.h"
+//#include <string>
+//
+//using namespace std;
+//
+//class MotiVAPI
+//{
+//    public:
+//    MotiVAPI();
+//    MotiVAPI(string url);
+//    ~MotiVAPI();
+//    
+//    MotiVAPI(const MotiVAPI&);
+//    MotiVAPI& operator=(const MotiVAPI&);
+//    
+//    EthernetInterface eth;
+//    bool connectAPI();
+//    
+//    private:
+//    //Add network connection
+//    string _url;
+//
+//};
+//
+//#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Table.cpp	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,25 @@
+#include "Table.h"
+
+Table::Table() 
+    :   id(0),
+        status(0),
+        fStatus(0),
+        dStatus(0),
+        sStatus(0),
+        statusPrev(0),
+        fStatusPrev(0),
+        dStatusPrev(0),
+        sStatusPrev(0)  {}
+
+Table::Table(int id) 
+    :   id(id),
+        status(0),
+        fStatus(0),
+        dStatus(0),
+        sStatus(0),
+        statusPrev(0),
+        fStatusPrev(0),
+        dStatusPrev(0),
+        sStatusPrev(0)  {}
+
+Table::~Table() {}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/library/Table.h	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,17 @@
+#ifndef MOTIV_TABLE_H
+#define MOTIV_TABLE_H
+
+class Table {
+    public:
+    Table();
+    Table(int id);
+    ~Table();
+    
+    private:
+    int id, status, fStatus, dStatus, sStatus;
+    int statusPrev, fStatusPrev, dStatusPrev, sStatusPrev;
+    
+    
+    };
+    
+#endif
\ No newline at end of file
--- a/main.cpp	Sat Oct 25 00:11:12 2014 +0000
+++ b/main.cpp	Sat Nov 15 13:04:09 2014 +0000
@@ -2,9 +2,13 @@
 //the library "TextLCD.h" was slightly altered to work with the GDM2004D LCD
 #include "TextLCD/TextLCD.h"
 #include "Controller.h"
-#include "MODSERIAL.h"
+#include "EthernetInterface.h"
+#include "SDFileSystem.h"
 #include <string>
 
+/*****************
+    Global vars
+******************/
 //the object "lcd" is initialized to act as a TextLCD with 20x4 characters
 TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);
 
@@ -18,27 +22,37 @@
 
 //Comms
 Serial pc(USBTX, USBRX); //tx, rx
-MODSERIAL rfd(p9, p10); //tx, rx
+Serial rfd(p9, p10); //tx, rx
+EthernetInterface eth;
 
-//
-string displayLines[26] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
+//Storage
+//SD card
+//CS P14
+//MOSI P11
+//CLK P13
+//MISO P12
+//SDFileSystem sdfs(p11,p12,p13,p14, "sdCard");
 
-//Main functionality in here
+
+//Controller mainly directs the program. It directs data and also controls the lcd output.
 Controller c(&lcd);
 
+/**********************
+    Declare functions
+***********************/
+
 void setup(); //Called once to setup
 void runProgram(); //Program with loop
 
+/****************
+      MAIN
+*****************/
 int main()
 {
     setup();
 
     //the LCD is cleared using function .cls()
     lcd.cls();
-    //a "\n" in a text string causes a line feed
-    lcd.printf("HELLO WORLDZ\n");
-    //if the end of a line is reached, the text is written to the next line automatically
-    //lcd.printf("Testbed for mbed\nLCD example software with altered library");
 
     pc.printf("Entering loop\r\n");
 
@@ -46,55 +60,192 @@
     runProgram();
 }
 
+/*************************
+  Implement  Function
+*************************/
 
 void setup()
 {
     pc.printf("Setup Controller Box\r\n");
+    c.setStatus(Controller::INIT);
     rfd.baud(9600);
+
+    //Initialize Ethernet
+    eth.init();
+    eth.connect();
 }
 
 void runProgram()
 {
-    c._lcd->cls();
-    c._lcd->locate(0,0);
+    c.lcd->cls();
+    c.lcd->locate(0,0);
     c.displayStatus();
+//    c.printDesc(1);
+    string ip = eth.getIPAddress();
+    c.setStatus(Controller::READY);
+
+    UDPSocket sock;
+    sock.init();
+    
+    Endpoint nist;
+    nist.set_address("utcnist.colorado.edu", 37);
+    
+    char out_buffer[] = "plop"; // Does not matter
+    sock.sendTo(nist, out_buffer, sizeof(out_buffer));
+    
+    char in_buffer[4];
+    int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer));
     
-    if(!rfd.writeable())
-    {
-        c._lcd->locate(0,1);
-        c._lcd->clearLine();
-        c._lcd->printf("rfd not writeable");
-    } else {
-        c._lcd->locate(0,1);
-        c._lcd->clearLine();
-        c._lcd->printf("rfd writeable");
-        if(!rfd.txBufferSane())
-        {
-            c._lcd->locate(0,3);
-            c._lcd->printf("buffer not sane");   
-        }
-    }
+    unsigned int timeRes = ntohl( *((unsigned int*)in_buffer));
+    pc.printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, nist.get_address(), nist.get_port(), timeRes);
+    
+    sock.close();
+
+
+    pc.printf("%s", ip);
+
+//    c.writeLine(3, ("IP: " + ipa));
+    c.lcd->locate(0,3);
+    c.lcd->clearLine();
+    c.lcd->locate(0,3);
+    c.lcd->printf("IP: %s", ip);
+
+    //Reset flower
+    rfd.putc(2);
+    rfd.putc(0);
+    rfd.putc(0);
+    rfd.putc(';');
+    wait_ms(2000);
 
     char received = 'a';
 
-    
+    string str = "";
+    int counter = 0;
+    int counterLast = -1;
+    bool pushedUp = false;
+    bool pushedDown = false;
+
     while(1) {
-//        rfd.printf("aaiPoesjes"); //TEST broadcast text
-        received = rfd.txGetLastChar();
-        c.displWriteLine(3, 'a');
-        pc.printf("%c", received);
-        received = 'b';
-        if(!Up)
-        {
-            c.setStatus(c.BUSY);
-            wait(1);
-            rfd.printf("%s","161;");
-            wait_ms(100);
-            rfd.printf("%s","308;");
-        } else {
-            c.setStatus(c.READY);
+
+//        received = rfd.txGetLastChar();
+//        c.displWriteLine(3, 'a');
+//        pc.printf("%c", received);
+//        received = 'b';
+        if(!Up && !pushedUp) {
+            pushedUp = true;
+            //Last resort
+//            c.setStatus(c.BUSY);
+            if(counter >= 6)
+                counter = 0;
+            else
+                counter++;
+        } else if(!Down && !pushedDown) {
+            pushedDown = true;
+            //Last resort
+            //  c.setStatus(c.READY);
+            if(counter < 0)
+                counter = 5;
+            else
+                counter--;
+        } else if(Up)
+            pushedUp = false;
+            else if(Down)
+            pushedDown = false;
+
+        if(counter != counterLast) {
+            switch(counter) {
+                case 0: //Tafel vrij
+                    rfd.putc(2);
+                    rfd.putc(50);
+                    rfd.putc(1);
+                    rfd.putc(';');
+                    str = "Tafel vrij";
+                    break;
+
+                case 1: //Tafel gereserveerd
+                    rfd.putc(2);
+                    rfd.putc(52);
+                    rfd.putc(1);
+                    rfd.putc(';');
+                    str = "Tafel gereserveerd";
+                    break;
+
+                case 2: //Tafel in gebruik
+                    rfd.putc(2);
+                    rfd.putc(29);
+                    rfd.putc(1);
+                    rfd.putc(';');
+                    wait_ms(500);
+                    rfd.putc(2);
+                    rfd.putc(51);
+                    rfd.putc(1);
+                    rfd.putc(';');
+                    str = "Tafel in gebruik";
+                    break;
+
+                case 3: //Eten besteld 20
+                    rfd.putc(2);
+                    rfd.putc(54);
+                    rfd.putc(50);
+                    rfd.putc(';');
+                    str = "Eten best. 50";
+                    break;
+
+                case 4: //Eten besteld 100
+                    rfd.putc(2);
+                    rfd.putc(54);
+                    rfd.putc(100);
+                    rfd.putc(';');
+                    str = "Eten best. 100";
+                    break;
+
+                case 5: //Demo 1
+                    rfd.putc(2);
+                    rfd.putc(101);
+                    rfd.putc(1);
+                    rfd.putc(';');
+                    str = "Demo 1";
+                    break;
+
+                default: //Default: lamp modus
+                    rfd.putc(2);
+                    rfd.putc(100);
+                    rfd.putc(1);
+                    rfd.putc(';');
+                    break;
+            }
+            counterLast = counter;
+        c.lcdWriteLine(2, str);
         }
-        wait_ms(1000);
+
+
+        wait_ms(200);
         //__WFI();
     }
-}
\ No newline at end of file
+}
+
+
+/*
+EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    
+    UDPSocket sock;
+    sock.init();
+    
+    Endpoint nist;
+    nist.set_address("utcnist.colorado.edu", 37);
+    
+    char out_buffer[] = "plop"; // Does not matter
+    sock.sendTo(nist, out_buffer, sizeof(out_buffer));
+    
+    char in_buffer[4];
+    int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer));
+    
+    unsigned int timeRes = ntohl( *((unsigned int*)in_buffer));
+    printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, nist.get_address(), nist.get_port(), timeRes);
+    
+    sock.close();
+    
+    eth.disconnect();
+    */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sat Nov 15 13:04:09 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#318e02f48146
--- a/mbed.bld	Sat Oct 25 00:11:12 2014 +0000
+++ b/mbed.bld	Sat Nov 15 13:04:09 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file