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:
Mon Nov 17 21:31:42 2014 +0000
Revision:
12:814a8fdbb6f7
Parent:
11:06f6e82b40a8
Child:
13:0661d658d9d1
dispense and sort working well, also stored correct chip values

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 12:814a8fdbb6f7 1 bool operationMode = true; //the MBED starts in operation mode.
IonSystems 0:8d54ffcf256e 2 #include "mbed.h"
IonSystems 6:e64796f1f384 3 #include <sstream>
IonSystems 12:814a8fdbb6f7 4 #include <string>
IonSystems 6:e64796f1f384 5 #include "lcdCommands.h"
IonSystems 6:e64796f1f384 6 #include "mbedStorage.h"
IonSystems 6:e64796f1f384 7 #include "rgbLED.h"
IonSystems 6:e64796f1f384 8 #include "mbedLCD.h"
IonSystems 7:6ba00694f9cd 9 #include "stateMachine.h"
IonSystems 8:b7771391adc9 10 #include "FPGAcomms.h"
IonSystems 10:8c0696b99692 11 #ifndef serialComm
IonSystems 10:8c0696b99692 12 #define serialComm
IonSystems 10:8c0696b99692 13 #include "serialCommunication.h"
IonSystems 10:8c0696b99692 14 #endif
IonSystems 10:8c0696b99692 15 #include "testFunctions.h"
IonSystems 5:644bca33c1ca 16
IonSystems 0:8d54ffcf256e 17
IonSystems 11:06f6e82b40a8 18
IonSystems 11:06f6e82b40a8 19
IonSystems 7:6ba00694f9cd 20 StateMachine stateMachine;
IonSystems 7:6ba00694f9cd 21
IonSystems 6:e64796f1f384 22 //Boolean values to easily enable and disable certain features for individual testing
IonSystems 6:e64796f1f384 23 bool colourSensor = true;
IonSystems 6:e64796f1f384 24 bool cardReader = true;
IonSystems 6:e64796f1f384 25 bool sorter = true;
IonSystems 6:e64796f1f384 26 bool dispensor = true;
IonSystems 10:8c0696b99692 27 bool testFunctions = true;
IonSystems 10:8c0696b99692 28 bool serialComms = true;
IonSystems 6:e64796f1f384 29
IonSystems 6:e64796f1f384 30 bool colourDataAcquired = false;
IonSystems 6:e64796f1f384 31 bool chipDetected = false;
IonSystems 12:814a8fdbb6f7 32
IonSystems 3:97668a4cd69d 33
IonSystems 12:814a8fdbb6f7 34 int mode = 0;
IonSystems 10:8c0696b99692 35
IonSystems 10:8c0696b99692 36
IonSystems 10:8c0696b99692 37
IonSystems 10:8c0696b99692 38
IonSystems 10:8c0696b99692 39 void checkSortDispenseButtons(){
IonSystems 11:06f6e82b40a8 40
IonSystems 11:06f6e82b40a8 41 if(par_port->read_bit(11)){
IonSystems 12:814a8fdbb6f7 42 mode++;
IonSystems 12:814a8fdbb6f7 43 if(mode >= 6) mode = 0;
IonSystems 11:06f6e82b40a8 44 }
IonSystems 11:06f6e82b40a8 45
IonSystems 11:06f6e82b40a8 46
IonSystems 12:814a8fdbb6f7 47 if(mode == 0){
IonSystems 11:06f6e82b40a8 48 printLCD("Dispense Mode");
IonSystems 10:8c0696b99692 49 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 50 log("Red Button pressed");
IonSystems 10:8c0696b99692 51 stateMachine = DISPENSE_RED;
IonSystems 10:8c0696b99692 52 processState(stateMachine);
IonSystems 10:8c0696b99692 53 }else if(par_port->read_bit(9)){
IonSystems 10:8c0696b99692 54 log("Green Button pressed");
IonSystems 10:8c0696b99692 55 stateMachine = DISPENSE_GREEN;
IonSystems 10:8c0696b99692 56 processState(stateMachine);
IonSystems 10:8c0696b99692 57 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 58 log("Blue Button pressed");
IonSystems 10:8c0696b99692 59 stateMachine = DISPENSE_BLUE;
IonSystems 10:8c0696b99692 60 processState(stateMachine);
IonSystems 10:8c0696b99692 61 }
IonSystems 12:814a8fdbb6f7 62 }else if(mode == 1){
IonSystems 11:06f6e82b40a8 63 printLCD("Sort Mode");
IonSystems 10:8c0696b99692 64 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 65 log("Red Button pressed");
IonSystems 10:8c0696b99692 66 stateMachine = SORT_RED;
IonSystems 10:8c0696b99692 67 processState(stateMachine);
IonSystems 10:8c0696b99692 68 }else if(par_port->read_bit(9)){
IonSystems 10:8c0696b99692 69 log("Green Button pressed");
IonSystems 10:8c0696b99692 70 stateMachine = SORT_GREEN;
IonSystems 10:8c0696b99692 71 processState(stateMachine);
IonSystems 10:8c0696b99692 72 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 73 log("Blue Button pressed");
IonSystems 10:8c0696b99692 74 stateMachine = SORT_BLUE;
IonSystems 10:8c0696b99692 75 processState(stateMachine);
IonSystems 10:8c0696b99692 76 }
IonSystems 11:06f6e82b40a8 77
IonSystems 12:814a8fdbb6f7 78 }else if(mode == 2){
IonSystems 11:06f6e82b40a8 79 printLCD("Bin/Recycle Mode");
IonSystems 11:06f6e82b40a8 80 if(par_port->read_bit(8)){
IonSystems 11:06f6e82b40a8 81 log("Bin button pressed");
IonSystems 11:06f6e82b40a8 82 stateMachine = SORT_BIN;
IonSystems 11:06f6e82b40a8 83 processState(stateMachine);
IonSystems 11:06f6e82b40a8 84 }else if(par_port->read_bit(9)){
IonSystems 11:06f6e82b40a8 85 log("Recycle Button");
IonSystems 11:06f6e82b40a8 86 stateMachine = SORT_RECYCLE;
IonSystems 11:06f6e82b40a8 87 processState(stateMachine);
IonSystems 11:06f6e82b40a8 88 }
IonSystems 12:814a8fdbb6f7 89 }else if(mode == 3){
IonSystems 11:06f6e82b40a8 90 if(colourSensor){
IonSystems 11:06f6e82b40a8 91 Colour colour = readColourSensor();
IonSystems 11:06f6e82b40a8 92 if(colour != BIN) sort(colour);
IonSystems 11:06f6e82b40a8 93 }
IonSystems 12:814a8fdbb6f7 94 }else if(mode == 4){
IonSystems 12:814a8fdbb6f7 95 if(cardReader && cardDetect){
IonSystems 12:814a8fdbb6f7 96 cardAcquisition();
IonSystems 12:814a8fdbb6f7 97
IonSystems 12:814a8fdbb6f7 98 }
IonSystems 12:814a8fdbb6f7 99 }else if(mode == 5){
IonSystems 12:814a8fdbb6f7 100 stringstream ss;
IonSystems 12:814a8fdbb6f7 101 ss << "Stored Values " << "R:" << redAmount << "G:" << greenAmount << "B:" << blueAmount;
IonSystems 12:814a8fdbb6f7 102 string tmp = ss.str();
IonSystems 12:814a8fdbb6f7 103 printLCD(tmp.c_str());
IonSystems 12:814a8fdbb6f7 104 wait(0.1);
IonSystems 12:814a8fdbb6f7 105 if(par_port->read_bit(8)){
IonSystems 12:814a8fdbb6f7 106 log("Dispense all button pressed");
IonSystems 12:814a8fdbb6f7 107 stateMachine = DISPENSE_ALL;
IonSystems 12:814a8fdbb6f7 108 processState(stateMachine);
IonSystems 12:814a8fdbb6f7 109 }else if(par_port->read_bit(9)){
IonSystems 12:814a8fdbb6f7 110 log("Clear stored numbers button pressed");
IonSystems 12:814a8fdbb6f7 111 writeFile(0,0,0);
IonSystems 12:814a8fdbb6f7 112 redAmount = 0;greenAmount = 0;blueAmount = 0;
IonSystems 12:814a8fdbb6f7 113 printLCD("Cleared values");
IonSystems 12:814a8fdbb6f7 114
IonSystems 12:814a8fdbb6f7 115 }else if(par_port->read_bit(10)){
IonSystems 12:814a8fdbb6f7 116 log("set all stored values to 10");
IonSystems 12:814a8fdbb6f7 117 writeFile(10,10,10);
IonSystems 12:814a8fdbb6f7 118 redAmount = 10;greenAmount = 10;blueAmount = 10;
IonSystems 12:814a8fdbb6f7 119 printLCD("setv val;ues to 10");
IonSystems 12:814a8fdbb6f7 120
IonSystems 12:814a8fdbb6f7 121 }
IonSystems 12:814a8fdbb6f7 122 }
IonSystems 9:8d78eb55ad5e 123 }
IonSystems 12:814a8fdbb6f7 124
IonSystems 12:814a8fdbb6f7 125
IonSystems 6:e64796f1f384 126
IonSystems 6:e64796f1f384 127 int main() {
IonSystems 12:814a8fdbb6f7 128
IonSystems 7:6ba00694f9cd 129 stateMachine = INITIALISING;
IonSystems 8:b7771391adc9 130 processState(stateMachine);
IonSystems 12:814a8fdbb6f7 131 readChipNumbers();
IonSystems 12:814a8fdbb6f7 132 printStoredChipValues();
IonSystems 12:814a8fdbb6f7 133 displayOperationMode();
IonSystems 8:b7771391adc9 134 while(true){
IonSystems 10:8c0696b99692 135 if(serialComms){
IonSystems 10:8c0696b99692 136 checkSerial();
IonSystems 12:814a8fdbb6f7 137 }if(testFunctions) checkSortDispenseButtons();
IonSystems 12:814a8fdbb6f7 138
IonSystems 11:06f6e82b40a8 139 wait(0.05);
IonSystems 12:814a8fdbb6f7 140
IonSystems 8:b7771391adc9 141 }
IonSystems 10:8c0696b99692 142 /*char c;
IonSystems 10:8c0696b99692 143 if(c = readCharacter()){
IonSystems 10:8c0696b99692 144 processMessage(c);
IonSystems 10:8c0696b99692 145 }*/
IonSystems 11:06f6e82b40a8 146
IonSystems 11:06f6e82b40a8 147
IonSystems 10:8c0696b99692 148 }
IonSystems 9:8d78eb55ad5e 149
IonSystems 9:8d78eb55ad5e 150
IonSystems 9:8d78eb55ad5e 151
IonSystems 8:b7771391adc9 152
IonSystems 8:b7771391adc9 153
IonSystems 8:b7771391adc9 154
IonSystems 8:b7771391adc9 155
IonSystems 8:b7771391adc9 156
IonSystems 8:b7771391adc9 157
IonSystems 8:b7771391adc9 158 //printStoredChipValues();
IonSystems 6:e64796f1f384 159 /*
IonSystems 0:8d54ffcf256e 160 while(1){
IonSystems 3:97668a4cd69d 161 if(par_port->read_bit(11)) resetForNextCustomer();
IonSystems 7:6ba00694f9cd 162
IonSystems 3:97668a4cd69d 163 if(cardDetect & !cardDataAcquired) cardAcquisition();
IonSystems 3:97668a4cd69d 164 setLEDs();
IonSystems 3:97668a4cd69d 165 readButtons();
IonSystems 3:97668a4cd69d 166
IonSystems 4:f3be545b3826 167 if(chipDetected & !colourDataAcquired){
IonSystems 4:f3be545b3826 168 Colour colour = readColourSensor();
IonSystems 4:f3be545b3826 169 sendColourSignal(colour);
IonSystems 4:f3be545b3826 170 }
IonSystems 4:f3be545b3826 171
IonSystems 5:644bca33c1ca 172 writeFile(redQueue, greenQueue, blueQueue);
IonSystems 4:f3be545b3826 173 readFile();
IonSystems 4:f3be545b3826 174 wait(2);
IonSystems 4:f3be545b3826 175
IonSystems 0:8d54ffcf256e 176 }
IonSystems 6:e64796f1f384 177 */
IonSystems 6:e64796f1f384 178
IonSystems 8:b7771391adc9 179 /* setLEDcolour(255,0,0);
IonSystems 6:e64796f1f384 180 wait(0.1);
IonSystems 6:e64796f1f384 181 setLEDcolour(0,255,0);
IonSystems 6:e64796f1f384 182 wait(0.1);
IonSystems 6:e64796f1f384 183 setLEDcolour(0,0,255);
IonSystems 6:e64796f1f384 184 wait(0.1);
IonSystems 6:e64796f1f384 185
IonSystems 8:b7771391adc9 186 displayOperationMode(); */
IonSystems 3:97668a4cd69d 187
IonSystems 10:8c0696b99692 188
IonSystems 10:8c0696b99692 189