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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  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) || ENABLED(PIDTEMPBED)
  952. #if ENABLED(PIDTEMP)
  953. int autotune_temp[EXTRUDERS] = { 150 };
  954. const int heater_maxtemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP);
  955. #endif
  956. #if ENABLED(PIDTEMPBED)
  957. int autotune_temp_bed = 70;
  958. #endif
  959. static void _lcd_autotune(int e) {
  960. char cmd[30];
  961. sprintf_P(cmd, PSTR("M303 U1 E%d S%d"), e,
  962. #if ENABLED(PIDTEMP) && ENABLED(PIDTEMPBED)
  963. e < 0 ? autotune_temp_bed : autotune_temp[e]
  964. #elif ENABLED(PIDTEMPBED)
  965. autotune_temp_bed
  966. #else
  967. autotune_temp[e]
  968. #endif
  969. );
  970. enqueue_and_echo_command_now(cmd);
  971. }
  972. #endif //PIDTEMP || PIDTEMPBED
  973. #if ENABLED(PIDTEMP)
  974. // Helpers for editing PID Ki & Kd values
  975. // grab the PID value out of the temp variable; scale it; then update the PID driver
  976. void copy_and_scalePID_i(int e) {
  977. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  978. updatePID();
  979. }
  980. void copy_and_scalePID_d(int e) {
  981. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  982. updatePID();
  983. }
  984. #define _PIDTEMP_FUNCTIONS(eindex) \
  985. void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
  986. void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); } \
  987. void lcd_autotune_callback_E ## eindex() { _lcd_autotune(eindex); }
  988. _PIDTEMP_FUNCTIONS(0);
  989. #if ENABLED(PID_PARAMS_PER_EXTRUDER)
  990. #if EXTRUDERS > 1
  991. _PIDTEMP_FUNCTIONS(1);
  992. #if EXTRUDERS > 2
  993. _PIDTEMP_FUNCTIONS(2);
  994. #if EXTRUDERS > 3
  995. _PIDTEMP_FUNCTIONS(3);
  996. #endif //EXTRUDERS > 3
  997. #endif //EXTRUDERS > 2
  998. #endif //EXTRUDERS > 1
  999. #endif //PID_PARAMS_PER_EXTRUDER
  1000. #endif //PIDTEMP
  1001. /**
  1002. *
  1003. * "Control" > "Temperature" submenu
  1004. *
  1005. */
  1006. static void lcd_control_temperature_menu() {
  1007. START_MENU();
  1008. //
  1009. // ^ Control
  1010. //
  1011. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1012. //
  1013. // Nozzle:
  1014. // Nozzle [1-4]:
  1015. //
  1016. #if EXTRUDERS == 1
  1017. #if TEMP_SENSOR_0 != 0
  1018. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1019. #endif
  1020. #else //EXTRUDERS > 1
  1021. #if TEMP_SENSOR_0 != 0
  1022. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1023. #endif
  1024. #if TEMP_SENSOR_1 != 0
  1025. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1026. #endif
  1027. #if EXTRUDERS > 2
  1028. #if TEMP_SENSOR_2 != 0
  1029. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1030. #endif
  1031. #if EXTRUDERS > 3
  1032. #if TEMP_SENSOR_3 != 0
  1033. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1034. #endif
  1035. #endif // EXTRUDERS > 3
  1036. #endif // EXTRUDERS > 2
  1037. #endif // EXTRUDERS > 1
  1038. //
  1039. // Bed:
  1040. //
  1041. #if TEMP_SENSOR_BED != 0
  1042. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  1043. #endif
  1044. //
  1045. // Fan Speed:
  1046. //
  1047. #if FAN_COUNT > 0
  1048. #if HAS_FAN0
  1049. #if FAN_COUNT > 1
  1050. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1051. #else
  1052. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1053. #endif
  1054. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1055. #endif
  1056. #if HAS_FAN1
  1057. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1058. #endif
  1059. #if HAS_FAN2
  1060. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1061. #endif
  1062. #endif // FAN_COUNT > 0
  1063. //
  1064. // Autotemp, Min, Max, Fact
  1065. //
  1066. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1067. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  1068. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1069. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1070. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  1071. #endif
  1072. //
  1073. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  1074. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  1075. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  1076. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  1077. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  1078. //
  1079. #if ENABLED(PIDTEMP)
  1080. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  1081. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1082. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1083. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1084. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1085. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1086. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  1087. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1088. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  1089. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1090. #else
  1091. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  1092. #endif
  1093. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1094. _PID_MENU_ITEMS(ELABEL, eindex); \
  1095. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  1096. #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
  1097. PID_MENU_ITEMS(MSG_E1, 0);
  1098. PID_MENU_ITEMS(MSG_E2, 1);
  1099. #if EXTRUDERS > 2
  1100. PID_MENU_ITEMS(MSG_E3, 2);
  1101. #if EXTRUDERS > 3
  1102. PID_MENU_ITEMS(MSG_E4, 3);
  1103. #endif //EXTRUDERS > 3
  1104. #endif //EXTRUDERS > 2
  1105. #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1106. PID_MENU_ITEMS("", 0);
  1107. #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1108. #endif //PIDTEMP
  1109. //
  1110. // Preheat PLA conf
  1111. //
  1112. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  1113. //
  1114. // Preheat ABS conf
  1115. //
  1116. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  1117. END_MENU();
  1118. }
  1119. /**
  1120. *
  1121. * "Temperature" > "Preheat PLA conf" submenu
  1122. *
  1123. */
  1124. static void lcd_control_temperature_preheat_pla_settings_menu() {
  1125. START_MENU();
  1126. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1127. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  1128. #if TEMP_SENSOR_0 != 0
  1129. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1130. #endif
  1131. #if TEMP_SENSOR_BED != 0
  1132. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1133. #endif
  1134. #if ENABLED(EEPROM_SETTINGS)
  1135. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1136. #endif
  1137. END_MENU();
  1138. }
  1139. /**
  1140. *
  1141. * "Temperature" > "Preheat ABS conf" submenu
  1142. *
  1143. */
  1144. static void lcd_control_temperature_preheat_abs_settings_menu() {
  1145. START_MENU();
  1146. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1147. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  1148. #if TEMP_SENSOR_0 != 0
  1149. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1150. #endif
  1151. #if TEMP_SENSOR_BED != 0
  1152. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1153. #endif
  1154. #if ENABLED(EEPROM_SETTINGS)
  1155. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1156. #endif
  1157. END_MENU();
  1158. }
  1159. /**
  1160. *
  1161. * "Control" > "Motion" submenu
  1162. *
  1163. */
  1164. static void lcd_control_motion_menu() {
  1165. START_MENU();
  1166. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1167. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  1168. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  1169. #endif
  1170. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 10, 99000);
  1171. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  1172. #if ENABLED(DELTA)
  1173. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &max_z_jerk, 1, 990);
  1174. #else
  1175. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  1176. #endif
  1177. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  1178. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  1179. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  1180. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  1181. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  1182. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  1183. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  1184. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  1185. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  1186. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 10, 99000, reset_acceleration_rates);
  1187. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  1188. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  1189. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &travel_acceleration, 100, 99000);
  1190. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  1191. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  1192. #if ENABLED(DELTA)
  1193. MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1194. #else
  1195. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1196. #endif
  1197. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  1198. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  1199. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
  1200. #endif
  1201. #if ENABLED(SCARA)
  1202. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS], 0.5, 2);
  1203. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS], 0.5, 2);
  1204. #endif
  1205. END_MENU();
  1206. }
  1207. /**
  1208. *
  1209. * "Control" > "Filament" submenu
  1210. *
  1211. */
  1212. static void lcd_control_volumetric_menu() {
  1213. START_MENU();
  1214. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1215. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  1216. if (volumetric_enabled) {
  1217. #if EXTRUDERS == 1
  1218. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1219. #else //EXTRUDERS > 1
  1220. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1221. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  1222. #if EXTRUDERS > 2
  1223. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  1224. #if EXTRUDERS > 3
  1225. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  1226. #endif //EXTRUDERS > 3
  1227. #endif //EXTRUDERS > 2
  1228. #endif //EXTRUDERS > 1
  1229. }
  1230. END_MENU();
  1231. }
  1232. /**
  1233. *
  1234. * "Control" > "Contrast" submenu
  1235. *
  1236. */
  1237. #if ENABLED(HAS_LCD_CONTRAST)
  1238. static void lcd_set_contrast() {
  1239. ENCODER_DIRECTION_NORMAL();
  1240. if (encoderPosition != 0) {
  1241. #if ENABLED(U8GLIB_LM6059_AF)
  1242. lcd_contrast += encoderPosition;
  1243. lcd_contrast &= 0xFF;
  1244. #else
  1245. lcd_contrast -= encoderPosition;
  1246. lcd_contrast &= 0x3F;
  1247. #endif
  1248. encoderPosition = 0;
  1249. lcdDrawUpdate = 1;
  1250. u8g.setContrast(lcd_contrast);
  1251. }
  1252. if (lcdDrawUpdate) {
  1253. #if ENABLED(U8GLIB_LM6059_AF)
  1254. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr3(lcd_contrast));
  1255. #else
  1256. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
  1257. #endif
  1258. }
  1259. if (LCD_CLICKED) lcd_goto_previous_menu();
  1260. }
  1261. #endif // HAS_LCD_CONTRAST
  1262. /**
  1263. *
  1264. * "Control" > "Retract" submenu
  1265. *
  1266. */
  1267. #if ENABLED(FWRETRACT)
  1268. static void lcd_control_retract_menu() {
  1269. START_MENU();
  1270. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1271. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  1272. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  1273. #if EXTRUDERS > 1
  1274. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  1275. #endif
  1276. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  1277. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  1278. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  1279. #if EXTRUDERS > 1
  1280. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  1281. #endif
  1282. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  1283. END_MENU();
  1284. }
  1285. #endif // FWRETRACT
  1286. #if ENABLED(SDSUPPORT)
  1287. #if !PIN_EXISTS(SD_DETECT)
  1288. static void lcd_sd_refresh() {
  1289. card.initsd();
  1290. currentMenuViewOffset = 0;
  1291. }
  1292. #endif
  1293. static void lcd_sd_updir() {
  1294. card.updir();
  1295. currentMenuViewOffset = 0;
  1296. }
  1297. /**
  1298. *
  1299. * "Print from SD" submenu
  1300. *
  1301. */
  1302. void lcd_sdcard_menu() {
  1303. ENCODER_DIRECTION_MENUS();
  1304. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
  1305. uint16_t fileCnt = card.getnrfilenames();
  1306. START_MENU();
  1307. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1308. card.getWorkDirName();
  1309. if (card.filename[0] == '/') {
  1310. #if !PIN_EXISTS(SD_DETECT)
  1311. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1312. #endif
  1313. }
  1314. else {
  1315. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1316. }
  1317. for (uint16_t i = 0; i < fileCnt; i++) {
  1318. if (_menuItemNr == _lineNr) {
  1319. card.getfilename(
  1320. #if ENABLED(SDCARD_RATHERRECENTFIRST)
  1321. fileCnt-1 -
  1322. #endif
  1323. i
  1324. );
  1325. if (card.filenameIsDir)
  1326. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1327. else
  1328. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1329. }
  1330. else {
  1331. MENU_ITEM_DUMMY();
  1332. }
  1333. }
  1334. END_MENU();
  1335. }
  1336. #endif //SDSUPPORT
  1337. /**
  1338. *
  1339. * Functions for editing single values
  1340. *
  1341. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  1342. *
  1343. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  1344. *
  1345. * bool _menu_edit_int3();
  1346. * void menu_edit_int3(); // edit int (interactively)
  1347. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  1348. * static void _menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1349. * static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1350. * static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callback); // edit int with callback
  1351. *
  1352. * You can then use one of the menu macros to present the edit interface:
  1353. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  1354. *
  1355. * This expands into a more primitive menu item:
  1356. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1357. *
  1358. *
  1359. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  1360. *
  1361. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1362. */
  1363. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1364. bool _menu_edit_ ## _name () { \
  1365. ENCODER_DIRECTION_NORMAL(); \
  1366. bool isClicked = LCD_CLICKED; \
  1367. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1368. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1369. if (lcdDrawUpdate) \
  1370. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1371. if (isClicked) { \
  1372. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1373. lcd_goto_previous_menu(); \
  1374. } \
  1375. return isClicked; \
  1376. } \
  1377. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  1378. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  1379. static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1380. lcd_save_previous_menu(); \
  1381. \
  1382. lcdDrawUpdate = 2; \
  1383. currentMenu = menu_edit_ ## _name; \
  1384. \
  1385. editLabel = pstr; \
  1386. editValue = ptr; \
  1387. minEditValue = minValue * scale; \
  1388. maxEditValue = maxValue * scale - minEditValue; \
  1389. encoderPosition = (*ptr) * scale - minEditValue; \
  1390. } \
  1391. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1392. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1393. currentMenu = menu_edit_ ## _name; \
  1394. }\
  1395. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) { \
  1396. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1397. currentMenu = menu_edit_callback_ ## _name; \
  1398. callbackFunc = callback; \
  1399. }
  1400. menu_edit_type(int, int3, itostr3, 1)
  1401. menu_edit_type(float, float3, ftostr3, 1)
  1402. menu_edit_type(float, float32, ftostr32, 100)
  1403. menu_edit_type(float, float43, ftostr43, 1000)
  1404. menu_edit_type(float, float5, ftostr5, 0.01)
  1405. menu_edit_type(float, float51, ftostr51, 10)
  1406. menu_edit_type(float, float52, ftostr52, 100)
  1407. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1408. /**
  1409. *
  1410. * Handlers for RepRap World Keypad input
  1411. *
  1412. */
  1413. #if ENABLED(REPRAPWORLD_KEYPAD)
  1414. static void reprapworld_keypad_move_z_up() {
  1415. encoderPosition = 1;
  1416. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1417. lcd_move_z();
  1418. }
  1419. static void reprapworld_keypad_move_z_down() {
  1420. encoderPosition = -1;
  1421. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1422. lcd_move_z();
  1423. }
  1424. static void reprapworld_keypad_move_x_left() {
  1425. encoderPosition = -1;
  1426. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1427. lcd_move_x();
  1428. }
  1429. static void reprapworld_keypad_move_x_right() {
  1430. encoderPosition = 1;
  1431. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1432. lcd_move_x();
  1433. }
  1434. static void reprapworld_keypad_move_y_down() {
  1435. encoderPosition = 1;
  1436. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1437. lcd_move_y();
  1438. }
  1439. static void reprapworld_keypad_move_y_up() {
  1440. encoderPosition = -1;
  1441. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1442. lcd_move_y();
  1443. }
  1444. static void reprapworld_keypad_move_home() {
  1445. enqueue_and_echo_commands_P((PSTR("G28"))); // move all axis home
  1446. }
  1447. #endif // REPRAPWORLD_KEYPAD
  1448. /**
  1449. *
  1450. * Audio feedback for controller clicks
  1451. *
  1452. */
  1453. #if ENABLED(LCD_USE_I2C_BUZZER)
  1454. void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
  1455. lcd.buzz(duration, freq);
  1456. }
  1457. #endif
  1458. void lcd_quick_feedback() {
  1459. lcdDrawUpdate = 2;
  1460. next_button_update_ms = millis() + 500;
  1461. #if ENABLED(LCD_USE_I2C_BUZZER)
  1462. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1463. #define LCD_FEEDBACK_FREQUENCY_HZ 100
  1464. #endif
  1465. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1466. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
  1467. #endif
  1468. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1469. #elif PIN_EXISTS(BEEPER)
  1470. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1471. #define LCD_FEEDBACK_FREQUENCY_HZ 5000
  1472. #endif
  1473. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1474. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1475. #endif
  1476. buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1477. #else
  1478. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1479. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1480. #endif
  1481. delay(LCD_FEEDBACK_FREQUENCY_DURATION_MS);
  1482. #endif
  1483. }
  1484. /**
  1485. *
  1486. * Menu actions
  1487. *
  1488. */
  1489. static void menu_action_back(menuFunc_t func) { lcd_goto_menu(func); }
  1490. static void menu_action_submenu(menuFunc_t func) { lcd_save_previous_menu(); lcd_goto_menu(func); }
  1491. static void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  1492. static void menu_action_function(menuFunc_t func) { (*func)(); }
  1493. #if ENABLED(SDSUPPORT)
  1494. static void menu_action_sdfile(const char* filename, char* longFilename) {
  1495. card.openAndPrintFile(filename);
  1496. lcd_return_to_status();
  1497. }
  1498. static void menu_action_sddirectory(const char* filename, char* longFilename) {
  1499. card.chdir(filename);
  1500. encoderPosition = 0;
  1501. }
  1502. #endif //SDSUPPORT
  1503. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { *ptr = !(*ptr); }
  1504. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback) {
  1505. menu_action_setting_edit_bool(pstr, ptr);
  1506. (*callback)();
  1507. }
  1508. #endif //ULTIPANEL
  1509. /** LCD API **/
  1510. void lcd_init() {
  1511. lcd_implementation_init();
  1512. #if ENABLED(NEWPANEL)
  1513. #if BTN_EN1 > 0
  1514. SET_INPUT(BTN_EN1);
  1515. WRITE(BTN_EN1, HIGH);
  1516. #endif
  1517. #if BTN_EN2 > 0
  1518. SET_INPUT(BTN_EN2);
  1519. WRITE(BTN_EN2, HIGH);
  1520. #endif
  1521. #if BTN_ENC > 0
  1522. SET_INPUT(BTN_ENC);
  1523. WRITE(BTN_ENC, HIGH);
  1524. #endif
  1525. #if ENABLED(REPRAPWORLD_KEYPAD)
  1526. pinMode(SHIFT_CLK, OUTPUT);
  1527. pinMode(SHIFT_LD, OUTPUT);
  1528. pinMode(SHIFT_OUT, INPUT);
  1529. WRITE(SHIFT_OUT, HIGH);
  1530. WRITE(SHIFT_LD, HIGH);
  1531. #endif
  1532. #ifdef RIGIDBOT_PANEL
  1533. SET_INPUT(BTN_UP);
  1534. SET_INPUT(BTN_DWN);
  1535. SET_INPUT(BTN_LFT);
  1536. SET_INPUT(BTN_RT);
  1537. #endif
  1538. #else // Not NEWPANEL
  1539. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  1540. pinMode(SR_DATA_PIN, OUTPUT);
  1541. pinMode(SR_CLK_PIN, OUTPUT);
  1542. #elif defined(SHIFT_CLK)
  1543. pinMode(SHIFT_CLK, OUTPUT);
  1544. pinMode(SHIFT_LD, OUTPUT);
  1545. pinMode(SHIFT_EN, OUTPUT);
  1546. pinMode(SHIFT_OUT, INPUT);
  1547. WRITE(SHIFT_OUT, HIGH);
  1548. WRITE(SHIFT_LD, HIGH);
  1549. WRITE(SHIFT_EN, LOW);
  1550. #endif // SR_LCD_2W_NL
  1551. #endif//!NEWPANEL
  1552. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1553. SET_INPUT(SD_DETECT_PIN);
  1554. WRITE(SD_DETECT_PIN, HIGH);
  1555. lcd_sd_status = 2; // UNKNOWN
  1556. #endif
  1557. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1558. slow_buttons = 0;
  1559. #endif
  1560. lcd_buttons_update();
  1561. #if ENABLED(ULTIPANEL)
  1562. encoderDiff = 0;
  1563. #endif
  1564. }
  1565. int lcd_strlen(const char* s) {
  1566. int i = 0, j = 0;
  1567. while (s[i]) {
  1568. if ((s[i] & 0xc0) != 0x80) j++;
  1569. i++;
  1570. }
  1571. return j;
  1572. }
  1573. int lcd_strlen_P(const char* s) {
  1574. int j = 0;
  1575. while (pgm_read_byte(s)) {
  1576. if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
  1577. s++;
  1578. }
  1579. return j;
  1580. }
  1581. /**
  1582. * Update the LCD, read encoder buttons, etc.
  1583. * - Read button states
  1584. * - Check the SD Card slot state
  1585. * - Act on RepRap World keypad input
  1586. * - Update the encoder position
  1587. * - Apply acceleration to the encoder position
  1588. * - Reset the Info Screen timeout if there's any input
  1589. * - Update status indicators, if any
  1590. * - Clear the LCD if lcdDrawUpdate == 2
  1591. *
  1592. * Warning: This function is called from interrupt context!
  1593. */
  1594. void lcd_update() {
  1595. #if ENABLED(ULTIPANEL)
  1596. static millis_t return_to_status_ms = 0;
  1597. #endif
  1598. lcd_buttons_update();
  1599. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1600. bool sd_status = IS_SD_INSERTED;
  1601. if (sd_status != lcd_sd_status && lcd_detected()) {
  1602. lcdDrawUpdate = 2;
  1603. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1604. #if ENABLED(LCD_PROGRESS_BAR)
  1605. currentMenu == lcd_status_screen
  1606. #endif
  1607. );
  1608. if (sd_status) {
  1609. card.initsd();
  1610. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1611. }
  1612. else {
  1613. card.release();
  1614. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1615. }
  1616. lcd_sd_status = sd_status;
  1617. }
  1618. #endif //SDSUPPORT && SD_DETECT_PIN
  1619. millis_t ms = millis();
  1620. if (ms > next_lcd_update_ms) {
  1621. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1622. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1623. #endif
  1624. #if ENABLED(ULTIPANEL)
  1625. #if ENABLED(REPRAPWORLD_KEYPAD)
  1626. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  1627. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  1628. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  1629. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  1630. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  1631. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  1632. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  1633. #endif
  1634. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  1635. if (encoderPastThreshold || LCD_CLICKED) {
  1636. if (encoderPastThreshold) {
  1637. int32_t encoderMultiplier = 1;
  1638. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  1639. if (encoderRateMultiplierEnabled) {
  1640. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  1641. if (lastEncoderMovementMillis != 0) {
  1642. // Note that the rate is always calculated between to passes through the
  1643. // loop and that the abs of the encoderDiff value is tracked.
  1644. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  1645. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  1646. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  1647. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  1648. SERIAL_ECHO_START;
  1649. SERIAL_ECHO("Enc Step Rate: ");
  1650. SERIAL_ECHO(encoderStepRate);
  1651. SERIAL_ECHO(" Multiplier: ");
  1652. SERIAL_ECHO(encoderMultiplier);
  1653. SERIAL_ECHO(" ENCODER_10X_STEPS_PER_SEC: ");
  1654. SERIAL_ECHO(ENCODER_10X_STEPS_PER_SEC);
  1655. SERIAL_ECHO(" ENCODER_100X_STEPS_PER_SEC: ");
  1656. SERIAL_ECHOLN(ENCODER_100X_STEPS_PER_SEC);
  1657. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  1658. }
  1659. lastEncoderMovementMillis = ms;
  1660. } // encoderRateMultiplierEnabled
  1661. #endif //ENCODER_RATE_MULTIPLIER
  1662. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  1663. encoderDiff = 0;
  1664. }
  1665. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  1666. lcdDrawUpdate = 1;
  1667. }
  1668. #endif //ULTIPANEL
  1669. if (currentMenu == lcd_status_screen) {
  1670. if (!lcd_status_update_delay) {
  1671. lcdDrawUpdate = 1;
  1672. 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 */
  1673. }
  1674. else {
  1675. lcd_status_update_delay--;
  1676. }
  1677. }
  1678. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  1679. if (lcdDrawUpdate) {
  1680. blink++; // Variable for animation and alive dot
  1681. u8g.firstPage();
  1682. do {
  1683. lcd_setFont(FONT_MENU);
  1684. u8g.setPrintPos(125, 0);
  1685. if (blink & 1) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1686. u8g.drawPixel(127, 63); // draw alive dot
  1687. u8g.setColorIndex(1); // black on white
  1688. (*currentMenu)();
  1689. } while (u8g.nextPage());
  1690. }
  1691. #else
  1692. if (lcdDrawUpdate) {
  1693. blink++; // Variable for animation
  1694. (*currentMenu)();
  1695. }
  1696. #endif
  1697. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  1698. lcd_implementation_update_indicators();
  1699. #endif
  1700. #if ENABLED(ULTIPANEL)
  1701. // Return to Status Screen after a timeout
  1702. if (currentMenu != lcd_status_screen &&
  1703. #if ENABLED(MANUAL_BED_LEVELING)
  1704. currentMenu != _lcd_level_bed &&
  1705. currentMenu != _lcd_level_bed_homing &&
  1706. #endif
  1707. millis() > return_to_status_ms
  1708. ) {
  1709. lcd_return_to_status();
  1710. lcdDrawUpdate = 2;
  1711. }
  1712. #endif // ULTIPANEL
  1713. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1714. if (lcdDrawUpdate) lcdDrawUpdate--;
  1715. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  1716. }
  1717. }
  1718. void lcd_ignore_click(bool b) {
  1719. ignore_click = b;
  1720. wait_for_unclick = false;
  1721. }
  1722. void lcd_finishstatus(bool persist=false) {
  1723. #if ENABLED(LCD_PROGRESS_BAR)
  1724. progress_bar_ms = millis();
  1725. #if PROGRESS_MSG_EXPIRE > 0
  1726. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  1727. #endif
  1728. #endif
  1729. lcdDrawUpdate = 2;
  1730. #if ENABLED(FILAMENT_LCD_DISPLAY)
  1731. previous_lcd_status_ms = millis(); //get status message to show up for a while
  1732. #endif
  1733. }
  1734. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  1735. void dontExpireStatus() { expire_status_ms = 0; }
  1736. #endif
  1737. void set_utf_strlen(char* s, uint8_t n) {
  1738. uint8_t i = 0, j = 0;
  1739. while (s[i] && (j < n)) {
  1740. if ((s[i] & 0xc0u) != 0x80u) j++;
  1741. i++;
  1742. }
  1743. while (j++ < n) s[i++] = ' ';
  1744. s[i] = 0;
  1745. }
  1746. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  1747. void lcd_setstatus(const char* message, bool persist) {
  1748. if (lcd_status_message_level > 0) return;
  1749. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  1750. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1751. lcd_finishstatus(persist);
  1752. }
  1753. void lcd_setstatuspgm(const char* message, uint8_t level) {
  1754. if (level >= lcd_status_message_level) {
  1755. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  1756. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1757. lcd_status_message_level = level;
  1758. lcd_finishstatus(level > 0);
  1759. }
  1760. }
  1761. void lcd_setalertstatuspgm(const char* message) {
  1762. lcd_setstatuspgm(message, 1);
  1763. #if ENABLED(ULTIPANEL)
  1764. lcd_return_to_status();
  1765. #endif
  1766. }
  1767. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  1768. #if ENABLED(HAS_LCD_CONTRAST)
  1769. void lcd_setcontrast(uint8_t value) {
  1770. lcd_contrast = value & 0x3F;
  1771. u8g.setContrast(lcd_contrast);
  1772. }
  1773. #endif
  1774. #if ENABLED(ULTIPANEL)
  1775. /**
  1776. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  1777. * These values are independent of which pins are used for EN_A and EN_B indications
  1778. * The rotary encoder part is also independent to the chipset used for the LCD
  1779. */
  1780. #if defined(EN_A) && defined(EN_B)
  1781. #define encrot0 0
  1782. #define encrot1 2
  1783. #define encrot2 3
  1784. #define encrot3 1
  1785. #endif
  1786. /**
  1787. * Read encoder buttons from the hardware registers
  1788. * Warning: This function is called from interrupt context!
  1789. */
  1790. void lcd_buttons_update() {
  1791. #if ENABLED(NEWPANEL)
  1792. uint8_t newbutton = 0;
  1793. #if BTN_EN1 > 0
  1794. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  1795. #endif
  1796. #if BTN_EN2 > 0
  1797. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  1798. #endif
  1799. #if ENABLED(RIGIDBOT_PANEL) || BTN_ENC > 0
  1800. millis_t now = millis();
  1801. #endif
  1802. #if ENABLED(RIGIDBOT_PANEL)
  1803. if (now > next_button_update_ms) {
  1804. if (READ(BTN_UP) == 0) {
  1805. encoderDiff = -1 * (ENCODER_STEPS_PER_MENU_ITEM);
  1806. next_button_update_ms = now + 300;
  1807. }
  1808. else if (READ(BTN_DWN) == 0) {
  1809. encoderDiff = ENCODER_STEPS_PER_MENU_ITEM;
  1810. next_button_update_ms = now + 300;
  1811. }
  1812. else if (READ(BTN_LFT) == 0) {
  1813. encoderDiff = -1 * (ENCODER_PULSES_PER_STEP);
  1814. next_button_update_ms = now + 300;
  1815. }
  1816. else if (READ(BTN_RT) == 0) {
  1817. encoderDiff = ENCODER_PULSES_PER_STEP;
  1818. next_button_update_ms = now + 300;
  1819. }
  1820. }
  1821. #endif
  1822. #if BTN_ENC > 0
  1823. if (now > next_button_update_ms && READ(BTN_ENC) == 0) newbutton |= EN_C;
  1824. #endif
  1825. buttons = newbutton;
  1826. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1827. buttons |= slow_buttons;
  1828. #endif
  1829. #if ENABLED(REPRAPWORLD_KEYPAD)
  1830. // for the reprapworld_keypad
  1831. uint8_t newbutton_reprapworld_keypad = 0;
  1832. WRITE(SHIFT_LD, LOW);
  1833. WRITE(SHIFT_LD, HIGH);
  1834. for (int8_t i = 0; i < 8; i++) {
  1835. newbutton_reprapworld_keypad >>= 1;
  1836. if (READ(SHIFT_OUT)) SBI(newbutton_reprapworld_keypad, 7);
  1837. WRITE(SHIFT_CLK, HIGH);
  1838. WRITE(SHIFT_CLK, LOW);
  1839. }
  1840. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1841. #endif
  1842. #else //read it from the shift register
  1843. uint8_t newbutton = 0;
  1844. WRITE(SHIFT_LD, LOW);
  1845. WRITE(SHIFT_LD, HIGH);
  1846. unsigned char tmp_buttons = 0;
  1847. for (int8_t i = 0; i < 8; i++) {
  1848. newbutton >>= 1;
  1849. if (READ(SHIFT_OUT)) SBI(newbutton, 7);
  1850. WRITE(SHIFT_CLK, HIGH);
  1851. WRITE(SHIFT_CLK, LOW);
  1852. }
  1853. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  1854. #endif //!NEWPANEL
  1855. #if ENABLED(REVERSE_MENU_DIRECTION)
  1856. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  1857. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  1858. #else
  1859. #define ENCODER_DIFF_CW (encoderDiff++)
  1860. #define ENCODER_DIFF_CCW (encoderDiff--)
  1861. #endif
  1862. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  1863. //manage encoder rotation
  1864. uint8_t enc = 0;
  1865. if (buttons & EN_A) enc |= B01;
  1866. if (buttons & EN_B) enc |= B10;
  1867. if (enc != lastEncoderBits) {
  1868. switch (enc) {
  1869. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  1870. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  1871. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  1872. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  1873. }
  1874. }
  1875. lastEncoderBits = enc;
  1876. }
  1877. bool lcd_detected(void) {
  1878. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  1879. return lcd.LcdDetected() == 1;
  1880. #else
  1881. return true;
  1882. #endif
  1883. }
  1884. bool lcd_clicked() { return LCD_CLICKED; }
  1885. #endif // ULTIPANEL
  1886. /*********************************/
  1887. /** Number to string conversion **/
  1888. /*********************************/
  1889. char conv[8];
  1890. // Convert float to rj string with 123 or -12 format
  1891. char *ftostr3(const float& x) { return itostr3((int)x); }
  1892. // Convert float to rj string with _123, -123, _-12, or __-1 format
  1893. char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
  1894. // Convert int to string with 12 format
  1895. char* itostr2(const uint8_t& x) {
  1896. //sprintf(conv,"%5.1f",x);
  1897. int xx = x;
  1898. conv[0] = (xx / 10) % 10 + '0';
  1899. conv[1] = xx % 10 + '0';
  1900. conv[2] = 0;
  1901. return conv;
  1902. }
  1903. // Convert float to string with +123.4 format
  1904. char* ftostr31(const float& x) {
  1905. int xx = abs(x * 10);
  1906. conv[0] = (x >= 0) ? '+' : '-';
  1907. conv[1] = (xx / 1000) % 10 + '0';
  1908. conv[2] = (xx / 100) % 10 + '0';
  1909. conv[3] = (xx / 10) % 10 + '0';
  1910. conv[4] = '.';
  1911. conv[5] = xx % 10 + '0';
  1912. conv[6] = 0;
  1913. return conv;
  1914. }
  1915. // Convert float to string with 123.4 format, dropping sign
  1916. char* ftostr31ns(const float& x) {
  1917. int xx = abs(x * 10);
  1918. conv[0] = (xx / 1000) % 10 + '0';
  1919. conv[1] = (xx / 100) % 10 + '0';
  1920. conv[2] = (xx / 10) % 10 + '0';
  1921. conv[3] = '.';
  1922. conv[4] = xx % 10 + '0';
  1923. conv[5] = 0;
  1924. return conv;
  1925. }
  1926. // Convert float to string with 123.45 format
  1927. char *ftostr32(const float& x) {
  1928. long xx = abs(x * 100);
  1929. conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
  1930. conv[1] = (xx / 1000) % 10 + '0';
  1931. conv[2] = (xx / 100) % 10 + '0';
  1932. conv[3] = '.';
  1933. conv[4] = (xx / 10) % 10 + '0';
  1934. conv[5] = xx % 10 + '0';
  1935. conv[6] = 0;
  1936. return conv;
  1937. }
  1938. // Convert float to string with 1.234 format
  1939. char* ftostr43(const float& x) {
  1940. long xx = x * 1000;
  1941. if (xx >= 0)
  1942. conv[0] = (xx / 1000) % 10 + '0';
  1943. else
  1944. conv[0] = '-';
  1945. xx = abs(xx);
  1946. conv[1] = '.';
  1947. conv[2] = (xx / 100) % 10 + '0';
  1948. conv[3] = (xx / 10) % 10 + '0';
  1949. conv[4] = (xx) % 10 + '0';
  1950. conv[5] = 0;
  1951. return conv;
  1952. }
  1953. // Convert float to string with 1.23 format
  1954. char* ftostr12ns(const float& x) {
  1955. long xx = x * 100;
  1956. xx = abs(xx);
  1957. conv[0] = (xx / 100) % 10 + '0';
  1958. conv[1] = '.';
  1959. conv[2] = (xx / 10) % 10 + '0';
  1960. conv[3] = (xx) % 10 + '0';
  1961. conv[4] = 0;
  1962. return conv;
  1963. }
  1964. // Convert float to space-padded string with -_23.4_ format
  1965. char* ftostr32sp(const float& x) {
  1966. long xx = abs(x * 100);
  1967. uint8_t dig;
  1968. if (x < 0) { // negative val = -_0
  1969. conv[0] = '-';
  1970. dig = (xx / 1000) % 10;
  1971. conv[1] = dig ? '0' + dig : ' ';
  1972. }
  1973. else { // positive val = __0
  1974. dig = (xx / 10000) % 10;
  1975. if (dig) {
  1976. conv[0] = '0' + dig;
  1977. conv[1] = '0' + (xx / 1000) % 10;
  1978. }
  1979. else {
  1980. conv[0] = ' ';
  1981. dig = (xx / 1000) % 10;
  1982. conv[1] = dig ? '0' + dig : ' ';
  1983. }
  1984. }
  1985. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1986. dig = xx % 10;
  1987. if (dig) { // 2 decimal places
  1988. conv[5] = '0' + dig;
  1989. conv[4] = '0' + (xx / 10) % 10;
  1990. conv[3] = '.';
  1991. }
  1992. else { // 1 or 0 decimal place
  1993. dig = (xx / 10) % 10;
  1994. if (dig) {
  1995. conv[4] = '0' + dig;
  1996. conv[3] = '.';
  1997. }
  1998. else {
  1999. conv[3] = conv[4] = ' ';
  2000. }
  2001. conv[5] = ' ';
  2002. }
  2003. conv[6] = '\0';
  2004. return conv;
  2005. }
  2006. // Convert int to lj string with +123.0 format
  2007. char* itostr31(const int& x) {
  2008. conv[0] = x >= 0 ? '+' : '-';
  2009. int xx = abs(x);
  2010. conv[1] = (xx / 100) % 10 + '0';
  2011. conv[2] = (xx / 10) % 10 + '0';
  2012. conv[3] = xx % 10 + '0';
  2013. conv[4] = '.';
  2014. conv[5] = '0';
  2015. conv[6] = 0;
  2016. return conv;
  2017. }
  2018. // Convert int to rj string with 123 or -12 format
  2019. char* itostr3(const int& x) {
  2020. int xx = x;
  2021. if (xx < 0) {
  2022. conv[0] = '-';
  2023. xx = -xx;
  2024. }
  2025. else
  2026. conv[0] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2027. conv[1] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2028. conv[2] = xx % 10 + '0';
  2029. conv[3] = 0;
  2030. return conv;
  2031. }
  2032. // Convert int to lj string with 123 format
  2033. char* itostr3left(const int& xx) {
  2034. if (xx >= 100) {
  2035. conv[0] = (xx / 100) % 10 + '0';
  2036. conv[1] = (xx / 10) % 10 + '0';
  2037. conv[2] = xx % 10 + '0';
  2038. conv[3] = 0;
  2039. }
  2040. else if (xx >= 10) {
  2041. conv[0] = (xx / 10) % 10 + '0';
  2042. conv[1] = xx % 10 + '0';
  2043. conv[2] = 0;
  2044. }
  2045. else {
  2046. conv[0] = xx % 10 + '0';
  2047. conv[1] = 0;
  2048. }
  2049. return conv;
  2050. }
  2051. // Convert int to rj string with 1234 format
  2052. char* itostr4(const int& xx) {
  2053. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2054. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2055. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2056. conv[3] = xx % 10 + '0';
  2057. conv[4] = 0;
  2058. return conv;
  2059. }
  2060. // Convert int to rj string with _123, -123, _-12, or __-1 format
  2061. char *itostr4sign(const int& x) {
  2062. int xx = abs(x);
  2063. int sign = 0;
  2064. if (xx >= 100) {
  2065. conv[1] = (xx / 100) % 10 + '0';
  2066. conv[2] = (xx / 10) % 10 + '0';
  2067. }
  2068. else if (xx >= 10) {
  2069. conv[0] = ' ';
  2070. sign = 1;
  2071. conv[2] = (xx / 10) % 10 + '0';
  2072. }
  2073. else {
  2074. conv[0] = ' ';
  2075. conv[1] = ' ';
  2076. sign = 2;
  2077. }
  2078. conv[sign] = x < 0 ? '-' : ' ';
  2079. conv[3] = xx % 10 + '0';
  2080. conv[4] = 0;
  2081. return conv;
  2082. }
  2083. // Convert float to rj string with 12345 format
  2084. char* ftostr5(const float& x) {
  2085. long xx = abs(x);
  2086. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2087. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2088. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2089. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2090. conv[4] = xx % 10 + '0';
  2091. conv[5] = 0;
  2092. return conv;
  2093. }
  2094. // Convert float to string with +1234.5 format
  2095. char* ftostr51(const float& x) {
  2096. long xx = abs(x * 10);
  2097. conv[0] = (x >= 0) ? '+' : '-';
  2098. conv[1] = (xx / 10000) % 10 + '0';
  2099. conv[2] = (xx / 1000) % 10 + '0';
  2100. conv[3] = (xx / 100) % 10 + '0';
  2101. conv[4] = (xx / 10) % 10 + '0';
  2102. conv[5] = '.';
  2103. conv[6] = xx % 10 + '0';
  2104. conv[7] = 0;
  2105. return conv;
  2106. }
  2107. // Convert float to string with +123.45 format
  2108. char* ftostr52(const float& x) {
  2109. conv[0] = (x >= 0) ? '+' : '-';
  2110. long xx = abs(x * 100);
  2111. conv[1] = (xx / 10000) % 10 + '0';
  2112. conv[2] = (xx / 1000) % 10 + '0';
  2113. conv[3] = (xx / 100) % 10 + '0';
  2114. conv[4] = '.';
  2115. conv[5] = (xx / 10) % 10 + '0';
  2116. conv[6] = xx % 10 + '0';
  2117. conv[7] = 0;
  2118. return conv;
  2119. }
  2120. #if ENABLED(MANUAL_BED_LEVELING)
  2121. static int _lcd_level_bed_position;
  2122. /**
  2123. * MBL Wait for controller movement and clicks:
  2124. * - Movement adjusts the Z axis
  2125. * - Click saves the Z and goes to the next mesh point
  2126. */
  2127. static void _lcd_level_bed() {
  2128. ENCODER_DIRECTION_NORMAL();
  2129. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  2130. refresh_cmd_timeout();
  2131. current_position[Z_AXIS] += float((int)encoderPosition) * (MBL_Z_STEP);
  2132. if (min_software_endstops) NOLESS(current_position[Z_AXIS], Z_MIN_POS);
  2133. if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
  2134. encoderPosition = 0;
  2135. line_to_current(Z_AXIS);
  2136. lcdDrawUpdate = 2;
  2137. }
  2138. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr43(current_position[Z_AXIS]));
  2139. static bool debounce_click = false;
  2140. if (LCD_CLICKED) {
  2141. if (!debounce_click) {
  2142. debounce_click = true;
  2143. int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
  2144. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2145. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2146. mbl.set_z(ix, iy, current_position[Z_AXIS]);
  2147. _lcd_level_bed_position++;
  2148. if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
  2149. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2150. line_to_current(Z_AXIS);
  2151. mbl.active = 1;
  2152. enqueue_and_echo_commands_P(PSTR("G28"));
  2153. lcd_return_to_status();
  2154. }
  2155. else {
  2156. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2157. line_to_current(Z_AXIS);
  2158. ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS);
  2159. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2160. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2161. current_position[X_AXIS] = mbl.get_x(ix);
  2162. current_position[Y_AXIS] = mbl.get_y(iy);
  2163. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2164. lcdDrawUpdate = 2;
  2165. }
  2166. }
  2167. }
  2168. else {
  2169. debounce_click = false;
  2170. }
  2171. }
  2172. /**
  2173. * MBL Move to mesh starting point
  2174. */
  2175. static void _lcd_level_bed_homing() {
  2176. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("XYZ"), PSTR(MSG_LEVEL_BED_HOMING));
  2177. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]) {
  2178. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2179. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2180. current_position[X_AXIS] = MESH_MIN_X;
  2181. current_position[Y_AXIS] = MESH_MIN_Y;
  2182. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2183. _lcd_level_bed_position = 0;
  2184. lcd_goto_menu(_lcd_level_bed);
  2185. }
  2186. lcdDrawUpdate = 2;
  2187. }
  2188. /**
  2189. * MBL entry-point
  2190. */
  2191. static void lcd_level_bed() {
  2192. axis_known_position[X_AXIS] = axis_known_position[Y_AXIS] = axis_known_position[Z_AXIS] = false;
  2193. mbl.reset();
  2194. enqueue_and_echo_commands_P(PSTR("G28"));
  2195. lcdDrawUpdate = 2;
  2196. lcd_goto_menu(_lcd_level_bed_homing);
  2197. }
  2198. #endif // MANUAL_BED_LEVELING
  2199. #endif // ULTRA_LCD