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 Dec 05 09:53:04 2014 +0000
Revision:
28:bdf2bf56f97b
Parent:
26:23ee3ea4ac7c
Commened main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 6:e64796f1f384 1 #include "mbed.h"
IonSystems 11:06f6e82b40a8 2 #include "colourProcessing.h"
IonSystems 24:8868101d01d0 3 ////////////////////////////
IonSystems 24:8868101d01d0 4 // START OF I/O DEFINITIONS
IonSystems 24:8868101d01d0 5 ////////////////////////////
IonSystems 6:e64796f1f384 6 //Setup pins to FPGA
IonSystems 6:e64796f1f384 7 DigitalOut startSort(p5); //A positive edge tells the FPGA to start sorting.
IonSystems 24:8868101d01d0 8 DigitalIn sortComplete(p16); //FPGA sets to 1 once complete until another signal is recieved.
IonSystems 6:e64796f1f384 9 /*
IonSystems 24:8868101d01d0 10 The command codes for the three sort select bits(ColourBit1,ColourBit2,ColourBit3)
IonSystems 24:8868101d01d0 11 See datasheet for furter information.
IonSystems 6:e64796f1f384 12 000 Sort red chip
IonSystems 6:e64796f1f384 13 001 Sort green chip
IonSystems 6:e64796f1f384 14 010 Sort blue chip
IonSystems 6:e64796f1f384 15 011 Bin the chip
IonSystems 6:e64796f1f384 16 100 Recycle the chip
IonSystems 6:e64796f1f384 17 101 Nothing
IonSystems 6:e64796f1f384 18 110 Nothing
IonSystems 6:e64796f1f384 19 111 Nothing
IonSystems 6:e64796f1f384 20 */
IonSystems 6:e64796f1f384 21
IonSystems 6:e64796f1f384 22 DigitalOut colourBit1(p6); //The 3 bits below are select bits for the sorter.
IonSystems 6:e64796f1f384 23 DigitalOut colourBit2(p7);
IonSystems 6:e64796f1f384 24 DigitalOut colourBit3(p8);
IonSystems 24:8868101d01d0 25 DigitalOut startDispense(p18); //A positive edge tells the FPGA to start dispensing.
IonSystems 6:e64796f1f384 26 /*
IonSystems 6:e64796f1f384 27 00 Dispense red chip
IonSystems 6:e64796f1f384 28 01 Dispense green chip
IonSystems 6:e64796f1f384 29 10 Dispense blue chip
IonSystems 6:e64796f1f384 30 11 Nothing
IonSystems 6:e64796f1f384 31 */
IonSystems 6:e64796f1f384 32
IonSystems 24:8868101d01d0 33 DigitalOut dispenseBit1(p19); //The 2 bits below are select bits for the dispenser.
IonSystems 24:8868101d01d0 34 DigitalOut dispenseBit2(p20);
IonSystems 8:b7771391adc9 35
IonSystems 12:814a8fdbb6f7 36 DigitalIn dispenseComplete(p11); //FPGA sets to 1 once complete until another signal is recieved.
IonSystems 10:8c0696b99692 37 DigitalOut select(p15); //0 for control, 1 for maintenance.
IonSystems 10:8c0696b99692 38
IonSystems 24:8868101d01d0 39 ////////////////////////////
IonSystems 24:8868101d01d0 40 // END OF I/O DEFINITIONS
IonSystems 24:8868101d01d0 41 ////////////////////////////
IonSystems 12:814a8fdbb6f7 42
IonSystems 24:8868101d01d0 43 /* Set the select lines for when the FPGA is in maintenance mode.
IonSystems 24:8868101d01d0 44 * The same pins have different functions in operation mode and maintenance mode on the FPGA.
IonSystems 24:8868101d01d0 45 */
IonSystems 19:78d4b78fa736 46 void setMaintenanceSelect(bool bit6, bool bit5, bool bit4, bool bit3, bool bit2, bool bit1)
IonSystems 19:78d4b78fa736 47 {
IonSystems 12:814a8fdbb6f7 48 startSort = bit1;
IonSystems 12:814a8fdbb6f7 49 colourBit1 = bit2;
IonSystems 12:814a8fdbb6f7 50 colourBit2 = bit3;
IonSystems 12:814a8fdbb6f7 51 colourBit3 = bit4;
IonSystems 12:814a8fdbb6f7 52 startDispense = bit5;
IonSystems 12:814a8fdbb6f7 53 dispenseBit1 = bit6;
IonSystems 19:78d4b78fa736 54 }
IonSystems 19:78d4b78fa736 55
IonSystems 24:8868101d01d0 56 //Set the maintenance start bit.
IonSystems 19:78d4b78fa736 57 void setMaintenanceStart(bool value)
IonSystems 19:78d4b78fa736 58 {
IonSystems 12:814a8fdbb6f7 59 dispenseBit2 = value;
IonSystems 19:78d4b78fa736 60 }
IonSystems 24:8868101d01d0 61
IonSystems 24:8868101d01d0 62 //Wait for the FPGA to complete a maintenance operation and return a complete signal.
IonSystems 19:78d4b78fa736 63 void waitForMaintenanceComplete()
IonSystems 19:78d4b78fa736 64 {
IonSystems 19:78d4b78fa736 65 while(!sortComplete) {
IonSystems 23:f9e7e64784be 66
IonSystems 19:78d4b78fa736 67 }
IonSystems 23:f9e7e64784be 68
IonSystems 19:78d4b78fa736 69 }
IonSystems 19:78d4b78fa736 70
IonSystems 24:8868101d01d0 71 //Set the select lines for a dispense operation for when the FPGA is in operation mode.
IonSystems 19:78d4b78fa736 72 void setDispenseSelect(bool dBit1, bool dBit2)
IonSystems 19:78d4b78fa736 73 {
IonSystems 19:78d4b78fa736 74 dispenseBit1 = dBit1;
IonSystems 19:78d4b78fa736 75 dispenseBit2 = dBit2;
IonSystems 12:814a8fdbb6f7 76 }
IonSystems 19:78d4b78fa736 77
IonSystems 24:8868101d01d0 78 //Set the select lines for a sorting operation for when the FPGA is in operation mode.
IonSystems 19:78d4b78fa736 79 void setSortSelect(bool sBit1, bool sBit2, bool sBit3)
IonSystems 19:78d4b78fa736 80 {
IonSystems 19:78d4b78fa736 81 colourBit1 = sBit1;
IonSystems 19:78d4b78fa736 82 colourBit2 = sBit2;
IonSystems 19:78d4b78fa736 83 colourBit3 = sBit3;
IonSystems 19:78d4b78fa736 84 }
IonSystems 19:78d4b78fa736 85
IonSystems 24:8868101d01d0 86 /* maintain(StateMachine statemachine)
IonSystems 24:8868101d01d0 87 * Carries out a maintenance operation depending on the value of the StateMachine input parameter.
IonSystems 24:8868101d01d0 88 */
IonSystems 19:78d4b78fa736 89 void maintain(StateMachine maintainState)
IonSystems 19:78d4b78fa736 90 {
IonSystems 12:814a8fdbb6f7 91 select = 1; //setting FPGA to maintenance mode.
IonSystems 24:8868101d01d0 92
IonSystems 24:8868101d01d0 93 /* Reset select pins to ensure FPGA carries out one operation.
IonSystems 24:8868101d01d0 94 * The FPGA triggers whenever the select lines change.
IonSystems 24:8868101d01d0 95 * Setting all bits high ensure a 'do nothing' state on the FPGA,
IonSystems 24:8868101d01d0 96 * so it won't do anything.
IonSystems 24:8868101d01d0 97 */
IonSystems 19:78d4b78fa736 98 setMaintenanceSelect(true,true,true,true,true,true);
IonSystems 24:8868101d01d0 99 switch(maintainState) { //Set the maintenanc select values depending on value of maintainState.
IonSystems 12:814a8fdbb6f7 100 case RB_LEFT:
IonSystems 12:814a8fdbb6f7 101 setMaintenanceSelect(false,false,false,true,false,true);
IonSystems 19:78d4b78fa736 102 break;
IonSystems 12:814a8fdbb6f7 103 case RB_CENTRE:
IonSystems 12:814a8fdbb6f7 104 setMaintenanceSelect(false,false,false,true,true,false);
IonSystems 19:78d4b78fa736 105 break;
IonSystems 12:814a8fdbb6f7 106 case RB_RIGHT:
IonSystems 12:814a8fdbb6f7 107 setMaintenanceSelect(false,false,false,true,true,true);
IonSystems 19:78d4b78fa736 108 break;
IonSystems 12:814a8fdbb6f7 109 case GO_UP:
IonSystems 12:814a8fdbb6f7 110 setMaintenanceSelect(false,false,true,false,false,false);
IonSystems 19:78d4b78fa736 111 break;
IonSystems 12:814a8fdbb6f7 112 case GO_CENTRE:
IonSystems 12:814a8fdbb6f7 113 setMaintenanceSelect(false,false,true,false,false,true);
IonSystems 19:78d4b78fa736 114 break;
IonSystems 12:814a8fdbb6f7 115 case GO_DOWN:
IonSystems 12:814a8fdbb6f7 116 setMaintenanceSelect(false,false,true,false,true,false);
IonSystems 19:78d4b78fa736 117 break;
IonSystems 12:814a8fdbb6f7 118 case BR_LEFT:
IonSystems 12:814a8fdbb6f7 119 setMaintenanceSelect(false,false,true,false,true,true);
IonSystems 19:78d4b78fa736 120 break;
IonSystems 12:814a8fdbb6f7 121 case BR_RIGHT:
IonSystems 12:814a8fdbb6f7 122 setMaintenanceSelect(false,false,true,true,false,false);
IonSystems 19:78d4b78fa736 123 break;
IonSystems 12:814a8fdbb6f7 124 case R_PUSH:
IonSystems 12:814a8fdbb6f7 125 setMaintenanceSelect(false,false,true,true,false,true);
IonSystems 19:78d4b78fa736 126 break;
IonSystems 22:8f11d1c178ab 127 case R_HOME:
IonSystems 22:8f11d1c178ab 128 setMaintenanceSelect(false,false,true,true,true,false);
IonSystems 22:8f11d1c178ab 129 break;
IonSystems 22:8f11d1c178ab 130 case GB_LEFT:
IonSystems 22:8f11d1c178ab 131 setMaintenanceSelect(false,false,true,true,true,true);
IonSystems 22:8f11d1c178ab 132 break;
IonSystems 22:8f11d1c178ab 133 case GB_CENTRE:
IonSystems 22:8f11d1c178ab 134 setMaintenanceSelect(false,true,false,false,false,false);
IonSystems 22:8f11d1c178ab 135 break;
IonSystems 22:8f11d1c178ab 136 case GB_RIGHT:
IonSystems 22:8f11d1c178ab 137 setMaintenanceSelect(false,true,false,false,false,true);
IonSystems 22:8f11d1c178ab 138 break;
IonSystems 22:8f11d1c178ab 139 case maintenanceEND:
IonSystems 22:8f11d1c178ab 140 setMaintenanceSelect(false,true,false,false,true,false);
IonSystems 23:f9e7e64784be 141 break;
IonSystems 14:31ba3e56c788 142 default:
IonSystems 19:78d4b78fa736 143 break;
IonSystems 19:78d4b78fa736 144 }
IonSystems 24:8868101d01d0 145 setMaintenanceStart(true); //Tell the FPGA to start the maintenance operation
IonSystems 24:8868101d01d0 146 waitForMaintenanceComplete(); //Wait for the FPGA to complete the maintenance operation.
IonSystems 24:8868101d01d0 147 setMaintenanceStart(false); //Set the start bit low.
IonSystems 24:8868101d01d0 148 setMaintenanceSelect(true,false,true,true,true,false); //Set select bits back to 'do nothing' state.
IonSystems 19:78d4b78fa736 149 }
IonSystems 19:78d4b78fa736 150
IonSystems 24:8868101d01d0 151 //Wait for the FPGA to complete a dispense operation and send a complete signal.
IonSystems 19:78d4b78fa736 152 void waitForDispenseComplete()
IonSystems 19:78d4b78fa736 153 {
IonSystems 23:f9e7e64784be 154 while(!dispenseComplete) {
IonSystems 25:7f5d764d8e34 155 }
IonSystems 19:78d4b78fa736 156 }
IonSystems 19:78d4b78fa736 157
IonSystems 24:8868101d01d0 158 /* dispense(Colour colour)
IonSystems 24:8868101d01d0 159 * Carries out a dispense operation for the colour defined by 'colour' which is a Colour.
IonSystems 24:8868101d01d0 160 */
IonSystems 19:78d4b78fa736 161 void dispense(Colour colour)
IonSystems 19:78d4b78fa736 162 {
IonSystems 24:8868101d01d0 163 startDispense = false; //Set start dispense to false, it should be false already.
IonSystems 24:8868101d01d0 164 bool validDispense = false; //Set up a boolean to record whether the dispense is valid or not.
IonSystems 24:8868101d01d0 165 select = 0; //Set the FPGA to operation mode.
IonSystems 24:8868101d01d0 166 setDispenseSelect(true,true); //Set the dispense selcect bits to 'no nothing' state.
IonSystems 23:f9e7e64784be 167 // A dispense operation can only take place if there are chips
IonSystems 23:f9e7e64784be 168
IonSystems 24:8868101d01d0 169 switch(colour) { //Carry out a dispense operation for the colour defined by 'colour'.
IonSystems 19:78d4b78fa736 170 case RED:
IonSystems 24:8868101d01d0 171
IonSystems 24:8868101d01d0 172 if(redAmount > 0 || operationMode == false) { //Ensure dispense is valid
IonSystems 24:8868101d01d0 173 setDispenseSelect(false,false); //Set select lines for RED dispense
IonSystems 24:8868101d01d0 174 if(operationMode)redAmount--; //Decrement tube amount if in operation mode
IonSystems 24:8868101d01d0 175 validDispense = true;
IonSystems 19:78d4b78fa736 176 }
IonSystems 10:8c0696b99692 177 break;
IonSystems 19:78d4b78fa736 178 case GREEN:
IonSystems 24:8868101d01d0 179 if(greenAmount > 0 || operationMode == false) { //Ensure dispense is valid
IonSystems 24:8868101d01d0 180 setDispenseSelect(true,false); //Set select lines for GREEN dispense
IonSystems 24:8868101d01d0 181 if(operationMode)greenAmount--; //Decrement tube amount if in operation mode
IonSystems 19:78d4b78fa736 182 validDispense = true;
IonSystems 19:78d4b78fa736 183 }
IonSystems 10:8c0696b99692 184 break;
IonSystems 19:78d4b78fa736 185 case BLUE:
IonSystems 24:8868101d01d0 186 if(blueAmount > 0 || operationMode == false) { //Ensure dispense is valid
IonSystems 24:8868101d01d0 187 setDispenseSelect(false,true); //Set select lines for BLUE dispense
IonSystems 24:8868101d01d0 188 if(operationMode)blueAmount--; //Decrement tube amount if in operation mode
IonSystems 12:814a8fdbb6f7 189 validDispense = true;
IonSystems 19:78d4b78fa736 190 }
IonSystems 10:8c0696b99692 191 break;
IonSystems 19:78d4b78fa736 192 }
IonSystems 23:f9e7e64784be 193
IonSystems 24:8868101d01d0 194 if(operationMode)writeFile(redAmount,greenAmount,blueAmount,recycleAmount); //Store new tube values if in operation mode.
IonSystems 24:8868101d01d0 195 /* If this is a valid dispense (enough chips in storage tubes) then
IonSystems 24:8868101d01d0 196 * set the start bit, wait for complete signal, then reset start bit,
IonSystems 24:8868101d01d0 197 * and select lines.
IonSystems 24:8868101d01d0 198 */
IonSystems 24:8868101d01d0 199 if(validDispense || operationMode == false) {
IonSystems 10:8c0696b99692 200 startDispense = true; //set the startDispense line high.
IonSystems 24:8868101d01d0 201 waitForDispenseComplete();
IonSystems 10:8c0696b99692 202 startDispense = false;
IonSystems 19:78d4b78fa736 203 setDispenseSelect(true,true);
IonSystems 10:8c0696b99692 204 }
IonSystems 19:78d4b78fa736 205 }
IonSystems 24:8868101d01d0 206
IonSystems 25:7f5d764d8e34 207 /* dispenseOrder(int r, int g, int b)
IonSystems 25:7f5d764d8e34 208 * Dispenses a certain amount of each coloured chip,
IonSystems 25:7f5d764d8e34 209 * depending on the three input values (one input for each colour).
IonSystems 24:8868101d01d0 210 */
IonSystems 19:78d4b78fa736 211 void dispenseOrder(int r, int g, int b)
IonSystems 19:78d4b78fa736 212 {
IonSystems 24:8868101d01d0 213 for(int i = r; i > 0; i--) {
IonSystems 14:31ba3e56c788 214 dispense(RED);
IonSystems 24:8868101d01d0 215 wait(0.2);
IonSystems 24:8868101d01d0 216 Thread::wait(200);
IonSystems 19:78d4b78fa736 217 }
IonSystems 23:f9e7e64784be 218 for(int i = g; i > 0; i--) {
IonSystems 15:0c5f20e15b6a 219 dispense(GREEN);
IonSystems 19:78d4b78fa736 220 }
IonSystems 23:f9e7e64784be 221 for(int i = b; i > 0; i--) {
IonSystems 15:0c5f20e15b6a 222 dispense(BLUE);
IonSystems 17:6a0bb0ad5bb4 223 }
IonSystems 19:78d4b78fa736 224 }
IonSystems 25:7f5d764d8e34 225 //Wait for the FPGA to complete a sort operation and send a complete signal.
IonSystems 20:6de191ac7ff3 226 void waitForSortComplete()
IonSystems 20:6de191ac7ff3 227 {
IonSystems 23:f9e7e64784be 228 while(!sortComplete) {}
IonSystems 20:6de191ac7ff3 229 }
IonSystems 25:7f5d764d8e34 230 /* lift()
IonSystems 25:7f5d764d8e34 231 * Communicate with the FPGA to carry out a lift operation.
IonSystems 25:7f5d764d8e34 232 */
IonSystems 20:6de191ac7ff3 233 void lift()
IonSystems 20:6de191ac7ff3 234 {
IonSystems 20:6de191ac7ff3 235 select = 0; //Setting to operation mode just in case it has not been set.
IonSystems 25:7f5d764d8e34 236 setSortSelect(true,true,true); //Setting sort select to 'no nothing' state.
IonSystems 25:7f5d764d8e34 237 setSortSelect(true,false,true); //Setting sort select to 'lift' state.
IonSystems 25:7f5d764d8e34 238 startSort = true; //Tell the FPGA to start the lift operation
IonSystems 25:7f5d764d8e34 239 waitForSortComplete(); //Wait for the FPGA to complete the lift operation
IonSystems 25:7f5d764d8e34 240 startSort = false; //Turn off startSort
IonSystems 25:7f5d764d8e34 241 setSortSelect(true,true,true); //Return sort select to 'no nothing' state.
IonSystems 23:f9e7e64784be 242 }
IonSystems 20:6de191ac7ff3 243
IonSystems 20:6de191ac7ff3 244
IonSystems 25:7f5d764d8e34 245 /* recycle()
IonSystems 25:7f5d764d8e34 246 * Communicate with the FPGA to carry out a recycle operation.
IonSystems 25:7f5d764d8e34 247 */
IonSystems 19:78d4b78fa736 248 void recycle()
IonSystems 19:78d4b78fa736 249 {
IonSystems 24:8868101d01d0 250 if(redAmount >= tubeSize && greenAmount >= tubeSize && blueAmount >= tubeSize && operationMode){
IonSystems 24:8868101d01d0 251 return;
IonSystems 24:8868101d01d0 252 }
IonSystems 19:78d4b78fa736 253 select = 0; //Setting to operation mode just in case it has not been set.
IonSystems 25:7f5d764d8e34 254 setSortSelect(true,true,true); //Setting sort select to 'no nothing' state.
IonSystems 25:7f5d764d8e34 255 setSortSelect(false,false,true); //Setting sort select to 'recycle' state.
IonSystems 25:7f5d764d8e34 256 if(operationMode)recycleAmount++; //Increment the amount of chips in the lift, if we are in operation mode.
IonSystems 25:7f5d764d8e34 257 startSort = true; //Tell the FPGA to start the recycle operation.
IonSystems 25:7f5d764d8e34 258 waitForSortComplete(); //Wait for the FPGA to complete the recycle operation
IonSystems 26:23ee3ea4ac7c 259 startSort = false; //Turn off startSort.
IonSystems 25:7f5d764d8e34 260 setSortSelect(true,true,true); //Return sort select to 'no nothing' state.
IonSystems 25:7f5d764d8e34 261 if(recycleAmount >= 5) { //Check whether the lift is full.
IonSystems 26:23ee3ea4ac7c 262 Thread::wait(1000); //Carry out a lift operation if the recycle tube is full.
IonSystems 23:f9e7e64784be 263 lift();
IonSystems 24:8868101d01d0 264 Thread::wait(1000);
IonSystems 23:f9e7e64784be 265 recycleAmount = 0;
IonSystems 23:f9e7e64784be 266 }
IonSystems 19:78d4b78fa736 267 }
IonSystems 19:78d4b78fa736 268
IonSystems 19:78d4b78fa736 269
IonSystems 26:23ee3ea4ac7c 270 /* sort(Colour colour)
IonSystems 26:23ee3ea4ac7c 271 * Sort a token into a storage tube. The storage tube is selected using the Colour input 'colour'.
IonSystems 26:23ee3ea4ac7c 272 */
IonSystems 19:78d4b78fa736 273 void sort(Colour colour)
IonSystems 19:78d4b78fa736 274 {
IonSystems 26:23ee3ea4ac7c 275 if(colour == NONE) { //Return if no colour is given.
IonSystems 19:78d4b78fa736 276 return;
IonSystems 26:23ee3ea4ac7c 277 } else {
IonSystems 26:23ee3ea4ac7c 278 startSort = false; //just in case it is high for some reason.
IonSystems 26:23ee3ea4ac7c 279 select = 0; //Setting to operation mode just in case it has not been set.
IonSystems 26:23ee3ea4ac7c 280 setSortSelect(true,true,true); //Set sort select to 'no nothing' state.
IonSystems 19:78d4b78fa736 281 switch(colour) {
IonSystems 24:8868101d01d0 282 case RED:
IonSystems 26:23ee3ea4ac7c 283 if(redAmount >= tubeSize && operationMode) { //Recycle if red tube full
IonSystems 17:6a0bb0ad5bb4 284 recycle();
IonSystems 17:6a0bb0ad5bb4 285 return;
IonSystems 19:78d4b78fa736 286 }
IonSystems 26:23ee3ea4ac7c 287 setSortSelect(false,false,false); //Set sort select for red sort
IonSystems 24:8868101d01d0 288 if(operationMode) redAmount++;
IonSystems 19:78d4b78fa736 289 break;
IonSystems 10:8c0696b99692 290 case GREEN:
IonSystems 26:23ee3ea4ac7c 291 if(greenAmount >= tubeSize && operationMode) { //Recycle if green tube full
IonSystems 17:6a0bb0ad5bb4 292 recycle();
IonSystems 17:6a0bb0ad5bb4 293 return;
IonSystems 19:78d4b78fa736 294 }
IonSystems 26:23ee3ea4ac7c 295 setSortSelect(true,false,false); //Set sort select for green sort
IonSystems 24:8868101d01d0 296 if(operationMode) greenAmount++;
IonSystems 19:78d4b78fa736 297 break;
IonSystems 10:8c0696b99692 298 case BLUE:
IonSystems 26:23ee3ea4ac7c 299 if(blueAmount >= tubeSize && operationMode) { //Recycle if blue tube full
IonSystems 17:6a0bb0ad5bb4 300 recycle();
IonSystems 17:6a0bb0ad5bb4 301 return;
IonSystems 19:78d4b78fa736 302 }
IonSystems 26:23ee3ea4ac7c 303 setSortSelect(false,true,false); //Set sort select for blue sort
IonSystems 24:8868101d01d0 304 if(operationMode) blueAmount++;
IonSystems 19:78d4b78fa736 305 break;
IonSystems 11:06f6e82b40a8 306 case BIN:
IonSystems 26:23ee3ea4ac7c 307 setSortSelect(true,true,false); //Set sort select for bin
IonSystems 19:78d4b78fa736 308 break;
IonSystems 10:8c0696b99692 309 }
IonSystems 26:23ee3ea4ac7c 310 startSort = true; //Tell the FPGA to start the sort
IonSystems 26:23ee3ea4ac7c 311 waitForSortComplete(); //Wait for the FPGA to complete sort operation and send complete signal
IonSystems 26:23ee3ea4ac7c 312 startSort = false;
IonSystems 26:23ee3ea4ac7c 313 setSortSelect(true,true,true); //Return sort select to 'do nothing' state.
IonSystems 26:23ee3ea4ac7c 314 //Save tube values to file if in operation mode.
IonSystems 24:8868101d01d0 315 if(operationMode) writeFile(redAmount,greenAmount,blueAmount,recycleAmount);
IonSystems 19:78d4b78fa736 316 }
IonSystems 12:814a8fdbb6f7 317 }
IonSystems 12:814a8fdbb6f7 318
IonSystems 19:78d4b78fa736 319
IonSystems 26:23ee3ea4ac7c 320 /* dispenseAll()
IonSystems 26:23ee3ea4ac7c 321 * Dispense all the tokens in the three tubes, according to the stored values.
IonSystems 26:23ee3ea4ac7c 322 */
IonSystems 19:78d4b78fa736 323 void dispenseAll()
IonSystems 19:78d4b78fa736 324 {
IonSystems 23:f9e7e64784be 325 dispenseOrder(redAmount,greenAmount,blueAmount);
IonSystems 24:8868101d01d0 326 redAmount = 0; greenAmount = 0; blueAmount = 0;
IonSystems 23:f9e7e64784be 327 writeFile(redAmount,greenAmount,blueAmount,recycleAmount);
IonSystems 19:78d4b78fa736 328 }