![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
The MBED firmware used on the Chipin sorter, developed over 12 weeks for a 3rd year university systems project. Chipin is a token sorter, it sorts tokens by colours and dispenses them to order through an online booking system and card reader. This program interfaces with an FPGA, PC and LCD screen to control the sorter. The sorter has an operation mode where it can process orders when a card is entered into the machine. There is also a maintenance mode where the device responds to maintenance instructions such as 'dispense all'. More information at http://www.ionsystems.uk/
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed-rtos mbed
Revision 28:bdf2bf56f97b, committed 2014-12-05
- Comitter:
- IonSystems
- Date:
- Fri Dec 05 09:53:04 2014 +0000
- Parent:
- 27:47a7bc902587
- Commit message:
- Commened main
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Dec 04 22:05:18 2014 +0000 +++ b/main.cpp Fri Dec 05 09:53:04 2014 +0000 @@ -34,11 +34,10 @@ bool testFunctions = true; bool serialComms = true; -int mode = 0; +int mode = 0; //mode select int maintenanceModeSelect = 0; - - +//Call to check if an MBED button is pressed bool buttonPressed(int buttonNumber) { if(buttonNumber > -1 && buttonNumber < 4) { @@ -46,7 +45,7 @@ } return false; } - +//Run a mode, defined by 'mode'. void checkSortDispenseButtons() { @@ -138,7 +137,7 @@ string mainModeSelect = ss.str(); printLCD("Maintenance: " + mainModeSelect); wait(0.1); //Maintenance Mode - //printLCD("Maintenance Mode"); + if(buttonPressed(0)) { //Next maintenance function maintenanceModeSelect++; if(maintenanceModeSelect > 13) maintenanceModeSelect = 0; @@ -216,14 +215,11 @@ printLCD("Ending Maintenance Mode"); maintain(maintenanceEND); break; - - } printLCD("Ready for next command"); wait(1); } } - } //Coordinate changing language on PC and Arduino. void changeLanguage() @@ -259,9 +255,9 @@ sort(colour); } +//Run sortFunction with a small delay between iterations, pulses LED. void sortMode(void const* args) { - while(colourSensor && sorter) { if(operationMode) { led2 = 1; @@ -271,7 +267,9 @@ } } } -bool pcReady = false; + +bool pcReady = false; //Defines whether the PC is ready to accept characters on the COM port. +//handles dispensing from a card, changing language void dispenseFunction() { if(!pcReady) { @@ -298,7 +296,7 @@ int green = 0; int blue = 0; - //Get order from pc + //Get order from pc, convert characters to integers. red = (int) pc.getc() - '0'; green = (int) pc.getc() - '0'; blue = (int) pc.getc() - '0'; @@ -319,9 +317,9 @@ //Display order on LCD glcd.putc(27); glcd.putc(18); - glcd.putc(red + '0'); - glcd.putc(green + '0'); - glcd.putc(blue + '0'); + glcd.putc(red + '0'); //Convert int to char + glcd.putc(green + '0');//Convert int to char + glcd.putc(blue + '0');//Convert int to char glcd.putc(255); //Dispense Order @@ -341,7 +339,7 @@ } } } - +//Runs dispenseFunction with a small delay between iterations, pulses LED. void dispenseMode(void const* args) { @@ -366,13 +364,13 @@ readChipNumbers(); printStoredChipValues(); printLCD("Resetting all sliders"); - maintain(maintenanceEND); + maintain(maintenanceEND); //reset sliders on FPGA printLCD(""); Thread::wait(1000); - sendLanguageCharacter(); + sendLanguageCharacter(); //Synchronise language on PC and arduino - Thread sortThread(sortMode); - if(!languageButton) { + Thread sortThread(sortMode); //Start the sorting thread. + if(!languageButton) { //Decide whether to start in operation mode or maintenance mode. operationMode = true; mode = 0; @@ -380,15 +378,15 @@ operationMode = false; mode = 1; } - Thread dispenseThread(dispenseMode); + Thread dispenseThread(dispenseMode); //Start the dispensing thread. while(true) { - led1 = 1; + led1 = 1; //pulse led1 led4 = cardDetect; - if(!operationMode) { + if(!operationMode) { //Check for maintenance commands if in maintenance mode. checkSerial(); } - if(testFunctions) checkSortDispenseButtons(); + if(testFunctions) checkSortDispenseButtons(); //Run the MBED modes if enabled. Thread::wait(100); led1=0; Thread::wait(100);