![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ControllerBox directs electromechanical equipment in restaurants to display information.
Dependencies: TextLCD MbedJSONValue libMotiv picojson mbed-rtos mbed
Fork of Mbed_MotiVControllerBox by
main.cpp@12:aedaf4554a44, 2015-01-14 (annotated)
- Committer:
- TimWoo
- Date:
- Wed Jan 14 21:02:31 2015 +0000
- Revision:
- 12:aedaf4554a44
- Parent:
- 11:17ccf6a50944
Some more cleaning up. Removed RTC library as it is not used.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TimWoo | 0:2279181caaa1 | 1 | #include "mbed.h" |
TimWoo | 0:2279181caaa1 | 2 | #include "TextLCD/TextLCD.h" |
TimWoo | 0:2279181caaa1 | 3 | #include "Controller.h" |
TimWoo | 9:11d0c72fef0d | 4 | //#include "picojson.h" |
TimWoo | 9:11d0c72fef0d | 5 | //#include "EthernetInterface.h" |
TimWoo | 5:e22a1ae893d2 | 6 | //#include "HTTPClient.h" |
TimWoo | 9:11d0c72fef0d | 7 | #include "libMotiv.h" |
TimWoo | 0:2279181caaa1 | 8 | #include <string> |
TimWoo | 0:2279181caaa1 | 9 | |
TimWoo | 1:d54aed10ddf3 | 10 | /***************** |
TimWoo | 1:d54aed10ddf3 | 11 | Global vars |
TimWoo | 1:d54aed10ddf3 | 12 | ******************/ |
TimWoo | 0:2279181caaa1 | 13 | //the object "lcd" is initialized to act as a TextLCD with 20x4 characters |
TimWoo | 0:2279181caaa1 | 14 | TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4); |
TimWoo | 0:2279181caaa1 | 15 | |
TimWoo | 9:11d0c72fef0d | 16 | //Timer for keeping track of intervals |
TimWoo | 9:11d0c72fef0d | 17 | Timer tim; |
TimWoo | 9:11d0c72fef0d | 18 | int intervalSec = 10; |
TimWoo | 9:11d0c72fef0d | 19 | |
TimWoo | 0:2279181caaa1 | 20 | |
TimWoo | 10:f03c1cb12f45 | 21 | |
TimWoo | 0:2279181caaa1 | 22 | //inputs |
TimWoo | 0:2279181caaa1 | 23 | DigitalIn Up(p8); |
TimWoo | 0:2279181caaa1 | 24 | DigitalIn Down(p14); |
TimWoo | 10:f03c1cb12f45 | 25 | bool pushedUp = false; |
TimWoo | 10:f03c1cb12f45 | 26 | bool pushedDown = false; |
TimWoo | 0:2279181caaa1 | 27 | |
TimWoo | 0:2279181caaa1 | 28 | //outputs |
TimWoo | 0:2279181caaa1 | 29 | DigitalOut led(p6); |
TimWoo | 0:2279181caaa1 | 30 | |
TimWoo | 0:2279181caaa1 | 31 | //Comms |
TimWoo | 0:2279181caaa1 | 32 | Serial pc(USBTX, USBRX); //tx, rx |
TimWoo | 1:d54aed10ddf3 | 33 | Serial rfd(p9, p10); //tx, rx |
TimWoo | 2:ad4509a9d051 | 34 | |
TimWoo | 2:ad4509a9d051 | 35 | //TODO: Should be the responsibility of Controller |
TimWoo | 9:11d0c72fef0d | 36 | //EthernetInterface eth; //Doeesn't want to initialize in the objects Controller->mAPI |
TimWoo | 9:11d0c72fef0d | 37 | //HTTPClient http; |
TimWoo | 9:11d0c72fef0d | 38 | //char str[1024]; |
TimWoo | 0:2279181caaa1 | 39 | |
TimWoo | 1:d54aed10ddf3 | 40 | //Storage |
TimWoo | 1:d54aed10ddf3 | 41 | //SD card |
TimWoo | 1:d54aed10ddf3 | 42 | //CS P14 |
TimWoo | 1:d54aed10ddf3 | 43 | //MOSI P11 |
TimWoo | 1:d54aed10ddf3 | 44 | //CLK P13 |
TimWoo | 1:d54aed10ddf3 | 45 | //MISO P12 |
TimWoo | 1:d54aed10ddf3 | 46 | //SDFileSystem sdfs(p11,p12,p13,p14, "sdCard"); |
TimWoo | 0:2279181caaa1 | 47 | |
TimWoo | 1:d54aed10ddf3 | 48 | |
TimWoo | 3:21c8adb97c8f | 49 | |
TimWoo | 1:d54aed10ddf3 | 50 | //Controller mainly directs the program. It directs data and also controls the lcd output. |
TimWoo | 9:11d0c72fef0d | 51 | Controller c(&lcd, &rfd/*, ð*/); |
TimWoo | 0:2279181caaa1 | 52 | |
TimWoo | 1:d54aed10ddf3 | 53 | /********************** |
TimWoo | 1:d54aed10ddf3 | 54 | Declare functions |
TimWoo | 1:d54aed10ddf3 | 55 | ***********************/ |
TimWoo | 1:d54aed10ddf3 | 56 | |
TimWoo | 0:2279181caaa1 | 57 | void setup(); //Called once to setup |
TimWoo | 0:2279181caaa1 | 58 | void runProgram(); //Program with loop |
TimWoo | 9:11d0c72fef0d | 59 | void runController(); //Controller loop |
TimWoo | 0:2279181caaa1 | 60 | |
TimWoo | 1:d54aed10ddf3 | 61 | /**************** |
TimWoo | 1:d54aed10ddf3 | 62 | MAIN |
TimWoo | 1:d54aed10ddf3 | 63 | *****************/ |
TimWoo | 0:2279181caaa1 | 64 | int main() |
TimWoo | 0:2279181caaa1 | 65 | { |
TimWoo | 9:11d0c72fef0d | 66 | // eth.init(); |
TimWoo | 9:11d0c72fef0d | 67 | // eth.connect(); |
TimWoo | 5:e22a1ae893d2 | 68 | printf("int main()\r\n"); |
TimWoo | 9:11d0c72fef0d | 69 | c.init(); |
TimWoo | 9:11d0c72fef0d | 70 | setup(); |
TimWoo | 9:11d0c72fef0d | 71 | |
TimWoo | 9:11d0c72fef0d | 72 | runController(); |
TimWoo | 0:2279181caaa1 | 73 | } |
TimWoo | 0:2279181caaa1 | 74 | |
TimWoo | 1:d54aed10ddf3 | 75 | /************************* |
TimWoo | 1:d54aed10ddf3 | 76 | Implement Function |
TimWoo | 1:d54aed10ddf3 | 77 | *************************/ |
TimWoo | 0:2279181caaa1 | 78 | |
TimWoo | 0:2279181caaa1 | 79 | void setup() |
TimWoo | 0:2279181caaa1 | 80 | { |
TimWoo | 0:2279181caaa1 | 81 | pc.printf("Setup Controller Box\r\n"); |
TimWoo | 1:d54aed10ddf3 | 82 | c.setStatus(Controller::INIT); |
TimWoo | 0:2279181caaa1 | 83 | rfd.baud(9600); |
TimWoo | 10:f03c1cb12f45 | 84 | lcd.clearDisplay(); |
TimWoo | 2:ad4509a9d051 | 85 | wait_ms(200); |
TimWoo | 0:2279181caaa1 | 86 | } |
TimWoo | 0:2279181caaa1 | 87 | |
TimWoo | 9:11d0c72fef0d | 88 | void runController() |
TimWoo | 9:11d0c72fef0d | 89 | { |
TimWoo | 9:11d0c72fef0d | 90 | int count; |
TimWoo | 9:11d0c72fef0d | 91 | tim.start(); |
TimWoo | 11:17ccf6a50944 | 92 | while(1) {//programma loop |
TimWoo | 9:11d0c72fef0d | 93 | if(tim.read() > intervalSec) { //polling interval passed, update tables |
TimWoo | 10:f03c1cb12f45 | 94 | printf("\r\n\r\n*%f seconds passed, reset timer*\r\n", tim.read()); |
TimWoo | 9:11d0c72fef0d | 95 | tim.reset(); |
TimWoo | 11:17ccf6a50944 | 96 | c.update();//update Table collection with API data |
TimWoo | 9:11d0c72fef0d | 97 | } |
TimWoo | 11:17ccf6a50944 | 98 | c.sendCommands(&tim, intervalSec);//Send a number of commands if commands in commandList |
TimWoo | 9:11d0c72fef0d | 99 | } |
TimWoo | 11:17ccf6a50944 | 100 | } |