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

Revision:
14:31ba3e56c788
Parent:
13:0661d658d9d1
Child:
15:0c5f20e15b6a
--- a/main.cpp	Thu Nov 20 11:15:47 2014 +0000
+++ b/main.cpp	Thu Nov 20 22:02:54 2014 +0000
@@ -31,9 +31,9 @@
 bool chipDetected       = false;
 
 
-int mode = 0;
+int mode = 3;
 int maintenanceModePointer = 0;
-
+Colour lastColour = NONE;
 
 void checkSortDispenseButtons(){
         
@@ -85,11 +85,19 @@
                 stateMachine = SORT_RECYCLE;
                 processState(stateMachine);
             }
-        }else if(mode == 3){                                //Colour Sensing Mode
+        }else if(mode == 3){  
+        printLCD("Colour Sensor Mode");                              //Colour Sensing Mode
             if(colourSensor){
                 Colour colour = readColourSensor();
-                if(sorter) sort(colour);                 //Put (sorter && colour != BIN) in if statement.
+                lastColour = colour;   
+                if(lastColour == NONE || lastColour == BIN){
+                    return;
+                }
+                
+                if(sorter) sort(colour);  
+                            //Put (sorter && colour != BIN) in if statement.
             }
+            //if
         }else if(mode == 4){                                //Card Reader Mode
             if(cardReader && cardDetect){
                 cardAcquisition();
@@ -119,6 +127,7 @@
                 
             }
         }else if(mode == 6){                                //Maintenance Mode
+        printLCD("Maintenace Mode");
             if(par_port->read_bit(8)){                      //Next maintenance function
             maintenanceModePointer++;
             if(maintenanceModePointer > 12) maintenanceModePointer = 0;    
@@ -128,60 +137,74 @@
             }else if(par_port->read_bit(10)){               //Process Instruction
                 switch(maintenanceModePointer){
                     case 0://RB_LEFT:
+                        printLCD("Moving Red/Blue Slider left.");
                         maintain(RB_LEFT);
                     break;
                     
                     case 1://RB_CENTRE:
+                        printLCD("Centering Red/Blue Slider.");
                         maintain(RB_CENTRE);
                     break;
                     
                     case 2://RB_RIGHT:
+                        printLCD("Moving Red/Blue Slider right.");
                         maintain(RB_RIGHT);
                     break;
                     
                     case 3://GO_UP:
+                        printLCD("Moving Green Slider up.");
                         maintain(GO_UP);
                     break;
                     
                     case 4://GO_CENTRE:
+                        printLCD("Centering Green Slider.");
                         maintain(GO_CENTRE);
                     break;
                     
                     case 5://GO_DOWN:
+                        printLCD("Moving Green Slider down.");
                         maintain(GO_DOWN);
                     break;
                     
                     case 6://BR_LEFT:
+                        printLCD("Moving Bin Slider left.");
                         maintain(BR_LEFT);
                     break;
                     
                     case 7://BR_RIGHT:
+                        printLCD("Moving Bin Slider right.");
                         maintain(BR_RIGHT);
                     break;
                     
                     case 8://R_PUSH:
+                        printLCD("Pushing red dispensor");
                         maintain(R_PUSH);
                     break;
                     
                     case 9://R_HOME:
-                    maintain(R_HOME);
+                        printLCD("Homing red dispensor");
+                        maintain(R_HOME);
                     break;
                     
                     case 10://GB_LEFT:
+                        printLCD("Pushing green dispensor");
                         maintain(GB_LEFT);
                     break;
                     
                     case 11://GB_CENTRE:
+                        printLCD("Centre green/blue dispensor");
                         maintain(GB_CENTRE);
                     break;
                     
                     case 12://GB_RIGHT:
-                        maintain(GB_RIGHT);
+                        printLCD("Pushing blue dispensor");
+                        maintain(GB_RIGHT );
                     break;
                     
                     
                 
-            }  
+            }  printLCD("Ready for next command");
+                wait(1);
                 }
             }
         }
@@ -194,7 +217,7 @@
     processState(stateMachine);
     readChipNumbers();
     printStoredChipValues();
-    displayOperationMode();
+    //displayOperationMode();
     while(true){
         if(serialComms){
             checkSerial();