Files
Bachelorarbeit-Rover/src/driveModi/driveManager.cpp
T
2023-08-18 15:34:56 +02:00

91 lines
2.4 KiB
C++

/**
* @file driveManager.cpp
* @author Alexander Klein (alex@kleiax.de)
* @brief Implementation of the class DriveManager
* @version 0.1
* @date 2021-12-14
*
* @copyright Copyright (c) 2021
*
*/
#include "driveModi/driveManager.h"
Modi& operator++(Modi& m, int) {
return m = (m == Modi::TestMode) ? Modi::Off : static_cast<Modi>(static_cast<int>(m)+1);
}
DriveManager::DriveManager(MoveControl *moveControl, SPIClass *spiPort, const ControlPadInput *input, bool wifi) {
this->moveControl = moveControl;
this->input = input;
this->spiPort = spiPort;
this->navigation = new Navigation(spiPort, PinNumbers::gnssSpiCs);
if (wifi)
this->navigation->initNtrip(NTRIP_HOST, NTRIP_PORT, NTRIP_MOUNT_POINT, NTRIP_USER, NTRIP_PASSWORD);
this->addChildComponent(this->moveControl);
this->addChildComponent(this->navigation);
this->activateOnlyChilds();
}
DriveManager::~DriveManager() {
delete this->navigation;
delete this->spiPort;
}
void DriveManager::run() {}
void DriveManager::nextModus() {
changeModus(this->currentModus++);
}
void DriveManager::changeModus(Modi modus) {
this->currentModus = modus;
if (this->currentModusPtr) {
this->removeChildComponent(this->currentModusPtr);
delete this->currentModusPtr;
}
//Reset Route to first point
this->navigation->startNavigation();
switch (modus) {
case Modi::Off:
this->currentModusPtr = nullptr;
break;
case Modi::ManualControl: {
this->currentModusPtr = new ManualControl(this->moveControl, this->input);
}
break;
case Modi::CaptureRoute: {
this->currentModusPtr = new CaptureRoute(this->moveControl, this->input, this->navigation);
}
break;
case Modi::Autopilot: {
this->currentModusPtr = new Autopilot(this->moveControl, this->input, this->navigation);
}
break;
case Modi::ConsolControl:
this->currentModusPtr = nullptr;
break;
case Modi::TestMode: {
this->currentModusPtr = new TestMode(this->moveControl, this->navigation);
}
break;
default:
this->currentModusPtr = nullptr;
break;
}
if (this->currentModusPtr)
this->addChildComponent(this->currentModusPtr);
}