2015-05-13 03:09:36 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
#include "Plane.h"
|
|
|
|
|
|
|
|
#if CLI_ENABLED == ENABLED
|
|
|
|
|
|
|
|
// Command/function table for the setup menu
|
2015-10-25 14:03:46 -03:00
|
|
|
static const struct Menu::command setup_menu_commands[] = {
|
2015-05-13 03:09:36 -03:00
|
|
|
// command function called
|
|
|
|
// ======= ===============
|
|
|
|
{"reset", MENU_FUNC(setup_factory)},
|
|
|
|
{"erase", MENU_FUNC(setup_erase)}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create the setup menu object.
|
|
|
|
MENU(setup_menu, "setup", setup_menu_commands);
|
|
|
|
|
|
|
|
// Called from the top-level menu to run the setup menu.
|
|
|
|
int8_t Plane::setup_mode(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
// Give the user some guidance
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("Setup Mode\n"
|
2015-05-13 03:09:36 -03:00
|
|
|
"\n"
|
|
|
|
"IMPORTANT: if you have not previously set this system up, use the\n"
|
|
|
|
"'reset' command to initialize the EEPROM to sensible default values\n"
|
|
|
|
"and then the 'radio' command to configure for your radio.\n"
|
2015-10-24 18:45:41 -03:00
|
|
|
"\n");
|
2015-05-13 03:09:36 -03:00
|
|
|
|
|
|
|
// Run the setup menu. When the menu exits, we will return to the main menu.
|
|
|
|
setup_menu.run();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise the EEPROM to 'factory' settings (mostly defined in APM_Config.h or via defaults).
|
|
|
|
// Called by the setup menu 'factoryreset' command.
|
|
|
|
int8_t Plane::setup_factory(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("\nType 'Y' and hit Enter to perform factory reset, any other key to abort: ");
|
2015-05-13 03:09:36 -03:00
|
|
|
|
|
|
|
do {
|
|
|
|
c = cliSerial->read();
|
|
|
|
} while (-1 == c);
|
|
|
|
|
|
|
|
if (('y' != c) && ('Y' != c))
|
|
|
|
return(-1);
|
|
|
|
AP_Param::erase_all();
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("\nFACTORY RESET complete - please reset board to continue");
|
2015-05-13 03:09:36 -03:00
|
|
|
|
|
|
|
for (;; ) {
|
|
|
|
}
|
|
|
|
// note, cannot actually return here
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int8_t Plane::setup_erase(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("\nType 'Y' and hit Enter to erase all waypoint and parameter data, any other key to abort: ");
|
2015-05-13 03:09:36 -03:00
|
|
|
|
|
|
|
do {
|
|
|
|
c = cliSerial->read();
|
|
|
|
} while (-1 == c);
|
|
|
|
|
|
|
|
if (('y' != c) && ('Y' != c))
|
|
|
|
return(-1);
|
|
|
|
zero_eeprom();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Plane::zero_eeprom(void)
|
|
|
|
{
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("\nErasing EEPROM\n");
|
2015-05-13 03:09:36 -03:00
|
|
|
StorageManager::erase();
|
2015-10-25 17:10:41 -03:00
|
|
|
cliSerial->printf("done\n");
|
2015-05-13 03:09:36 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CLI_ENABLED
|