
ControllerBox directs electromechanical equipment in restaurants to display information.
Dependencies: TextLCD MbedJSONValue libMotiv picojson mbed-rtos mbed
Fork of Mbed_MotiVControllerBox by
library/Controller.cpp@1:d54aed10ddf3, 2014-11-15 (annotated)
- Committer:
- TimWoo
- Date:
- Sat Nov 15 13:04:09 2014 +0000
- Revision:
- 1:d54aed10ddf3
- Parent:
- Controller.cpp@0:2279181caaa1
Dirty testing stage. Testing ethernet/internet connection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TimWoo | 0:2279181caaa1 | 1 | #include <string> |
TimWoo | 1:d54aed10ddf3 | 2 | #include <stdlib.h> |
TimWoo | 0:2279181caaa1 | 3 | #include "TextLCD.h" |
TimWoo | 0:2279181caaa1 | 4 | #include "Controller.h" |
TimWoo | 1:d54aed10ddf3 | 5 | #include "Device.h" |
TimWoo | 1:d54aed10ddf3 | 6 | #include "Table.h" |
TimWoo | 1:d54aed10ddf3 | 7 | #include "Flower.h" |
TimWoo | 1:d54aed10ddf3 | 8 | //#include "MotiVAPI.h" |
TimWoo | 1:d54aed10ddf3 | 9 | |
TimWoo | 1:d54aed10ddf3 | 10 | //Test endpoint: http://demo.motiv.jvanbaarsen.com/demo/test |
TimWoo | 1:d54aed10ddf3 | 11 | using namespace std; |
TimWoo | 0:2279181caaa1 | 12 | |
TimWoo | 0:2279181caaa1 | 13 | Controller::Controller(TextLCD *lcd): |
TimWoo | 1:d54aed10ddf3 | 14 | status(WAITING) |
TimWoo | 0:2279181caaa1 | 15 | { |
TimWoo | 1:d54aed10ddf3 | 16 | this->lcd = lcd; |
TimWoo | 0:2279181caaa1 | 17 | //setStatus(WAITING); |
TimWoo | 1:d54aed10ddf3 | 18 | // _mapi = new MotiVAPI("http://demo.motiv.jvanbaarsen.com/demo/test"); |
TimWoo | 0:2279181caaa1 | 19 | displayStatus(); |
TimWoo | 1:d54aed10ddf3 | 20 | // devices.push_back(new <Device>Flower(1)); |
TimWoo | 1:d54aed10ddf3 | 21 | // devices.append(new Flower(2)); |
TimWoo | 1:d54aed10ddf3 | 22 | // devices.append(new Flower(3)); |
TimWoo | 1:d54aed10ddf3 | 23 | |
TimWoo | 1:d54aed10ddf3 | 24 | // tables.append(new Table(1)); |
TimWoo | 1:d54aed10ddf3 | 25 | // tables.append(new Table(2)); |
TimWoo | 1:d54aed10ddf3 | 26 | // tables.append(new Table(3)); |
TimWoo | 1:d54aed10ddf3 | 27 | |
TimWoo | 1:d54aed10ddf3 | 28 | flower = new Flower(1); |
TimWoo | 1:d54aed10ddf3 | 29 | commandList.push_back(flower->makeCommand(flower->fRESET, 0)); |
TimWoo | 1:d54aed10ddf3 | 30 | commandList.push_back(flower->makeCommand(flower->fPETAL_SPD, 50)); |
TimWoo | 1:d54aed10ddf3 | 31 | commandList.push_back(flower->makeCommand(flower->fPETAL_POS, 50)); |
TimWoo | 1:d54aed10ddf3 | 32 | commandList.push_back(flower->makeCommand(flower->fDEMO1, 1)); |
TimWoo | 1:d54aed10ddf3 | 33 | printDesc(commandList[1].cmd); |
TimWoo | 1:d54aed10ddf3 | 34 | } |
TimWoo | 1:d54aed10ddf3 | 35 | |
TimWoo | 1:d54aed10ddf3 | 36 | void Controller::printDesc(int c) |
TimWoo | 1:d54aed10ddf3 | 37 | { |
TimWoo | 1:d54aed10ddf3 | 38 | string desc = flower->getCommandDesc(c); |
TimWoo | 1:d54aed10ddf3 | 39 | lcdWriteLine(2, desc); |
TimWoo | 0:2279181caaa1 | 40 | } |
TimWoo | 0:2279181caaa1 | 41 | |
TimWoo | 0:2279181caaa1 | 42 | Controller::cStatus Controller::getStatus() |
TimWoo | 0:2279181caaa1 | 43 | { |
TimWoo | 1:d54aed10ddf3 | 44 | return this->status; |
TimWoo | 0:2279181caaa1 | 45 | } |
TimWoo | 0:2279181caaa1 | 46 | |
TimWoo | 0:2279181caaa1 | 47 | string Controller::statusString() |
TimWoo | 0:2279181caaa1 | 48 | { |
TimWoo | 1:d54aed10ddf3 | 49 | switch(status) { |
TimWoo | 0:2279181caaa1 | 50 | case READY: |
TimWoo | 0:2279181caaa1 | 51 | return "ready"; |
TimWoo | 0:2279181caaa1 | 52 | |
TimWoo | 0:2279181caaa1 | 53 | case WAITING: |
TimWoo | 0:2279181caaa1 | 54 | return "waiting"; |
TimWoo | 0:2279181caaa1 | 55 | |
TimWoo | 0:2279181caaa1 | 56 | case BUSY: |
TimWoo | 0:2279181caaa1 | 57 | return "busy"; |
TimWoo | 0:2279181caaa1 | 58 | |
TimWoo | 0:2279181caaa1 | 59 | case ERROR: |
TimWoo | 0:2279181caaa1 | 60 | return "error"; |
TimWoo | 0:2279181caaa1 | 61 | |
TimWoo | 1:d54aed10ddf3 | 62 | case INIT: |
TimWoo | 1:d54aed10ddf3 | 63 | return "intializing"; |
TimWoo | 1:d54aed10ddf3 | 64 | |
TimWoo | 0:2279181caaa1 | 65 | default: |
TimWoo | 0:2279181caaa1 | 66 | return "unknown"; |
TimWoo | 0:2279181caaa1 | 67 | } |
TimWoo | 0:2279181caaa1 | 68 | } |
TimWoo | 0:2279181caaa1 | 69 | |
TimWoo | 0:2279181caaa1 | 70 | void Controller::setStatus(cStatus status) |
TimWoo | 0:2279181caaa1 | 71 | { |
TimWoo | 1:d54aed10ddf3 | 72 | this->status = status; |
TimWoo | 0:2279181caaa1 | 73 | displayStatus(); |
TimWoo | 0:2279181caaa1 | 74 | } |
TimWoo | 0:2279181caaa1 | 75 | |
TimWoo | 0:2279181caaa1 | 76 | void Controller::displayStatus() |
TimWoo | 0:2279181caaa1 | 77 | { |
TimWoo | 1:d54aed10ddf3 | 78 | this->lcd->locate(0,0); |
TimWoo | 1:d54aed10ddf3 | 79 | this->lcd->clearLine(); |
TimWoo | 1:d54aed10ddf3 | 80 | this->lcd->locate(0,0); |
TimWoo | 1:d54aed10ddf3 | 81 | this->lcd->printf("Status: %s", statusString()); |
TimWoo | 1:d54aed10ddf3 | 82 | } |
TimWoo | 1:d54aed10ddf3 | 83 | |
TimWoo | 1:d54aed10ddf3 | 84 | |
TimWoo | 1:d54aed10ddf3 | 85 | void Controller::lcdWriteLine(int row, string str) |
TimWoo | 1:d54aed10ddf3 | 86 | { |
TimWoo | 1:d54aed10ddf3 | 87 | this->lcd->locate(0,row); |
TimWoo | 1:d54aed10ddf3 | 88 | this->lcd->clearLine(); |
TimWoo | 1:d54aed10ddf3 | 89 | this->lcd->locate(0,row); |
TimWoo | 1:d54aed10ddf3 | 90 | this->lcd->printf("%s", str); |
TimWoo | 0:2279181caaa1 | 91 | } |
TimWoo | 0:2279181caaa1 | 92 | |
TimWoo | 1:d54aed10ddf3 | 93 | void Controller::nextCommand() |
TimWoo | 0:2279181caaa1 | 94 | { |
TimWoo | 1:d54aed10ddf3 | 95 | std::vector<Device::mCommand>::iterator it; |
TimWoo | 1:d54aed10ddf3 | 96 | it = commandList.begin(); |
TimWoo | 1:d54aed10ddf3 | 97 | it = commandList.insert(it, commandList.back()); |
TimWoo | 1:d54aed10ddf3 | 98 | it = commandList.begin(); |
TimWoo | 1:d54aed10ddf3 | 99 | commandList.pop_back(); |
TimWoo | 1:d54aed10ddf3 | 100 | it = commandList.begin(); |
TimWoo | 1:d54aed10ddf3 | 101 | Flower::mCommand command = *it; |
TimWoo | 1:d54aed10ddf3 | 102 | printDesc(command.cmd); |
TimWoo | 1:d54aed10ddf3 | 103 | } |
TimWoo | 1:d54aed10ddf3 | 104 | |
TimWoo | 1:d54aed10ddf3 | 105 | void Controller::prevCommand() |
TimWoo | 1:d54aed10ddf3 | 106 | { |
TimWoo | 1:d54aed10ddf3 | 107 | |
TimWoo | 1:d54aed10ddf3 | 108 | } |
TimWoo | 1:d54aed10ddf3 | 109 | |
TimWoo | 1:d54aed10ddf3 | 110 | void Controller::sendCommandDem() |
TimWoo | 1:d54aed10ddf3 | 111 | { |
TimWoo | 1:d54aed10ddf3 | 112 | |
TimWoo | 1:d54aed10ddf3 | 113 | } |
TimWoo | 1:d54aed10ddf3 | 114 |