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:
12:814a8fdbb6f7
Parent:
11:06f6e82b40a8
Child:
13:0661d658d9d1
--- a/main.cpp	Thu Nov 13 11:59:39 2014 +0000
+++ b/main.cpp	Mon Nov 17 21:31:42 2014 +0000
@@ -1,5 +1,7 @@
+bool operationMode      = true; //the MBED starts in operation mode.
 #include "mbed.h"
 #include <sstream>
+#include <string>
 #include "lcdCommands.h"
 #include "mbedStorage.h"
 #include "rgbLED.h"
@@ -27,9 +29,9 @@
 
 bool colourDataAcquired = false;
 bool chipDetected       = false;
-bool operationMode      = true; //the MBED starts in operation mode.
+
 
-int sortDispenseRecycleMode = 0;
+int mode = 0;
 
 
 
@@ -37,12 +39,12 @@
 void checkSortDispenseButtons(){
         
         if(par_port->read_bit(11)){
-            sortDispenseRecycleMode++;
-            if(sortDispenseRecycleMode >= 4) sortDispenseRecycleMode = 0;
+            mode++;
+            if(mode >= 6) mode = 0;
         }
         
         
-        if(sortDispenseRecycleMode == 0){
+        if(mode == 0){
             printLCD("Dispense Mode");
             if(par_port->read_bit(8)){
                 log("Red Button pressed");
@@ -57,7 +59,7 @@
                 stateMachine = DISPENSE_BLUE;
                 processState(stateMachine);
             }
-        }else if(sortDispenseRecycleMode == 1){
+        }else if(mode == 1){
             printLCD("Sort Mode");
             if(par_port->read_bit(8)){
                 log("Red Button pressed");
@@ -73,7 +75,7 @@
                 processState(stateMachine);
             }
             
-        }else if(sortDispenseRecycleMode == 2){
+        }else if(mode == 2){
             printLCD("Bin/Recycle Mode");
             if(par_port->read_bit(8)){
                 log("Bin button pressed");
@@ -84,29 +86,58 @@
                 stateMachine = SORT_RECYCLE;
                 processState(stateMachine);
             }
-        }else if(sortDispenseRecycleMode == 3){
+        }else if(mode == 3){
             if(colourSensor){
                 Colour colour = readColourSensor();
                 if(colour != BIN) sort(colour);
             }
+        }else if(mode == 4){
+            if(cardReader && cardDetect){
+                cardAcquisition();
+                
+            }
+        }else if(mode == 5){
+            stringstream ss;
+            ss << "Stored Values   " << "R:" << redAmount << "G:" << greenAmount << "B:" << blueAmount;
+            string tmp = ss.str();
+            printLCD(tmp.c_str());
+            wait(0.1);
+            if(par_port->read_bit(8)){
+                log("Dispense all button pressed");
+                stateMachine = DISPENSE_ALL;
+                processState(stateMachine);
+            }else if(par_port->read_bit(9)){
+                log("Clear stored numbers button pressed");
+                writeFile(0,0,0);
+                redAmount = 0;greenAmount = 0;blueAmount = 0;
+                printLCD("Cleared values");
+                
+            }else if(par_port->read_bit(10)){
+                log("set all stored values to 10");
+                writeFile(10,10,10);
+                redAmount = 10;greenAmount = 10;blueAmount = 10;
+                printLCD("setv val;ues to 10");
+                
+            }
+            }
         }
-    }
+    
+    
       
 int main() { 
+    
     stateMachine = INITIALISING;
     processState(stateMachine);
-    writeFile(2,6,22);
-    stateMachine = READING_RGB_VALUES;
-    processState(stateMachine);
-    
+    readChipNumbers();
+    printStoredChipValues();
+    displayOperationMode();
     while(true){
-        if(testFunctions) checkSortDispenseButtons();
-    
-        
         if(serialComms){
             checkSerial();
-        }  
+        }if(testFunctions) checkSortDispenseButtons();
+        
          wait(0.05);
+         
     }
         /*char c;
         if(c = readCharacter()){