From af96673004aab138ba94286efc05941e7b4f221f Mon Sep 17 00:00:00 2001 From: Alexander Malishev Date: Tue, 26 Jun 2018 01:25:42 +0400 Subject: [PATCH] AP_OSD: added screen switch by rc channel --- libraries/AP_OSD/AP_OSD.cpp | 33 ++++++++++++++++++++++++++++----- libraries/AP_OSD/AP_OSD.h | 7 +++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/libraries/AP_OSD/AP_OSD.cpp b/libraries/AP_OSD/AP_OSD.cpp index 5ba79b3c65..aa0776e28d 100644 --- a/libraries/AP_OSD/AP_OSD.cpp +++ b/libraries/AP_OSD/AP_OSD.cpp @@ -21,6 +21,7 @@ #include "AP_OSD_MAX7456.h" #include #include +#include #include @@ -34,12 +35,12 @@ const AP_Param::GroupInfo AP_OSD::var_info[] = { // @RebootRequired: True AP_GROUPINFO_FLAGS("_TYPE", 1, AP_OSD, osd_type, 0, AP_PARAM_FLAG_ENABLE), - // @Param: _UPDATE_FONT - // @DisplayName: Update font - // @Description: Update font inside osd chip - // @Values: 0:Do not update,1:Update + // @Param: _CHAN + // @DisplayName: Screen switch transmitter channel + // @Description: This sets the channel used to switch different OSD screens. + // @Values: 0:Disable,5:Chan5,6:Chan6,7:Chan7,8:Chan8,9:Chan9,10:Chan10,11:Chan11,12:Chan12,13:Chan13,14:Chan14,15:Chan15,16:Chan16 // @User: Standard - AP_GROUPINFO("_UPDATE_FONT", 2, AP_OSD, update_font, 1), + AP_GROUPINFO("_CHAN", 2, AP_OSD, rc_channel, 0), // @Group: 1_ // @Path: AP_OSD_Screen.cpp @@ -105,9 +106,31 @@ void AP_OSD::update_osd() { backend->clear(); + update_current_screen(); + screen[current_screen].set_backend(backend); screen[current_screen].draw(); backend->flush(); } +void AP_OSD::update_current_screen() +{ + if(rc_channel == 0) { + return; + } + + RC_Channel *channel = RC_Channels::rc_channel(rc_channel-1); + if(channel == nullptr) { + return; + } + + int16_t channel_value = channel->get_radio_in(); + for(int i=0; i channel_value) { + current_screen = i; + break; + } + } +} + diff --git a/libraries/AP_OSD/AP_OSD.h b/libraries/AP_OSD/AP_OSD.h index eb569744cb..163799cad6 100644 --- a/libraries/AP_OSD/AP_OSD.h +++ b/libraries/AP_OSD/AP_OSD.h @@ -54,7 +54,9 @@ public: static const struct AP_Param::GroupInfo var_info[]; AP_Int8 enabled; - + AP_Int16 channel_min; + AP_Int16 channel_max; + private: AP_OSD_Backend *backend; @@ -98,13 +100,14 @@ public: }; AP_Int8 osd_type; - AP_Int8 update_font; + AP_Int8 rc_channel; AP_OSD_Screen screen[AP_OSD_NUM_SCREENS]; private: void timer(); void update_osd(); + void update_current_screen(); AP_OSD_Backend *backend; uint32_t last_update_ms;