Kristof T'Jonck / Mbed 2 deprecated proj2_car

Dependencies:   RemoteIR m3pi mbed-rtos mbed

Controller.cpp

Committer:
Kristof@LAPTOP-FT09DA9V.home
Date:
2017-05-09
Revision:
1:76cff32344d1
Child:
7:1d77c7e0208c

File content as of revision 1:76cff32344d1:

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

#include "Controller.h"

Controller::Controller() {
    //constructor once to initialise
    static LightCommunication lightCommunication;
    car = new m3pi();
    receiveThread.start(&LightCommunication::receiveData);
    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;
}