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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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};
  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. bool force_lcd_update;
  64. long lastencoderpos;
  65. int8_t lineoffset;
  66. int8_t lastlineoffset;
  67. bool linechanging;
  68. bool tune;
  69. private:
  70. FORCE_INLINE void updateActiveLines(const uint8_t &maxlines,volatile long &encoderpos)
  71. {
  72. if(linechanging) return; // an item is changint its value, do not switch lines hence
  73. lastlineoffset=lineoffset;
  74. long curencoderpos=encoderpos;
  75. force_lcd_update=false;
  76. if( (abs(curencoderpos-lastencoderpos)<lcdslow) )
  77. {
  78. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  79. if(curencoderpos<0)
  80. {
  81. lineoffset--;
  82. if(lineoffset<0) lineoffset=0;
  83. curencoderpos=lcdslow-1;
  84. }
  85. if(curencoderpos>(LCD_HEIGHT-1+1)*lcdslow)
  86. {
  87. lineoffset++;
  88. curencoderpos=(LCD_HEIGHT-1)*lcdslow;
  89. if(lineoffset>(maxlines+1-LCD_HEIGHT))
  90. lineoffset=maxlines+1-LCD_HEIGHT;
  91. if(curencoderpos>maxlines*lcdslow)
  92. curencoderpos=maxlines*lcdslow;
  93. }
  94. lastencoderpos=encoderpos=curencoderpos;
  95. activeline=curencoderpos/lcdslow;
  96. if(activeline<0) activeline=0;
  97. if(activeline>LCD_HEIGHT-1) activeline=LCD_HEIGHT-1;
  98. if(activeline>maxlines)
  99. {
  100. activeline=maxlines;
  101. curencoderpos=maxlines*lcdslow;
  102. }
  103. if(lastlineoffset!=lineoffset)
  104. force_lcd_update=true;
  105. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  106. }
  107. }
  108. FORCE_INLINE void clearIfNecessary()
  109. {
  110. if(lastlineoffset!=lineoffset ||force_lcd_update)
  111. {
  112. force_lcd_update=true;
  113. lcd.clear();
  114. }
  115. }
  116. };
  117. //conversion routines, could need some overworking
  118. char *ftostr51(const float &x);
  119. char *ftostr52(const float &x);
  120. char *ftostr31(const float &x);
  121. char *ftostr3(const float &x);
  122. #define LCD_INIT lcd_init();
  123. #define LCD_MESSAGE(x) lcd_status(x);
  124. #define LCD_MESSAGEPGM(x) lcd_statuspgm(MYPGM(x));
  125. #define LCD_STATUS lcd_status()
  126. #else //no lcd
  127. #define LCD_INIT
  128. #define LCD_STATUS
  129. #define LCD_MESSAGE(x)
  130. #define LCD_MESSAGEPGM(x)
  131. FORCE_INLINE void lcd_status() {};
  132. #define CLICKED false
  133. #define BLOCK ;
  134. #endif
  135. void lcd_statuspgm(const char* message);
  136. char *ftostr3(const float &x);
  137. char *itostr2(const uint8_t &x);
  138. char *ftostr31(const float &x);
  139. char *ftostr32(const float &x);
  140. char *itostr31(const int &xx);
  141. char *itostr3(const int &xx);
  142. char *itostr4(const int &xx);
  143. char *ftostr51(const float &x);
  144. #endif //ULTRALCD