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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426
  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, PSTR(""));
  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. #if FAN_COUNT > 0
  545. #if HAS_FAN0
  546. #if FAN_COUNT > 1
  547. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  548. #else
  549. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  550. #endif
  551. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  552. #endif
  553. #if HAS_FAN1
  554. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  555. #endif
  556. #if HAS_FAN2
  557. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  558. #endif
  559. #endif // FAN_COUNT > 0
  560. //
  561. // Flow:
  562. // Flow 1:
  563. // Flow 2:
  564. // Flow 3:
  565. // Flow 4:
  566. //
  567. #if EXTRUDERS == 1
  568. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[0], 10, 999);
  569. #else // EXTRUDERS > 1
  570. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[active_extruder], 10, 999);
  571. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &extruder_multiplier[0], 10, 999);
  572. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &extruder_multiplier[1], 10, 999);
  573. #if EXTRUDERS > 2
  574. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &extruder_multiplier[2], 10, 999);
  575. #if EXTRUDERS > 3
  576. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &extruder_multiplier[3], 10, 999);
  577. #endif //EXTRUDERS > 3
  578. #endif //EXTRUDERS > 2
  579. #endif //EXTRUDERS > 1
  580. //
  581. // Babystep X:
  582. // Babystep Y:
  583. // Babystep Z:
  584. //
  585. #if ENABLED(BABYSTEPPING)
  586. #if ENABLED(BABYSTEP_XY)
  587. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  588. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  589. #endif //BABYSTEP_XY
  590. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  591. #endif
  592. //
  593. // Change filament
  594. //
  595. #if ENABLED(FILAMENTCHANGEENABLE)
  596. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  597. #endif
  598. END_MENU();
  599. }
  600. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  601. if (temph > 0) setTargetHotend(temph, endnum);
  602. #if TEMP_SENSOR_BED != 0
  603. setTargetBed(tempb);
  604. #endif
  605. #if FAN_COUNT > 0
  606. #if FAN_COUNT > 1
  607. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  608. #else
  609. fanSpeeds[0] = fan;
  610. #endif
  611. #endif
  612. lcd_return_to_status();
  613. }
  614. #if TEMP_SENSOR_0 != 0
  615. void lcd_preheat_pla0() { _lcd_preheat(0, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  616. void lcd_preheat_abs0() { _lcd_preheat(0, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  617. #endif
  618. #if EXTRUDERS > 1
  619. void lcd_preheat_pla1() { _lcd_preheat(1, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  620. void lcd_preheat_abs1() { _lcd_preheat(1, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  621. #if EXTRUDERS > 2
  622. void lcd_preheat_pla2() { _lcd_preheat(2, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  623. void lcd_preheat_abs2() { _lcd_preheat(2, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  624. #if EXTRUDERS > 3
  625. void lcd_preheat_pla3() { _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  626. void lcd_preheat_abs3() { _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  627. #endif
  628. #endif
  629. void lcd_preheat_pla0123() {
  630. setTargetHotend0(plaPreheatHotendTemp);
  631. setTargetHotend1(plaPreheatHotendTemp);
  632. setTargetHotend2(plaPreheatHotendTemp);
  633. _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed);
  634. }
  635. void lcd_preheat_abs0123() {
  636. setTargetHotend0(absPreheatHotendTemp);
  637. setTargetHotend1(absPreheatHotendTemp);
  638. setTargetHotend2(absPreheatHotendTemp);
  639. _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed);
  640. }
  641. #endif // EXTRUDERS > 1
  642. #if TEMP_SENSOR_BED != 0
  643. void lcd_preheat_pla_bedonly() { _lcd_preheat(0, 0, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  644. void lcd_preheat_abs_bedonly() { _lcd_preheat(0, 0, absPreheatHPBTemp, absPreheatFanSpeed); }
  645. #endif
  646. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  647. static void lcd_preheat_pla_menu() {
  648. START_MENU();
  649. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  650. #if EXTRUDERS == 1
  651. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  652. #else
  653. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H1, lcd_preheat_pla0);
  654. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H2, lcd_preheat_pla1);
  655. #if EXTRUDERS > 2
  656. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H3, lcd_preheat_pla2);
  657. #if EXTRUDERS > 3
  658. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H4, lcd_preheat_pla3);
  659. #endif
  660. #endif
  661. MENU_ITEM(function, MSG_PREHEAT_PLA_ALL, lcd_preheat_pla0123);
  662. #endif
  663. #if TEMP_SENSOR_BED != 0
  664. MENU_ITEM(function, MSG_PREHEAT_PLA_BEDONLY, lcd_preheat_pla_bedonly);
  665. #endif
  666. END_MENU();
  667. }
  668. static void lcd_preheat_abs_menu() {
  669. START_MENU();
  670. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  671. #if EXTRUDERS == 1
  672. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  673. #else
  674. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H1, lcd_preheat_abs0);
  675. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H2, lcd_preheat_abs1);
  676. #if EXTRUDERS > 2
  677. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H3, lcd_preheat_abs2);
  678. #if EXTRUDERS > 3
  679. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H4, lcd_preheat_abs3);
  680. #endif
  681. #endif
  682. MENU_ITEM(function, MSG_PREHEAT_ABS_ALL, lcd_preheat_abs0123);
  683. #endif
  684. #if TEMP_SENSOR_BED != 0
  685. MENU_ITEM(function, MSG_PREHEAT_ABS_BEDONLY, lcd_preheat_abs_bedonly);
  686. #endif
  687. END_MENU();
  688. }
  689. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  690. void lcd_cooldown() {
  691. #if FAN_COUNT > 0
  692. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  693. #endif
  694. disable_all_heaters();
  695. lcd_return_to_status();
  696. }
  697. /**
  698. *
  699. * "Prepare" submenu
  700. *
  701. */
  702. static void lcd_prepare_menu() {
  703. START_MENU();
  704. //
  705. // ^ Main
  706. //
  707. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  708. //
  709. // Auto Home
  710. //
  711. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  712. //
  713. // Set Home Offsets
  714. //
  715. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  716. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  717. //
  718. // Level Bed
  719. //
  720. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  721. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS])
  722. MENU_ITEM(gcode, MSG_LEVEL_BED, PSTR("G29"));
  723. #elif ENABLED(MANUAL_BED_LEVELING)
  724. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  725. #endif
  726. //
  727. // Move Axis
  728. //
  729. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  730. //
  731. // Disable Steppers
  732. //
  733. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  734. //
  735. // Preheat PLA
  736. // Preheat ABS
  737. //
  738. #if TEMP_SENSOR_0 != 0
  739. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  740. MENU_ITEM(submenu, MSG_PREHEAT_PLA, lcd_preheat_pla_menu);
  741. MENU_ITEM(submenu, MSG_PREHEAT_ABS, lcd_preheat_abs_menu);
  742. #else
  743. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  744. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  745. #endif
  746. #endif
  747. //
  748. // Cooldown
  749. //
  750. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  751. //
  752. // Switch power on/off
  753. //
  754. #if HAS_POWER_SWITCH
  755. if (powersupply)
  756. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  757. else
  758. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  759. #endif
  760. //
  761. // Autostart
  762. //
  763. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  764. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  765. #endif
  766. END_MENU();
  767. }
  768. #if ENABLED(DELTA_CALIBRATION_MENU)
  769. static void lcd_delta_calibrate_menu() {
  770. START_MENU();
  771. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  772. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  773. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_X, PSTR("G0 F8000 X-77.94 Y-45 Z0"));
  774. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Y, PSTR("G0 F8000 X77.94 Y-45 Z0"));
  775. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Z, PSTR("G0 F8000 X0 Y90 Z0"));
  776. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_CENTER, PSTR("G0 F8000 X0 Y0 Z0"));
  777. END_MENU();
  778. }
  779. #endif // DELTA_CALIBRATION_MENU
  780. inline void line_to_current(AxisEnum axis) {
  781. #if ENABLED(DELTA)
  782. calculate_delta(current_position);
  783. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  784. #else
  785. 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);
  786. #endif
  787. }
  788. /**
  789. *
  790. * "Prepare" > "Move Axis" submenu
  791. *
  792. */
  793. float move_menu_scale;
  794. static void lcd_move_menu_axis();
  795. static void _lcd_move(const char* name, AxisEnum axis, int min, int max) {
  796. ENCODER_DIRECTION_NORMAL();
  797. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  798. refresh_cmd_timeout();
  799. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  800. if (min_software_endstops) NOLESS(current_position[axis], min);
  801. if (max_software_endstops) NOMORE(current_position[axis], max);
  802. encoderPosition = 0;
  803. line_to_current(axis);
  804. lcdDrawUpdate = 1;
  805. }
  806. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  807. if (LCD_CLICKED) lcd_goto_previous_menu();
  808. }
  809. #if ENABLED(DELTA)
  810. static float delta_clip_radius_2 = (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS);
  811. static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - a*a); }
  812. 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)); }
  813. 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)); }
  814. #else
  815. static void lcd_move_x() { _lcd_move(PSTR(MSG_MOVE_X), X_AXIS, X_MIN_POS, X_MAX_POS); }
  816. static void lcd_move_y() { _lcd_move(PSTR(MSG_MOVE_Y), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
  817. #endif
  818. static void lcd_move_z() { _lcd_move(PSTR(MSG_MOVE_Z), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
  819. static void lcd_move_e(
  820. #if EXTRUDERS > 1
  821. uint8_t e
  822. #endif
  823. ) {
  824. ENCODER_DIRECTION_NORMAL();
  825. #if EXTRUDERS > 1
  826. unsigned short original_active_extruder = active_extruder;
  827. active_extruder = e;
  828. #endif
  829. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  830. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  831. encoderPosition = 0;
  832. line_to_current(E_AXIS);
  833. lcdDrawUpdate = 1;
  834. }
  835. if (lcdDrawUpdate) {
  836. PGM_P pos_label;
  837. #if EXTRUDERS == 1
  838. pos_label = PSTR(MSG_MOVE_E);
  839. #else
  840. switch (e) {
  841. case 0: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  842. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  843. #if EXTRUDERS > 2
  844. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  845. #if EXTRUDERS > 3
  846. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  847. #endif //EXTRUDERS > 3
  848. #endif //EXTRUDERS > 2
  849. }
  850. #endif //EXTRUDERS > 1
  851. lcd_implementation_drawedit(pos_label, ftostr31(current_position[E_AXIS]));
  852. }
  853. if (LCD_CLICKED) lcd_goto_previous_menu();
  854. #if EXTRUDERS > 1
  855. active_extruder = original_active_extruder;
  856. #endif
  857. }
  858. #if EXTRUDERS > 1
  859. static void lcd_move_e0() { lcd_move_e(0); }
  860. static void lcd_move_e1() { lcd_move_e(1); }
  861. #if EXTRUDERS > 2
  862. static void lcd_move_e2() { lcd_move_e(2); }
  863. #if EXTRUDERS > 3
  864. static void lcd_move_e3() { lcd_move_e(3); }
  865. #endif
  866. #endif
  867. #endif // EXTRUDERS > 1
  868. /**
  869. *
  870. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  871. *
  872. */
  873. static void lcd_move_menu_axis() {
  874. START_MENU();
  875. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  876. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  877. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  878. if (move_menu_scale < 10.0) {
  879. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  880. #if EXTRUDERS == 1
  881. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  882. #else
  883. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_e0);
  884. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_e1);
  885. #if EXTRUDERS > 2
  886. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_e2);
  887. #if EXTRUDERS > 3
  888. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_e3);
  889. #endif
  890. #endif
  891. #endif // EXTRUDERS > 1
  892. }
  893. END_MENU();
  894. }
  895. static void lcd_move_menu_10mm() {
  896. move_menu_scale = 10.0;
  897. lcd_move_menu_axis();
  898. }
  899. static void lcd_move_menu_1mm() {
  900. move_menu_scale = 1.0;
  901. lcd_move_menu_axis();
  902. }
  903. static void lcd_move_menu_01mm() {
  904. move_menu_scale = 0.1;
  905. lcd_move_menu_axis();
  906. }
  907. /**
  908. *
  909. * "Prepare" > "Move Axis" submenu
  910. *
  911. */
  912. static void lcd_move_menu() {
  913. START_MENU();
  914. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  915. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  916. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  917. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  918. //TODO:X,Y,Z,E
  919. END_MENU();
  920. }
  921. /**
  922. *
  923. * "Control" submenu
  924. *
  925. */
  926. static void lcd_control_menu() {
  927. START_MENU();
  928. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  929. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  930. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  931. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  932. #if ENABLED(HAS_LCD_CONTRAST)
  933. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  934. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  935. #endif
  936. #if ENABLED(FWRETRACT)
  937. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  938. #endif
  939. #if ENABLED(EEPROM_SETTINGS)
  940. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  941. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  942. #endif
  943. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  944. END_MENU();
  945. }
  946. /**
  947. *
  948. * "Temperature" submenu
  949. *
  950. */
  951. #if ENABLED(PIDTEMP)
  952. // Helpers for editing PID Ki & Kd values
  953. // grab the PID value out of the temp variable; scale it; then update the PID driver
  954. void copy_and_scalePID_i(int e) {
  955. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  956. updatePID();
  957. }
  958. void copy_and_scalePID_d(int e) {
  959. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  960. updatePID();
  961. }
  962. #define COPY_AND_SCALE(eindex) \
  963. void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
  964. void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); }
  965. COPY_AND_SCALE(0);
  966. #if ENABLED(PID_PARAMS_PER_EXTRUDER)
  967. #if EXTRUDERS > 1
  968. COPY_AND_SCALE(1);
  969. #if EXTRUDERS > 2
  970. COPY_AND_SCALE(2);
  971. #if EXTRUDERS > 3
  972. COPY_AND_SCALE(3);
  973. #endif //EXTRUDERS > 3
  974. #endif //EXTRUDERS > 2
  975. #endif //EXTRUDERS > 1
  976. #endif //PID_PARAMS_PER_EXTRUDER
  977. #endif //PIDTEMP
  978. /**
  979. *
  980. * "Control" > "Temperature" submenu
  981. *
  982. */
  983. static void lcd_control_temperature_menu() {
  984. START_MENU();
  985. //
  986. // ^ Control
  987. //
  988. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  989. //
  990. // Nozzle:
  991. // Nozzle [1-4]:
  992. //
  993. #if EXTRUDERS == 1
  994. #if TEMP_SENSOR_0 != 0
  995. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  996. #endif
  997. #else //EXTRUDERS > 1
  998. #if TEMP_SENSOR_0 != 0
  999. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1000. #endif
  1001. #if TEMP_SENSOR_1 != 0
  1002. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1003. #endif
  1004. #if EXTRUDERS > 2
  1005. #if TEMP_SENSOR_2 != 0
  1006. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1007. #endif
  1008. #if EXTRUDERS > 3
  1009. #if TEMP_SENSOR_3 != 0
  1010. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1011. #endif
  1012. #endif // EXTRUDERS > 3
  1013. #endif // EXTRUDERS > 2
  1014. #endif // EXTRUDERS > 1
  1015. //
  1016. // Bed:
  1017. //
  1018. #if TEMP_SENSOR_BED != 0
  1019. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  1020. #endif
  1021. //
  1022. // Fan Speed:
  1023. //
  1024. #if FAN_COUNT > 0
  1025. #if HAS_FAN0
  1026. #if FAN_COUNT > 1
  1027. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1028. #else
  1029. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1030. #endif
  1031. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1032. #endif
  1033. #if HAS_FAN1
  1034. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1035. #endif
  1036. #if HAS_FAN2
  1037. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1038. #endif
  1039. #endif // FAN_COUNT > 0
  1040. //
  1041. // Autotemp, Min, Max, Fact
  1042. //
  1043. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1044. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  1045. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1046. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1047. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  1048. #endif
  1049. //
  1050. // PID-P, PID-I, PID-D, PID-C
  1051. // PID-P E1, PID-I E1, PID-D E1, PID-C E1
  1052. // PID-P E2, PID-I E2, PID-D E2, PID-C E2
  1053. // PID-P E3, PID-I E3, PID-D E3, PID-C E3
  1054. // PID-P E4, PID-I E4, PID-D E4, PID-C E4
  1055. //
  1056. #if ENABLED(PIDTEMP)
  1057. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1058. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1059. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1060. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1061. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1062. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1063. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  1064. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1065. _PID_MENU_ITEMS(ELABEL, eindex); \
  1066. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1067. #else
  1068. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1069. #endif
  1070. #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
  1071. PID_MENU_ITEMS(MSG_E1, 0);
  1072. PID_MENU_ITEMS(MSG_E2, 1);
  1073. #if EXTRUDERS > 2
  1074. PID_MENU_ITEMS(MSG_E3, 2);
  1075. #if EXTRUDERS > 3
  1076. PID_MENU_ITEMS(MSG_E4, 3);
  1077. #endif //EXTRUDERS > 3
  1078. #endif //EXTRUDERS > 2
  1079. #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1080. PID_MENU_ITEMS("", 0);
  1081. #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1082. #endif //PIDTEMP
  1083. //
  1084. // Preheat PLA conf
  1085. //
  1086. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  1087. //
  1088. // Preheat ABS conf
  1089. //
  1090. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  1091. END_MENU();
  1092. }
  1093. /**
  1094. *
  1095. * "Temperature" > "Preheat PLA conf" submenu
  1096. *
  1097. */
  1098. static void lcd_control_temperature_preheat_pla_settings_menu() {
  1099. START_MENU();
  1100. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1101. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  1102. #if TEMP_SENSOR_0 != 0
  1103. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1104. #endif
  1105. #if TEMP_SENSOR_BED != 0
  1106. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1107. #endif
  1108. #if ENABLED(EEPROM_SETTINGS)
  1109. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1110. #endif
  1111. END_MENU();
  1112. }
  1113. /**
  1114. *
  1115. * "Temperature" > "Preheat ABS conf" submenu
  1116. *
  1117. */
  1118. static void lcd_control_temperature_preheat_abs_settings_menu() {
  1119. START_MENU();
  1120. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1121. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  1122. #if TEMP_SENSOR_0 != 0
  1123. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1124. #endif
  1125. #if TEMP_SENSOR_BED != 0
  1126. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1127. #endif
  1128. #if ENABLED(EEPROM_SETTINGS)
  1129. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1130. #endif
  1131. END_MENU();
  1132. }
  1133. /**
  1134. *
  1135. * "Control" > "Motion" submenu
  1136. *
  1137. */
  1138. static void lcd_control_motion_menu() {
  1139. START_MENU();
  1140. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1141. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  1142. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  1143. #endif
  1144. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 10, 99000);
  1145. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  1146. #if ENABLED(DELTA)
  1147. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &max_z_jerk, 1, 990);
  1148. #else
  1149. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  1150. #endif
  1151. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  1152. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  1153. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  1154. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  1155. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  1156. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  1157. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  1158. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  1159. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  1160. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 10, 99000, reset_acceleration_rates);
  1161. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  1162. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  1163. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &travel_acceleration, 100, 99000);
  1164. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  1165. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  1166. #if ENABLED(DELTA)
  1167. MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1168. #else
  1169. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1170. #endif
  1171. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  1172. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  1173. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
  1174. #endif
  1175. #if ENABLED(SCARA)
  1176. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS], 0.5, 2);
  1177. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS], 0.5, 2);
  1178. #endif
  1179. END_MENU();
  1180. }
  1181. /**
  1182. *
  1183. * "Control" > "Filament" submenu
  1184. *
  1185. */
  1186. static void lcd_control_volumetric_menu() {
  1187. START_MENU();
  1188. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1189. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  1190. if (volumetric_enabled) {
  1191. #if EXTRUDERS == 1
  1192. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1193. #else //EXTRUDERS > 1
  1194. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1195. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  1196. #if EXTRUDERS > 2
  1197. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  1198. #if EXTRUDERS > 3
  1199. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  1200. #endif //EXTRUDERS > 3
  1201. #endif //EXTRUDERS > 2
  1202. #endif //EXTRUDERS > 1
  1203. }
  1204. END_MENU();
  1205. }
  1206. /**
  1207. *
  1208. * "Control" > "Contrast" submenu
  1209. *
  1210. */
  1211. #if ENABLED(HAS_LCD_CONTRAST)
  1212. static void lcd_set_contrast() {
  1213. ENCODER_DIRECTION_NORMAL();
  1214. if (encoderPosition != 0) {
  1215. #if ENABLED(U8GLIB_LM6059_AF)
  1216. lcd_contrast += encoderPosition;
  1217. lcd_contrast &= 0xFF;
  1218. #else
  1219. lcd_contrast -= encoderPosition;
  1220. lcd_contrast &= 0x3F;
  1221. #endif
  1222. encoderPosition = 0;
  1223. lcdDrawUpdate = 1;
  1224. u8g.setContrast(lcd_contrast);
  1225. }
  1226. if (lcdDrawUpdate) {
  1227. #if ENABLED(U8GLIB_LM6059_AF)
  1228. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr3(lcd_contrast));
  1229. #else
  1230. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
  1231. #endif
  1232. }
  1233. if (LCD_CLICKED) lcd_goto_previous_menu();
  1234. }
  1235. #endif // HAS_LCD_CONTRAST
  1236. /**
  1237. *
  1238. * "Control" > "Retract" submenu
  1239. *
  1240. */
  1241. #if ENABLED(FWRETRACT)
  1242. static void lcd_control_retract_menu() {
  1243. START_MENU();
  1244. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1245. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  1246. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  1247. #if EXTRUDERS > 1
  1248. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  1249. #endif
  1250. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  1251. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  1252. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  1253. #if EXTRUDERS > 1
  1254. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  1255. #endif
  1256. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  1257. END_MENU();
  1258. }
  1259. #endif // FWRETRACT
  1260. #if ENABLED(SDSUPPORT)
  1261. #if !PIN_EXISTS(SD_DETECT)
  1262. static void lcd_sd_refresh() {
  1263. card.initsd();
  1264. currentMenuViewOffset = 0;
  1265. }
  1266. #endif
  1267. static void lcd_sd_updir() {
  1268. card.updir();
  1269. currentMenuViewOffset = 0;
  1270. }
  1271. /**
  1272. *
  1273. * "Print from SD" submenu
  1274. *
  1275. */
  1276. void lcd_sdcard_menu() {
  1277. ENCODER_DIRECTION_MENUS();
  1278. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
  1279. uint16_t fileCnt = card.getnrfilenames();
  1280. START_MENU();
  1281. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1282. card.getWorkDirName();
  1283. if (card.filename[0] == '/') {
  1284. #if !PIN_EXISTS(SD_DETECT)
  1285. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1286. #endif
  1287. }
  1288. else {
  1289. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1290. }
  1291. for (uint16_t i = 0; i < fileCnt; i++) {
  1292. if (_menuItemNr == _lineNr) {
  1293. card.getfilename(
  1294. #if ENABLED(SDCARD_RATHERRECENTFIRST)
  1295. fileCnt-1 -
  1296. #endif
  1297. i
  1298. );
  1299. if (card.filenameIsDir)
  1300. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1301. else
  1302. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1303. }
  1304. else {
  1305. MENU_ITEM_DUMMY();
  1306. }
  1307. }
  1308. END_MENU();
  1309. }
  1310. #endif //SDSUPPORT
  1311. /**
  1312. *
  1313. * Functions for editing single values
  1314. *
  1315. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  1316. *
  1317. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  1318. *
  1319. * bool _menu_edit_int3();
  1320. * void menu_edit_int3(); // edit int (interactively)
  1321. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  1322. * static void _menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1323. * static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1324. * static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callback); // edit int with callback
  1325. *
  1326. * You can then use one of the menu macros to present the edit interface:
  1327. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  1328. *
  1329. * This expands into a more primitive menu item:
  1330. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1331. *
  1332. *
  1333. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  1334. *
  1335. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1336. */
  1337. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1338. bool _menu_edit_ ## _name () { \
  1339. ENCODER_DIRECTION_NORMAL(); \
  1340. bool isClicked = LCD_CLICKED; \
  1341. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1342. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1343. if (lcdDrawUpdate) \
  1344. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1345. if (isClicked) { \
  1346. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1347. lcd_goto_previous_menu(); \
  1348. } \
  1349. return isClicked; \
  1350. } \
  1351. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  1352. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  1353. static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1354. lcd_save_previous_menu(); \
  1355. \
  1356. lcdDrawUpdate = 2; \
  1357. currentMenu = menu_edit_ ## _name; \
  1358. \
  1359. editLabel = pstr; \
  1360. editValue = ptr; \
  1361. minEditValue = minValue * scale; \
  1362. maxEditValue = maxValue * scale - minEditValue; \
  1363. encoderPosition = (*ptr) * scale - minEditValue; \
  1364. } \
  1365. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1366. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1367. currentMenu = menu_edit_ ## _name; \
  1368. }\
  1369. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) { \
  1370. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1371. currentMenu = menu_edit_callback_ ## _name; \
  1372. callbackFunc = callback; \
  1373. }
  1374. menu_edit_type(int, int3, itostr3, 1)
  1375. menu_edit_type(float, float3, ftostr3, 1)
  1376. menu_edit_type(float, float32, ftostr32, 100)
  1377. menu_edit_type(float, float43, ftostr43, 1000)
  1378. menu_edit_type(float, float5, ftostr5, 0.01)
  1379. menu_edit_type(float, float51, ftostr51, 10)
  1380. menu_edit_type(float, float52, ftostr52, 100)
  1381. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1382. /**
  1383. *
  1384. * Handlers for RepRap World Keypad input
  1385. *
  1386. */
  1387. #if ENABLED(REPRAPWORLD_KEYPAD)
  1388. static void reprapworld_keypad_move_z_up() {
  1389. encoderPosition = 1;
  1390. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1391. lcd_move_z();
  1392. }
  1393. static void reprapworld_keypad_move_z_down() {
  1394. encoderPosition = -1;
  1395. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1396. lcd_move_z();
  1397. }
  1398. static void reprapworld_keypad_move_x_left() {
  1399. encoderPosition = -1;
  1400. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1401. lcd_move_x();
  1402. }
  1403. static void reprapworld_keypad_move_x_right() {
  1404. encoderPosition = 1;
  1405. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1406. lcd_move_x();
  1407. }
  1408. static void reprapworld_keypad_move_y_down() {
  1409. encoderPosition = 1;
  1410. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1411. lcd_move_y();
  1412. }
  1413. static void reprapworld_keypad_move_y_up() {
  1414. encoderPosition = -1;
  1415. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1416. lcd_move_y();
  1417. }
  1418. static void reprapworld_keypad_move_home() {
  1419. enqueue_and_echo_commands_P((PSTR("G28"))); // move all axis home
  1420. }
  1421. #endif // REPRAPWORLD_KEYPAD
  1422. /**
  1423. *
  1424. * Audio feedback for controller clicks
  1425. *
  1426. */
  1427. #if ENABLED(LCD_USE_I2C_BUZZER)
  1428. void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
  1429. lcd.buzz(duration, freq);
  1430. }
  1431. #endif
  1432. void lcd_quick_feedback() {
  1433. lcdDrawUpdate = 2;
  1434. next_button_update_ms = millis() + 500;
  1435. #if ENABLED(LCD_USE_I2C_BUZZER)
  1436. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1437. #define LCD_FEEDBACK_FREQUENCY_HZ 100
  1438. #endif
  1439. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1440. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
  1441. #endif
  1442. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1443. #elif PIN_EXISTS(BEEPER)
  1444. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1445. #define LCD_FEEDBACK_FREQUENCY_HZ 5000
  1446. #endif
  1447. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1448. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1449. #endif
  1450. buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1451. #else
  1452. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1453. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1454. #endif
  1455. delay(LCD_FEEDBACK_FREQUENCY_DURATION_MS);
  1456. #endif
  1457. }
  1458. /**
  1459. *
  1460. * Menu actions
  1461. *
  1462. */
  1463. static void menu_action_back(menuFunc_t func) { lcd_goto_menu(func); }
  1464. static void menu_action_submenu(menuFunc_t func) { lcd_save_previous_menu(); lcd_goto_menu(func); }
  1465. static void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  1466. static void menu_action_function(menuFunc_t func) { (*func)(); }
  1467. #if ENABLED(SDSUPPORT)
  1468. static void menu_action_sdfile(const char* filename, char* longFilename) {
  1469. card.openAndPrintFile(filename);
  1470. lcd_return_to_status();
  1471. }
  1472. static void menu_action_sddirectory(const char* filename, char* longFilename) {
  1473. card.chdir(filename);
  1474. encoderPosition = 0;
  1475. }
  1476. #endif //SDSUPPORT
  1477. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { *ptr = !(*ptr); }
  1478. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback) {
  1479. menu_action_setting_edit_bool(pstr, ptr);
  1480. (*callback)();
  1481. }
  1482. #endif //ULTIPANEL
  1483. /** LCD API **/
  1484. void lcd_init() {
  1485. lcd_implementation_init();
  1486. #if ENABLED(NEWPANEL)
  1487. #if BTN_EN1 > 0
  1488. SET_INPUT(BTN_EN1);
  1489. WRITE(BTN_EN1, HIGH);
  1490. #endif
  1491. #if BTN_EN2 > 0
  1492. SET_INPUT(BTN_EN2);
  1493. WRITE(BTN_EN2, HIGH);
  1494. #endif
  1495. #if BTN_ENC > 0
  1496. SET_INPUT(BTN_ENC);
  1497. WRITE(BTN_ENC, HIGH);
  1498. #endif
  1499. #if ENABLED(REPRAPWORLD_KEYPAD)
  1500. pinMode(SHIFT_CLK, OUTPUT);
  1501. pinMode(SHIFT_LD, OUTPUT);
  1502. pinMode(SHIFT_OUT, INPUT);
  1503. WRITE(SHIFT_OUT, HIGH);
  1504. WRITE(SHIFT_LD, HIGH);
  1505. #endif
  1506. #ifdef RIGIDBOT_PANEL
  1507. SET_INPUT(BTN_UP);
  1508. SET_INPUT(BTN_DWN);
  1509. SET_INPUT(BTN_LFT);
  1510. SET_INPUT(BTN_RT);
  1511. #endif
  1512. #else // Not NEWPANEL
  1513. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  1514. pinMode(SR_DATA_PIN, OUTPUT);
  1515. pinMode(SR_CLK_PIN, OUTPUT);
  1516. #elif defined(SHIFT_CLK)
  1517. pinMode(SHIFT_CLK, OUTPUT);
  1518. pinMode(SHIFT_LD, OUTPUT);
  1519. pinMode(SHIFT_EN, OUTPUT);
  1520. pinMode(SHIFT_OUT, INPUT);
  1521. WRITE(SHIFT_OUT, HIGH);
  1522. WRITE(SHIFT_LD, HIGH);
  1523. WRITE(SHIFT_EN, LOW);
  1524. #endif // SR_LCD_2W_NL
  1525. #endif//!NEWPANEL
  1526. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1527. SET_INPUT(SD_DETECT_PIN);
  1528. WRITE(SD_DETECT_PIN, HIGH);
  1529. lcd_sd_status = 2; // UNKNOWN
  1530. #endif
  1531. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1532. slow_buttons = 0;
  1533. #endif
  1534. lcd_buttons_update();
  1535. #if ENABLED(ULTIPANEL)
  1536. encoderDiff = 0;
  1537. #endif
  1538. }
  1539. int lcd_strlen(const char* s) {
  1540. int i = 0, j = 0;
  1541. while (s[i]) {
  1542. if ((s[i] & 0xc0) != 0x80) j++;
  1543. i++;
  1544. }
  1545. return j;
  1546. }
  1547. int lcd_strlen_P(const char* s) {
  1548. int j = 0;
  1549. while (pgm_read_byte(s)) {
  1550. if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
  1551. s++;
  1552. }
  1553. return j;
  1554. }
  1555. /**
  1556. * Update the LCD, read encoder buttons, etc.
  1557. * - Read button states
  1558. * - Check the SD Card slot state
  1559. * - Act on RepRap World keypad input
  1560. * - Update the encoder position
  1561. * - Apply acceleration to the encoder position
  1562. * - Reset the Info Screen timeout if there's any input
  1563. * - Update status indicators, if any
  1564. * - Clear the LCD if lcdDrawUpdate == 2
  1565. *
  1566. * Warning: This function is called from interrupt context!
  1567. */
  1568. void lcd_update() {
  1569. #if ENABLED(ULTIPANEL)
  1570. static millis_t return_to_status_ms = 0;
  1571. #endif
  1572. lcd_buttons_update();
  1573. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1574. bool sd_status = IS_SD_INSERTED;
  1575. if (sd_status != lcd_sd_status && lcd_detected()) {
  1576. lcdDrawUpdate = 2;
  1577. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1578. #if ENABLED(LCD_PROGRESS_BAR)
  1579. currentMenu == lcd_status_screen
  1580. #endif
  1581. );
  1582. if (sd_status) {
  1583. card.initsd();
  1584. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1585. }
  1586. else {
  1587. card.release();
  1588. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1589. }
  1590. lcd_sd_status = sd_status;
  1591. }
  1592. #endif //SDSUPPORT && SD_DETECT_PIN
  1593. millis_t ms = millis();
  1594. if (ms > next_lcd_update_ms) {
  1595. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1596. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1597. #endif
  1598. #if ENABLED(ULTIPANEL)
  1599. #if ENABLED(REPRAPWORLD_KEYPAD)
  1600. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  1601. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  1602. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  1603. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  1604. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  1605. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  1606. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  1607. #endif
  1608. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  1609. if (encoderPastThreshold || LCD_CLICKED) {
  1610. if (encoderPastThreshold) {
  1611. int32_t encoderMultiplier = 1;
  1612. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  1613. if (encoderRateMultiplierEnabled) {
  1614. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  1615. if (lastEncoderMovementMillis != 0) {
  1616. // Note that the rate is always calculated between to passes through the
  1617. // loop and that the abs of the encoderDiff value is tracked.
  1618. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  1619. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  1620. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  1621. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  1622. SERIAL_ECHO_START;
  1623. SERIAL_ECHO("Enc Step Rate: ");
  1624. SERIAL_ECHO(encoderStepRate);
  1625. SERIAL_ECHO(" Multiplier: ");
  1626. SERIAL_ECHO(encoderMultiplier);
  1627. SERIAL_ECHO(" ENCODER_10X_STEPS_PER_SEC: ");
  1628. SERIAL_ECHO(ENCODER_10X_STEPS_PER_SEC);
  1629. SERIAL_ECHO(" ENCODER_100X_STEPS_PER_SEC: ");
  1630. SERIAL_ECHOLN(ENCODER_100X_STEPS_PER_SEC);
  1631. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  1632. }
  1633. lastEncoderMovementMillis = ms;
  1634. } // encoderRateMultiplierEnabled
  1635. #endif //ENCODER_RATE_MULTIPLIER
  1636. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  1637. encoderDiff = 0;
  1638. }
  1639. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  1640. lcdDrawUpdate = 1;
  1641. }
  1642. #endif //ULTIPANEL
  1643. if (currentMenu == lcd_status_screen) {
  1644. if (!lcd_status_update_delay) {
  1645. lcdDrawUpdate = 1;
  1646. 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 */
  1647. }
  1648. else {
  1649. lcd_status_update_delay--;
  1650. }
  1651. }
  1652. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  1653. if (lcdDrawUpdate) {
  1654. blink++; // Variable for animation and alive dot
  1655. u8g.firstPage();
  1656. do {
  1657. lcd_setFont(FONT_MENU);
  1658. u8g.setPrintPos(125, 0);
  1659. if (blink & 1) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1660. u8g.drawPixel(127, 63); // draw alive dot
  1661. u8g.setColorIndex(1); // black on white
  1662. (*currentMenu)();
  1663. } while (u8g.nextPage());
  1664. }
  1665. #else
  1666. if (lcdDrawUpdate) {
  1667. blink++; // Variable for animation
  1668. (*currentMenu)();
  1669. }
  1670. #endif
  1671. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  1672. lcd_implementation_update_indicators();
  1673. #endif
  1674. #if ENABLED(ULTIPANEL)
  1675. // Return to Status Screen after a timeout
  1676. if (currentMenu != lcd_status_screen &&
  1677. #if ENABLED(MANUAL_BED_LEVELING)
  1678. currentMenu != _lcd_level_bed &&
  1679. currentMenu != _lcd_level_bed_homing &&
  1680. #endif
  1681. millis() > return_to_status_ms
  1682. ) {
  1683. lcd_return_to_status();
  1684. lcdDrawUpdate = 2;
  1685. }
  1686. #endif // ULTIPANEL
  1687. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1688. if (lcdDrawUpdate) lcdDrawUpdate--;
  1689. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  1690. }
  1691. }
  1692. void lcd_ignore_click(bool b) {
  1693. ignore_click = b;
  1694. wait_for_unclick = false;
  1695. }
  1696. void lcd_finishstatus(bool persist=false) {
  1697. #if ENABLED(LCD_PROGRESS_BAR)
  1698. progress_bar_ms = millis();
  1699. #if PROGRESS_MSG_EXPIRE > 0
  1700. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  1701. #endif
  1702. #endif
  1703. lcdDrawUpdate = 2;
  1704. #if ENABLED(FILAMENT_LCD_DISPLAY)
  1705. previous_lcd_status_ms = millis(); //get status message to show up for a while
  1706. #endif
  1707. }
  1708. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  1709. void dontExpireStatus() { expire_status_ms = 0; }
  1710. #endif
  1711. void set_utf_strlen(char* s, uint8_t n) {
  1712. uint8_t i = 0, j = 0;
  1713. while (s[i] && (j < n)) {
  1714. if ((s[i] & 0xc0u) != 0x80u) j++;
  1715. i++;
  1716. }
  1717. while (j++ < n) s[i++] = ' ';
  1718. s[i] = 0;
  1719. }
  1720. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  1721. void lcd_setstatus(const char* message, bool persist) {
  1722. if (lcd_status_message_level > 0) return;
  1723. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  1724. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1725. lcd_finishstatus(persist);
  1726. }
  1727. void lcd_setstatuspgm(const char* message, uint8_t level) {
  1728. if (level >= lcd_status_message_level) {
  1729. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  1730. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1731. lcd_status_message_level = level;
  1732. lcd_finishstatus(level > 0);
  1733. }
  1734. }
  1735. void lcd_setalertstatuspgm(const char* message) {
  1736. lcd_setstatuspgm(message, 1);
  1737. #if ENABLED(ULTIPANEL)
  1738. lcd_return_to_status();
  1739. #endif
  1740. }
  1741. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  1742. #if ENABLED(HAS_LCD_CONTRAST)
  1743. void lcd_setcontrast(uint8_t value) {
  1744. lcd_contrast = value & 0x3F;
  1745. u8g.setContrast(lcd_contrast);
  1746. }
  1747. #endif
  1748. #if ENABLED(ULTIPANEL)
  1749. /**
  1750. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  1751. * These values are independent of which pins are used for EN_A and EN_B indications
  1752. * The rotary encoder part is also independent to the chipset used for the LCD
  1753. */
  1754. #if defined(EN_A) && defined(EN_B)
  1755. #define encrot0 0
  1756. #define encrot1 2
  1757. #define encrot2 3
  1758. #define encrot3 1
  1759. #endif
  1760. /**
  1761. * Read encoder buttons from the hardware registers
  1762. * Warning: This function is called from interrupt context!
  1763. */
  1764. void lcd_buttons_update() {
  1765. #if ENABLED(NEWPANEL)
  1766. uint8_t newbutton = 0;
  1767. #if BTN_EN1 > 0
  1768. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  1769. #endif
  1770. #if BTN_EN2 > 0
  1771. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  1772. #endif
  1773. #if ENABLED(RIGIDBOT_PANEL) || BTN_ENC > 0
  1774. millis_t now = millis();
  1775. #endif
  1776. #if ENABLED(RIGIDBOT_PANEL)
  1777. if (now > next_button_update_ms) {
  1778. if (READ(BTN_UP) == 0) {
  1779. encoderDiff = -1 * (ENCODER_STEPS_PER_MENU_ITEM);
  1780. next_button_update_ms = now + 300;
  1781. }
  1782. else if (READ(BTN_DWN) == 0) {
  1783. encoderDiff = ENCODER_STEPS_PER_MENU_ITEM;
  1784. next_button_update_ms = now + 300;
  1785. }
  1786. else if (READ(BTN_LFT) == 0) {
  1787. encoderDiff = -1 * (ENCODER_PULSES_PER_STEP);
  1788. next_button_update_ms = now + 300;
  1789. }
  1790. else if (READ(BTN_RT) == 0) {
  1791. encoderDiff = ENCODER_PULSES_PER_STEP;
  1792. next_button_update_ms = now + 300;
  1793. }
  1794. }
  1795. #endif
  1796. #if BTN_ENC > 0
  1797. if (now > next_button_update_ms && READ(BTN_ENC) == 0) newbutton |= EN_C;
  1798. #endif
  1799. buttons = newbutton;
  1800. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1801. buttons |= slow_buttons;
  1802. #endif
  1803. #if ENABLED(REPRAPWORLD_KEYPAD)
  1804. // for the reprapworld_keypad
  1805. uint8_t newbutton_reprapworld_keypad = 0;
  1806. WRITE(SHIFT_LD, LOW);
  1807. WRITE(SHIFT_LD, HIGH);
  1808. for (int8_t i = 0; i < 8; i++) {
  1809. newbutton_reprapworld_keypad >>= 1;
  1810. if (READ(SHIFT_OUT)) SBI(newbutton_reprapworld_keypad, 7);
  1811. WRITE(SHIFT_CLK, HIGH);
  1812. WRITE(SHIFT_CLK, LOW);
  1813. }
  1814. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1815. #endif
  1816. #else //read it from the shift register
  1817. uint8_t newbutton = 0;
  1818. WRITE(SHIFT_LD, LOW);
  1819. WRITE(SHIFT_LD, HIGH);
  1820. unsigned char tmp_buttons = 0;
  1821. for (int8_t i = 0; i < 8; i++) {
  1822. newbutton >>= 1;
  1823. if (READ(SHIFT_OUT)) SBI(newbutton, 7);
  1824. WRITE(SHIFT_CLK, HIGH);
  1825. WRITE(SHIFT_CLK, LOW);
  1826. }
  1827. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  1828. #endif //!NEWPANEL
  1829. #if ENABLED(REVERSE_MENU_DIRECTION)
  1830. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  1831. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  1832. #else
  1833. #define ENCODER_DIFF_CW (encoderDiff++)
  1834. #define ENCODER_DIFF_CCW (encoderDiff--)
  1835. #endif
  1836. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  1837. //manage encoder rotation
  1838. uint8_t enc = 0;
  1839. if (buttons & EN_A) enc |= B01;
  1840. if (buttons & EN_B) enc |= B10;
  1841. if (enc != lastEncoderBits) {
  1842. switch (enc) {
  1843. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  1844. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  1845. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  1846. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  1847. }
  1848. }
  1849. lastEncoderBits = enc;
  1850. }
  1851. bool lcd_detected(void) {
  1852. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  1853. return lcd.LcdDetected() == 1;
  1854. #else
  1855. return true;
  1856. #endif
  1857. }
  1858. bool lcd_clicked() { return LCD_CLICKED; }
  1859. #endif // ULTIPANEL
  1860. /*********************************/
  1861. /** Number to string conversion **/
  1862. /*********************************/
  1863. char conv[8];
  1864. // Convert float to rj string with 123 or -12 format
  1865. char *ftostr3(const float& x) { return itostr3((int)x); }
  1866. // Convert float to rj string with _123, -123, _-12, or __-1 format
  1867. char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
  1868. // Convert int to string with 12 format
  1869. char* itostr2(const uint8_t& x) {
  1870. //sprintf(conv,"%5.1f",x);
  1871. int xx = x;
  1872. conv[0] = (xx / 10) % 10 + '0';
  1873. conv[1] = xx % 10 + '0';
  1874. conv[2] = 0;
  1875. return conv;
  1876. }
  1877. // Convert float to string with +123.4 format
  1878. char* ftostr31(const float& x) {
  1879. int xx = abs(x * 10);
  1880. conv[0] = (x >= 0) ? '+' : '-';
  1881. conv[1] = (xx / 1000) % 10 + '0';
  1882. conv[2] = (xx / 100) % 10 + '0';
  1883. conv[3] = (xx / 10) % 10 + '0';
  1884. conv[4] = '.';
  1885. conv[5] = xx % 10 + '0';
  1886. conv[6] = 0;
  1887. return conv;
  1888. }
  1889. // Convert float to string with 123.4 format, dropping sign
  1890. char* ftostr31ns(const float& x) {
  1891. int xx = abs(x * 10);
  1892. conv[0] = (xx / 1000) % 10 + '0';
  1893. conv[1] = (xx / 100) % 10 + '0';
  1894. conv[2] = (xx / 10) % 10 + '0';
  1895. conv[3] = '.';
  1896. conv[4] = xx % 10 + '0';
  1897. conv[5] = 0;
  1898. return conv;
  1899. }
  1900. // Convert float to string with 123.45 format
  1901. char *ftostr32(const float& x) {
  1902. long xx = abs(x * 100);
  1903. conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
  1904. conv[1] = (xx / 1000) % 10 + '0';
  1905. conv[2] = (xx / 100) % 10 + '0';
  1906. conv[3] = '.';
  1907. conv[4] = (xx / 10) % 10 + '0';
  1908. conv[5] = xx % 10 + '0';
  1909. conv[6] = 0;
  1910. return conv;
  1911. }
  1912. // Convert float to string with 1.234 format
  1913. char* ftostr43(const float& x) {
  1914. long xx = x * 1000;
  1915. if (xx >= 0)
  1916. conv[0] = (xx / 1000) % 10 + '0';
  1917. else
  1918. conv[0] = '-';
  1919. xx = abs(xx);
  1920. conv[1] = '.';
  1921. conv[2] = (xx / 100) % 10 + '0';
  1922. conv[3] = (xx / 10) % 10 + '0';
  1923. conv[4] = (xx) % 10 + '0';
  1924. conv[5] = 0;
  1925. return conv;
  1926. }
  1927. // Convert float to string with 1.23 format
  1928. char* ftostr12ns(const float& x) {
  1929. long xx = x * 100;
  1930. xx = abs(xx);
  1931. conv[0] = (xx / 100) % 10 + '0';
  1932. conv[1] = '.';
  1933. conv[2] = (xx / 10) % 10 + '0';
  1934. conv[3] = (xx) % 10 + '0';
  1935. conv[4] = 0;
  1936. return conv;
  1937. }
  1938. // Convert float to space-padded string with -_23.4_ format
  1939. char* ftostr32sp(const float& x) {
  1940. long xx = abs(x * 100);
  1941. uint8_t dig;
  1942. if (x < 0) { // negative val = -_0
  1943. conv[0] = '-';
  1944. dig = (xx / 1000) % 10;
  1945. conv[1] = dig ? '0' + dig : ' ';
  1946. }
  1947. else { // positive val = __0
  1948. dig = (xx / 10000) % 10;
  1949. if (dig) {
  1950. conv[0] = '0' + dig;
  1951. conv[1] = '0' + (xx / 1000) % 10;
  1952. }
  1953. else {
  1954. conv[0] = ' ';
  1955. dig = (xx / 1000) % 10;
  1956. conv[1] = dig ? '0' + dig : ' ';
  1957. }
  1958. }
  1959. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1960. dig = xx % 10;
  1961. if (dig) { // 2 decimal places
  1962. conv[5] = '0' + dig;
  1963. conv[4] = '0' + (xx / 10) % 10;
  1964. conv[3] = '.';
  1965. }
  1966. else { // 1 or 0 decimal place
  1967. dig = (xx / 10) % 10;
  1968. if (dig) {
  1969. conv[4] = '0' + dig;
  1970. conv[3] = '.';
  1971. }
  1972. else {
  1973. conv[3] = conv[4] = ' ';
  1974. }
  1975. conv[5] = ' ';
  1976. }
  1977. conv[6] = '\0';
  1978. return conv;
  1979. }
  1980. // Convert int to lj string with +123.0 format
  1981. char* itostr31(const int& x) {
  1982. conv[0] = x >= 0 ? '+' : '-';
  1983. int xx = abs(x);
  1984. conv[1] = (xx / 100) % 10 + '0';
  1985. conv[2] = (xx / 10) % 10 + '0';
  1986. conv[3] = xx % 10 + '0';
  1987. conv[4] = '.';
  1988. conv[5] = '0';
  1989. conv[6] = 0;
  1990. return conv;
  1991. }
  1992. // Convert int to rj string with 123 or -12 format
  1993. char* itostr3(const int& x) {
  1994. int xx = x;
  1995. if (xx < 0) {
  1996. conv[0] = '-';
  1997. xx = -xx;
  1998. }
  1999. else
  2000. conv[0] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2001. conv[1] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2002. conv[2] = xx % 10 + '0';
  2003. conv[3] = 0;
  2004. return conv;
  2005. }
  2006. // Convert int to lj string with 123 format
  2007. char* itostr3left(const int& xx) {
  2008. if (xx >= 100) {
  2009. conv[0] = (xx / 100) % 10 + '0';
  2010. conv[1] = (xx / 10) % 10 + '0';
  2011. conv[2] = xx % 10 + '0';
  2012. conv[3] = 0;
  2013. }
  2014. else if (xx >= 10) {
  2015. conv[0] = (xx / 10) % 10 + '0';
  2016. conv[1] = xx % 10 + '0';
  2017. conv[2] = 0;
  2018. }
  2019. else {
  2020. conv[0] = xx % 10 + '0';
  2021. conv[1] = 0;
  2022. }
  2023. return conv;
  2024. }
  2025. // Convert int to rj string with 1234 format
  2026. char* itostr4(const int& xx) {
  2027. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2028. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2029. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2030. conv[3] = xx % 10 + '0';
  2031. conv[4] = 0;
  2032. return conv;
  2033. }
  2034. // Convert int to rj string with _123, -123, _-12, or __-1 format
  2035. char *itostr4sign(const int& x) {
  2036. int xx = abs(x);
  2037. int sign = 0;
  2038. if (xx >= 100) {
  2039. conv[1] = (xx / 100) % 10 + '0';
  2040. conv[2] = (xx / 10) % 10 + '0';
  2041. }
  2042. else if (xx >= 10) {
  2043. conv[0] = ' ';
  2044. sign = 1;
  2045. conv[2] = (xx / 10) % 10 + '0';
  2046. }
  2047. else {
  2048. conv[0] = ' ';
  2049. conv[1] = ' ';
  2050. sign = 2;
  2051. }
  2052. conv[sign] = x < 0 ? '-' : ' ';
  2053. conv[3] = xx % 10 + '0';
  2054. conv[4] = 0;
  2055. return conv;
  2056. }
  2057. // Convert float to rj string with 12345 format
  2058. char* ftostr5(const float& x) {
  2059. long xx = abs(x);
  2060. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2061. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2062. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2063. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2064. conv[4] = xx % 10 + '0';
  2065. conv[5] = 0;
  2066. return conv;
  2067. }
  2068. // Convert float to string with +1234.5 format
  2069. char* ftostr51(const float& x) {
  2070. long xx = abs(x * 10);
  2071. conv[0] = (x >= 0) ? '+' : '-';
  2072. conv[1] = (xx / 10000) % 10 + '0';
  2073. conv[2] = (xx / 1000) % 10 + '0';
  2074. conv[3] = (xx / 100) % 10 + '0';
  2075. conv[4] = (xx / 10) % 10 + '0';
  2076. conv[5] = '.';
  2077. conv[6] = xx % 10 + '0';
  2078. conv[7] = 0;
  2079. return conv;
  2080. }
  2081. // Convert float to string with +123.45 format
  2082. char* ftostr52(const float& x) {
  2083. conv[0] = (x >= 0) ? '+' : '-';
  2084. long xx = abs(x * 100);
  2085. conv[1] = (xx / 10000) % 10 + '0';
  2086. conv[2] = (xx / 1000) % 10 + '0';
  2087. conv[3] = (xx / 100) % 10 + '0';
  2088. conv[4] = '.';
  2089. conv[5] = (xx / 10) % 10 + '0';
  2090. conv[6] = xx % 10 + '0';
  2091. conv[7] = 0;
  2092. return conv;
  2093. }
  2094. #if ENABLED(MANUAL_BED_LEVELING)
  2095. static int _lcd_level_bed_position;
  2096. /**
  2097. * MBL Wait for controller movement and clicks:
  2098. * - Movement adjusts the Z axis
  2099. * - Click saves the Z and goes to the next mesh point
  2100. */
  2101. static void _lcd_level_bed() {
  2102. ENCODER_DIRECTION_NORMAL();
  2103. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  2104. refresh_cmd_timeout();
  2105. current_position[Z_AXIS] += float((int)encoderPosition) * (MBL_Z_STEP);
  2106. if (min_software_endstops) NOLESS(current_position[Z_AXIS], Z_MIN_POS);
  2107. if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
  2108. encoderPosition = 0;
  2109. line_to_current(Z_AXIS);
  2110. lcdDrawUpdate = 2;
  2111. }
  2112. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr43(current_position[Z_AXIS]));
  2113. static bool debounce_click = false;
  2114. if (LCD_CLICKED) {
  2115. if (!debounce_click) {
  2116. debounce_click = true;
  2117. int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
  2118. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2119. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2120. mbl.set_z(ix, iy, current_position[Z_AXIS]);
  2121. _lcd_level_bed_position++;
  2122. if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
  2123. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2124. line_to_current(Z_AXIS);
  2125. mbl.active = 1;
  2126. enqueue_and_echo_commands_P(PSTR("G28"));
  2127. lcd_return_to_status();
  2128. }
  2129. else {
  2130. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2131. line_to_current(Z_AXIS);
  2132. ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS);
  2133. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2134. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2135. current_position[X_AXIS] = mbl.get_x(ix);
  2136. current_position[Y_AXIS] = mbl.get_y(iy);
  2137. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2138. lcdDrawUpdate = 2;
  2139. }
  2140. }
  2141. }
  2142. else {
  2143. debounce_click = false;
  2144. }
  2145. }
  2146. /**
  2147. * MBL Move to mesh starting point
  2148. */
  2149. static void _lcd_level_bed_homing() {
  2150. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("XYZ"), PSTR(MSG_LEVEL_BED_HOMING));
  2151. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]) {
  2152. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2153. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2154. current_position[X_AXIS] = MESH_MIN_X;
  2155. current_position[Y_AXIS] = MESH_MIN_Y;
  2156. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2157. _lcd_level_bed_position = 0;
  2158. lcd_goto_menu(_lcd_level_bed);
  2159. }
  2160. lcdDrawUpdate = 2;
  2161. }
  2162. /**
  2163. * MBL entry-point
  2164. */
  2165. static void lcd_level_bed() {
  2166. axis_known_position[X_AXIS] = axis_known_position[Y_AXIS] = axis_known_position[Z_AXIS] = false;
  2167. mbl.reset();
  2168. enqueue_and_echo_commands_P(PSTR("G28"));
  2169. lcdDrawUpdate = 2;
  2170. lcd_goto_menu(_lcd_level_bed_homing);
  2171. }
  2172. #endif // MANUAL_BED_LEVELING
  2173. #endif // ULTRA_LCD