2018-06-23 04:11:05 -03:00
|
|
|
/*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-03-18 19:43:47 -03:00
|
|
|
#include "AP_OSD_config.h"
|
|
|
|
|
2022-02-28 21:19:13 -04:00
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
|
|
|
#include <AP_HAL/Semaphores.h>
|
2018-06-23 04:11:05 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
2018-06-29 17:14:09 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2021-02-23 18:05:37 -04:00
|
|
|
#include <AP_ESC_Telem/AP_ESC_Telem.h>
|
2020-04-18 17:16:02 -03:00
|
|
|
#include <RC_Channel/RC_Channel.h>
|
2022-11-08 00:23:10 -04:00
|
|
|
#include <GCS_MAVLink/GCS_config.h>
|
2020-09-16 05:18:35 -03:00
|
|
|
#include <AP_OLC/AP_OLC.h>
|
2021-08-18 08:42:17 -03:00
|
|
|
#include <AP_MSP/msp.h>
|
2021-09-28 04:50:14 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2022-11-08 00:23:10 -04:00
|
|
|
#if HAL_GCS_ENABLED
|
2022-07-11 07:07:03 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2022-11-08 00:23:10 -04:00
|
|
|
#endif
|
2022-11-06 19:20:46 -04:00
|
|
|
#include <AC_Fence/AC_Fence_config.h>
|
2021-03-05 13:12:43 -04:00
|
|
|
|
2018-06-23 04:11:05 -03:00
|
|
|
class AP_OSD_Backend;
|
2020-08-04 17:41:02 -03:00
|
|
|
class AP_MSP;
|
2018-06-23 04:11:05 -03:00
|
|
|
|
2020-04-18 17:16:02 -03:00
|
|
|
#define AP_OSD_NUM_DISPLAY_SCREENS 4
|
|
|
|
#if OSD_PARAM_ENABLED
|
|
|
|
#define AP_OSD_NUM_PARAM_SCREENS 2
|
|
|
|
#else
|
|
|
|
#define AP_OSD_NUM_PARAM_SCREENS 0
|
|
|
|
#endif
|
|
|
|
#define AP_OSD_NUM_SCREENS (AP_OSD_NUM_DISPLAY_SCREENS + AP_OSD_NUM_PARAM_SCREENS)
|
|
|
|
|
|
|
|
#define PARAM_INDEX(key, idx, group) (uint32_t(uint32_t(key) << 23 | uint32_t(idx) << 18 | uint32_t(group)))
|
|
|
|
#define PARAM_TOKEN_INDEX(token) PARAM_INDEX(AP_Param::get_persistent_key(token.key), token.idx, token.group_element)
|
2018-06-24 07:00:23 -03:00
|
|
|
|
2021-08-28 17:21:57 -03:00
|
|
|
#define AP_OSD_NUM_SYMBOLS 91
|
2018-06-24 07:00:23 -03:00
|
|
|
/*
|
|
|
|
class to hold one setting
|
|
|
|
*/
|
2019-09-16 18:35:45 -03:00
|
|
|
class AP_OSD_Setting
|
|
|
|
{
|
2018-06-24 07:00:23 -03:00
|
|
|
public:
|
|
|
|
AP_Int8 enabled;
|
|
|
|
AP_Int8 xpos;
|
|
|
|
AP_Int8 ypos;
|
|
|
|
|
2023-01-11 09:32:00 -04:00
|
|
|
AP_OSD_Setting(bool enabled = 0, uint8_t x = 0, uint8_t y = 0);
|
2018-06-25 18:26:21 -03:00
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
// User settable parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2023-01-11 09:32:00 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
const float default_enabled;
|
|
|
|
const float default_xpos;
|
|
|
|
const float default_ypos;
|
2018-06-24 07:00:23 -03:00
|
|
|
};
|
|
|
|
|
2018-07-05 17:54:47 -03:00
|
|
|
class AP_OSD;
|
2018-06-24 07:00:23 -03:00
|
|
|
|
2020-04-18 17:16:02 -03:00
|
|
|
class AP_OSD_AbstractScreen
|
|
|
|
{
|
2021-08-06 12:54:02 -03:00
|
|
|
friend class AP_OSD;
|
2020-04-18 17:16:02 -03:00
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
AP_OSD_AbstractScreen() {}
|
2020-09-10 17:51:04 -03:00
|
|
|
virtual void draw(void) {}
|
2020-04-18 17:16:02 -03:00
|
|
|
|
|
|
|
void set_backend(AP_OSD_Backend *_backend);
|
|
|
|
|
|
|
|
AP_Int8 enabled;
|
|
|
|
AP_Int16 channel_min;
|
|
|
|
AP_Int16 channel_max;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool check_option(uint32_t option);
|
2022-01-10 04:36:43 -04:00
|
|
|
#ifdef HAL_WITH_MSP_DISPLAYPORT
|
|
|
|
virtual uint8_t get_txt_resolution() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
virtual uint8_t get_font_index() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-18 17:16:02 -03:00
|
|
|
enum unit_type {
|
|
|
|
ALTITUDE=0,
|
|
|
|
SPEED=1,
|
|
|
|
VSPEED=2,
|
|
|
|
DISTANCE=3,
|
|
|
|
DISTANCE_LONG=4,
|
|
|
|
TEMPERATURE=5,
|
|
|
|
UNIT_TYPE_LAST=6,
|
|
|
|
};
|
|
|
|
|
|
|
|
char u_icon(enum unit_type unit);
|
|
|
|
float u_scale(enum unit_type unit, float value);
|
|
|
|
|
|
|
|
AP_OSD_Backend *backend;
|
|
|
|
AP_OSD *osd;
|
2021-08-06 12:54:02 -03:00
|
|
|
|
|
|
|
static uint8_t symbols_lookup_table[AP_OSD_NUM_SYMBOLS];
|
2020-04-18 17:16:02 -03:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:30:08 -03:00
|
|
|
#if OSD_ENABLED
|
2018-06-24 07:00:23 -03:00
|
|
|
/*
|
|
|
|
class to hold one screen of settings
|
|
|
|
*/
|
2020-04-18 17:16:02 -03:00
|
|
|
class AP_OSD_Screen : public AP_OSD_AbstractScreen
|
2019-09-16 18:35:45 -03:00
|
|
|
{
|
2018-06-24 07:00:23 -03:00
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
AP_OSD_Screen();
|
2020-09-10 17:51:04 -03:00
|
|
|
|
|
|
|
// skip the drawing if we are not using a font based backend. This saves a lot of flash space when
|
|
|
|
// using the MSP OSD system on boards that don't have a MAX7456
|
2021-08-06 12:54:02 -03:00
|
|
|
#if HAL_WITH_OSD_BITMAP || HAL_WITH_MSP_DISPLAYPORT
|
2020-04-18 17:16:02 -03:00
|
|
|
void draw(void) override;
|
|
|
|
#endif
|
2018-07-05 17:54:47 -03:00
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
// User settable parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2021-07-15 21:59:29 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info2[];
|
2018-06-24 07:45:58 -03:00
|
|
|
|
2022-01-10 04:36:43 -04:00
|
|
|
#ifdef HAL_WITH_MSP_DISPLAYPORT
|
|
|
|
uint8_t get_txt_resolution() const override {
|
|
|
|
return txt_resolution;
|
|
|
|
}
|
|
|
|
uint8_t get_font_index() const override {
|
|
|
|
return font_index;
|
|
|
|
}
|
|
|
|
#endif
|
2018-06-24 07:00:23 -03:00
|
|
|
private:
|
2020-08-04 17:41:02 -03:00
|
|
|
friend class AP_MSP;
|
|
|
|
friend class AP_MSP_Telem_Backend;
|
2021-09-06 11:07:53 -03:00
|
|
|
friend class AP_MSP_Telem_DJI;
|
2020-08-04 17:41:02 -03:00
|
|
|
|
2018-06-29 17:14:09 -03:00
|
|
|
static const uint8_t message_visible_width = 26;
|
|
|
|
static const uint8_t message_scroll_time_ms = 200;
|
|
|
|
static const uint8_t message_scroll_delay = 5;
|
|
|
|
|
|
|
|
static constexpr float ah_max_pitch = DEG_TO_RAD * 20;
|
|
|
|
//typical fpv camera has 80deg vertical field of view, 16 row of chars
|
|
|
|
static constexpr float ah_pitch_rad_to_char = 16.0f/(DEG_TO_RAD * 80);
|
|
|
|
|
2023-02-06 09:22:48 -04:00
|
|
|
enum class VoltageType {
|
|
|
|
VOLTAGE,
|
|
|
|
RESTING_VOLTAGE,
|
|
|
|
AVG_CELL,
|
|
|
|
RESTING_CELL,
|
|
|
|
};
|
|
|
|
|
2018-07-05 16:57:16 -03:00
|
|
|
AP_OSD_Setting altitude{true, 23, 8};
|
|
|
|
AP_OSD_Setting bat_volt{true, 24, 1};
|
|
|
|
AP_OSD_Setting rssi{true, 1, 1};
|
2021-07-14 16:28:34 -03:00
|
|
|
AP_OSD_Setting link_quality{false,1,1};
|
2021-03-22 12:03:42 -03:00
|
|
|
AP_OSD_Setting restvolt{false, 24, 2};
|
|
|
|
AP_OSD_Setting avgcellvolt{false, 24, 3};
|
2023-02-06 09:22:48 -04:00
|
|
|
AP_OSD_Setting avgcellrestvolt{false, 24, 4};
|
2018-07-05 16:57:16 -03:00
|
|
|
AP_OSD_Setting current{true, 25, 2};
|
|
|
|
AP_OSD_Setting batused{true, 23, 3};
|
|
|
|
AP_OSD_Setting sats{true, 1, 3};
|
|
|
|
AP_OSD_Setting fltmode{true, 2, 8};
|
|
|
|
AP_OSD_Setting message{true, 2, 6};
|
|
|
|
AP_OSD_Setting gspeed{true, 2, 14};
|
|
|
|
AP_OSD_Setting horizon{true, 14, 8};
|
|
|
|
AP_OSD_Setting home{true, 14, 1};
|
|
|
|
AP_OSD_Setting throttle{true, 24, 11};
|
|
|
|
AP_OSD_Setting heading{true, 13, 2};
|
|
|
|
AP_OSD_Setting compass{true, 15, 3};
|
|
|
|
AP_OSD_Setting wind{false, 2, 12};
|
|
|
|
AP_OSD_Setting aspeed{false, 2, 13};
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting aspd1;
|
|
|
|
AP_OSD_Setting aspd2;
|
2018-07-05 16:57:16 -03:00
|
|
|
AP_OSD_Setting vspeed{true, 24, 9};
|
2021-02-23 18:05:37 -04:00
|
|
|
#if HAL_WITH_ESC_TELEM
|
2021-06-03 19:31:35 -03:00
|
|
|
AP_OSD_Setting esc_temp {false, 24, 13};
|
|
|
|
AP_OSD_Setting esc_rpm{false, 22, 12};
|
|
|
|
AP_OSD_Setting esc_amps{false, 24, 14};
|
2018-07-01 12:57:11 -03:00
|
|
|
#endif
|
2018-07-05 16:57:16 -03:00
|
|
|
AP_OSD_Setting gps_latitude{true, 9, 13};
|
|
|
|
AP_OSD_Setting gps_longitude{true, 9, 14};
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting roll_angle;
|
|
|
|
AP_OSD_Setting pitch_angle;
|
|
|
|
AP_OSD_Setting temp;
|
2021-09-28 04:50:14 -03:00
|
|
|
#if BARO_MAX_INSTANCES > 1
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting btemp;
|
2021-09-28 04:50:14 -03:00
|
|
|
#endif
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting hdop;
|
|
|
|
AP_OSD_Setting waypoint;
|
|
|
|
AP_OSD_Setting xtrack_error;
|
2018-08-11 14:07:31 -03:00
|
|
|
AP_OSD_Setting dist{false,22,11};
|
|
|
|
AP_OSD_Setting stat{false,0,0};
|
2018-07-16 03:40:40 -03:00
|
|
|
AP_OSD_Setting flightime{false, 23, 10};
|
2018-08-16 20:26:49 -03:00
|
|
|
AP_OSD_Setting climbeff{false,0,0};
|
|
|
|
AP_OSD_Setting eff{false, 22, 10};
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting atemp;
|
|
|
|
AP_OSD_Setting bat2_vlt;
|
|
|
|
AP_OSD_Setting bat2used;
|
|
|
|
AP_OSD_Setting current2;
|
|
|
|
AP_OSD_Setting clk;
|
|
|
|
AP_OSD_Setting callsign;
|
|
|
|
AP_OSD_Setting vtx_power;
|
2021-05-24 18:36:55 -03:00
|
|
|
AP_OSD_Setting hgt_abvterr{false, 23, 7};
|
|
|
|
AP_OSD_Setting fence{false, 14, 9};
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting rngf;
|
2020-09-16 05:18:35 -03:00
|
|
|
#if HAL_PLUSCODE_ENABLE
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting pluscode;
|
2020-09-16 05:18:35 -03:00
|
|
|
#endif
|
2021-08-28 17:21:57 -03:00
|
|
|
AP_OSD_Setting sidebars{false, 4, 5};
|
2020-08-20 02:24:57 -03:00
|
|
|
|
2020-08-04 17:41:02 -03:00
|
|
|
// MSP OSD only
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_Setting crosshair;
|
2020-08-04 17:41:02 -03:00
|
|
|
AP_OSD_Setting home_dist{true, 1, 1};
|
|
|
|
AP_OSD_Setting home_dir{true, 1, 1};
|
|
|
|
AP_OSD_Setting power{true, 1, 1};
|
|
|
|
AP_OSD_Setting cell_volt{true, 1, 1};
|
|
|
|
AP_OSD_Setting batt_bar{true, 1, 1};
|
|
|
|
AP_OSD_Setting arming{true, 1, 1};
|
2018-06-25 18:26:21 -03:00
|
|
|
|
2022-01-10 04:36:43 -04:00
|
|
|
#ifdef HAL_WITH_MSP_DISPLAYPORT
|
|
|
|
// Per screen HD resolution options (currently supported only by DisplayPort)
|
|
|
|
AP_Int8 txt_resolution;
|
|
|
|
AP_Int8 font_index;
|
|
|
|
#endif
|
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw_altitude(uint8_t x, uint8_t y);
|
2023-02-06 09:22:48 -04:00
|
|
|
void draw_bat_volt(uint8_t instance,VoltageType type,uint8_t x, uint8_t y);
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw_bat_volt(uint8_t x, uint8_t y);
|
2021-03-22 12:03:42 -03:00
|
|
|
void draw_avgcellvolt(uint8_t x, uint8_t y);
|
2023-02-06 09:22:48 -04:00
|
|
|
void draw_avgcellrestvolt(uint8_t x, uint8_t y);
|
2021-03-22 12:03:42 -03:00
|
|
|
void draw_restvolt(uint8_t x, uint8_t y);
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw_rssi(uint8_t x, uint8_t y);
|
2021-07-14 16:28:34 -03:00
|
|
|
void draw_link_quality(uint8_t x, uint8_t y);
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw_current(uint8_t x, uint8_t y);
|
2020-11-21 14:08:56 -04:00
|
|
|
void draw_current(uint8_t instance, uint8_t x, uint8_t y);
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw_batused(uint8_t x, uint8_t y);
|
2019-07-07 11:39:31 -03:00
|
|
|
void draw_batused(uint8_t instance, uint8_t x, uint8_t y);
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw_sats(uint8_t x, uint8_t y);
|
|
|
|
void draw_fltmode(uint8_t x, uint8_t y);
|
|
|
|
void draw_message(uint8_t x, uint8_t y);
|
2018-06-26 14:10:57 -03:00
|
|
|
void draw_gspeed(uint8_t x, uint8_t y);
|
2018-06-29 17:14:09 -03:00
|
|
|
void draw_horizon(uint8_t x, uint8_t y);
|
2018-06-30 18:43:51 -03:00
|
|
|
void draw_home(uint8_t x, uint8_t y);
|
2018-06-28 02:56:00 -03:00
|
|
|
void draw_throttle(uint8_t x, uint8_t y);
|
|
|
|
void draw_heading(uint8_t x, uint8_t y);
|
2021-09-26 17:24:03 -03:00
|
|
|
#ifdef HAL_OSD_SIDEBAR_ENABLE
|
2021-08-28 17:21:57 -03:00
|
|
|
void draw_sidebars(uint8_t x, uint8_t y);
|
2021-09-26 17:24:03 -03:00
|
|
|
#endif
|
2018-07-03 18:06:36 -03:00
|
|
|
void draw_compass(uint8_t x, uint8_t y);
|
2018-07-03 18:50:05 -03:00
|
|
|
void draw_wind(uint8_t x, uint8_t y);
|
2018-07-03 19:23:53 -03:00
|
|
|
void draw_aspeed(uint8_t x, uint8_t y);
|
2019-07-21 05:48:16 -03:00
|
|
|
void draw_aspd1(uint8_t x, uint8_t y);
|
2018-09-11 14:31:07 -03:00
|
|
|
void draw_aspd2(uint8_t x, uint8_t y);
|
2018-07-03 19:23:53 -03:00
|
|
|
void draw_vspeed(uint8_t x, uint8_t y);
|
2020-09-16 05:18:35 -03:00
|
|
|
#if HAL_PLUSCODE_ENABLE
|
2020-08-20 02:24:42 -03:00
|
|
|
void draw_pluscode(uint8_t x, uint8_t y);
|
2020-09-16 05:18:35 -03:00
|
|
|
#endif
|
2018-07-08 19:32:29 -03:00
|
|
|
//helper functions
|
2020-09-27 12:49:48 -03:00
|
|
|
void draw_speed(uint8_t x, uint8_t y, float angle_rad, float magnitude);
|
2018-07-08 19:32:29 -03:00
|
|
|
void draw_distance(uint8_t x, uint8_t y, float distance);
|
2023-03-27 12:23:25 -03:00
|
|
|
char get_arrow_font_index (int32_t angle_cd);
|
2021-02-23 18:05:37 -04:00
|
|
|
#if HAL_WITH_ESC_TELEM
|
2021-06-03 19:31:35 -03:00
|
|
|
void draw_esc_temp(uint8_t x, uint8_t y);
|
|
|
|
void draw_esc_rpm(uint8_t x, uint8_t y);
|
|
|
|
void draw_esc_amps(uint8_t x, uint8_t y);
|
2018-07-01 12:57:11 -03:00
|
|
|
#endif
|
|
|
|
void draw_gps_latitude(uint8_t x, uint8_t y);
|
|
|
|
void draw_gps_longitude(uint8_t x, uint8_t y);
|
2018-07-09 19:49:03 -03:00
|
|
|
void draw_roll_angle(uint8_t x, uint8_t y);
|
|
|
|
void draw_pitch_angle(uint8_t x, uint8_t y);
|
2018-07-14 15:08:06 -03:00
|
|
|
void draw_temp(uint8_t x, uint8_t y);
|
2021-09-28 04:50:14 -03:00
|
|
|
#if BARO_MAX_INSTANCES > 1
|
2018-09-08 04:03:23 -03:00
|
|
|
void draw_btemp(uint8_t x, uint8_t y);
|
2021-09-28 04:50:14 -03:00
|
|
|
#endif
|
2018-08-07 20:13:39 -03:00
|
|
|
void draw_hdop(uint8_t x, uint8_t y);
|
2018-07-25 20:47:06 -03:00
|
|
|
void draw_waypoint(uint8_t x, uint8_t y);
|
|
|
|
void draw_xtrack_error(uint8_t x, uint8_t y);
|
2018-08-11 14:07:31 -03:00
|
|
|
void draw_dist(uint8_t x, uint8_t y);
|
|
|
|
void draw_stat(uint8_t x, uint8_t y);
|
2018-07-16 03:40:40 -03:00
|
|
|
void draw_flightime(uint8_t x, uint8_t y);
|
2018-08-16 20:26:49 -03:00
|
|
|
void draw_climbeff(uint8_t x, uint8_t y);
|
|
|
|
void draw_eff(uint8_t x, uint8_t y);
|
2018-08-23 12:46:35 -03:00
|
|
|
void draw_atemp(uint8_t x, uint8_t y);
|
|
|
|
void draw_bat2_vlt(uint8_t x, uint8_t y);
|
|
|
|
void draw_bat2used(uint8_t x, uint8_t y);
|
2019-10-04 16:20:51 -03:00
|
|
|
void draw_clk(uint8_t x, uint8_t y);
|
2020-11-12 03:49:08 -04:00
|
|
|
void draw_callsign(uint8_t x, uint8_t y);
|
2020-11-21 14:08:56 -04:00
|
|
|
void draw_current2(uint8_t x, uint8_t y);
|
2021-02-11 12:33:51 -04:00
|
|
|
void draw_vtx_power(uint8_t x, uint8_t y);
|
2021-03-05 13:12:43 -04:00
|
|
|
void draw_hgt_abvterr(uint8_t x, uint8_t y);
|
2022-07-19 08:33:12 -03:00
|
|
|
#if AP_FENCE_ENABLED
|
2021-04-29 11:42:38 -03:00
|
|
|
void draw_fence(uint8_t x, uint8_t y);
|
2022-03-04 12:39:00 -04:00
|
|
|
#endif
|
2021-05-26 17:50:51 -03:00
|
|
|
void draw_rngf(uint8_t x, uint8_t y);
|
2021-03-05 13:12:43 -04:00
|
|
|
|
2020-11-12 03:49:08 -04:00
|
|
|
struct {
|
|
|
|
bool load_attempted;
|
|
|
|
const char *str;
|
|
|
|
} callsign_data;
|
2018-06-24 07:00:23 -03:00
|
|
|
};
|
2020-10-19 17:30:08 -03:00
|
|
|
#endif // OSD_ENABLED
|
2018-06-24 07:00:23 -03:00
|
|
|
|
2020-04-18 17:16:02 -03:00
|
|
|
#if OSD_PARAM_ENABLED
|
|
|
|
/*
|
|
|
|
class to hold one setting
|
|
|
|
*/
|
2023-01-05 19:29:08 -04:00
|
|
|
class AP_OSD_ParamSetting
|
2020-04-18 17:16:02 -03:00
|
|
|
{
|
|
|
|
public:
|
2023-01-05 19:29:08 -04:00
|
|
|
|
|
|
|
AP_Int8 enabled;
|
|
|
|
AP_Int8 xpos;
|
|
|
|
AP_Int8 ypos;
|
|
|
|
|
2020-04-18 17:16:02 -03:00
|
|
|
// configured index.
|
|
|
|
AP_Int32 _param_group;
|
|
|
|
AP_Int16 _param_key;
|
|
|
|
AP_Int8 _param_idx;
|
|
|
|
// metadata
|
|
|
|
AP_Float _param_min;
|
|
|
|
AP_Float _param_max;
|
|
|
|
AP_Float _param_incr;
|
|
|
|
AP_Int8 _type;
|
|
|
|
|
|
|
|
// parameter number
|
|
|
|
uint8_t _param_number;
|
|
|
|
AP_Param* _param;
|
|
|
|
ap_var_type _param_type;
|
|
|
|
AP_Param::ParamToken _current_token;
|
|
|
|
|
|
|
|
// structure to contain setting constraints for important settings
|
|
|
|
struct ParamMetadata {
|
|
|
|
float min_value;
|
|
|
|
float max_value;
|
|
|
|
float increment;
|
|
|
|
uint8_t values_max;
|
|
|
|
const char** values;
|
|
|
|
};
|
2020-09-10 17:51:04 -03:00
|
|
|
// compact structure used to hold default values for static initialization
|
|
|
|
struct Initializer {
|
|
|
|
uint8_t index;
|
|
|
|
AP_Param::ParamToken token;
|
|
|
|
int8_t type;
|
|
|
|
};
|
2020-04-18 17:16:02 -03:00
|
|
|
|
|
|
|
static const ParamMetadata _param_metadata[];
|
|
|
|
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_ParamSetting() {};
|
2020-09-10 17:51:04 -03:00
|
|
|
AP_OSD_ParamSetting(uint8_t param_number);
|
|
|
|
AP_OSD_ParamSetting(const Initializer& initializer);
|
2020-04-18 17:16:02 -03:00
|
|
|
|
|
|
|
// initialize the setting from the configured information
|
|
|
|
void update();
|
2020-10-19 17:30:08 -03:00
|
|
|
// grab the parameter name
|
2021-02-01 12:26:32 -04:00
|
|
|
void copy_name(char* name, size_t len) const {
|
2020-10-19 17:30:08 -03:00
|
|
|
_param->copy_name_token(_current_token, name, len);
|
|
|
|
if (len > 16) name[16] = 0;
|
|
|
|
}
|
|
|
|
// copy the name converting FOO_BAR_BAZ to FooBarBaz
|
2021-02-01 12:26:32 -04:00
|
|
|
void copy_name_camel_case(char* name, size_t len) const;
|
2020-04-18 17:16:02 -03:00
|
|
|
// set the ranges from static metadata
|
|
|
|
bool set_from_metadata();
|
|
|
|
bool set_by_name(const char* name, uint8_t config_type, float pmin=0, float pmax=0, float pincr=0);
|
|
|
|
void guess_ranges(bool force = false);
|
|
|
|
void save_as_new();
|
|
|
|
|
|
|
|
const ParamMetadata* get_custom_metadata() const {
|
|
|
|
return (_type > 0 ? &_param_metadata[_type - 1] : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// User settable parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
private:
|
2023-01-11 09:32:00 -04:00
|
|
|
float default_enabled;
|
|
|
|
float default_ypos;
|
|
|
|
float default_param_group;
|
|
|
|
float default_param_idx;
|
|
|
|
float default_param_key;
|
|
|
|
float default_type;
|
|
|
|
|
2020-04-18 17:16:02 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
class to hold one screen of settings
|
|
|
|
*/
|
|
|
|
class AP_OSD_ParamScreen : public AP_OSD_AbstractScreen
|
|
|
|
{
|
|
|
|
public:
|
2020-09-10 17:51:04 -03:00
|
|
|
AP_OSD_ParamScreen(uint8_t index);
|
2020-04-18 17:16:02 -03:00
|
|
|
|
|
|
|
enum class Event {
|
|
|
|
NONE,
|
|
|
|
MENU_ENTER,
|
|
|
|
MENU_UP,
|
|
|
|
MENU_DOWN,
|
|
|
|
MENU_EXIT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class MenuState {
|
|
|
|
PARAM_SELECT,
|
|
|
|
PARAM_VALUE_MODIFY,
|
|
|
|
PARAM_PARAM_MODIFY
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t NUM_PARAMS = 9;
|
|
|
|
static const uint8_t SAVE_PARAM = NUM_PARAMS + 1;
|
|
|
|
|
2021-11-03 15:31:18 -03:00
|
|
|
#if OSD_ENABLED && (HAL_WITH_OSD_BITMAP || HAL_WITH_MSP_DISPLAYPORT)
|
2020-04-18 17:16:02 -03:00
|
|
|
void draw(void) override;
|
2020-10-19 17:30:08 -03:00
|
|
|
#endif
|
2021-09-17 10:37:20 -03:00
|
|
|
#if HAL_GCS_ENABLED
|
2022-11-08 00:23:10 -04:00
|
|
|
void handle_write_msg(const mavlink_osd_param_config_t& packet, const class GCS_MAVLINK& link);
|
|
|
|
void handle_read_msg(const mavlink_osd_param_show_config_t& packet, const class GCS_MAVLINK& link);
|
2021-09-17 10:37:20 -03:00
|
|
|
#endif
|
2020-10-19 17:30:08 -03:00
|
|
|
// get a setting and associated metadata
|
|
|
|
AP_OSD_ParamSetting* get_setting(uint8_t param_idx);
|
2020-04-18 17:16:02 -03:00
|
|
|
// Save button co-ordinates
|
|
|
|
AP_Int8 save_x;
|
|
|
|
AP_Int8 save_y;
|
|
|
|
|
|
|
|
// User settable parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
private:
|
2023-01-05 19:29:08 -04:00
|
|
|
AP_OSD_ParamSetting params[NUM_PARAMS];
|
2020-04-18 17:16:02 -03:00
|
|
|
|
2020-10-19 17:30:08 -03:00
|
|
|
void save_parameters();
|
|
|
|
#if OSD_ENABLED
|
2020-04-18 17:16:02 -03:00
|
|
|
void update_state_machine();
|
|
|
|
void draw_parameter(uint8_t param_number, uint8_t x, uint8_t y);
|
|
|
|
void modify_parameter(uint8_t number, Event ev);
|
|
|
|
void modify_configured_parameter(uint8_t number, Event ev);
|
|
|
|
|
|
|
|
Event map_rc_input_to_event() const;
|
|
|
|
RC_Channel::AuxSwitchPos get_channel_pos(uint8_t rcmapchan) const;
|
|
|
|
|
|
|
|
uint8_t _selected_param = 1;
|
|
|
|
MenuState _menu_state = MenuState::PARAM_SELECT;
|
|
|
|
Event _last_rc_event = Event::NONE;
|
|
|
|
|
|
|
|
// start time of the current button press
|
|
|
|
uint32_t _transition_start_ms;
|
|
|
|
// timeout of the current button press
|
|
|
|
uint32_t _transition_timeout_ms;
|
|
|
|
// number of consecutive times the current transition has happened
|
|
|
|
uint32_t _transition_count;
|
2020-10-19 17:30:08 -03:00
|
|
|
#endif
|
|
|
|
uint16_t _requires_save;
|
2020-04-18 17:16:02 -03:00
|
|
|
};
|
|
|
|
|
2020-10-19 17:30:08 -03:00
|
|
|
#endif // OSD_PARAM_ENABLED
|
2020-04-18 17:16:02 -03:00
|
|
|
|
2019-09-16 18:35:45 -03:00
|
|
|
class AP_OSD
|
|
|
|
{
|
2018-06-23 04:11:05 -03:00
|
|
|
public:
|
2018-07-25 20:47:06 -03:00
|
|
|
friend class AP_OSD_Screen;
|
2020-08-04 17:41:02 -03:00
|
|
|
friend class AP_MSP;
|
|
|
|
friend class AP_MSP_Telem_Backend;
|
2020-04-18 17:16:02 -03:00
|
|
|
friend class AP_OSD_ParamScreen;
|
2018-06-23 04:11:05 -03:00
|
|
|
//constructor
|
|
|
|
AP_OSD();
|
|
|
|
|
|
|
|
/* Do not allow copies */
|
2022-09-30 06:50:43 -03:00
|
|
|
CLASS_NO_COPY(AP_OSD);
|
2018-06-23 04:11:05 -03:00
|
|
|
|
2019-11-22 17:52:11 -04:00
|
|
|
// get singleton instance
|
|
|
|
static AP_OSD *get_singleton()
|
|
|
|
{
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2018-06-23 04:11:05 -03:00
|
|
|
// init - perform required initialisation
|
|
|
|
void init();
|
|
|
|
|
|
|
|
// User settable parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
enum osd_types {
|
|
|
|
OSD_NONE=0,
|
|
|
|
OSD_MAX7456=1,
|
2018-07-01 07:09:51 -03:00
|
|
|
OSD_SITL=2,
|
2020-08-04 17:41:02 -03:00
|
|
|
OSD_MSP=3,
|
2021-08-06 12:54:02 -03:00
|
|
|
OSD_TXONLY=4,
|
|
|
|
OSD_MSP_DISPLAYPORT=5
|
2018-06-24 07:00:23 -03:00
|
|
|
};
|
2018-06-29 17:14:09 -03:00
|
|
|
enum switch_method {
|
|
|
|
TOGGLE=0,
|
|
|
|
PWM_RANGE=1,
|
|
|
|
AUTO_SWITCH=2,
|
|
|
|
};
|
2018-06-25 18:26:21 -03:00
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
AP_Int8 osd_type;
|
2020-10-19 17:30:08 -03:00
|
|
|
AP_Int8 font_num;
|
|
|
|
AP_Int32 options;
|
|
|
|
|
|
|
|
#if OSD_ENABLED
|
2018-06-25 18:25:42 -03:00
|
|
|
AP_Int8 rc_channel;
|
2018-06-29 17:14:09 -03:00
|
|
|
AP_Int8 sw_method;
|
2018-06-23 04:11:05 -03:00
|
|
|
|
2018-07-05 17:31:16 -03:00
|
|
|
AP_Int8 v_offset;
|
|
|
|
AP_Int8 h_offset;
|
|
|
|
|
2018-07-05 19:31:01 -03:00
|
|
|
AP_Int8 warn_rssi;
|
|
|
|
AP_Int8 warn_nsat;
|
2021-03-05 13:12:43 -04:00
|
|
|
AP_Int32 warn_terr;
|
2021-03-22 12:03:42 -03:00
|
|
|
AP_Float warn_avgcellvolt;
|
|
|
|
AP_Float max_battery_voltage;
|
|
|
|
AP_Int8 cell_count;
|
|
|
|
AP_Float warn_restvolt;
|
2023-02-06 09:22:48 -04:00
|
|
|
AP_Float warn_avgcellrestvolt;
|
2018-07-05 19:31:01 -03:00
|
|
|
AP_Float warn_batvolt;
|
2018-08-23 12:46:35 -03:00
|
|
|
AP_Float warn_bat2volt;
|
2018-07-12 19:30:56 -03:00
|
|
|
AP_Int8 msgtime_s;
|
2019-03-01 08:54:36 -04:00
|
|
|
AP_Int8 arm_scr;
|
|
|
|
AP_Int8 disarm_scr;
|
|
|
|
AP_Int8 failsafe_scr;
|
2020-04-18 17:16:02 -03:00
|
|
|
AP_Int32 button_delay_ms;
|
2018-07-05 19:31:01 -03:00
|
|
|
|
2018-07-04 05:07:20 -03:00
|
|
|
enum {
|
|
|
|
OPTION_DECIMAL_PACK = 1U<<0,
|
2018-07-05 17:54:47 -03:00
|
|
|
OPTION_INVERTED_WIND = 1U<<1,
|
|
|
|
OPTION_INVERTED_AH_ROLL = 1U<<2,
|
2021-08-07 09:27:58 -03:00
|
|
|
OPTION_IMPERIAL_MILES = 1U<<3,
|
2021-07-28 05:56:02 -03:00
|
|
|
OPTION_DISABLE_CROSSHAIR = 1U<<4,
|
2023-03-27 12:23:25 -03:00
|
|
|
OPTION_BF_ARROWS = 1U<<5,
|
2018-07-04 05:07:20 -03:00
|
|
|
};
|
2018-07-05 17:31:16 -03:00
|
|
|
|
2018-07-08 19:32:29 -03:00
|
|
|
enum {
|
|
|
|
UNITS_METRIC=0,
|
|
|
|
UNITS_IMPERIAL=1,
|
2018-07-09 19:54:21 -03:00
|
|
|
UNITS_SI=2,
|
|
|
|
UNITS_AVIATION=3,
|
|
|
|
UNITS_LAST=4,
|
2018-07-08 19:32:29 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
AP_Int8 units;
|
|
|
|
|
2020-04-18 17:16:02 -03:00
|
|
|
AP_OSD_Screen screen[AP_OSD_NUM_DISPLAY_SCREENS];
|
2020-10-19 17:30:08 -03:00
|
|
|
|
2018-07-25 20:47:06 -03:00
|
|
|
struct NavInfo {
|
|
|
|
float wp_distance;
|
|
|
|
int32_t wp_bearing;
|
|
|
|
float wp_xtrack_error;
|
|
|
|
uint16_t wp_number;
|
|
|
|
};
|
|
|
|
|
2021-09-06 11:07:53 -03:00
|
|
|
struct StatsInfo {
|
|
|
|
uint32_t last_update_ms;
|
|
|
|
float last_distance_m;
|
|
|
|
float max_dist_m;
|
|
|
|
float max_alt_m;
|
|
|
|
float max_speed_mps;
|
|
|
|
float max_airspeed_mps;
|
|
|
|
float max_current_a;
|
|
|
|
float avg_current_a;
|
|
|
|
float min_voltage_v = FLT_MAX;
|
|
|
|
float min_rssi = FLT_MAX; // 0-1
|
|
|
|
int16_t max_esc_temp;
|
|
|
|
};
|
|
|
|
|
2018-07-25 20:47:06 -03:00
|
|
|
void set_nav_info(NavInfo &nav_info);
|
2021-09-06 11:07:53 -03:00
|
|
|
const volatile StatsInfo& get_stats_info() const {return _stats;};
|
2019-11-22 17:52:11 -04:00
|
|
|
// disable the display
|
|
|
|
void disable() {
|
|
|
|
_disable = true;
|
|
|
|
}
|
|
|
|
// enable the display
|
|
|
|
void enable() {
|
|
|
|
_disable = false;
|
|
|
|
}
|
2018-08-16 20:26:49 -03:00
|
|
|
|
2020-04-18 17:16:02 -03:00
|
|
|
AP_OSD_AbstractScreen& get_screen(uint8_t idx) {
|
|
|
|
#if OSD_PARAM_ENABLED
|
|
|
|
if (idx >= AP_OSD_NUM_DISPLAY_SCREENS) {
|
|
|
|
return param_screen[idx - AP_OSD_NUM_DISPLAY_SCREENS];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return screen[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether arming is allowed
|
|
|
|
bool pre_arm_check(char *failure_msg, const uint8_t failure_msg_len) const;
|
|
|
|
bool is_readonly_screen() const { return current_screen < AP_OSD_NUM_DISPLAY_SCREENS; }
|
2021-09-06 11:07:53 -03:00
|
|
|
// get the current screen
|
|
|
|
uint8_t get_current_screen() const { return current_screen; };
|
2020-10-19 17:30:08 -03:00
|
|
|
#endif // OSD_ENABLED
|
|
|
|
#if OSD_PARAM_ENABLED
|
|
|
|
AP_OSD_ParamScreen param_screen[AP_OSD_NUM_PARAM_SCREENS] { 0, 1 };
|
|
|
|
// return a setting for use by TX based OSD
|
|
|
|
AP_OSD_ParamSetting* get_setting(uint8_t screen_idx, uint8_t param_idx) {
|
|
|
|
if (screen_idx >= AP_OSD_NUM_PARAM_SCREENS) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return param_screen[screen_idx].get_setting(param_idx);
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-18 17:16:02 -03:00
|
|
|
// handle OSD parameter configuration
|
2021-09-17 10:37:20 -03:00
|
|
|
#if HAL_GCS_ENABLED
|
2022-11-08 00:23:10 -04:00
|
|
|
void handle_msg(const mavlink_message_t &msg, const class GCS_MAVLINK& link);
|
2021-09-17 10:37:20 -03:00
|
|
|
#endif
|
|
|
|
|
2021-09-06 11:07:53 -03:00
|
|
|
// allow threads to lock against OSD update
|
|
|
|
HAL_Semaphore &get_semaphore(void) {
|
|
|
|
return _sem;
|
|
|
|
}
|
2020-04-18 17:16:02 -03:00
|
|
|
|
2018-06-23 04:11:05 -03:00
|
|
|
private:
|
2018-07-06 20:30:53 -03:00
|
|
|
void osd_thread();
|
2020-10-19 17:30:08 -03:00
|
|
|
#if OSD_ENABLED
|
2018-06-23 04:11:05 -03:00
|
|
|
void update_osd();
|
2021-09-06 11:07:53 -03:00
|
|
|
void update_stats();
|
2018-06-25 18:25:42 -03:00
|
|
|
void update_current_screen();
|
2018-06-29 17:14:09 -03:00
|
|
|
void next_screen();
|
2019-09-16 18:35:45 -03:00
|
|
|
|
2018-06-29 17:14:09 -03:00
|
|
|
//variables for screen switching
|
2018-06-24 07:00:23 -03:00
|
|
|
uint8_t current_screen;
|
2018-06-29 17:14:09 -03:00
|
|
|
uint16_t previous_channel_value;
|
|
|
|
bool switch_debouncer;
|
|
|
|
uint32_t last_switch_ms;
|
2018-07-25 20:47:06 -03:00
|
|
|
struct NavInfo nav_info;
|
2019-03-01 08:54:36 -04:00
|
|
|
int8_t previous_pwm_screen;
|
|
|
|
int8_t pre_fs_screen;
|
|
|
|
bool was_armed;
|
|
|
|
bool was_failsafe;
|
2019-11-22 17:52:11 -04:00
|
|
|
bool _disable;
|
2019-09-16 18:35:45 -03:00
|
|
|
|
2021-09-06 11:07:53 -03:00
|
|
|
StatsInfo _stats;
|
2020-10-19 17:30:08 -03:00
|
|
|
#endif
|
|
|
|
AP_OSD_Backend *backend;
|
2019-11-22 17:52:11 -04:00
|
|
|
|
|
|
|
static AP_OSD *_singleton;
|
2021-09-06 11:07:53 -03:00
|
|
|
// multi-thread access support
|
|
|
|
HAL_Semaphore _sem;
|
2019-11-22 17:52:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace AP
|
|
|
|
{
|
|
|
|
AP_OSD *osd();
|
2018-06-23 04:11:05 -03:00
|
|
|
};
|