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 Nov 07 20:16:23 2014 +0000
Revision:
6:e64796f1f384
Child:
18:12e2c82a5a6c
Recovered from the attack of Euan

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 6:e64796f1f384 10
IonSystems 6:e64796f1f384 11 void printLCD(const char * text){
IonSystems 6:e64796f1f384 12 std::string txt_str = std::string(text); //Convert ther character array to a std::string,
IonSystems 6:e64796f1f384 13 //to use in the string manipulation functions.
IonSystems 6:e64796f1f384 14 lcd->reset();
IonSystems 6:e64796f1f384 15 if(txt_str.length() > 32){
IonSystems 6:e64796f1f384 16 int length = txt_str.length();
IonSystems 6:e64796f1f384 17 txt_str = txt_str.erase(32,length-32);
IonSystems 6:e64796f1f384 18 lcd->locate(0,0); //Going to new line
IonSystems 6:e64796f1f384 19 text = txt_str.c_str();
IonSystems 6:e64796f1f384 20 }
IonSystems 6:e64796f1f384 21 if(txt_str.length() > 16){
IonSystems 6:e64796f1f384 22 string line1 = txt_str.substr(0,16);
IonSystems 6:e64796f1f384 23 string line2 = txt_str.substr(16,16);
IonSystems 6:e64796f1f384 24 lcd->locate(0,0); //Going to new line
IonSystems 6:e64796f1f384 25 lcd->printf(line1.c_str());
IonSystems 6:e64796f1f384 26 lcd->locate(1,0); //Going to new line
IonSystems 6:e64796f1f384 27 lcd->printf(line2.c_str());
IonSystems 6:e64796f1f384 28 lcd->locate(0,0); //Going to new line
IonSystems 6:e64796f1f384 29 }
IonSystems 6:e64796f1f384 30 if(txt_str.length() <= 16){
IonSystems 6:e64796f1f384 31 lcd->locate(0,0);
IonSystems 6:e64796f1f384 32 lcd->printf(text);
IonSystems 6:e64796f1f384 33 }
IonSystems 6:e64796f1f384 34
IonSystems 6:e64796f1f384 35 }
IonSystems 6:e64796f1f384 36
IonSystems 6:e64796f1f384 37 void setupLCD(){
IonSystems 6:e64796f1f384 38 par_port = new MCP23017(p9, p10, 0x40);
IonSystems 6:e64796f1f384 39 par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob
IonSystems 6:e64796f1f384 40 BACK_LIGHT_ON(par_port);
IonSystems 6:e64796f1f384 41 lcd = new WattBob_TextLCD(par_port);
IonSystems 6:e64796f1f384 42 lcd->reset();
IonSystems 6:e64796f1f384 43 }
IonSystems 6:e64796f1f384 44
IonSystems 6:e64796f1f384 45 void printStoredChipValues(){
IonSystems 6:e64796f1f384 46 stringstream strs;
IonSystems 6:e64796f1f384 47 strs << "Stored chip values";
IonSystems 6:e64796f1f384 48 strs << "R:";
IonSystems 6:e64796f1f384 49 strs << redAmount;
IonSystems 6:e64796f1f384 50 strs << ", G:";
IonSystems 6:e64796f1f384 51 strs << greenAmount;
IonSystems 6:e64796f1f384 52 strs << ", B:";
IonSystems 6:e64796f1f384 53 strs << blueAmount;
IonSystems 6:e64796f1f384 54 string temp_str = strs.str();
IonSystems 6:e64796f1f384 55 char const* pchar = temp_str.c_str(); //dont use cast
IonSystems 6:e64796f1f384 56 printLCD(pchar);
IonSystems 6:e64796f1f384 57 }