AP_OSD.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. */
  16. #pragma once
  17. #include <AP_Param/AP_Param.h>
  18. #include <AP_Math/AP_Math.h>
  19. #include <AP_BLHeli/AP_BLHeli.h>
  20. class AP_OSD_Backend;
  21. #define AP_OSD_NUM_SCREENS 4
  22. /*
  23. class to hold one setting
  24. */
  25. class AP_OSD_Setting {
  26. public:
  27. AP_Int8 enabled;
  28. AP_Int8 xpos;
  29. AP_Int8 ypos;
  30. AP_OSD_Setting(bool enabled, uint8_t x, uint8_t y);
  31. // User settable parameters
  32. static const struct AP_Param::GroupInfo var_info[];
  33. };
  34. class AP_OSD;
  35. /*
  36. class to hold one screen of settings
  37. */
  38. class AP_OSD_Screen {
  39. public:
  40. // constructor
  41. AP_OSD_Screen();
  42. void draw(void);
  43. void set_backend(AP_OSD_Backend *_backend);
  44. // User settable parameters
  45. static const struct AP_Param::GroupInfo var_info[];
  46. AP_Int8 enabled;
  47. AP_Int16 channel_min;
  48. AP_Int16 channel_max;
  49. private:
  50. AP_OSD_Backend *backend;
  51. AP_OSD *osd;
  52. static const uint8_t message_visible_width = 26;
  53. static const uint8_t message_scroll_time_ms = 200;
  54. static const uint8_t message_scroll_delay = 5;
  55. static constexpr float ah_max_pitch = DEG_TO_RAD * 20;
  56. //typical fpv camera has 80deg vertical field of view, 16 row of chars
  57. static constexpr float ah_pitch_rad_to_char = 16.0f/(DEG_TO_RAD * 80);
  58. AP_OSD_Setting altitude{true, 23, 8};
  59. AP_OSD_Setting bat_volt{true, 24, 1};
  60. AP_OSD_Setting rssi{true, 1, 1};
  61. AP_OSD_Setting current{true, 25, 2};
  62. AP_OSD_Setting batused{true, 23, 3};
  63. AP_OSD_Setting sats{true, 1, 3};
  64. AP_OSD_Setting fltmode{true, 2, 8};
  65. AP_OSD_Setting message{true, 2, 6};
  66. AP_OSD_Setting gspeed{true, 2, 14};
  67. AP_OSD_Setting horizon{true, 14, 8};
  68. AP_OSD_Setting home{true, 14, 1};
  69. AP_OSD_Setting throttle{true, 24, 11};
  70. AP_OSD_Setting heading{true, 13, 2};
  71. AP_OSD_Setting compass{true, 15, 3};
  72. AP_OSD_Setting wind{false, 2, 12};
  73. AP_OSD_Setting aspeed{false, 2, 13};
  74. AP_OSD_Setting aspd1{false, 0, 0};
  75. AP_OSD_Setting aspd2{false, 0, 0};
  76. AP_OSD_Setting vspeed{true, 24, 9};
  77. #ifdef HAVE_AP_BLHELI_SUPPORT
  78. AP_OSD_Setting blh_temp {false, 24, 13};
  79. AP_OSD_Setting blh_rpm{false, 22, 12};
  80. AP_OSD_Setting blh_amps{false, 24, 14};
  81. #endif
  82. AP_OSD_Setting gps_latitude{true, 9, 13};
  83. AP_OSD_Setting gps_longitude{true, 9, 14};
  84. AP_OSD_Setting roll_angle{false, 0, 0};
  85. AP_OSD_Setting pitch_angle{false, 0, 0};
  86. AP_OSD_Setting temp{false, 0, 0};
  87. AP_OSD_Setting btemp{false, 0, 0};
  88. AP_OSD_Setting hdop{false, 0, 0};
  89. AP_OSD_Setting waypoint{false, 0, 0};
  90. AP_OSD_Setting xtrack_error{false, 0, 0};
  91. AP_OSD_Setting dist{false,22,11};
  92. AP_OSD_Setting stat{false,0,0};
  93. AP_OSD_Setting flightime{false, 23, 10};
  94. AP_OSD_Setting climbeff{false,0,0};
  95. AP_OSD_Setting eff{false, 22, 10};
  96. AP_OSD_Setting atemp{false, 0, 0};
  97. AP_OSD_Setting bat2_vlt{false, 0, 0};
  98. AP_OSD_Setting bat2used{false, 0, 0};
  99. bool check_option(uint32_t option);
  100. enum unit_type {
  101. ALTITUDE=0,
  102. SPEED=1,
  103. VSPEED=2,
  104. DISTANCE=3,
  105. DISTANCE_LONG=4,
  106. TEMPERATURE=5,
  107. UNIT_TYPE_LAST=6,
  108. };
  109. char u_icon(enum unit_type unit);
  110. float u_scale(enum unit_type unit, float value);
  111. void draw_altitude(uint8_t x, uint8_t y);
  112. void draw_bat_volt(uint8_t x, uint8_t y);
  113. void draw_rssi(uint8_t x, uint8_t y);
  114. void draw_current(uint8_t x, uint8_t y);
  115. void draw_batused(uint8_t x, uint8_t y);
  116. void draw_batused(uint8_t instance, uint8_t x, uint8_t y);
  117. void draw_sats(uint8_t x, uint8_t y);
  118. void draw_fltmode(uint8_t x, uint8_t y);
  119. void draw_message(uint8_t x, uint8_t y);
  120. void draw_gspeed(uint8_t x, uint8_t y);
  121. void draw_horizon(uint8_t x, uint8_t y);
  122. void draw_home(uint8_t x, uint8_t y);
  123. void draw_throttle(uint8_t x, uint8_t y);
  124. void draw_heading(uint8_t x, uint8_t y);
  125. void draw_compass(uint8_t x, uint8_t y);
  126. void draw_wind(uint8_t x, uint8_t y);
  127. void draw_aspeed(uint8_t x, uint8_t y);
  128. void draw_aspd1(uint8_t x, uint8_t y);
  129. void draw_aspd2(uint8_t x, uint8_t y);
  130. void draw_vspeed(uint8_t x, uint8_t y);
  131. //helper functions
  132. void draw_speed_vector(uint8_t x, uint8_t y, Vector2f v, int32_t yaw);
  133. void draw_distance(uint8_t x, uint8_t y, float distance);
  134. #ifdef HAVE_AP_BLHELI_SUPPORT
  135. void draw_blh_temp(uint8_t x, uint8_t y);
  136. void draw_blh_rpm(uint8_t x, uint8_t y);
  137. void draw_blh_amps(uint8_t x, uint8_t y);
  138. #endif
  139. void draw_gps_latitude(uint8_t x, uint8_t y);
  140. void draw_gps_longitude(uint8_t x, uint8_t y);
  141. void draw_roll_angle(uint8_t x, uint8_t y);
  142. void draw_pitch_angle(uint8_t x, uint8_t y);
  143. void draw_temp(uint8_t x, uint8_t y);
  144. void draw_btemp(uint8_t x, uint8_t y);
  145. void draw_hdop(uint8_t x, uint8_t y);
  146. void draw_waypoint(uint8_t x, uint8_t y);
  147. void draw_xtrack_error(uint8_t x, uint8_t y);
  148. void draw_dist(uint8_t x, uint8_t y);
  149. void draw_stat(uint8_t x, uint8_t y);
  150. void draw_flightime(uint8_t x, uint8_t y);
  151. void draw_climbeff(uint8_t x, uint8_t y);
  152. void draw_eff(uint8_t x, uint8_t y);
  153. void draw_atemp(uint8_t x, uint8_t y);
  154. void draw_bat2_vlt(uint8_t x, uint8_t y);
  155. void draw_bat2used(uint8_t x, uint8_t y);
  156. };
  157. class AP_OSD {
  158. public:
  159. friend class AP_OSD_Screen;
  160. //constructor
  161. AP_OSD();
  162. /* Do not allow copies */
  163. AP_OSD(const AP_OSD &other) = delete;
  164. AP_OSD &operator=(const AP_OSD&) = delete;
  165. // init - perform required initialisation
  166. void init();
  167. // User settable parameters
  168. static const struct AP_Param::GroupInfo var_info[];
  169. enum osd_types {
  170. OSD_NONE=0,
  171. OSD_MAX7456=1,
  172. OSD_SITL=2,
  173. };
  174. enum switch_method {
  175. TOGGLE=0,
  176. PWM_RANGE=1,
  177. AUTO_SWITCH=2,
  178. };
  179. AP_Int8 osd_type;
  180. AP_Int8 rc_channel;
  181. AP_Int8 sw_method;
  182. AP_Int8 font_num;
  183. AP_Int8 v_offset;
  184. AP_Int8 h_offset;
  185. AP_Int8 warn_rssi;
  186. AP_Int8 warn_nsat;
  187. AP_Float warn_batvolt;
  188. AP_Float warn_bat2volt;
  189. AP_Int8 msgtime_s;
  190. AP_Int8 arm_scr;
  191. AP_Int8 disarm_scr;
  192. AP_Int8 failsafe_scr;
  193. enum {
  194. OPTION_DECIMAL_PACK = 1U<<0,
  195. OPTION_INVERTED_WIND = 1U<<1,
  196. OPTION_INVERTED_AH_ROLL = 1U<<2,
  197. };
  198. AP_Int32 options;
  199. enum {
  200. UNITS_METRIC=0,
  201. UNITS_IMPERIAL=1,
  202. UNITS_SI=2,
  203. UNITS_AVIATION=3,
  204. UNITS_LAST=4,
  205. };
  206. AP_Int8 units;
  207. AP_OSD_Screen screen[AP_OSD_NUM_SCREENS];
  208. struct NavInfo {
  209. float wp_distance;
  210. int32_t wp_bearing;
  211. float wp_xtrack_error;
  212. uint16_t wp_number;
  213. };
  214. void set_nav_info(NavInfo &nav_info);
  215. private:
  216. void osd_thread();
  217. void update_osd();
  218. void stats();
  219. void update_current_screen();
  220. void next_screen();
  221. AP_OSD_Backend *backend;
  222. //variables for screen switching
  223. uint8_t current_screen;
  224. uint16_t previous_channel_value;
  225. bool switch_debouncer;
  226. uint32_t last_switch_ms;
  227. struct NavInfo nav_info;
  228. int8_t previous_pwm_screen;
  229. int8_t pre_fs_screen;
  230. bool was_armed;
  231. bool was_failsafe;
  232. uint32_t last_update_ms;
  233. float last_distance_m;
  234. float max_dist_m;
  235. float max_alt_m;
  236. float max_speed_mps;
  237. float max_current_a;
  238. };