From a09c18386e947c5e2c76672d63a4a94f8bb4cfb6 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Fri, 22 Nov 2019 21:52:11 +0000 Subject: [PATCH] AP_OSD: allow osd to be disabled --- libraries/AP_OSD/AP_OSD.cpp | 22 ++++++++++++++++++---- libraries/AP_OSD/AP_OSD.h | 28 +++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/libraries/AP_OSD/AP_OSD.cpp b/libraries/AP_OSD/AP_OSD.cpp index 90016d0be7..14f3f385e7 100644 --- a/libraries/AP_OSD/AP_OSD.cpp +++ b/libraries/AP_OSD/AP_OSD.cpp @@ -163,8 +163,14 @@ const AP_Param::GroupInfo AP_OSD::var_info[] = { extern const AP_HAL::HAL& hal; +// singleton instance +AP_OSD *AP_OSD::_singleton; + AP_OSD::AP_OSD() { + if (_singleton != nullptr) { + AP_HAL::panic("AP_OSD must be singleton"); + } AP_Param::setup_object_defaults(this, var_info); // default first screen enabled screen[0].enabled = 1; @@ -176,6 +182,7 @@ AP_OSD::AP_OSD() osd_type.set_default(HAL_OSD_TYPE_DEFAULT); #endif previous_pwm_screen = -1; + _singleton = this; } void AP_OSD::init() @@ -226,11 +233,14 @@ void AP_OSD::osd_thread() void AP_OSD::update_osd() { backend->clear(); - stats(); - update_current_screen(); - screen[current_screen].set_backend(backend); - screen[current_screen].draw(); + if (!_disable) { + stats(); + update_current_screen(); + + screen[current_screen].set_backend(backend); + screen[current_screen].draw(); + } backend->flush(); } @@ -386,3 +396,7 @@ void AP_OSD::set_nav_info(NavInfo &navinfo) // do this without a lock for now nav_info = navinfo; } + +AP_OSD *AP::osd() { + return AP_OSD::get_singleton(); +} diff --git a/libraries/AP_OSD/AP_OSD.h b/libraries/AP_OSD/AP_OSD.h index 422de519c1..5222d81591 100644 --- a/libraries/AP_OSD/AP_OSD.h +++ b/libraries/AP_OSD/AP_OSD.h @@ -16,10 +16,15 @@ #pragma once +#include #include #include #include +#ifndef OSD_ENABLED +#define OSD_ENABLED 0 +#endif + class AP_OSD_Backend; #define AP_OSD_NUM_SCREENS 4 @@ -196,6 +201,12 @@ public: AP_OSD(const AP_OSD &other) = delete; AP_OSD &operator=(const AP_OSD&) = delete; + // get singleton instance + static AP_OSD *get_singleton() + { + return _singleton; + } + // init - perform required initialisation void init(); @@ -258,7 +269,14 @@ public: }; void set_nav_info(NavInfo &nav_info); - + // disable the display + void disable() { + _disable = true; + } + // enable the display + void enable() { + _disable = false; + } private: void osd_thread(); @@ -278,6 +296,7 @@ private: int8_t pre_fs_screen; bool was_armed; bool was_failsafe; + bool _disable; uint32_t last_update_ms; float last_distance_m; @@ -286,4 +305,11 @@ private: float max_speed_mps; float max_current_a; float avg_current_a; + + static AP_OSD *_singleton; +}; + +namespace AP +{ +AP_OSD *osd(); };