![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
Diff: main.cpp
- Revision:
- 1:a8a01df48d1a
- Parent:
- 0:8d54ffcf256e
- Child:
- 2:168850019d5a
diff -r 8d54ffcf256e -r a8a01df48d1a main.cpp --- a/main.cpp Wed Oct 29 09:20:19 2014 +0000 +++ b/main.cpp Wed Oct 29 09:39:09 2014 +0000 @@ -87,11 +87,21 @@ lcd->reset(); lcd->printf(text); } - +/* valueToChar(int value): + Expects an int value what it 0 or 1. + Returns the int value as a char. + 0 will return '0' + 1 will return '1' + Used to read the bits in the card reader. +*/ char valueToChar(int value){ - if(!value) + if(value == 0){ return '0'; - else return '1'; + }else if(value == 1){ + return '1'; + }else{ + return NULL; + } } /* readBit(int bitNumber): Takes a bit number between 1 and 6 inclusive. @@ -121,8 +131,12 @@ } return valueToChar(value); } -/* - The processMessage function has two case statements: one for maintenance mode and one for operation mode. +/* processMessage(char c): + Runs when the MBED recieves a character from the PC. + Carries out tasks based on the char value. + An acknowledge signal is always send back to the PC so that it knows the MBED + has recieved the command. + Has two case statements: one for maintenance mode and one for operation mode. */ void processMessage(char c){ @@ -162,11 +176,17 @@ } else if (operation){ switch(c){ - case 'a':// Start sorting - sendCharacter('A'); //Confirm to PC that we are processing the instruction. - startSort = true; - wait(0.1); - startSort = false; + 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; } }