slcd.hxx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /////////////////////////////////////////////////////////////////////////////
  2. // apps/include/graphics/slcd.hxx
  3. //
  4. // Licensed to the Apache Software Foundation (ASF) under one or more
  5. // contributor license agreements. See the NOTICE file distributed with
  6. // this work for additional information regarding copyright ownership. The
  7. // ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. // "License"); you may not use this file except in compliance with the
  9. // License. You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. // License for the specific language governing permissions and limitations
  17. // under the License.
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #ifndef __APPS_INCLUDE_GRAPHICS_SLCD_H
  21. #define __APPS_INCLUDE_GRAPHICS_SLCD_H
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Included Files
  24. /////////////////////////////////////////////////////////////////////////////
  25. #include <fixedmath.h>
  26. #include <nuttx/nx/nxglib.h>
  27. #include "graphics/nxwidgets/nxconfig.hxx"
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Pre-processor definitions
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Segment
  32. //
  33. // 11111111
  34. // 2 3
  35. // 2 3
  36. // 2 3
  37. // 44444444
  38. // 5 6
  39. // 5 6
  40. // 5 6
  41. // 77777777
  42. // Number of trapezoids in each segment
  43. #define NTOP_TRAPEZOIDS 3
  44. #define NTOPLEFT_TRAPEZOIDS 5
  45. #define NTOPRIGHT_TRAPEZOIDS 5
  46. #define NMIDDLE_TRAPEZOIDS 2
  47. #define NBOTTOMLEFT_TRAPEZOIDS 4
  48. #define NBOTTOMRIGHT_TRAPEZOIDS 5
  49. #define NBOTTOM_TRAPEZOIDS 2
  50. // Clock colors: Light grey-green background, greenish-black foreground.
  51. // Similar to what you would see on a classic LCD.
  52. #define SLCD_BACKGROUND MKRGB(128, 140, 128)
  53. #define SLCD_FOREGROUND MKRGB(0, 16, 0)
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CSLcd Implementation Class
  56. /////////////////////////////////////////////////////////////////////////////
  57. namespace NXWidgets
  58. {
  59. class INxWindow; // Forward Reference
  60. }
  61. namespace SLcd
  62. {
  63. class CSLcd
  64. {
  65. private:
  66. FAR NXWidgets::INxWindow *m_window; /**< Drawing window */
  67. nxgl_coord_t m_height;
  68. // Scaled trapezoids
  69. struct nxgl_trapezoid_s m_top[NTOP_TRAPEZOIDS];
  70. struct nxgl_trapezoid_s m_topLeft[NTOPLEFT_TRAPEZOIDS];
  71. struct nxgl_trapezoid_s m_topRight[NTOPRIGHT_TRAPEZOIDS];
  72. struct nxgl_trapezoid_s m_middle[NMIDDLE_TRAPEZOIDS];
  73. struct nxgl_trapezoid_s m_bottomLeft[NBOTTOMLEFT_TRAPEZOIDS];
  74. struct nxgl_trapezoid_s m_bottomRight[NBOTTOMRIGHT_TRAPEZOIDS];
  75. struct nxgl_trapezoid_s m_bottom[NBOTTOM_TRAPEZOIDS];
  76. /**
  77. * Created scaled trapezoids for the specified height
  78. *
  79. * @param run A pointer to the beginning of an array of runs
  80. * @param trapezoid A pointer to a trapezoid array to catch the
  81. * output
  82. * @param nRuns The number of runs in the array. The number of
  83. * trapezoids will be be nRuns - 1;
  84. */
  85. void scaleSegment(FAR const struct SLcdTrapezoidRun *run,
  86. FAR struct nxgl_trapezoid_s *trapezoid,
  87. int nRuns);
  88. /**
  89. * Rend one segment of the SLCD image in the window at the provided
  90. * position.
  91. *
  92. * @param trapezoid A pointer to the trapezoid array to show.
  93. * @param pos The offset position of the SLCD image in the window
  94. * @param nTraps The number of trapezoids in the the array
  95. */
  96. void showSegment(FAR const struct nxgl_trapezoid_s *trapezoid,
  97. FAR const struct nxgl_point_s &pos,
  98. int nTraps);
  99. public:
  100. /**
  101. * CSLcd Constructor
  102. *
  103. * @param wnd Identifies the window to draw into
  104. * @param height The initial height of the SLCD image
  105. */
  106. CSLcd(NXWidgets::INxWindow *wnd, nxgl_coord_t height);
  107. /**
  108. * CSLcd Destructor
  109. */
  110. inline ~CSLcd(void)
  111. {
  112. }
  113. /**
  114. * Created scaled trapezoids for the specified height
  115. *
  116. * @param height The height of the SLCD image
  117. */
  118. void scale(nxgl_coord_t height);
  119. /**
  120. * Get the SLcd image height
  121. *
  122. * @return The height of the SLCD image (in rows)
  123. */
  124. inline nxgl_coord_t getHeight(void)
  125. {
  126. return m_height;
  127. }
  128. /**
  129. * Get the SLcd image width. No since the images are
  130. * slight slanted, this includes some minimal intra-image
  131. * spacing
  132. *
  133. * @return The width of the SLCD image (in pixels)
  134. */
  135. nxgl_coord_t getWidth(void);
  136. /**
  137. * Erase the SLCD image at this position
  138. *
  139. * @param pos The upper left position of the SLCD image
  140. */
  141. void erase(FAR const nxgl_point_s &pos);
  142. /**
  143. * Return a the code associated with this ASCII character
  144. *
  145. * @param ch The ASCII encoded character to be converted
  146. * @param code The location to return the code
  147. * @return True if the character can be represented
  148. */
  149. bool convert(char ch, FAR uint8_t &code);
  150. /* Show the SCLD image at the provided position on the
  151. * display.
  152. *
  153. * @param code The encode value that describes the SLCD image
  154. * @param pos The location to show the SLCD image in the window
  155. * @return True if the display update was successfully queued
  156. */
  157. bool show(uint8_t code, FAR const struct nxgl_point_s &pos);
  158. };
  159. }
  160. #endif /* __APPS_INCLUDE_GRAPHICS_SLCD_H */