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:
Fri Nov 21 22:14:21 2014 +0000
Revision:
15:0c5f20e15b6a
Parent:
14:31ba3e56c788
Child:
16:498359d078dc
card object created and database object created for testing language emun created

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 15:0c5f20e15b6a 3 #include "Language.h"
IonSystems 15:0c5f20e15b6a 4 DigitalIn languageButton(p30);
IonSystems 15:0c5f20e15b6a 5 Language currentLanguage = ENGLISH;
IonSystems 6:e64796f1f384 6 #include <sstream>
IonSystems 12:814a8fdbb6f7 7 #include <string>
IonSystems 15:0c5f20e15b6a 8
IonSystems 6:e64796f1f384 9 #include "lcdCommands.h"
IonSystems 6:e64796f1f384 10 #include "mbedStorage.h"
IonSystems 6:e64796f1f384 11 #include "rgbLED.h"
IonSystems 6:e64796f1f384 12 #include "mbedLCD.h"
IonSystems 7:6ba00694f9cd 13 #include "stateMachine.h"
IonSystems 8:b7771391adc9 14 #include "FPGAcomms.h"
IonSystems 10:8c0696b99692 15 #ifndef serialComm
IonSystems 10:8c0696b99692 16 #define serialComm
IonSystems 15:0c5f20e15b6a 17
IonSystems 10:8c0696b99692 18 #include "serialCommunication.h"
IonSystems 10:8c0696b99692 19 #endif
IonSystems 10:8c0696b99692 20 #include "testFunctions.h"
IonSystems 5:644bca33c1ca 21
IonSystems 0:8d54ffcf256e 22
IonSystems 11:06f6e82b40a8 23
IonSystems 11:06f6e82b40a8 24
IonSystems 7:6ba00694f9cd 25 StateMachine stateMachine;
IonSystems 7:6ba00694f9cd 26
IonSystems 6:e64796f1f384 27 //Boolean values to easily enable and disable certain features for individual testing
IonSystems 6:e64796f1f384 28 bool colourSensor = true;
IonSystems 6:e64796f1f384 29 bool cardReader = true;
IonSystems 6:e64796f1f384 30 bool sorter = true;
IonSystems 6:e64796f1f384 31 bool dispensor = true;
IonSystems 10:8c0696b99692 32 bool testFunctions = true;
IonSystems 10:8c0696b99692 33 bool serialComms = true;
IonSystems 6:e64796f1f384 34
IonSystems 6:e64796f1f384 35 bool colourDataAcquired = false;
IonSystems 6:e64796f1f384 36 bool chipDetected = false;
IonSystems 12:814a8fdbb6f7 37
IonSystems 3:97668a4cd69d 38
IonSystems 15:0c5f20e15b6a 39 int mode = 4;
IonSystems 13:0661d658d9d1 40 int maintenanceModePointer = 0;
IonSystems 14:31ba3e56c788 41 Colour lastColour = NONE;
IonSystems 10:8c0696b99692 42
IonSystems 10:8c0696b99692 43 void checkSortDispenseButtons(){
IonSystems 11:06f6e82b40a8 44
IonSystems 11:06f6e82b40a8 45 if(par_port->read_bit(11)){
IonSystems 12:814a8fdbb6f7 46 mode++;
IonSystems 13:0661d658d9d1 47 if(mode >= 7) mode = 0;
IonSystems 11:06f6e82b40a8 48 }
IonSystems 11:06f6e82b40a8 49
IonSystems 11:06f6e82b40a8 50
IonSystems 13:0661d658d9d1 51 if(mode == 0){ //Dispense Mode
IonSystems 11:06f6e82b40a8 52 printLCD("Dispense Mode");
IonSystems 10:8c0696b99692 53 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 54 log("Red Button pressed");
IonSystems 10:8c0696b99692 55 stateMachine = DISPENSE_RED;
IonSystems 10:8c0696b99692 56 processState(stateMachine);
IonSystems 10:8c0696b99692 57 }else if(par_port->read_bit(9)){
IonSystems 10:8c0696b99692 58 log("Green Button pressed");
IonSystems 10:8c0696b99692 59 stateMachine = DISPENSE_GREEN;
IonSystems 10:8c0696b99692 60 processState(stateMachine);
IonSystems 10:8c0696b99692 61 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 62 log("Blue Button pressed");
IonSystems 10:8c0696b99692 63 stateMachine = DISPENSE_BLUE;
IonSystems 10:8c0696b99692 64 processState(stateMachine);
IonSystems 10:8c0696b99692 65 }
IonSystems 13:0661d658d9d1 66 }else if(mode == 1){ //Sort Mode
IonSystems 11:06f6e82b40a8 67 printLCD("Sort Mode");
IonSystems 10:8c0696b99692 68 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 69 log("Red Button pressed");
IonSystems 10:8c0696b99692 70 stateMachine = SORT_RED;
IonSystems 10:8c0696b99692 71 processState(stateMachine);
IonSystems 10:8c0696b99692 72 }else if(par_port->read_bit(9)){
IonSystems 13:0661d658d9d1 73 log("Green Button pressed");
IonSystems 10:8c0696b99692 74 stateMachine = SORT_GREEN;
IonSystems 10:8c0696b99692 75 processState(stateMachine);
IonSystems 10:8c0696b99692 76 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 77 log("Blue Button pressed");
IonSystems 10:8c0696b99692 78 stateMachine = SORT_BLUE;
IonSystems 10:8c0696b99692 79 processState(stateMachine);
IonSystems 10:8c0696b99692 80 }
IonSystems 11:06f6e82b40a8 81
IonSystems 13:0661d658d9d1 82 }else if(mode == 2){ //Bin/Recycle Mode
IonSystems 11:06f6e82b40a8 83 printLCD("Bin/Recycle Mode");
IonSystems 11:06f6e82b40a8 84 if(par_port->read_bit(8)){
IonSystems 11:06f6e82b40a8 85 log("Bin button pressed");
IonSystems 11:06f6e82b40a8 86 stateMachine = SORT_BIN;
IonSystems 11:06f6e82b40a8 87 processState(stateMachine);
IonSystems 11:06f6e82b40a8 88 }else if(par_port->read_bit(9)){
IonSystems 11:06f6e82b40a8 89 log("Recycle Button");
IonSystems 11:06f6e82b40a8 90 stateMachine = SORT_RECYCLE;
IonSystems 11:06f6e82b40a8 91 processState(stateMachine);
IonSystems 11:06f6e82b40a8 92 }
IonSystems 14:31ba3e56c788 93 }else if(mode == 3){
IonSystems 14:31ba3e56c788 94 printLCD("Colour Sensor Mode"); //Colour Sensing Mode
IonSystems 11:06f6e82b40a8 95 if(colourSensor){
IonSystems 11:06f6e82b40a8 96 Colour colour = readColourSensor();
IonSystems 15:0c5f20e15b6a 97
IonSystems 15:0c5f20e15b6a 98 /* Tries to prevent a colour mis-read. When a chip is read as BIN or NONE,
IonSystems 15:0c5f20e15b6a 99 the chip may be falling down the tube as the reading was taken. The chip may
IonSystems 15:0c5f20e15b6a 100 also be out of position on the slider. Ignoring the next reading is trying to
IonSystems 15:0c5f20e15b6a 101 prevent a mis-read being valid.
IonSystems 15:0c5f20e15b6a 102 */
IonSystems 15:0c5f20e15b6a 103 if(lastColour == NONE || lastColour == BIN){
IonSystems 14:31ba3e56c788 104 return;
IonSystems 14:31ba3e56c788 105 }
IonSystems 15:0c5f20e15b6a 106 lastColour = colour;
IonSystems 14:31ba3e56c788 107 if(sorter) sort(colour);
IonSystems 14:31ba3e56c788 108 //Put (sorter && colour != BIN) in if statement.
IonSystems 11:06f6e82b40a8 109 }
IonSystems 14:31ba3e56c788 110 //if
IonSystems 13:0661d658d9d1 111 }else if(mode == 4){ //Card Reader Mode
IonSystems 12:814a8fdbb6f7 112 if(cardReader && cardDetect){
IonSystems 12:814a8fdbb6f7 113 cardAcquisition();
IonSystems 12:814a8fdbb6f7 114
IonSystems 12:814a8fdbb6f7 115 }
IonSystems 13:0661d658d9d1 116 }else if(mode == 5){ //Storage Mode
IonSystems 12:814a8fdbb6f7 117 stringstream ss;
IonSystems 12:814a8fdbb6f7 118 ss << "Stored Values " << "R:" << redAmount << "G:" << greenAmount << "B:" << blueAmount;
IonSystems 12:814a8fdbb6f7 119 string tmp = ss.str();
IonSystems 12:814a8fdbb6f7 120 printLCD(tmp.c_str());
IonSystems 12:814a8fdbb6f7 121 wait(0.1);
IonSystems 12:814a8fdbb6f7 122 if(par_port->read_bit(8)){
IonSystems 12:814a8fdbb6f7 123 log("Dispense all button pressed");
IonSystems 12:814a8fdbb6f7 124 stateMachine = DISPENSE_ALL;
IonSystems 12:814a8fdbb6f7 125 processState(stateMachine);
IonSystems 12:814a8fdbb6f7 126 }else if(par_port->read_bit(9)){
IonSystems 12:814a8fdbb6f7 127 log("Clear stored numbers button pressed");
IonSystems 12:814a8fdbb6f7 128 writeFile(0,0,0);
IonSystems 12:814a8fdbb6f7 129 redAmount = 0;greenAmount = 0;blueAmount = 0;
IonSystems 12:814a8fdbb6f7 130 printLCD("Cleared values");
IonSystems 12:814a8fdbb6f7 131
IonSystems 12:814a8fdbb6f7 132 }else if(par_port->read_bit(10)){
IonSystems 12:814a8fdbb6f7 133 log("set all stored values to 10");
IonSystems 13:0661d658d9d1 134 writeFile(2,2,2);
IonSystems 13:0661d658d9d1 135 redAmount = 2;greenAmount = 2;blueAmount = 2;
IonSystems 13:0661d658d9d1 136 printLCD("set values to 2");
IonSystems 12:814a8fdbb6f7 137
IonSystems 12:814a8fdbb6f7 138 }
IonSystems 13:0661d658d9d1 139 }else if(mode == 6){ //Maintenance Mode
IonSystems 14:31ba3e56c788 140 printLCD("Maintenace Mode");
IonSystems 13:0661d658d9d1 141 if(par_port->read_bit(8)){ //Next maintenance function
IonSystems 13:0661d658d9d1 142 maintenanceModePointer++;
IonSystems 13:0661d658d9d1 143 if(maintenanceModePointer > 12) maintenanceModePointer = 0;
IonSystems 13:0661d658d9d1 144 }else if(par_port->read_bit(9)){ //Previous maintenance function
IonSystems 13:0661d658d9d1 145 maintenanceModePointer--;
IonSystems 13:0661d658d9d1 146 if(maintenanceModePointer < 0) maintenanceModePointer = 12;
IonSystems 13:0661d658d9d1 147 }else if(par_port->read_bit(10)){ //Process Instruction
IonSystems 13:0661d658d9d1 148 switch(maintenanceModePointer){
IonSystems 13:0661d658d9d1 149 case 0://RB_LEFT:
IonSystems 14:31ba3e56c788 150 printLCD("Moving Red/Blue Slider left.");
IonSystems 13:0661d658d9d1 151 maintain(RB_LEFT);
IonSystems 13:0661d658d9d1 152 break;
IonSystems 13:0661d658d9d1 153
IonSystems 13:0661d658d9d1 154 case 1://RB_CENTRE:
IonSystems 14:31ba3e56c788 155 printLCD("Centering Red/Blue Slider.");
IonSystems 13:0661d658d9d1 156 maintain(RB_CENTRE);
IonSystems 13:0661d658d9d1 157 break;
IonSystems 13:0661d658d9d1 158
IonSystems 13:0661d658d9d1 159 case 2://RB_RIGHT:
IonSystems 14:31ba3e56c788 160 printLCD("Moving Red/Blue Slider right.");
IonSystems 13:0661d658d9d1 161 maintain(RB_RIGHT);
IonSystems 13:0661d658d9d1 162 break;
IonSystems 13:0661d658d9d1 163
IonSystems 13:0661d658d9d1 164 case 3://GO_UP:
IonSystems 14:31ba3e56c788 165 printLCD("Moving Green Slider up.");
IonSystems 13:0661d658d9d1 166 maintain(GO_UP);
IonSystems 13:0661d658d9d1 167 break;
IonSystems 13:0661d658d9d1 168
IonSystems 13:0661d658d9d1 169 case 4://GO_CENTRE:
IonSystems 14:31ba3e56c788 170 printLCD("Centering Green Slider.");
IonSystems 13:0661d658d9d1 171 maintain(GO_CENTRE);
IonSystems 13:0661d658d9d1 172 break;
IonSystems 13:0661d658d9d1 173
IonSystems 13:0661d658d9d1 174 case 5://GO_DOWN:
IonSystems 14:31ba3e56c788 175 printLCD("Moving Green Slider down.");
IonSystems 13:0661d658d9d1 176 maintain(GO_DOWN);
IonSystems 13:0661d658d9d1 177 break;
IonSystems 13:0661d658d9d1 178
IonSystems 13:0661d658d9d1 179 case 6://BR_LEFT:
IonSystems 14:31ba3e56c788 180 printLCD("Moving Bin Slider left.");
IonSystems 13:0661d658d9d1 181 maintain(BR_LEFT);
IonSystems 13:0661d658d9d1 182 break;
IonSystems 13:0661d658d9d1 183
IonSystems 13:0661d658d9d1 184 case 7://BR_RIGHT:
IonSystems 14:31ba3e56c788 185 printLCD("Moving Bin Slider right.");
IonSystems 13:0661d658d9d1 186 maintain(BR_RIGHT);
IonSystems 13:0661d658d9d1 187 break;
IonSystems 13:0661d658d9d1 188
IonSystems 13:0661d658d9d1 189 case 8://R_PUSH:
IonSystems 14:31ba3e56c788 190 printLCD("Pushing red dispensor");
IonSystems 13:0661d658d9d1 191 maintain(R_PUSH);
IonSystems 13:0661d658d9d1 192 break;
IonSystems 13:0661d658d9d1 193
IonSystems 13:0661d658d9d1 194 case 9://R_HOME:
IonSystems 14:31ba3e56c788 195 printLCD("Homing red dispensor");
IonSystems 14:31ba3e56c788 196 maintain(R_HOME);
IonSystems 13:0661d658d9d1 197 break;
IonSystems 13:0661d658d9d1 198
IonSystems 13:0661d658d9d1 199 case 10://GB_LEFT:
IonSystems 14:31ba3e56c788 200 printLCD("Pushing green dispensor");
IonSystems 13:0661d658d9d1 201 maintain(GB_LEFT);
IonSystems 13:0661d658d9d1 202 break;
IonSystems 13:0661d658d9d1 203
IonSystems 13:0661d658d9d1 204 case 11://GB_CENTRE:
IonSystems 14:31ba3e56c788 205 printLCD("Centre green/blue dispensor");
IonSystems 13:0661d658d9d1 206 maintain(GB_CENTRE);
IonSystems 13:0661d658d9d1 207 break;
IonSystems 13:0661d658d9d1 208
IonSystems 13:0661d658d9d1 209 case 12://GB_RIGHT:
IonSystems 14:31ba3e56c788 210 printLCD("Pushing blue dispensor");
IonSystems 14:31ba3e56c788 211 maintain(GB_RIGHT );
IonSystems 13:0661d658d9d1 212 break;
IonSystems 13:0661d658d9d1 213
IonSystems 13:0661d658d9d1 214
IonSystems 13:0661d658d9d1 215
IonSystems 14:31ba3e56c788 216 } printLCD("Ready for next command");
IonSystems 14:31ba3e56c788 217 wait(1);
IonSystems 13:0661d658d9d1 218 }
IonSystems 12:814a8fdbb6f7 219 }
IonSystems 9:8d78eb55ad5e 220 }
IonSystems 12:814a8fdbb6f7 221
IonSystems 15:0c5f20e15b6a 222 void changeLanguage(){
IonSystems 15:0c5f20e15b6a 223 currentLanguage = nextLanguage(currentLanguage);
IonSystems 15:0c5f20e15b6a 224 //tell PC to change language
IonSystems 15:0c5f20e15b6a 225 sendLanguageCharacter(); //Tell PC to change language
IonSystems 15:0c5f20e15b6a 226 updateLCDLanguage();
IonSystems 15:0c5f20e15b6a 227 printLCD("setting language to english");
IonSystems 15:0c5f20e15b6a 228 wait(0.5);
IonSystems 15:0c5f20e15b6a 229 }
IonSystems 6:e64796f1f384 230
IonSystems 6:e64796f1f384 231 int main() {
IonSystems 12:814a8fdbb6f7 232
IonSystems 7:6ba00694f9cd 233 stateMachine = INITIALISING;
IonSystems 8:b7771391adc9 234 processState(stateMachine);
IonSystems 12:814a8fdbb6f7 235 readChipNumbers();
IonSystems 12:814a8fdbb6f7 236 printStoredChipValues();
IonSystems 14:31ba3e56c788 237 //displayOperationMode();
IonSystems 8:b7771391adc9 238 while(true){
IonSystems 10:8c0696b99692 239 if(serialComms){
IonSystems 10:8c0696b99692 240 checkSerial();
IonSystems 12:814a8fdbb6f7 241 }if(testFunctions) checkSortDispenseButtons();
IonSystems 15:0c5f20e15b6a 242 if(languageButton) changeLanguage();
IonSystems 15:0c5f20e15b6a 243
IonSystems 15:0c5f20e15b6a 244
IonSystems 15:0c5f20e15b6a 245
IonSystems 15:0c5f20e15b6a 246
IonSystems 11:06f6e82b40a8 247 wait(0.05);
IonSystems 12:814a8fdbb6f7 248
IonSystems 8:b7771391adc9 249 }
IonSystems 10:8c0696b99692 250 /*char c;
IonSystems 10:8c0696b99692 251 if(c = readCharacter()){
IonSystems 10:8c0696b99692 252 processMessage(c);
IonSystems 10:8c0696b99692 253 }*/
IonSystems 11:06f6e82b40a8 254
IonSystems 11:06f6e82b40a8 255
IonSystems 10:8c0696b99692 256 }
IonSystems 9:8d78eb55ad5e 257
IonSystems 9:8d78eb55ad5e 258
IonSystems 9:8d78eb55ad5e 259
IonSystems 8:b7771391adc9 260
IonSystems 8:b7771391adc9 261
IonSystems 8:b7771391adc9 262
IonSystems 8:b7771391adc9 263
IonSystems 8:b7771391adc9 264
IonSystems 8:b7771391adc9 265
IonSystems 8:b7771391adc9 266 //printStoredChipValues();
IonSystems 6:e64796f1f384 267 /*
IonSystems 0:8d54ffcf256e 268 while(1){
IonSystems 3:97668a4cd69d 269 if(par_port->read_bit(11)) resetForNextCustomer();
IonSystems 7:6ba00694f9cd 270
IonSystems 3:97668a4cd69d 271 if(cardDetect & !cardDataAcquired) cardAcquisition();
IonSystems 3:97668a4cd69d 272 setLEDs();
IonSystems 3:97668a4cd69d 273 readButtons();
IonSystems 3:97668a4cd69d 274
IonSystems 4:f3be545b3826 275 if(chipDetected & !colourDataAcquired){
IonSystems 4:f3be545b3826 276 Colour colour = readColourSensor();
IonSystems 4:f3be545b3826 277 sendColourSignal(colour);
IonSystems 4:f3be545b3826 278 }
IonSystems 4:f3be545b3826 279
IonSystems 5:644bca33c1ca 280 writeFile(redQueue, greenQueue, blueQueue);
IonSystems 4:f3be545b3826 281 readFile();
IonSystems 4:f3be545b3826 282 wait(2);
IonSystems 4:f3be545b3826 283
IonSystems 0:8d54ffcf256e 284 }
IonSystems 6:e64796f1f384 285 */
IonSystems 6:e64796f1f384 286
IonSystems 8:b7771391adc9 287 /* setLEDcolour(255,0,0);
IonSystems 6:e64796f1f384 288 wait(0.1);
IonSystems 6:e64796f1f384 289 setLEDcolour(0,255,0);
IonSystems 6:e64796f1f384 290 wait(0.1);
IonSystems 6:e64796f1f384 291 setLEDcolour(0,0,255);
IonSystems 6:e64796f1f384 292 wait(0.1);
IonSystems 6:e64796f1f384 293
IonSystems 8:b7771391adc9 294 displayOperationMode(); */
IonSystems 3:97668a4cd69d 295
IonSystems 10:8c0696b99692 296
IonSystems 10:8c0696b99692 297