My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef __ULTRALCDH
  2. #define __ULTRALCDH
  3. #include "Marlin.h"
  4. #ifdef ULTRA_LCD
  5. #include <LiquidCrystal.h>
  6. void lcd_status();
  7. void lcd_init();
  8. void lcd_status(const char* message);
  9. void beep();
  10. void buttons_check();
  11. #define LCD_UPDATE_INTERVAL 100
  12. #define STATUSTIMEOUT 15000
  13. extern LiquidCrystal lcd;
  14. #ifdef NEWPANEL
  15. #define EN_C (1<<BLEN_C)
  16. #define EN_B (1<<BLEN_B)
  17. #define EN_A (1<<BLEN_A)
  18. #define CLICKED (buttons&EN_C)
  19. #define BLOCK {blocking=millis()+blocktime;}
  20. #if (SDCARDDETECT > -1)
  21. {
  22. #define CARDINSERTED (READ(SDCARDDETECT)==0)
  23. }
  24. #endif
  25. #else
  26. //atomatic, do not change
  27. #define B_LE (1<<BL_LE)
  28. #define B_UP (1<<BL_UP)
  29. #define B_MI (1<<BL_MI)
  30. #define B_DW (1<<BL_DW)
  31. #define B_RI (1<<BL_RI)
  32. #define B_ST (1<<BL_ST)
  33. #define EN_B (1<<BLEN_B)
  34. #define EN_A (1<<BLEN_A)
  35. #define CLICKED ((buttons&B_MI)||(buttons&B_ST))
  36. #define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;}
  37. #endif
  38. // blocking time for recognizing a new keypress of one key, ms
  39. #define blocktime 500
  40. #define lcdslow 5
  41. enum MainStatus{Main_Status, Main_Menu, Main_Prepare, Main_Control, Main_SD,Sub_TempControl,Sub_MotionControl};
  42. class MainMenu{
  43. public:
  44. MainMenu();
  45. void update();
  46. int8_t activeline;
  47. MainStatus status;
  48. uint8_t displayStartingRow;
  49. void showStatus();
  50. void showMainMenu();
  51. void showPrepare();
  52. void showTune();
  53. void showControl();
  54. void showControlMotion();
  55. void showControlTemp();
  56. void showSD();
  57. bool force_lcd_update;
  58. int lastencoderpos;
  59. int8_t lineoffset;
  60. int8_t lastlineoffset;
  61. bool linechanging;
  62. bool tune;
  63. private:
  64. FORCE_INLINE void updateActiveLines(const uint8_t &maxlines,volatile int &encoderpos)
  65. {
  66. if(linechanging) return; // an item is changint its value, do not switch lines hence
  67. lastlineoffset=lineoffset;
  68. int curencoderpos=encoderpos;
  69. force_lcd_update=false;
  70. if( (abs(curencoderpos-lastencoderpos)<lcdslow) )
  71. {
  72. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  73. if(curencoderpos<0)
  74. {
  75. lineoffset--;
  76. if(lineoffset<0) lineoffset=0;
  77. curencoderpos=lcdslow-1;
  78. }
  79. if(curencoderpos>(LCD_HEIGHT-1+1)*lcdslow)
  80. {
  81. lineoffset++;
  82. curencoderpos=(LCD_HEIGHT-1)*lcdslow;
  83. if(lineoffset>(maxlines+1-LCD_HEIGHT))
  84. lineoffset=maxlines+1-LCD_HEIGHT;
  85. if(curencoderpos>maxlines*lcdslow)
  86. curencoderpos=maxlines*lcdslow;
  87. }
  88. lastencoderpos=encoderpos=curencoderpos;
  89. activeline=curencoderpos/lcdslow;
  90. if(activeline<0) activeline=0;
  91. if(activeline>LCD_HEIGHT-1) activeline=LCD_HEIGHT-1;
  92. if(activeline>maxlines)
  93. {
  94. activeline=maxlines;
  95. curencoderpos=maxlines*lcdslow;
  96. }
  97. if(lastlineoffset!=lineoffset)
  98. force_lcd_update=true;
  99. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  100. }
  101. }
  102. FORCE_INLINE void clearIfNecessary()
  103. {
  104. if(lastlineoffset!=lineoffset ||force_lcd_update)
  105. {
  106. force_lcd_update=true;
  107. lcd.clear();
  108. }
  109. }
  110. };
  111. //conversion routines, could need some overworking
  112. char *ftostr51(const float &x);
  113. char *ftostr31(const float &x);
  114. char *ftostr3(const float &x);
  115. #define LCD_MESSAGE(x) lcd_status(x);
  116. #define LCD_MESSAGEPGM(x) lcd_statuspgm(MYPGM(x));
  117. #define LCD_STATUS lcd_status()
  118. #else //no lcd
  119. #define LCD_STATUS
  120. #define LCD_MESSAGE(x)
  121. #define LCD_MESSAGEPGM(x)
  122. FORCE_INLINE void lcd_status() {};
  123. #endif
  124. #ifndef ULTIPANEL
  125. #define CLICKED false
  126. #define BLOCK ;
  127. #endif
  128. void lcd_statuspgm(const char* message);
  129. char *ftostr3(const float &x);
  130. char *itostr2(const uint8_t &x);
  131. char *ftostr31(const float &x);
  132. char *ftostr32(const float &x);
  133. char *itostr31(const int &xx);
  134. char *itostr3(const int &xx);
  135. char *itostr4(const int &xx);
  136. char *ftostr51(const float &x);
  137. #endif //ULTRALCD