lcd.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //! @file
  2. #ifndef _LCD_H
  3. #define _LCD_H
  4. #include <inttypes.h>
  5. #include <stdio.h>
  6. #include "Timer.h"
  7. extern FILE _lcdout;
  8. #define lcdout (&_lcdout)
  9. extern void lcd_init(void);
  10. extern void lcd_refresh(void);
  11. extern void lcd_refresh_noclear(void);
  12. extern void lcd_clear(void);
  13. extern void lcd_home(void);
  14. /*extern void lcd_no_display(void);
  15. extern void lcd_display(void);
  16. extern void lcd_no_blink(void);
  17. extern void lcd_blink(void);
  18. extern void lcd_no_cursor(void);
  19. extern void lcd_cursor(void);
  20. extern void lcd_scrollDisplayLeft(void);
  21. extern void lcd_scrollDisplayRight(void);
  22. extern void lcd_leftToRight(void);
  23. extern void lcd_rightToLeft(void);
  24. extern void lcd_autoscroll(void);
  25. extern void lcd_no_autoscroll(void);*/
  26. extern void lcd_set_cursor(uint8_t col, uint8_t row);
  27. extern void lcd_createChar_P(uint8_t, const uint8_t*);
  28. // char c is non-standard, however it saves 1B on stack
  29. extern int lcd_putc(char c);
  30. extern int lcd_putc_at(uint8_t c, uint8_t r, char ch);
  31. extern int lcd_puts_P(const char* str);
  32. extern int lcd_puts_at_P(uint8_t c, uint8_t r, const char* str);
  33. extern int lcd_printf_P(const char* format, ...);
  34. extern void lcd_space(uint8_t n);
  35. extern void lcd_printNumber(unsigned long n, uint8_t base);
  36. extern void lcd_printFloat(double number, uint8_t digits);
  37. extern void lcd_print(const char*);
  38. extern void lcd_print_pad(const char*, uint8_t len);
  39. extern void lcd_print(char, int = 0);
  40. extern void lcd_print(unsigned char, int = 0);
  41. extern void lcd_print(int, int = 10);
  42. extern void lcd_print(unsigned int, int = 10);
  43. extern void lcd_print(long, int = 10);
  44. extern void lcd_print(unsigned long, int = 10);
  45. extern void lcd_print(double, int = 2);
  46. //! @brief Clear screen
  47. #define ESC_2J "\x1b[2J"
  48. //! @brief Show cursor
  49. #define ESC_25h "\x1b[?25h"
  50. //! @brief Hide cursor
  51. #define ESC_25l "\x1b[?25l"
  52. //! @brief Set cursor to
  53. //! @param c column
  54. //! @param r row
  55. #define ESC_H(c,r) "\x1b["#r";"#c"H"
  56. #define LCD_UPDATE_INTERVAL 100
  57. #define LCD_TIMEOUT_TO_STATUS 30000ul //!< Generic timeout to status screen in ms, when no user action.
  58. #define LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z 90000ul //!< Specific timeout for lcd_babystep_z screen in ms.
  59. typedef void (*lcd_longpress_func_t)(void);
  60. typedef void (*lcd_charsetup_func_t)(void);
  61. typedef void (*lcd_lcdupdate_func_t)(void);
  62. //Set to none-zero when the LCD needs to draw, decreased after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
  63. extern uint8_t lcd_draw_update;
  64. extern int32_t lcd_encoder;
  65. extern uint8_t lcd_encoder_bits;
  66. // lcd_encoder_diff is updated from interrupt context and added to lcd_encoder every LCD update
  67. extern int8_t lcd_encoder_diff;
  68. //the last checked lcd_buttons in a bit array.
  69. extern uint8_t lcd_buttons;
  70. extern uint8_t lcd_button_pressed;
  71. extern uint8_t lcd_update_enabled;
  72. extern LongTimer lcd_timeoutToStatus;
  73. extern uint32_t lcd_next_update_millis;
  74. extern lcd_longpress_func_t lcd_longpress_func;
  75. extern bool lcd_longpress_trigger;
  76. extern lcd_lcdupdate_func_t lcd_lcdupdate_func;
  77. extern uint8_t lcd_clicked(void);
  78. extern void lcd_beeper_quick_feedback(void);
  79. //Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  80. extern void lcd_quick_feedback(void);
  81. extern void lcd_update(uint8_t lcdDrawUpdateOverride);
  82. extern void lcd_update_enable(uint8_t enabled);
  83. extern void lcd_buttons_update(void);
  84. //! @brief Helper class to temporarily disable LCD updates
  85. //!
  86. //! When constructed (on stack), original state state of lcd_update_enabled is stored
  87. //! and LCD updates are disabled.
  88. //! When destroyed (gone out of scope), original state of LCD update is restored.
  89. //! It has zero overhead compared to storing bool saved = lcd_update_enabled
  90. //! and calling lcd_update_enable(false) and lcd_update_enable(saved).
  91. class LcdUpdateDisabler
  92. {
  93. public:
  94. LcdUpdateDisabler(): m_updateEnabled(lcd_update_enabled)
  95. {
  96. lcd_update_enable(false);
  97. }
  98. ~LcdUpdateDisabler()
  99. {
  100. lcd_update_enable(m_updateEnabled);
  101. }
  102. private:
  103. bool m_updateEnabled;
  104. };
  105. ////////////////////////////////////
  106. // Setup button and encode mappings for each panel (into 'lcd_buttons' variable
  107. //
  108. // This is just to map common functions (across different panels) onto the same
  109. // macro name. The mapping is independent of whether the button is directly connected or
  110. // via a shift/i2c register.
  111. #define BLEN_B 1
  112. #define BLEN_A 0
  113. #define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
  114. #define EN_A (1<<BLEN_A)
  115. #define BLEN_C 2
  116. #define EN_C (1<<BLEN_C)
  117. //! @brief Was button clicked?
  118. //!
  119. //! Doesn't consume button click event. See lcd_clicked()
  120. //! for function consuming the event.
  121. //!
  122. //! Generally is used in non-modal menus.
  123. //!
  124. //! @retval 0 button was not clicked
  125. //! @retval 1 button was clicked
  126. #define LCD_CLICKED (lcd_buttons&EN_C)
  127. ////////////////////////
  128. // Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  129. // These values are independent of which pins are used for EN_A and EN_B indications
  130. // The rotary encoder part is also independent to the chipset used for the LCD
  131. #define encrot0 0
  132. #define encrot1 2
  133. #define encrot2 3
  134. #define encrot3 1
  135. //Custom characters defined in the first 8 characters of the LCD
  136. #define LCD_STR_BEDTEMP "\x00"
  137. #define LCD_STR_DEGREE "\x01"
  138. #define LCD_STR_THERMOMETER "\x02"
  139. #define LCD_STR_UPLEVEL "\x03"
  140. #define LCD_STR_REFRESH "\x04"
  141. #define LCD_STR_FOLDER "\x05"
  142. #define LCD_STR_FEEDRATE "\x06"
  143. #define LCD_STR_ARROW_2_DOWN "\x06"
  144. #define LCD_STR_CLOCK "\x07"
  145. #define LCD_STR_CONFIRM "\x07"
  146. #define LCD_STR_ARROW_RIGHT "\x7E" //from the default character set
  147. #define LCD_STR_SOLID_BLOCK "\xFF" //from the default character set
  148. extern void lcd_set_custom_characters(void);
  149. extern void lcd_set_custom_characters_nextpage(void);
  150. //! @brief Consume click event
  151. inline void lcd_consume_click()
  152. {
  153. lcd_button_pressed = 0;
  154. lcd_buttons &= 0xff^EN_C;
  155. }
  156. #endif //_LCD_H