My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.cpp 74KB

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