Robin Mechele / Mbed 2 deprecated Project_mbed

Dependencies:   EthernetInterface LM75B mbed-rtos mbed

Setup.cpp

Committer:
RobinMechele
Date:
2018-03-16
Revision:
3:fbf3c92f10ee
Parent:
2:ecc0c5c14bc1
Child:
5:665ba017d54e

File content as of revision 3:fbf3c92f10ee:

#include "setup.h"
#include "lcdcontrol.h"

BusIn joy(p15,p12,p13,p16);
DigitalIn fire(p14);

LcdControl lcd;

Setup::Setup()
    :tempID("100"), partOfIP("192.168.0.")
{
    //Constructor
}

int Setup::chooseID()
{
    int setID = 100;
    lcd.lcdReset();
    lcd.printID(setID);
    while(fire==0)
    {
        if(joy.read() == 1)
        {
            lcd.lcdReset();
            if(setID == 110){
                setID = 100;
            }
            else{
                setID++;
            }
            lcd.printID(setID);
            wait(0.3);
        }
        if(joy.read() == 2)
        {
            lcd.lcdReset();
            if(setID == 100){
                setID = 110;
            }
            else{
                setID--;
            }
            lcd.printID(setID);
            wait(0.3);
        }
    }    while(fire != 0){}
    return setID;
}

int Setup::chooseMode()
{
    lcd.printMode();
    lcd.printSlave();
    while(fire != 0){}
    while(fire == 0){
        if(joy.read() == 8) {
            if(mode == 1){
                mode=0;
                lcd.printMode();
                lcd.printSlave();
            }
        } 
        else if(joy.read() == 4) {
            if(mode == 0){
                mode=1;
                lcd.printMode();
                lcd.printMaster();
            }
        }
    }
    return mode;
}

char* Setup::convertToIP(int ID)
{
    sprintf(tempID,"%ld",ID);
    return strcat(partOfIP,tempID);
}