Navigator: Add on_inactivation() interface.

This allows to run a command / function once when being deactivated. This avoids having flight modes which are not active run unnecessary code all the time.
This commit is contained in:
Lorenz Meier
2017-08-20 22:47:48 +02:00
parent 0f8f5d29be
commit 447c167d3e
2 changed files with 24 additions and 9 deletions
+17 -7
View File
@@ -45,11 +45,12 @@
NavigatorMode::NavigatorMode(Navigator *navigator, const char *name) :
SuperBlock(navigator, name),
_navigator(navigator),
_first_run(true)
_active(false)
{
/* load initial params */
updateParams();
/* set initial mission items */
on_inactivation();
on_inactive();
}
@@ -57,10 +58,8 @@ void
NavigatorMode::run(bool active)
{
if (active) {
if (_first_run) {
/* first run */
_first_run = false;
/* Reset stay in failsafe flag */
if (!_active) {
/* first run, reset stay in failsafe flag */
_navigator->get_mission_result()->stay_in_failsafe = false;
_navigator->set_mission_result_updated();
on_activation();
@@ -72,9 +71,15 @@ NavigatorMode::run(bool active)
} else {
/* periodic updates when inactive */
_first_run = true;
on_inactive();
if (_active) {
on_inactivation();
} else {
on_inactive();
}
}
_active = active;
}
void
@@ -82,6 +87,11 @@ NavigatorMode::on_inactive()
{
}
void
NavigatorMode::on_inactivation()
{
}
void
NavigatorMode::on_activation()
{