diff --git a/make/source.mk b/make/source.mk index 9e1452511..bf7047667 100644 --- a/make/source.mk +++ b/make/source.mk @@ -121,6 +121,7 @@ COMMON_SRC = \ cms/cms.c \ cms/cms_menu_blackbox.c \ cms/cms_menu_builtin.c \ + cms/cms_menu_failsafe.c \ cms/cms_menu_imu.c \ cms/cms_menu_ledstrip.c \ cms/cms_menu_misc.c \ @@ -297,6 +298,7 @@ SIZE_OPTIMISED_SRC := $(SIZE_OPTIMISED_SRC) \ cms/cms.c \ cms/cms_menu_blackbox.c \ cms/cms_menu_builtin.c \ + cms/cms_menu_failsafe.c \ cms/cms_menu_imu.c \ cms/cms_menu_ledstrip.c \ cms/cms_menu_misc.c \ diff --git a/src/main/cms/cms_menu_builtin.c b/src/main/cms/cms_menu_builtin.c index 9ed0b4990..37332103f 100644 --- a/src/main/cms/cms_menu_builtin.c +++ b/src/main/cms/cms_menu_builtin.c @@ -47,6 +47,7 @@ #include "cms/cms_menu_ledstrip.h" #include "cms/cms_menu_misc.h" #include "cms/cms_menu_power.h" +#include "cms/cms_menu_failsafe.h" // VTX supplied menus @@ -120,6 +121,9 @@ static OSD_Entry menuFeaturesEntries[] = {"LED STRIP", OME_Submenu, cmsMenuChange, &cmsx_menuLedstrip, 0}, #endif // LED_STRIP {"POWER", OME_Submenu, cmsMenuChange, &cmsx_menuPower, 0}, +#ifdef USE_CMS_FAILSAFE_MENU + {"FAILSAFE", OME_Submenu, cmsMenuChange, &cmsx_menuFailsafe, 0}, +#endif {"BACK", OME_Back, NULL, NULL, 0}, {NULL, OME_END, NULL, NULL, 0} }; diff --git a/src/main/cms/cms_menu_failsafe.c b/src/main/cms/cms_menu_failsafe.c new file mode 100644 index 000000000..aa8bf364d --- /dev/null +++ b/src/main/cms/cms_menu_failsafe.c @@ -0,0 +1,90 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#include +#include +#include +#include + +#include "platform.h" + +#ifdef USE_CMS_FAILSAFE_MENU + +#include "cms/cms.h" +#include "cms/cms_types.h" +#include "cms/cms_menu_failsafe.h" + +#include "config/feature.h" + +#include "fc/config.h" + +#include "flight/failsafe.h" + +#include "rx/rx.h" + +uint8_t failsafeConfig_failsafe_procedure; +uint8_t failsafeConfig_failsafe_delay; +uint8_t failsafeConfig_failsafe_off_delay; +uint16_t failsafeConfig_failsafe_throttle; + +static long cmsx_Failsafe_onEnter(void) +{ + failsafeConfig_failsafe_procedure = failsafeConfig()->failsafe_procedure; + failsafeConfig_failsafe_delay = failsafeConfig()->failsafe_delay; + failsafeConfig_failsafe_off_delay = failsafeConfig()->failsafe_off_delay; + failsafeConfig_failsafe_throttle = failsafeConfig()->failsafe_throttle; + return 0; +} + +static long cmsx_Failsafe_onExit(const OSD_Entry *self) +{ + UNUSED(self); + + failsafeConfigMutable()->failsafe_procedure = failsafeConfig_failsafe_procedure; + failsafeConfigMutable()->failsafe_delay = failsafeConfig_failsafe_delay; + failsafeConfigMutable()->failsafe_off_delay = failsafeConfig_failsafe_off_delay; + failsafeConfigMutable()->failsafe_throttle = failsafeConfig_failsafe_throttle; + + return 0; +} + +static OSD_Entry cmsx_menuFailsafeEntries[] = +{ + { "-- FAILSAFE --", OME_Label, NULL, NULL, 0}, + + { "PROCEDURE", OME_TAB, NULL, &(OSD_TAB_t) { &failsafeConfig_failsafe_procedure, FAILSAFE_PROCEDURE_COUNT - 1, failsafeProcedureNames }, 0 }, + { "GUARD TIME", OME_FLOAT, NULL, &(OSD_FLOAT_t) { &failsafeConfig_failsafe_delay, 0, 200, 1, 100 }, 0 }, + { "STAGE 2 DELAY", OME_FLOAT, NULL, &(OSD_FLOAT_t) { &failsafeConfig_failsafe_off_delay, 0, 200, 1, 100 }, 0 }, + { "STAGE 2 THROTTLE", OME_UINT16, NULL, &(OSD_UINT16_t) { &failsafeConfig_failsafe_throttle, PWM_PULSE_MIN, PWM_PULSE_MAX, 1 }, 0 }, + { "BACK", OME_Back, NULL, NULL, 0 }, + { NULL, OME_END, NULL, NULL, 0 } +}; + +CMS_Menu cmsx_menuFailsafe = { +#ifdef CMS_MENU_DEBUG + .GUARD_text = "MENUFS", + .GUARD_type = OME_MENU, +#endif + .onEnter = cmsx_Failsafe_onEnter, + .onExit = cmsx_Failsafe_onExit, + .entries = cmsx_menuFailsafeEntries +}; + +#endif diff --git a/src/main/cms/cms_menu_failsafe.h b/src/main/cms/cms_menu_failsafe.h new file mode 100644 index 000000000..4ba6e8513 --- /dev/null +++ b/src/main/cms/cms_menu_failsafe.h @@ -0,0 +1,23 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +#pragma once + +extern CMS_Menu cmsx_menuFailsafe; diff --git a/src/main/flight/failsafe.c b/src/main/flight/failsafe.c index c59a64f30..d1a8556a3 100644 --- a/src/main/flight/failsafe.c +++ b/src/main/flight/failsafe.c @@ -72,6 +72,12 @@ PG_RESET_TEMPLATE(failsafeConfig_t, failsafeConfig, .failsafe_procedure = FAILSAFE_PROCEDURE_DROP_IT // default full failsafe procedure is 0: auto-landing ); +const char * const failsafeProcedureNames[FAILSAFE_PROCEDURE_COUNT] = { + "AUTO-LAND", + "DROP", + "GPS-RESCUE" +}; + /* * Should called when the failsafe config needs to be changed - e.g. a different profile has been selected. */ diff --git a/src/main/flight/failsafe.h b/src/main/flight/failsafe.h index fa246c7b0..ae6b09c49 100644 --- a/src/main/flight/failsafe.h +++ b/src/main/flight/failsafe.h @@ -61,9 +61,12 @@ typedef enum { typedef enum { FAILSAFE_PROCEDURE_AUTO_LANDING = 0, FAILSAFE_PROCEDURE_DROP_IT, - FAILSAFE_PROCEDURE_GPS_RESCUE + FAILSAFE_PROCEDURE_GPS_RESCUE, + FAILSAFE_PROCEDURE_COUNT // must be last } failsafeProcedure_e; +extern const char * const failsafeProcedureNames[FAILSAFE_PROCEDURE_COUNT]; + typedef enum { FAILSAFE_SWITCH_MODE_STAGE1 = 0, FAILSAFE_SWITCH_MODE_KILL, diff --git a/src/main/target/common_post.h b/src/main/target/common_post.h index cfd404f43..2447cba40 100644 --- a/src/main/target/common_post.h +++ b/src/main/target/common_post.h @@ -243,3 +243,7 @@ #undef USE_DSHOT_TELEMETRY #undef USE_RPM_FILTER #endif + +#ifndef USE_CMS +#undef USE_CMS_FAILSAFE_MENU +#endif diff --git a/src/main/target/common_pre.h b/src/main/target/common_pre.h index 5af3a3b09..01005dc3a 100644 --- a/src/main/target/common_pre.h +++ b/src/main/target/common_pre.h @@ -245,5 +245,6 @@ #define USE_OSD_STICK_OVERLAY #define USE_ESCSERIAL_SIMONK #define USE_SERIAL_4WAY_SK_BOOTLOADER +#define USE_CMS_FAILSAFE_MENU #endif