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:
10:8c0696b99692
Parent:
9:8d78eb55ad5e
Child:
11:06f6e82b40a8
diff -r 8d78eb55ad5e -r 8c0696b99692 main.cpp
--- a/main.cpp	Mon Nov 10 19:01:43 2014 +0000
+++ b/main.cpp	Wed Nov 12 20:14:45 2014 +0000
@@ -6,59 +6,62 @@
 #include "mbedLCD.h"
 #include "stateMachine.h"
 #include "FPGAcomms.h"
+#ifndef serialComm
+#define serialComm
+#include "serialCommunication.h"
+#endif
+#include "testFunctions.h"
 
 
-Serial pc(USBTX, USBRX);
-
 StateMachine stateMachine;
 
-
 //Boolean values to easily enable and disable certain features for individual testing
 bool colourSensor   =   true;
 bool cardReader     =   true;
 bool sorter         =   true;
 bool dispensor      =   true;
+bool testFunctions  =   true;
+bool serialComms    =   true;
 
-bool cardDataAcquired   = false;
 bool colourDataAcquired = false;
 bool chipDetected       = false;
 bool operationMode      = true; //the MBED starts in operation mode.
 
-void processState(StateMachine stateMachine){
-   switch(stateMachine){    
-      case INITIALISING:
-        setupLCD();
-        printLCD("Welcome to the  Chipin Sorter");
-        wait(1);
-      break;
-      case READING_RGB_VALUES:
-        readChipNumbers();
-      break;
-      case DISPENSE_RED:
-        printLCD("DISPENSING A RED CHIP");
-        select = 0; //Setting to operation mode just in case it has not been set.
-        dispenseBit1 = true;
-        dispenseBit2 = true;
-        
-        dispenseBit2 = false;
-        dispenseBit1 = false;
-        wait(0.01);
-        startDispense = true; //set the startDispense line high.
-       
-        
-        //wait(1); //temporary delay
-        while(!complete){
-            wait(0.1);
-            printLCD("Waiting to complete");            
+
+
+
+
+void checkSortDispenseButtons(){
+        if(!par_port->read_bit(11)){
+            if(par_port->read_bit(8)){
+                log("Red Button pressed");
+                stateMachine = DISPENSE_RED;
+                processState(stateMachine);
+            }else if(par_port->read_bit(9)){
+                log("Green Button pressed");
+                stateMachine = DISPENSE_GREEN;
+                processState(stateMachine);
+            }else if(par_port->read_bit(10)){
+                log("Blue Button pressed");
+                stateMachine = DISPENSE_BLUE;
+                processState(stateMachine);
+            }
+        }else if(par_port->read_bit(11)){
+            if(par_port->read_bit(8)){
+                log("Red Button pressed");
+                stateMachine = SORT_RED;
+                processState(stateMachine);
+            }else if(par_port->read_bit(9)){
+                log("Green Button pressed");
+                stateMachine = SORT_GREEN;
+                processState(stateMachine);
+            }else if(par_port->read_bit(10)){
+                log("Blue Button pressed");
+                stateMachine = SORT_BLUE;
+                processState(stateMachine);
+            }
         }
-        dispenseBit1 = true;    //reset the dispense select to do nothing
-        dispenseBit2 = true;    //reset the dispense select to do nothing
-        //startDispense = false;
-        printLCD("RED DISPENSE COMPLETE");
-      
-      break;
     }
-}
       
 int main() { 
     stateMachine = INITIALISING;
@@ -68,11 +71,18 @@
     processState(stateMachine);
     
     while(true){
-        if(par_port->read_bit(9)){
-        stateMachine = DISPENSE_RED;
-        processState(stateMachine);
-        }
+        if(testFunctions) checkSortDispenseButtons();
+    
+        
+        if(serialComms){
+            checkSerial();
+        }  
     }
+        /*char c;
+        if(c = readCharacter()){
+            processMessage(c);
+        }*/
+}
        
         
     
@@ -112,4 +122,5 @@
     
     displayOperationMode();  */  
 
-    }
\ No newline at end of file
+    
+    
\ No newline at end of file