From a86ec8c786fef8ad34c16d0932516c49ef09ce74 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Nov 2013 10:16:14 +1100 Subject: [PATCH] AP_Menu: fixed double display of prompt --- libraries/AP_Menu/AP_Menu.cpp | 28 +++++++++++++++++++++------- libraries/AP_Menu/AP_Menu.h | 4 +++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/libraries/AP_Menu/AP_Menu.cpp b/libraries/AP_Menu/AP_Menu.cpp index d95f352537..9246153a63 100644 --- a/libraries/AP_Menu/AP_Menu.cpp +++ b/libraries/AP_Menu/AP_Menu.cpp @@ -80,10 +80,16 @@ Menu::_check_for_input(void) return false; } +// display the prompt +void +Menu::_display_prompt(void) +{ + _port->printf_P(PSTR("%S] "), FPSTR(_prompt)); +} // run the menu bool -Menu::_run_command(void) +Menu::_run_command(bool prompt_on_enter) { int8_t ret; uint8_t i; @@ -109,7 +115,9 @@ Menu::_run_command(void) if (_argv[0].str == NULL) { // we got a blank line, re-display the prompt - _port->printf_P(PSTR("%S] "), FPSTR(_prompt)); + if (prompt_on_enter) { + _display_prompt(); + } return false; } @@ -167,16 +175,20 @@ Menu::run(void) _allocate_buffers(); + _display_prompt(); + // loop performing commands for (;;) { // run the pre-prompt function, if one is defined - if ((NULL != _ppfunc) && !_ppfunc()) - return; + if (NULL != _ppfunc) { + if (!_ppfunc()) + return; + _display_prompt(); + } // loop reading characters from the input _input_len = 0; - _port->printf_P(PSTR("%S] "), FPSTR(_prompt)); for (;; ) { if (_check_for_input()) { @@ -186,7 +198,9 @@ Menu::run(void) } // we have a full command to run - if (_run_command()) break; + if (_run_command(false)) break; + + _display_prompt(); } } @@ -202,7 +216,7 @@ Menu::check_input(void) _allocate_buffers(); if (_check_for_input()) { - return _run_command(); + return _run_command(true); } return false; diff --git a/libraries/AP_Menu/AP_Menu.h b/libraries/AP_Menu/AP_Menu.h index 19f2b37b15..3374923a96 100644 --- a/libraries/AP_Menu/AP_Menu.h +++ b/libraries/AP_Menu/AP_Menu.h @@ -148,7 +148,9 @@ private: // run one full entered command. // return true if the menu loop should exit - bool _run_command(void); + bool _run_command(bool prompt_on_enter); + + void _display_prompt(); // port to run on static AP_HAL::BetterStream *_port;