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

Committer:
IonSystems
Date:
Fri Dec 05 09:53:04 2014 +0000
Revision:
28:bdf2bf56f97b
Parent:
27:47a7bc902587
Commened main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 10:8c0696b99692 1 #include "cardReader.h"
IonSystems 10:8c0696b99692 2
IonSystems 10:8c0696b99692 3
IonSystems 27:47a7bc902587 4 /* void sendCharacter(char ch)
IonSystems 27:47a7bc902587 5 * Send a character along the serial port to the PC.
IonSystems 27:47a7bc902587 6 */
IonSystems 23:f9e7e64784be 7 void sendCharacter(char ch)
IonSystems 23:f9e7e64784be 8 {
IonSystems 23:f9e7e64784be 9 pc.putc(ch);
IonSystems 10:8c0696b99692 10 }
IonSystems 10:8c0696b99692 11
IonSystems 27:47a7bc902587 12 /* void sendString(char* ch)
IonSystems 27:47a7bc902587 13 * Send a string along the serial port to the PC.
IonSystems 27:47a7bc902587 14 */
IonSystems 23:f9e7e64784be 15 void sendString(char* ch)
IonSystems 23:f9e7e64784be 16 {
IonSystems 23:f9e7e64784be 17 pc.puts(ch);
IonSystems 10:8c0696b99692 18 }
IonSystems 27:47a7bc902587 19 /* void processMessage(char c)
IonSystems 27:47a7bc902587 20 * Decide what to do when a character is recieved.
IonSystems 27:47a7bc902587 21 */
IonSystems 23:f9e7e64784be 22 void processMessage(char c)
IonSystems 23:f9e7e64784be 23 {
IonSystems 23:f9e7e64784be 24 switch(c) {
IonSystems 24:8868101d01d0 25 case 'a' : //Dispense red
IonSystems 23:f9e7e64784be 26 dispense(RED);
IonSystems 27:47a7bc902587 27 sendCharacter('A'); //Tell the PC the operation is complete
IonSystems 6:e64796f1f384 28 break;
IonSystems 24:8868101d01d0 29
IonSystems 24:8868101d01d0 30 case 'b' : //dispense green
IonSystems 24:8868101d01d0 31 dispense(GREEN);
IonSystems 27:47a7bc902587 32 sendCharacter('B');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 33 break;
IonSystems 24:8868101d01d0 34
IonSystems 24:8868101d01d0 35 case 'c': //dispense blue
IonSystems 24:8868101d01d0 36 dispense(BLUE);
IonSystems 27:47a7bc902587 37 sendCharacter('C');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 38 break;
IonSystems 24:8868101d01d0 39
IonSystems 24:8868101d01d0 40 case 'm':// Read card command
IonSystems 24:8868101d01d0 41 sendCharacter('M');
IonSystems 24:8868101d01d0 42 int cardNumber = cardAcquisition();
IonSystems 24:8868101d01d0 43 //Send card number to pc
IonSystems 24:8868101d01d0 44 wait(0.5);
IonSystems 24:8868101d01d0 45 pc.printf("%i\n",cardNumber);
IonSystems 24:8868101d01d0 46 printLCD("Reading Card");
IonSystems 24:8868101d01d0 47 break;
IonSystems 24:8868101d01d0 48
IonSystems 24:8868101d01d0 49 case 'X':
IonSystems 24:8868101d01d0 50 sendCharacter('X'); //Notify the PC that this is an MBED
IonSystems 24:8868101d01d0 51 printLCD("Connected to PC");
IonSystems 24:8868101d01d0 52 break;
IonSystems 23:f9e7e64784be 53
IonSystems 24:8868101d01d0 54 case 'd': //Sort Bin
IonSystems 24:8868101d01d0 55 sort(BIN);
IonSystems 27:47a7bc902587 56 sendCharacter('D');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 57 break;
IonSystems 24:8868101d01d0 58
IonSystems 24:8868101d01d0 59 case 'o': //testServoredBlueLeft
IonSystems 24:8868101d01d0 60 maintain(RB_LEFT);
IonSystems 27:47a7bc902587 61 sendCharacter('O');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 62 break;
IonSystems 23:f9e7e64784be 63
IonSystems 24:8868101d01d0 64 case 'p':
IonSystems 24:8868101d01d0 65 maintain(RB_CENTRE);
IonSystems 27:47a7bc902587 66 sendCharacter('P');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 67 break;
IonSystems 24:8868101d01d0 68
IonSystems 24:8868101d01d0 69 case 'q':
IonSystems 24:8868101d01d0 70 maintain(RB_RIGHT);
IonSystems 27:47a7bc902587 71 sendCharacter('O');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 72 break;
IonSystems 24:8868101d01d0 73
IonSystems 24:8868101d01d0 74
IonSystems 24:8868101d01d0 75 case 's':
IonSystems 24:8868101d01d0 76 maintain(GO_UP);
IonSystems 27:47a7bc902587 77 sendCharacter('S');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 78 break;
IonSystems 24:8868101d01d0 79
IonSystems 23:f9e7e64784be 80
IonSystems 24:8868101d01d0 81 case 't':
IonSystems 24:8868101d01d0 82 maintain(GO_CENTRE);
IonSystems 27:47a7bc902587 83 sendCharacter('T');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 84 break;
IonSystems 24:8868101d01d0 85
IonSystems 24:8868101d01d0 86
IonSystems 24:8868101d01d0 87 case 'u':
IonSystems 24:8868101d01d0 88 maintain(GO_DOWN);
IonSystems 27:47a7bc902587 89 sendCharacter('U');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 90 break;
IonSystems 24:8868101d01d0 91
IonSystems 24:8868101d01d0 92 case 'v':
IonSystems 24:8868101d01d0 93 maintain(BR_LEFT);
IonSystems 27:47a7bc902587 94 sendCharacter('V');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 95 break;
IonSystems 24:8868101d01d0 96
IonSystems 24:8868101d01d0 97 case 'w':
IonSystems 24:8868101d01d0 98 maintain(BR_RIGHT);
IonSystems 27:47a7bc902587 99 sendCharacter('O');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 100 break;
IonSystems 24:8868101d01d0 101
IonSystems 24:8868101d01d0 102 case 'j':
IonSystems 24:8868101d01d0 103 sort(RED);
IonSystems 27:47a7bc902587 104 sendCharacter('J');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 105 break;
IonSystems 23:f9e7e64784be 106
IonSystems 24:8868101d01d0 107 case 'k':
IonSystems 24:8868101d01d0 108 sort(GREEN);
IonSystems 27:47a7bc902587 109 sendCharacter('K');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 110 break;
IonSystems 24:8868101d01d0 111
IonSystems 24:8868101d01d0 112 case 'l':
IonSystems 24:8868101d01d0 113 sort(BLUE);
IonSystems 27:47a7bc902587 114 sendCharacter('L');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 115 break;
IonSystems 24:8868101d01d0 116
IonSystems 24:8868101d01d0 117 case '0': //Dispense all
IonSystems 24:8868101d01d0 118 dispenseAll();
IonSystems 27:47a7bc902587 119 sendCharacter('1');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 120 break;
IonSystems 23:f9e7e64784be 121
IonSystems 24:8868101d01d0 122 case '2':
IonSystems 24:8868101d01d0 123 maintain(GO_CENTRE);
IonSystems 24:8868101d01d0 124 maintain(RB_CENTRE);
IonSystems 27:47a7bc902587 125 sendCharacter('3');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 126 break;
IonSystems 24:8868101d01d0 127
IonSystems 24:8868101d01d0 128 case '4':
IonSystems 24:8868101d01d0 129 lift();
IonSystems 27:47a7bc902587 130 sendCharacter('5');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 131 break;
IonSystems 24:8868101d01d0 132
IonSystems 24:8868101d01d0 133 case 'e':
IonSystems 24:8868101d01d0 134 recycle();
IonSystems 27:47a7bc902587 135 sendCharacter('E');//Tell the PC the operation is complete
IonSystems 24:8868101d01d0 136 break;
IonSystems 23:f9e7e64784be 137 }
IonSystems 23:f9e7e64784be 138 }
IonSystems 27:47a7bc902587 139 /* If the serial port is readable, get a character and do something, depending on the character recieved.
IonSystems 27:47a7bc902587 140 */
IonSystems 23:f9e7e64784be 141 bool checkSerial()
IonSystems 23:f9e7e64784be 142 {
IonSystems 10:8c0696b99692 143 printLCD("");
IonSystems 23:f9e7e64784be 144 if(pc.readable()) {
IonSystems 10:8c0696b99692 145 char c = pc.getc();
IonSystems 10:8c0696b99692 146 processMessage(c);
IonSystems 10:8c0696b99692 147 return true;
IonSystems 23:f9e7e64784be 148 } else {
IonSystems 10:8c0696b99692 149 return false;
IonSystems 10:8c0696b99692 150 }
IonSystems 6:e64796f1f384 151 }
IonSystems 27:47a7bc902587 152
IonSystems 23:f9e7e64784be 153
IonSystems 27:47a7bc902587 154 /* Set the PC's and LCD's language to whatever our language is.
IonSystems 15:0c5f20e15b6a 155 */
IonSystems 23:f9e7e64784be 156 void sendLanguageCharacter()
IonSystems 23:f9e7e64784be 157 {
IonSystems 23:f9e7e64784be 158 switch(currentLanguage) {
IonSystems 15:0c5f20e15b6a 159 case ENGLISH:
IonSystems 24:8868101d01d0 160 pc.putc('Y');
IonSystems 24:8868101d01d0 161 glcd.putc(27);
IonSystems 24:8868101d01d0 162 glcd.putc(15);
IonSystems 24:8868101d01d0 163 glcd.putc(255);
IonSystems 23:f9e7e64784be 164 break;
IonSystems 23:f9e7e64784be 165
IonSystems 15:0c5f20e15b6a 166 case FRENCH:
IonSystems 24:8868101d01d0 167 pc.putc('Z');
IonSystems 24:8868101d01d0 168 glcd.putc(27);
IonSystems 24:8868101d01d0 169 glcd.putc(16);
IonSystems 24:8868101d01d0 170 glcd.putc(255);
IonSystems 23:f9e7e64784be 171 break;
IonSystems 23:f9e7e64784be 172
IonSystems 15:0c5f20e15b6a 173 case GERMAN:
IonSystems 24:8868101d01d0 174 pc.putc('!');
IonSystems 24:8868101d01d0 175 glcd.putc(27);
IonSystems 24:8868101d01d0 176 glcd.putc(17);
IonSystems 24:8868101d01d0 177 glcd.putc(255);
IonSystems 23:f9e7e64784be 178 break;
IonSystems 15:0c5f20e15b6a 179 }
IonSystems 23:f9e7e64784be 180 }
IonSystems 6:e64796f1f384 181
IonSystems 10:8c0696b99692 182