Subversion Repositories libOLED

Rev

Rev 16 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ///
  2. /// Dial drawing library : used to display anything from compass display to arcs of "meter" displays
  3. ///
  4. #pragma once
  5. #include <cstdint>
  6.  
  7. namespace
  8. {
  9.   constexpr unsigned DEFAULT_WIDTH = 3;
  10. }
  11.  
  12. class displayDial_t
  13. {
  14. public:
  15.   /// \param display the parent display
  16.   /// \param x x pos
  17.   /// \param y y pos
  18.   /// \param siz = size
  19.   /// \param angle Angle from straight up for lowest (-angle) and highest (angle) reading
  20.   displayDial_t(display_t &display,
  21.                 uint8_t x,
  22.                 uint8_t y,
  23.                 uint8_t siz,
  24.                 uint16_t angle = 90);
  25.  
  26.   /// @brief Construct a display with angle from Angle high to angle low
  27.   /// @param display
  28.   /// @param x
  29.   /// @param y
  30.   /// @param siz
  31.   /// @param angle_high Angle relative to straight up for highest reading
  32.   /// @param angle_low Angle relative to straight up for lowest reading
  33.   displayDial_t(display_t &display,
  34.                 uint8_t x,
  35.                 uint8_t y,
  36.                 uint8_t siz,
  37.                 int16_t angle_low,
  38.                 int16_t angle_high);
  39.  
  40.   /// @brief  Put the dial needle on the display
  41.   /// @param position values are from  0 .. math.SINE_STEPS
  42.   void draw_needle(int16_t position);
  43.  
  44.   /// @brief draw the scale
  45.   /// \param low low end of range
  46.   /// \param high high end of range
  47.   /// \param width length of long marker
  48.   /// \param num_step number of ticks
  49.   /// \param scale
  50.   void draw_scale(int16_t low, int16_t high, uint8_t width, uint8_t num_step, int16_t scale);
  51.  
  52.   /// @brief print min/max limits and print the title
  53.   virtual void draw_limits(){};
  54.  
  55.   /// @brief Draw value on display
  56.   /// @param val integer value to show with fake decimal point
  57.   /// @param dp  decimal point code
  58.   /// @param width number of digits plus sign
  59.   virtual void draw_value(int val, int dp, int width= DEFAULT_WIDTH){};
  60.  
  61.   /// @brief Set units string on display
  62.   /// @param str Constant string to refer to
  63.   void set_units(char const *str){m_unitStr = str; };
  64.  
  65.   /// @brief Set title on the screen
  66.   /// @param str Constant string to display
  67.   void set_title(char const * str){m_titleStr = str; };
  68.  
  69. protected:
  70.  
  71.   void draw_value_items(int val, int dpCode, int wid,  int x , int y );
  72.  
  73.  
  74.   display_t &m_display;
  75.   uint8_t const m_xo;         ///< Position of origin
  76.   uint8_t const m_yo;         ///< Position of origin
  77.   uint8_t const m_siz;        ///< Display size
  78.   int16_t const m_angleLow;   ///< Angle for lowest value
  79.   int16_t const m_angleRange; ///< Angle range from lowest to highest  value
  80.   int16_t m_low;              ///< lower scale limit
  81.   int16_t m_high;             ///< upper scale limit
  82.   char const * m_unitStr;     ///< Units_string
  83.   char const * m_titleStr;    ///< Title_string
  84. };
  85.  
  86. //////////////////////////////////////////////////
  87. /// A display using the whole graphics area, 180 degree sweep
  88. class displayFullDial_t : public displayDial_t
  89. {
  90. public:
  91.   /// @brief Constructor for full-screen display
  92.   /// @param display The display it is being shown on
  93.   displayFullDial_t(display_t &display);
  94.  
  95.   /// @brief  draw axes limits
  96.   virtual void draw_limits() final;
  97.  
  98.   /// @brief Draw value on display
  99.   /// @param val integer value to show with fake decimal point
  100.   /// @param dp  decimal point code
  101.   virtual void draw_value(int val, int dp, int width= DEFAULT_WIDTH) final;
  102.  
  103.  
  104. };
  105.  
  106. //////////////////////////////////////////////////
  107. /// A display using left hand side of graphics area, 90 degree quadrant
  108. class displayLeftQuadrantDial_t : public displayDial_t
  109. {
  110. public:
  111.   /// @brief Constructor for left quadrant display
  112.   /// @param display The display it is being shown on
  113.   displayLeftQuadrantDial_t(display_t &display);
  114.  
  115.   /// @brief  draw axes limits
  116.   virtual void draw_limits() final;
  117.  
  118.   /// @brief Draw value on display
  119.   /// @param val integer value to show with fake decimal point
  120.   /// @param dp  decimal point code
  121.   virtual void draw_value(int val, int dp,int width= DEFAULT_WIDTH) final;
  122.  
  123.  
  124. };
  125.  
  126. //////////////////////////////////////////////////
  127. /// A display using right hand side of graphics area, 90 degree quadrant
  128. class displayRightQuadrantDial_t : public displayDial_t
  129. {
  130. public:
  131.   /// @brief Constructor for right quadrant display
  132.   /// @param display The display it is being shown on
  133.   displayRightQuadrantDial_t(display_t &display);
  134.   /// @brief  draw axes limits
  135.   virtual void draw_limits() final;
  136.  
  137.   /// @brief Draw value on display
  138.   /// @param val integer value to show with fake decimal point
  139.   /// @param dp  decimal point code
  140.   virtual void draw_value(int val, int dp,int width = DEFAULT_WIDTH) final;
  141.  
  142.  
  143. };