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:
Thu Nov 13 11:59:39 2014 +0000
Revision:
11:06f6e82b40a8
Parent:
10:8c0696b99692
Child:
12:814a8fdbb6f7
Changed colour values for blue bottom plate

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 11:06f6e82b40a8 16
IonSystems 11:06f6e82b40a8 17
IonSystems 7:6ba00694f9cd 18 StateMachine stateMachine;
IonSystems 7:6ba00694f9cd 19
IonSystems 6:e64796f1f384 20 //Boolean values to easily enable and disable certain features for individual testing
IonSystems 6:e64796f1f384 21 bool colourSensor = true;
IonSystems 6:e64796f1f384 22 bool cardReader = true;
IonSystems 6:e64796f1f384 23 bool sorter = true;
IonSystems 6:e64796f1f384 24 bool dispensor = true;
IonSystems 10:8c0696b99692 25 bool testFunctions = true;
IonSystems 10:8c0696b99692 26 bool serialComms = true;
IonSystems 6:e64796f1f384 27
IonSystems 6:e64796f1f384 28 bool colourDataAcquired = false;
IonSystems 6:e64796f1f384 29 bool chipDetected = false;
IonSystems 6:e64796f1f384 30 bool operationMode = true; //the MBED starts in operation mode.
IonSystems 3:97668a4cd69d 31
IonSystems 11:06f6e82b40a8 32 int sortDispenseRecycleMode = 0;
IonSystems 10:8c0696b99692 33
IonSystems 10:8c0696b99692 34
IonSystems 10:8c0696b99692 35
IonSystems 10:8c0696b99692 36
IonSystems 10:8c0696b99692 37 void checkSortDispenseButtons(){
IonSystems 11:06f6e82b40a8 38
IonSystems 11:06f6e82b40a8 39 if(par_port->read_bit(11)){
IonSystems 11:06f6e82b40a8 40 sortDispenseRecycleMode++;
IonSystems 11:06f6e82b40a8 41 if(sortDispenseRecycleMode >= 4) sortDispenseRecycleMode = 0;
IonSystems 11:06f6e82b40a8 42 }
IonSystems 11:06f6e82b40a8 43
IonSystems 11:06f6e82b40a8 44
IonSystems 11:06f6e82b40a8 45 if(sortDispenseRecycleMode == 0){
IonSystems 11:06f6e82b40a8 46 printLCD("Dispense Mode");
IonSystems 10:8c0696b99692 47 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 48 log("Red Button pressed");
IonSystems 10:8c0696b99692 49 stateMachine = DISPENSE_RED;
IonSystems 10:8c0696b99692 50 processState(stateMachine);
IonSystems 10:8c0696b99692 51 }else if(par_port->read_bit(9)){
IonSystems 10:8c0696b99692 52 log("Green Button pressed");
IonSystems 10:8c0696b99692 53 stateMachine = DISPENSE_GREEN;
IonSystems 10:8c0696b99692 54 processState(stateMachine);
IonSystems 10:8c0696b99692 55 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 56 log("Blue Button pressed");
IonSystems 10:8c0696b99692 57 stateMachine = DISPENSE_BLUE;
IonSystems 10:8c0696b99692 58 processState(stateMachine);
IonSystems 10:8c0696b99692 59 }
IonSystems 11:06f6e82b40a8 60 }else if(sortDispenseRecycleMode == 1){
IonSystems 11:06f6e82b40a8 61 printLCD("Sort Mode");
IonSystems 10:8c0696b99692 62 if(par_port->read_bit(8)){
IonSystems 10:8c0696b99692 63 log("Red Button pressed");
IonSystems 10:8c0696b99692 64 stateMachine = SORT_RED;
IonSystems 10:8c0696b99692 65 processState(stateMachine);
IonSystems 10:8c0696b99692 66 }else if(par_port->read_bit(9)){
IonSystems 10:8c0696b99692 67 log("Green Button pressed");
IonSystems 10:8c0696b99692 68 stateMachine = SORT_GREEN;
IonSystems 10:8c0696b99692 69 processState(stateMachine);
IonSystems 10:8c0696b99692 70 }else if(par_port->read_bit(10)){
IonSystems 10:8c0696b99692 71 log("Blue Button pressed");
IonSystems 10:8c0696b99692 72 stateMachine = SORT_BLUE;
IonSystems 10:8c0696b99692 73 processState(stateMachine);
IonSystems 10:8c0696b99692 74 }
IonSystems 11:06f6e82b40a8 75
IonSystems 11:06f6e82b40a8 76 }else if(sortDispenseRecycleMode == 2){
IonSystems 11:06f6e82b40a8 77 printLCD("Bin/Recycle Mode");
IonSystems 11:06f6e82b40a8 78 if(par_port->read_bit(8)){
IonSystems 11:06f6e82b40a8 79 log("Bin button pressed");
IonSystems 11:06f6e82b40a8 80 stateMachine = SORT_BIN;
IonSystems 11:06f6e82b40a8 81 processState(stateMachine);
IonSystems 11:06f6e82b40a8 82 }else if(par_port->read_bit(9)){
IonSystems 11:06f6e82b40a8 83 log("Recycle Button");
IonSystems 11:06f6e82b40a8 84 stateMachine = SORT_RECYCLE;
IonSystems 11:06f6e82b40a8 85 processState(stateMachine);
IonSystems 11:06f6e82b40a8 86 }
IonSystems 11:06f6e82b40a8 87 }else if(sortDispenseRecycleMode == 3){
IonSystems 11:06f6e82b40a8 88 if(colourSensor){
IonSystems 11:06f6e82b40a8 89 Colour colour = readColourSensor();
IonSystems 11:06f6e82b40a8 90 if(colour != BIN) sort(colour);
IonSystems 11:06f6e82b40a8 91 }
IonSystems 9:8d78eb55ad5e 92 }
IonSystems 8:b7771391adc9 93 }
IonSystems 6:e64796f1f384 94
IonSystems 6:e64796f1f384 95 int main() {
IonSystems 7:6ba00694f9cd 96 stateMachine = INITIALISING;
IonSystems 8:b7771391adc9 97 processState(stateMachine);
IonSystems 7:6ba00694f9cd 98 writeFile(2,6,22);
IonSystems 8:b7771391adc9 99 stateMachine = READING_RGB_VALUES;
IonSystems 8:b7771391adc9 100 processState(stateMachine);
IonSystems 8:b7771391adc9 101
IonSystems 8:b7771391adc9 102 while(true){
IonSystems 10:8c0696b99692 103 if(testFunctions) checkSortDispenseButtons();
IonSystems 10:8c0696b99692 104
IonSystems 10:8c0696b99692 105
IonSystems 10:8c0696b99692 106 if(serialComms){
IonSystems 10:8c0696b99692 107 checkSerial();
IonSystems 10:8c0696b99692 108 }
IonSystems 11:06f6e82b40a8 109 wait(0.05);
IonSystems 8:b7771391adc9 110 }
IonSystems 10:8c0696b99692 111 /*char c;
IonSystems 10:8c0696b99692 112 if(c = readCharacter()){
IonSystems 10:8c0696b99692 113 processMessage(c);
IonSystems 10:8c0696b99692 114 }*/
IonSystems 11:06f6e82b40a8 115
IonSystems 11:06f6e82b40a8 116
IonSystems 10:8c0696b99692 117 }
IonSystems 9:8d78eb55ad5e 118
IonSystems 9:8d78eb55ad5e 119
IonSystems 9:8d78eb55ad5e 120
IonSystems 8:b7771391adc9 121
IonSystems 8:b7771391adc9 122
IonSystems 8:b7771391adc9 123
IonSystems 8:b7771391adc9 124
IonSystems 8:b7771391adc9 125
IonSystems 8:b7771391adc9 126
IonSystems 8:b7771391adc9 127 //printStoredChipValues();
IonSystems 6:e64796f1f384 128 /*
IonSystems 0:8d54ffcf256e 129 while(1){
IonSystems 3:97668a4cd69d 130 if(par_port->read_bit(11)) resetForNextCustomer();
IonSystems 7:6ba00694f9cd 131
IonSystems 3:97668a4cd69d 132 if(cardDetect & !cardDataAcquired) cardAcquisition();
IonSystems 3:97668a4cd69d 133 setLEDs();
IonSystems 3:97668a4cd69d 134 readButtons();
IonSystems 3:97668a4cd69d 135
IonSystems 4:f3be545b3826 136 if(chipDetected & !colourDataAcquired){
IonSystems 4:f3be545b3826 137 Colour colour = readColourSensor();
IonSystems 4:f3be545b3826 138 sendColourSignal(colour);
IonSystems 4:f3be545b3826 139 }
IonSystems 4:f3be545b3826 140
IonSystems 5:644bca33c1ca 141 writeFile(redQueue, greenQueue, blueQueue);
IonSystems 4:f3be545b3826 142 readFile();
IonSystems 4:f3be545b3826 143 wait(2);
IonSystems 4:f3be545b3826 144
IonSystems 0:8d54ffcf256e 145 }
IonSystems 6:e64796f1f384 146 */
IonSystems 6:e64796f1f384 147
IonSystems 8:b7771391adc9 148 /* setLEDcolour(255,0,0);
IonSystems 6:e64796f1f384 149 wait(0.1);
IonSystems 6:e64796f1f384 150 setLEDcolour(0,255,0);
IonSystems 6:e64796f1f384 151 wait(0.1);
IonSystems 6:e64796f1f384 152 setLEDcolour(0,0,255);
IonSystems 6:e64796f1f384 153 wait(0.1);
IonSystems 6:e64796f1f384 154
IonSystems 8:b7771391adc9 155 displayOperationMode(); */
IonSystems 3:97668a4cd69d 156
IonSystems 10:8c0696b99692 157
IonSystems 10:8c0696b99692 158