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:
27:47a7bc902587
Parent:
24:8868101d01d0
--- a/serialCommunication.h	Thu Dec 04 12:31:23 2014 +0000
+++ b/serialCommunication.h	Thu Dec 04 22:05:18 2014 +0000
@@ -1,42 +1,40 @@
 #include "cardReader.h"
 
-char bitToChar(bool bit)
-{
-    if(bit == 0) {
-        return '0';
-    } else if(bit == 1) {
-        return '1';
-    } else {
-        return NULL;
-    }
-}
 
+/*  void sendCharacter(char ch)
+ *  Send a character along the serial port to the PC.
+ */
 void sendCharacter(char ch)
 {
     pc.putc(ch);
 }
 
+/*  void sendString(char* ch)
+ *  Send a string along the serial port to the PC.
+ */
 void sendString(char* ch)
 {
     pc.puts(ch);
 }
-
+/*  void processMessage(char c)
+ *  Decide what to do when a character is recieved.
+ */
 void processMessage(char c)
 {
     switch(c) {
         case 'a' :  //Dispense red
             dispense(RED);
-            sendCharacter('A');
+            sendCharacter('A'); //Tell the PC the operation is complete
             break;
 
         case 'b' :  //dispense green
             dispense(GREEN);
-            sendCharacter('B');
+            sendCharacter('B');//Tell the PC the operation is complete
             break;
 
         case 'c':   //dispense blue
             dispense(BLUE);
-            sendCharacter('C');
+            sendCharacter('C');//Tell the PC the operation is complete
             break;
 
         case 'm':// Read card command
@@ -55,110 +53,91 @@
 
         case 'd':   //Sort Bin
             sort(BIN);
-            sendCharacter('D');
+            sendCharacter('D');//Tell the PC the operation is complete
             break;
 
         case 'o':   //testServoredBlueLeft
             maintain(RB_LEFT);
-            sendCharacter('O');
+            sendCharacter('O');//Tell the PC the operation is complete
             break;
 
         case 'p':
             maintain(RB_CENTRE);
-            sendCharacter('P');
+            sendCharacter('P');//Tell the PC the operation is complete
             break;
 
         case 'q':
             maintain(RB_RIGHT);
-            sendCharacter('O');
+            sendCharacter('O');//Tell the PC the operation is complete
             break;
 
 
         case 's':
             maintain(GO_UP);
-            sendCharacter('S');
+            sendCharacter('S');//Tell the PC the operation is complete
             break;
 
 
         case 't':
             maintain(GO_CENTRE);
-            sendCharacter('T');
+            sendCharacter('T');//Tell the PC the operation is complete
             break;
 
 
         case 'u':
             maintain(GO_DOWN);
-            sendCharacter('U');
+            sendCharacter('U');//Tell the PC the operation is complete
             break;
 
         case 'v':
             maintain(BR_LEFT);
-            sendCharacter('V');
+            sendCharacter('V');//Tell the PC the operation is complete
             break;
 
         case 'w':
             maintain(BR_RIGHT);
-            sendCharacter('O');
+            sendCharacter('O');//Tell the PC the operation is complete
             break;
 
         case 'j':
             sort(RED);
-            sendCharacter('J');
+            sendCharacter('J');//Tell the PC the operation is complete
             break;
 
         case 'k':
             sort(GREEN);
-            sendCharacter('K');
+            sendCharacter('K');//Tell the PC the operation is complete
             break;
 
         case 'l':
             sort(BLUE);
-            sendCharacter('L');
+            sendCharacter('L');//Tell the PC the operation is complete
             break;
 
         case '0': //Dispense all
             dispenseAll();
-            sendCharacter('1');
+            sendCharacter('1');//Tell the PC the operation is complete
             break;
 
         case '2':
             maintain(GO_CENTRE);
             maintain(RB_CENTRE);
-            sendCharacter('3');
+            sendCharacter('3');//Tell the PC the operation is complete
             break;
 
         case '4':
             lift();
-            sendCharacter('5');
+            sendCharacter('5');//Tell the PC the operation is complete
             break;
 
         case 'e':
             recycle();
-            sendCharacter('E');
+            sendCharacter('E');//Tell the PC the operation is complete
             break;
     }
 }
-
-/*else if (operationMode){
-    switch(c){
-        case 'n':// Start sorting
-            sendCharacter('N'); //Confirm to PC that we are processing the instruction.
-            startSort = true; //Pulse the startSort control line to FPGA
-            wait(0.1);
-            startSort = false;
-        break;
-        case 'o':   //Start dispensing
-            sendCharacter('O');
-            startDispense = true; //Pulse the startDispense control line to FPGA
-            wait(0.1);
-            startDispense = false;
-        break;
-        case 'p':   //
-            sendCharacter('P');
-        break;
-        }
-   }
-}*/
+/* If the serial port is readable, get a character and do something, depending on the character recieved.
+ */
 bool checkSerial()
 {
     printLCD("");
@@ -170,14 +149,9 @@
         return false;
     }
 }
-bool readCharacter()
-{
-    char c = pc.getc(); //wait for a serial character to be recieved.
-    processMessage(c);  //Do something, based on the character recieved.
-    return true;
-}
+
 
-/* Set the PC's laguage to whatever our language is
+/* Set the PC's and LCD's language to whatever our language is.
 */
 void sendLanguageCharacter()
 {