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 6:e64796f1f384 1 #include "MCP23017.h"
IonSystems 6:e64796f1f384 2 #include "WattBob_TextLCD.h"
IonSystems 6:e64796f1f384 3 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
IonSystems 6:e64796f1f384 4 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)
IonSystems 6:e64796f1f384 5 #include <string>
IonSystems 6:e64796f1f384 6 #include "chipNumbers.h"
IonSystems 6:e64796f1f384 7 MCP23017 *par_port;
IonSystems 6:e64796f1f384 8 WattBob_TextLCD *lcd;
IonSystems 6:e64796f1f384 9
IonSystems 27:47a7bc902587 10 /* void printLCD(const char * text)
IonSystems 27:47a7bc902587 11 * Take a character array and split and trim it into two lines, to be displayed on the WattBob LCD screen.
IonSystems 27:47a7bc902587 12 */
IonSystems 23:f9e7e64784be 13 void printLCD(const char * text)
IonSystems 23:f9e7e64784be 14 {
IonSystems 23:f9e7e64784be 15 std::string txt_str = std::string(text); //Convert ther character array to a std::string,
IonSystems 23:f9e7e64784be 16 //to use in the string manipulation functions.
IonSystems 23:f9e7e64784be 17 lcd->reset();
IonSystems 23:f9e7e64784be 18 if(txt_str.length() > 32) {
IonSystems 23:f9e7e64784be 19 int length = txt_str.length();
IonSystems 23:f9e7e64784be 20 txt_str = txt_str.erase(32,length-32);
IonSystems 23:f9e7e64784be 21 lcd->locate(0,0); //Going to new line
IonSystems 23:f9e7e64784be 22 text = txt_str.c_str();
IonSystems 23:f9e7e64784be 23 }
IonSystems 23:f9e7e64784be 24 if(txt_str.length() > 16) {
IonSystems 23:f9e7e64784be 25 string line1 = txt_str.substr(0,16);
IonSystems 23:f9e7e64784be 26 string line2 = txt_str.substr(16,16);
IonSystems 23:f9e7e64784be 27 lcd->locate(0,0); //Going to new line
IonSystems 23:f9e7e64784be 28 lcd->printf(line1.c_str());
IonSystems 23:f9e7e64784be 29 lcd->locate(1,0); //Going to new line
IonSystems 23:f9e7e64784be 30 lcd->printf(line2.c_str());
IonSystems 23:f9e7e64784be 31 lcd->locate(0,0); //Going to new line
IonSystems 23:f9e7e64784be 32 }
IonSystems 23:f9e7e64784be 33 if(txt_str.length() <= 16) {
IonSystems 23:f9e7e64784be 34 lcd->locate(0,0);
IonSystems 23:f9e7e64784be 35 lcd->printf(text);
IonSystems 23:f9e7e64784be 36 }
IonSystems 23:f9e7e64784be 37
IonSystems 6:e64796f1f384 38 }
IonSystems 6:e64796f1f384 39
IonSystems 27:47a7bc902587 40 /* void printLCD(string txt_str)
IonSystems 27:47a7bc902587 41 * Take a string and split and trim it into two lines, to be displayed on the WattBob LCD screen.
IonSystems 27:47a7bc902587 42 */
IonSystems 23:f9e7e64784be 43 void printLCD(string txt_str)
IonSystems 23:f9e7e64784be 44 {
IonSystems 23:f9e7e64784be 45 lcd->reset();
IonSystems 23:f9e7e64784be 46 if(txt_str.length() > 32) {
IonSystems 23:f9e7e64784be 47 int length = txt_str.length();
IonSystems 23:f9e7e64784be 48 txt_str = txt_str.erase(32,length-32);
IonSystems 23:f9e7e64784be 49 lcd->locate(0,0); //Going to new line
IonSystems 23:f9e7e64784be 50
IonSystems 23:f9e7e64784be 51 }
IonSystems 23:f9e7e64784be 52 if(txt_str.length() > 16) {
IonSystems 23:f9e7e64784be 53 string line1 = txt_str.substr(0,16);
IonSystems 23:f9e7e64784be 54 string line2 = txt_str.substr(16,16);
IonSystems 23:f9e7e64784be 55 lcd->locate(0,0); //Going to new line
IonSystems 23:f9e7e64784be 56 lcd->printf(line1.c_str());
IonSystems 23:f9e7e64784be 57 lcd->locate(1,0); //Going to new line
IonSystems 23:f9e7e64784be 58 lcd->printf(line2.c_str());
IonSystems 23:f9e7e64784be 59 lcd->locate(0,0); //Going to new line
IonSystems 23:f9e7e64784be 60 }
IonSystems 23:f9e7e64784be 61 if(txt_str.length() <= 16) {
IonSystems 23:f9e7e64784be 62 lcd->locate(0,0);
IonSystems 23:f9e7e64784be 63 lcd->printf(&txt_str[0]);
IonSystems 23:f9e7e64784be 64 }
IonSystems 23:f9e7e64784be 65
IonSystems 18:12e2c82a5a6c 66 }
IonSystems 27:47a7bc902587 67 /* void setupLCD()
IonSystems 27:47a7bc902587 68 * Setup the I2C communication line to the WattBob.
IonSystems 27:47a7bc902587 69 */
IonSystems 23:f9e7e64784be 70 void setupLCD()
IonSystems 23:f9e7e64784be 71 {
IonSystems 6:e64796f1f384 72 par_port = new MCP23017(p9, p10, 0x40);
IonSystems 6:e64796f1f384 73 par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob
IonSystems 6:e64796f1f384 74 BACK_LIGHT_ON(par_port);
IonSystems 6:e64796f1f384 75 lcd = new WattBob_TextLCD(par_port);
IonSystems 6:e64796f1f384 76 lcd->reset();
IonSystems 6:e64796f1f384 77 }
IonSystems 27:47a7bc902587 78 /* void printStoresChipValues()
IonSystems 27:47a7bc902587 79 * Print out the values of the stored chip values to the LCD.
IonSystems 27:47a7bc902587 80 */
IonSystems 23:f9e7e64784be 81 void printStoredChipValues()
IonSystems 23:f9e7e64784be 82 {
IonSystems 6:e64796f1f384 83 stringstream strs;
IonSystems 6:e64796f1f384 84 strs << "Stored chip values";
IonSystems 6:e64796f1f384 85 strs << "R:";
IonSystems 6:e64796f1f384 86 strs << redAmount;
IonSystems 6:e64796f1f384 87 strs << ", G:";
IonSystems 6:e64796f1f384 88 strs << greenAmount;
IonSystems 6:e64796f1f384 89 strs << ", B:";
IonSystems 6:e64796f1f384 90 strs << blueAmount;
IonSystems 6:e64796f1f384 91 string temp_str = strs.str();
IonSystems 27:47a7bc902587 92 char const* pchar = temp_str.c_str();
IonSystems 6:e64796f1f384 93 printLCD(pchar);
IonSystems 23:f9e7e64784be 94 }