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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  1. #include "ultralcd.h"
  2. #if ENABLED(ULTRA_LCD)
  3. #include "Marlin.h"
  4. #include "language.h"
  5. #include "cardreader.h"
  6. #include "temperature.h"
  7. #include "stepper.h"
  8. #include "configuration_store.h"
  9. /**
  10. * REVERSE_MENU_DIRECTION
  11. *
  12. * To reverse the menu direction we need a general way to reverse
  13. * the direction of the encoder everywhere. So encoderDirection is
  14. * added to allow the encoder to go the other way.
  15. *
  16. * This behavior is limited to scrolling Menus and SD card listings,
  17. * and is disabled in other contexts.
  18. */
  19. #if ENABLED(REVERSE_MENU_DIRECTION)
  20. int8_t encoderDirection = 1;
  21. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  22. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  23. #else
  24. #define ENCODER_DIRECTION_NORMAL() ;
  25. #define ENCODER_DIRECTION_MENUS() ;
  26. #endif
  27. uint8_t blink = 0; // Variable for animation
  28. int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
  29. bool encoderRateMultiplierEnabled;
  30. int32_t lastEncoderMovementMillis;
  31. int plaPreheatHotendTemp;
  32. int plaPreheatHPBTemp;
  33. int plaPreheatFanSpeed;
  34. int absPreheatHotendTemp;
  35. int absPreheatHPBTemp;
  36. int absPreheatFanSpeed;
  37. #if ENABLED(FILAMENT_LCD_DISPLAY)
  38. millis_t previous_lcd_status_ms = 0;
  39. #endif
  40. // Function pointer to menu functions.
  41. typedef void (*menuFunc_t)();
  42. uint8_t lcd_status_message_level;
  43. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  44. #if ENABLED(DOGLCD)
  45. #include "dogm_lcd_implementation.h"
  46. #else
  47. #include "ultralcd_implementation_hitachi_HD44780.h"
  48. #endif
  49. // The main status screen
  50. static void lcd_status_screen();
  51. #if ENABLED(ULTIPANEL)
  52. #if HAS_POWER_SWITCH
  53. extern bool powersupply;
  54. #endif
  55. const float manual_feedrate[] = MANUAL_FEEDRATE;
  56. static void lcd_main_menu();
  57. static void lcd_tune_menu();
  58. static void lcd_prepare_menu();
  59. static void lcd_move_menu();
  60. static void lcd_control_menu();
  61. static void lcd_control_temperature_menu();
  62. static void lcd_control_temperature_preheat_pla_settings_menu();
  63. static void lcd_control_temperature_preheat_abs_settings_menu();
  64. static void lcd_control_motion_menu();
  65. static void lcd_control_volumetric_menu();
  66. #if ENABLED(HAS_LCD_CONTRAST)
  67. static void lcd_set_contrast();
  68. #endif
  69. #if ENABLED(FWRETRACT)
  70. static void lcd_control_retract_menu();
  71. #endif
  72. #if ENABLED(DELTA_CALIBRATION_MENU)
  73. static void lcd_delta_calibrate_menu();
  74. #endif
  75. #if ENABLED(MANUAL_BED_LEVELING)
  76. #include "mesh_bed_leveling.h"
  77. static void _lcd_level_bed();
  78. static void _lcd_level_bed_homing();
  79. static void lcd_level_bed();
  80. #endif
  81. /* Different types of actions that can be used in menu items. */
  82. static void menu_action_back(menuFunc_t data);
  83. static void menu_action_submenu(menuFunc_t data);
  84. static void menu_action_gcode(const char* pgcode);
  85. static void menu_action_function(menuFunc_t data);
  86. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  87. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  88. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  89. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  90. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  91. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  92. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  93. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  94. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  95. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  96. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  97. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  98. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  99. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  100. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  101. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  102. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  103. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  104. #if ENABLED(SDSUPPORT)
  105. static void lcd_sdcard_menu();
  106. static void menu_action_sdfile(const char* filename, char* longFilename);
  107. static void menu_action_sddirectory(const char* filename, char* longFilename);
  108. #endif
  109. #define ENCODER_FEEDRATE_DEADZONE 10
  110. #if DISABLED(LCD_I2C_VIKI)
  111. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  112. #define ENCODER_STEPS_PER_MENU_ITEM 5
  113. #endif
  114. #ifndef ENCODER_PULSES_PER_STEP
  115. #define ENCODER_PULSES_PER_STEP 1
  116. #endif
  117. #else
  118. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  119. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  120. #endif
  121. #ifndef ENCODER_PULSES_PER_STEP
  122. #define ENCODER_PULSES_PER_STEP 1
  123. #endif
  124. #endif
  125. /* Helper macros for menus */
  126. /**
  127. * START_MENU generates the init code for a menu function
  128. */
  129. #define START_MENU() do { \
  130. ENCODER_DIRECTION_MENUS(); \
  131. encoderRateMultiplierEnabled = false; \
  132. if (encoderPosition > 0x8000) encoderPosition = 0; \
  133. uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
  134. NOMORE(currentMenuViewOffset, encoderLine); \
  135. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  136. bool wasClicked = LCD_CLICKED, itemSelected; \
  137. for (uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  138. _menuItemNr = 0;
  139. /**
  140. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  141. *
  142. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  143. * menu_action_[type](arg3...)
  144. *
  145. * Examples:
  146. * MENU_ITEM(back, MSG_WATCH, lcd_status_screen)
  147. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH), lcd_status_screen)
  148. * menu_action_back(lcd_status_screen)
  149. *
  150. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  151. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  152. * menu_action_function(lcd_sdcard_pause)
  153. *
  154. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  155. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  156. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  157. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  158. *
  159. */
  160. #define MENU_ITEM(type, label, args...) do { \
  161. if (_menuItemNr == _lineNr) { \
  162. itemSelected = encoderLine == _menuItemNr; \
  163. if (lcdDrawUpdate) \
  164. lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
  165. if (wasClicked && itemSelected) { \
  166. lcd_quick_feedback(); \
  167. menu_action_ ## type(args); \
  168. return; \
  169. } \
  170. } \
  171. _menuItemNr++; \
  172. } while(0)
  173. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  174. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  175. /**
  176. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  177. */
  178. #define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
  179. if (_menuItemNr == _lineNr) { \
  180. itemSelected = encoderLine == _menuItemNr; \
  181. if (lcdDrawUpdate) \
  182. lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
  183. if (wasClicked && itemSelected) { \
  184. lcd_quick_feedback(); \
  185. encoderRateMultiplierEnabled = true; \
  186. lastEncoderMovementMillis = 0; \
  187. menu_action_ ## type(args); \
  188. return; \
  189. } \
  190. } \
  191. _menuItemNr++; \
  192. } while(0)
  193. #endif //ENCODER_RATE_MULTIPLIER
  194. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  195. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  196. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  197. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  198. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  199. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  200. #else //!ENCODER_RATE_MULTIPLIER
  201. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  202. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  203. #endif //!ENCODER_RATE_MULTIPLIER
  204. #define END_MENU() \
  205. if (encoderLine >= _menuItemNr) { encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; encoderLine = _menuItemNr - 1; }\
  206. if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
  207. } } while(0)
  208. /** Used variables to keep track of the menu */
  209. volatile uint8_t buttons; //the last checked buttons in a bit array.
  210. #if ENABLED(REPRAPWORLD_KEYPAD)
  211. volatile uint8_t buttons_reprapworld_keypad; // to store the keypad shift register values
  212. #endif
  213. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  214. volatile uint8_t slow_buttons; // Bits of the pressed buttons.
  215. #endif
  216. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  217. millis_t next_button_update_ms;
  218. uint8_t lastEncoderBits;
  219. uint32_t encoderPosition;
  220. #if PIN_EXISTS(SD_DETECT)
  221. uint8_t lcd_sd_status;
  222. #endif
  223. #endif // ULTIPANEL
  224. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  225. millis_t next_lcd_update_ms;
  226. uint8_t lcd_status_update_delay;
  227. bool ignore_click = false;
  228. bool wait_for_unclick;
  229. uint8_t lcdDrawUpdate = 2; /* 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) */
  230. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  231. menuFunc_t prevMenu = NULL;
  232. uint16_t prevEncoderPosition;
  233. //Variables used when editing values.
  234. const char* editLabel;
  235. void* editValue;
  236. int32_t minEditValue, maxEditValue;
  237. menuFunc_t callbackFunc;
  238. // place-holders for Ki and Kd edits
  239. float raw_Ki, raw_Kd;
  240. /**
  241. * General function to go directly to a menu
  242. */
  243. static void lcd_goto_menu(menuFunc_t menu, const bool feedback = false, const uint32_t encoder = 0) {
  244. if (currentMenu != menu) {
  245. currentMenu = menu;
  246. #if ENABLED(NEWPANEL)
  247. encoderPosition = encoder;
  248. if (feedback) lcd_quick_feedback();
  249. #endif
  250. // For LCD_PROGRESS_BAR re-initialize the custom characters
  251. #if ENABLED(LCD_PROGRESS_BAR)
  252. lcd_set_custom_characters(menu == lcd_status_screen);
  253. #endif
  254. }
  255. }
  256. inline void lcd_save_previous_menu() { prevMenu = currentMenu; prevEncoderPosition = encoderPosition; }
  257. static void lcd_goto_previous_menu() { lcd_goto_menu(prevMenu, true, prevEncoderPosition); }
  258. /**
  259. *
  260. * "Info Screen"
  261. *
  262. * This is very display-dependent, so the lcd implementation draws this.
  263. */
  264. static void lcd_status_screen() {
  265. ENCODER_DIRECTION_NORMAL();
  266. encoderRateMultiplierEnabled = false;
  267. #if ENABLED(LCD_PROGRESS_BAR)
  268. millis_t ms = millis();
  269. #if DISABLED(PROGRESS_MSG_ONCE)
  270. if (ms > progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
  271. progress_bar_ms = ms;
  272. }
  273. #endif
  274. #if PROGRESS_MSG_EXPIRE > 0
  275. // Handle message expire
  276. if (expire_status_ms > 0) {
  277. #if ENABLED(SDSUPPORT)
  278. if (card.isFileOpen()) {
  279. // Expire the message when printing is active
  280. if (IS_SD_PRINTING) {
  281. if (ms >= expire_status_ms) {
  282. lcd_status_message[0] = '\0';
  283. expire_status_ms = 0;
  284. }
  285. }
  286. else {
  287. expire_status_ms += LCD_UPDATE_INTERVAL;
  288. }
  289. }
  290. else {
  291. expire_status_ms = 0;
  292. }
  293. #else
  294. expire_status_ms = 0;
  295. #endif //SDSUPPORT
  296. }
  297. #endif
  298. #endif //LCD_PROGRESS_BAR
  299. lcd_implementation_status_screen();
  300. #if ENABLED(ULTIPANEL)
  301. bool current_click = LCD_CLICKED;
  302. if (ignore_click) {
  303. if (wait_for_unclick) {
  304. if (!current_click)
  305. ignore_click = wait_for_unclick = false;
  306. else
  307. current_click = false;
  308. }
  309. else if (current_click) {
  310. lcd_quick_feedback();
  311. wait_for_unclick = true;
  312. current_click = false;
  313. }
  314. }
  315. if (current_click) {
  316. lcd_goto_menu(lcd_main_menu, true);
  317. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  318. #if ENABLED(LCD_PROGRESS_BAR)
  319. currentMenu == lcd_status_screen
  320. #endif
  321. );
  322. #if ENABLED(FILAMENT_LCD_DISPLAY)
  323. previous_lcd_status_ms = millis(); // get status message to show up for a while
  324. #endif
  325. }
  326. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  327. // Dead zone at 100% feedrate
  328. if ((feedrate_multiplier < 100 && (feedrate_multiplier + int(encoderPosition)) > 100) ||
  329. (feedrate_multiplier > 100 && (feedrate_multiplier + int(encoderPosition)) < 100)) {
  330. encoderPosition = 0;
  331. feedrate_multiplier = 100;
  332. }
  333. if (feedrate_multiplier == 100) {
  334. if (int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE) {
  335. feedrate_multiplier += int(encoderPosition) - (ENCODER_FEEDRATE_DEADZONE);
  336. encoderPosition = 0;
  337. }
  338. else if (int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE) {
  339. feedrate_multiplier += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  340. encoderPosition = 0;
  341. }
  342. }
  343. else {
  344. feedrate_multiplier += int(encoderPosition);
  345. encoderPosition = 0;
  346. }
  347. #endif // ULTIPANEL_FEEDMULTIPLY
  348. feedrate_multiplier = constrain(feedrate_multiplier, 10, 999);
  349. #endif //ULTIPANEL
  350. }
  351. #if ENABLED(ULTIPANEL)
  352. static void lcd_return_to_status() { lcd_goto_menu(lcd_status_screen); }
  353. #if ENABLED(SDSUPPORT)
  354. static void lcd_sdcard_pause() { card.pauseSDPrint(); }
  355. static void lcd_sdcard_resume() { card.startFileprint(); }
  356. static void lcd_sdcard_stop() {
  357. quickStop();
  358. card.sdprinting = false;
  359. card.closefile();
  360. autotempShutdown();
  361. cancel_heatup = true;
  362. lcd_setstatus(MSG_PRINT_ABORTED, true);
  363. }
  364. #endif //SDSUPPORT
  365. /**
  366. *
  367. * "Main" menu
  368. *
  369. */
  370. static void lcd_main_menu() {
  371. START_MENU();
  372. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  373. if (movesplanned() || IS_SD_PRINTING) {
  374. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  375. }
  376. else {
  377. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  378. #if ENABLED(DELTA_CALIBRATION_MENU)
  379. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  380. #endif
  381. }
  382. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  383. #if ENABLED(SDSUPPORT)
  384. if (card.cardOK) {
  385. if (card.isFileOpen()) {
  386. if (card.sdprinting)
  387. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  388. else
  389. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  390. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  391. }
  392. else {
  393. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  394. #if !PIN_EXISTS(SD_DETECT)
  395. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  396. #endif
  397. }
  398. }
  399. else {
  400. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  401. #if !PIN_EXISTS(SD_DETECT)
  402. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  403. #endif
  404. }
  405. #endif //SDSUPPORT
  406. END_MENU();
  407. }
  408. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  409. static void lcd_autostart_sd() {
  410. card.autostart_index = 0;
  411. card.setroot();
  412. card.checkautostart(true);
  413. }
  414. #endif
  415. /**
  416. * Set the home offset based on the current_position
  417. */
  418. void lcd_set_home_offsets() {
  419. // M428 Command
  420. enqueue_and_echo_commands_P(PSTR("M428"));
  421. lcd_return_to_status();
  422. }
  423. #if ENABLED(BABYSTEPPING)
  424. static void _lcd_babystep(const int axis, const char* msg) {
  425. ENCODER_DIRECTION_NORMAL();
  426. if (encoderPosition != 0) {
  427. encoderPosition = 0;
  428. lcdDrawUpdate = 1;
  429. int distance = (int)encoderPosition * BABYSTEP_MULTIPLICATOR;
  430. #if ENABLED(COREXY) || ENABLED(COREXZ)
  431. #if ENABLED(BABYSTEP_XY)
  432. switch(axis) {
  433. case X_AXIS: // X on CoreXY and CoreXZ
  434. babystepsTodo[A_AXIS] += distance * 2;
  435. babystepsTodo[CORE_AXIS_2] += distance * 2;
  436. break;
  437. case CORE_AXIS_2: // Y on CoreXY, Z on CoreXZ
  438. babystepsTodo[A_AXIS] += distance * 2;
  439. babystepsTodo[CORE_AXIS_2] -= distance * 2;
  440. break;
  441. case CORE_AXIS_3: // Z on CoreXY, Y on CoreXZ
  442. babystepsTodo[CORE_AXIS_3] += distance;
  443. break;
  444. }
  445. #elif ENABLED(COREXZ)
  446. babystepsTodo[A_AXIS] += distance * 2;
  447. babystepsTodo[C_AXIS] -= distance * 2;
  448. #else
  449. babystepsTodo[Z_AXIS] += distance;
  450. #endif
  451. #else
  452. babystepsTodo[axis] += distance;
  453. #endif
  454. }
  455. if (lcdDrawUpdate) lcd_implementation_drawedit(msg, (char*)"");
  456. if (LCD_CLICKED) lcd_goto_previous_menu();
  457. }
  458. #if ENABLED(BABYSTEP_XY)
  459. static void lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  460. static void lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  461. #endif
  462. static void lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  463. #endif //BABYSTEPPING
  464. /**
  465. * Watch temperature callbacks
  466. */
  467. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  468. #if TEMP_SENSOR_0 != 0
  469. void watch_temp_callback_E0() { start_watching_heater(0); }
  470. #endif
  471. #if EXTRUDERS > 1 && TEMP_SENSOR_1 != 0
  472. void watch_temp_callback_E1() { start_watching_heater(1); }
  473. #endif // EXTRUDERS > 1
  474. #if EXTRUDERS > 2 && TEMP_SENSOR_2 != 0
  475. void watch_temp_callback_E2() { start_watching_heater(2); }
  476. #endif // EXTRUDERS > 2
  477. #if EXTRUDERS > 3 && TEMP_SENSOR_3 != 0
  478. void watch_temp_callback_E3() { start_watching_heater(3); }
  479. #endif // EXTRUDERS > 3
  480. #else
  481. #if TEMP_SENSOR_0 != 0
  482. void watch_temp_callback_E0() {}
  483. #endif
  484. #if EXTRUDERS > 1 && TEMP_SENSOR_1 != 0
  485. void watch_temp_callback_E1() {}
  486. #endif // EXTRUDERS > 1
  487. #if EXTRUDERS > 2 && TEMP_SENSOR_2 != 0
  488. void watch_temp_callback_E2() {}
  489. #endif // EXTRUDERS > 2
  490. #if EXTRUDERS > 3 && TEMP_SENSOR_3 != 0
  491. void watch_temp_callback_E3() {}
  492. #endif // EXTRUDERS > 3
  493. #endif
  494. /**
  495. *
  496. * "Tune" submenu
  497. *
  498. */
  499. static void lcd_tune_menu() {
  500. START_MENU();
  501. //
  502. // ^ Main
  503. //
  504. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  505. //
  506. // Speed:
  507. //
  508. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999);
  509. //
  510. // Nozzle:
  511. // Nozzle [1-4]:
  512. //
  513. #if EXTRUDERS == 1
  514. #if TEMP_SENSOR_0 != 0
  515. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  516. #endif
  517. #else //EXTRUDERS > 1
  518. #if TEMP_SENSOR_0 != 0
  519. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  520. #endif
  521. #if TEMP_SENSOR_1 != 0
  522. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  523. #endif
  524. #if EXTRUDERS > 2
  525. #if TEMP_SENSOR_2 != 0
  526. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  527. #endif
  528. #if EXTRUDERS > 3
  529. #if TEMP_SENSOR_3 != 0
  530. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  531. #endif
  532. #endif // EXTRUDERS > 3
  533. #endif // EXTRUDERS > 2
  534. #endif // EXTRUDERS > 1
  535. //
  536. // Bed:
  537. //
  538. #if TEMP_SENSOR_BED != 0
  539. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  540. #endif
  541. //
  542. // Fan Speed:
  543. //
  544. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  545. //
  546. // Flow:
  547. // Flow 1:
  548. // Flow 2:
  549. // Flow 3:
  550. // Flow 4:
  551. //
  552. #if EXTRUDERS == 1
  553. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[0], 10, 999);
  554. #else // EXTRUDERS > 1
  555. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[active_extruder], 10, 999);
  556. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &extruder_multiplier[0], 10, 999);
  557. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &extruder_multiplier[1], 10, 999);
  558. #if EXTRUDERS > 2
  559. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &extruder_multiplier[2], 10, 999);
  560. #if EXTRUDERS > 3
  561. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &extruder_multiplier[3], 10, 999);
  562. #endif //EXTRUDERS > 3
  563. #endif //EXTRUDERS > 2
  564. #endif //EXTRUDERS > 1
  565. //
  566. // Babystep X:
  567. // Babystep Y:
  568. // Babystep Z:
  569. //
  570. #if ENABLED(BABYSTEPPING)
  571. #if ENABLED(BABYSTEP_XY)
  572. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  573. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  574. #endif //BABYSTEP_XY
  575. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  576. #endif
  577. //
  578. // Change filament
  579. //
  580. #if ENABLED(FILAMENTCHANGEENABLE)
  581. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  582. #endif
  583. END_MENU();
  584. }
  585. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  586. if (temph > 0) setTargetHotend(temph, endnum);
  587. #if TEMP_SENSOR_BED != 0
  588. setTargetBed(tempb);
  589. #endif
  590. fanSpeed = fan;
  591. lcd_return_to_status();
  592. }
  593. #if TEMP_SENSOR_0 != 0
  594. void lcd_preheat_pla0() { _lcd_preheat(0, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  595. void lcd_preheat_abs0() { _lcd_preheat(0, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  596. #endif
  597. #if EXTRUDERS > 1
  598. void lcd_preheat_pla1() { _lcd_preheat(1, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  599. void lcd_preheat_abs1() { _lcd_preheat(1, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  600. #if EXTRUDERS > 2
  601. void lcd_preheat_pla2() { _lcd_preheat(2, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  602. void lcd_preheat_abs2() { _lcd_preheat(2, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  603. #if EXTRUDERS > 3
  604. void lcd_preheat_pla3() { _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  605. void lcd_preheat_abs3() { _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  606. #endif
  607. #endif
  608. void lcd_preheat_pla0123() {
  609. setTargetHotend0(plaPreheatHotendTemp);
  610. setTargetHotend1(plaPreheatHotendTemp);
  611. setTargetHotend2(plaPreheatHotendTemp);
  612. _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed);
  613. }
  614. void lcd_preheat_abs0123() {
  615. setTargetHotend0(absPreheatHotendTemp);
  616. setTargetHotend1(absPreheatHotendTemp);
  617. setTargetHotend2(absPreheatHotendTemp);
  618. _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed);
  619. }
  620. #endif // EXTRUDERS > 1
  621. #if TEMP_SENSOR_BED != 0
  622. void lcd_preheat_pla_bedonly() { _lcd_preheat(0, 0, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  623. void lcd_preheat_abs_bedonly() { _lcd_preheat(0, 0, absPreheatHPBTemp, absPreheatFanSpeed); }
  624. #endif
  625. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  626. static void lcd_preheat_pla_menu() {
  627. START_MENU();
  628. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  629. #if EXTRUDERS == 1
  630. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  631. #else
  632. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H1, lcd_preheat_pla0);
  633. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H2, lcd_preheat_pla1);
  634. #if EXTRUDERS > 2
  635. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H3, lcd_preheat_pla2);
  636. #if EXTRUDERS > 3
  637. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H4, lcd_preheat_pla3);
  638. #endif
  639. #endif
  640. MENU_ITEM(function, MSG_PREHEAT_PLA_ALL, lcd_preheat_pla0123);
  641. #endif
  642. #if TEMP_SENSOR_BED != 0
  643. MENU_ITEM(function, MSG_PREHEAT_PLA_BEDONLY, lcd_preheat_pla_bedonly);
  644. #endif
  645. END_MENU();
  646. }
  647. static void lcd_preheat_abs_menu() {
  648. START_MENU();
  649. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  650. #if EXTRUDERS == 1
  651. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  652. #else
  653. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H1, lcd_preheat_abs0);
  654. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H2, lcd_preheat_abs1);
  655. #if EXTRUDERS > 2
  656. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H3, lcd_preheat_abs2);
  657. #if EXTRUDERS > 3
  658. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H4, lcd_preheat_abs3);
  659. #endif
  660. #endif
  661. MENU_ITEM(function, MSG_PREHEAT_ABS_ALL, lcd_preheat_abs0123);
  662. #endif
  663. #if TEMP_SENSOR_BED != 0
  664. MENU_ITEM(function, MSG_PREHEAT_ABS_BEDONLY, lcd_preheat_abs_bedonly);
  665. #endif
  666. END_MENU();
  667. }
  668. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  669. void lcd_cooldown() {
  670. disable_all_heaters();
  671. fanSpeed = 0;
  672. lcd_return_to_status();
  673. }
  674. /**
  675. *
  676. * "Prepare" submenu
  677. *
  678. */
  679. static void lcd_prepare_menu() {
  680. START_MENU();
  681. //
  682. // ^ Main
  683. //
  684. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  685. //
  686. // Auto Home
  687. //
  688. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  689. //
  690. // Set Home Offsets
  691. //
  692. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  693. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  694. //
  695. // Level Bed
  696. //
  697. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  698. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS])
  699. MENU_ITEM(gcode, MSG_LEVEL_BED, PSTR("G29"));
  700. #elif ENABLED(MANUAL_BED_LEVELING)
  701. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  702. #endif
  703. //
  704. // Move Axis
  705. //
  706. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  707. //
  708. // Disable Steppers
  709. //
  710. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  711. //
  712. // Preheat PLA
  713. // Preheat ABS
  714. //
  715. #if TEMP_SENSOR_0 != 0
  716. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  717. MENU_ITEM(submenu, MSG_PREHEAT_PLA, lcd_preheat_pla_menu);
  718. MENU_ITEM(submenu, MSG_PREHEAT_ABS, lcd_preheat_abs_menu);
  719. #else
  720. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  721. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  722. #endif
  723. #endif
  724. //
  725. // Cooldown
  726. //
  727. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  728. //
  729. // Switch power on/off
  730. //
  731. #if HAS_POWER_SWITCH
  732. if (powersupply)
  733. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  734. else
  735. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  736. #endif
  737. //
  738. // Autostart
  739. //
  740. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  741. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  742. #endif
  743. END_MENU();
  744. }
  745. #if ENABLED(DELTA_CALIBRATION_MENU)
  746. static void lcd_delta_calibrate_menu() {
  747. START_MENU();
  748. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  749. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  750. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_X, PSTR("G0 F8000 X-77.94 Y-45 Z0"));
  751. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Y, PSTR("G0 F8000 X77.94 Y-45 Z0"));
  752. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Z, PSTR("G0 F8000 X0 Y90 Z0"));
  753. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_CENTER, PSTR("G0 F8000 X0 Y0 Z0"));
  754. END_MENU();
  755. }
  756. #endif // DELTA_CALIBRATION_MENU
  757. inline void line_to_current(AxisEnum axis) {
  758. #if ENABLED(DELTA)
  759. calculate_delta(current_position);
  760. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  761. #else
  762. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  763. #endif
  764. }
  765. /**
  766. *
  767. * "Prepare" > "Move Axis" submenu
  768. *
  769. */
  770. float move_menu_scale;
  771. static void lcd_move_menu_axis();
  772. static void _lcd_move(const char* name, AxisEnum axis, int min, int max) {
  773. ENCODER_DIRECTION_NORMAL();
  774. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  775. refresh_cmd_timeout();
  776. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  777. if (min_software_endstops) NOLESS(current_position[axis], min);
  778. if (max_software_endstops) NOMORE(current_position[axis], max);
  779. encoderPosition = 0;
  780. line_to_current(axis);
  781. lcdDrawUpdate = 1;
  782. }
  783. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  784. if (LCD_CLICKED) lcd_goto_previous_menu();
  785. }
  786. #if ENABLED(DELTA)
  787. static float delta_clip_radius_2 = (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS);
  788. static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - a*a); }
  789. static void lcd_move_x() { int clip = delta_clip(current_position[Y_AXIS]); _lcd_move(PSTR(MSG_MOVE_X), X_AXIS, max(X_MIN_POS, -clip), min(X_MAX_POS, clip)); }
  790. static void lcd_move_y() { int clip = delta_clip(current_position[X_AXIS]); _lcd_move(PSTR(MSG_MOVE_X), X_AXIS, max(X_MIN_POS, -clip), min(X_MAX_POS, clip)); }
  791. #else
  792. static void lcd_move_x() { _lcd_move(PSTR(MSG_MOVE_X), X_AXIS, X_MIN_POS, X_MAX_POS); }
  793. static void lcd_move_y() { _lcd_move(PSTR(MSG_MOVE_Y), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
  794. #endif
  795. static void lcd_move_z() { _lcd_move(PSTR(MSG_MOVE_Z), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
  796. static void lcd_move_e(
  797. #if EXTRUDERS > 1
  798. uint8_t e
  799. #endif
  800. ) {
  801. ENCODER_DIRECTION_NORMAL();
  802. #if EXTRUDERS > 1
  803. unsigned short original_active_extruder = active_extruder;
  804. active_extruder = e;
  805. #endif
  806. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  807. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  808. encoderPosition = 0;
  809. line_to_current(E_AXIS);
  810. lcdDrawUpdate = 1;
  811. }
  812. if (lcdDrawUpdate) {
  813. PGM_P pos_label;
  814. #if EXTRUDERS == 1
  815. pos_label = PSTR(MSG_MOVE_E);
  816. #else
  817. switch (e) {
  818. case 0: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  819. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  820. #if EXTRUDERS > 2
  821. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  822. #if EXTRUDERS > 3
  823. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  824. #endif //EXTRUDERS > 3
  825. #endif //EXTRUDERS > 2
  826. }
  827. #endif //EXTRUDERS > 1
  828. lcd_implementation_drawedit(pos_label, ftostr31(current_position[E_AXIS]));
  829. }
  830. if (LCD_CLICKED) lcd_goto_previous_menu();
  831. #if EXTRUDERS > 1
  832. active_extruder = original_active_extruder;
  833. #endif
  834. }
  835. #if EXTRUDERS > 1
  836. static void lcd_move_e0() { lcd_move_e(0); }
  837. static void lcd_move_e1() { lcd_move_e(1); }
  838. #if EXTRUDERS > 2
  839. static void lcd_move_e2() { lcd_move_e(2); }
  840. #if EXTRUDERS > 3
  841. static void lcd_move_e3() { lcd_move_e(3); }
  842. #endif
  843. #endif
  844. #endif // EXTRUDERS > 1
  845. /**
  846. *
  847. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  848. *
  849. */
  850. static void lcd_move_menu_axis() {
  851. START_MENU();
  852. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  853. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  854. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  855. if (move_menu_scale < 10.0) {
  856. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  857. #if EXTRUDERS == 1
  858. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  859. #else
  860. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_e0);
  861. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_e1);
  862. #if EXTRUDERS > 2
  863. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_e2);
  864. #if EXTRUDERS > 3
  865. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_e3);
  866. #endif
  867. #endif
  868. #endif // EXTRUDERS > 1
  869. }
  870. END_MENU();
  871. }
  872. static void lcd_move_menu_10mm() {
  873. move_menu_scale = 10.0;
  874. lcd_move_menu_axis();
  875. }
  876. static void lcd_move_menu_1mm() {
  877. move_menu_scale = 1.0;
  878. lcd_move_menu_axis();
  879. }
  880. static void lcd_move_menu_01mm() {
  881. move_menu_scale = 0.1;
  882. lcd_move_menu_axis();
  883. }
  884. /**
  885. *
  886. * "Prepare" > "Move Axis" submenu
  887. *
  888. */
  889. static void lcd_move_menu() {
  890. START_MENU();
  891. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  892. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  893. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  894. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  895. //TODO:X,Y,Z,E
  896. END_MENU();
  897. }
  898. /**
  899. *
  900. * "Control" submenu
  901. *
  902. */
  903. static void lcd_control_menu() {
  904. START_MENU();
  905. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  906. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  907. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  908. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  909. #if ENABLED(HAS_LCD_CONTRAST)
  910. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  911. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  912. #endif
  913. #if ENABLED(FWRETRACT)
  914. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  915. #endif
  916. #if ENABLED(EEPROM_SETTINGS)
  917. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  918. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  919. #endif
  920. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  921. END_MENU();
  922. }
  923. /**
  924. *
  925. * "Temperature" submenu
  926. *
  927. */
  928. #if ENABLED(PIDTEMP)
  929. // Helpers for editing PID Ki & Kd values
  930. // grab the PID value out of the temp variable; scale it; then update the PID driver
  931. void copy_and_scalePID_i(int e) {
  932. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  933. updatePID();
  934. }
  935. void copy_and_scalePID_d(int e) {
  936. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  937. updatePID();
  938. }
  939. #define COPY_AND_SCALE(eindex) \
  940. void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
  941. void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); }
  942. COPY_AND_SCALE(0);
  943. #if ENABLED(PID_PARAMS_PER_EXTRUDER)
  944. #if EXTRUDERS > 1
  945. COPY_AND_SCALE(1);
  946. #if EXTRUDERS > 2
  947. COPY_AND_SCALE(2);
  948. #if EXTRUDERS > 3
  949. COPY_AND_SCALE(3);
  950. #endif //EXTRUDERS > 3
  951. #endif //EXTRUDERS > 2
  952. #endif //EXTRUDERS > 1
  953. #endif //PID_PARAMS_PER_EXTRUDER
  954. #endif //PIDTEMP
  955. /**
  956. *
  957. * "Control" > "Temperature" submenu
  958. *
  959. */
  960. static void lcd_control_temperature_menu() {
  961. START_MENU();
  962. //
  963. // ^ Control
  964. //
  965. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  966. //
  967. // Nozzle:
  968. // Nozzle [1-4]:
  969. //
  970. #if EXTRUDERS == 1
  971. #if TEMP_SENSOR_0 != 0
  972. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  973. #endif
  974. #else //EXTRUDERS > 1
  975. #if TEMP_SENSOR_0 != 0
  976. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  977. #endif
  978. #if TEMP_SENSOR_1 != 0
  979. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  980. #endif
  981. #if EXTRUDERS > 2
  982. #if TEMP_SENSOR_2 != 0
  983. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  984. #endif
  985. #if EXTRUDERS > 3
  986. #if TEMP_SENSOR_3 != 0
  987. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  988. #endif
  989. #endif // EXTRUDERS > 3
  990. #endif // EXTRUDERS > 2
  991. #endif // EXTRUDERS > 1
  992. //
  993. // Bed:
  994. //
  995. #if TEMP_SENSOR_BED != 0
  996. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  997. #endif
  998. //
  999. // Fan Speed:
  1000. //
  1001. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  1002. //
  1003. // Autotemp, Min, Max, Fact
  1004. //
  1005. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1006. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  1007. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1008. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1009. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  1010. #endif
  1011. //
  1012. // PID-P, PID-I, PID-D, PID-C
  1013. // PID-P E1, PID-I E1, PID-D E1, PID-C E1
  1014. // PID-P E2, PID-I E2, PID-D E2, PID-C E2
  1015. // PID-P E3, PID-I E3, PID-D E3, PID-C E3
  1016. // PID-P E4, PID-I E4, PID-D E4, PID-C E4
  1017. //
  1018. #if ENABLED(PIDTEMP)
  1019. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1020. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1021. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1022. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1023. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1024. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1025. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  1026. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1027. _PID_MENU_ITEMS(ELABEL, eindex); \
  1028. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1029. #else
  1030. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1031. #endif
  1032. #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
  1033. PID_MENU_ITEMS(MSG_E1, 0);
  1034. PID_MENU_ITEMS(MSG_E2, 1);
  1035. #if EXTRUDERS > 2
  1036. PID_MENU_ITEMS(MSG_E3, 2);
  1037. #if EXTRUDERS > 3
  1038. PID_MENU_ITEMS(MSG_E4, 3);
  1039. #endif //EXTRUDERS > 3
  1040. #endif //EXTRUDERS > 2
  1041. #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1042. PID_MENU_ITEMS("", 0);
  1043. #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1044. #endif //PIDTEMP
  1045. //
  1046. // Preheat PLA conf
  1047. //
  1048. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  1049. //
  1050. // Preheat ABS conf
  1051. //
  1052. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  1053. END_MENU();
  1054. }
  1055. /**
  1056. *
  1057. * "Temperature" > "Preheat PLA conf" submenu
  1058. *
  1059. */
  1060. static void lcd_control_temperature_preheat_pla_settings_menu() {
  1061. START_MENU();
  1062. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1063. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  1064. #if TEMP_SENSOR_0 != 0
  1065. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1066. #endif
  1067. #if TEMP_SENSOR_BED != 0
  1068. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1069. #endif
  1070. #if ENABLED(EEPROM_SETTINGS)
  1071. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1072. #endif
  1073. END_MENU();
  1074. }
  1075. /**
  1076. *
  1077. * "Temperature" > "Preheat ABS conf" submenu
  1078. *
  1079. */
  1080. static void lcd_control_temperature_preheat_abs_settings_menu() {
  1081. START_MENU();
  1082. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1083. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  1084. #if TEMP_SENSOR_0 != 0
  1085. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1086. #endif
  1087. #if TEMP_SENSOR_BED != 0
  1088. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1089. #endif
  1090. #if ENABLED(EEPROM_SETTINGS)
  1091. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1092. #endif
  1093. END_MENU();
  1094. }
  1095. /**
  1096. *
  1097. * "Control" > "Motion" submenu
  1098. *
  1099. */
  1100. static void lcd_control_motion_menu() {
  1101. START_MENU();
  1102. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1103. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  1104. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  1105. #endif
  1106. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 10, 99000);
  1107. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  1108. #if ENABLED(DELTA)
  1109. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &max_z_jerk, 1, 990);
  1110. #else
  1111. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  1112. #endif
  1113. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  1114. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  1115. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  1116. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  1117. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  1118. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  1119. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  1120. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  1121. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  1122. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 10, 99000, reset_acceleration_rates);
  1123. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  1124. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  1125. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &travel_acceleration, 100, 99000);
  1126. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  1127. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  1128. #if ENABLED(DELTA)
  1129. MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1130. #else
  1131. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1132. #endif
  1133. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  1134. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  1135. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
  1136. #endif
  1137. #if ENABLED(SCARA)
  1138. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS], 0.5, 2);
  1139. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS], 0.5, 2);
  1140. #endif
  1141. END_MENU();
  1142. }
  1143. /**
  1144. *
  1145. * "Control" > "Filament" submenu
  1146. *
  1147. */
  1148. static void lcd_control_volumetric_menu() {
  1149. START_MENU();
  1150. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1151. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  1152. if (volumetric_enabled) {
  1153. #if EXTRUDERS == 1
  1154. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1155. #else //EXTRUDERS > 1
  1156. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1157. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  1158. #if EXTRUDERS > 2
  1159. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  1160. #if EXTRUDERS > 3
  1161. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  1162. #endif //EXTRUDERS > 3
  1163. #endif //EXTRUDERS > 2
  1164. #endif //EXTRUDERS > 1
  1165. }
  1166. END_MENU();
  1167. }
  1168. /**
  1169. *
  1170. * "Control" > "Contrast" submenu
  1171. *
  1172. */
  1173. #if ENABLED(HAS_LCD_CONTRAST)
  1174. static void lcd_set_contrast() {
  1175. ENCODER_DIRECTION_NORMAL();
  1176. if (encoderPosition != 0) {
  1177. #if ENABLED(U8GLIB_LM6059_AF)
  1178. lcd_contrast += encoderPosition;
  1179. lcd_contrast &= 0xFF;
  1180. #else
  1181. lcd_contrast -= encoderPosition;
  1182. lcd_contrast &= 0x3F;
  1183. #endif
  1184. encoderPosition = 0;
  1185. lcdDrawUpdate = 1;
  1186. u8g.setContrast(lcd_contrast);
  1187. }
  1188. if (lcdDrawUpdate) {
  1189. #if ENABLED(U8GLIB_LM6059_AF)
  1190. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr3(lcd_contrast));
  1191. #else
  1192. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
  1193. #endif
  1194. }
  1195. if (LCD_CLICKED) lcd_goto_previous_menu();
  1196. }
  1197. #endif // HAS_LCD_CONTRAST
  1198. /**
  1199. *
  1200. * "Control" > "Retract" submenu
  1201. *
  1202. */
  1203. #if ENABLED(FWRETRACT)
  1204. static void lcd_control_retract_menu() {
  1205. START_MENU();
  1206. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1207. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  1208. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  1209. #if EXTRUDERS > 1
  1210. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  1211. #endif
  1212. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  1213. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  1214. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  1215. #if EXTRUDERS > 1
  1216. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  1217. #endif
  1218. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  1219. END_MENU();
  1220. }
  1221. #endif // FWRETRACT
  1222. #if ENABLED(SDSUPPORT)
  1223. #if !PIN_EXISTS(SD_DETECT)
  1224. static void lcd_sd_refresh() {
  1225. card.initsd();
  1226. currentMenuViewOffset = 0;
  1227. }
  1228. #endif
  1229. static void lcd_sd_updir() {
  1230. card.updir();
  1231. currentMenuViewOffset = 0;
  1232. }
  1233. /**
  1234. *
  1235. * "Print from SD" submenu
  1236. *
  1237. */
  1238. void lcd_sdcard_menu() {
  1239. ENCODER_DIRECTION_MENUS();
  1240. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
  1241. uint16_t fileCnt = card.getnrfilenames();
  1242. START_MENU();
  1243. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1244. card.getWorkDirName();
  1245. if (card.filename[0] == '/') {
  1246. #if !PIN_EXISTS(SD_DETECT)
  1247. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1248. #endif
  1249. }
  1250. else {
  1251. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1252. }
  1253. for (uint16_t i = 0; i < fileCnt; i++) {
  1254. if (_menuItemNr == _lineNr) {
  1255. card.getfilename(
  1256. #if ENABLED(SDCARD_RATHERRECENTFIRST)
  1257. fileCnt-1 -
  1258. #endif
  1259. i
  1260. );
  1261. if (card.filenameIsDir)
  1262. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1263. else
  1264. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1265. }
  1266. else {
  1267. MENU_ITEM_DUMMY();
  1268. }
  1269. }
  1270. END_MENU();
  1271. }
  1272. #endif //SDSUPPORT
  1273. /**
  1274. *
  1275. * Functions for editing single values
  1276. *
  1277. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  1278. *
  1279. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  1280. *
  1281. * bool _menu_edit_int3();
  1282. * void menu_edit_int3(); // edit int (interactively)
  1283. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  1284. * static void _menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1285. * static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1286. * static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callback); // edit int with callback
  1287. *
  1288. * You can then use one of the menu macros to present the edit interface:
  1289. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  1290. *
  1291. * This expands into a more primitive menu item:
  1292. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1293. *
  1294. *
  1295. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  1296. *
  1297. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1298. */
  1299. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1300. bool _menu_edit_ ## _name () { \
  1301. ENCODER_DIRECTION_NORMAL(); \
  1302. bool isClicked = LCD_CLICKED; \
  1303. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1304. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1305. if (lcdDrawUpdate) \
  1306. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1307. if (isClicked) { \
  1308. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1309. lcd_goto_previous_menu(); \
  1310. } \
  1311. return isClicked; \
  1312. } \
  1313. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  1314. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  1315. static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1316. lcd_save_previous_menu(); \
  1317. \
  1318. lcdDrawUpdate = 2; \
  1319. currentMenu = menu_edit_ ## _name; \
  1320. \
  1321. editLabel = pstr; \
  1322. editValue = ptr; \
  1323. minEditValue = minValue * scale; \
  1324. maxEditValue = maxValue * scale - minEditValue; \
  1325. encoderPosition = (*ptr) * scale - minEditValue; \
  1326. } \
  1327. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1328. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1329. currentMenu = menu_edit_ ## _name; \
  1330. }\
  1331. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) { \
  1332. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1333. currentMenu = menu_edit_callback_ ## _name; \
  1334. callbackFunc = callback; \
  1335. }
  1336. menu_edit_type(int, int3, itostr3, 1)
  1337. menu_edit_type(float, float3, ftostr3, 1)
  1338. menu_edit_type(float, float32, ftostr32, 100)
  1339. menu_edit_type(float, float43, ftostr43, 1000)
  1340. menu_edit_type(float, float5, ftostr5, 0.01)
  1341. menu_edit_type(float, float51, ftostr51, 10)
  1342. menu_edit_type(float, float52, ftostr52, 100)
  1343. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1344. /**
  1345. *
  1346. * Handlers for RepRap World Keypad input
  1347. *
  1348. */
  1349. #if ENABLED(REPRAPWORLD_KEYPAD)
  1350. static void reprapworld_keypad_move_z_up() {
  1351. encoderPosition = 1;
  1352. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1353. lcd_move_z();
  1354. }
  1355. static void reprapworld_keypad_move_z_down() {
  1356. encoderPosition = -1;
  1357. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1358. lcd_move_z();
  1359. }
  1360. static void reprapworld_keypad_move_x_left() {
  1361. encoderPosition = -1;
  1362. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1363. lcd_move_x();
  1364. }
  1365. static void reprapworld_keypad_move_x_right() {
  1366. encoderPosition = 1;
  1367. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1368. lcd_move_x();
  1369. }
  1370. static void reprapworld_keypad_move_y_down() {
  1371. encoderPosition = 1;
  1372. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1373. lcd_move_y();
  1374. }
  1375. static void reprapworld_keypad_move_y_up() {
  1376. encoderPosition = -1;
  1377. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1378. lcd_move_y();
  1379. }
  1380. static void reprapworld_keypad_move_home() {
  1381. enqueue_and_echo_commands_P((PSTR("G28"))); // move all axis home
  1382. }
  1383. #endif // REPRAPWORLD_KEYPAD
  1384. /**
  1385. *
  1386. * Audio feedback for controller clicks
  1387. *
  1388. */
  1389. #if ENABLED(LCD_USE_I2C_BUZZER)
  1390. void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
  1391. lcd.buzz(duration, freq);
  1392. }
  1393. #endif
  1394. void lcd_quick_feedback() {
  1395. lcdDrawUpdate = 2;
  1396. next_button_update_ms = millis() + 500;
  1397. #if ENABLED(LCD_USE_I2C_BUZZER)
  1398. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1399. #define LCD_FEEDBACK_FREQUENCY_HZ 100
  1400. #endif
  1401. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1402. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
  1403. #endif
  1404. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1405. #elif PIN_EXISTS(BEEPER)
  1406. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1407. #define LCD_FEEDBACK_FREQUENCY_HZ 5000
  1408. #endif
  1409. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1410. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1411. #endif
  1412. buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1413. #else
  1414. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1415. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1416. #endif
  1417. delay(LCD_FEEDBACK_FREQUENCY_DURATION_MS);
  1418. #endif
  1419. }
  1420. /**
  1421. *
  1422. * Menu actions
  1423. *
  1424. */
  1425. static void menu_action_back(menuFunc_t func) { lcd_goto_menu(func); }
  1426. static void menu_action_submenu(menuFunc_t func) { lcd_save_previous_menu(); lcd_goto_menu(func); }
  1427. static void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  1428. static void menu_action_function(menuFunc_t func) { (*func)(); }
  1429. #if ENABLED(SDSUPPORT)
  1430. static void menu_action_sdfile(const char* filename, char* longFilename) {
  1431. card.openAndPrintFile(filename);
  1432. lcd_return_to_status();
  1433. }
  1434. static void menu_action_sddirectory(const char* filename, char* longFilename) {
  1435. card.chdir(filename);
  1436. encoderPosition = 0;
  1437. }
  1438. #endif //SDSUPPORT
  1439. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { *ptr = !(*ptr); }
  1440. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback) {
  1441. menu_action_setting_edit_bool(pstr, ptr);
  1442. (*callback)();
  1443. }
  1444. #endif //ULTIPANEL
  1445. /** LCD API **/
  1446. void lcd_init() {
  1447. lcd_implementation_init();
  1448. #if ENABLED(NEWPANEL)
  1449. #if BTN_EN1 > 0
  1450. SET_INPUT(BTN_EN1);
  1451. WRITE(BTN_EN1, HIGH);
  1452. #endif
  1453. #if BTN_EN2 > 0
  1454. SET_INPUT(BTN_EN2);
  1455. WRITE(BTN_EN2, HIGH);
  1456. #endif
  1457. #if BTN_ENC > 0
  1458. SET_INPUT(BTN_ENC);
  1459. WRITE(BTN_ENC, HIGH);
  1460. #endif
  1461. #if ENABLED(REPRAPWORLD_KEYPAD)
  1462. pinMode(SHIFT_CLK, OUTPUT);
  1463. pinMode(SHIFT_LD, OUTPUT);
  1464. pinMode(SHIFT_OUT, INPUT);
  1465. WRITE(SHIFT_OUT, HIGH);
  1466. WRITE(SHIFT_LD, HIGH);
  1467. #endif
  1468. #ifdef RIGIDBOT_PANEL
  1469. SET_INPUT(BTN_UP);
  1470. SET_INPUT(BTN_DWN);
  1471. SET_INPUT(BTN_LFT);
  1472. SET_INPUT(BTN_RT);
  1473. #endif
  1474. #else // Not NEWPANEL
  1475. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  1476. pinMode(SR_DATA_PIN, OUTPUT);
  1477. pinMode(SR_CLK_PIN, OUTPUT);
  1478. #elif defined(SHIFT_CLK)
  1479. pinMode(SHIFT_CLK, OUTPUT);
  1480. pinMode(SHIFT_LD, OUTPUT);
  1481. pinMode(SHIFT_EN, OUTPUT);
  1482. pinMode(SHIFT_OUT, INPUT);
  1483. WRITE(SHIFT_OUT, HIGH);
  1484. WRITE(SHIFT_LD, HIGH);
  1485. WRITE(SHIFT_EN, LOW);
  1486. #endif // SR_LCD_2W_NL
  1487. #endif//!NEWPANEL
  1488. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1489. SET_INPUT(SD_DETECT_PIN);
  1490. WRITE(SD_DETECT_PIN, HIGH);
  1491. lcd_sd_status = 2; // UNKNOWN
  1492. #endif
  1493. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1494. slow_buttons = 0;
  1495. #endif
  1496. lcd_buttons_update();
  1497. #if ENABLED(ULTIPANEL)
  1498. encoderDiff = 0;
  1499. #endif
  1500. }
  1501. int lcd_strlen(char* s) {
  1502. int i = 0, j = 0;
  1503. while (s[i]) {
  1504. if ((s[i] & 0xc0) != 0x80) j++;
  1505. i++;
  1506. }
  1507. return j;
  1508. }
  1509. int lcd_strlen_P(const char* s) {
  1510. int j = 0;
  1511. while (pgm_read_byte(s)) {
  1512. if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
  1513. s++;
  1514. }
  1515. return j;
  1516. }
  1517. /**
  1518. * Update the LCD, read encoder buttons, etc.
  1519. * - Read button states
  1520. * - Check the SD Card slot state
  1521. * - Act on RepRap World keypad input
  1522. * - Update the encoder position
  1523. * - Apply acceleration to the encoder position
  1524. * - Reset the Info Screen timeout if there's any input
  1525. * - Update status indicators, if any
  1526. * - Clear the LCD if lcdDrawUpdate == 2
  1527. *
  1528. * Warning: This function is called from interrupt context!
  1529. */
  1530. void lcd_update() {
  1531. #if ENABLED(ULTIPANEL)
  1532. static millis_t return_to_status_ms = 0;
  1533. #endif
  1534. lcd_buttons_update();
  1535. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1536. bool sd_status = IS_SD_INSERTED;
  1537. if (sd_status != lcd_sd_status && lcd_detected()) {
  1538. lcdDrawUpdate = 2;
  1539. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1540. #if ENABLED(LCD_PROGRESS_BAR)
  1541. currentMenu == lcd_status_screen
  1542. #endif
  1543. );
  1544. if (sd_status) {
  1545. card.initsd();
  1546. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1547. }
  1548. else {
  1549. card.release();
  1550. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1551. }
  1552. lcd_sd_status = sd_status;
  1553. }
  1554. #endif //SDSUPPORT && SD_DETECT_PIN
  1555. millis_t ms = millis();
  1556. if (ms > next_lcd_update_ms) {
  1557. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1558. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1559. #endif
  1560. #if ENABLED(ULTIPANEL)
  1561. #if ENABLED(REPRAPWORLD_KEYPAD)
  1562. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  1563. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  1564. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  1565. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  1566. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  1567. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  1568. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  1569. #endif
  1570. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  1571. if (encoderPastThreshold || LCD_CLICKED) {
  1572. if (encoderPastThreshold) {
  1573. int32_t encoderMultiplier = 1;
  1574. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  1575. if (encoderRateMultiplierEnabled) {
  1576. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  1577. if (lastEncoderMovementMillis != 0) {
  1578. // Note that the rate is always calculated between to passes through the
  1579. // loop and that the abs of the encoderDiff value is tracked.
  1580. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  1581. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  1582. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  1583. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  1584. SERIAL_ECHO_START;
  1585. SERIAL_ECHO("Enc Step Rate: ");
  1586. SERIAL_ECHO(encoderStepRate);
  1587. SERIAL_ECHO(" Multiplier: ");
  1588. SERIAL_ECHO(encoderMultiplier);
  1589. SERIAL_ECHO(" ENCODER_10X_STEPS_PER_SEC: ");
  1590. SERIAL_ECHO(ENCODER_10X_STEPS_PER_SEC);
  1591. SERIAL_ECHO(" ENCODER_100X_STEPS_PER_SEC: ");
  1592. SERIAL_ECHOLN(ENCODER_100X_STEPS_PER_SEC);
  1593. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  1594. }
  1595. lastEncoderMovementMillis = ms;
  1596. } // encoderRateMultiplierEnabled
  1597. #endif //ENCODER_RATE_MULTIPLIER
  1598. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  1599. encoderDiff = 0;
  1600. }
  1601. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  1602. lcdDrawUpdate = 1;
  1603. }
  1604. #endif //ULTIPANEL
  1605. if (currentMenu == lcd_status_screen) {
  1606. if (!lcd_status_update_delay) {
  1607. lcdDrawUpdate = 1;
  1608. lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
  1609. }
  1610. else {
  1611. lcd_status_update_delay--;
  1612. }
  1613. }
  1614. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  1615. if (lcdDrawUpdate) {
  1616. blink++; // Variable for animation and alive dot
  1617. u8g.firstPage();
  1618. do {
  1619. lcd_setFont(FONT_MENU);
  1620. u8g.setPrintPos(125, 0);
  1621. if (blink & 1) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1622. u8g.drawPixel(127, 63); // draw alive dot
  1623. u8g.setColorIndex(1); // black on white
  1624. (*currentMenu)();
  1625. } while (u8g.nextPage());
  1626. }
  1627. #else
  1628. if (lcdDrawUpdate) {
  1629. blink++; // Variable for animation
  1630. (*currentMenu)();
  1631. }
  1632. #endif
  1633. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  1634. lcd_implementation_update_indicators();
  1635. #endif
  1636. #if ENABLED(ULTIPANEL)
  1637. // Return to Status Screen after a timeout
  1638. if (currentMenu != lcd_status_screen &&
  1639. #if ENABLED(MANUAL_BED_LEVELING)
  1640. currentMenu != _lcd_level_bed &&
  1641. currentMenu != _lcd_level_bed_homing &&
  1642. #endif
  1643. millis() > return_to_status_ms
  1644. ) {
  1645. lcd_return_to_status();
  1646. lcdDrawUpdate = 2;
  1647. }
  1648. #endif // ULTIPANEL
  1649. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1650. if (lcdDrawUpdate) lcdDrawUpdate--;
  1651. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  1652. }
  1653. }
  1654. void lcd_ignore_click(bool b) {
  1655. ignore_click = b;
  1656. wait_for_unclick = false;
  1657. }
  1658. void lcd_finishstatus(bool persist=false) {
  1659. #if ENABLED(LCD_PROGRESS_BAR)
  1660. progress_bar_ms = millis();
  1661. #if PROGRESS_MSG_EXPIRE > 0
  1662. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  1663. #endif
  1664. #endif
  1665. lcdDrawUpdate = 2;
  1666. #if ENABLED(FILAMENT_LCD_DISPLAY)
  1667. previous_lcd_status_ms = millis(); //get status message to show up for a while
  1668. #endif
  1669. }
  1670. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  1671. void dontExpireStatus() { expire_status_ms = 0; }
  1672. #endif
  1673. void set_utf_strlen(char* s, uint8_t n) {
  1674. uint8_t i = 0, j = 0;
  1675. while (s[i] && (j < n)) {
  1676. if ((s[i] & 0xc0u) != 0x80u) j++;
  1677. i++;
  1678. }
  1679. while (j++ < n) s[i++] = ' ';
  1680. s[i] = 0;
  1681. }
  1682. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  1683. void lcd_setstatus(const char* message, bool persist) {
  1684. if (lcd_status_message_level > 0) return;
  1685. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  1686. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1687. lcd_finishstatus(persist);
  1688. }
  1689. void lcd_setstatuspgm(const char* message, uint8_t level) {
  1690. if (level >= lcd_status_message_level) {
  1691. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  1692. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1693. lcd_status_message_level = level;
  1694. lcd_finishstatus(level > 0);
  1695. }
  1696. }
  1697. void lcd_setalertstatuspgm(const char* message) {
  1698. lcd_setstatuspgm(message, 1);
  1699. #if ENABLED(ULTIPANEL)
  1700. lcd_return_to_status();
  1701. #endif
  1702. }
  1703. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  1704. #if ENABLED(HAS_LCD_CONTRAST)
  1705. void lcd_setcontrast(uint8_t value) {
  1706. lcd_contrast = value & 0x3F;
  1707. u8g.setContrast(lcd_contrast);
  1708. }
  1709. #endif
  1710. #if ENABLED(ULTIPANEL)
  1711. /**
  1712. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  1713. * These values are independent of which pins are used for EN_A and EN_B indications
  1714. * The rotary encoder part is also independent to the chipset used for the LCD
  1715. */
  1716. #if defined(EN_A) && defined(EN_B)
  1717. #define encrot0 0
  1718. #define encrot1 2
  1719. #define encrot2 3
  1720. #define encrot3 1
  1721. #endif
  1722. /**
  1723. * Read encoder buttons from the hardware registers
  1724. * Warning: This function is called from interrupt context!
  1725. */
  1726. void lcd_buttons_update() {
  1727. #if ENABLED(NEWPANEL)
  1728. uint8_t newbutton = 0;
  1729. #if BTN_EN1 > 0
  1730. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  1731. #endif
  1732. #if BTN_EN2 > 0
  1733. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  1734. #endif
  1735. #if ENABLED(RIGIDBOT_PANEL) || BTN_ENC > 0
  1736. millis_t now = millis();
  1737. #endif
  1738. #if ENABLED(RIGIDBOT_PANEL)
  1739. if (now > next_button_update_ms) {
  1740. if (READ(BTN_UP) == 0) {
  1741. encoderDiff = -1 * (ENCODER_STEPS_PER_MENU_ITEM);
  1742. next_button_update_ms = now + 300;
  1743. }
  1744. else if (READ(BTN_DWN) == 0) {
  1745. encoderDiff = ENCODER_STEPS_PER_MENU_ITEM;
  1746. next_button_update_ms = now + 300;
  1747. }
  1748. else if (READ(BTN_LFT) == 0) {
  1749. encoderDiff = -1 * (ENCODER_PULSES_PER_STEP);
  1750. next_button_update_ms = now + 300;
  1751. }
  1752. else if (READ(BTN_RT) == 0) {
  1753. encoderDiff = ENCODER_PULSES_PER_STEP;
  1754. next_button_update_ms = now + 300;
  1755. }
  1756. }
  1757. #endif
  1758. #if BTN_ENC > 0
  1759. if (now > next_button_update_ms && READ(BTN_ENC) == 0) newbutton |= EN_C;
  1760. #endif
  1761. buttons = newbutton;
  1762. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1763. buttons |= slow_buttons;
  1764. #endif
  1765. #if ENABLED(REPRAPWORLD_KEYPAD)
  1766. // for the reprapworld_keypad
  1767. uint8_t newbutton_reprapworld_keypad = 0;
  1768. WRITE(SHIFT_LD, LOW);
  1769. WRITE(SHIFT_LD, HIGH);
  1770. for (int8_t i = 0; i < 8; i++) {
  1771. newbutton_reprapworld_keypad >>= 1;
  1772. if (READ(SHIFT_OUT)) SBI(newbutton_reprapworld_keypad, 7);
  1773. WRITE(SHIFT_CLK, HIGH);
  1774. WRITE(SHIFT_CLK, LOW);
  1775. }
  1776. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1777. #endif
  1778. #else //read it from the shift register
  1779. uint8_t newbutton = 0;
  1780. WRITE(SHIFT_LD, LOW);
  1781. WRITE(SHIFT_LD, HIGH);
  1782. unsigned char tmp_buttons = 0;
  1783. for (int8_t i = 0; i < 8; i++) {
  1784. newbutton >>= 1;
  1785. if (READ(SHIFT_OUT)) SBI(newbutton, 7);
  1786. WRITE(SHIFT_CLK, HIGH);
  1787. WRITE(SHIFT_CLK, LOW);
  1788. }
  1789. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  1790. #endif //!NEWPANEL
  1791. #if ENABLED(REVERSE_MENU_DIRECTION)
  1792. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  1793. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  1794. #else
  1795. #define ENCODER_DIFF_CW (encoderDiff++)
  1796. #define ENCODER_DIFF_CCW (encoderDiff--)
  1797. #endif
  1798. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  1799. //manage encoder rotation
  1800. uint8_t enc = 0;
  1801. if (buttons & EN_A) enc |= B01;
  1802. if (buttons & EN_B) enc |= B10;
  1803. if (enc != lastEncoderBits) {
  1804. switch (enc) {
  1805. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  1806. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  1807. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  1808. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  1809. }
  1810. }
  1811. lastEncoderBits = enc;
  1812. }
  1813. bool lcd_detected(void) {
  1814. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  1815. return lcd.LcdDetected() == 1;
  1816. #else
  1817. return true;
  1818. #endif
  1819. }
  1820. bool lcd_clicked() { return LCD_CLICKED; }
  1821. #endif // ULTIPANEL
  1822. /*********************************/
  1823. /** Number to string conversion **/
  1824. /*********************************/
  1825. char conv[8];
  1826. // Convert float to rj string with 123 or -12 format
  1827. char *ftostr3(const float& x) { return itostr3((int)x); }
  1828. // Convert float to rj string with _123, -123, _-12, or __-1 format
  1829. char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
  1830. // Convert int to string with 12 format
  1831. char* itostr2(const uint8_t& x) {
  1832. //sprintf(conv,"%5.1f",x);
  1833. int xx = x;
  1834. conv[0] = (xx / 10) % 10 + '0';
  1835. conv[1] = xx % 10 + '0';
  1836. conv[2] = 0;
  1837. return conv;
  1838. }
  1839. // Convert float to string with +123.4 format
  1840. char* ftostr31(const float& x) {
  1841. int xx = abs(x * 10);
  1842. conv[0] = (x >= 0) ? '+' : '-';
  1843. conv[1] = (xx / 1000) % 10 + '0';
  1844. conv[2] = (xx / 100) % 10 + '0';
  1845. conv[3] = (xx / 10) % 10 + '0';
  1846. conv[4] = '.';
  1847. conv[5] = xx % 10 + '0';
  1848. conv[6] = 0;
  1849. return conv;
  1850. }
  1851. // Convert float to string with 123.4 format, dropping sign
  1852. char* ftostr31ns(const float& x) {
  1853. int xx = abs(x * 10);
  1854. conv[0] = (xx / 1000) % 10 + '0';
  1855. conv[1] = (xx / 100) % 10 + '0';
  1856. conv[2] = (xx / 10) % 10 + '0';
  1857. conv[3] = '.';
  1858. conv[4] = xx % 10 + '0';
  1859. conv[5] = 0;
  1860. return conv;
  1861. }
  1862. // Convert float to string with 123.45 format
  1863. char *ftostr32(const float& x) {
  1864. long xx = abs(x * 100);
  1865. conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
  1866. conv[1] = (xx / 1000) % 10 + '0';
  1867. conv[2] = (xx / 100) % 10 + '0';
  1868. conv[3] = '.';
  1869. conv[4] = (xx / 10) % 10 + '0';
  1870. conv[5] = xx % 10 + '0';
  1871. conv[6] = 0;
  1872. return conv;
  1873. }
  1874. // Convert float to string with 1.234 format
  1875. char* ftostr43(const float& x) {
  1876. long xx = x * 1000;
  1877. if (xx >= 0)
  1878. conv[0] = (xx / 1000) % 10 + '0';
  1879. else
  1880. conv[0] = '-';
  1881. xx = abs(xx);
  1882. conv[1] = '.';
  1883. conv[2] = (xx / 100) % 10 + '0';
  1884. conv[3] = (xx / 10) % 10 + '0';
  1885. conv[4] = (xx) % 10 + '0';
  1886. conv[5] = 0;
  1887. return conv;
  1888. }
  1889. // Convert float to string with 1.23 format
  1890. char* ftostr12ns(const float& x) {
  1891. long xx = x * 100;
  1892. xx = abs(xx);
  1893. conv[0] = (xx / 100) % 10 + '0';
  1894. conv[1] = '.';
  1895. conv[2] = (xx / 10) % 10 + '0';
  1896. conv[3] = (xx) % 10 + '0';
  1897. conv[4] = 0;
  1898. return conv;
  1899. }
  1900. // Convert float to space-padded string with -_23.4_ format
  1901. char* ftostr32sp(const float& x) {
  1902. long xx = abs(x * 100);
  1903. uint8_t dig;
  1904. if (x < 0) { // negative val = -_0
  1905. conv[0] = '-';
  1906. dig = (xx / 1000) % 10;
  1907. conv[1] = dig ? '0' + dig : ' ';
  1908. }
  1909. else { // positive val = __0
  1910. dig = (xx / 10000) % 10;
  1911. if (dig) {
  1912. conv[0] = '0' + dig;
  1913. conv[1] = '0' + (xx / 1000) % 10;
  1914. }
  1915. else {
  1916. conv[0] = ' ';
  1917. dig = (xx / 1000) % 10;
  1918. conv[1] = dig ? '0' + dig : ' ';
  1919. }
  1920. }
  1921. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1922. dig = xx % 10;
  1923. if (dig) { // 2 decimal places
  1924. conv[5] = '0' + dig;
  1925. conv[4] = '0' + (xx / 10) % 10;
  1926. conv[3] = '.';
  1927. }
  1928. else { // 1 or 0 decimal place
  1929. dig = (xx / 10) % 10;
  1930. if (dig) {
  1931. conv[4] = '0' + dig;
  1932. conv[3] = '.';
  1933. }
  1934. else {
  1935. conv[3] = conv[4] = ' ';
  1936. }
  1937. conv[5] = ' ';
  1938. }
  1939. conv[6] = '\0';
  1940. return conv;
  1941. }
  1942. // Convert int to lj string with +123.0 format
  1943. char* itostr31(const int& x) {
  1944. conv[0] = x >= 0 ? '+' : '-';
  1945. int xx = abs(x);
  1946. conv[1] = (xx / 100) % 10 + '0';
  1947. conv[2] = (xx / 10) % 10 + '0';
  1948. conv[3] = xx % 10 + '0';
  1949. conv[4] = '.';
  1950. conv[5] = '0';
  1951. conv[6] = 0;
  1952. return conv;
  1953. }
  1954. // Convert int to rj string with 123 or -12 format
  1955. char* itostr3(const int& x) {
  1956. int xx = x;
  1957. if (xx < 0) {
  1958. conv[0] = '-';
  1959. xx = -xx;
  1960. }
  1961. else
  1962. conv[0] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1963. conv[1] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1964. conv[2] = xx % 10 + '0';
  1965. conv[3] = 0;
  1966. return conv;
  1967. }
  1968. // Convert int to lj string with 123 format
  1969. char* itostr3left(const int& xx) {
  1970. if (xx >= 100) {
  1971. conv[0] = (xx / 100) % 10 + '0';
  1972. conv[1] = (xx / 10) % 10 + '0';
  1973. conv[2] = xx % 10 + '0';
  1974. conv[3] = 0;
  1975. }
  1976. else if (xx >= 10) {
  1977. conv[0] = (xx / 10) % 10 + '0';
  1978. conv[1] = xx % 10 + '0';
  1979. conv[2] = 0;
  1980. }
  1981. else {
  1982. conv[0] = xx % 10 + '0';
  1983. conv[1] = 0;
  1984. }
  1985. return conv;
  1986. }
  1987. // Convert int to rj string with 1234 format
  1988. char* itostr4(const int& xx) {
  1989. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1990. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1991. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1992. conv[3] = xx % 10 + '0';
  1993. conv[4] = 0;
  1994. return conv;
  1995. }
  1996. // Convert int to rj string with _123, -123, _-12, or __-1 format
  1997. char *itostr4sign(const int& x) {
  1998. int xx = abs(x);
  1999. int sign = 0;
  2000. if (xx >= 100) {
  2001. conv[1] = (xx / 100) % 10 + '0';
  2002. conv[2] = (xx / 10) % 10 + '0';
  2003. }
  2004. else if (xx >= 10) {
  2005. conv[0] = ' ';
  2006. sign = 1;
  2007. conv[2] = (xx / 10) % 10 + '0';
  2008. }
  2009. else {
  2010. conv[0] = ' ';
  2011. conv[1] = ' ';
  2012. sign = 2;
  2013. }
  2014. conv[sign] = x < 0 ? '-' : ' ';
  2015. conv[3] = xx % 10 + '0';
  2016. conv[4] = 0;
  2017. return conv;
  2018. }
  2019. // Convert float to rj string with 12345 format
  2020. char* ftostr5(const float& x) {
  2021. long xx = abs(x);
  2022. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2023. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2024. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2025. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2026. conv[4] = xx % 10 + '0';
  2027. conv[5] = 0;
  2028. return conv;
  2029. }
  2030. // Convert float to string with +1234.5 format
  2031. char* ftostr51(const float& x) {
  2032. long xx = abs(x * 10);
  2033. conv[0] = (x >= 0) ? '+' : '-';
  2034. conv[1] = (xx / 10000) % 10 + '0';
  2035. conv[2] = (xx / 1000) % 10 + '0';
  2036. conv[3] = (xx / 100) % 10 + '0';
  2037. conv[4] = (xx / 10) % 10 + '0';
  2038. conv[5] = '.';
  2039. conv[6] = xx % 10 + '0';
  2040. conv[7] = 0;
  2041. return conv;
  2042. }
  2043. // Convert float to string with +123.45 format
  2044. char* ftostr52(const float& x) {
  2045. conv[0] = (x >= 0) ? '+' : '-';
  2046. long xx = abs(x * 100);
  2047. conv[1] = (xx / 10000) % 10 + '0';
  2048. conv[2] = (xx / 1000) % 10 + '0';
  2049. conv[3] = (xx / 100) % 10 + '0';
  2050. conv[4] = '.';
  2051. conv[5] = (xx / 10) % 10 + '0';
  2052. conv[6] = xx % 10 + '0';
  2053. conv[7] = 0;
  2054. return conv;
  2055. }
  2056. #if ENABLED(MANUAL_BED_LEVELING)
  2057. static int _lcd_level_bed_position;
  2058. /**
  2059. * MBL Wait for controller movement and clicks:
  2060. * - Movement adjusts the Z axis
  2061. * - Click saves the Z and goes to the next mesh point
  2062. */
  2063. static void _lcd_level_bed() {
  2064. ENCODER_DIRECTION_NORMAL();
  2065. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  2066. refresh_cmd_timeout();
  2067. current_position[Z_AXIS] += float((int)encoderPosition) * (MBL_Z_STEP);
  2068. if (min_software_endstops) NOLESS(current_position[Z_AXIS], Z_MIN_POS);
  2069. if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
  2070. encoderPosition = 0;
  2071. line_to_current(Z_AXIS);
  2072. lcdDrawUpdate = 2;
  2073. }
  2074. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr43(current_position[Z_AXIS]));
  2075. static bool debounce_click = false;
  2076. if (LCD_CLICKED) {
  2077. if (!debounce_click) {
  2078. debounce_click = true;
  2079. int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
  2080. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2081. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2082. mbl.set_z(ix, iy, current_position[Z_AXIS]);
  2083. _lcd_level_bed_position++;
  2084. if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
  2085. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2086. line_to_current(Z_AXIS);
  2087. mbl.active = 1;
  2088. enqueue_and_echo_commands_P(PSTR("G28"));
  2089. lcd_return_to_status();
  2090. }
  2091. else {
  2092. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2093. line_to_current(Z_AXIS);
  2094. ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS);
  2095. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2096. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2097. current_position[X_AXIS] = mbl.get_x(ix);
  2098. current_position[Y_AXIS] = mbl.get_y(iy);
  2099. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2100. lcdDrawUpdate = 2;
  2101. }
  2102. }
  2103. }
  2104. else {
  2105. debounce_click = false;
  2106. }
  2107. }
  2108. /**
  2109. * MBL Move to mesh starting point
  2110. */
  2111. static void _lcd_level_bed_homing() {
  2112. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("XYZ"), (char*)"Homing");
  2113. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]) {
  2114. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2115. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2116. current_position[X_AXIS] = MESH_MIN_X;
  2117. current_position[Y_AXIS] = MESH_MIN_Y;
  2118. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2119. _lcd_level_bed_position = 0;
  2120. lcd_goto_menu(_lcd_level_bed);
  2121. }
  2122. lcdDrawUpdate = 2;
  2123. }
  2124. /**
  2125. * MBL entry-point
  2126. */
  2127. static void lcd_level_bed() {
  2128. axis_known_position[X_AXIS] = axis_known_position[Y_AXIS] = axis_known_position[Z_AXIS] = false;
  2129. mbl.reset();
  2130. enqueue_and_echo_commands_P(PSTR("G28"));
  2131. lcdDrawUpdate = 2;
  2132. lcd_goto_menu(_lcd_level_bed_homing);
  2133. }
  2134. #endif // MANUAL_BED_LEVELING
  2135. #endif // ULTRA_LCD