AP_OSD: added screen switch by rc channel

This commit is contained in:
Alexander Malishev 2018-06-26 01:25:42 +04:00 committed by Andrew Tridgell
parent e487f37fd7
commit af96673004
2 changed files with 33 additions and 7 deletions

View File

@ -21,6 +21,7 @@
#include "AP_OSD_MAX7456.h"
#include <AP_HAL/AP_HAL.h>
#include <AP_HAL/Util.h>
#include <RC_Channel/RC_Channel.h>
#include <utility>
@ -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<AP_OSD_NUM_SCREENS; i++){
if(screen[i].enabled && screen[i].channel_min <= channel_value && screen[i].channel_max > channel_value) {
current_screen = i;
break;
}
}
}

View File

@ -54,6 +54,8 @@ 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;