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
|
|
|
|
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2018-06-29 17:14:09 -03:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2018-07-01 12:57:11 -03:00
|
|
|
#include <AP_BLHeli/AP_BLHeli.h>
|
2018-06-23 04:11:05 -03:00
|
|
|
|
|
|
|
class AP_OSD_Backend;
|
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
#define AP_OSD_NUM_SCREENS 4
|
|
|
|
|
|
|
|
/*
|
|
|
|
class to hold one setting
|
|
|
|
*/
|
|
|
|
class AP_OSD_Setting {
|
|
|
|
public:
|
|
|
|
AP_Int8 enabled;
|
|
|
|
AP_Int8 xpos;
|
|
|
|
AP_Int8 ypos;
|
|
|
|
|
|
|
|
AP_OSD_Setting(bool enabled, uint8_t x, uint8_t y);
|
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[];
|
|
|
|
};
|
|
|
|
|
2018-07-05 17:54:47 -03:00
|
|
|
class AP_OSD;
|
2018-06-24 07:00:23 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
class to hold one screen of settings
|
|
|
|
*/
|
|
|
|
class AP_OSD_Screen {
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
AP_OSD_Screen();
|
2018-06-25 18:26:21 -03:00
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw(void);
|
|
|
|
|
2018-07-08 19:32:29 -03:00
|
|
|
void set_backend(AP_OSD_Backend *_backend);
|
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[];
|
2018-06-24 07:45:58 -03:00
|
|
|
|
|
|
|
AP_Int8 enabled;
|
2018-06-25 18:25:42 -03:00
|
|
|
AP_Int16 channel_min;
|
|
|
|
AP_Int16 channel_max;
|
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
private:
|
|
|
|
AP_OSD_Backend *backend;
|
2018-07-05 17:54:47 -03:00
|
|
|
AP_OSD *osd;
|
2018-06-24 07:00:23 -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);
|
|
|
|
|
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};
|
|
|
|
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};
|
|
|
|
AP_OSD_Setting vspeed{true, 24, 9};
|
2018-07-05 17:31:16 -03:00
|
|
|
|
2018-07-01 12:57:11 -03:00
|
|
|
#ifdef HAVE_AP_BLHELI_SUPPORT
|
2018-07-05 17:31:16 -03:00
|
|
|
AP_OSD_Setting blh_temp {false, 24, 13};
|
2018-07-05 16:57:16 -03:00
|
|
|
AP_OSD_Setting blh_rpm{false, 22, 12};
|
|
|
|
AP_OSD_Setting blh_amps{false, 24, 14};
|
2018-07-01 12:57:11 -03:00
|
|
|
#endif
|
2018-07-05 17:31:16 -03:00
|
|
|
|
2018-07-05 16:57:16 -03:00
|
|
|
AP_OSD_Setting gps_latitude{true, 9, 13};
|
|
|
|
AP_OSD_Setting gps_longitude{true, 9, 14};
|
2018-07-09 19:49:03 -03:00
|
|
|
AP_OSD_Setting roll_angle{false, 0, 0};
|
|
|
|
AP_OSD_Setting pitch_angle{false, 0, 0};
|
2018-07-14 15:08:06 -03:00
|
|
|
AP_OSD_Setting temp{false, 0, 0};
|
2018-08-07 20:13:39 -03:00
|
|
|
AP_OSD_Setting hdop{false, 0, 0};
|
2018-07-25 20:47:06 -03:00
|
|
|
AP_OSD_Setting waypoint{false, 0, 0};
|
|
|
|
AP_OSD_Setting xtrack_error{false, 0, 0};
|
2018-08-11 14:07:31 -03:00
|
|
|
AP_OSD_Setting dist{false,22,11};
|
|
|
|
AP_OSD_Setting stat{false,0,0};
|
2018-06-25 18:26:21 -03:00
|
|
|
|
2018-07-08 19:32:29 -03:00
|
|
|
bool check_option(uint32_t option);
|
|
|
|
|
2018-07-09 19:01:17 -03:00
|
|
|
enum unit_type {
|
|
|
|
ALTITUDE=0,
|
|
|
|
SPEED=1,
|
|
|
|
VSPEED=2,
|
|
|
|
DISTANCE=3,
|
|
|
|
DISTANCE_LONG=4,
|
|
|
|
TEMPERATURE=5,
|
|
|
|
UNIT_TYPE_LAST=6,
|
|
|
|
};
|
2018-07-11 19:13:44 -03:00
|
|
|
|
2018-07-09 19:01:17 -03:00
|
|
|
char u_icon(enum unit_type unit);
|
|
|
|
float u_scale(enum unit_type unit, float value);
|
2018-07-08 19:32:29 -03:00
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
void draw_altitude(uint8_t x, uint8_t y);
|
|
|
|
void draw_bat_volt(uint8_t x, uint8_t y);
|
|
|
|
void draw_rssi(uint8_t x, uint8_t y);
|
|
|
|
void draw_current(uint8_t x, uint8_t y);
|
|
|
|
void draw_batused(uint8_t x, uint8_t y);
|
|
|
|
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);
|
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);
|
|
|
|
void draw_vspeed(uint8_t x, uint8_t y);
|
2018-07-03 18:50:05 -03:00
|
|
|
|
2018-07-08 19:32:29 -03:00
|
|
|
//helper functions
|
2018-07-04 02:03:17 -03:00
|
|
|
void draw_speed_vector(uint8_t x, uint8_t y, Vector2f v, int32_t yaw);
|
2018-07-08 19:32:29 -03:00
|
|
|
void draw_distance(uint8_t x, uint8_t y, float distance);
|
2018-07-01 12:57:11 -03:00
|
|
|
|
|
|
|
#ifdef HAVE_AP_BLHELI_SUPPORT
|
|
|
|
void draw_blh_temp(uint8_t x, uint8_t y);
|
|
|
|
void draw_blh_rpm(uint8_t x, uint8_t y);
|
|
|
|
void draw_blh_amps(uint8_t x, uint8_t y);
|
|
|
|
#endif
|
2018-07-05 17:31:16 -03:00
|
|
|
|
2018-07-01 12:57:11 -03:00
|
|
|
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);
|
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-06-24 07:00:23 -03:00
|
|
|
};
|
|
|
|
|
2018-06-23 04:11:05 -03:00
|
|
|
class AP_OSD {
|
|
|
|
public:
|
2018-07-25 20:47:06 -03:00
|
|
|
friend class AP_OSD_Screen;
|
2018-06-23 04:11:05 -03:00
|
|
|
//constructor
|
|
|
|
AP_OSD();
|
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_OSD(const AP_OSD &other) = delete;
|
|
|
|
AP_OSD &operator=(const AP_OSD&) = delete;
|
|
|
|
|
|
|
|
// 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,
|
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;
|
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-07-09 05:08:47 -03:00
|
|
|
AP_Int8 font_num;
|
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;
|
|
|
|
AP_Float warn_batvolt;
|
2018-07-12 19:30:56 -03:00
|
|
|
AP_Int8 msgtime_s;
|
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,
|
2018-07-04 05:07:20 -03:00
|
|
|
};
|
2018-07-05 17:31:16 -03:00
|
|
|
|
2018-07-04 05:07:20 -03:00
|
|
|
AP_Int32 options;
|
|
|
|
|
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;
|
|
|
|
|
2018-06-24 07:00:23 -03:00
|
|
|
AP_OSD_Screen screen[AP_OSD_NUM_SCREENS];
|
2018-06-23 04:11:05 -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;
|
|
|
|
};
|
|
|
|
|
|
|
|
void set_nav_info(NavInfo &nav_info);
|
|
|
|
|
2018-06-23 04:11:05 -03:00
|
|
|
private:
|
2018-07-06 20:30:53 -03:00
|
|
|
void osd_thread();
|
2018-06-23 04:11:05 -03:00
|
|
|
void update_osd();
|
2018-08-11 14:07:31 -03:00
|
|
|
void stats();
|
2018-06-25 18:25:42 -03:00
|
|
|
void update_current_screen();
|
2018-06-29 17:14:09 -03:00
|
|
|
void next_screen();
|
2018-06-23 04:11:05 -03:00
|
|
|
AP_OSD_Backend *backend;
|
2018-08-11 14:07:31 -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;
|
2018-08-11 14:07:31 -03:00
|
|
|
|
|
|
|
uint32_t last_update_ms;
|
|
|
|
float last_distance_m;
|
|
|
|
float max_dist_m;
|
|
|
|
float max_alt_m;
|
|
|
|
float max_speed_mps;
|
|
|
|
float max_current_a;
|
2018-06-23 04:11:05 -03:00
|
|
|
};
|