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

main.cpp

Committer:
IonSystems
Date:
2014-11-13
Revision:
11:06f6e82b40a8
Parent:
10:8c0696b99692
Child:
12:814a8fdbb6f7

File content as of revision 11:06f6e82b40a8:

#include "mbed.h"
#include <sstream>
#include "lcdCommands.h"
#include "mbedStorage.h"
#include "rgbLED.h"
#include "mbedLCD.h"
#include "stateMachine.h"
#include "FPGAcomms.h"
#ifndef serialComm
#define serialComm
#include "serialCommunication.h"
#endif
#include "testFunctions.h"




StateMachine stateMachine;

//Boolean values to easily enable and disable certain features for individual testing
bool colourSensor   =   true;
bool cardReader     =   true;
bool sorter         =   true;
bool dispensor      =   true;
bool testFunctions  =   true;
bool serialComms    =   true;

bool colourDataAcquired = false;
bool chipDetected       = false;
bool operationMode      = true; //the MBED starts in operation mode.

int sortDispenseRecycleMode = 0;




void checkSortDispenseButtons(){
        
        if(par_port->read_bit(11)){
            sortDispenseRecycleMode++;
            if(sortDispenseRecycleMode >= 4) sortDispenseRecycleMode = 0;
        }
        
        
        if(sortDispenseRecycleMode == 0){
            printLCD("Dispense Mode");
            if(par_port->read_bit(8)){
                log("Red Button pressed");
                stateMachine = DISPENSE_RED;
                processState(stateMachine);
            }else if(par_port->read_bit(9)){
                log("Green Button pressed");
                stateMachine = DISPENSE_GREEN;
                processState(stateMachine);
            }else if(par_port->read_bit(10)){
                log("Blue Button pressed");
                stateMachine = DISPENSE_BLUE;
                processState(stateMachine);
            }
        }else if(sortDispenseRecycleMode == 1){
            printLCD("Sort Mode");
            if(par_port->read_bit(8)){
                log("Red Button pressed");
                stateMachine = SORT_RED;
                processState(stateMachine);
            }else if(par_port->read_bit(9)){
                log("Green Button pressed");
                stateMachine = SORT_GREEN;
                processState(stateMachine);
            }else if(par_port->read_bit(10)){
                log("Blue Button pressed");
                stateMachine = SORT_BLUE;
                processState(stateMachine);
            }
            
        }else if(sortDispenseRecycleMode == 2){
            printLCD("Bin/Recycle Mode");
            if(par_port->read_bit(8)){
                log("Bin button pressed");
                stateMachine = SORT_BIN;
                processState(stateMachine);
            }else if(par_port->read_bit(9)){
                log("Recycle Button");
                stateMachine = SORT_RECYCLE;
                processState(stateMachine);
            }
        }else if(sortDispenseRecycleMode == 3){
            if(colourSensor){
                Colour colour = readColourSensor();
                if(colour != BIN) sort(colour);
            }
        }
    }
      
int main() { 
    stateMachine = INITIALISING;
    processState(stateMachine);
    writeFile(2,6,22);
    stateMachine = READING_RGB_VALUES;
    processState(stateMachine);
    
    while(true){
        if(testFunctions) checkSortDispenseButtons();
    
        
        if(serialComms){
            checkSerial();
        }  
         wait(0.05);
    }
        /*char c;
        if(c = readCharacter()){
            processMessage(c);
        }*/
        
       
}
       
        
    
    
    
    
    
    
    
    //printStoredChipValues();
/*     
    while(1){
       if(par_port->read_bit(11)) resetForNextCustomer();
       
        if(cardDetect & !cardDataAcquired) cardAcquisition();
        setLEDs();
        readButtons();
        
        if(chipDetected & !colourDataAcquired){
            Colour colour = readColourSensor();
            sendColourSignal(colour);
        }
        
        writeFile(redQueue, greenQueue, blueQueue);
        readFile();
        wait(2);
        
        }
    */
    
   /* setLEDcolour(255,0,0);
    wait(0.1);
    setLEDcolour(0,255,0);
     wait(0.1);
    setLEDcolour(0,0,255);
    wait(0.1);
    
    displayOperationMode();  */