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:
Sat Nov 29 16:32:57 2014 +0000
Revision:
23:f9e7e64784be
Parent:
18:12e2c82a5a6c
Child:
27:47a7bc902587
might be working

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