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

Committer:
IonSystems
Date:
Wed Nov 12 20:14:45 2014 +0000
Revision:
10:8c0696b99692
Parent:
9:8d78eb55ad5e
Child:
11:06f6e82b40a8
works with serial and buttons, ready for demo tomorrow 13-11-14

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 0:8d54ffcf256e 1 #include "mbed.h"
IonSystems 6:e64796f1f384 2 #include <sstream>
IonSystems 6:e64796f1f384 3 #include "lcdCommands.h"
IonSystems 6:e64796f1f384 4 #include "mbedStorage.h"
IonSystems 6:e64796f1f384 5 #include "rgbLED.h"
IonSystems 6:e64796f1f384 6 #include "mbedLCD.h"
IonSystems 7:6ba00694f9cd 7 #include "stateMachine.h"
IonSystems 8:b7771391adc9 8 #include "FPGAcomms.h"
IonSystems 10:8c0696b99692 9 #ifndef serialComm
IonSystems 10:8c0696b99692 10 #define serialComm
IonSystems 10:8c0696b99692 11 #include "serialCommunication.h"
IonSystems 10:8c0696b99692 12 #endif
IonSystems 10:8c0696b99692 13 #include "testFunctions.h"
IonSystems 5:644bca33c1ca 14
IonSystems 0:8d54ffcf256e 15
IonSystems 7:6ba00694f9cd 16 StateMachine stateMachine;
IonSystems 7:6ba00694f9cd 17
IonSystems 6:e64796f1f384 18 //Boolean values to easily enable and disable certain features for individual testing
IonSystems 6:e64796f1f384 19 bool colourSensor = true;
IonSystems 6:e64796f1f384 20 bool cardReader = true;
IonSystems 6:e64796f1f384 21 bool sorter = true;
IonSystems 6:e64796f1f384 22 bool dispensor = true;
IonSystems 10:8c0696b99692 23 bool testFunctions = true;
IonSystems 10:8c0696b99692 24 bool serialComms = true;
IonSystems 6:e64796f1f384 25
IonSystems 6:e64796f1f384 26 bool colourDataAcquired = false;
IonSystems 6:e64796f1f384 27 bool chipDetected = false;
IonSystems 6:e64796f1f384 28 bool operationMode = true; //the MBED starts in operation mode.
IonSystems 3:97668a4cd69d 29
IonSystems 10:8c0696b99692 30
IonSystems 10:8c0696b99692 31
IonSystems 10:8c0696b99692 32
IonSystems 10:8c0696b99692 33
IonSystems 10:8c0696b99692 34 void checkSortDispenseButtons(){
IonSystems 10:8c0696b99692 35 if(!par_port->read_bit(11)){
IonSystems 10:8c0696b99692 36 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 37 log("Red Button pressed");
IonSystems 10:8c0696b99692 38 stateMachine = DISPENSE_RED;
IonSystems 10:8c0696b99692 39 processState(stateMachine);
IonSystems 10:8c0696b99692 40 }else if(par_port->read_bit(9)){
IonSystems 10:8c0696b99692 41 log("Green Button pressed");
IonSystems 10:8c0696b99692 42 stateMachine = DISPENSE_GREEN;
IonSystems 10:8c0696b99692 43 processState(stateMachine);
IonSystems 10:8c0696b99692 44 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 45 log("Blue Button pressed");
IonSystems 10:8c0696b99692 46 stateMachine = DISPENSE_BLUE;
IonSystems 10:8c0696b99692 47 processState(stateMachine);
IonSystems 10:8c0696b99692 48 }
IonSystems 10:8c0696b99692 49 }else if(par_port->read_bit(11)){
IonSystems 10:8c0696b99692 50 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 51 log("Red Button pressed");
IonSystems 10:8c0696b99692 52 stateMachine = SORT_RED;
IonSystems 10:8c0696b99692 53 processState(stateMachine);
IonSystems 10:8c0696b99692 54 }else if(par_port->read_bit(9)){
IonSystems 10:8c0696b99692 55 log("Green Button pressed");
IonSystems 10:8c0696b99692 56 stateMachine = SORT_GREEN;
IonSystems 10:8c0696b99692 57 processState(stateMachine);
IonSystems 10:8c0696b99692 58 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 59 log("Blue Button pressed");
IonSystems 10:8c0696b99692 60 stateMachine = SORT_BLUE;
IonSystems 10:8c0696b99692 61 processState(stateMachine);
IonSystems 10:8c0696b99692 62 }
IonSystems 9:8d78eb55ad5e 63 }
IonSystems 8:b7771391adc9 64 }
IonSystems 6:e64796f1f384 65
IonSystems 6:e64796f1f384 66 int main() {
IonSystems 7:6ba00694f9cd 67 stateMachine = INITIALISING;
IonSystems 8:b7771391adc9 68 processState(stateMachine);
IonSystems 7:6ba00694f9cd 69 writeFile(2,6,22);
IonSystems 8:b7771391adc9 70 stateMachine = READING_RGB_VALUES;
IonSystems 8:b7771391adc9 71 processState(stateMachine);
IonSystems 8:b7771391adc9 72
IonSystems 8:b7771391adc9 73 while(true){
IonSystems 10:8c0696b99692 74 if(testFunctions) checkSortDispenseButtons();
IonSystems 10:8c0696b99692 75
IonSystems 10:8c0696b99692 76
IonSystems 10:8c0696b99692 77 if(serialComms){
IonSystems 10:8c0696b99692 78 checkSerial();
IonSystems 10:8c0696b99692 79 }
IonSystems 8:b7771391adc9 80 }
IonSystems 10:8c0696b99692 81 /*char c;
IonSystems 10:8c0696b99692 82 if(c = readCharacter()){
IonSystems 10:8c0696b99692 83 processMessage(c);
IonSystems 10:8c0696b99692 84 }*/
IonSystems 10:8c0696b99692 85 }
IonSystems 9:8d78eb55ad5e 86
IonSystems 9:8d78eb55ad5e 87
IonSystems 9:8d78eb55ad5e 88
IonSystems 8:b7771391adc9 89
IonSystems 8:b7771391adc9 90
IonSystems 8:b7771391adc9 91
IonSystems 8:b7771391adc9 92
IonSystems 8:b7771391adc9 93
IonSystems 8:b7771391adc9 94
IonSystems 8:b7771391adc9 95 //printStoredChipValues();
IonSystems 6:e64796f1f384 96 /*
IonSystems 0:8d54ffcf256e 97 while(1){
IonSystems 3:97668a4cd69d 98 if(par_port->read_bit(11)) resetForNextCustomer();
IonSystems 7:6ba00694f9cd 99
IonSystems 3:97668a4cd69d 100 if(cardDetect & !cardDataAcquired) cardAcquisition();
IonSystems 3:97668a4cd69d 101 setLEDs();
IonSystems 3:97668a4cd69d 102 readButtons();
IonSystems 3:97668a4cd69d 103
IonSystems 4:f3be545b3826 104 if(chipDetected & !colourDataAcquired){
IonSystems 4:f3be545b3826 105 Colour colour = readColourSensor();
IonSystems 4:f3be545b3826 106 sendColourSignal(colour);
IonSystems 4:f3be545b3826 107 }
IonSystems 4:f3be545b3826 108
IonSystems 5:644bca33c1ca 109 writeFile(redQueue, greenQueue, blueQueue);
IonSystems 4:f3be545b3826 110 readFile();
IonSystems 4:f3be545b3826 111 wait(2);
IonSystems 4:f3be545b3826 112
IonSystems 0:8d54ffcf256e 113 }
IonSystems 6:e64796f1f384 114 */
IonSystems 6:e64796f1f384 115
IonSystems 8:b7771391adc9 116 /* setLEDcolour(255,0,0);
IonSystems 6:e64796f1f384 117 wait(0.1);
IonSystems 6:e64796f1f384 118 setLEDcolour(0,255,0);
IonSystems 6:e64796f1f384 119 wait(0.1);
IonSystems 6:e64796f1f384 120 setLEDcolour(0,0,255);
IonSystems 6:e64796f1f384 121 wait(0.1);
IonSystems 6:e64796f1f384 122
IonSystems 8:b7771391adc9 123 displayOperationMode(); */
IonSystems 3:97668a4cd69d 124
IonSystems 10:8c0696b99692 125
IonSystems 10:8c0696b99692 126