Copter: Clarify the exclusion determination in the ENUM definition

Co-authored-by: Pierre Kancir <pierre.kancir.emn@gmail.com>
Co-authored-by: Peter Barker <pbarker@barker.dropbear.id.au>
This commit is contained in:
murata 2022-07-16 23:11:58 +09:00 committed by Randy Mackay
parent d928e8b002
commit 7a7f84adee
3 changed files with 7 additions and 5 deletions

View File

@ -407,7 +407,7 @@ public:
AP_Int16 rtl_alt_final;
AP_Int16 rtl_climb_min; // rtl minimum climb in cm
AP_Int32 rtl_loiter_time;
AP_Int8 rtl_alt_type;
AP_Enum<ModeRTL::RTLAltType> rtl_alt_type;
#endif
AP_Int8 failsafe_gcs; // ground station failsafe behavior

View File

@ -1338,7 +1338,7 @@ public:
void restart_without_terrain();
// enum for RTL_ALT_TYPE parameter
enum class RTLAltType {
enum class RTLAltType : int8_t {
RTL_ALTTYPE_RELATIVE = 0,
RTL_ALTTYPE_TERRAIN = 1
};

View File

@ -49,10 +49,12 @@ void ModeRTL::restart_without_terrain()
ModeRTL::RTLAltType ModeRTL::get_alt_type() const
{
// sanity check parameter
if (g.rtl_alt_type < 0 || g.rtl_alt_type > (int)RTLAltType::RTL_ALTTYPE_TERRAIN) {
return RTLAltType::RTL_ALTTYPE_RELATIVE;
switch ((ModeRTL::RTLAltType)g.rtl_alt_type) {
case RTLAltType::RTL_ALTTYPE_RELATIVE ... RTLAltType::RTL_ALTTYPE_TERRAIN:
return g.rtl_alt_type;
}
return (RTLAltType)g.rtl_alt_type.get();
// user has an invalid value
return RTLAltType::RTL_ALTTYPE_RELATIVE;
}
// rtl_run - runs the return-to-launch controller