Plane: add mehtod to check terrain by mode

This commit is contained in:
Iampete1 2021-09-19 00:12:33 +01:00 committed by Andrew Tridgell
parent dc2ba8236a
commit 0549e08c5c
2 changed files with 7 additions and 1 deletions

View File

@ -798,6 +798,7 @@ private:
bool terrain_disabled();
#if AP_TERRAIN_AVAILABLE
bool terrain_enabled_in_current_mode() const;
bool terrain_enabled_in_mode(Mode::Number num) const;
enum class terrain_bitmask {
ALL = 1U << 0,
FLY_BY_WIRE_B = 1U << 1,

View File

@ -765,6 +765,11 @@ const Plane::TerrainLookupTable Plane::Terrain_lookup[] = {
};
bool Plane::terrain_enabled_in_current_mode() const
{
return terrain_enabled_in_mode(control_mode->mode_number());
}
bool Plane::terrain_enabled_in_mode(Mode::Number num) const
{
// Global enable
if ((g.terrain_follow.get() & int32_t(terrain_bitmask::ALL)) != 0) {
@ -773,7 +778,7 @@ bool Plane::terrain_enabled_in_current_mode() const
// Specific enable
for (const struct TerrainLookupTable entry : Terrain_lookup) {
if (entry.mode_num == control_mode->mode_number()) {
if (entry.mode_num == num) {
if ((g.terrain_follow.get() & int32_t(entry.bitmask)) != 0) {
return true;
}