AP_OSD_SITL.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifdef WITH_SITL_OSD
  18. #include <AP_OSD/AP_OSD_Backend.h>
  19. #ifdef HAVE_SFML_GRAPHICS_H
  20. #include <SFML/Graphics.h>
  21. #else
  22. #include <SFML/Graphics.hpp>
  23. #endif
  24. class AP_OSD_SITL : public AP_OSD_Backend {
  25. public:
  26. static AP_OSD_Backend *probe(AP_OSD &osd);
  27. //draw given text to framebuffer
  28. void write(uint8_t x, uint8_t y, const char* text) override;
  29. //initilize display port and underlying hardware
  30. bool init() override;
  31. //flush framebuffer to screen
  32. void flush() override;
  33. //clear framebuffer
  34. void clear() override;
  35. private:
  36. //constructor
  37. AP_OSD_SITL(AP_OSD &osd);
  38. sf::RenderWindow *w;
  39. sf::Texture font[256];
  40. uint8_t last_font;
  41. // setup to match MAX7456 layout
  42. static const uint8_t char_width = 12;
  43. static const uint8_t char_height = 18;
  44. static const uint8_t video_lines = 16; // PAL
  45. static const uint8_t video_cols = 30;
  46. static const uint8_t char_spacing = 0;
  47. // scaling factor to make it easier to read
  48. static const uint8_t char_scale = 2;
  49. uint8_t buffer[video_lines][video_cols];
  50. void update_thread();
  51. static void *update_thread_start(void *obj);
  52. void load_font();
  53. pthread_t thread;
  54. HAL_Semaphore mutex;
  55. uint32_t counter;
  56. uint32_t last_counter;
  57. };
  58. #endif // WITH_SITL_OSD