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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "ultralcd.h"
  23. #if ENABLED(ULTRA_LCD)
  24. #include "Marlin.h"
  25. #include "language.h"
  26. #include "cardreader.h"
  27. #include "temperature.h"
  28. #include "stepper.h"
  29. #include "configuration_store.h"
  30. #if ENABLED(PRINTCOUNTER)
  31. #include "printcounter.h"
  32. #endif
  33. int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
  34. preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2;
  35. #if ENABLED(FILAMENT_LCD_DISPLAY)
  36. millis_t previous_lcd_status_ms = 0;
  37. #endif
  38. uint8_t lcd_status_message_level;
  39. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  40. #if ENABLED(DOGLCD)
  41. #include "dogm_lcd_implementation.h"
  42. #else
  43. #include "ultralcd_implementation_hitachi_HD44780.h"
  44. #endif
  45. // The main status screen
  46. static void lcd_status_screen();
  47. millis_t next_lcd_update_ms;
  48. enum LCDViewAction {
  49. LCDVIEW_NONE,
  50. LCDVIEW_REDRAW_NOW,
  51. LCDVIEW_CALL_REDRAW_NEXT,
  52. LCDVIEW_CLEAR_CALL_REDRAW,
  53. LCDVIEW_CALL_NO_REDRAW
  54. };
  55. uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
  56. #if ENABLED(ULTIPANEL)
  57. // place-holders for Ki and Kd edits
  58. float raw_Ki, raw_Kd;
  59. /**
  60. * REVERSE_MENU_DIRECTION
  61. *
  62. * To reverse the menu direction we need a general way to reverse
  63. * the direction of the encoder everywhere. So encoderDirection is
  64. * added to allow the encoder to go the other way.
  65. *
  66. * This behavior is limited to scrolling Menus and SD card listings,
  67. * and is disabled in other contexts.
  68. */
  69. #if ENABLED(REVERSE_MENU_DIRECTION)
  70. int8_t encoderDirection = 1;
  71. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  72. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  73. #else
  74. #define ENCODER_DIRECTION_NORMAL() ;
  75. #define ENCODER_DIRECTION_MENUS() ;
  76. #endif
  77. int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
  78. millis_t manual_move_start_time = 0;
  79. int8_t manual_move_axis = (int8_t)NO_AXIS;
  80. #if EXTRUDERS > 1
  81. int8_t manual_move_e_index = 0;
  82. #else
  83. #define manual_move_e_index 0
  84. #endif
  85. bool encoderRateMultiplierEnabled;
  86. int32_t lastEncoderMovementMillis;
  87. #if HAS_POWER_SWITCH
  88. extern bool powersupply;
  89. #endif
  90. const float manual_feedrate[] = MANUAL_FEEDRATE;
  91. static void lcd_main_menu();
  92. static void lcd_tune_menu();
  93. static void lcd_prepare_menu();
  94. static void lcd_move_menu();
  95. static void lcd_control_menu();
  96. static void lcd_control_temperature_menu();
  97. static void lcd_control_temperature_preheat_pla_settings_menu();
  98. static void lcd_control_temperature_preheat_abs_settings_menu();
  99. static void lcd_control_motion_menu();
  100. static void lcd_control_volumetric_menu();
  101. #if ENABLED(LCD_INFO_MENU)
  102. #if ENABLED(PRINTCOUNTER)
  103. static void lcd_info_stats_menu();
  104. #endif
  105. static void lcd_info_thermistors_menu();
  106. static void lcd_info_board_menu();
  107. static void lcd_info_menu();
  108. #endif // LCD_INFO_MENU
  109. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  110. static void lcd_filament_change_option_menu();
  111. static void lcd_filament_change_init_message();
  112. static void lcd_filament_change_unload_message();
  113. static void lcd_filament_change_insert_message();
  114. static void lcd_filament_change_load_message();
  115. static void lcd_filament_change_extrude_message();
  116. static void lcd_filament_change_resume_message();
  117. #endif
  118. #if HAS_LCD_CONTRAST
  119. static void lcd_set_contrast();
  120. #endif
  121. #if ENABLED(FWRETRACT)
  122. static void lcd_control_retract_menu();
  123. #endif
  124. #if ENABLED(DELTA_CALIBRATION_MENU)
  125. static void lcd_delta_calibrate_menu();
  126. #endif
  127. #if ENABLED(MANUAL_BED_LEVELING)
  128. #include "mesh_bed_leveling.h"
  129. #endif
  130. // Function pointer to menu functions.
  131. typedef void (*screenFunc_t)();
  132. // Different types of actions that can be used in menu items.
  133. static void menu_action_back();
  134. static void menu_action_submenu(screenFunc_t data);
  135. static void menu_action_gcode(const char* pgcode);
  136. static void menu_action_function(screenFunc_t data);
  137. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  138. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  139. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  140. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  141. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  142. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  143. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  144. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  145. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  146. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  147. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, screenFunc_t callbackFunc);
  148. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  149. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  150. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  151. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  152. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  153. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  154. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, screenFunc_t callbackFunc);
  155. #if ENABLED(SDSUPPORT)
  156. static void lcd_sdcard_menu();
  157. static void menu_action_sdfile(const char* filename, char* longFilename);
  158. static void menu_action_sddirectory(const char* filename, char* longFilename);
  159. #endif
  160. #define ENCODER_FEEDRATE_DEADZONE 10
  161. #if DISABLED(LCD_I2C_VIKI)
  162. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  163. #define ENCODER_STEPS_PER_MENU_ITEM 5
  164. #endif
  165. #ifndef ENCODER_PULSES_PER_STEP
  166. #define ENCODER_PULSES_PER_STEP 1
  167. #endif
  168. #else
  169. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  170. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  171. #endif
  172. #ifndef ENCODER_PULSES_PER_STEP
  173. #define ENCODER_PULSES_PER_STEP 1
  174. #endif
  175. #endif
  176. /* Helper macros for menus */
  177. /**
  178. * START_SCREEN generates the init code for a screen function
  179. *
  180. * encoderLine is the position based on the encoder
  181. * encoderTopLine is the top menu line to display
  182. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  183. * _menuLineNr is the menu item to draw and process
  184. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  185. */
  186. #define _START_SCREEN(CODE) \
  187. ENCODER_DIRECTION_MENUS(); \
  188. encoderRateMultiplierEnabled = false; \
  189. if (encoderPosition > 0x8000) encoderPosition = 0; \
  190. int8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
  191. NOMORE(encoderTopLine, encoderLine); \
  192. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  193. CODE; \
  194. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \
  195. _thisItemNr = 0;
  196. #define START_SCREEN() _START_SCREEN(NOOP)
  197. /**
  198. * START_MENU generates the init code for a menu function
  199. *
  200. * wasClicked indicates the controller was clicked
  201. */
  202. #define START_MENU() _START_SCREEN(bool wasClicked = LCD_CLICKED)
  203. /**
  204. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  205. *
  206. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  207. * menu_action_[type](arg3...)
  208. *
  209. * Examples:
  210. * MENU_ITEM(back, MSG_WATCH)
  211. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  212. * menu_action_back()
  213. *
  214. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  215. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  216. * menu_action_function(lcd_sdcard_pause)
  217. *
  218. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  219. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  220. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  221. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  222. *
  223. */
  224. #define _MENU_ITEM_PART_1(TYPE, LABEL, ARGS...) \
  225. if (_menuLineNr == _thisItemNr) { \
  226. if (lcdDrawUpdate) \
  227. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## ARGS); \
  228. if (wasClicked && encoderLine == _thisItemNr) { \
  229. lcd_quick_feedback()
  230. #define _MENU_ITEM_PART_2(TYPE, ARGS...) \
  231. menu_action_ ## TYPE(ARGS); \
  232. return; \
  233. } \
  234. } \
  235. _thisItemNr++
  236. #define MENU_ITEM(TYPE, LABEL, ARGS...) do { \
  237. _MENU_ITEM_PART_1(TYPE, LABEL, ## ARGS); \
  238. _MENU_ITEM_PART_2(TYPE, ## ARGS); \
  239. } while(0)
  240. // Used to print static text with no visible cursor.
  241. #define STATIC_ITEM(LABEL, ARGS...) \
  242. if (_menuLineNr == _thisItemNr) { \
  243. if (encoderLine == _thisItemNr && _thisItemNr < LCD_HEIGHT - 1) { \
  244. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  245. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  246. } \
  247. if (lcdDrawUpdate) \
  248. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## ARGS); \
  249. } \
  250. _thisItemNr++
  251. /**
  252. *
  253. * END_SCREEN Closing code for a screen having only static items.
  254. * Do simplified scrolling of the entire screen.
  255. *
  256. * END_MENU Closing code for a screen with menu items.
  257. * Scroll as-needed to keep the selected line in view.
  258. *
  259. * At this point _thisItemNr equals the total number of items.
  260. *
  261. */
  262. // Simple-scroll by using encoderLine as encoderTopLine
  263. #define END_SCREEN() \
  264. } \
  265. NOMORE(encoderLine, _thisItemNr - LCD_HEIGHT); \
  266. NOLESS(encoderLine, 0); \
  267. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  268. if (encoderTopLine != encoderLine) { \
  269. encoderTopLine = encoderLine; \
  270. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  271. }
  272. // Scroll through menu items, scrolling as-needed to stay in view
  273. #define END_MENU() \
  274. } \
  275. if (encoderLine >= _thisItemNr) { \
  276. encoderLine = _thisItemNr - 1; \
  277. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  278. } \
  279. if (encoderLine >= encoderTopLine + LCD_HEIGHT) { \
  280. encoderTopLine = encoderLine - (LCD_HEIGHT - 1); \
  281. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  282. }
  283. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  284. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  285. /**
  286. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  287. */
  288. #define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
  289. _MENU_ITEM_PART_1(type, label, ## args); \
  290. encoderRateMultiplierEnabled = true; \
  291. lastEncoderMovementMillis = 0; \
  292. _MENU_ITEM_PART_2(type, ## args); \
  293. } while(0)
  294. #endif //ENCODER_RATE_MULTIPLIER
  295. #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
  296. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  297. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  298. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  299. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  300. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  301. #else //!ENCODER_RATE_MULTIPLIER
  302. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  303. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  304. #endif //!ENCODER_RATE_MULTIPLIER
  305. /** Used variables to keep track of the menu */
  306. volatile uint8_t buttons; //the last checked buttons in a bit array.
  307. #if ENABLED(REPRAPWORLD_KEYPAD)
  308. volatile uint8_t buttons_reprapworld_keypad; // to store the keypad shift register values
  309. #endif
  310. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  311. volatile uint8_t slow_buttons; // Bits of the pressed buttons.
  312. #endif
  313. int8_t encoderTopLine; /* scroll offset in the current menu */
  314. millis_t next_button_update_ms;
  315. uint8_t lastEncoderBits;
  316. uint32_t encoderPosition;
  317. #if PIN_EXISTS(SD_DETECT)
  318. uint8_t lcd_sd_status;
  319. #endif
  320. typedef struct {
  321. screenFunc_t menu_function;
  322. uint32_t encoder_position;
  323. } menuPosition;
  324. screenFunc_t currentScreen = lcd_status_screen; // pointer to the currently active menu handler
  325. menuPosition screen_history[10];
  326. uint8_t screen_history_depth = 0;
  327. bool ignore_click = false;
  328. bool wait_for_unclick;
  329. bool defer_return_to_status = false;
  330. // Variables used when editing values.
  331. const char* editLabel;
  332. void* editValue;
  333. int32_t minEditValue, maxEditValue;
  334. screenFunc_t callbackFunc; // call this after editing
  335. /**
  336. * General function to go directly to a menu
  337. * Remembers the previous position
  338. */
  339. static void lcd_goto_screen(screenFunc_t screen, const bool feedback = false, const uint32_t encoder = 0) {
  340. if (currentScreen != screen) {
  341. currentScreen = screen;
  342. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  343. encoderPosition = encoder;
  344. if (feedback) lcd_quick_feedback();
  345. if (screen == lcd_status_screen) {
  346. defer_return_to_status = false;
  347. screen_history_depth = 0;
  348. }
  349. #if ENABLED(LCD_PROGRESS_BAR)
  350. // For LCD_PROGRESS_BAR re-initialize custom characters
  351. lcd_set_custom_characters(screen == lcd_status_screen);
  352. #endif
  353. }
  354. }
  355. static void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  356. inline void lcd_save_previous_menu() {
  357. if (screen_history_depth < COUNT(screen_history)) {
  358. screen_history[screen_history_depth].menu_function = currentScreen;
  359. screen_history[screen_history_depth].encoder_position = encoderPosition;
  360. ++screen_history_depth;
  361. }
  362. }
  363. static void lcd_goto_previous_menu(bool feedback=false) {
  364. if (screen_history_depth > 0) {
  365. --screen_history_depth;
  366. lcd_goto_screen(
  367. screen_history[screen_history_depth].menu_function,
  368. feedback,
  369. screen_history[screen_history_depth].encoder_position
  370. );
  371. }
  372. else
  373. lcd_return_to_status();
  374. }
  375. void lcd_ignore_click(bool b) {
  376. ignore_click = b;
  377. wait_for_unclick = false;
  378. }
  379. #endif // ULTIPANEL
  380. /**
  381. *
  382. * "Info Screen"
  383. *
  384. * This is very display-dependent, so the lcd implementation draws this.
  385. */
  386. static void lcd_status_screen() {
  387. #if ENABLED(ULTIPANEL)
  388. ENCODER_DIRECTION_NORMAL();
  389. encoderRateMultiplierEnabled = false;
  390. #endif
  391. #if ENABLED(LCD_PROGRESS_BAR)
  392. millis_t ms = millis();
  393. #if DISABLED(PROGRESS_MSG_ONCE)
  394. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  395. progress_bar_ms = ms;
  396. }
  397. #endif
  398. #if PROGRESS_MSG_EXPIRE > 0
  399. // Handle message expire
  400. if (expire_status_ms > 0) {
  401. #if ENABLED(SDSUPPORT)
  402. if (card.isFileOpen()) {
  403. // Expire the message when printing is active
  404. if (IS_SD_PRINTING) {
  405. if (ELAPSED(ms, expire_status_ms)) {
  406. lcd_status_message[0] = '\0';
  407. expire_status_ms = 0;
  408. }
  409. }
  410. else {
  411. expire_status_ms += LCD_UPDATE_INTERVAL;
  412. }
  413. }
  414. else {
  415. expire_status_ms = 0;
  416. }
  417. #else
  418. expire_status_ms = 0;
  419. #endif //SDSUPPORT
  420. }
  421. #endif
  422. #endif //LCD_PROGRESS_BAR
  423. lcd_implementation_status_screen();
  424. #if ENABLED(ULTIPANEL)
  425. bool current_click = LCD_CLICKED;
  426. if (ignore_click) {
  427. if (wait_for_unclick) {
  428. if (!current_click)
  429. ignore_click = wait_for_unclick = false;
  430. else
  431. current_click = false;
  432. }
  433. else if (current_click) {
  434. lcd_quick_feedback();
  435. wait_for_unclick = true;
  436. current_click = false;
  437. }
  438. }
  439. if (current_click) {
  440. lcd_goto_screen(lcd_main_menu, true);
  441. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  442. #if ENABLED(LCD_PROGRESS_BAR) && ENABLED(ULTIPANEL)
  443. currentScreen == lcd_status_screen
  444. #endif
  445. );
  446. #if ENABLED(FILAMENT_LCD_DISPLAY)
  447. previous_lcd_status_ms = millis(); // get status message to show up for a while
  448. #endif
  449. }
  450. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  451. int new_frm = feedrate_multiplier + (int32_t)encoderPosition;
  452. // Dead zone at 100% feedrate
  453. if ((feedrate_multiplier < 100 && new_frm > 100) || (feedrate_multiplier > 100 && new_frm < 100)) {
  454. feedrate_multiplier = 100;
  455. encoderPosition = 0;
  456. }
  457. else if (feedrate_multiplier == 100) {
  458. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  459. feedrate_multiplier += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  460. encoderPosition = 0;
  461. }
  462. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  463. feedrate_multiplier += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  464. encoderPosition = 0;
  465. }
  466. }
  467. else {
  468. feedrate_multiplier = new_frm;
  469. encoderPosition = 0;
  470. }
  471. #endif // ULTIPANEL_FEEDMULTIPLY
  472. feedrate_multiplier = constrain(feedrate_multiplier, 10, 999);
  473. #endif //ULTIPANEL
  474. }
  475. /**
  476. *
  477. * draw the kill screen
  478. *
  479. */
  480. void kill_screen(const char* lcd_msg) {
  481. lcd_init();
  482. lcd_setalertstatuspgm(lcd_msg);
  483. #if ENABLED(DOGLCD)
  484. u8g.firstPage();
  485. do {
  486. lcd_kill_screen();
  487. } while (u8g.nextPage());
  488. #else
  489. lcd_kill_screen();
  490. #endif
  491. }
  492. #if ENABLED(ULTIPANEL)
  493. inline void line_to_current(AxisEnum axis) {
  494. #if ENABLED(DELTA)
  495. calculate_delta(current_position);
  496. planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  497. #else // !DELTA
  498. planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  499. #endif // !DELTA
  500. }
  501. #if ENABLED(SDSUPPORT)
  502. static void lcd_sdcard_pause() {
  503. card.pauseSDPrint();
  504. print_job_timer.pause();
  505. }
  506. static void lcd_sdcard_resume() {
  507. card.startFileprint();
  508. print_job_timer.start();
  509. }
  510. static void lcd_sdcard_stop() {
  511. card.stopSDPrint();
  512. clear_command_queue();
  513. quickstop_stepper();
  514. print_job_timer.stop();
  515. thermalManager.autotempShutdown();
  516. wait_for_heatup = false;
  517. lcd_setstatus(MSG_PRINT_ABORTED, true);
  518. }
  519. #endif //SDSUPPORT
  520. /**
  521. *
  522. * "Main" menu
  523. *
  524. */
  525. static void lcd_main_menu() {
  526. START_MENU();
  527. MENU_ITEM(back, MSG_WATCH);
  528. if (planner.movesplanned() || IS_SD_PRINTING) {
  529. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  530. }
  531. else {
  532. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  533. #if ENABLED(DELTA_CALIBRATION_MENU)
  534. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  535. #endif
  536. }
  537. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  538. #if ENABLED(SDSUPPORT)
  539. if (card.cardOK) {
  540. if (card.isFileOpen()) {
  541. if (card.sdprinting)
  542. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  543. else
  544. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  545. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  546. }
  547. else {
  548. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  549. #if !PIN_EXISTS(SD_DETECT)
  550. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  551. #endif
  552. }
  553. }
  554. else {
  555. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  556. #if !PIN_EXISTS(SD_DETECT)
  557. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  558. #endif
  559. }
  560. #endif //SDSUPPORT
  561. #if ENABLED(LCD_INFO_MENU)
  562. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  563. #endif
  564. END_MENU();
  565. }
  566. /**
  567. *
  568. * "Tune" submenu items
  569. *
  570. */
  571. /**
  572. * Set the home offset based on the current_position
  573. */
  574. void lcd_set_home_offsets() {
  575. // M428 Command
  576. enqueue_and_echo_commands_P(PSTR("M428"));
  577. lcd_return_to_status();
  578. }
  579. #if ENABLED(BABYSTEPPING)
  580. long babysteps_done = 0;
  581. static void _lcd_babystep(const AxisEnum axis, const char* msg) {
  582. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  583. ENCODER_DIRECTION_NORMAL();
  584. if (encoderPosition) {
  585. int babystep_increment = (int32_t)encoderPosition * BABYSTEP_MULTIPLICATOR;
  586. encoderPosition = 0;
  587. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  588. thermalManager.babystep_axis(axis, babystep_increment);
  589. babysteps_done += babystep_increment;
  590. }
  591. if (lcdDrawUpdate)
  592. lcd_implementation_drawedit(msg, ftostr43sign(
  593. ((1000 * babysteps_done) / planner.axis_steps_per_mm[axis]) * 0.001f
  594. ));
  595. }
  596. #if ENABLED(BABYSTEP_XY)
  597. static void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  598. static void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  599. static void lcd_babystep_x() { babysteps_done = 0; lcd_goto_screen(_lcd_babystep_x); }
  600. static void lcd_babystep_y() { babysteps_done = 0; lcd_goto_screen(_lcd_babystep_y); }
  601. #endif
  602. static void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  603. static void lcd_babystep_z() { babysteps_done = 0; lcd_goto_screen(_lcd_babystep_z); }
  604. #endif //BABYSTEPPING
  605. /**
  606. * Watch temperature callbacks
  607. */
  608. #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
  609. #if TEMP_SENSOR_0 != 0
  610. void watch_temp_callback_E0() { thermalManager.start_watching_heater(0); }
  611. #endif
  612. #if HOTENDS > 1 && TEMP_SENSOR_1 != 0
  613. void watch_temp_callback_E1() { thermalManager.start_watching_heater(1); }
  614. #endif // HOTENDS > 1
  615. #if HOTENDS > 2 && TEMP_SENSOR_2 != 0
  616. void watch_temp_callback_E2() { thermalManager.start_watching_heater(2); }
  617. #endif // HOTENDS > 2
  618. #if HOTENDS > 3 && TEMP_SENSOR_3 != 0
  619. void watch_temp_callback_E3() { thermalManager.start_watching_heater(3); }
  620. #endif // HOTENDS > 3
  621. #else
  622. #if TEMP_SENSOR_0 != 0
  623. void watch_temp_callback_E0() {}
  624. #endif
  625. #if HOTENDS > 1 && TEMP_SENSOR_1 != 0
  626. void watch_temp_callback_E1() {}
  627. #endif // HOTENDS > 1
  628. #if HOTENDS > 2 && TEMP_SENSOR_2 != 0
  629. void watch_temp_callback_E2() {}
  630. #endif // HOTENDS > 2
  631. #if HOTENDS > 3 && TEMP_SENSOR_3 != 0
  632. void watch_temp_callback_E3() {}
  633. #endif // HOTENDS > 3
  634. #endif
  635. #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
  636. #if TEMP_SENSOR_BED != 0
  637. void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
  638. #endif
  639. #else
  640. #if TEMP_SENSOR_BED != 0
  641. void watch_temp_callback_bed() {}
  642. #endif
  643. #endif
  644. /**
  645. *
  646. * "Tune" submenu
  647. *
  648. */
  649. static void lcd_tune_menu() {
  650. START_MENU();
  651. //
  652. // ^ Main
  653. //
  654. MENU_ITEM(back, MSG_MAIN);
  655. //
  656. // Speed:
  657. //
  658. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999);
  659. // Manual bed leveling, Bed Z:
  660. #if ENABLED(MANUAL_BED_LEVELING)
  661. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  662. #endif
  663. //
  664. // Nozzle:
  665. // Nozzle [1-4]:
  666. //
  667. #if HOTENDS == 1
  668. #if TEMP_SENSOR_0 != 0
  669. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  670. #endif
  671. #else //HOTENDS > 1
  672. #if TEMP_SENSOR_0 != 0
  673. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  674. #endif
  675. #if TEMP_SENSOR_1 != 0
  676. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  677. #endif
  678. #if HOTENDS > 2
  679. #if TEMP_SENSOR_2 != 0
  680. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  681. #endif
  682. #if HOTENDS > 3
  683. #if TEMP_SENSOR_3 != 0
  684. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  685. #endif
  686. #endif // HOTENDS > 3
  687. #endif // HOTENDS > 2
  688. #endif // HOTENDS > 1
  689. //
  690. // Bed:
  691. //
  692. #if TEMP_SENSOR_BED != 0
  693. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  694. #endif
  695. //
  696. // Fan Speed:
  697. //
  698. #if FAN_COUNT > 0
  699. #if HAS_FAN0
  700. #if FAN_COUNT > 1
  701. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  702. #else
  703. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  704. #endif
  705. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  706. #endif
  707. #if HAS_FAN1
  708. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  709. #endif
  710. #if HAS_FAN2
  711. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  712. #endif
  713. #endif // FAN_COUNT > 0
  714. //
  715. // Flow:
  716. // Flow 1:
  717. // Flow 2:
  718. // Flow 3:
  719. // Flow 4:
  720. //
  721. #if EXTRUDERS == 1
  722. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[0], 10, 999);
  723. #else // EXTRUDERS > 1
  724. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[active_extruder], 10, 999);
  725. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &extruder_multiplier[0], 10, 999);
  726. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &extruder_multiplier[1], 10, 999);
  727. #if EXTRUDERS > 2
  728. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &extruder_multiplier[2], 10, 999);
  729. #if EXTRUDERS > 3
  730. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &extruder_multiplier[3], 10, 999);
  731. #endif //EXTRUDERS > 3
  732. #endif //EXTRUDERS > 2
  733. #endif //EXTRUDERS > 1
  734. //
  735. // Babystep X:
  736. // Babystep Y:
  737. // Babystep Z:
  738. //
  739. #if ENABLED(BABYSTEPPING)
  740. #if ENABLED(BABYSTEP_XY)
  741. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  742. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  743. #endif //BABYSTEP_XY
  744. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  745. #endif
  746. //
  747. // Change filament
  748. //
  749. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  750. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  751. #endif
  752. END_MENU();
  753. }
  754. /**
  755. *
  756. * "Prepare" submenu items
  757. *
  758. */
  759. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  760. if (temph > 0) thermalManager.setTargetHotend(temph, endnum);
  761. #if TEMP_SENSOR_BED != 0
  762. thermalManager.setTargetBed(tempb);
  763. #else
  764. UNUSED(tempb);
  765. #endif
  766. #if FAN_COUNT > 0
  767. #if FAN_COUNT > 1
  768. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  769. #else
  770. fanSpeeds[0] = fan;
  771. #endif
  772. #else
  773. UNUSED(fan);
  774. #endif
  775. lcd_return_to_status();
  776. }
  777. #if TEMP_SENSOR_0 != 0
  778. void lcd_preheat_pla0() { _lcd_preheat(0, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
  779. void lcd_preheat_abs0() { _lcd_preheat(0, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
  780. #endif
  781. #if HOTENDS > 1
  782. void lcd_preheat_pla1() { _lcd_preheat(1, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
  783. void lcd_preheat_abs1() { _lcd_preheat(1, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
  784. #if HOTENDS > 2
  785. void lcd_preheat_pla2() { _lcd_preheat(2, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
  786. void lcd_preheat_abs2() { _lcd_preheat(2, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
  787. #if HOTENDS > 3
  788. void lcd_preheat_pla3() { _lcd_preheat(3, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
  789. void lcd_preheat_abs3() { _lcd_preheat(3, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
  790. #endif
  791. #endif
  792. void lcd_preheat_pla0123() {
  793. #if HOTENDS > 1
  794. thermalManager.setTargetHotend(preheatHotendTemp1, 1);
  795. #if HOTENDS > 2
  796. thermalManager.setTargetHotend(preheatHotendTemp1, 2);
  797. #if HOTENDS > 3
  798. thermalManager.setTargetHotend(preheatHotendTemp1, 3);
  799. #endif
  800. #endif
  801. #endif
  802. lcd_preheat_pla0();
  803. }
  804. void lcd_preheat_abs0123() {
  805. #if HOTENDS > 1
  806. thermalManager.setTargetHotend(preheatHotendTemp2, 1);
  807. #if HOTENDS > 2
  808. thermalManager.setTargetHotend(preheatHotendTemp2, 2);
  809. #if HOTENDS > 3
  810. thermalManager.setTargetHotend(preheatHotendTemp2, 3);
  811. #endif
  812. #endif
  813. #endif
  814. lcd_preheat_abs0();
  815. }
  816. #endif // HOTENDS > 1
  817. #if TEMP_SENSOR_BED != 0
  818. void lcd_preheat_pla_bedonly() { _lcd_preheat(0, 0, preheatBedTemp1, preheatFanSpeed1); }
  819. void lcd_preheat_abs_bedonly() { _lcd_preheat(0, 0, preheatBedTemp2, preheatFanSpeed2); }
  820. #endif
  821. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  822. static void lcd_preheat_pla_menu() {
  823. START_MENU();
  824. MENU_ITEM(back, MSG_PREPARE);
  825. #if HOTENDS == 1
  826. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_pla0);
  827. #else
  828. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_pla0);
  829. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_pla1);
  830. #if HOTENDS > 2
  831. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_pla2);
  832. #if HOTENDS > 3
  833. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_pla3);
  834. #endif
  835. #endif
  836. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_pla0123);
  837. #endif
  838. #if TEMP_SENSOR_BED != 0
  839. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_pla_bedonly);
  840. #endif
  841. END_MENU();
  842. }
  843. static void lcd_preheat_abs_menu() {
  844. START_MENU();
  845. MENU_ITEM(back, MSG_PREPARE);
  846. #if HOTENDS == 1
  847. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_abs0);
  848. #else
  849. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_abs0);
  850. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_abs1);
  851. #if HOTENDS > 2
  852. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_abs2);
  853. #if HOTENDS > 3
  854. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_abs3);
  855. #endif
  856. #endif
  857. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_abs0123);
  858. #endif
  859. #if TEMP_SENSOR_BED != 0
  860. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_abs_bedonly);
  861. #endif
  862. END_MENU();
  863. }
  864. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  865. void lcd_cooldown() {
  866. #if FAN_COUNT > 0
  867. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  868. #endif
  869. thermalManager.disable_all_heaters();
  870. lcd_return_to_status();
  871. }
  872. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  873. static void lcd_autostart_sd() {
  874. card.autostart_index = 0;
  875. card.setroot();
  876. card.checkautostart(true);
  877. }
  878. #endif
  879. #if ENABLED(MANUAL_BED_LEVELING)
  880. /**
  881. *
  882. * "Prepare" > "Bed Leveling" handlers
  883. *
  884. */
  885. static uint8_t _lcd_level_bed_position;
  886. // Utility to go to the next mesh point
  887. // A raise is added between points if MIN_Z_HEIGHT_FOR_HOMING is in use
  888. // Note: During Manual Bed Leveling the homed Z position is MESH_HOME_SEARCH_Z
  889. // Z position will be restored with the final action, a G28
  890. inline void _mbl_goto_xy(float x, float y) {
  891. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + MIN_Z_HEIGHT_FOR_HOMING;
  892. line_to_current(Z_AXIS);
  893. current_position[X_AXIS] = x + home_offset[X_AXIS];
  894. current_position[Y_AXIS] = y + home_offset[Y_AXIS];
  895. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  896. #if MIN_Z_HEIGHT_FOR_HOMING > 0
  897. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z; // How do condition and action match?
  898. line_to_current(Z_AXIS);
  899. #endif
  900. stepper.synchronize();
  901. }
  902. static void _lcd_level_goto_next_point();
  903. static void _lcd_level_bed_done() {
  904. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  905. lcdDrawUpdate =
  906. #if ENABLED(DOGLCD)
  907. LCDVIEW_CALL_REDRAW_NEXT
  908. #else
  909. LCDVIEW_CALL_NO_REDRAW
  910. #endif
  911. ;
  912. }
  913. /**
  914. * Step 7: Get the Z coordinate, then goto next point or exit
  915. */
  916. static void _lcd_level_bed_get_z() {
  917. ENCODER_DIRECTION_NORMAL();
  918. // Encoder wheel adjusts the Z position
  919. if (encoderPosition) {
  920. refresh_cmd_timeout();
  921. current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
  922. NOLESS(current_position[Z_AXIS], 0);
  923. NOMORE(current_position[Z_AXIS], MESH_HOME_SEARCH_Z * 2);
  924. line_to_current(Z_AXIS);
  925. lcdDrawUpdate =
  926. #if ENABLED(DOGLCD)
  927. LCDVIEW_CALL_REDRAW_NEXT
  928. #else
  929. LCDVIEW_REDRAW_NOW
  930. #endif
  931. ;
  932. encoderPosition = 0;
  933. }
  934. static bool debounce_click = false;
  935. if (LCD_CLICKED) {
  936. if (!debounce_click) {
  937. debounce_click = true; // ignore multiple "clicks" in a row
  938. mbl.set_zigzag_z(_lcd_level_bed_position++, current_position[Z_AXIS]);
  939. if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
  940. lcd_goto_screen(_lcd_level_bed_done, true);
  941. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + MIN_Z_HEIGHT_FOR_HOMING;
  942. line_to_current(Z_AXIS);
  943. stepper.synchronize();
  944. mbl.set_has_mesh(true);
  945. enqueue_and_echo_commands_P(PSTR("G28"));
  946. lcd_return_to_status();
  947. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  948. #if HAS_BUZZER
  949. buzzer.tone(200, 659);
  950. buzzer.tone(200, 698);
  951. #endif
  952. }
  953. else {
  954. lcd_goto_screen(_lcd_level_goto_next_point, true);
  955. }
  956. }
  957. }
  958. else {
  959. debounce_click = false;
  960. }
  961. // Update on first display, then only on updates to Z position
  962. // Show message above on clicks instead
  963. if (lcdDrawUpdate) {
  964. float v = current_position[Z_AXIS] - MESH_HOME_SEARCH_Z;
  965. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  966. }
  967. }
  968. /**
  969. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  970. */
  971. static void _lcd_level_bed_moving() {
  972. if (lcdDrawUpdate) {
  973. char msg[10];
  974. sprintf_P(msg, PSTR("%i / %u"), (int)(_lcd_level_bed_position + 1), (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS));
  975. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  976. }
  977. lcdDrawUpdate =
  978. #if ENABLED(DOGLCD)
  979. LCDVIEW_CALL_REDRAW_NEXT
  980. #else
  981. LCDVIEW_CALL_NO_REDRAW
  982. #endif
  983. ;
  984. }
  985. /**
  986. * Step 5: Initiate a move to the next point
  987. */
  988. static void _lcd_level_goto_next_point() {
  989. // Set the menu to display ahead of blocking call
  990. lcd_goto_screen(_lcd_level_bed_moving);
  991. // _mbl_goto_xy runs the menu loop until the move is done
  992. int8_t px, py;
  993. mbl.zigzag(_lcd_level_bed_position, px, py);
  994. _mbl_goto_xy(mbl.get_probe_x(px), mbl.get_probe_y(py));
  995. // After the blocking function returns, change menus
  996. lcd_goto_screen(_lcd_level_bed_get_z);
  997. }
  998. /**
  999. * Step 4: Display "Click to Begin", wait for click
  1000. * Move to the first probe position
  1001. */
  1002. static void _lcd_level_bed_homing_done() {
  1003. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1004. if (LCD_CLICKED) {
  1005. _lcd_level_bed_position = 0;
  1006. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z
  1007. #if Z_HOME_DIR > 0
  1008. + Z_MAX_POS
  1009. #endif
  1010. ;
  1011. planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1012. lcd_goto_screen(_lcd_level_goto_next_point, true);
  1013. }
  1014. }
  1015. /**
  1016. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1017. */
  1018. static void _lcd_level_bed_homing() {
  1019. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1020. lcdDrawUpdate =
  1021. #if ENABLED(DOGLCD)
  1022. LCDVIEW_CALL_REDRAW_NEXT
  1023. #else
  1024. LCDVIEW_CALL_NO_REDRAW
  1025. #endif
  1026. ;
  1027. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1028. lcd_goto_screen(_lcd_level_bed_homing_done);
  1029. }
  1030. /**
  1031. * Step 2: Continue Bed Leveling...
  1032. */
  1033. static void _lcd_level_bed_continue() {
  1034. defer_return_to_status = true;
  1035. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1036. mbl.reset();
  1037. enqueue_and_echo_commands_P(PSTR("G28"));
  1038. lcd_goto_screen(_lcd_level_bed_homing);
  1039. }
  1040. /**
  1041. * Step 1: MBL entry-point: "Cancel" or "Level Bed"
  1042. */
  1043. static void lcd_level_bed() {
  1044. START_MENU();
  1045. MENU_ITEM(back, MSG_LEVEL_BED_CANCEL);
  1046. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1047. END_MENU();
  1048. }
  1049. #endif // MANUAL_BED_LEVELING
  1050. /**
  1051. *
  1052. * "Prepare" submenu
  1053. *
  1054. */
  1055. static void lcd_prepare_menu() {
  1056. START_MENU();
  1057. //
  1058. // ^ Main
  1059. //
  1060. MENU_ITEM(back, MSG_MAIN);
  1061. //
  1062. // Auto Home
  1063. //
  1064. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1065. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  1066. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  1067. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  1068. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  1069. #endif
  1070. //
  1071. // Set Home Offsets
  1072. //
  1073. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  1074. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  1075. //
  1076. // Level Bed
  1077. //
  1078. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  1079. MENU_ITEM(gcode, MSG_LEVEL_BED,
  1080. axis_homed[X_AXIS] && axis_homed[Y_AXIS] ? PSTR("G29") : PSTR("G28\nG29")
  1081. );
  1082. #elif ENABLED(MANUAL_BED_LEVELING)
  1083. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  1084. #endif
  1085. //
  1086. // Move Axis
  1087. //
  1088. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  1089. //
  1090. // Disable Steppers
  1091. //
  1092. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1093. //
  1094. // Preheat PLA
  1095. // Preheat ABS
  1096. //
  1097. #if TEMP_SENSOR_0 != 0
  1098. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  1099. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_pla_menu);
  1100. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_abs_menu);
  1101. #else
  1102. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_pla0);
  1103. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_abs0);
  1104. #endif
  1105. #endif
  1106. //
  1107. // Cooldown
  1108. //
  1109. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1110. //
  1111. // Switch power on/off
  1112. //
  1113. #if HAS_POWER_SWITCH
  1114. if (powersupply)
  1115. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  1116. else
  1117. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  1118. #endif
  1119. //
  1120. // Autostart
  1121. //
  1122. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1123. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  1124. #endif
  1125. END_MENU();
  1126. }
  1127. #if ENABLED(DELTA_CALIBRATION_MENU)
  1128. static void lcd_delta_calibrate_menu() {
  1129. START_MENU();
  1130. MENU_ITEM(back, MSG_MAIN);
  1131. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1132. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_X, PSTR("G0 F8000 X-77.94 Y-45 Z0"));
  1133. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Y, PSTR("G0 F8000 X77.94 Y-45 Z0"));
  1134. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Z, PSTR("G0 F8000 X0 Y90 Z0"));
  1135. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_CENTER, PSTR("G0 F8000 X0 Y0 Z0"));
  1136. END_MENU();
  1137. }
  1138. #endif // DELTA_CALIBRATION_MENU
  1139. float move_menu_scale;
  1140. /**
  1141. * If the most recent manual move hasn't been fed to the planner yet,
  1142. * and the planner can accept one, send immediately
  1143. */
  1144. inline void manage_manual_move() {
  1145. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  1146. #if ENABLED(DELTA)
  1147. calculate_delta(current_position);
  1148. planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[manual_move_axis]/60, manual_move_e_index);
  1149. #else
  1150. planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[manual_move_axis]/60, manual_move_e_index);
  1151. #endif
  1152. manual_move_axis = (int8_t)NO_AXIS;
  1153. }
  1154. }
  1155. /**
  1156. * Set a flag that lcd_update() should start a move
  1157. * to "current_position" after a short delay.
  1158. */
  1159. inline void manual_move_to_current(AxisEnum axis
  1160. #if EXTRUDERS > 1
  1161. , int8_t eindex=-1
  1162. #endif
  1163. ) {
  1164. #if EXTRUDERS > 1
  1165. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  1166. #endif
  1167. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  1168. manual_move_axis = (int8_t)axis;
  1169. }
  1170. /**
  1171. *
  1172. * "Prepare" > "Move Axis" submenu
  1173. *
  1174. */
  1175. static void _lcd_move_xyz(const char* name, AxisEnum axis, float min, float max) {
  1176. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  1177. ENCODER_DIRECTION_NORMAL();
  1178. if (encoderPosition) {
  1179. refresh_cmd_timeout();
  1180. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  1181. if (min_software_endstops) NOLESS(current_position[axis], min);
  1182. if (max_software_endstops) NOMORE(current_position[axis], max);
  1183. encoderPosition = 0;
  1184. manual_move_to_current(axis);
  1185. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1186. }
  1187. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  1188. }
  1189. #if ENABLED(DELTA)
  1190. static float delta_clip_radius_2 = (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS);
  1191. static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - a*a); }
  1192. static void lcd_move_x() { int clip = delta_clip(current_position[Y_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS, max(sw_endstop_min[X_AXIS], -clip), min(sw_endstop_max[X_AXIS], clip)); }
  1193. static void lcd_move_y() { int clip = delta_clip(current_position[X_AXIS]); _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS, max(sw_endstop_min[Y_AXIS], -clip), min(sw_endstop_max[Y_AXIS], clip)); }
  1194. #else
  1195. static void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS, sw_endstop_min[X_AXIS], sw_endstop_max[X_AXIS]); }
  1196. static void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS, sw_endstop_min[Y_AXIS], sw_endstop_max[Y_AXIS]); }
  1197. #endif
  1198. static void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS, sw_endstop_min[Z_AXIS], sw_endstop_max[Z_AXIS]); }
  1199. static void lcd_move_e(
  1200. #if EXTRUDERS > 1
  1201. int8_t eindex = -1
  1202. #endif
  1203. ) {
  1204. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  1205. ENCODER_DIRECTION_NORMAL();
  1206. if (encoderPosition) {
  1207. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  1208. encoderPosition = 0;
  1209. manual_move_to_current(E_AXIS
  1210. #if EXTRUDERS > 1
  1211. , eindex
  1212. #endif
  1213. );
  1214. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1215. }
  1216. if (lcdDrawUpdate) {
  1217. PGM_P pos_label;
  1218. #if EXTRUDERS == 1
  1219. pos_label = PSTR(MSG_MOVE_E);
  1220. #else
  1221. switch (eindex) {
  1222. case 0: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  1223. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  1224. #if EXTRUDERS > 2
  1225. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  1226. #if EXTRUDERS > 3
  1227. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  1228. #endif //EXTRUDERS > 3
  1229. #endif //EXTRUDERS > 2
  1230. }
  1231. #endif //EXTRUDERS > 1
  1232. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  1233. }
  1234. }
  1235. #if EXTRUDERS > 1
  1236. static void lcd_move_e0() { lcd_move_e(0); }
  1237. static void lcd_move_e1() { lcd_move_e(1); }
  1238. #if EXTRUDERS > 2
  1239. static void lcd_move_e2() { lcd_move_e(2); }
  1240. #if EXTRUDERS > 3
  1241. static void lcd_move_e3() { lcd_move_e(3); }
  1242. #endif
  1243. #endif
  1244. #endif // EXTRUDERS > 1
  1245. /**
  1246. *
  1247. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  1248. *
  1249. */
  1250. #if ENABLED(DELTA) || ENABLED(SCARA)
  1251. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1252. #else
  1253. #define _MOVE_XYZ_ALLOWED true
  1254. #endif
  1255. static void _lcd_move_menu_axis() {
  1256. START_MENU();
  1257. MENU_ITEM(back, MSG_MOVE_AXIS);
  1258. if (_MOVE_XYZ_ALLOWED) {
  1259. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  1260. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  1261. }
  1262. if (move_menu_scale < 10.0) {
  1263. if (_MOVE_XYZ_ALLOWED) MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1264. #if EXTRUDERS == 1
  1265. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1266. #else
  1267. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_e0);
  1268. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_e1);
  1269. #if EXTRUDERS > 2
  1270. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_e2);
  1271. #if EXTRUDERS > 3
  1272. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_e3);
  1273. #endif
  1274. #endif
  1275. #endif // EXTRUDERS > 1
  1276. }
  1277. END_MENU();
  1278. }
  1279. static void lcd_move_menu_10mm() {
  1280. move_menu_scale = 10.0;
  1281. _lcd_move_menu_axis();
  1282. }
  1283. static void lcd_move_menu_1mm() {
  1284. move_menu_scale = 1.0;
  1285. _lcd_move_menu_axis();
  1286. }
  1287. static void lcd_move_menu_01mm() {
  1288. move_menu_scale = 0.1;
  1289. _lcd_move_menu_axis();
  1290. }
  1291. /**
  1292. *
  1293. * "Prepare" > "Move Axis" submenu
  1294. *
  1295. */
  1296. static void lcd_move_menu() {
  1297. START_MENU();
  1298. MENU_ITEM(back, MSG_PREPARE);
  1299. if (_MOVE_XYZ_ALLOWED)
  1300. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  1301. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  1302. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  1303. //TODO:X,Y,Z,E
  1304. END_MENU();
  1305. }
  1306. /**
  1307. *
  1308. * "Control" submenu
  1309. *
  1310. */
  1311. static void lcd_control_menu() {
  1312. START_MENU();
  1313. MENU_ITEM(back, MSG_MAIN);
  1314. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1315. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  1316. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  1317. #if HAS_LCD_CONTRAST
  1318. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  1319. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  1320. #endif
  1321. #if ENABLED(FWRETRACT)
  1322. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  1323. #endif
  1324. #if ENABLED(EEPROM_SETTINGS)
  1325. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1326. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  1327. #endif
  1328. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  1329. END_MENU();
  1330. }
  1331. /**
  1332. *
  1333. * "Temperature" submenu
  1334. *
  1335. */
  1336. #if ENABLED(PID_AUTOTUNE_MENU)
  1337. #if ENABLED(PIDTEMP)
  1338. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  1339. const int heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP);
  1340. #endif
  1341. #if ENABLED(PIDTEMPBED)
  1342. int autotune_temp_bed = 70;
  1343. #endif
  1344. static void _lcd_autotune(int e) {
  1345. char cmd[30];
  1346. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  1347. #if HAS_PID_FOR_BOTH
  1348. e < 0 ? autotune_temp_bed : autotune_temp[e]
  1349. #elif ENABLED(PIDTEMPBED)
  1350. autotune_temp_bed
  1351. #else
  1352. autotune_temp[e]
  1353. #endif
  1354. );
  1355. enqueue_and_echo_command(cmd);
  1356. }
  1357. #endif //PID_AUTOTUNE_MENU
  1358. #if ENABLED(PIDTEMP)
  1359. // Helpers for editing PID Ki & Kd values
  1360. // grab the PID value out of the temp variable; scale it; then update the PID driver
  1361. void copy_and_scalePID_i(int e) {
  1362. #if DISABLED(PID_PARAMS_PER_HOTEND)
  1363. UNUSED(e);
  1364. #endif
  1365. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  1366. thermalManager.updatePID();
  1367. }
  1368. void copy_and_scalePID_d(int e) {
  1369. #if DISABLED(PID_PARAMS_PER_HOTEND)
  1370. UNUSED(e);
  1371. #endif
  1372. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  1373. thermalManager.updatePID();
  1374. }
  1375. #define _PIDTEMP_BASE_FUNCTIONS(eindex) \
  1376. void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
  1377. void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); }
  1378. #if ENABLED(PID_AUTOTUNE_MENU)
  1379. #define _PIDTEMP_FUNCTIONS(eindex) \
  1380. _PIDTEMP_BASE_FUNCTIONS(eindex); \
  1381. void lcd_autotune_callback_E ## eindex() { _lcd_autotune(eindex); }
  1382. #else
  1383. #define _PIDTEMP_FUNCTIONS(eindex) _PIDTEMP_BASE_FUNCTIONS(eindex)
  1384. #endif
  1385. _PIDTEMP_FUNCTIONS(0);
  1386. #if ENABLED(PID_PARAMS_PER_HOTEND)
  1387. #if HOTENDS > 1
  1388. _PIDTEMP_FUNCTIONS(1);
  1389. #if HOTENDS > 2
  1390. _PIDTEMP_FUNCTIONS(2);
  1391. #if HOTENDS > 3
  1392. _PIDTEMP_FUNCTIONS(3);
  1393. #endif //HOTENDS > 3
  1394. #endif //HOTENDS > 2
  1395. #endif //HOTENDS > 1
  1396. #endif //PID_PARAMS_PER_HOTEND
  1397. #endif //PIDTEMP
  1398. /**
  1399. *
  1400. * "Control" > "Temperature" submenu
  1401. *
  1402. */
  1403. static void lcd_control_temperature_menu() {
  1404. START_MENU();
  1405. //
  1406. // ^ Control
  1407. //
  1408. MENU_ITEM(back, MSG_CONTROL);
  1409. //
  1410. // Nozzle:
  1411. // Nozzle [1-4]:
  1412. //
  1413. #if HOTENDS == 1
  1414. #if TEMP_SENSOR_0 != 0
  1415. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1416. #endif
  1417. #else //HOTENDS > 1
  1418. #if TEMP_SENSOR_0 != 0
  1419. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1420. #endif
  1421. #if TEMP_SENSOR_1 != 0
  1422. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1423. #endif
  1424. #if HOTENDS > 2
  1425. #if TEMP_SENSOR_2 != 0
  1426. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1427. #endif
  1428. #if HOTENDS > 3
  1429. #if TEMP_SENSOR_3 != 0
  1430. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1431. #endif
  1432. #endif // HOTENDS > 3
  1433. #endif // HOTENDS > 2
  1434. #endif // HOTENDS > 1
  1435. //
  1436. // Bed:
  1437. //
  1438. #if TEMP_SENSOR_BED != 0
  1439. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15);
  1440. #endif
  1441. //
  1442. // Fan Speed:
  1443. //
  1444. #if FAN_COUNT > 0
  1445. #if HAS_FAN0
  1446. #if FAN_COUNT > 1
  1447. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1448. #else
  1449. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1450. #endif
  1451. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1452. #endif
  1453. #if HAS_FAN1
  1454. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1455. #endif
  1456. #if HAS_FAN2
  1457. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1458. #endif
  1459. #endif // FAN_COUNT > 0
  1460. //
  1461. // Autotemp, Min, Max, Fact
  1462. //
  1463. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1464. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  1465. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1466. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1467. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  1468. #endif
  1469. //
  1470. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  1471. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  1472. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  1473. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  1474. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  1475. //
  1476. #if ENABLED(PIDTEMP)
  1477. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  1478. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1479. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1480. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1481. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1482. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1483. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  1484. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1485. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  1486. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1487. #else
  1488. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  1489. #endif
  1490. #if ENABLED(PID_AUTOTUNE_MENU)
  1491. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1492. _PID_MENU_ITEMS(ELABEL, eindex); \
  1493. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  1494. #else
  1495. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1496. #endif
  1497. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1498. PID_MENU_ITEMS(MSG_E1, 0);
  1499. PID_MENU_ITEMS(MSG_E2, 1);
  1500. #if HOTENDS > 2
  1501. PID_MENU_ITEMS(MSG_E3, 2);
  1502. #if HOTENDS > 3
  1503. PID_MENU_ITEMS(MSG_E4, 3);
  1504. #endif //HOTENDS > 3
  1505. #endif //HOTENDS > 2
  1506. #else //!PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1507. PID_MENU_ITEMS("", 0);
  1508. #endif //!PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1509. #endif //PIDTEMP
  1510. //
  1511. // Preheat PLA conf
  1512. //
  1513. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  1514. //
  1515. // Preheat ABS conf
  1516. //
  1517. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  1518. END_MENU();
  1519. }
  1520. /**
  1521. *
  1522. * "Temperature" > "Preheat PLA conf" submenu
  1523. *
  1524. */
  1525. static void lcd_control_temperature_preheat_pla_settings_menu() {
  1526. START_MENU();
  1527. MENU_ITEM(back, MSG_TEMPERATURE);
  1528. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &preheatFanSpeed1, 0, 255);
  1529. #if TEMP_SENSOR_0 != 0
  1530. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &preheatHotendTemp1, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1531. #endif
  1532. #if TEMP_SENSOR_BED != 0
  1533. MENU_ITEM_EDIT(int3, MSG_BED, &preheatBedTemp1, BED_MINTEMP, BED_MAXTEMP - 15);
  1534. #endif
  1535. #if ENABLED(EEPROM_SETTINGS)
  1536. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1537. #endif
  1538. END_MENU();
  1539. }
  1540. /**
  1541. *
  1542. * "Temperature" > "Preheat ABS conf" submenu
  1543. *
  1544. */
  1545. static void lcd_control_temperature_preheat_abs_settings_menu() {
  1546. START_MENU();
  1547. MENU_ITEM(back, MSG_TEMPERATURE);
  1548. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &preheatFanSpeed2, 0, 255);
  1549. #if TEMP_SENSOR_0 != 0
  1550. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &preheatHotendTemp2, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1551. #endif
  1552. #if TEMP_SENSOR_BED != 0
  1553. MENU_ITEM_EDIT(int3, MSG_BED, &preheatBedTemp2, BED_MINTEMP, BED_MAXTEMP - 15);
  1554. #endif
  1555. #if ENABLED(EEPROM_SETTINGS)
  1556. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1557. #endif
  1558. END_MENU();
  1559. }
  1560. static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  1561. /**
  1562. *
  1563. * "Control" > "Motion" submenu
  1564. *
  1565. */
  1566. static void lcd_control_motion_menu() {
  1567. START_MENU();
  1568. MENU_ITEM(back, MSG_CONTROL);
  1569. #if HAS_BED_PROBE
  1570. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  1571. #endif
  1572. // Manual bed leveling, Bed Z:
  1573. #if ENABLED(MANUAL_BED_LEVELING)
  1574. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1575. #endif
  1576. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  1577. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &planner.max_xy_jerk, 1, 990);
  1578. #if ENABLED(DELTA)
  1579. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_z_jerk, 1, 990);
  1580. #else
  1581. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_z_jerk, 0.1, 990);
  1582. #endif
  1583. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_e_jerk, 1, 990);
  1584. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate[X_AXIS], 1, 999);
  1585. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate[Y_AXIS], 1, 999);
  1586. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate[Z_AXIS], 1, 999);
  1587. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate[E_AXIS], 1, 999);
  1588. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate, 0, 999);
  1589. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate, 0, 999);
  1590. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  1591. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  1592. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  1593. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  1594. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  1595. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  1596. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999);
  1597. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999);
  1598. #if ENABLED(DELTA)
  1599. MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999);
  1600. #else
  1601. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999);
  1602. #endif
  1603. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999);
  1604. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  1605. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  1606. #endif
  1607. #if ENABLED(SCARA)
  1608. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS], 0.5, 2);
  1609. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS], 0.5, 2);
  1610. #endif
  1611. END_MENU();
  1612. }
  1613. /**
  1614. *
  1615. * "Control" > "Filament" submenu
  1616. *
  1617. */
  1618. static void lcd_control_volumetric_menu() {
  1619. START_MENU();
  1620. MENU_ITEM(back, MSG_CONTROL);
  1621. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  1622. if (volumetric_enabled) {
  1623. #if EXTRUDERS == 1
  1624. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1625. #else //EXTRUDERS > 1
  1626. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1627. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  1628. #if EXTRUDERS > 2
  1629. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  1630. #if EXTRUDERS > 3
  1631. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  1632. #endif //EXTRUDERS > 3
  1633. #endif //EXTRUDERS > 2
  1634. #endif //EXTRUDERS > 1
  1635. }
  1636. END_MENU();
  1637. }
  1638. /**
  1639. *
  1640. * "Control" > "Contrast" submenu
  1641. *
  1642. */
  1643. #if HAS_LCD_CONTRAST
  1644. static void lcd_set_contrast() {
  1645. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  1646. ENCODER_DIRECTION_NORMAL();
  1647. if (encoderPosition) {
  1648. set_lcd_contrast(lcd_contrast + encoderPosition);
  1649. encoderPosition = 0;
  1650. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1651. }
  1652. if (lcdDrawUpdate) {
  1653. lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
  1654. #if LCD_CONTRAST_MAX >= 100
  1655. itostr3(lcd_contrast)
  1656. #else
  1657. itostr2(lcd_contrast)
  1658. #endif
  1659. );
  1660. }
  1661. }
  1662. #endif // HAS_LCD_CONTRAST
  1663. /**
  1664. *
  1665. * "Control" > "Retract" submenu
  1666. *
  1667. */
  1668. #if ENABLED(FWRETRACT)
  1669. static void lcd_control_retract_menu() {
  1670. START_MENU();
  1671. MENU_ITEM(back, MSG_CONTROL);
  1672. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  1673. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  1674. #if EXTRUDERS > 1
  1675. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  1676. #endif
  1677. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  1678. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  1679. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  1680. #if EXTRUDERS > 1
  1681. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  1682. #endif
  1683. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  1684. END_MENU();
  1685. }
  1686. #endif // FWRETRACT
  1687. #if ENABLED(SDSUPPORT)
  1688. #if !PIN_EXISTS(SD_DETECT)
  1689. static void lcd_sd_refresh() {
  1690. card.initsd();
  1691. encoderTopLine = 0;
  1692. }
  1693. #endif
  1694. static void lcd_sd_updir() {
  1695. card.updir();
  1696. encoderTopLine = 0;
  1697. }
  1698. /**
  1699. *
  1700. * "Print from SD" submenu
  1701. *
  1702. */
  1703. void lcd_sdcard_menu() {
  1704. ENCODER_DIRECTION_MENUS();
  1705. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
  1706. uint16_t fileCnt = card.getnrfilenames();
  1707. START_MENU();
  1708. MENU_ITEM(back, MSG_MAIN);
  1709. card.getWorkDirName();
  1710. if (card.filename[0] == '/') {
  1711. #if !PIN_EXISTS(SD_DETECT)
  1712. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1713. #endif
  1714. }
  1715. else {
  1716. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1717. }
  1718. for (uint16_t i = 0; i < fileCnt; i++) {
  1719. if (_menuLineNr == _thisItemNr) {
  1720. card.getfilename(
  1721. #if ENABLED(SDCARD_RATHERRECENTFIRST)
  1722. fileCnt-1 -
  1723. #endif
  1724. i
  1725. );
  1726. if (card.filenameIsDir)
  1727. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1728. else
  1729. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1730. }
  1731. else {
  1732. MENU_ITEM_DUMMY();
  1733. }
  1734. }
  1735. END_MENU();
  1736. }
  1737. #endif //SDSUPPORT
  1738. #if ENABLED(LCD_INFO_MENU)
  1739. #if ENABLED(PRINTCOUNTER)
  1740. /**
  1741. *
  1742. * About Printer > Statistics submenu
  1743. *
  1744. */
  1745. static void lcd_info_stats_menu() {
  1746. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  1747. PrintCounter print_job_counter = PrintCounter();
  1748. print_job_counter.loadStats();
  1749. printStatistics stats = print_job_counter.getStats();
  1750. char timeString[8];
  1751. sprintf_P(timeString, PSTR("%i:%02i"), int(stats.printTime / 60 / 60), int(stats.printTime / 60) % 60);
  1752. START_SCREEN(); // 12345678901234567890
  1753. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count : 999
  1754. STATIC_ITEM(MSG_INFO_FINISHED_PRINTS ": ", false, false, itostr3left(stats.finishedPrints)); // Finished : 666
  1755. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false, timeString); // Total Time : 123:45
  1756. END_SCREEN();
  1757. }
  1758. #endif // PRINTCOUNTER
  1759. /**
  1760. *
  1761. * About Printer > Thermistors
  1762. *
  1763. */
  1764. static void lcd_info_thermistors_menu() {
  1765. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  1766. START_SCREEN();
  1767. #define THERMISTOR_ID TEMP_SENSOR_0
  1768. #include "thermistornames.h"
  1769. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  1770. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  1771. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  1772. #if TEMP_SENSOR_1 != 0
  1773. #undef THERMISTOR_ID
  1774. #define THERMISTOR_ID TEMP_SENSOR_1
  1775. #include "thermistornames.h"
  1776. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  1777. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  1778. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  1779. #endif
  1780. #if TEMP_SENSOR_2 != 0
  1781. #undef THERMISTOR_ID
  1782. #define THERMISTOR_ID TEMP_SENSOR_2
  1783. #include "thermistornames.h"
  1784. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  1785. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  1786. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  1787. #endif
  1788. #if TEMP_SENSOR_3 != 0
  1789. #undef THERMISTOR_ID
  1790. #define THERMISTOR_ID TEMP_SENSOR_3
  1791. #include "thermistornames.h"
  1792. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  1793. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  1794. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  1795. #endif
  1796. #if TEMP_SENSOR_BED != 0
  1797. #undef THERMISTOR_ID
  1798. #define THERMISTOR_ID TEMP_SENSOR_BED
  1799. #include "thermistornames.h"
  1800. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  1801. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  1802. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  1803. #endif
  1804. END_SCREEN();
  1805. }
  1806. /**
  1807. *
  1808. * About Printer > Board Info
  1809. *
  1810. */
  1811. static void lcd_info_board_menu() {
  1812. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  1813. START_SCREEN();
  1814. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  1815. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE)); // Baud: 250000
  1816. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION); // Protocol: 1.0
  1817. #ifdef POWER_SUPPLY
  1818. #if (POWER_SUPPLY == 1)
  1819. STATIC_ITEM(MSG_INFO_PSU ": ATX"); // Power Supply: ATX
  1820. #elif (POWER_SUPPLY == 2)
  1821. STATIC_ITEM(MSG_INFO_PSU ": XBox"); // Power Supply: XBox
  1822. #endif
  1823. #endif // POWER_SUPPLY
  1824. END_SCREEN();
  1825. }
  1826. /**
  1827. *
  1828. * About Printer > Printer Info
  1829. *
  1830. */
  1831. static void lcd_info_printer_menu() {
  1832. if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
  1833. START_SCREEN();
  1834. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  1835. STATIC_ITEM(SHORT_BUILD_VERSION); // x.x.x-Branch
  1836. STATIC_ITEM(STRING_DISTRIBUTION_DATE); // YYYY-MM-DD HH:MM
  1837. STATIC_ITEM(MACHINE_NAME); // My3DPrinter
  1838. STATIC_ITEM(WEBSITE_URL); // www.my3dprinter.com
  1839. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS)); // Extruders: 2
  1840. END_SCREEN();
  1841. }
  1842. /**
  1843. *
  1844. * "About Printer" submenu
  1845. *
  1846. */
  1847. static void lcd_info_menu() {
  1848. START_MENU();
  1849. MENU_ITEM(back, MSG_MAIN);
  1850. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  1851. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  1852. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  1853. #if ENABLED(PRINTCOUNTER)
  1854. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  1855. #endif
  1856. END_MENU();
  1857. }
  1858. #endif // LCD_INFO_MENU
  1859. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  1860. static void lcd_filament_change_resume_print() {
  1861. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_RESUME_PRINT;
  1862. lcdDrawUpdate = 2;
  1863. lcd_goto_screen(lcd_status_screen);
  1864. }
  1865. static void lcd_filament_change_extrude_more() {
  1866. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_EXTRUDE_MORE;
  1867. }
  1868. static void lcd_filament_change_option_menu() {
  1869. START_MENU();
  1870. #if LCD_HEIGHT > 2
  1871. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  1872. #endif
  1873. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_filament_change_resume_print);
  1874. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_filament_change_extrude_more);
  1875. END_MENU();
  1876. }
  1877. static void lcd_filament_change_init_message() {
  1878. START_SCREEN();
  1879. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1880. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  1881. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  1882. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  1883. #endif
  1884. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  1885. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  1886. #endif
  1887. END_SCREEN();
  1888. }
  1889. static void lcd_filament_change_unload_message() {
  1890. START_SCREEN();
  1891. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1892. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  1893. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  1894. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  1895. #endif
  1896. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  1897. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  1898. #endif
  1899. END_SCREEN();
  1900. }
  1901. static void lcd_filament_change_insert_message() {
  1902. START_SCREEN();
  1903. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1904. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  1905. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  1906. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  1907. #endif
  1908. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  1909. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  1910. #endif
  1911. END_SCREEN();
  1912. }
  1913. static void lcd_filament_change_load_message() {
  1914. START_SCREEN();
  1915. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1916. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  1917. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  1918. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  1919. #endif
  1920. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  1921. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  1922. #endif
  1923. END_SCREEN();
  1924. }
  1925. static void lcd_filament_change_extrude_message() {
  1926. START_SCREEN();
  1927. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1928. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  1929. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  1930. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  1931. #endif
  1932. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  1933. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  1934. #endif
  1935. END_SCREEN();
  1936. }
  1937. static void lcd_filament_change_resume_message() {
  1938. START_SCREEN();
  1939. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1940. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  1941. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  1942. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  1943. #endif
  1944. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  1945. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  1946. #endif
  1947. END_SCREEN();
  1948. }
  1949. void lcd_filament_change_show_message(FilamentChangeMessage message) {
  1950. switch (message) {
  1951. case FILAMENT_CHANGE_MESSAGE_INIT:
  1952. defer_return_to_status = true;
  1953. lcd_goto_screen(lcd_filament_change_init_message);
  1954. break;
  1955. case FILAMENT_CHANGE_MESSAGE_UNLOAD:
  1956. lcd_goto_screen(lcd_filament_change_unload_message);
  1957. break;
  1958. case FILAMENT_CHANGE_MESSAGE_INSERT:
  1959. lcd_goto_screen(lcd_filament_change_insert_message);
  1960. break;
  1961. case FILAMENT_CHANGE_MESSAGE_LOAD:
  1962. lcd_goto_screen(lcd_filament_change_load_message);
  1963. break;
  1964. case FILAMENT_CHANGE_MESSAGE_EXTRUDE:
  1965. lcd_goto_screen(lcd_filament_change_extrude_message);
  1966. break;
  1967. case FILAMENT_CHANGE_MESSAGE_OPTION:
  1968. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_WAIT_FOR;
  1969. lcd_goto_screen(lcd_filament_change_option_menu);
  1970. break;
  1971. case FILAMENT_CHANGE_MESSAGE_RESUME:
  1972. lcd_goto_screen(lcd_filament_change_resume_message);
  1973. break;
  1974. case FILAMENT_CHANGE_MESSAGE_STATUS:
  1975. lcd_return_to_status();
  1976. break;
  1977. }
  1978. }
  1979. #endif // FILAMENT_CHANGE_FEATURE
  1980. /**
  1981. *
  1982. * Functions for editing single values
  1983. *
  1984. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  1985. *
  1986. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  1987. *
  1988. * bool _menu_edit_int3();
  1989. * void menu_edit_int3(); // edit int (interactively)
  1990. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  1991. * static void _menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1992. * static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1993. * static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, screenFunc_t callback); // edit int with callback
  1994. *
  1995. * You can then use one of the menu macros to present the edit interface:
  1996. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  1997. *
  1998. * This expands into a more primitive menu item:
  1999. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  2000. *
  2001. *
  2002. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  2003. *
  2004. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  2005. */
  2006. #define menu_edit_type(_type, _name, _strFunc, scale) \
  2007. bool _menu_edit_ ## _name () { \
  2008. ENCODER_DIRECTION_NORMAL(); \
  2009. bool isClicked = LCD_CLICKED; \
  2010. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2011. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  2012. if (lcdDrawUpdate) \
  2013. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  2014. if (isClicked) { \
  2015. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  2016. lcd_goto_previous_menu(true); \
  2017. } \
  2018. return isClicked; \
  2019. } \
  2020. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  2021. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  2022. static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  2023. lcd_save_previous_menu(); \
  2024. \
  2025. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  2026. \
  2027. editLabel = pstr; \
  2028. editValue = ptr; \
  2029. minEditValue = minValue * scale; \
  2030. maxEditValue = maxValue * scale - minEditValue; \
  2031. encoderPosition = (*ptr) * scale - minEditValue; \
  2032. } \
  2033. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  2034. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2035. currentScreen = menu_edit_ ## _name; \
  2036. }\
  2037. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, screenFunc_t callback) { \
  2038. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2039. currentScreen = menu_edit_callback_ ## _name; \
  2040. callbackFunc = callback; \
  2041. }
  2042. menu_edit_type(int, int3, itostr3, 1);
  2043. menu_edit_type(float, float3, ftostr3, 1);
  2044. menu_edit_type(float, float32, ftostr32, 100);
  2045. menu_edit_type(float, float43, ftostr43sign, 1000);
  2046. menu_edit_type(float, float5, ftostr5rj, 0.01);
  2047. menu_edit_type(float, float51, ftostr51sign, 10);
  2048. menu_edit_type(float, float52, ftostr52sign, 100);
  2049. menu_edit_type(unsigned long, long5, ftostr5rj, 0.01);
  2050. /**
  2051. *
  2052. * Handlers for RepRap World Keypad input
  2053. *
  2054. */
  2055. #if ENABLED(REPRAPWORLD_KEYPAD)
  2056. static void reprapworld_keypad_move_z_up() {
  2057. encoderPosition = 1;
  2058. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2059. lcd_move_z();
  2060. }
  2061. static void reprapworld_keypad_move_z_down() {
  2062. encoderPosition = -1;
  2063. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2064. lcd_move_z();
  2065. }
  2066. static void reprapworld_keypad_move_x_left() {
  2067. encoderPosition = -1;
  2068. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2069. lcd_move_x();
  2070. }
  2071. static void reprapworld_keypad_move_x_right() {
  2072. encoderPosition = 1;
  2073. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2074. lcd_move_x();
  2075. }
  2076. static void reprapworld_keypad_move_y_down() {
  2077. encoderPosition = 1;
  2078. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2079. lcd_move_y();
  2080. }
  2081. static void reprapworld_keypad_move_y_up() {
  2082. encoderPosition = -1;
  2083. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2084. lcd_move_y();
  2085. }
  2086. static void reprapworld_keypad_move_home() {
  2087. enqueue_and_echo_commands_P(PSTR("G28")); // move all axes home
  2088. }
  2089. #endif // REPRAPWORLD_KEYPAD
  2090. /**
  2091. *
  2092. * Audio feedback for controller clicks
  2093. *
  2094. */
  2095. #if ENABLED(LCD_USE_I2C_BUZZER)
  2096. void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
  2097. lcd.buzz(duration, freq);
  2098. }
  2099. #endif
  2100. void lcd_quick_feedback() {
  2101. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2102. next_button_update_ms = millis() + 500;
  2103. // Buzz and wait. The delay is needed for buttons to settle!
  2104. #if ENABLED(LCD_USE_I2C_BUZZER)
  2105. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  2106. delay(10);
  2107. #elif PIN_EXISTS(BEEPER)
  2108. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  2109. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  2110. #endif
  2111. }
  2112. /**
  2113. *
  2114. * Menu actions
  2115. *
  2116. */
  2117. static void menu_action_back() { lcd_goto_previous_menu(); }
  2118. static void menu_action_submenu(screenFunc_t func) { lcd_save_previous_menu(); lcd_goto_screen(func); }
  2119. static void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  2120. static void menu_action_function(screenFunc_t func) { (*func)(); }
  2121. #if ENABLED(SDSUPPORT)
  2122. static void menu_action_sdfile(const char* filename, char* longFilename) {
  2123. UNUSED(longFilename);
  2124. card.openAndPrintFile(filename);
  2125. lcd_return_to_status();
  2126. }
  2127. static void menu_action_sddirectory(const char* filename, char* longFilename) {
  2128. UNUSED(longFilename);
  2129. card.chdir(filename);
  2130. encoderPosition = 0;
  2131. }
  2132. #endif //SDSUPPORT
  2133. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr = !(*ptr); }
  2134. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  2135. menu_action_setting_edit_bool(pstr, ptr);
  2136. (*callback)();
  2137. }
  2138. #endif //ULTIPANEL
  2139. /** LCD API **/
  2140. void lcd_init() {
  2141. lcd_implementation_init();
  2142. #if ENABLED(NEWPANEL)
  2143. #if BUTTON_EXISTS(EN1)
  2144. SET_INPUT(BTN_EN1);
  2145. WRITE(BTN_EN1, HIGH);
  2146. #endif
  2147. #if BUTTON_EXISTS(EN2)
  2148. SET_INPUT(BTN_EN2);
  2149. WRITE(BTN_EN2, HIGH);
  2150. #endif
  2151. #if BUTTON_EXISTS(ENC)
  2152. SET_INPUT(BTN_ENC);
  2153. WRITE(BTN_ENC, HIGH);
  2154. #endif
  2155. #if ENABLED(REPRAPWORLD_KEYPAD)
  2156. pinMode(SHIFT_CLK, OUTPUT);
  2157. pinMode(SHIFT_LD, OUTPUT);
  2158. pinMode(SHIFT_OUT, INPUT);
  2159. WRITE(SHIFT_OUT, HIGH);
  2160. WRITE(SHIFT_LD, HIGH);
  2161. #endif
  2162. #if BUTTON_EXISTS(UP)
  2163. SET_INPUT(BTN_UP);
  2164. #endif
  2165. #if BUTTON_EXISTS(DWN)
  2166. SET_INPUT(BTN_DWN);
  2167. #endif
  2168. #if BUTTON_EXISTS(LFT)
  2169. SET_INPUT(BTN_LFT);
  2170. #endif
  2171. #if BUTTON_EXISTS(RT)
  2172. SET_INPUT(BTN_RT);
  2173. #endif
  2174. #else // !NEWPANEL
  2175. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  2176. pinMode(SR_DATA_PIN, OUTPUT);
  2177. pinMode(SR_CLK_PIN, OUTPUT);
  2178. #elif defined(SHIFT_CLK)
  2179. pinMode(SHIFT_CLK, OUTPUT);
  2180. pinMode(SHIFT_LD, OUTPUT);
  2181. pinMode(SHIFT_EN, OUTPUT);
  2182. pinMode(SHIFT_OUT, INPUT);
  2183. WRITE(SHIFT_OUT, HIGH);
  2184. WRITE(SHIFT_LD, HIGH);
  2185. WRITE(SHIFT_EN, LOW);
  2186. #endif // SR_LCD_2W_NL
  2187. #endif // !NEWPANEL
  2188. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2189. SET_INPUT(SD_DETECT_PIN);
  2190. WRITE(SD_DETECT_PIN, HIGH);
  2191. lcd_sd_status = 2; // UNKNOWN
  2192. #endif
  2193. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2194. slow_buttons = 0;
  2195. #endif
  2196. lcd_buttons_update();
  2197. #if ENABLED(ULTIPANEL)
  2198. encoderDiff = 0;
  2199. #endif
  2200. }
  2201. int lcd_strlen(const char* s) {
  2202. int i = 0, j = 0;
  2203. while (s[i]) {
  2204. #ifdef MAPPER_NON
  2205. j++;
  2206. #else
  2207. if ((s[i] & 0xc0) != 0x80) j++;
  2208. #endif
  2209. i++;
  2210. }
  2211. return j;
  2212. }
  2213. int lcd_strlen_P(const char* s) {
  2214. int j = 0;
  2215. while (pgm_read_byte(s)) {
  2216. #ifdef MAPPER_NON
  2217. j++;
  2218. #else
  2219. if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
  2220. #endif
  2221. s++;
  2222. }
  2223. return j;
  2224. }
  2225. bool lcd_blink() {
  2226. static uint8_t blink = 0;
  2227. static millis_t next_blink_ms = 0;
  2228. millis_t ms = millis();
  2229. if (ELAPSED(ms, next_blink_ms)) {
  2230. blink ^= 0xFF;
  2231. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  2232. }
  2233. return blink != 0;
  2234. }
  2235. /**
  2236. * Update the LCD, read encoder buttons, etc.
  2237. * - Read button states
  2238. * - Check the SD Card slot state
  2239. * - Act on RepRap World keypad input
  2240. * - Update the encoder position
  2241. * - Apply acceleration to the encoder position
  2242. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  2243. * - Reset the Info Screen timeout if there's any input
  2244. * - Update status indicators, if any
  2245. *
  2246. * Run the current LCD menu handler callback function:
  2247. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  2248. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  2249. * - Call the menu handler. Menu handlers should do the following:
  2250. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  2251. * (Encoder events automatically set lcdDrawUpdate for you.)
  2252. * - if (lcdDrawUpdate) { redraw }
  2253. * - Before exiting the handler set lcdDrawUpdate to:
  2254. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  2255. * - LCDVIEW_REDRAW_NOW or LCDVIEW_NONE to keep drawingm but only in this loop.
  2256. * - LCDVIEW_REDRAW_NEXT to keep drawing and draw on the next loop also.
  2257. * - LCDVIEW_CALL_NO_REDRAW to keep drawing (or start drawing) with no redraw on the next loop.
  2258. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  2259. * so don't change lcdDrawUpdate without considering this.
  2260. *
  2261. * After the menu handler callback runs (or not):
  2262. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  2263. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  2264. *
  2265. * No worries. This function is only called from the main thread.
  2266. */
  2267. void lcd_update() {
  2268. #if ENABLED(ULTIPANEL)
  2269. static millis_t return_to_status_ms = 0;
  2270. manage_manual_move();
  2271. #endif
  2272. lcd_buttons_update();
  2273. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2274. bool sd_status = IS_SD_INSERTED;
  2275. if (sd_status != lcd_sd_status && lcd_detected()) {
  2276. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2277. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  2278. #if ENABLED(LCD_PROGRESS_BAR) && ENABLED(ULTIPANEL)
  2279. currentScreen == lcd_status_screen
  2280. #endif
  2281. );
  2282. if (sd_status) {
  2283. card.initsd();
  2284. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2285. }
  2286. else {
  2287. card.release();
  2288. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2289. }
  2290. lcd_sd_status = sd_status;
  2291. }
  2292. #endif //SDSUPPORT && SD_DETECT_PIN
  2293. millis_t ms = millis();
  2294. if (ELAPSED(ms, next_lcd_update_ms)) {
  2295. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  2296. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  2297. lcd_implementation_update_indicators();
  2298. #endif
  2299. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2300. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  2301. #endif
  2302. #if ENABLED(ULTIPANEL)
  2303. #if ENABLED(REPRAPWORLD_KEYPAD)
  2304. #if ENABLED(DELTA) || ENABLED(SCARA)
  2305. #define _KEYPAD_MOVE_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2306. #else
  2307. #define _KEYPAD_MOVE_ALLOWED true
  2308. #endif
  2309. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  2310. if (_KEYPAD_MOVE_ALLOWED) {
  2311. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2312. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  2313. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  2314. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  2315. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  2316. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  2317. }
  2318. #endif
  2319. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  2320. if (encoderPastThreshold || LCD_CLICKED) {
  2321. if (encoderPastThreshold) {
  2322. int32_t encoderMultiplier = 1;
  2323. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  2324. if (encoderRateMultiplierEnabled) {
  2325. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  2326. if (lastEncoderMovementMillis != 0) {
  2327. // Note that the rate is always calculated between to passes through the
  2328. // loop and that the abs of the encoderDiff value is tracked.
  2329. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  2330. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  2331. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  2332. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  2333. SERIAL_ECHO_START;
  2334. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  2335. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  2336. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  2337. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  2338. SERIAL_EOL;
  2339. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  2340. }
  2341. lastEncoderMovementMillis = ms;
  2342. } // encoderRateMultiplierEnabled
  2343. #endif //ENCODER_RATE_MULTIPLIER
  2344. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  2345. encoderDiff = 0;
  2346. }
  2347. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  2348. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2349. }
  2350. #endif //ULTIPANEL
  2351. // We arrive here every ~100ms when idling often enough.
  2352. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  2353. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  2354. if (
  2355. #if ENABLED(ULTIPANEL)
  2356. currentScreen == lcd_status_screen &&
  2357. #endif
  2358. !lcd_status_update_delay--) {
  2359. lcd_status_update_delay = 9;
  2360. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2361. }
  2362. if (lcdDrawUpdate) {
  2363. switch (lcdDrawUpdate) {
  2364. case LCDVIEW_CALL_NO_REDRAW:
  2365. lcdDrawUpdate = LCDVIEW_NONE;
  2366. break;
  2367. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  2368. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  2369. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2370. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  2371. case LCDVIEW_NONE:
  2372. break;
  2373. }
  2374. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  2375. static int8_t dot_color = 0;
  2376. dot_color = 1 - dot_color;
  2377. u8g.firstPage();
  2378. do {
  2379. lcd_setFont(FONT_MENU);
  2380. u8g.setPrintPos(125, 0);
  2381. u8g.setColorIndex(dot_color); // Set color for the alive dot
  2382. u8g.drawPixel(127, 63); // draw alive dot
  2383. u8g.setColorIndex(1); // black on white
  2384. (*currentScreen)();
  2385. } while (u8g.nextPage());
  2386. #elif ENABLED(ULTIPANEL)
  2387. (*currentScreen)();
  2388. #else
  2389. lcd_status_screen();
  2390. #endif
  2391. }
  2392. #if ENABLED(ULTIPANEL)
  2393. // Return to Status Screen after a timeout
  2394. if (currentScreen == lcd_status_screen || defer_return_to_status)
  2395. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  2396. else if (ELAPSED(ms, return_to_status_ms))
  2397. lcd_return_to_status();
  2398. #endif // ULTIPANEL
  2399. switch (lcdDrawUpdate) {
  2400. case LCDVIEW_CLEAR_CALL_REDRAW:
  2401. lcd_implementation_clear();
  2402. case LCDVIEW_CALL_REDRAW_NEXT:
  2403. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2404. break;
  2405. case LCDVIEW_REDRAW_NOW:
  2406. lcdDrawUpdate = LCDVIEW_NONE;
  2407. break;
  2408. case LCDVIEW_NONE:
  2409. break;
  2410. }
  2411. }
  2412. }
  2413. void lcd_finishstatus(bool persist=false) {
  2414. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  2415. UNUSED(persist);
  2416. #endif
  2417. #if ENABLED(LCD_PROGRESS_BAR)
  2418. progress_bar_ms = millis();
  2419. #if PROGRESS_MSG_EXPIRE > 0
  2420. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  2421. #endif
  2422. #endif
  2423. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2424. #if ENABLED(FILAMENT_LCD_DISPLAY)
  2425. previous_lcd_status_ms = millis(); //get status message to show up for a while
  2426. #endif
  2427. }
  2428. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  2429. void dontExpireStatus() { expire_status_ms = 0; }
  2430. #endif
  2431. void set_utf_strlen(char* s, uint8_t n) {
  2432. uint8_t i = 0, j = 0;
  2433. while (s[i] && (j < n)) {
  2434. if ((s[i] & 0xc0u) != 0x80u) j++;
  2435. i++;
  2436. }
  2437. while (j++ < n) s[i++] = ' ';
  2438. s[i] = '\0';
  2439. }
  2440. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  2441. void lcd_setstatus(const char* message, bool persist) {
  2442. if (lcd_status_message_level > 0) return;
  2443. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  2444. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  2445. lcd_finishstatus(persist);
  2446. }
  2447. void lcd_setstatuspgm(const char* message, uint8_t level) {
  2448. if (level >= lcd_status_message_level) {
  2449. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  2450. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  2451. lcd_status_message_level = level;
  2452. lcd_finishstatus(level > 0);
  2453. }
  2454. }
  2455. void lcd_setalertstatuspgm(const char* message) {
  2456. lcd_setstatuspgm(message, 1);
  2457. #if ENABLED(ULTIPANEL)
  2458. lcd_return_to_status();
  2459. #endif
  2460. }
  2461. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  2462. #if HAS_LCD_CONTRAST
  2463. void set_lcd_contrast(int value) {
  2464. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  2465. u8g.setContrast(lcd_contrast);
  2466. }
  2467. #endif
  2468. #if ENABLED(ULTIPANEL)
  2469. /**
  2470. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  2471. * These values are independent of which pins are used for EN_A and EN_B indications
  2472. * The rotary encoder part is also independent to the chipset used for the LCD
  2473. */
  2474. #if defined(EN_A) && defined(EN_B)
  2475. #define encrot0 0
  2476. #define encrot1 2
  2477. #define encrot2 3
  2478. #define encrot3 1
  2479. #endif
  2480. #define GET_BUTTON_STATES(DST) \
  2481. uint8_t new_##DST = 0; \
  2482. WRITE(SHIFT_LD, LOW); \
  2483. WRITE(SHIFT_LD, HIGH); \
  2484. for (int8_t i = 0; i < 8; i++) { \
  2485. new_##DST >>= 1; \
  2486. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  2487. WRITE(SHIFT_CLK, HIGH); \
  2488. WRITE(SHIFT_CLK, LOW); \
  2489. } \
  2490. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  2491. /**
  2492. * Read encoder buttons from the hardware registers
  2493. * Warning: This function is called from interrupt context!
  2494. */
  2495. void lcd_buttons_update() {
  2496. #if ENABLED(NEWPANEL)
  2497. uint8_t newbutton = 0;
  2498. #if BUTTON_EXISTS(EN1)
  2499. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  2500. #endif
  2501. #if BUTTON_EXISTS(EN2)
  2502. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  2503. #endif
  2504. #if LCD_HAS_DIRECTIONAL_BUTTONS || BUTTON_EXISTS(ENC)
  2505. millis_t now = millis();
  2506. #endif
  2507. #if LCD_HAS_DIRECTIONAL_BUTTONS
  2508. if (ELAPSED(now, next_button_update_ms)) {
  2509. if (false) {
  2510. // for the else-ifs below
  2511. }
  2512. #if BUTTON_EXISTS(UP)
  2513. else if (BUTTON_PRESSED(UP)) {
  2514. encoderDiff = -(ENCODER_STEPS_PER_MENU_ITEM);
  2515. next_button_update_ms = now + 300;
  2516. }
  2517. #endif
  2518. #if BUTTON_EXISTS(DWN)
  2519. else if (BUTTON_PRESSED(DWN)) {
  2520. encoderDiff = ENCODER_STEPS_PER_MENU_ITEM;
  2521. next_button_update_ms = now + 300;
  2522. }
  2523. #endif
  2524. #if BUTTON_EXISTS(LFT)
  2525. else if (BUTTON_PRESSED(LFT)) {
  2526. encoderDiff = -(ENCODER_PULSES_PER_STEP);
  2527. next_button_update_ms = now + 300;
  2528. }
  2529. #endif
  2530. #if BUTTON_EXISTS(RT)
  2531. else if (BUTTON_PRESSED(RT)) {
  2532. encoderDiff = ENCODER_PULSES_PER_STEP;
  2533. next_button_update_ms = now + 300;
  2534. }
  2535. #endif
  2536. }
  2537. #endif
  2538. #if BUTTON_EXISTS(ENC)
  2539. if (ELAPSED(now, next_button_update_ms) && BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  2540. #endif
  2541. buttons = newbutton;
  2542. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2543. buttons |= slow_buttons;
  2544. #endif
  2545. #if ENABLED(REPRAPWORLD_KEYPAD)
  2546. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  2547. #endif
  2548. #else
  2549. GET_BUTTON_STATES(buttons);
  2550. #endif //!NEWPANEL
  2551. // Manage encoder rotation
  2552. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  2553. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  2554. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  2555. #elif ENABLED(REVERSE_MENU_DIRECTION)
  2556. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  2557. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  2558. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  2559. #define ENCODER_DIFF_CW (encoderDiff--)
  2560. #define ENCODER_DIFF_CCW (encoderDiff++)
  2561. #else
  2562. #define ENCODER_DIFF_CW (encoderDiff++)
  2563. #define ENCODER_DIFF_CCW (encoderDiff--)
  2564. #endif
  2565. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  2566. uint8_t enc = 0;
  2567. if (buttons & EN_A) enc |= B01;
  2568. if (buttons & EN_B) enc |= B10;
  2569. if (enc != lastEncoderBits) {
  2570. switch (enc) {
  2571. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  2572. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  2573. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  2574. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  2575. }
  2576. }
  2577. lastEncoderBits = enc;
  2578. }
  2579. bool lcd_detected(void) {
  2580. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  2581. return lcd.LcdDetected() == 1;
  2582. #else
  2583. return true;
  2584. #endif
  2585. }
  2586. bool lcd_clicked() { return LCD_CLICKED; }
  2587. #endif // ULTIPANEL
  2588. /*********************************/
  2589. /** Number to string conversion **/
  2590. /*********************************/
  2591. #define DIGIT(n) ('0' + (n))
  2592. #define DIGIMOD(n) DIGIT((n) % 10)
  2593. char conv[8];
  2594. // Convert float to rj string with 123 or -12 format
  2595. char *ftostr3(const float& x) { return itostr3((int)x); }
  2596. // Convert float to rj string with _123, -123, _-12, or __-1 format
  2597. char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
  2598. // Convert unsigned int to string with 12 format
  2599. char* itostr2(const uint8_t& x) {
  2600. int xx = x;
  2601. conv[0] = DIGIMOD(xx / 10);
  2602. conv[1] = DIGIMOD(xx);
  2603. conv[2] = '\0';
  2604. return conv;
  2605. }
  2606. // Convert float to string with +123.4 / -123.4 format
  2607. char* ftostr41sign(const float& x) {
  2608. int xx = int(abs(x * 10)) % 10000;
  2609. conv[0] = x >= 0 ? '+' : '-';
  2610. conv[1] = DIGIMOD(xx / 1000);
  2611. conv[2] = DIGIMOD(xx / 100);
  2612. conv[3] = DIGIMOD(xx / 10);
  2613. conv[4] = '.';
  2614. conv[5] = DIGIMOD(xx);
  2615. conv[6] = '\0';
  2616. return conv;
  2617. }
  2618. // Convert signed float to string with 023.45 / -23.45 format
  2619. char *ftostr32(const float& x) {
  2620. long xx = abs(x * 100);
  2621. conv[0] = x >= 0 ? DIGIMOD(xx / 10000) : '-';
  2622. conv[1] = DIGIMOD(xx / 1000);
  2623. conv[2] = DIGIMOD(xx / 100);
  2624. conv[3] = '.';
  2625. conv[4] = DIGIMOD(xx / 10);
  2626. conv[5] = DIGIMOD(xx);
  2627. conv[6] = '\0';
  2628. return conv;
  2629. }
  2630. // Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
  2631. char* ftostr43sign(const float& x, char plus/*=' '*/) {
  2632. long xx = x * 1000;
  2633. if (xx == 0)
  2634. conv[0] = ' ';
  2635. else if (xx > 0)
  2636. conv[0] = plus;
  2637. else {
  2638. xx = -xx;
  2639. conv[0] = '-';
  2640. }
  2641. conv[1] = DIGIMOD(xx / 1000);
  2642. conv[2] = '.';
  2643. conv[3] = DIGIMOD(xx / 100);
  2644. conv[4] = DIGIMOD(xx / 10);
  2645. conv[5] = DIGIMOD(xx);
  2646. conv[6] = '\0';
  2647. return conv;
  2648. }
  2649. // Convert unsigned float to string with 1.23 format
  2650. char* ftostr12ns(const float& x) {
  2651. long xx = x * 100;
  2652. xx = abs(xx);
  2653. conv[0] = DIGIMOD(xx / 100);
  2654. conv[1] = '.';
  2655. conv[2] = DIGIMOD(xx / 10);
  2656. conv[3] = DIGIMOD(xx);
  2657. conv[4] = '\0';
  2658. return conv;
  2659. }
  2660. // Convert signed int to lj string with +012 / -012 format
  2661. char* itostr3sign(const int& x) {
  2662. int xx;
  2663. if (x >= 0) {
  2664. conv[0] = '+';
  2665. xx = x;
  2666. }
  2667. else {
  2668. conv[0] = '-';
  2669. xx = -x;
  2670. }
  2671. conv[1] = DIGIMOD(xx / 100);
  2672. conv[2] = DIGIMOD(xx / 10);
  2673. conv[3] = DIGIMOD(xx);
  2674. conv[4] = '.';
  2675. conv[5] = '0';
  2676. conv[6] = '\0';
  2677. return conv;
  2678. }
  2679. // Convert signed int to rj string with 123 or -12 format
  2680. char* itostr3(const int& x) {
  2681. int xx = x;
  2682. if (xx < 0) {
  2683. conv[0] = '-';
  2684. xx = -xx;
  2685. }
  2686. else
  2687. conv[0] = xx >= 100 ? DIGIMOD(xx / 100) : ' ';
  2688. conv[1] = xx >= 10 ? DIGIMOD(xx / 10) : ' ';
  2689. conv[2] = DIGIMOD(xx);
  2690. conv[3] = '\0';
  2691. return conv;
  2692. }
  2693. // Convert unsigned int to lj string with 123 format
  2694. char* itostr3left(const int& xx) {
  2695. if (xx >= 100) {
  2696. conv[0] = DIGIMOD(xx / 100);
  2697. conv[1] = DIGIMOD(xx / 10);
  2698. conv[2] = DIGIMOD(xx);
  2699. conv[3] = '\0';
  2700. }
  2701. else if (xx >= 10) {
  2702. conv[0] = DIGIMOD(xx / 10);
  2703. conv[1] = DIGIMOD(xx);
  2704. conv[2] = '\0';
  2705. }
  2706. else {
  2707. conv[0] = DIGIMOD(xx);
  2708. conv[1] = '\0';
  2709. }
  2710. return conv;
  2711. }
  2712. // Convert signed int to rj string with _123, -123, _-12, or __-1 format
  2713. char *itostr4sign(const int& x) {
  2714. int xx = abs(x);
  2715. int sign = 0;
  2716. if (xx >= 100) {
  2717. conv[1] = DIGIMOD(xx / 100);
  2718. conv[2] = DIGIMOD(xx / 10);
  2719. }
  2720. else if (xx >= 10) {
  2721. conv[0] = ' ';
  2722. sign = 1;
  2723. conv[2] = DIGIMOD(xx / 10);
  2724. }
  2725. else {
  2726. conv[0] = ' ';
  2727. conv[1] = ' ';
  2728. sign = 2;
  2729. }
  2730. conv[sign] = x < 0 ? '-' : ' ';
  2731. conv[3] = DIGIMOD(xx);
  2732. conv[4] = '\0';
  2733. return conv;
  2734. }
  2735. // Convert unsigned float to rj string with 12345 format
  2736. char* ftostr5rj(const float& x) {
  2737. long xx = abs(x);
  2738. conv[0] = xx >= 10000 ? DIGIMOD(xx / 10000) : ' ';
  2739. conv[1] = xx >= 1000 ? DIGIMOD(xx / 1000) : ' ';
  2740. conv[2] = xx >= 100 ? DIGIMOD(xx / 100) : ' ';
  2741. conv[3] = xx >= 10 ? DIGIMOD(xx / 10) : ' ';
  2742. conv[4] = DIGIMOD(xx);
  2743. conv[5] = '\0';
  2744. return conv;
  2745. }
  2746. // Convert signed float to string with +1234.5 format
  2747. char* ftostr51sign(const float& x) {
  2748. long xx = abs(x * 10);
  2749. conv[0] = (x >= 0) ? '+' : '-';
  2750. conv[1] = DIGIMOD(xx / 10000);
  2751. conv[2] = DIGIMOD(xx / 1000);
  2752. conv[3] = DIGIMOD(xx / 100);
  2753. conv[4] = DIGIMOD(xx / 10);
  2754. conv[5] = '.';
  2755. conv[6] = DIGIMOD(xx);
  2756. conv[7] = '\0';
  2757. return conv;
  2758. }
  2759. // Convert signed float to string with +123.45 format
  2760. char* ftostr52sign(const float& x) {
  2761. long xx = abs(x * 100);
  2762. conv[0] = (x >= 0) ? '+' : '-';
  2763. conv[1] = DIGIMOD(xx / 10000);
  2764. conv[2] = DIGIMOD(xx / 1000);
  2765. conv[3] = DIGIMOD(xx / 100);
  2766. conv[4] = '.';
  2767. conv[5] = DIGIMOD(xx / 10);
  2768. conv[6] = DIGIMOD(xx);
  2769. conv[7] = '\0';
  2770. return conv;
  2771. }
  2772. // Convert signed float to space-padded string with -_23.4_ format
  2773. char* ftostr52sp(const float& x) {
  2774. long xx = x * 100;
  2775. uint8_t dig;
  2776. if (xx < 0) { // negative val = -_0
  2777. xx = -xx;
  2778. conv[0] = '-';
  2779. dig = (xx / 1000) % 10;
  2780. conv[1] = dig ? DIGIT(dig) : ' ';
  2781. }
  2782. else { // positive val = __0
  2783. dig = (xx / 10000) % 10;
  2784. if (dig) {
  2785. conv[0] = DIGIT(dig);
  2786. conv[1] = DIGIMOD(xx / 1000);
  2787. }
  2788. else {
  2789. conv[0] = ' ';
  2790. dig = (xx / 1000) % 10;
  2791. conv[1] = dig ? DIGIT(dig) : ' ';
  2792. }
  2793. }
  2794. conv[2] = DIGIMOD(xx / 100); // lsd always
  2795. dig = xx % 10;
  2796. if (dig) { // 2 decimal places
  2797. conv[5] = DIGIT(dig);
  2798. conv[4] = DIGIMOD(xx / 10);
  2799. conv[3] = '.';
  2800. }
  2801. else { // 1 or 0 decimal place
  2802. dig = (xx / 10) % 10;
  2803. if (dig) {
  2804. conv[4] = DIGIT(dig);
  2805. conv[3] = '.';
  2806. }
  2807. else {
  2808. conv[3] = conv[4] = ' ';
  2809. }
  2810. conv[5] = ' ';
  2811. }
  2812. conv[6] = '\0';
  2813. return conv;
  2814. }
  2815. #endif // ULTRA_LCD