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:
Mon Nov 24 16:09:52 2014 +0000
Revision:
18:12e2c82a5a6c
Parent:
6:e64796f1f384
Child:
23:f9e7e64784be
Added some functions for button presses

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 18:12e2c82a5a6c 37 void printLCD(string txt_str){
IonSystems 18:12e2c82a5a6c 38 lcd->reset();
IonSystems 18:12e2c82a5a6c 39 if(txt_str.length() > 32){
IonSystems 18:12e2c82a5a6c 40 int length = txt_str.length();
IonSystems 18:12e2c82a5a6c 41 txt_str = txt_str.erase(32,length-32);
IonSystems 18:12e2c82a5a6c 42 lcd->locate(0,0); //Going to new line
IonSystems 18:12e2c82a5a6c 43
IonSystems 18:12e2c82a5a6c 44 }
IonSystems 18:12e2c82a5a6c 45 if(txt_str.length() > 16){
IonSystems 18:12e2c82a5a6c 46 string line1 = txt_str.substr(0,16);
IonSystems 18:12e2c82a5a6c 47 string line2 = txt_str.substr(16,16);
IonSystems 18:12e2c82a5a6c 48 lcd->locate(0,0); //Going to new line
IonSystems 18:12e2c82a5a6c 49 lcd->printf(line1.c_str());
IonSystems 18:12e2c82a5a6c 50 lcd->locate(1,0); //Going to new line
IonSystems 18:12e2c82a5a6c 51 lcd->printf(line2.c_str());
IonSystems 18:12e2c82a5a6c 52 lcd->locate(0,0); //Going to new line
IonSystems 18:12e2c82a5a6c 53 }
IonSystems 18:12e2c82a5a6c 54 if(txt_str.length() <= 16){
IonSystems 18:12e2c82a5a6c 55 lcd->locate(0,0);
IonSystems 18:12e2c82a5a6c 56 lcd->printf(&txt_str[0]);
IonSystems 18:12e2c82a5a6c 57 }
IonSystems 18:12e2c82a5a6c 58
IonSystems 18:12e2c82a5a6c 59 }
IonSystems 18:12e2c82a5a6c 60
IonSystems 6:e64796f1f384 61 void setupLCD(){
IonSystems 6:e64796f1f384 62 par_port = new MCP23017(p9, p10, 0x40);
IonSystems 6:e64796f1f384 63 par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob
IonSystems 6:e64796f1f384 64 BACK_LIGHT_ON(par_port);
IonSystems 6:e64796f1f384 65 lcd = new WattBob_TextLCD(par_port);
IonSystems 6:e64796f1f384 66 lcd->reset();
IonSystems 6:e64796f1f384 67 }
IonSystems 6:e64796f1f384 68
IonSystems 6:e64796f1f384 69 void printStoredChipValues(){
IonSystems 6:e64796f1f384 70 stringstream strs;
IonSystems 6:e64796f1f384 71 strs << "Stored chip values";
IonSystems 6:e64796f1f384 72 strs << "R:";
IonSystems 6:e64796f1f384 73 strs << redAmount;
IonSystems 6:e64796f1f384 74 strs << ", G:";
IonSystems 6:e64796f1f384 75 strs << greenAmount;
IonSystems 6:e64796f1f384 76 strs << ", B:";
IonSystems 6:e64796f1f384 77 strs << blueAmount;
IonSystems 6:e64796f1f384 78 string temp_str = strs.str();
IonSystems 6:e64796f1f384 79 char const* pchar = temp_str.c_str(); //dont use cast
IonSystems 6:e64796f1f384 80 printLCD(pchar);
IonSystems 6:e64796f1f384 81 }