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:
24:8868101d01d0
Parent:
23:f9e7e64784be
Child:
27:47a7bc902587
--- a/serialCommunication.h	Sat Nov 29 16:32:57 2014 +0000
+++ b/serialCommunication.h	Wed Dec 03 17:49:41 2014 +0000
@@ -24,136 +24,118 @@
 void processMessage(char c)
 {
     switch(c) {
-        case 'a' : { //Dispense red
+        case 'a' :  //Dispense red
             dispense(RED);
             sendCharacter('A');
             break;
-        }
-        {
-            case 'b' :  //dispense green
-                dispense(GREEN);
-                sendCharacter('B');
-                break;
-            }
-            {
-            case 'c':   //dispense blue
-                dispense(BLUE);
-                sendCharacter('C');
-                break;
-            }
-            {
-            case 'C':// Read card command
-                printLCD("Reading Card");                
-                break;
-            }
-            {
-            case 'X':
-                sendCharacter('X'); //Notify the PC that this is an MBED
-                printLCD("Connected to PC");
-                break;
-            }
-            {
-            case 'd':   //Sort Bin
-                sort(BIN);
-                sendCharacter('D');
-                break;
-            }
-            {
+
+        case 'b' :  //dispense green
+            dispense(GREEN);
+            sendCharacter('B');
+            break;
+
+        case 'c':   //dispense blue
+            dispense(BLUE);
+            sendCharacter('C');
+            break;
+
+        case 'm':// Read card command
+            sendCharacter('M');
+            int cardNumber = cardAcquisition();
+            //Send card number to pc
+            wait(0.5);
+            pc.printf("%i\n",cardNumber);
+            printLCD("Reading Card");
+            break;
+
+        case 'X':
+            sendCharacter('X'); //Notify the PC that this is an MBED
+            printLCD("Connected to PC");
+            break;
 
-            case 'o':   //testServoredBlueLeft
-                maintain(RB_LEFT);
-                sendCharacter('O');
-                break;
-            }
-            {
+        case 'd':   //Sort Bin
+            sort(BIN);
+            sendCharacter('D');
+            break;
+
+        case 'o':   //testServoredBlueLeft
+            maintain(RB_LEFT);
+            sendCharacter('O');
+            break;
 
-            case 'p':
-                maintain(RB_CENTRE);
-                sendCharacter('P');
-                break;
-            }
-            {
+        case 'p':
+            maintain(RB_CENTRE);
+            sendCharacter('P');
+            break;
+
+        case 'q':
+            maintain(RB_RIGHT);
+            sendCharacter('O');
+            break;
+
+
+        case 's':
+            maintain(GO_UP);
+            sendCharacter('S');
+            break;
+
 
-            case 'q':
-                maintain(RB_RIGHT);
-                sendCharacter('O');
-                break;
-            }
-            {
-            case 's':
-                maintain(GO_UP);
-                sendCharacter('S');
-                break;
-            }
-            {
-            case 't':
-                maintain(GO_CENTRE);
-                sendCharacter('T');
-                break;
-            }
-            {
-            case 'u':
-                maintain(GO_DOWN);
-                sendCharacter('U');
-                break;
-            }
+        case 't':
+            maintain(GO_CENTRE);
+            sendCharacter('T');
+            break;
+
+
+        case 'u':
+            maintain(GO_DOWN);
+            sendCharacter('U');
+            break;
+
+        case 'v':
+            maintain(BR_LEFT);
+            sendCharacter('V');
+            break;
+
+        case 'w':
+            maintain(BR_RIGHT);
+            sendCharacter('O');
+            break;
+
+        case 'j':
+            sort(RED);
+            sendCharacter('J');
+            break;
 
-            {
-            case 'v':
-                maintain(BR_LEFT);
-                sendCharacter('V');
-                break;
-            }
-            {
-            case 'w':
-                maintain(BR_RIGHT);
-                sendCharacter('O');
-                break;
-            }
-            {
-            case 'j':
-                sort(RED);
-                sendCharacter('J');
-                break;
-            }
-            {
-            case 'k':
-                sort(GREEN);
-                sendCharacter('K');
-                break;
-            }
-            {
-            case 'l':
-                sort(BLUE);
-                sendCharacter('L');
-                break;
-            }
-            {
+        case 'k':
+            sort(GREEN);
+            sendCharacter('K');
+            break;
+
+        case 'l':
+            sort(BLUE);
+            sendCharacter('L');
+            break;
+
+        case '0': //Dispense all
+            dispenseAll();
+            sendCharacter('1');
+            break;
 
-            case '0': //Dispense all
-                dispenseAll();
-                sendCharacter('1');
-                break;
-            }
-            {
-            case '2':
-                maintain(GO_CENTRE);
-                maintain(RB_CENTRE);
-                sendCharacter('3');
-                break;
-            }
-            {
-            case '4':
-                lift();
-                sendCharacter('5');
-                break;
-            }
-            {
-            case 'e':
-                recycle();
-                sendCharacter('E');
-                break;
-            }
+        case '2':
+            maintain(GO_CENTRE);
+            maintain(RB_CENTRE);
+            sendCharacter('3');
+            break;
+
+        case '4':
+            lift();
+            sendCharacter('5');
+            break;
+
+        case 'e':
+            recycle();
+            sendCharacter('E');
+            break;
     }
 }
 
@@ -201,21 +183,24 @@
 {
     switch(currentLanguage) {
         case ENGLISH:
-            printLCD("Setting language to English");
-            sendCharacter('Y');
-            printLCD("Language set to English");
+            pc.putc('Y');
+            glcd.putc(27);
+            glcd.putc(15);
+            glcd.putc(255);
             break;
 
         case FRENCH:
-            printLCD("Setting language to French");
-            sendCharacter('Z');
-            printLCD("Language set to French");
+            pc.putc('Z');
+            glcd.putc(27);
+            glcd.putc(16);
+            glcd.putc(255);
             break;
 
         case GERMAN:
-            printLCD("Setting language to German");
-            sendCharacter('!');
-            printLCD("Language set to German");
+            pc.putc('!');
+            glcd.putc(27);
+            glcd.putc(17);
+            glcd.putc(255);
             break;
     }
 }