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

library/Controller.cpp

Committer:
TimWoo
Date:
2014-11-15
Revision:
1:d54aed10ddf3
Parent:
Controller.cpp@ 0:2279181caaa1

File content as of revision 1:d54aed10ddf3:

#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()
{
    
    }