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:
7:1d77c7e0208c
Parent:
1:76cff32344d1
Child:
8:aff4290aacff

File content as of revision 7:1d77c7e0208c:

//
// 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(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;
}