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.7KB

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