refactore all captureRoute stuff
This commit is contained in:
@@ -159,6 +159,7 @@ class Navigation {
|
|||||||
*/
|
*/
|
||||||
RouteInfo getRouteInfo() const { return this->route->getRouteInfo(); }
|
RouteInfo getRouteInfo() const { return this->route->getRouteInfo(); }
|
||||||
Route* getRoute() const { return this->route; }
|
Route* getRoute() const { return this->route; }
|
||||||
|
Point getCurrentPosition() const { return this->currentPosition; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get azimuth
|
* @brief Get azimuth
|
||||||
|
|||||||
@@ -12,24 +12,41 @@
|
|||||||
|
|
||||||
void MenuCaptureRoute::printPage() const {
|
void MenuCaptureRoute::printPage() const {
|
||||||
RouteInfo routeInfo = this->captureRoute->getRouteInfo();
|
RouteInfo routeInfo = this->captureRoute->getRouteInfo();
|
||||||
uint8_t currentPage = this->getCurrentPage();
|
|
||||||
|
|
||||||
String lineOne = "";
|
String lineOne = "";
|
||||||
String lineTwo = "";
|
String lineTwo = "";
|
||||||
|
|
||||||
switch (currentPage)
|
switch (this->getCurrentPage())
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
lineOne = "Points: ";
|
lineOne = "Capture Route";
|
||||||
lineOne.concat(routeInfo.totalPoints);
|
lineTwo = "You can drive";
|
||||||
lineTwo = "You can drive.";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
lineOne = "Average distance";
|
lineOne = "Saved waypoints";
|
||||||
lineTwo = "xxx meters";
|
lineTwo.concat(routeInfo.totalPoints);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
lineOne = "Distance to last";
|
||||||
|
lineTwo = "point: ";
|
||||||
|
lineTwo.concat(this->captureRoute->getDistanceToLastPoint());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: {
|
||||||
|
NTRIPClientStates status = this->driveManager->getNavigation()->getNTRIPClient()->getClientState();
|
||||||
|
lineOne = "NTRIP Client is";
|
||||||
|
|
||||||
|
if (status == NTRIPClientStates::pushData)
|
||||||
|
lineTwo = "enabled";
|
||||||
|
else if (status == NTRIPClientStates::notAvailable)
|
||||||
|
lineTwo = "not available";
|
||||||
|
else
|
||||||
|
lineTwo = "disabled";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this->printDefault();
|
this->printDefault();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,13 +14,18 @@
|
|||||||
CaptureRoute::CaptureRoute(MoveControl* moveControl, const ControlPadInput *input, Navigation* navigation)
|
CaptureRoute::CaptureRoute(MoveControl* moveControl, const ControlPadInput *input, Navigation* navigation)
|
||||||
: ManualControl(moveControl, input) {
|
: ManualControl(moveControl, input) {
|
||||||
this->navigation = navigation;
|
this->navigation = navigation;
|
||||||
|
this->navigation->getRoute()->clear();
|
||||||
this->routeInfo = navigation->getRouteInfo();
|
this->routeInfo = navigation->getRouteInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CaptureRoute::~CaptureRoute() {
|
||||||
|
this->navigation->getNTRIPClient()->setActivated(false);
|
||||||
|
}
|
||||||
|
|
||||||
void CaptureRoute::loop() {
|
void CaptureRoute::loop() {
|
||||||
ManualControl::loop();
|
ManualControl::loop();
|
||||||
|
|
||||||
if (millis() - this->lastMillis < delay) {
|
if (millis() - this->lastMillis < this->delay) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->runCaptureRoute();
|
this->runCaptureRoute();
|
||||||
@@ -28,14 +33,26 @@ void CaptureRoute::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CaptureRoute::runCaptureRoute() {
|
void CaptureRoute::runCaptureRoute() {
|
||||||
|
this->checkNtrip();
|
||||||
|
|
||||||
|
if (this->state != NtripState::Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action)) {
|
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action)) {
|
||||||
if (this->navigation->addCurrentPosToRoute()) {
|
if (this->navigation->addCurrentPosToRoute()) {
|
||||||
|
this->lastSavedPoint = this->navigation->getCurrentPosition();
|
||||||
this->routeInfo = navigation->getRouteInfo();
|
this->routeInfo = navigation->getRouteInfo();
|
||||||
this->updateDisplay = true;
|
this->updateDisplay = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double CaptureRoute::getDistanceToLastPoint() {
|
||||||
|
if (!this->lastSavedPoint.isInit())
|
||||||
|
return 0;
|
||||||
|
return this->lastSavedPoint.distanceTo(this->navigation->getCurrentPosition());
|
||||||
|
}
|
||||||
|
|
||||||
bool CaptureRoute::shouldUpdate() {
|
bool CaptureRoute::shouldUpdate() {
|
||||||
if (this->updateDisplay) {
|
if (this->updateDisplay) {
|
||||||
this->updateDisplay = false;
|
this->updateDisplay = false;
|
||||||
@@ -43,3 +60,27 @@ bool CaptureRoute::shouldUpdate() {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CaptureRoute::checkNtrip() {
|
||||||
|
NTRIPClient* client = this->navigation->getNTRIPClient();
|
||||||
|
NTRIPClientStates state = client->getClientState();
|
||||||
|
if (state == NTRIPClientStates::notAvailable) {
|
||||||
|
this->state = NtripState::NoNtrip;
|
||||||
|
} else if (state == NTRIPClientStates::pushData) {
|
||||||
|
this->ntripReconnectAttemps = 0;
|
||||||
|
this->state = NtripState::Enabled;
|
||||||
|
} else if (state ==NTRIPClientStates::wait) {
|
||||||
|
this->state = NtripState::Waiting;
|
||||||
|
if (millis() - this->reconnectNtripLastMillis < this->reconnectNtripDelayMillis)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this->ntripReconnectAttemps > this->ntripReconnectMaxAttemps) {
|
||||||
|
this->state = NtripState::NoNtrip;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->reconnectNtripLastMillis = millis();
|
||||||
|
client->setActivated(true);
|
||||||
|
this->ntripReconnectAttemps++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,12 @@
|
|||||||
*/
|
*/
|
||||||
class CaptureRoute : public ManualControl {
|
class CaptureRoute : public ManualControl {
|
||||||
public:
|
public:
|
||||||
|
enum NtripState {
|
||||||
|
NoNtrip,
|
||||||
|
Waiting,
|
||||||
|
Enabled
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Capture Route object
|
* @brief Construct a new Capture Route object
|
||||||
*
|
*
|
||||||
@@ -35,6 +41,13 @@ class CaptureRoute : public ManualControl {
|
|||||||
*/
|
*/
|
||||||
CaptureRoute(MoveControl* moveControl, const ControlPadInput *input, Navigation* navigation);
|
CaptureRoute(MoveControl* moveControl, const ControlPadInput *input, Navigation* navigation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy the Capture Route object
|
||||||
|
*
|
||||||
|
* Disconnect the NTRIP-Client
|
||||||
|
*/
|
||||||
|
~CaptureRoute();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calls runCaptureRoute and ManualControl::loop
|
* @brief Calls runCaptureRoute and ManualControl::loop
|
||||||
*
|
*
|
||||||
@@ -64,6 +77,13 @@ class CaptureRoute : public ManualControl {
|
|||||||
*/
|
*/
|
||||||
RouteInfo getRouteInfo() const { return this->routeInfo; }
|
RouteInfo getRouteInfo() const { return this->routeInfo; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the distance to the last saved oint
|
||||||
|
*
|
||||||
|
* @return double in meters
|
||||||
|
*/
|
||||||
|
double getDistanceToLastPoint();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Tells if there are new informations to display
|
* @brief Tells if there are new informations to display
|
||||||
*
|
*
|
||||||
@@ -72,11 +92,19 @@ class CaptureRoute : public ManualControl {
|
|||||||
*/
|
*/
|
||||||
bool shouldUpdate();
|
bool shouldUpdate();
|
||||||
private:
|
private:
|
||||||
|
void checkNtrip();
|
||||||
|
|
||||||
Navigation* navigation;
|
Navigation* navigation;
|
||||||
RouteInfo routeInfo;
|
RouteInfo routeInfo;
|
||||||
|
Point lastSavedPoint;
|
||||||
|
NtripState state = NtripState::Waiting;
|
||||||
|
|
||||||
uint32_t lastMillis = 0;
|
uint8_t ntripReconnectAttemps = 0;
|
||||||
|
uint8_t ntripReconnectMaxAttemps = 10;
|
||||||
|
uint16_t reconnectNtripDelayMillis = 1000;
|
||||||
uint16_t delay = 200;
|
uint16_t delay = 200;
|
||||||
|
uint32_t lastMillis = 0;
|
||||||
|
uint32_t reconnectNtripLastMillis = 0;
|
||||||
|
|
||||||
bool updateDisplay = false;
|
bool updateDisplay = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user