Kristof T'Jonck / Mbed 2 deprecated proj2_car

Dependencies:   RemoteIR m3pi mbed-rtos mbed

Controller.cpp

Committer:
Kristof@LAPTOP-FT09DA9V
Date:
2017-05-10
Revision:
8:aff4290aacff
Parent:
7:1d77c7e0208c
Child:
9:8c5229dfab82

File content as of revision 8:aff4290aacff:

//
// Created by Kristof on 5/9/2017.
//

#include "Controller.h"

void Controller::runThread(){
    lightCommunication->receiveData();
}

Controller::Controller() {
    //constructor once to initialise
    lightCommunication = new LightCommunication();
    car = new m3pi();
    receiveThread.start(callback(this,Controller::runThread));
    ir_rx = new ReceiverIR(p21);

}

Controller::~Controller() {

}
int Controller::run() {

    lightCommunication->mut.lock();
    if (lightCommunication->needsToStop()){
        car->stop();
        lightCommunication->mut.unlock();
    }else {
        current_left = lightCommunication->getLeft(current_left);
        current_right = lightCommunication->getRight(current_right);
        lightCommunication->mut.unlock();
        car->left_motor(current_left) ;
        car->right_motor(current_right) ;
    }
    return 0;
}