refactore all captureRoute stuff
This commit is contained in:
@@ -14,13 +14,18 @@
|
||||
CaptureRoute::CaptureRoute(MoveControl* moveControl, const ControlPadInput *input, Navigation* navigation)
|
||||
: ManualControl(moveControl, input) {
|
||||
this->navigation = navigation;
|
||||
this->navigation->getRoute()->clear();
|
||||
this->routeInfo = navigation->getRouteInfo();
|
||||
}
|
||||
|
||||
CaptureRoute::~CaptureRoute() {
|
||||
this->navigation->getNTRIPClient()->setActivated(false);
|
||||
}
|
||||
|
||||
void CaptureRoute::loop() {
|
||||
ManualControl::loop();
|
||||
|
||||
if (millis() - this->lastMillis < delay) {
|
||||
if (millis() - this->lastMillis < this->delay) {
|
||||
return;
|
||||
}
|
||||
this->runCaptureRoute();
|
||||
@@ -28,14 +33,26 @@ void CaptureRoute::loop() {
|
||||
}
|
||||
|
||||
void CaptureRoute::runCaptureRoute() {
|
||||
this->checkNtrip();
|
||||
|
||||
if (this->state != NtripState::Enabled)
|
||||
return;
|
||||
|
||||
if (ControlPadButton::isControlPadButtonPressed(this->input, ControlPadButton::PadButton::Action)) {
|
||||
if (this->navigation->addCurrentPosToRoute()) {
|
||||
this->lastSavedPoint = this->navigation->getCurrentPosition();
|
||||
this->routeInfo = navigation->getRouteInfo();
|
||||
this->updateDisplay = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double CaptureRoute::getDistanceToLastPoint() {
|
||||
if (!this->lastSavedPoint.isInit())
|
||||
return 0;
|
||||
return this->lastSavedPoint.distanceTo(this->navigation->getCurrentPosition());
|
||||
}
|
||||
|
||||
bool CaptureRoute::shouldUpdate() {
|
||||
if (this->updateDisplay) {
|
||||
this->updateDisplay = false;
|
||||
@@ -43,3 +60,27 @@ bool CaptureRoute::shouldUpdate() {
|
||||
}
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user