
ControllerBox directs electromechanical equipment in restaurants to display information.
Dependencies: TextLCD MbedJSONValue libMotiv picojson mbed-rtos mbed
Fork of Mbed_MotiVControllerBox by
Revision 3:21c8adb97c8f, committed 2014-12-04
- Comitter:
- TimWoo
- Date:
- Thu Dec 04 22:26:30 2014 +0000
- Parent:
- 2:ad4509a9d051
- Child:
- 4:8155d4d6a193
- Commit message:
- Still sandboxing, but more inside the classes.; ; command building by Device and thus Flower works; updating table works; commandList basics now done;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libMotiv/Controller.cpp Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,221 @@ +#include <string> +#include <stdlib.h> +#include "TextLCD.h" +#include "Controller.h" +#include "Device.h" +#include "Table.h" +#include "Flower.h" + +#include <exception> +//#include <logic_error> +//#include <runtime_error> +#include <iostream> +//Flower commands +// 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 +//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) + +//#include "MotiVAPI.h" + +//Test endpoint: http://demo.motiv.jvanbaarsen.com/demo/test +using namespace std; + +Controller::Controller(TextLCD *lcd): + status(WAITING) +{ + printf("Controller constructor\r\n"); + 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)); + + //tables stores Tables + //Tables can be updated with information + //Tables can be asked for commands to send + //Tables will check changes between new info (this API update) and old info (previous API update) + //Tables can use the Flower interface to build commands + + + //Would like to have: + //Sending commands in different thread than receiving api update + //Commands then put into shared object commandQueue (FIFO) + + +// Test + Table table(1); + Table table2(2); + + vector<MCommand> insertVector; + insertVector = table.update(1,0,0,0); + printf("Updated first table\r\n"); + commandList.insert(commandList.begin(), insertVector.begin(), insertVector.end()); + printCommandList(); + insertVector = table2.update(2,0,0,0); + printf("Updated second table\r\n"); + commandList.insert(commandList.begin(), insertVector.begin(), insertVector.end()); +} + +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<MCommand>::iterator it; +// it = commandList->begin(); +// it = commandList->insert(it, commandList->back()); +// it = commandList->begin(); +// commandList->pop_back(); +// it = commandList->begin(); +// MCommand command = *it; +// printDesc(command->getCmd()); +//} + +void Controller::prevCommand() +{ + +} + +void Controller::sendCommandDem() +{ + +} + +void Controller::printCommandList() +{ + printf("\r\nCommand list printing\r\n\r\n"); + printf("The command list contains %d commands\r\n", commandList.size()); + if(commandList.size()) { + for(std::vector<MCommand>::iterator it = commandList.begin(); it != commandList.end(); ++it) { + /* std::cout << *it; ... */ + it->print(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libMotiv/Controller.h Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,58 @@ +#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(); + + + //DEBUG + void printCommandList(); + + /** + 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; + + +// std::vector<Device*> devices; +// vector <Table>tables + vector <MCommand> commandList; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libMotiv/Device.cpp Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,104 @@ +#include "Device.h" +#include <stdlib.h> + + + +using namespace std; + +//MCommand +MCommand::MCommand() + :id(0), + cmd(0), + val(0) { + printf("MCommand default constructor\r\n"); + } + +MCommand::MCommand(char id, char cmd, char val) + :id(id), + cmd(cmd), + val(val) +{ + printf("MCommand::MCommand(%d, %d, %d)\r\n", id, cmd, val); +} + +MCommand::~MCommand() +{ + +} + +MCommand& MCommand::operator=(const MCommand& mc) +{ + id = mc.id; + cmd = mc.cmd; + val = mc.val; + return *this; +} + +char MCommand::getId() +{ + return id; +} + +char MCommand::getCmd() +{ + return cmd; +} + +char MCommand::getVal() +{ + return val; +} + +void MCommand::print() +{ + printf(" This command's values are: id=%d, cmd=%d, val=%d\r\n", this->id, this->cmd, this->val); +} + + +//Device +Device::Device() + :id(0) { + printf("Device default constructor\r\n"); + } + +Device::Device(int id) + :id(id) { + printf("Device constructor override (int id)\r\n"); + } + +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; +} + +MCommand Device::buildCommand(char cmd, char value) +{ + printf("Device::buildCommand(%d, %d) Device::id = %d\r\n", cmd, value, this->id); + MCommand retCmd(this->id, cmd, value); + printf("Command initialized\r\n"); +// rc.id = id; +// printf("id set"); +// rc.cmd = cmd; +// printf("cmd set"); +// rc.val = value; +// printf("val set"); +// rc.delim = DELIMITER; + printf("Command = %d, %d, %d\r\n", retCmd.getId(), retCmd.getCmd(), retCmd.getVal()); + return retCmd; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libMotiv/Device.h Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,64 @@ +#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 MCommand +{ + public: + + MCommand(); + MCommand(char id, char cmd, char val); + ~MCommand(); + + MCommand& operator=(const MCommand& mc); + + char getId(), getCmd(), getVal(); + void print(); + + private: + char id, cmd, val; +}; + + + +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 buildCommand(int,int); + */ + MCommand buildCommand(char cmd, char value); + +protected: + + int id; + +private: + + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libMotiv/Flower.cpp Thu Dec 04 22:26:30 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/libMotiv/Flower.h Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,104 @@ +/* +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/libMotiv/MotiVAPI.cpp Thu Dec 04 22:26:30 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/libMotiv/MotiVAPI.h Thu Dec 04 22:26:30 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/libMotiv/Table.cpp Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,195 @@ +#include "Table.h" +#include "Flower.h" +#include "Device.h" +#include "stdlib.h" +#include <vector> +//Flower commands +// 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 +//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) + +using namespace std; + +Table::Table() + : id(0), + status(0), + fStatus(0), + dStatus(0), + sStatus(0), + statusPrev(0), + fStatusPrev(0), + dStatusPrev(0), + sStatusPrev(0) { printf("Table default constructor\r\n"); } + +Table::Table(int id) + : id(id), + status(0), + fStatus(0), + dStatus(0), + sStatus(0), + statusPrev(0), + fStatusPrev(0), + dStatusPrev(0), + sStatusPrev(0), + mFlower(id) +{ + printf("Table constructor override(int id)\r\n"); + } + +Table::~Table() {} + +Table& Table::operator=(const Table& tbl) +{ + id = tbl.id; + status = tbl.status; + fStatus = tbl.fStatus; + dStatus = tbl.dStatus; + sStatus = tbl.sStatus; + statusPrev = tbl.statusPrev; + fStatusPrev = tbl.fStatusPrev; + dStatusPrev = tbl.dStatusPrev; + sStatusPrev = tbl.sStatusPrev; + return *this; +} + +vector<MCommand> Table::update(int dinnerStatus, int foodStatus, int drinkStatus, int serviceStatus) +{ + printf("update table\r\n"); + //current info is now previous info + statusPrev = status; + fStatusPrev = fStatus; + dStatusPrev = dStatus; + sStatusPrev = sStatus; + + + //new info from API is current info + status = dinnerStatus; + fStatus = foodStatus; + dStatus = drinkStatus; + sStatus = serviceStatus; + + printf("dinnerStatus = %d\r\nstatus = %d\r\nstatusPrev = %d\r\n", dinnerStatus, status, statusPrev); + //make and "send" the commands to control the devices to the controller + return prepareCommands(); +} + +int Table::getId() +{ + return this->id; +} + +vector<MCommand> Table::prepareCommands() +{ + vector<MCommand> commandList; + printf("prepareCommands()\r\n"); + //Decide what commands to retrieve from the flower + if(status != statusPrev) { //dinner status has changed since last update + if(status == 0) { //Table free + printf("status == 0\r\n"); + commandList.push_back(mFlower.buildCommand(Flower::fPETAL_POS, 0)); + commandList.push_back(mFlower.buildCommand(Flower::fLED_TABLE_FREE, 1)); + commandList.push_back(mFlower.buildCommand(Flower::fLED_FOOD, 0)); + commandList.push_back(mFlower.buildCommand(Flower::fLED_DRINK, 0)); + commandList.push_back(mFlower.buildCommand(Flower::fLED_SERVICE, 0)); + } else if(status == 1) { //Table reserved + printf("status == 1\r\n"); +// commandList.push_back(mFlower.buildCommand(Flower::fPETAL_POS, 0)); + commandList.push_back(mFlower.buildCommand(Flower::fLED_TABLE_RES, 1)); //For now assume that table reserved is only called after table free +// MCommand leCmd = mFlower.buildCommand(Flower::fLED_TABLE_RES, 1); + printf("Command in prepCommands"); +// leCmd.print(); +// vector<MCommand> cmdLst; +// cmdLst.push_back(leCmd); + printf("pushed_back?\r\n"); +// std::vector<MCommand>::iterator it = commandList.begin(); +// printf("leDeux command: "); +// it->print(); +// commandList.push_back(mFlower.buildCommand(Flower::fLED_FOOD, 0)); +// commandList.push_back(mFlower.buildCommand(Flower::fLED_DRINK, 0)); +// commandList.push_back(mFlower.buildCommand(Flower::fLED_SERVICE, 0)); + } else if(status >= 2) { //Table occupied + printf("status == 2\r\n"); + commandList.push_back(mFlower.buildCommand(Flower::fPETAL_POS, 0)); + commandList.push_back(mFlower.buildCommand(Flower::fLED_CLR, 1)); + } + printf("dinnerStatus commands done\r\n"); + } + if(fStatus != fStatusPrev) { + printf("foodStatus commands done\r\n"); + } + if(dStatus != dStatusPrev) { + printf("drinksStatus commands done\r\n"); + } + if(sStatus != sStatusPrev) { + printf("serviceStatus commands done\r\n"); + } + printf("all commands done\r\n"); + return commandList; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libMotiv/Table.h Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,38 @@ +#ifndef MOTIV_TABLE_H +#define MOTIV_TABLE_H + +#include "Device.h" +#include "Flower.h" +#include <stdlib.h> +#include <vector> + +using namespace std; + +class Table { + public: + Table(); + Table(int id); + ~Table(); + + + Table& operator=(const Table& tbl); + + int getId(); + + vector<MCommand> update(int dinnerStatus,int foodStatus,int drinkStatus,int serviceStatus); + int getNextCommand(); + + + private: + int id, status, fStatus, dStatus, sStatus; + int statusPrev, fStatusPrev, dStatusPrev, sStatusPrev; + + Flower mFlower; + + //"table":{"id":7,"code":"vrij","food":0,"service":0,"drink":0,"dinner_status":0} + + vector<MCommand> prepareCommands(); + + }; + +#endif \ No newline at end of file
--- a/library/Controller.cpp Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -#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
--- a/library/Controller.h Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -#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
--- a/library/Device.cpp Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -#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
--- a/library/Device.h Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -#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
--- a/library/Flower.cpp Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -#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
--- a/library/Flower.h Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -/* - -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
--- a/library/MotiVAPI.cpp Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -//#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
--- a/library/MotiVAPI.h Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -//#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
--- a/library/Table.cpp Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#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
--- a/library/Table.h Tue Dec 02 20:51:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#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 Tue Dec 02 20:51:18 2014 +0000 +++ b/main.cpp Thu Dec 04 22:26:30 2014 +0000 @@ -4,6 +4,7 @@ #include "Controller.h" #include "EthernetInterface.h" #include "HTTPClient.h" +#include "picojson.h" //#include "SDFileSystem.h" Needed if config files are going to be implemented #include <string> @@ -39,6 +40,7 @@ //SDFileSystem sdfs(p11,p12,p13,p14, "sdCard"); + //Controller mainly directs the program. It directs data and also controls the lcd output. Controller c(&lcd); @@ -55,15 +57,21 @@ *****************/ int main() { + printf("\r\n\r\nBuild "); + printf(__DATE__); + printf(" - "); + printf(__TIME__); + printf("\r\n\r\n"); setup(); c.lcd->cls(); //the LCD is cleared using function .cls() lcd.cls(); + c.printCommandList(); pc.printf("Entering loop\r\n"); //the endless loop keeps mbed in low power mode - runProgram(); +// runProgram(); } /************************* @@ -77,8 +85,8 @@ rfd.baud(9600); //Initialize Ethernet - eth.init(); - eth.connect(); +// eth.init(); +// eth.connect(); wait_ms(200); } @@ -88,30 +96,46 @@ c.lcd->locate(0,0); c.displayStatus(); // c.printDesc(1); - string ip = eth.getIPAddress(); - string mStr = "IP: " + ip + "\r\n"; - c.lcdWriteLine(3, mStr); - pc.printf("%s", ip); +// string ip = eth.getIPAddress(); +// string mStr = "IP: " + ip + "\r\n"; +// c.lcdWriteLine(3, mStr); +// pc.printf("%s", ip); +//// +// // - - - //GET data - printf("\nTrying to fetch page...\r\n"); - int ret = http.get("http://core.motiv.jvanbaarsen.com/v1/tables/7", str, 128); - if (!ret) - { - printf("Page fetched successfully - read %d characters\r\n", strlen(str)); - printf("Result: %s\r\n", str); - c.lcdWriteLine(1, str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } - - +// //GET data +// printf("\nTrying to fetch page...\r\n"); +// int ret = http.get("http://core.motiv.jvanbaarsen.com/v1/tables/7", str, 128); +// if (!ret) +// { +// printf("Page fetched successfully - read %d characters\r\n", strlen(str)); +// printf("Result: %s\r\n", str); +// c.lcdWriteLine(1, str); +// } +// else +// { +// 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); @@ -120,8 +144,6 @@ rfd.putc(';'); wait_ms(2000); - char received = 'a'; - string str = ""; int counter = 0; int counterLast = -1;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/picojson.lib Thu Dec 04 22:26:30 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mimil/code/picojson/#2bb500b021e2