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

ultralcd.cpp 141KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213
  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. #include "utility.h"
  31. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  32. #include "buzzer.h"
  33. #endif
  34. #if ENABLED(PRINTCOUNTER)
  35. #include "printcounter.h"
  36. #include "duration_t.h"
  37. #endif
  38. #if ENABLED(BLTOUCH)
  39. #include "endstops.h"
  40. #endif
  41. int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  42. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  43. millis_t previous_lcd_status_ms = 0;
  44. #endif
  45. #if ENABLED(BABYSTEPPING)
  46. long babysteps_done = 0;
  47. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  48. static void lcd_babystep_zoffset();
  49. #else
  50. static void lcd_babystep_z();
  51. #endif
  52. #endif
  53. uint8_t lcd_status_message_level;
  54. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  55. #if ENABLED(DOGLCD)
  56. #include "ultralcd_impl_DOGM.h"
  57. #include <U8glib.h>
  58. #else
  59. #include "ultralcd_impl_HD44780.h"
  60. #endif
  61. // The main status screen
  62. void lcd_status_screen();
  63. millis_t next_lcd_update_ms;
  64. 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)
  65. uint16_t max_display_update_time = 0;
  66. #if ENABLED(DOGLCD)
  67. bool drawing_screen = false;
  68. #endif
  69. #if ENABLED(DAC_STEPPER_CURRENT)
  70. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  71. int16_t driverPercent[XYZE];
  72. #endif
  73. #if ENABLED(ULTIPANEL)
  74. #ifndef TALL_FONT_CORRECTION
  75. #define TALL_FONT_CORRECTION 0
  76. #endif
  77. // Function pointer to menu functions.
  78. typedef void (*screenFunc_t)();
  79. #if HAS_POWER_SWITCH
  80. extern bool powersupply_on;
  81. #endif
  82. #if ENABLED(AUTO_BED_LEVELING_UBL)
  83. #include "ubl.h"
  84. #endif
  85. ////////////////////////////////////////////
  86. ///////////////// Menu Tree ////////////////
  87. ////////////////////////////////////////////
  88. void lcd_main_menu();
  89. void lcd_tune_menu();
  90. void lcd_prepare_menu();
  91. void lcd_move_menu();
  92. void lcd_control_menu();
  93. void lcd_control_temperature_menu();
  94. void lcd_control_temperature_preheat_material1_settings_menu();
  95. void lcd_control_temperature_preheat_material2_settings_menu();
  96. void lcd_control_motion_menu();
  97. void lcd_control_filament_menu();
  98. #if ENABLED(LCD_INFO_MENU)
  99. #if ENABLED(PRINTCOUNTER)
  100. void lcd_info_stats_menu();
  101. #endif
  102. void lcd_info_thermistors_menu();
  103. void lcd_info_board_menu();
  104. void lcd_info_menu();
  105. #endif // LCD_INFO_MENU
  106. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  107. void lcd_advanced_pause_toocold_menu();
  108. void lcd_advanced_pause_option_menu();
  109. void lcd_advanced_pause_init_message();
  110. void lcd_advanced_pause_unload_message();
  111. void lcd_advanced_pause_insert_message();
  112. void lcd_advanced_pause_load_message();
  113. void lcd_advanced_pause_heat_nozzle();
  114. void lcd_advanced_pause_extrude_message();
  115. void lcd_advanced_pause_resume_message();
  116. #endif
  117. #if ENABLED(DAC_STEPPER_CURRENT)
  118. void dac_driver_commit();
  119. void dac_driver_getValues();
  120. void lcd_dac_menu();
  121. void lcd_dac_write_eeprom();
  122. #endif
  123. #if ENABLED(FWRETRACT)
  124. void lcd_control_retract_menu();
  125. #endif
  126. #if ENABLED(DELTA_CALIBRATION_MENU)
  127. void lcd_delta_calibrate_menu();
  128. #endif
  129. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  130. #include "mesh_bed_leveling.h"
  131. extern void mesh_probing_done();
  132. #endif
  133. ////////////////////////////////////////////
  134. //////////// Menu System Actions ///////////
  135. ////////////////////////////////////////////
  136. #define menu_action_back(dummy) _menu_action_back()
  137. void _menu_action_back();
  138. void menu_action_submenu(screenFunc_t data);
  139. void menu_action_gcode(const char* pgcode);
  140. void menu_action_function(screenFunc_t data);
  141. #define DECLARE_MENU_EDIT_TYPE(_type, _name) \
  142. bool _menu_edit_ ## _name(); \
  143. void menu_edit_ ## _name(); \
  144. void menu_edit_callback_ ## _name(); \
  145. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
  146. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
  147. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
  148. typedef void _name##_void
  149. DECLARE_MENU_EDIT_TYPE(int, int3);
  150. DECLARE_MENU_EDIT_TYPE(float, float3);
  151. DECLARE_MENU_EDIT_TYPE(float, float32);
  152. DECLARE_MENU_EDIT_TYPE(float, float43);
  153. DECLARE_MENU_EDIT_TYPE(float, float5);
  154. DECLARE_MENU_EDIT_TYPE(float, float51);
  155. DECLARE_MENU_EDIT_TYPE(float, float52);
  156. DECLARE_MENU_EDIT_TYPE(float, float62);
  157. DECLARE_MENU_EDIT_TYPE(unsigned long, long5);
  158. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  159. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  160. #if ENABLED(SDSUPPORT)
  161. void lcd_sdcard_menu();
  162. void menu_action_sdfile(const char* filename, char* longFilename);
  163. void menu_action_sddirectory(const char* filename, char* longFilename);
  164. #endif
  165. ////////////////////////////////////////////
  166. //////////// Menu System Macros ////////////
  167. ////////////////////////////////////////////
  168. #ifndef ENCODER_FEEDRATE_DEADZONE
  169. #define ENCODER_FEEDRATE_DEADZONE 10
  170. #endif
  171. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  172. #define ENCODER_STEPS_PER_MENU_ITEM 5
  173. #endif
  174. #ifndef ENCODER_PULSES_PER_STEP
  175. #define ENCODER_PULSES_PER_STEP 1
  176. #endif
  177. /**
  178. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  179. *
  180. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  181. * menu_action_[type](arg3...)
  182. *
  183. * Examples:
  184. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  185. * or
  186. * MENU_BACK(MSG_WATCH)
  187. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  188. * menu_action_back()
  189. *
  190. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  191. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  192. * menu_action_function(lcd_sdcard_pause)
  193. *
  194. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  195. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  196. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  197. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  198. *
  199. */
  200. #define _MENU_ITEM_PART_1(TYPE, LABEL, ...) \
  201. if (_menuLineNr == _thisItemNr) { \
  202. if (lcdDrawUpdate) \
  203. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  204. if (lcd_clicked && encoderLine == _thisItemNr) {
  205. #define _MENU_ITEM_PART_2(TYPE, ...) \
  206. menu_action_ ## TYPE(__VA_ARGS__); \
  207. if (screen_changed) return; \
  208. } \
  209. } \
  210. ++_thisItemNr
  211. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  212. _skipStatic = false; \
  213. _MENU_ITEM_PART_1(TYPE, LABEL, ## __VA_ARGS__); \
  214. _MENU_ITEM_PART_2(TYPE, ## __VA_ARGS__); \
  215. } while(0)
  216. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  217. // Used to print static text with no visible cursor.
  218. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  219. #define STATIC_ITEM(LABEL, ...) \
  220. if (_menuLineNr == _thisItemNr) { \
  221. if (_skipStatic && encoderLine <= _thisItemNr) { \
  222. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  223. ++encoderLine; \
  224. } \
  225. if (lcdDrawUpdate) \
  226. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  227. } \
  228. ++_thisItemNr
  229. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  230. bool encoderRateMultiplierEnabled;
  231. #define ENCODER_RATE_MULTIPLY(F) (encoderRateMultiplierEnabled = F)
  232. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  233. /**
  234. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  235. */
  236. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  237. _MENU_ITEM_PART_1(type, label, ## __VA_ARGS__); \
  238. encoderRateMultiplierEnabled = true; \
  239. lastEncoderMovementMillis = 0; \
  240. _MENU_ITEM_PART_2(type, ## __VA_ARGS__); \
  241. } while(0)
  242. #else // !ENCODER_RATE_MULTIPLIER
  243. #define ENCODER_RATE_MULTIPLY(F) NOOP
  244. #endif // !ENCODER_RATE_MULTIPLIER
  245. #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
  246. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  247. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  248. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  249. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  250. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  251. #else // !ENCODER_RATE_MULTIPLIER
  252. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  253. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  254. #endif // !ENCODER_RATE_MULTIPLIER
  255. /**
  256. * START_SCREEN_OR_MENU generates init code for a screen or menu
  257. *
  258. * encoderLine is the position based on the encoder
  259. * encoderTopLine is the top menu line to display
  260. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  261. * _menuLineNr is the menu item to draw and process
  262. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  263. * _countedItems is the total number of items in the menu (after one call)
  264. */
  265. #define START_SCREEN_OR_MENU(LIMIT) \
  266. ENCODER_DIRECTION_MENUS(); \
  267. ENCODER_RATE_MULTIPLY(false); \
  268. if (encoderPosition > 0x8000) encoderPosition = 0; \
  269. static int8_t _countedItems = 0; \
  270. int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
  271. if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
  272. encoderLine = max(0, _countedItems - (LIMIT)); \
  273. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  274. }
  275. #define SCREEN_OR_MENU_LOOP() \
  276. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  277. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
  278. _thisItemNr = 0
  279. /**
  280. * START_SCREEN Opening code for a screen having only static items.
  281. * Do simplified scrolling of the entire screen.
  282. *
  283. * START_MENU Opening code for a screen with menu items.
  284. * Scroll as-needed to keep the selected line in view.
  285. */
  286. #define START_SCREEN() \
  287. START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
  288. encoderTopLine = encoderLine; \
  289. bool _skipStatic = false; \
  290. SCREEN_OR_MENU_LOOP()
  291. #define START_MENU() \
  292. START_SCREEN_OR_MENU(1); \
  293. screen_changed = false; \
  294. NOMORE(encoderTopLine, encoderLine); \
  295. if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
  296. encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
  297. } \
  298. bool _skipStatic = true; \
  299. SCREEN_OR_MENU_LOOP()
  300. #define END_SCREEN() \
  301. } \
  302. _countedItems = _thisItemNr
  303. #define END_MENU() \
  304. } \
  305. _countedItems = _thisItemNr; \
  306. UNUSED(_skipStatic)
  307. ////////////////////////////////////////////
  308. ///////////// Global Variables /////////////
  309. ////////////////////////////////////////////
  310. /**
  311. * REVERSE_MENU_DIRECTION
  312. *
  313. * To reverse the menu direction we need a general way to reverse
  314. * the direction of the encoder everywhere. So encoderDirection is
  315. * added to allow the encoder to go the other way.
  316. *
  317. * This behavior is limited to scrolling Menus and SD card listings,
  318. * and is disabled in other contexts.
  319. */
  320. #if ENABLED(REVERSE_MENU_DIRECTION)
  321. int8_t encoderDirection = 1;
  322. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  323. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  324. #else
  325. #define ENCODER_DIRECTION_NORMAL() ;
  326. #define ENCODER_DIRECTION_MENUS() ;
  327. #endif
  328. // Encoder Movement
  329. volatile int8_t encoderDiff; // Updated in lcd_buttons_update, added to encoderPosition every LCD update
  330. uint32_t encoderPosition;
  331. millis_t lastEncoderMovementMillis = 0;
  332. // Button States
  333. bool lcd_clicked, wait_for_unclick;
  334. volatile uint8_t buttons;
  335. millis_t next_button_update_ms;
  336. #if ENABLED(REPRAPWORLD_KEYPAD)
  337. volatile uint8_t buttons_reprapworld_keypad;
  338. #endif
  339. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  340. volatile uint8_t slow_buttons;
  341. #endif
  342. // Menu System Navigation
  343. screenFunc_t currentScreen = lcd_status_screen;
  344. int8_t encoderTopLine;
  345. typedef struct {
  346. screenFunc_t menu_function;
  347. uint32_t encoder_position;
  348. } menuPosition;
  349. menuPosition screen_history[6];
  350. uint8_t screen_history_depth = 0;
  351. bool screen_changed, defer_return_to_status;
  352. // Value Editing
  353. const char *editLabel;
  354. void *editValue;
  355. int32_t minEditValue, maxEditValue;
  356. screenFunc_t callbackFunc;
  357. bool liveEdit;
  358. // Manual Moves
  359. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  360. millis_t manual_move_start_time = 0;
  361. int8_t manual_move_axis = (int8_t)NO_AXIS;
  362. #if EXTRUDERS > 1
  363. int8_t manual_move_e_index = 0;
  364. #else
  365. #define manual_move_e_index 0
  366. #endif
  367. #if PIN_EXISTS(SD_DETECT)
  368. uint8_t lcd_sd_status;
  369. #endif
  370. #if ENABLED(PIDTEMP)
  371. float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
  372. #endif
  373. /**
  374. * General function to go directly to a screen
  375. */
  376. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0) {
  377. if (currentScreen != screen) {
  378. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  379. static millis_t doubleclick_expire_ms = 0;
  380. // Going to lcd_main_menu from status screen? Remember first click time.
  381. // Going back to status screen within a very short time? Go to Z babystepping.
  382. if (screen == lcd_main_menu) {
  383. if (currentScreen == lcd_status_screen)
  384. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  385. }
  386. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
  387. screen =
  388. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  389. lcd_babystep_zoffset
  390. #else
  391. lcd_babystep_z
  392. #endif
  393. ;
  394. #endif
  395. currentScreen = screen;
  396. encoderPosition = encoder;
  397. if (screen == lcd_status_screen) {
  398. defer_return_to_status = false;
  399. screen_history_depth = 0;
  400. }
  401. lcd_implementation_clear();
  402. #if ENABLED(LCD_PROGRESS_BAR)
  403. // For LCD_PROGRESS_BAR re-initialize custom characters
  404. lcd_set_custom_characters(screen == lcd_status_screen);
  405. #endif
  406. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  407. screen_changed = true;
  408. #if ENABLED(DOGLCD)
  409. drawing_screen = false;
  410. #endif
  411. }
  412. }
  413. /**
  414. * Show "Moving..." till moves are done, then revert to previous display.
  415. */
  416. inline void lcd_synchronize() {
  417. static bool no_reentry = false;
  418. lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_MOVING));
  419. if (no_reentry) return;
  420. // Make this the current handler till all moves are done
  421. no_reentry = true;
  422. screenFunc_t old_screen = currentScreen;
  423. lcd_goto_screen(lcd_synchronize);
  424. stepper.synchronize();
  425. no_reentry = false;
  426. lcd_goto_screen(old_screen);
  427. }
  428. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  429. void lcd_save_previous_screen() {
  430. if (screen_history_depth < COUNT(screen_history)) {
  431. screen_history[screen_history_depth].menu_function = currentScreen;
  432. screen_history[screen_history_depth].encoder_position = encoderPosition;
  433. ++screen_history_depth;
  434. }
  435. }
  436. void lcd_goto_previous_menu() {
  437. if (screen_history_depth > 0) {
  438. --screen_history_depth;
  439. lcd_goto_screen(
  440. screen_history[screen_history_depth].menu_function,
  441. screen_history[screen_history_depth].encoder_position
  442. );
  443. }
  444. else
  445. lcd_return_to_status();
  446. }
  447. #endif // ULTIPANEL
  448. /**
  449. *
  450. * "Info Screen"
  451. *
  452. * This is very display-dependent, so the lcd implementation draws this.
  453. */
  454. void lcd_status_screen() {
  455. #if ENABLED(ULTIPANEL)
  456. ENCODER_DIRECTION_NORMAL();
  457. ENCODER_RATE_MULTIPLY(false);
  458. #endif
  459. #if ENABLED(LCD_PROGRESS_BAR)
  460. millis_t ms = millis();
  461. #if DISABLED(PROGRESS_MSG_ONCE)
  462. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  463. progress_bar_ms = ms;
  464. }
  465. #endif
  466. #if PROGRESS_MSG_EXPIRE > 0
  467. // Handle message expire
  468. if (expire_status_ms > 0) {
  469. #if ENABLED(SDSUPPORT)
  470. if (card.isFileOpen()) {
  471. // Expire the message when printing is active
  472. if (IS_SD_PRINTING) {
  473. if (ELAPSED(ms, expire_status_ms)) {
  474. lcd_status_message[0] = '\0';
  475. expire_status_ms = 0;
  476. }
  477. }
  478. else {
  479. expire_status_ms += LCD_UPDATE_INTERVAL;
  480. }
  481. }
  482. else {
  483. expire_status_ms = 0;
  484. }
  485. #else
  486. expire_status_ms = 0;
  487. #endif // SDSUPPORT
  488. }
  489. #endif
  490. #endif // LCD_PROGRESS_BAR
  491. lcd_implementation_status_screen();
  492. #if ENABLED(ULTIPANEL)
  493. if (lcd_clicked) {
  494. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  495. previous_lcd_status_ms = millis(); // get status message to show up for a while
  496. #endif
  497. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  498. #if ENABLED(LCD_PROGRESS_BAR)
  499. false
  500. #endif
  501. );
  502. lcd_goto_screen(lcd_main_menu);
  503. }
  504. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  505. const int new_frm = feedrate_percentage + (int32_t)encoderPosition;
  506. // Dead zone at 100% feedrate
  507. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  508. feedrate_percentage = 100;
  509. encoderPosition = 0;
  510. }
  511. else if (feedrate_percentage == 100) {
  512. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  513. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  514. encoderPosition = 0;
  515. }
  516. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  517. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  518. encoderPosition = 0;
  519. }
  520. }
  521. else {
  522. feedrate_percentage = new_frm;
  523. encoderPosition = 0;
  524. }
  525. #endif // ULTIPANEL_FEEDMULTIPLY
  526. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  527. #endif // ULTIPANEL
  528. }
  529. /**
  530. *
  531. * draw the kill screen
  532. *
  533. */
  534. void kill_screen(const char* lcd_msg) {
  535. lcd_init();
  536. lcd_setalertstatuspgm(lcd_msg);
  537. #if ENABLED(DOGLCD)
  538. u8g.firstPage();
  539. do {
  540. lcd_kill_screen();
  541. } while (u8g.nextPage());
  542. #else
  543. lcd_kill_screen();
  544. #endif
  545. }
  546. #if ENABLED(ULTIPANEL)
  547. /**
  548. *
  549. * Audio feedback for controller clicks
  550. *
  551. */
  552. void lcd_buzz(long duration, uint16_t freq) {
  553. #if ENABLED(LCD_USE_I2C_BUZZER)
  554. lcd.buzz(duration, freq);
  555. #elif PIN_EXISTS(BEEPER)
  556. buzzer.tone(duration, freq);
  557. #else
  558. UNUSED(duration); UNUSED(freq);
  559. #endif
  560. }
  561. void lcd_quick_feedback() {
  562. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  563. buttons = 0;
  564. next_button_update_ms = millis() + 500;
  565. // Buzz and wait. The delay is needed for buttons to settle!
  566. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  567. #if ENABLED(LCD_USE_I2C_BUZZER)
  568. delay(10);
  569. #elif PIN_EXISTS(BEEPER)
  570. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  571. #endif
  572. }
  573. void lcd_completion_feedback(const bool good/*=true*/) {
  574. if (good) {
  575. lcd_buzz(100, 659);
  576. lcd_buzz(100, 698);
  577. }
  578. else lcd_buzz(20, 440);
  579. }
  580. inline void line_to_current(AxisEnum axis) {
  581. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
  582. }
  583. #if ENABLED(SDSUPPORT)
  584. void lcd_sdcard_pause() {
  585. card.pauseSDPrint();
  586. print_job_timer.pause();
  587. #if ENABLED(PARK_HEAD_ON_PAUSE)
  588. enqueue_and_echo_commands_P(PSTR("M125"));
  589. #endif
  590. lcd_setstatuspgm(PSTR(MSG_PRINT_PAUSED), true);
  591. }
  592. void lcd_sdcard_resume() {
  593. #if ENABLED(PARK_HEAD_ON_PAUSE)
  594. enqueue_and_echo_commands_P(PSTR("M24"));
  595. #else
  596. card.startFileprint();
  597. print_job_timer.start();
  598. #endif
  599. lcd_setstatuspgm(PSTR(""), true);
  600. }
  601. void lcd_sdcard_stop() {
  602. card.stopSDPrint();
  603. clear_command_queue();
  604. quickstop_stepper();
  605. print_job_timer.stop();
  606. thermalManager.disable_all_heaters();
  607. #if FAN_COUNT > 0
  608. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  609. #endif
  610. wait_for_heatup = false;
  611. LCD_MESSAGEPGM(MSG_PRINT_ABORTED);
  612. }
  613. #endif // SDSUPPORT
  614. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  615. extern bool case_light_on;
  616. extern void update_case_light();
  617. void toggle_case_light() {
  618. case_light_on ^= true;
  619. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  620. update_case_light();
  621. }
  622. #endif // MENU_ITEM_CASE_LIGHT
  623. #if ENABLED(BLTOUCH)
  624. /**
  625. *
  626. * "BLTouch" submenu
  627. *
  628. */
  629. static void bltouch_menu() {
  630. START_MENU();
  631. //
  632. // ^ Main
  633. //
  634. MENU_BACK(MSG_MAIN);
  635. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  636. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  637. MENU_ITEM(gcode, MSG_BLTOUCH_DEPLOY, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_DEPLOY)));
  638. MENU_ITEM(gcode, MSG_BLTOUCH_STOW, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_STOW)));
  639. END_MENU();
  640. }
  641. #endif // BLTOUCH
  642. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  643. static void progress_bar_test() {
  644. static int8_t bar_percent = 0;
  645. if (lcd_clicked) {
  646. lcd_goto_previous_menu();
  647. lcd_set_custom_characters(false);
  648. return;
  649. }
  650. bar_percent += (int8_t)encoderPosition;
  651. bar_percent = constrain(bar_percent, 0, 100);
  652. encoderPosition = 0;
  653. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  654. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  655. lcd.print(itostr3(bar_percent)); lcd.print('%');
  656. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  657. }
  658. void _progress_bar_test() {
  659. lcd_goto_screen(progress_bar_test);
  660. lcd_set_custom_characters();
  661. }
  662. #endif // LCD_PROGRESS_BAR_TEST
  663. #if HAS_DEBUG_MENU
  664. void lcd_debug_menu() {
  665. START_MENU();
  666. MENU_BACK(MSG_MAIN); // ^ Main
  667. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  668. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  669. #endif
  670. END_MENU();
  671. }
  672. #endif // HAS_DEBUG_MENU
  673. /**
  674. *
  675. * "Main" menu
  676. *
  677. */
  678. void lcd_main_menu() {
  679. START_MENU();
  680. MENU_BACK(MSG_WATCH);
  681. //
  682. // Debug Menu when certain options are enabled
  683. //
  684. #if HAS_DEBUG_MENU
  685. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  686. #endif
  687. //
  688. // Switch case light on/off
  689. //
  690. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  691. if (case_light_on)
  692. MENU_ITEM(function, MSG_LIGHTS_OFF, toggle_case_light);
  693. else
  694. MENU_ITEM(function, MSG_LIGHTS_ON, toggle_case_light);
  695. #endif
  696. if (planner.movesplanned() || IS_SD_PRINTING) {
  697. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  698. }
  699. else {
  700. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  701. #if ENABLED(DELTA_CALIBRATION_MENU)
  702. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  703. #endif
  704. }
  705. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  706. #if ENABLED(SDSUPPORT)
  707. if (card.cardOK) {
  708. if (card.isFileOpen()) {
  709. if (card.sdprinting)
  710. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  711. else
  712. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  713. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  714. }
  715. else {
  716. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  717. #if !PIN_EXISTS(SD_DETECT)
  718. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  719. #endif
  720. }
  721. }
  722. else {
  723. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  724. #if !PIN_EXISTS(SD_DETECT)
  725. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  726. #endif
  727. }
  728. #endif // SDSUPPORT
  729. #if ENABLED(LCD_INFO_MENU)
  730. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  731. #endif
  732. END_MENU();
  733. }
  734. /**
  735. *
  736. * "Tune" submenu items
  737. *
  738. */
  739. #if HAS_M206_COMMAND
  740. /**
  741. * Set the home offset based on the current_position
  742. */
  743. void lcd_set_home_offsets() {
  744. // M428 Command
  745. enqueue_and_echo_commands_P(PSTR("M428"));
  746. lcd_return_to_status();
  747. }
  748. #endif
  749. #if ENABLED(BABYSTEPPING)
  750. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  751. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  752. ENCODER_DIRECTION_NORMAL();
  753. if (encoderPosition) {
  754. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  755. encoderPosition = 0;
  756. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  757. thermalManager.babystep_axis(axis, babystep_increment);
  758. babysteps_done += babystep_increment;
  759. }
  760. if (lcdDrawUpdate)
  761. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  762. }
  763. #if ENABLED(BABYSTEP_XY)
  764. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  765. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  766. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  767. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  768. #endif
  769. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  770. void lcd_babystep_zoffset() {
  771. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  772. defer_return_to_status = true;
  773. ENCODER_DIRECTION_NORMAL();
  774. if (encoderPosition) {
  775. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  776. encoderPosition = 0;
  777. const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
  778. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  779. if (planner.abl_enabled)
  780. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  781. zprobe_zoffset = new_zoffset;
  782. refresh_zprobe_zoffset(true);
  783. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  784. }
  785. }
  786. if (lcdDrawUpdate)
  787. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  788. }
  789. #else // !BABYSTEP_ZPROBE_OFFSET
  790. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  791. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  792. #endif // !BABYSTEP_ZPROBE_OFFSET
  793. #endif // BABYSTEPPING
  794. #if ENABLED(AUTO_BED_LEVELING_UBL)
  795. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  796. // seperate value that doesn't lose precision.
  797. static int ubl_encoderPosition = 0;
  798. static void _lcd_mesh_fine_tune(const char* msg) {
  799. defer_return_to_status = true;
  800. if (ubl.encoder_diff) {
  801. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  802. ubl.encoder_diff = 0;
  803. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  804. mesh_edit_value = mesh_edit_accumulator;
  805. encoderPosition = 0;
  806. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  807. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  808. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  809. }
  810. if (lcdDrawUpdate)
  811. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  812. }
  813. void _lcd_mesh_edit_NOP() {
  814. defer_return_to_status = true;
  815. }
  816. float lcd_mesh_edit() {
  817. lcd_goto_screen(_lcd_mesh_edit_NOP);
  818. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  819. return mesh_edit_value;
  820. }
  821. void lcd_mesh_edit_setup(float initial) {
  822. mesh_edit_value = mesh_edit_accumulator = initial;
  823. lcd_goto_screen(_lcd_mesh_edit_NOP);
  824. }
  825. void _lcd_z_offset_edit() {
  826. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  827. }
  828. float lcd_z_offset_edit() {
  829. lcd_goto_screen(_lcd_z_offset_edit);
  830. return mesh_edit_value;
  831. }
  832. void lcd_z_offset_edit_setup(float initial) {
  833. mesh_edit_value = mesh_edit_accumulator = initial;
  834. lcd_goto_screen(_lcd_z_offset_edit);
  835. }
  836. #endif // AUTO_BED_LEVELING_UBL
  837. /**
  838. * Watch temperature callbacks
  839. */
  840. #if HAS_TEMP_HOTEND
  841. #if WATCH_HOTENDS
  842. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  843. #else
  844. #define _WATCH_FUNC(N) NOOP
  845. #endif
  846. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  847. #if HOTENDS > 1
  848. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  849. #if HOTENDS > 2
  850. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  851. #if HOTENDS > 3
  852. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  853. #if HOTENDS > 4
  854. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  855. #endif // HOTENDS > 4
  856. #endif // HOTENDS > 3
  857. #endif // HOTENDS > 2
  858. #endif // HOTENDS > 1
  859. #endif // HAS_TEMP_HOTEND
  860. #if WATCH_THE_BED
  861. void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
  862. #endif
  863. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  864. void lcd_enqueue_filament_change() {
  865. if (!DEBUGGING(DRYRUN) && thermalManager.tooColdToExtrude(active_extruder)) {
  866. lcd_save_previous_screen();
  867. lcd_goto_screen(lcd_advanced_pause_toocold_menu);
  868. return;
  869. }
  870. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  871. enqueue_and_echo_commands_P(PSTR("M600 B0"));
  872. }
  873. #endif
  874. /**
  875. *
  876. * "Tune" submenu
  877. *
  878. */
  879. void lcd_tune_menu() {
  880. START_MENU();
  881. //
  882. // ^ Main
  883. //
  884. MENU_BACK(MSG_MAIN);
  885. //
  886. // Speed:
  887. //
  888. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  889. // Manual bed leveling, Bed Z:
  890. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  891. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  892. #endif
  893. //
  894. // Nozzle:
  895. // Nozzle [1-4]:
  896. //
  897. #if HOTENDS == 1
  898. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  899. #else // HOTENDS > 1
  900. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  901. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  902. #if HOTENDS > 2
  903. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  904. #if HOTENDS > 3
  905. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  906. #if HOTENDS > 4
  907. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  908. #endif // HOTENDS > 4
  909. #endif // HOTENDS > 3
  910. #endif // HOTENDS > 2
  911. #endif // HOTENDS > 1
  912. //
  913. // Bed:
  914. //
  915. #if WATCH_THE_BED
  916. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  917. #endif
  918. //
  919. // Fan Speed:
  920. //
  921. #if FAN_COUNT > 0
  922. #if HAS_FAN0
  923. #if FAN_COUNT > 1
  924. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  925. #else
  926. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  927. #endif
  928. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  929. #endif
  930. #if HAS_FAN1
  931. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  932. #endif
  933. #if HAS_FAN2
  934. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  935. #endif
  936. #endif // FAN_COUNT > 0
  937. //
  938. // Flow:
  939. // Flow [1-5]:
  940. //
  941. #if EXTRUDERS == 1
  942. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  943. #else // EXTRUDERS > 1
  944. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  945. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  946. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  947. #if EXTRUDERS > 2
  948. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  949. #if EXTRUDERS > 3
  950. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  951. #if EXTRUDERS > 4
  952. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  953. #endif // EXTRUDERS > 4
  954. #endif // EXTRUDERS > 3
  955. #endif // EXTRUDERS > 2
  956. #endif // EXTRUDERS > 1
  957. //
  958. // Babystep X:
  959. // Babystep Y:
  960. // Babystep Z:
  961. //
  962. #if ENABLED(BABYSTEPPING)
  963. #if ENABLED(BABYSTEP_XY)
  964. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  965. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  966. #endif
  967. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  968. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  969. #else
  970. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  971. #endif
  972. #endif
  973. //
  974. // Change filament
  975. //
  976. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  977. if (!thermalManager.tooColdToExtrude(active_extruder))
  978. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  979. #endif
  980. END_MENU();
  981. }
  982. /**
  983. *
  984. * "Driver current control" submenu items
  985. *
  986. */
  987. #if ENABLED(DAC_STEPPER_CURRENT)
  988. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  989. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  990. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  991. void lcd_dac_menu() {
  992. dac_driver_getValues();
  993. START_MENU();
  994. MENU_BACK(MSG_CONTROL);
  995. MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  996. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  997. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  998. MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  999. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  1000. END_MENU();
  1001. }
  1002. #endif
  1003. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  1004. /**
  1005. *
  1006. * "Prepare" submenu items
  1007. *
  1008. */
  1009. void _lcd_preheat(const int endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
  1010. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  1011. #if TEMP_SENSOR_BED != 0
  1012. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  1013. #else
  1014. UNUSED(tempb);
  1015. #endif
  1016. #if FAN_COUNT > 0
  1017. #if FAN_COUNT > 1
  1018. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  1019. #else
  1020. fanSpeeds[0] = fan;
  1021. #endif
  1022. #else
  1023. UNUSED(fan);
  1024. #endif
  1025. lcd_return_to_status();
  1026. }
  1027. #if TEMP_SENSOR_0 != 0
  1028. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1029. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1030. #if TEMP_SENSOR_BED != 0
  1031. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1032. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1033. #endif
  1034. #endif
  1035. #if HOTENDS > 1
  1036. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1037. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1038. #if TEMP_SENSOR_BED != 0
  1039. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1040. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1041. #endif
  1042. #if HOTENDS > 2
  1043. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1044. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1045. #if TEMP_SENSOR_BED != 0
  1046. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1047. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1048. #endif
  1049. #if HOTENDS > 3
  1050. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1051. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1052. #if TEMP_SENSOR_BED != 0
  1053. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1054. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1055. #endif
  1056. #if HOTENDS > 4
  1057. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1058. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1059. #if TEMP_SENSOR_BED != 0
  1060. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1061. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1062. #endif
  1063. #endif // HOTENDS > 4
  1064. #endif // HOTENDS > 3
  1065. #endif // HOTENDS > 2
  1066. void lcd_preheat_m1_all() {
  1067. #if HOTENDS > 1
  1068. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1069. #if HOTENDS > 2
  1070. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1071. #if HOTENDS > 3
  1072. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1073. #if HOTENDS > 4
  1074. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1075. #endif // HOTENDS > 4
  1076. #endif // HOTENDS > 3
  1077. #endif // HOTENDS > 2
  1078. #endif // HOTENDS > 1
  1079. #if TEMP_SENSOR_BED != 0
  1080. lcd_preheat_m1_e0();
  1081. #else
  1082. lcd_preheat_m1_e0_only();
  1083. #endif
  1084. }
  1085. void lcd_preheat_m2_all() {
  1086. #if HOTENDS > 1
  1087. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1088. #if HOTENDS > 2
  1089. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1090. #if HOTENDS > 3
  1091. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1092. #if HOTENDS > 4
  1093. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1094. #endif // HOTENDS > 4
  1095. #endif // HOTENDS > 3
  1096. #endif // HOTENDS > 2
  1097. #endif // HOTENDS > 1
  1098. #if TEMP_SENSOR_BED != 0
  1099. lcd_preheat_m2_e0();
  1100. #else
  1101. lcd_preheat_m2_e0_only();
  1102. #endif
  1103. }
  1104. #endif // HOTENDS > 1
  1105. #if TEMP_SENSOR_BED != 0
  1106. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1107. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1108. #endif
  1109. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0)
  1110. void lcd_preheat_m1_menu() {
  1111. START_MENU();
  1112. MENU_BACK(MSG_PREPARE);
  1113. #if HOTENDS == 1
  1114. #if TEMP_SENSOR_BED != 0
  1115. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1116. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1117. #else
  1118. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1119. #endif
  1120. #else
  1121. #if TEMP_SENSOR_BED != 0
  1122. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1123. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1124. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1125. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1126. #else
  1127. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1128. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1129. #endif
  1130. #if HOTENDS > 2
  1131. #if TEMP_SENSOR_BED != 0
  1132. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1133. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1134. #else
  1135. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1136. #endif
  1137. #if HOTENDS > 3
  1138. #if TEMP_SENSOR_BED != 0
  1139. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1140. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1141. #else
  1142. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1143. #endif
  1144. #if HOTENDS > 4
  1145. #if TEMP_SENSOR_BED != 0
  1146. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1147. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1148. #else
  1149. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1150. #endif
  1151. #endif // HOTENDS > 4
  1152. #endif // HOTENDS > 3
  1153. #endif // HOTENDS > 2
  1154. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1155. #endif // HOTENDS > 1
  1156. #if TEMP_SENSOR_BED != 0
  1157. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1158. #endif
  1159. END_MENU();
  1160. }
  1161. void lcd_preheat_m2_menu() {
  1162. START_MENU();
  1163. MENU_BACK(MSG_PREPARE);
  1164. #if HOTENDS == 1
  1165. #if TEMP_SENSOR_BED != 0
  1166. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1167. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1168. #else
  1169. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1170. #endif
  1171. #else
  1172. #if TEMP_SENSOR_BED != 0
  1173. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1174. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1175. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1176. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1177. #else
  1178. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1179. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1180. #endif
  1181. #if HOTENDS > 2
  1182. #if TEMP_SENSOR_BED != 0
  1183. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1184. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1185. #else
  1186. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1187. #endif
  1188. #if HOTENDS > 3
  1189. #if TEMP_SENSOR_BED != 0
  1190. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1191. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1192. #else
  1193. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1194. #endif
  1195. #if HOTENDS > 4
  1196. #if TEMP_SENSOR_BED != 0
  1197. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1198. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1199. #else
  1200. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1201. #endif
  1202. #endif // HOTENDS > 4
  1203. #endif // HOTENDS > 3
  1204. #endif // HOTENDS > 2
  1205. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1206. #endif // HOTENDS > 1
  1207. #if TEMP_SENSOR_BED != 0
  1208. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1209. #endif
  1210. END_MENU();
  1211. }
  1212. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED)
  1213. void lcd_cooldown() {
  1214. #if FAN_COUNT > 0
  1215. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1216. #endif
  1217. thermalManager.disable_all_heaters();
  1218. lcd_return_to_status();
  1219. }
  1220. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1221. void lcd_autostart_sd() {
  1222. card.autostart_index = 0;
  1223. card.setroot();
  1224. card.checkautostart(true);
  1225. }
  1226. #endif
  1227. #if ENABLED(LCD_BED_LEVELING)
  1228. /**
  1229. *
  1230. * "Prepare" > "Level Bed" handlers
  1231. *
  1232. */
  1233. static uint8_t manual_probe_index;
  1234. // LCD probed points are from defaults
  1235. constexpr uint8_t total_probe_points = (
  1236. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  1237. 3
  1238. #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
  1239. GRID_MAX_POINTS
  1240. #endif
  1241. );
  1242. #if ENABLED(MESH_BED_LEVELING)
  1243. // Utility to go to the next mesh point
  1244. inline void _manual_probe_goto_xy(float x, float y) {
  1245. #if MANUAL_PROBE_HEIGHT > 0
  1246. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1247. line_to_current(Z_AXIS);
  1248. #endif
  1249. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1250. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1251. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1252. #if MANUAL_PROBE_HEIGHT > 0
  1253. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + 0.2;
  1254. line_to_current(Z_AXIS);
  1255. #endif
  1256. lcd_synchronize();
  1257. }
  1258. #endif // MESH_BED_LEVELING
  1259. void _lcd_level_bed_done() {
  1260. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1261. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1262. }
  1263. void _lcd_level_goto_next_point();
  1264. /**
  1265. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1266. */
  1267. void _lcd_level_bed_get_z() {
  1268. ENCODER_DIRECTION_NORMAL();
  1269. if (lcd_clicked) {
  1270. // Use a hook to set the probe point z
  1271. #if ENABLED(MESH_BED_LEVELING)
  1272. // MBL records the position but doesn't move to the next one
  1273. mbl.set_zigzag_z(manual_probe_index, current_position[Z_AXIS]);
  1274. #elif ENABLED(PROBE_MANUALLY)
  1275. // The last G29 will record but not move
  1276. if (manual_probe_index == total_probe_points - 1)
  1277. enqueue_and_echo_commands_P("G29 V1");
  1278. #endif
  1279. // If done...
  1280. if (++manual_probe_index >= total_probe_points) {
  1281. // Say "Done!"
  1282. lcd_goto_screen(_lcd_level_bed_done);
  1283. // Raise Z to the "manual probe height"
  1284. #if MANUAL_PROBE_HEIGHT > 0
  1285. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1286. line_to_current(Z_AXIS);
  1287. lcd_synchronize();
  1288. #endif
  1289. // Enable leveling, if needed
  1290. #if ENABLED(MESH_BED_LEVELING)
  1291. lcd_synchronize();
  1292. mbl.set_has_mesh(true);
  1293. mesh_probing_done();
  1294. #elif ENABLED(PROBE_MANUALLY)
  1295. // ABL will be enabled due to "G29".
  1296. #endif
  1297. lcd_return_to_status();
  1298. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1299. lcd_completion_feedback();
  1300. }
  1301. else
  1302. _lcd_level_goto_next_point();
  1303. return;
  1304. }
  1305. // Encoder knob or keypad buttons adjust the Z position
  1306. if (encoderPosition) {
  1307. refresh_cmd_timeout();
  1308. current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1309. NOLESS(current_position[Z_AXIS], -(LCD_PROBE_Z_RANGE) * 0.5);
  1310. NOMORE(current_position[Z_AXIS], (LCD_PROBE_Z_RANGE) * 0.5);
  1311. line_to_current(Z_AXIS);
  1312. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1313. encoderPosition = 0;
  1314. }
  1315. // Update on first display, then only on updates to Z position
  1316. // Show message above on clicks instead
  1317. if (lcdDrawUpdate) {
  1318. const float v = current_position[Z_AXIS];
  1319. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1320. }
  1321. }
  1322. /**
  1323. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1324. */
  1325. #if ENABLED(PROBE_MANUALLY)
  1326. bool lcd_wait_for_move;
  1327. #endif
  1328. void _lcd_level_bed_moving() {
  1329. if (lcdDrawUpdate) {
  1330. char msg[10];
  1331. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1332. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1333. }
  1334. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1335. #if ENABLED(PROBE_MANUALLY)
  1336. if (!lcd_wait_for_move) lcd_goto_screen(_lcd_level_bed_get_z);
  1337. #endif
  1338. }
  1339. /**
  1340. * Step 5: Initiate a move to the next point
  1341. */
  1342. void _lcd_level_goto_next_point() {
  1343. // Set the menu to display ahead of blocking call
  1344. lcd_goto_screen(_lcd_level_bed_moving);
  1345. #if ENABLED(MESH_BED_LEVELING)
  1346. int8_t px, py;
  1347. mbl.zigzag(manual_probe_index, px, py);
  1348. // Controls the loop until the move is done
  1349. _manual_probe_goto_xy(
  1350. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1351. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1352. );
  1353. // After the blocking function returns, change menus
  1354. lcd_goto_screen(_lcd_level_bed_get_z);
  1355. #elif ENABLED(PROBE_MANUALLY)
  1356. // G29 will signal when it's done
  1357. lcd_wait_for_move = true;
  1358. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1359. #endif
  1360. }
  1361. /**
  1362. * Step 4: Display "Click to Begin", wait for click
  1363. * Move to the first probe position
  1364. */
  1365. void _lcd_level_bed_homing_done() {
  1366. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1367. if (lcd_clicked) {
  1368. manual_probe_index = 0;
  1369. _lcd_level_goto_next_point();
  1370. }
  1371. }
  1372. /**
  1373. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1374. */
  1375. void _lcd_level_bed_homing() {
  1376. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1377. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1378. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1379. lcd_goto_screen(_lcd_level_bed_homing_done);
  1380. }
  1381. #if ENABLED(PROBE_MANUALLY)
  1382. extern bool g29_in_progress;
  1383. #endif
  1384. /**
  1385. * Step 2: Continue Bed Leveling...
  1386. */
  1387. void _lcd_level_bed_continue() {
  1388. defer_return_to_status = true;
  1389. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1390. lcd_goto_screen(_lcd_level_bed_homing);
  1391. enqueue_and_echo_commands_P(PSTR("G28"));
  1392. }
  1393. /**
  1394. * Step 1: Bed Level entry-point: "Cancel" or "Level Bed"
  1395. */
  1396. void lcd_level_bed() {
  1397. START_MENU();
  1398. MENU_BACK(MSG_LEVEL_BED_CANCEL);
  1399. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1400. END_MENU();
  1401. }
  1402. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1403. void _lcd_ubl_level_bed();
  1404. static int ubl_storage_slot = 0,
  1405. custom_bed_temp = 50,
  1406. custom_hotend_temp = 190,
  1407. side_points = 3,
  1408. ubl_fillin_amount = 5,
  1409. ubl_height_amount,
  1410. map_type;
  1411. /**
  1412. * UBL Build Custom Mesh Command
  1413. */
  1414. void _lcd_ubl_build_custom_mesh() {
  1415. char UBL_LCD_GCODE[20];
  1416. enqueue_and_echo_commands_P(PSTR("G28"));
  1417. #if WATCH_THE_BED
  1418. sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
  1419. enqueue_and_echo_command(UBL_LCD_GCODE);
  1420. #endif
  1421. sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
  1422. enqueue_and_echo_command(UBL_LCD_GCODE);
  1423. enqueue_and_echo_commands_P(PSTR("G29 P1"));
  1424. }
  1425. /**
  1426. * UBL Custom Mesh submenu
  1427. */
  1428. void _lcd_ubl_custom_mesh() {
  1429. START_MENU();
  1430. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1431. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_HOTEND_TEMP, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
  1432. #if WATCH_THE_BED
  1433. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_BED_TEMP, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 5));
  1434. #endif
  1435. MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  1436. END_MENU();
  1437. }
  1438. /**
  1439. * UBL Adjust Mesh Height Command
  1440. */
  1441. void _lcd_ubl_adjust_height_cmd() {
  1442. char UBL_LCD_GCODE[16];
  1443. const int ind = ubl_height_amount < 0 ? 6 : 7;
  1444. strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6-"));
  1445. sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
  1446. enqueue_and_echo_command(UBL_LCD_GCODE);
  1447. }
  1448. /**
  1449. * UBL Adjust Mesh Height submenu
  1450. */
  1451. void _lcd_ubl_height_adjust_menu() {
  1452. START_MENU();
  1453. MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
  1454. MENU_ITEM_EDIT(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9);
  1455. MENU_ITEM(function, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_adjust_height_cmd);
  1456. MENU_ITEM(submenu, MSG_WATCH, lcd_status_screen);
  1457. END_MENU();
  1458. }
  1459. /**
  1460. * UBL Edit Mesh submenu
  1461. */
  1462. void _lcd_ubl_edit_mesh() {
  1463. START_MENU();
  1464. MENU_BACK(MSG_UBL_TOOLS);
  1465. MENU_BACK(MSG_UBL_LEVEL_BED);
  1466. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R T"));
  1467. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  1468. MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_height_adjust_menu);
  1469. MENU_ITEM(submenu, MSG_WATCH, lcd_status_screen);
  1470. END_MENU();
  1471. }
  1472. /**
  1473. * UBL Validate Custom Mesh Command
  1474. */
  1475. void _lcd_ubl_validate_custom_mesh() {
  1476. char UBL_LCD_GCODE[24];
  1477. const int temp =
  1478. #if WATCH_THE_BED
  1479. custom_bed_temp
  1480. #else
  1481. 0
  1482. #endif
  1483. ;
  1484. sprintf_P(UBL_LCD_GCODE, PSTR("G28\nG26 C B%i H%i P"), temp, custom_hotend_temp);
  1485. enqueue_and_echo_command(UBL_LCD_GCODE);
  1486. }
  1487. /**
  1488. * UBL Validate Mesh submenu
  1489. */
  1490. void _lcd_ubl_validate_mesh() {
  1491. START_MENU();
  1492. MENU_BACK(MSG_UBL_TOOLS);
  1493. #if WATCH_THE_BED
  1494. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1495. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1496. #else
  1497. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1498. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1499. #endif
  1500. MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  1501. MENU_ITEM(submenu, MSG_WATCH, lcd_status_screen);
  1502. END_MENU();
  1503. }
  1504. /**
  1505. * UBL Grid Leveling Command
  1506. */
  1507. void _lcd_ubl_grid_level_cmd() {
  1508. char UBL_LCD_GCODE[10];
  1509. sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
  1510. enqueue_and_echo_command(UBL_LCD_GCODE);
  1511. }
  1512. /**
  1513. * UBL Grid Leveling submenu
  1514. */
  1515. void _lcd_ubl_grid_level() {
  1516. START_MENU();
  1517. MENU_BACK(MSG_UBL_TOOLS);
  1518. MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  1519. MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
  1520. END_MENU();
  1521. }
  1522. /**
  1523. * UBL Mesh Leveling submenu
  1524. */
  1525. void _lcd_ubl_mesh_leveling() {
  1526. START_MENU();
  1527. MENU_BACK(MSG_UBL_TOOLS);
  1528. MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  1529. MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  1530. MENU_ITEM(submenu, MSG_WATCH, lcd_status_screen);
  1531. END_MENU();
  1532. }
  1533. /**
  1534. * UBL Fill-in Amount Mesh Command
  1535. */
  1536. void _lcd_ubl_fillin_amount_cmd() {
  1537. char UBL_LCD_GCODE[16];
  1538. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  1539. enqueue_and_echo_command(UBL_LCD_GCODE);
  1540. }
  1541. /**
  1542. * UBL Smart Fill-in Command
  1543. */
  1544. void _lcd_ubl_smart_fillin_cmd() {
  1545. char UBL_LCD_GCODE[12];
  1546. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 T%i"), map_type);
  1547. enqueue_and_echo_command(UBL_LCD_GCODE);
  1548. }
  1549. /**
  1550. * UBL Fill-in Mesh submenu
  1551. */
  1552. void _lcd_ubl_fillin_menu() {
  1553. START_MENU();
  1554. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1555. MENU_ITEM_EDIT(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9);
  1556. MENU_ITEM(function, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_amount_cmd);
  1557. MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
  1558. MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  1559. MENU_ITEM(submenu, MSG_WATCH, lcd_status_screen);
  1560. END_MENU();
  1561. }
  1562. void _lcd_ubl_invalidate() {
  1563. ubl.invalidate();
  1564. SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
  1565. }
  1566. /**
  1567. * UBL Build Mesh submenu
  1568. */
  1569. void _lcd_ubl_build_mesh() {
  1570. START_MENU();
  1571. MENU_BACK(MSG_UBL_TOOLS);
  1572. #if WATCH_THE_BED
  1573. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1574. "G28\n"
  1575. "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
  1576. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1577. "G29 P1\n"
  1578. "M104 S0\n"
  1579. "M140 S0"
  1580. ));
  1581. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1582. "G28\n"
  1583. "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
  1584. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1585. "G29 P1\n"
  1586. "M104 S0\n"
  1587. "M140 S0"
  1588. ));
  1589. #else
  1590. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1591. "G28\n"
  1592. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1593. "G29 P1\n"
  1594. "M104 S0"
  1595. ));
  1596. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1597. "G28\n"
  1598. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1599. "G29 P1\n"
  1600. "M104 S0"
  1601. ));
  1602. #endif
  1603. MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  1604. MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  1605. MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_menu);
  1606. MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  1607. MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  1608. MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  1609. MENU_ITEM(submenu, MSG_WATCH, lcd_status_screen);
  1610. END_MENU();
  1611. }
  1612. /**
  1613. * UBL Load Mesh Command
  1614. */
  1615. void _lcd_ubl_load_mesh_cmd() {
  1616. char UBL_LCD_GCODE[8];
  1617. sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
  1618. enqueue_and_echo_command(UBL_LCD_GCODE);
  1619. }
  1620. /**
  1621. * UBL Save Mesh Command
  1622. */
  1623. void _lcd_ubl_save_mesh_cmd() {
  1624. char UBL_LCD_GCODE[8];
  1625. sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
  1626. enqueue_and_echo_command(UBL_LCD_GCODE);
  1627. }
  1628. /**
  1629. * UBL Mesh Storage submenu
  1630. */
  1631. void _lcd_ubl_storage_mesh() {
  1632. START_MENU();
  1633. MENU_BACK(MSG_UBL_LEVEL_BED);
  1634. MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, 9);
  1635. MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  1636. MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  1637. END_MENU();
  1638. }
  1639. /**
  1640. * UBL Output map Command
  1641. */
  1642. void _lcd_ubl_output_map_cmd() {
  1643. char UBL_LCD_GCODE[10];
  1644. sprintf_P(UBL_LCD_GCODE, PSTR("G29 T%i"), map_type);
  1645. enqueue_and_echo_command(UBL_LCD_GCODE);
  1646. }
  1647. /**
  1648. * UBL Output map submenu
  1649. */
  1650. void _lcd_ubl_output_map() {
  1651. START_MENU();
  1652. MENU_BACK(MSG_UBL_LEVEL_BED);
  1653. MENU_ITEM_EDIT(int3, MSG_UBL_MAP_TYPE, &map_type, 0, 1);
  1654. if (map_type == 0) MENU_ITEM(function, MSG_UBL_OUTPUT_MAP_HOST, _lcd_ubl_output_map_cmd);
  1655. if (map_type == 1) MENU_ITEM(function, MSG_UBL_OUTPUT_MAP_CSV, _lcd_ubl_output_map_cmd);
  1656. END_MENU();
  1657. }
  1658. /**
  1659. * UBL Tools submenu
  1660. */
  1661. void _lcd_ubl_tools_menu() {
  1662. START_MENU();
  1663. MENU_BACK(MSG_UBL_LEVEL_BED);
  1664. MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  1665. MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  1666. MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
  1667. MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  1668. END_MENU();
  1669. }
  1670. /**
  1671. * UBL System submenu
  1672. *
  1673. * Prepare
  1674. * - Unified Bed Leveling
  1675. * - Activate UBL
  1676. * - Deactivate UBL
  1677. * - Mesh Storage
  1678. * Memory Slot:
  1679. * Load Bed Mesh
  1680. * Save Bed Mesh
  1681. * - Output Map
  1682. * Map Type:
  1683. * Output Bed Mesh Host / Output Bed Mesh CSV
  1684. * - UBL Tools
  1685. * - Build Mesh
  1686. * Build PLA Mesh
  1687. * Build ABS Mesh
  1688. * - Build Custom Mesh
  1689. * Hotend Temp:
  1690. * Bed Temp:
  1691. * Build Custom Mesh
  1692. * Info Screen
  1693. * - Build Cold Mesh
  1694. * - Fill-in Mesh
  1695. * Fill-in Mesh
  1696. * Smart Fill-in
  1697. * Manual Fill-in
  1698. * Info Screen
  1699. * Continue Bed Mesh
  1700. * Invalidate All
  1701. * Invalidate Closest
  1702. * - Validate Mesh
  1703. * PLA Mesh Validation
  1704. * ABS Mesh Validation
  1705. * - Custom Mesh Validation
  1706. * Hotend Temp:
  1707. * Bed Temp:
  1708. * Validate Mesh
  1709. * Info Screen
  1710. * - Edit Mesh
  1711. * Fine Tune All
  1712. * Fine Tune Closest
  1713. * - Adjust Mesh Height
  1714. * Height Amount:
  1715. * Adjust Mesh Height
  1716. * Info Screen
  1717. * - Mesh Leveling
  1718. * 3-Point Mesh Leveling
  1719. * - Grid Mesh Leveling
  1720. * Side points:
  1721. * Level Mesh
  1722. * Info Screen
  1723. * - Output UBL Info
  1724. */
  1725. void _lcd_ubl_level_bed() {
  1726. START_MENU();
  1727. MENU_BACK(MSG_PREPARE);
  1728. MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  1729. MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  1730. MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  1731. MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  1732. MENU_ITEM(submenu, MSG_UBL_TOOLS, _lcd_ubl_tools_menu);
  1733. MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
  1734. END_MENU();
  1735. }
  1736. #endif // AUTO_BED_LEVELING_UBL
  1737. /**
  1738. *
  1739. * "Prepare" submenu
  1740. *
  1741. */
  1742. void lcd_prepare_menu() {
  1743. START_MENU();
  1744. //
  1745. // ^ Main
  1746. //
  1747. MENU_BACK(MSG_MAIN);
  1748. //
  1749. // Move Axis
  1750. //
  1751. #if ENABLED(DELTA)
  1752. if (axis_homed[Z_AXIS])
  1753. #endif
  1754. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  1755. //
  1756. // Auto Home
  1757. //
  1758. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1759. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  1760. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  1761. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  1762. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  1763. #endif
  1764. //
  1765. // Level Bed
  1766. //
  1767. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1768. MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  1769. #elif ENABLED(LCD_BED_LEVELING)
  1770. #if ENABLED(PROBE_MANUALLY)
  1771. if (!g29_in_progress)
  1772. #endif
  1773. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  1774. #endif
  1775. #if HAS_M206_COMMAND
  1776. //
  1777. // Set Home Offsets
  1778. //
  1779. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  1780. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  1781. #endif
  1782. //
  1783. // Disable Steppers
  1784. //
  1785. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1786. //
  1787. // Change filament
  1788. //
  1789. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1790. if (!thermalManager.tooColdToExtrude(active_extruder))
  1791. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1792. #endif
  1793. #if TEMP_SENSOR_0 != 0
  1794. //
  1795. // Cooldown
  1796. //
  1797. bool has_heat = false;
  1798. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  1799. #if HAS_TEMP_BED
  1800. if (thermalManager.target_temperature_bed) has_heat = true;
  1801. #endif
  1802. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1803. //
  1804. // Preheat for Material 1 and 2
  1805. //
  1806. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0
  1807. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  1808. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  1809. #else
  1810. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1811. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1812. #endif
  1813. #endif // TEMP_SENSOR_0 != 0
  1814. //
  1815. // BLTouch Self-Test and Reset
  1816. //
  1817. #if ENABLED(BLTOUCH)
  1818. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  1819. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  1820. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  1821. #endif
  1822. //
  1823. // Switch power on/off
  1824. //
  1825. #if HAS_POWER_SWITCH
  1826. if (powersupply_on)
  1827. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  1828. else
  1829. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  1830. #endif
  1831. //
  1832. // Autostart
  1833. //
  1834. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1835. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  1836. #endif
  1837. END_MENU();
  1838. }
  1839. float move_menu_scale;
  1840. #if ENABLED(DELTA_CALIBRATION_MENU)
  1841. void lcd_move_z();
  1842. void lcd_delta_calibrate_menu();
  1843. void _lcd_calibrate_homing() {
  1844. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  1845. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1846. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1847. lcd_goto_previous_menu();
  1848. }
  1849. void _lcd_delta_calibrate_home() {
  1850. #if HAS_LEVELING
  1851. reset_bed_level(); // After calibration bed-level data is no longer valid
  1852. #endif
  1853. enqueue_and_echo_commands_P(PSTR("G28"));
  1854. lcd_goto_screen(_lcd_calibrate_homing);
  1855. }
  1856. // Move directly to the tower position with uninterpolated moves
  1857. // If we used interpolated moves it would cause this to become re-entrant
  1858. void _goto_tower_pos(const float &a) {
  1859. #if HAS_LEVELING
  1860. reset_bed_level(); // After calibration bed-level data is no longer valid
  1861. #endif
  1862. current_position[Z_AXIS] = max(Z_HOMING_HEIGHT, Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5;
  1863. line_to_current(Z_AXIS);
  1864. current_position[X_AXIS] = a < 0 ? LOGICAL_X_POSITION(X_HOME_POS) : cos(RADIANS(a)) * delta_calibration_radius;
  1865. current_position[Y_AXIS] = a < 0 ? LOGICAL_Y_POSITION(Y_HOME_POS) : sin(RADIANS(a)) * delta_calibration_radius;
  1866. line_to_current(Z_AXIS);
  1867. current_position[Z_AXIS] = 4.0;
  1868. line_to_current(Z_AXIS);
  1869. lcd_synchronize();
  1870. move_menu_scale = 0.1;
  1871. lcd_goto_screen(lcd_move_z);
  1872. }
  1873. void _goto_tower_x() { _goto_tower_pos(210); }
  1874. void _goto_tower_y() { _goto_tower_pos(330); }
  1875. void _goto_tower_z() { _goto_tower_pos(90); }
  1876. void _goto_center() { _goto_tower_pos(-1); }
  1877. void lcd_delta_calibrate_menu() {
  1878. START_MENU();
  1879. MENU_BACK(MSG_MAIN);
  1880. #if ENABLED(DELTA_AUTO_CALIBRATION)
  1881. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33"));
  1882. MENU_ITEM(gcode, MSG_DELTA_HEIGHT_CALIBRATE, PSTR("G33 P1 A"));
  1883. #endif
  1884. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  1885. if (axis_homed[Z_AXIS]) {
  1886. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  1887. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  1888. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  1889. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  1890. }
  1891. END_MENU();
  1892. }
  1893. #endif // DELTA_CALIBRATION_MENU
  1894. /**
  1895. * If the most recent manual move hasn't been fed to the planner yet,
  1896. * and the planner can accept one, send immediately
  1897. */
  1898. inline void manage_manual_move() {
  1899. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  1900. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  1901. manual_move_axis = (int8_t)NO_AXIS;
  1902. }
  1903. }
  1904. /**
  1905. * Set a flag that lcd_update() should start a move
  1906. * to "current_position" after a short delay.
  1907. */
  1908. inline void manual_move_to_current(AxisEnum axis
  1909. #if E_MANUAL > 1
  1910. , int8_t eindex=-1
  1911. #endif
  1912. ) {
  1913. #if E_MANUAL > 1
  1914. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  1915. #endif
  1916. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  1917. manual_move_axis = (int8_t)axis;
  1918. }
  1919. /**
  1920. *
  1921. * "Prepare" > "Move Axis" submenu
  1922. *
  1923. */
  1924. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  1925. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1926. ENCODER_DIRECTION_NORMAL();
  1927. if (encoderPosition) {
  1928. refresh_cmd_timeout();
  1929. float min = current_position[axis] - 1000,
  1930. max = current_position[axis] + 1000;
  1931. #if HAS_SOFTWARE_ENDSTOPS
  1932. // Limit to software endstops, if enabled
  1933. if (soft_endstops_enabled) {
  1934. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  1935. min = soft_endstop_min[axis];
  1936. #endif
  1937. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  1938. max = soft_endstop_max[axis];
  1939. #endif
  1940. }
  1941. #endif
  1942. // Get the new position
  1943. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  1944. // Delta limits XY based on the current offset from center
  1945. // This assumes the center is 0,0
  1946. #if ENABLED(DELTA)
  1947. if (axis != Z_AXIS) {
  1948. max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  1949. min = -max;
  1950. }
  1951. #endif
  1952. // Limit only when trying to move towards the limit
  1953. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  1954. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  1955. manual_move_to_current(axis);
  1956. encoderPosition = 0;
  1957. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1958. }
  1959. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  1960. }
  1961. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  1962. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  1963. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  1964. void _lcd_move_e(
  1965. #if E_MANUAL > 1
  1966. int8_t eindex=-1
  1967. #endif
  1968. ) {
  1969. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1970. ENCODER_DIRECTION_NORMAL();
  1971. if (encoderPosition) {
  1972. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  1973. encoderPosition = 0;
  1974. manual_move_to_current(E_AXIS
  1975. #if E_MANUAL > 1
  1976. , eindex
  1977. #endif
  1978. );
  1979. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1980. }
  1981. if (lcdDrawUpdate) {
  1982. PGM_P pos_label;
  1983. #if E_MANUAL == 1
  1984. pos_label = PSTR(MSG_MOVE_E);
  1985. #else
  1986. switch (eindex) {
  1987. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  1988. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  1989. #if E_MANUAL > 2
  1990. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  1991. #if E_MANUAL > 3
  1992. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  1993. #if E_MANUAL > 4
  1994. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  1995. #endif // E_MANUAL > 4
  1996. #endif // E_MANUAL > 3
  1997. #endif // E_MANUAL > 2
  1998. }
  1999. #endif // E_MANUAL > 1
  2000. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  2001. }
  2002. }
  2003. void lcd_move_e() { _lcd_move_e(); }
  2004. #if E_MANUAL > 1
  2005. void lcd_move_e0() { _lcd_move_e(0); }
  2006. void lcd_move_e1() { _lcd_move_e(1); }
  2007. #if E_MANUAL > 2
  2008. void lcd_move_e2() { _lcd_move_e(2); }
  2009. #if E_MANUAL > 3
  2010. void lcd_move_e3() { _lcd_move_e(3); }
  2011. #if E_MANUAL > 4
  2012. void lcd_move_e4() { _lcd_move_e(4); }
  2013. #endif // E_MANUAL > 4
  2014. #endif // E_MANUAL > 3
  2015. #endif // E_MANUAL > 2
  2016. #endif // E_MANUAL > 1
  2017. /**
  2018. *
  2019. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  2020. *
  2021. */
  2022. screenFunc_t _manual_move_func_ptr;
  2023. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  2024. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  2025. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  2026. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  2027. _manual_move_func_ptr = func;
  2028. START_MENU();
  2029. if (LCD_HEIGHT >= 4) {
  2030. switch(axis) {
  2031. case X_AXIS:
  2032. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  2033. case Y_AXIS:
  2034. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  2035. case Z_AXIS:
  2036. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  2037. default:
  2038. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  2039. }
  2040. }
  2041. MENU_BACK(MSG_MOVE_AXIS);
  2042. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  2043. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  2044. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  2045. END_MENU();
  2046. }
  2047. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  2048. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  2049. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  2050. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  2051. #if E_MANUAL > 1
  2052. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  2053. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  2054. #if E_MANUAL > 2
  2055. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  2056. #if E_MANUAL > 3
  2057. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  2058. #if E_MANUAL > 4
  2059. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  2060. #endif // E_MANUAL > 4
  2061. #endif // E_MANUAL > 3
  2062. #endif // E_MANUAL > 2
  2063. #endif // E_MANUAL > 1
  2064. /**
  2065. *
  2066. * "Prepare" > "Move Axis" submenu
  2067. *
  2068. */
  2069. #if IS_KINEMATIC
  2070. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2071. #if ENABLED(DELTA)
  2072. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  2073. void lcd_lower_z_to_clip_height() {
  2074. current_position[Z_AXIS] = delta_clip_start_height;
  2075. line_to_current(Z_AXIS);
  2076. lcd_synchronize();
  2077. }
  2078. #else
  2079. #define _MOVE_XY_ALLOWED true
  2080. #endif
  2081. #else
  2082. #define _MOVE_XYZ_ALLOWED true
  2083. #define _MOVE_XY_ALLOWED true
  2084. #endif
  2085. void lcd_move_menu() {
  2086. START_MENU();
  2087. MENU_BACK(MSG_PREPARE);
  2088. if (_MOVE_XYZ_ALLOWED) {
  2089. if (_MOVE_XY_ALLOWED) {
  2090. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  2091. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  2092. }
  2093. #if ENABLED(DELTA)
  2094. else
  2095. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  2096. #endif
  2097. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  2098. }
  2099. else
  2100. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2101. #if ENABLED(SWITCHING_EXTRUDER)
  2102. if (active_extruder)
  2103. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2104. else
  2105. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2106. #endif
  2107. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  2108. #if E_MANUAL > 1
  2109. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  2110. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  2111. #if E_MANUAL > 2
  2112. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  2113. #if E_MANUAL > 3
  2114. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  2115. #if E_MANUAL > 4
  2116. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  2117. #endif // E_MANUAL > 4
  2118. #endif // E_MANUAL > 3
  2119. #endif // E_MANUAL > 2
  2120. #endif // E_MANUAL > 1
  2121. END_MENU();
  2122. }
  2123. /**
  2124. *
  2125. * "Control" submenu
  2126. *
  2127. */
  2128. /**
  2129. *
  2130. * Callback for LCD contrast
  2131. *
  2132. */
  2133. #if HAS_LCD_CONTRAST
  2134. void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
  2135. #endif // HAS_LCD_CONTRAST
  2136. #if ENABLED(EEPROM_SETTINGS)
  2137. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  2138. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  2139. #endif
  2140. static void lcd_factory_settings() {
  2141. settings.reset();
  2142. lcd_completion_feedback();
  2143. }
  2144. void lcd_control_menu() {
  2145. START_MENU();
  2146. MENU_BACK(MSG_MAIN);
  2147. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2148. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  2149. MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
  2150. #if HAS_LCD_CONTRAST
  2151. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
  2152. #endif
  2153. #if ENABLED(FWRETRACT)
  2154. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  2155. #endif
  2156. #if ENABLED(DAC_STEPPER_CURRENT)
  2157. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  2158. #endif
  2159. #if ENABLED(BLTOUCH)
  2160. MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);
  2161. #endif
  2162. #if ENABLED(EEPROM_SETTINGS)
  2163. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2164. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2165. #endif
  2166. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  2167. #if ENABLED(EEPROM_SETTINGS)
  2168. MENU_ITEM(gcode, MSG_INIT_EEPROM, PSTR("M502\nM500")); // TODO: Add "Are You Sure?" step
  2169. #endif
  2170. END_MENU();
  2171. }
  2172. /**
  2173. *
  2174. * "Temperature" submenu
  2175. *
  2176. */
  2177. #if ENABLED(PID_AUTOTUNE_MENU)
  2178. #if ENABLED(PIDTEMP)
  2179. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  2180. #endif
  2181. #if ENABLED(PIDTEMPBED)
  2182. int autotune_temp_bed = 70;
  2183. #endif
  2184. void _lcd_autotune(int e) {
  2185. char cmd[30];
  2186. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  2187. #if HAS_PID_FOR_BOTH
  2188. e < 0 ? autotune_temp_bed : autotune_temp[e]
  2189. #elif ENABLED(PIDTEMPBED)
  2190. autotune_temp_bed
  2191. #else
  2192. autotune_temp[e]
  2193. #endif
  2194. );
  2195. enqueue_and_echo_command(cmd);
  2196. }
  2197. #endif // PID_AUTOTUNE_MENU
  2198. #if ENABLED(PIDTEMP)
  2199. // Helpers for editing PID Ki & Kd values
  2200. // grab the PID value out of the temp variable; scale it; then update the PID driver
  2201. void copy_and_scalePID_i(int e) {
  2202. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2203. UNUSED(e);
  2204. #endif
  2205. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  2206. thermalManager.updatePID();
  2207. }
  2208. void copy_and_scalePID_d(int e) {
  2209. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2210. UNUSED(e);
  2211. #endif
  2212. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  2213. thermalManager.updatePID();
  2214. }
  2215. #define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
  2216. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  2217. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  2218. #if ENABLED(PID_AUTOTUNE_MENU)
  2219. #define DEFINE_PIDTEMP_FUNCS(N) \
  2220. _DEFINE_PIDTEMP_BASE_FUNCS(N); \
  2221. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); } typedef void _pid_##N##_void
  2222. #else
  2223. #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N) typedef void _pid_##N##_void
  2224. #endif
  2225. DEFINE_PIDTEMP_FUNCS(0);
  2226. #if ENABLED(PID_PARAMS_PER_HOTEND)
  2227. #if HOTENDS > 1
  2228. DEFINE_PIDTEMP_FUNCS(1);
  2229. #if HOTENDS > 2
  2230. DEFINE_PIDTEMP_FUNCS(2);
  2231. #if HOTENDS > 3
  2232. DEFINE_PIDTEMP_FUNCS(3);
  2233. #if HOTENDS > 4
  2234. DEFINE_PIDTEMP_FUNCS(4);
  2235. #endif // HOTENDS > 4
  2236. #endif // HOTENDS > 3
  2237. #endif // HOTENDS > 2
  2238. #endif // HOTENDS > 1
  2239. #endif // PID_PARAMS_PER_HOTEND
  2240. #endif // PIDTEMP
  2241. /**
  2242. *
  2243. * "Control" > "Temperature" submenu
  2244. *
  2245. */
  2246. void lcd_control_temperature_menu() {
  2247. START_MENU();
  2248. //
  2249. // ^ Control
  2250. //
  2251. MENU_BACK(MSG_CONTROL);
  2252. //
  2253. // Nozzle:
  2254. // Nozzle [1-5]:
  2255. //
  2256. #if HOTENDS == 1
  2257. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2258. #else // HOTENDS > 1
  2259. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2260. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  2261. #if HOTENDS > 2
  2262. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  2263. #if HOTENDS > 3
  2264. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  2265. #if HOTENDS > 4
  2266. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  2267. #endif // HOTENDS > 4
  2268. #endif // HOTENDS > 3
  2269. #endif // HOTENDS > 2
  2270. #endif // HOTENDS > 1
  2271. //
  2272. // Bed:
  2273. //
  2274. #if WATCH_THE_BED
  2275. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  2276. #endif
  2277. //
  2278. // Fan Speed:
  2279. //
  2280. #if FAN_COUNT > 0
  2281. #if HAS_FAN0
  2282. #if FAN_COUNT > 1
  2283. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  2284. #else
  2285. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  2286. #endif
  2287. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  2288. #endif
  2289. #if HAS_FAN1
  2290. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  2291. #endif
  2292. #if HAS_FAN2
  2293. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  2294. #endif
  2295. #endif // FAN_COUNT > 0
  2296. //
  2297. // Autotemp, Min, Max, Fact
  2298. //
  2299. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  2300. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  2301. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  2302. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  2303. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  2304. #endif
  2305. //
  2306. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  2307. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  2308. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  2309. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  2310. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  2311. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  2312. //
  2313. #if ENABLED(PIDTEMP)
  2314. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  2315. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  2316. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  2317. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  2318. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  2319. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  2320. #if ENABLED(PID_EXTRUSION_SCALING)
  2321. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  2322. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  2323. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  2324. #else
  2325. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  2326. #endif
  2327. #if ENABLED(PID_AUTOTUNE_MENU)
  2328. #define PID_MENU_ITEMS(ELABEL, eindex) \
  2329. _PID_MENU_ITEMS(ELABEL, eindex); \
  2330. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  2331. #else
  2332. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  2333. #endif
  2334. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  2335. PID_MENU_ITEMS(" " MSG_E1, 0);
  2336. PID_MENU_ITEMS(" " MSG_E2, 1);
  2337. #if HOTENDS > 2
  2338. PID_MENU_ITEMS(" " MSG_E3, 2);
  2339. #if HOTENDS > 3
  2340. PID_MENU_ITEMS(" " MSG_E4, 3);
  2341. #if HOTENDS > 4
  2342. PID_MENU_ITEMS(" " MSG_E5, 4);
  2343. #endif // HOTENDS > 4
  2344. #endif // HOTENDS > 3
  2345. #endif // HOTENDS > 2
  2346. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2347. PID_MENU_ITEMS("", 0);
  2348. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2349. #endif // PIDTEMP
  2350. //
  2351. // Preheat Material 1 conf
  2352. //
  2353. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  2354. //
  2355. // Preheat Material 2 conf
  2356. //
  2357. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  2358. END_MENU();
  2359. }
  2360. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  2361. #if HOTENDS > 4
  2362. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  2363. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  2364. #elif HOTENDS > 3
  2365. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  2366. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  2367. #elif HOTENDS > 2
  2368. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  2369. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  2370. #elif HOTENDS > 1
  2371. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  2372. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  2373. #else
  2374. #define MINTEMP_ALL HEATER_0_MINTEMP
  2375. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  2376. #endif
  2377. START_MENU();
  2378. MENU_BACK(MSG_TEMPERATURE);
  2379. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  2380. #if TEMP_SENSOR_0 != 0
  2381. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  2382. #endif
  2383. #if TEMP_SENSOR_BED != 0
  2384. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2385. #endif
  2386. #if ENABLED(EEPROM_SETTINGS)
  2387. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2388. #endif
  2389. END_MENU();
  2390. }
  2391. /**
  2392. *
  2393. * "Temperature" > "Preheat Material 1 conf" submenu
  2394. *
  2395. */
  2396. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2397. /**
  2398. *
  2399. * "Temperature" > "Preheat Material 2 conf" submenu
  2400. *
  2401. */
  2402. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2403. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2404. #if ENABLED(DISTINCT_E_FACTORS)
  2405. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2406. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2407. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2408. #if E_STEPPERS > 2
  2409. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2410. #if E_STEPPERS > 3
  2411. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2412. #if E_STEPPERS > 4
  2413. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2414. #endif // E_STEPPERS > 4
  2415. #endif // E_STEPPERS > 3
  2416. #endif // E_STEPPERS > 2
  2417. #endif
  2418. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2419. #if ENABLED(DISTINCT_E_FACTORS)
  2420. void _planner_refresh_e_positioning(const uint8_t e) {
  2421. if (e == active_extruder)
  2422. _planner_refresh_positioning();
  2423. else
  2424. planner.steps_to_mm[e] = 1.0 / planner.axis_steps_per_mm[e];
  2425. }
  2426. void _planner_refresh_e0_positioning() { _reset_e_acceleration_rate(0); }
  2427. void _planner_refresh_e1_positioning() { _reset_e_acceleration_rate(1); }
  2428. #if E_STEPPERS > 2
  2429. void _planner_refresh_e2_positioning() { _reset_e_acceleration_rate(2); }
  2430. #if E_STEPPERS > 3
  2431. void _planner_refresh_e3_positioning() { _reset_e_acceleration_rate(3); }
  2432. #if E_STEPPERS > 4
  2433. void _planner_refresh_e4_positioning() { _reset_e_acceleration_rate(4); }
  2434. #endif // E_STEPPERS > 4
  2435. #endif // E_STEPPERS > 3
  2436. #endif // E_STEPPERS > 2
  2437. #endif
  2438. /**
  2439. *
  2440. * "Control" > "Motion" submenu
  2441. *
  2442. */
  2443. #if HAS_BED_PROBE && DISABLED(BABYSTEP_ZPROBE_OFFSET)
  2444. static void lcd_refresh_zprobe_zoffset() { refresh_zprobe_zoffset(); }
  2445. #endif
  2446. void lcd_control_motion_menu() {
  2447. START_MENU();
  2448. MENU_BACK(MSG_CONTROL);
  2449. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2450. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2451. #elif HAS_BED_PROBE
  2452. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  2453. #endif
  2454. // Manual bed leveling, Bed Z:
  2455. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  2456. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  2457. #endif
  2458. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2459. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2460. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2461. #if ENABLED(DELTA)
  2462. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2463. #else
  2464. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2465. #endif
  2466. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2467. //
  2468. // M203 Settings
  2469. //
  2470. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2471. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2472. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2473. #if ENABLED(DISTINCT_E_FACTORS)
  2474. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2475. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2476. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2477. #if E_STEPPERS > 2
  2478. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2479. #if E_STEPPERS > 3
  2480. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2481. #if E_STEPPERS > 4
  2482. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2483. #endif // E_STEPPERS > 4
  2484. #endif // E_STEPPERS > 3
  2485. #endif // E_STEPPERS > 2
  2486. #else
  2487. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2488. #endif
  2489. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2490. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2491. //
  2492. // M201 Settings
  2493. //
  2494. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2495. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2496. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2497. #if ENABLED(DISTINCT_E_FACTORS)
  2498. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2499. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2500. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2501. #if E_STEPPERS > 2
  2502. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2503. #if E_STEPPERS > 3
  2504. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2505. #if E_STEPPERS > 4
  2506. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2507. #endif // E_STEPPERS > 4
  2508. #endif // E_STEPPERS > 3
  2509. #endif // E_STEPPERS > 2
  2510. #else
  2511. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2512. #endif
  2513. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2514. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2515. //
  2516. // M92 Settings
  2517. //
  2518. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2519. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2520. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2521. #if ENABLED(DISTINCT_E_FACTORS)
  2522. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2523. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2524. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2525. #if E_STEPPERS > 2
  2526. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2527. #if E_STEPPERS > 3
  2528. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2529. #if E_STEPPERS > 4
  2530. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2531. #endif // E_STEPPERS > 4
  2532. #endif // E_STEPPERS > 3
  2533. #endif // E_STEPPERS > 2
  2534. #else
  2535. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2536. #endif
  2537. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2538. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2539. #endif
  2540. END_MENU();
  2541. }
  2542. /**
  2543. *
  2544. * "Control" > "Filament" submenu
  2545. *
  2546. */
  2547. void lcd_control_filament_menu() {
  2548. START_MENU();
  2549. MENU_BACK(MSG_CONTROL);
  2550. #if ENABLED(LIN_ADVANCE)
  2551. MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
  2552. #endif
  2553. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  2554. if (volumetric_enabled) {
  2555. #if EXTRUDERS == 1
  2556. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2557. #else // EXTRUDERS > 1
  2558. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2559. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  2560. #if EXTRUDERS > 2
  2561. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  2562. #if EXTRUDERS > 3
  2563. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  2564. #if EXTRUDERS > 4
  2565. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  2566. #endif // EXTRUDERS > 4
  2567. #endif // EXTRUDERS > 3
  2568. #endif // EXTRUDERS > 2
  2569. #endif // EXTRUDERS > 1
  2570. }
  2571. END_MENU();
  2572. }
  2573. /**
  2574. *
  2575. * "Control" > "Retract" submenu
  2576. *
  2577. */
  2578. #if ENABLED(FWRETRACT)
  2579. void lcd_control_retract_menu() {
  2580. START_MENU();
  2581. MENU_BACK(MSG_CONTROL);
  2582. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  2583. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  2584. #if EXTRUDERS > 1
  2585. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  2586. #endif
  2587. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  2588. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  2589. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  2590. #if EXTRUDERS > 1
  2591. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, -100, 100);
  2592. #endif
  2593. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  2594. END_MENU();
  2595. }
  2596. #endif // FWRETRACT
  2597. #if ENABLED(SDSUPPORT)
  2598. #if !PIN_EXISTS(SD_DETECT)
  2599. void lcd_sd_refresh() {
  2600. card.initsd();
  2601. encoderTopLine = 0;
  2602. }
  2603. #endif
  2604. void lcd_sd_updir() {
  2605. card.updir();
  2606. encoderTopLine = 0;
  2607. screen_changed = true;
  2608. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2609. }
  2610. /**
  2611. *
  2612. * "Print from SD" submenu
  2613. *
  2614. */
  2615. void lcd_sdcard_menu() {
  2616. ENCODER_DIRECTION_MENUS();
  2617. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  2618. const uint16_t fileCnt = card.getnrfilenames();
  2619. START_MENU();
  2620. MENU_BACK(MSG_MAIN);
  2621. card.getWorkDirName();
  2622. if (card.filename[0] == '/') {
  2623. #if !PIN_EXISTS(SD_DETECT)
  2624. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  2625. #endif
  2626. }
  2627. else {
  2628. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  2629. }
  2630. for (uint16_t i = 0; i < fileCnt; i++) {
  2631. if (_menuLineNr == _thisItemNr) {
  2632. const uint16_t nr =
  2633. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  2634. fileCnt - 1 -
  2635. #endif
  2636. i;
  2637. #if ENABLED(SDCARD_SORT_ALPHA)
  2638. card.getfilename_sorted(nr);
  2639. #else
  2640. card.getfilename(nr);
  2641. #endif
  2642. if (card.filenameIsDir)
  2643. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2644. else
  2645. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2646. }
  2647. else {
  2648. MENU_ITEM_DUMMY();
  2649. }
  2650. }
  2651. END_MENU();
  2652. }
  2653. #endif // SDSUPPORT
  2654. #if ENABLED(LCD_INFO_MENU)
  2655. #if ENABLED(PRINTCOUNTER)
  2656. /**
  2657. *
  2658. * About Printer > Statistics submenu
  2659. *
  2660. */
  2661. void lcd_info_stats_menu() {
  2662. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2663. char buffer[21];
  2664. printStatistics stats = print_job_timer.getStats();
  2665. START_SCREEN(); // 12345678901234567890
  2666. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  2667. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  2668. duration_t elapsed = stats.printTime;
  2669. elapsed.toString(buffer);
  2670. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  2671. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2672. elapsed = stats.longestPrint;
  2673. elapsed.toString(buffer);
  2674. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  2675. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2676. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  2677. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  2678. STATIC_ITEM("", false, false, buffer); // 125m
  2679. END_SCREEN();
  2680. }
  2681. #endif // PRINTCOUNTER
  2682. /**
  2683. *
  2684. * About Printer > Thermistors
  2685. *
  2686. */
  2687. void lcd_info_thermistors_menu() {
  2688. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2689. START_SCREEN();
  2690. #define THERMISTOR_ID TEMP_SENSOR_0
  2691. #include "thermistornames.h"
  2692. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  2693. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  2694. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  2695. #if TEMP_SENSOR_1 != 0
  2696. #undef THERMISTOR_ID
  2697. #define THERMISTOR_ID TEMP_SENSOR_1
  2698. #include "thermistornames.h"
  2699. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  2700. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  2701. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  2702. #endif
  2703. #if TEMP_SENSOR_2 != 0
  2704. #undef THERMISTOR_ID
  2705. #define THERMISTOR_ID TEMP_SENSOR_2
  2706. #include "thermistornames.h"
  2707. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  2708. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  2709. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  2710. #endif
  2711. #if TEMP_SENSOR_3 != 0
  2712. #undef THERMISTOR_ID
  2713. #define THERMISTOR_ID TEMP_SENSOR_3
  2714. #include "thermistornames.h"
  2715. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  2716. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  2717. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  2718. #endif
  2719. #if TEMP_SENSOR_4 != 0
  2720. #undef THERMISTOR_ID
  2721. #define THERMISTOR_ID TEMP_SENSOR_4
  2722. #include "thermistornames.h"
  2723. STATIC_ITEM("T4: " THERMISTOR_NAME, false, true);
  2724. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_4_MINTEMP), false);
  2725. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false);
  2726. #endif
  2727. #if TEMP_SENSOR_BED != 0
  2728. #undef THERMISTOR_ID
  2729. #define THERMISTOR_ID TEMP_SENSOR_BED
  2730. #include "thermistornames.h"
  2731. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  2732. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  2733. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  2734. #endif
  2735. END_SCREEN();
  2736. }
  2737. /**
  2738. *
  2739. * About Printer > Board Info
  2740. *
  2741. */
  2742. void lcd_info_board_menu() {
  2743. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2744. START_SCREEN();
  2745. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  2746. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  2747. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  2748. #if POWER_SUPPLY == 0
  2749. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  2750. #elif POWER_SUPPLY == 1
  2751. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  2752. #elif POWER_SUPPLY == 2
  2753. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  2754. #endif
  2755. END_SCREEN();
  2756. }
  2757. /**
  2758. *
  2759. * About Printer > Printer Info
  2760. *
  2761. */
  2762. void lcd_info_printer_menu() {
  2763. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2764. START_SCREEN();
  2765. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  2766. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  2767. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  2768. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  2769. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  2770. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  2771. END_SCREEN();
  2772. }
  2773. /**
  2774. *
  2775. * "About Printer" submenu
  2776. *
  2777. */
  2778. void lcd_info_menu() {
  2779. START_MENU();
  2780. MENU_BACK(MSG_MAIN);
  2781. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  2782. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  2783. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  2784. #if ENABLED(PRINTCOUNTER)
  2785. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  2786. #endif
  2787. END_MENU();
  2788. }
  2789. #endif // LCD_INFO_MENU
  2790. /**
  2791. *
  2792. * Filament Change Feature Screens
  2793. *
  2794. */
  2795. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2796. // Portions from STATIC_ITEM...
  2797. #define HOTEND_STATUS_ITEM() do { \
  2798. if (_menuLineNr == _thisItemNr) { \
  2799. if (lcdDrawUpdate) { \
  2800. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  2801. lcd_implementation_hotend_status(_lcdLineNr); \
  2802. } \
  2803. if (_skipStatic && encoderLine <= _thisItemNr) { \
  2804. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  2805. ++encoderLine; \
  2806. } \
  2807. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  2808. } \
  2809. ++_thisItemNr; \
  2810. } while(0)
  2811. void lcd_advanced_pause_toocold_menu() {
  2812. START_MENU();
  2813. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  2814. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  2815. MENU_BACK(MSG_BACK);
  2816. #if LCD_HEIGHT > 4
  2817. STATIC_ITEM(" ");
  2818. #endif
  2819. HOTEND_STATUS_ITEM();
  2820. END_MENU();
  2821. }
  2822. void lcd_advanced_pause_resume_print() {
  2823. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_RESUME_PRINT;
  2824. }
  2825. void lcd_advanced_pause_extrude_more() {
  2826. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE;
  2827. }
  2828. void lcd_advanced_pause_option_menu() {
  2829. START_MENU();
  2830. #if LCD_HEIGHT > 2
  2831. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  2832. #endif
  2833. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_advanced_pause_resume_print);
  2834. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_advanced_pause_extrude_more);
  2835. END_MENU();
  2836. }
  2837. void lcd_advanced_pause_init_message() {
  2838. START_SCREEN();
  2839. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2840. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  2841. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  2842. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  2843. #define __FC_LINES_A 3
  2844. #else
  2845. #define __FC_LINES_A 2
  2846. #endif
  2847. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  2848. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  2849. #define _FC_LINES_A (__FC_LINES_A + 1)
  2850. #else
  2851. #define _FC_LINES_A __FC_LINES_A
  2852. #endif
  2853. #if LCD_HEIGHT > _FC_LINES_A + 1
  2854. STATIC_ITEM(" ");
  2855. #endif
  2856. HOTEND_STATUS_ITEM();
  2857. END_SCREEN();
  2858. }
  2859. void lcd_advanced_pause_unload_message() {
  2860. START_SCREEN();
  2861. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2862. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  2863. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  2864. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  2865. #define __FC_LINES_B 3
  2866. #else
  2867. #define __FC_LINES_B 2
  2868. #endif
  2869. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  2870. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  2871. #define _FC_LINES_B (__FC_LINES_B + 1)
  2872. #else
  2873. #define _FC_LINES_B __FC_LINES_B
  2874. #endif
  2875. #if LCD_HEIGHT > _FC_LINES_B + 1
  2876. STATIC_ITEM(" ");
  2877. #endif
  2878. HOTEND_STATUS_ITEM();
  2879. END_SCREEN();
  2880. }
  2881. void lcd_advanced_pause_wait_for_nozzles_to_heat() {
  2882. START_SCREEN();
  2883. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2884. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  2885. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  2886. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  2887. #define _FC_LINES_C 3
  2888. #else
  2889. #define _FC_LINES_C 2
  2890. #endif
  2891. #if LCD_HEIGHT > _FC_LINES_C + 1
  2892. STATIC_ITEM(" ");
  2893. #endif
  2894. HOTEND_STATUS_ITEM();
  2895. END_SCREEN();
  2896. }
  2897. void lcd_advanced_pause_heat_nozzle() {
  2898. START_SCREEN();
  2899. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2900. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  2901. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2902. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  2903. #define _FC_LINES_D 3
  2904. #else
  2905. #define _FC_LINES_D 2
  2906. #endif
  2907. #if LCD_HEIGHT > _FC_LINES_D + 1
  2908. STATIC_ITEM(" ");
  2909. #endif
  2910. HOTEND_STATUS_ITEM();
  2911. END_SCREEN();
  2912. }
  2913. void lcd_advanced_pause_insert_message() {
  2914. START_SCREEN();
  2915. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2916. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  2917. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2918. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  2919. #define __FC_LINES_E 3
  2920. #else
  2921. #define __FC_LINES_E 2
  2922. #endif
  2923. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  2924. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  2925. #define _FC_LINES_E (__FC_LINES_E + 1)
  2926. #else
  2927. #define _FC_LINES_E __FC_LINES_E
  2928. #endif
  2929. #if LCD_HEIGHT > _FC_LINES_E + 1
  2930. STATIC_ITEM(" ");
  2931. #endif
  2932. HOTEND_STATUS_ITEM();
  2933. END_SCREEN();
  2934. }
  2935. void lcd_advanced_pause_load_message() {
  2936. START_SCREEN();
  2937. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2938. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  2939. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  2940. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  2941. #define __FC_LINES_F 3
  2942. #else
  2943. #define __FC_LINES_F 2
  2944. #endif
  2945. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  2946. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  2947. #define _FC_LINES_F (__FC_LINES_F + 1)
  2948. #else
  2949. #define _FC_LINES_F __FC_LINES_F
  2950. #endif
  2951. #if LCD_HEIGHT > _FC_LINES_F + 1
  2952. STATIC_ITEM(" ");
  2953. #endif
  2954. HOTEND_STATUS_ITEM();
  2955. END_SCREEN();
  2956. }
  2957. void lcd_advanced_pause_extrude_message() {
  2958. START_SCREEN();
  2959. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2960. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  2961. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  2962. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  2963. #define __FC_LINES_G 3
  2964. #else
  2965. #define __FC_LINES_G 2
  2966. #endif
  2967. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  2968. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  2969. #define _FC_LINES_G (__FC_LINES_G + 1)
  2970. #else
  2971. #define _FC_LINES_G __FC_LINES_G
  2972. #endif
  2973. #if LCD_HEIGHT > _FC_LINES_G + 1
  2974. STATIC_ITEM(" ");
  2975. #endif
  2976. HOTEND_STATUS_ITEM();
  2977. END_SCREEN();
  2978. }
  2979. void lcd_advanced_pause_resume_message() {
  2980. START_SCREEN();
  2981. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2982. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  2983. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  2984. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  2985. #endif
  2986. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  2987. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  2988. #endif
  2989. END_SCREEN();
  2990. }
  2991. void lcd_advanced_pause_show_message(const AdvancedPauseMessage message) {
  2992. switch (message) {
  2993. case ADVANCED_PAUSE_MESSAGE_INIT:
  2994. defer_return_to_status = true;
  2995. lcd_goto_screen(lcd_advanced_pause_init_message);
  2996. break;
  2997. case ADVANCED_PAUSE_MESSAGE_UNLOAD:
  2998. defer_return_to_status = true;
  2999. lcd_goto_screen(lcd_advanced_pause_unload_message);
  3000. break;
  3001. case ADVANCED_PAUSE_MESSAGE_INSERT:
  3002. defer_return_to_status = true;
  3003. lcd_goto_screen(lcd_advanced_pause_insert_message);
  3004. break;
  3005. case ADVANCED_PAUSE_MESSAGE_LOAD:
  3006. defer_return_to_status = true;
  3007. lcd_goto_screen(lcd_advanced_pause_load_message);
  3008. break;
  3009. case ADVANCED_PAUSE_MESSAGE_EXTRUDE:
  3010. defer_return_to_status = true;
  3011. lcd_goto_screen(lcd_advanced_pause_extrude_message);
  3012. break;
  3013. case ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  3014. defer_return_to_status = true;
  3015. lcd_goto_screen(lcd_advanced_pause_heat_nozzle);
  3016. break;
  3017. case ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  3018. defer_return_to_status = true;
  3019. lcd_goto_screen(lcd_advanced_pause_wait_for_nozzles_to_heat);
  3020. break;
  3021. case ADVANCED_PAUSE_MESSAGE_OPTION:
  3022. defer_return_to_status = true;
  3023. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_WAIT_FOR;
  3024. lcd_goto_screen(lcd_advanced_pause_option_menu);
  3025. break;
  3026. case ADVANCED_PAUSE_MESSAGE_RESUME:
  3027. defer_return_to_status = true;
  3028. lcd_goto_screen(lcd_advanced_pause_resume_message);
  3029. break;
  3030. case ADVANCED_PAUSE_MESSAGE_STATUS:
  3031. lcd_return_to_status();
  3032. break;
  3033. }
  3034. }
  3035. #endif // ADVANCED_PAUSE_FEATURE
  3036. /**
  3037. *
  3038. * Functions for editing single values
  3039. *
  3040. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  3041. *
  3042. * For example, DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1) expands into these functions:
  3043. *
  3044. * bool _menu_edit_int3();
  3045. * void menu_edit_int3(); // edit int (interactively)
  3046. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  3047. * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  3048. * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  3049. * void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback, const bool live); // edit int with callback
  3050. *
  3051. * You can then use one of the menu macros to present the edit interface:
  3052. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  3053. *
  3054. * This expands into a more primitive menu item:
  3055. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3056. *
  3057. * ...which calls:
  3058. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3059. */
  3060. #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
  3061. bool _menu_edit_ ## _name() { \
  3062. ENCODER_DIRECTION_NORMAL(); \
  3063. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3064. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  3065. if (lcdDrawUpdate) \
  3066. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  3067. if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
  3068. _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  3069. if (editValue != NULL) *((_type*)editValue) = value; \
  3070. if (liveEdit) (*callbackFunc)(); \
  3071. if (lcd_clicked) lcd_goto_previous_menu(); \
  3072. } \
  3073. return lcd_clicked; \
  3074. } \
  3075. void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
  3076. void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
  3077. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  3078. lcd_save_previous_screen(); \
  3079. \
  3080. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  3081. \
  3082. editLabel = pstr; \
  3083. editValue = ptr; \
  3084. minEditValue = minValue * _scale; \
  3085. maxEditValue = maxValue * _scale - minEditValue; \
  3086. encoderPosition = (*ptr) * _scale - minEditValue; \
  3087. } \
  3088. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  3089. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3090. currentScreen = menu_edit_ ## _name; \
  3091. } \
  3092. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
  3093. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3094. currentScreen = menu_edit_callback_ ## _name; \
  3095. callbackFunc = callback; \
  3096. liveEdit = live; \
  3097. } \
  3098. typedef void _name
  3099. DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
  3100. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
  3101. DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
  3102. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
  3103. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01);
  3104. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
  3105. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
  3106. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
  3107. DEFINE_MENU_EDIT_TYPE(unsigned long, long5, ftostr5rj, 0.01);
  3108. /**
  3109. *
  3110. * Handlers for RepRap World Keypad input
  3111. *
  3112. */
  3113. #if ENABLED(REPRAPWORLD_KEYPAD)
  3114. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  3115. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  3116. encoderPosition = dir;
  3117. switch (axis) {
  3118. case X_AXIS: lcd_move_x(); break;
  3119. case Y_AXIS: lcd_move_y(); break;
  3120. case Z_AXIS: lcd_move_z();
  3121. default: break;
  3122. }
  3123. }
  3124. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  3125. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  3126. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  3127. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  3128. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  3129. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  3130. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  3131. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  3132. inline void handle_reprapworld_keypad() {
  3133. static uint8_t keypad_debounce = 0;
  3134. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  3135. if (keypad_debounce > 0) keypad_debounce--;
  3136. }
  3137. else if (!keypad_debounce) {
  3138. keypad_debounce = 2;
  3139. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  3140. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  3141. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3142. #endif
  3143. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  3144. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  3145. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3146. #endif
  3147. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  3148. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  3149. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  3150. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  3151. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  3152. }
  3153. else {
  3154. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  3155. }
  3156. }
  3157. }
  3158. #endif // REPRAPWORLD_KEYPAD
  3159. /**
  3160. *
  3161. * Menu actions
  3162. *
  3163. */
  3164. void _menu_action_back() { lcd_goto_previous_menu(); }
  3165. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  3166. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  3167. void menu_action_function(screenFunc_t func) { (*func)(); }
  3168. #if ENABLED(SDSUPPORT)
  3169. void menu_action_sdfile(const char* filename, char* longFilename) {
  3170. UNUSED(longFilename);
  3171. card.openAndPrintFile(filename);
  3172. lcd_return_to_status();
  3173. }
  3174. void menu_action_sddirectory(const char* filename, char* longFilename) {
  3175. UNUSED(longFilename);
  3176. card.chdir(filename);
  3177. encoderPosition = 0;
  3178. screen_changed = true;
  3179. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3180. }
  3181. #endif // SDSUPPORT
  3182. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  3183. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  3184. menu_action_setting_edit_bool(pstr, ptr);
  3185. (*callback)();
  3186. }
  3187. #endif // ULTIPANEL
  3188. void lcd_init() {
  3189. lcd_implementation_init(
  3190. #if ENABLED(LCD_PROGRESS_BAR)
  3191. true
  3192. #endif
  3193. );
  3194. #if ENABLED(NEWPANEL)
  3195. #if BUTTON_EXISTS(EN1)
  3196. SET_INPUT_PULLUP(BTN_EN1);
  3197. #endif
  3198. #if BUTTON_EXISTS(EN2)
  3199. SET_INPUT_PULLUP(BTN_EN2);
  3200. #endif
  3201. #if BUTTON_EXISTS(ENC)
  3202. SET_INPUT_PULLUP(BTN_ENC);
  3203. #endif
  3204. #if ENABLED(REPRAPWORLD_KEYPAD)
  3205. SET_OUTPUT(SHIFT_CLK);
  3206. OUT_WRITE(SHIFT_LD, HIGH);
  3207. SET_INPUT_PULLUP(SHIFT_OUT);
  3208. #endif
  3209. #if BUTTON_EXISTS(UP)
  3210. SET_INPUT(BTN_UP);
  3211. #endif
  3212. #if BUTTON_EXISTS(DWN)
  3213. SET_INPUT(BTN_DWN);
  3214. #endif
  3215. #if BUTTON_EXISTS(LFT)
  3216. SET_INPUT(BTN_LFT);
  3217. #endif
  3218. #if BUTTON_EXISTS(RT)
  3219. SET_INPUT(BTN_RT);
  3220. #endif
  3221. #else // !NEWPANEL
  3222. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  3223. SET_OUTPUT(SR_DATA_PIN);
  3224. SET_OUTPUT(SR_CLK_PIN);
  3225. #elif defined(SHIFT_CLK)
  3226. SET_OUTPUT(SHIFT_CLK);
  3227. OUT_WRITE(SHIFT_LD, HIGH);
  3228. OUT_WRITE(SHIFT_EN, LOW);
  3229. SET_INPUT_PULLUP(SHIFT_OUT);
  3230. #endif // SR_LCD_2W_NL
  3231. #endif // !NEWPANEL
  3232. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3233. SET_INPUT_PULLUP(SD_DETECT_PIN);
  3234. lcd_sd_status = 2; // UNKNOWN
  3235. #endif
  3236. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3237. slow_buttons = 0;
  3238. #endif
  3239. lcd_buttons_update();
  3240. #if ENABLED(ULTIPANEL)
  3241. encoderDiff = 0;
  3242. #endif
  3243. }
  3244. int lcd_strlen(const char* s) {
  3245. int i = 0, j = 0;
  3246. while (s[i]) {
  3247. #if ENABLED(MAPPER_NON)
  3248. j++;
  3249. #else
  3250. if ((s[i] & 0xC0u) != 0x80u) j++;
  3251. #endif
  3252. i++;
  3253. }
  3254. return j;
  3255. }
  3256. int lcd_strlen_P(const char* s) {
  3257. int j = 0;
  3258. while (pgm_read_byte(s)) {
  3259. #if ENABLED(MAPPER_NON)
  3260. j++;
  3261. #else
  3262. if ((pgm_read_byte(s) & 0xC0u) != 0x80u) j++;
  3263. #endif
  3264. s++;
  3265. }
  3266. return j;
  3267. }
  3268. bool lcd_blink() {
  3269. static uint8_t blink = 0;
  3270. static millis_t next_blink_ms = 0;
  3271. millis_t ms = millis();
  3272. if (ELAPSED(ms, next_blink_ms)) {
  3273. blink ^= 0xFF;
  3274. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  3275. }
  3276. return blink != 0;
  3277. }
  3278. /**
  3279. * Update the LCD, read encoder buttons, etc.
  3280. * - Read button states
  3281. * - Check the SD Card slot state
  3282. * - Act on RepRap World keypad input
  3283. * - Update the encoder position
  3284. * - Apply acceleration to the encoder position
  3285. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  3286. * - Reset the Info Screen timeout if there's any input
  3287. * - Update status indicators, if any
  3288. *
  3289. * Run the current LCD menu handler callback function:
  3290. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  3291. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  3292. * - Call the menu handler. Menu handlers should do the following:
  3293. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  3294. * (Encoder events automatically set lcdDrawUpdate for you.)
  3295. * - if (lcdDrawUpdate) { redraw }
  3296. * - Before exiting the handler set lcdDrawUpdate to:
  3297. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  3298. * - LCDVIEW_REDRAW_NOW to draw now (including remaining stripes).
  3299. * - LCDVIEW_CALL_REDRAW_NEXT to draw now and get LCDVIEW_REDRAW_NOW on the next loop.
  3300. * - LCDVIEW_CALL_NO_REDRAW to draw now and get LCDVIEW_NONE on the next loop.
  3301. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  3302. * so don't change lcdDrawUpdate without considering this.
  3303. *
  3304. * After the menu handler callback runs (or not):
  3305. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  3306. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  3307. *
  3308. * No worries. This function is only called from the main thread.
  3309. */
  3310. void lcd_update() {
  3311. #if ENABLED(ULTIPANEL)
  3312. static millis_t return_to_status_ms = 0;
  3313. manage_manual_move();
  3314. lcd_buttons_update();
  3315. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3316. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  3317. #else
  3318. constexpr bool UBL_CONDITION = true;
  3319. #endif
  3320. // If the action button is pressed...
  3321. if (UBL_CONDITION && LCD_CLICKED) {
  3322. if (!wait_for_unclick) { // If not waiting for a debounce release:
  3323. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  3324. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  3325. wait_for_user = false; // Any click clears wait for user
  3326. lcd_quick_feedback(); // Always make a click sound
  3327. }
  3328. }
  3329. else wait_for_unclick = false;
  3330. #endif
  3331. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3332. const bool sd_status = IS_SD_INSERTED;
  3333. if (sd_status != lcd_sd_status && lcd_detected()) {
  3334. if (sd_status) {
  3335. card.initsd();
  3336. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  3337. }
  3338. else {
  3339. card.release();
  3340. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  3341. }
  3342. lcd_sd_status = sd_status;
  3343. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3344. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3345. #if ENABLED(LCD_PROGRESS_BAR)
  3346. currentScreen == lcd_status_screen
  3347. #endif
  3348. );
  3349. }
  3350. #endif // SDSUPPORT && SD_DETECT_PIN
  3351. const millis_t ms = millis();
  3352. if (ELAPSED(ms, next_lcd_update_ms)
  3353. #if ENABLED(DOGLCD)
  3354. || drawing_screen
  3355. #endif
  3356. ) {
  3357. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  3358. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  3359. lcd_implementation_update_indicators();
  3360. #endif
  3361. #if ENABLED(ULTIPANEL)
  3362. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3363. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3364. #endif
  3365. #if ENABLED(REPRAPWORLD_KEYPAD)
  3366. handle_reprapworld_keypad();
  3367. #endif
  3368. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  3369. if (encoderPastThreshold || lcd_clicked) {
  3370. if (encoderPastThreshold) {
  3371. int32_t encoderMultiplier = 1;
  3372. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  3373. if (encoderRateMultiplierEnabled) {
  3374. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  3375. if (lastEncoderMovementMillis != 0) {
  3376. // Note that the rate is always calculated between to passes through the
  3377. // loop and that the abs of the encoderDiff value is tracked.
  3378. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  3379. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  3380. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  3381. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  3382. SERIAL_ECHO_START;
  3383. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3384. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3385. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3386. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3387. SERIAL_EOL;
  3388. #endif // ENCODER_RATE_MULTIPLIER_DEBUG
  3389. }
  3390. lastEncoderMovementMillis = ms;
  3391. } // encoderRateMultiplierEnabled
  3392. #endif // ENCODER_RATE_MULTIPLIER
  3393. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3394. encoderDiff = 0;
  3395. }
  3396. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3397. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3398. }
  3399. #endif // ULTIPANEL
  3400. // We arrive here every ~100ms when idling often enough.
  3401. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3402. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3403. if (
  3404. #if ENABLED(ULTIPANEL)
  3405. currentScreen == lcd_status_screen &&
  3406. #endif
  3407. !lcd_status_update_delay--
  3408. ) {
  3409. lcd_status_update_delay = 9
  3410. #if ENABLED(DOGLCD)
  3411. + 3
  3412. #endif
  3413. ;
  3414. max_display_update_time--;
  3415. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3416. }
  3417. // then we want to use 1/2 of the time only.
  3418. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3419. #if ENABLED(DOGLCD)
  3420. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3421. #else
  3422. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3423. #endif
  3424. {
  3425. #if ENABLED(DOGLCD)
  3426. if (!drawing_screen)
  3427. #endif
  3428. {
  3429. switch (lcdDrawUpdate) {
  3430. case LCDVIEW_CALL_NO_REDRAW:
  3431. lcdDrawUpdate = LCDVIEW_NONE;
  3432. break;
  3433. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3434. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3435. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3436. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3437. case LCDVIEW_NONE:
  3438. break;
  3439. } // switch
  3440. }
  3441. #if ENABLED(ULTIPANEL)
  3442. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3443. #else
  3444. #define CURRENTSCREEN() lcd_status_screen()
  3445. #endif
  3446. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3447. if (!drawing_screen) {
  3448. u8g.firstPage();
  3449. drawing_screen = 1;
  3450. }
  3451. lcd_setFont(FONT_MENU);
  3452. u8g.setColorIndex(1);
  3453. CURRENTSCREEN();
  3454. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3455. NOLESS(max_display_update_time, millis() - ms);
  3456. return;
  3457. }
  3458. #else
  3459. CURRENTSCREEN();
  3460. #endif
  3461. NOLESS(max_display_update_time, millis() - ms);
  3462. }
  3463. #if ENABLED(ULTIPANEL)
  3464. // Return to Status Screen after a timeout
  3465. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3466. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3467. else if (ELAPSED(ms, return_to_status_ms))
  3468. lcd_return_to_status();
  3469. #endif // ULTIPANEL
  3470. #if ENABLED(DOGLCD)
  3471. if (!drawing_screen)
  3472. #endif
  3473. {
  3474. switch (lcdDrawUpdate) {
  3475. case LCDVIEW_CLEAR_CALL_REDRAW:
  3476. lcd_implementation_clear();
  3477. case LCDVIEW_CALL_REDRAW_NEXT:
  3478. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3479. break;
  3480. case LCDVIEW_REDRAW_NOW:
  3481. lcdDrawUpdate = LCDVIEW_NONE;
  3482. break;
  3483. case LCDVIEW_NONE:
  3484. break;
  3485. } // switch
  3486. }
  3487. } // ELAPSED(ms, next_lcd_update_ms)
  3488. }
  3489. void set_utf_strlen(char* s, uint8_t n) {
  3490. uint8_t i = 0, j = 0;
  3491. while (s[i] && (j < n)) {
  3492. #if ENABLED(MAPPER_NON)
  3493. j++;
  3494. #else
  3495. if ((s[i] & 0xC0u) != 0x80u) j++;
  3496. #endif
  3497. i++;
  3498. }
  3499. while (j++ < n) s[i++] = ' ';
  3500. s[i] = '\0';
  3501. }
  3502. void lcd_finishstatus(bool persist=false) {
  3503. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  3504. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3505. UNUSED(persist);
  3506. #endif
  3507. #if ENABLED(LCD_PROGRESS_BAR)
  3508. progress_bar_ms = millis();
  3509. #if PROGRESS_MSG_EXPIRE > 0
  3510. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  3511. #endif
  3512. #endif
  3513. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3514. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  3515. previous_lcd_status_ms = millis(); //get status message to show up for a while
  3516. #endif
  3517. }
  3518. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  3519. void dontExpireStatus() { expire_status_ms = 0; }
  3520. #endif
  3521. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  3522. void lcd_setstatus(const char * const message, const bool persist) {
  3523. if (lcd_status_message_level > 0) return;
  3524. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  3525. lcd_finishstatus(persist);
  3526. }
  3527. void lcd_setstatuspgm(const char * const message, const uint8_t level) {
  3528. if (level < lcd_status_message_level) return;
  3529. lcd_status_message_level = level;
  3530. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  3531. lcd_finishstatus(level > 0);
  3532. }
  3533. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  3534. if (level < lcd_status_message_level) return;
  3535. lcd_status_message_level = level;
  3536. va_list args;
  3537. va_start(args, fmt);
  3538. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  3539. va_end(args);
  3540. lcd_finishstatus(level > 0);
  3541. }
  3542. void lcd_setalertstatuspgm(const char * const message) {
  3543. lcd_setstatuspgm(message, 1);
  3544. #if ENABLED(ULTIPANEL)
  3545. lcd_return_to_status();
  3546. #endif
  3547. }
  3548. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  3549. #if HAS_LCD_CONTRAST
  3550. void set_lcd_contrast(const uint16_t value) {
  3551. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  3552. u8g.setContrast(lcd_contrast);
  3553. }
  3554. #endif
  3555. #if ENABLED(ULTIPANEL)
  3556. /**
  3557. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  3558. * These values are independent of which pins are used for EN_A and EN_B indications
  3559. * The rotary encoder part is also independent to the chipset used for the LCD
  3560. */
  3561. #if defined(EN_A) && defined(EN_B)
  3562. #define encrot0 0
  3563. #define encrot1 2
  3564. #define encrot2 3
  3565. #define encrot3 1
  3566. #endif
  3567. #define GET_BUTTON_STATES(DST) \
  3568. uint8_t new_##DST = 0; \
  3569. WRITE(SHIFT_LD, LOW); \
  3570. WRITE(SHIFT_LD, HIGH); \
  3571. for (int8_t i = 0; i < 8; i++) { \
  3572. new_##DST >>= 1; \
  3573. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  3574. WRITE(SHIFT_CLK, HIGH); \
  3575. WRITE(SHIFT_CLK, LOW); \
  3576. } \
  3577. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  3578. /**
  3579. * Read encoder buttons from the hardware registers
  3580. * Warning: This function is called from interrupt context!
  3581. */
  3582. void lcd_buttons_update() {
  3583. static uint8_t lastEncoderBits;
  3584. millis_t now = millis();
  3585. if (ELAPSED(now, next_button_update_ms)) {
  3586. #if ENABLED(NEWPANEL)
  3587. uint8_t newbutton = 0;
  3588. #if BUTTON_EXISTS(EN1)
  3589. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  3590. #endif
  3591. #if BUTTON_EXISTS(EN2)
  3592. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  3593. #endif
  3594. #if BUTTON_EXISTS(ENC)
  3595. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  3596. #endif
  3597. #if LCD_HAS_DIRECTIONAL_BUTTONS
  3598. // Manage directional buttons
  3599. #if ENABLED(REVERSE_MENU_DIRECTION)
  3600. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  3601. #else
  3602. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  3603. #endif
  3604. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  3605. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  3606. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  3607. #else
  3608. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  3609. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  3610. #endif
  3611. if (false) {
  3612. // for the else-ifs below
  3613. }
  3614. #if BUTTON_EXISTS(UP)
  3615. else if (BUTTON_PRESSED(UP)) {
  3616. encoderDiff = -(ENCODER_UD_STEPS);
  3617. next_button_update_ms = now + 300;
  3618. }
  3619. #endif
  3620. #if BUTTON_EXISTS(DWN)
  3621. else if (BUTTON_PRESSED(DWN)) {
  3622. encoderDiff = ENCODER_UD_STEPS;
  3623. next_button_update_ms = now + 300;
  3624. }
  3625. #endif
  3626. #if BUTTON_EXISTS(LFT)
  3627. else if (BUTTON_PRESSED(LFT)) {
  3628. encoderDiff = -(ENCODER_LR_PULSES);
  3629. next_button_update_ms = now + 300;
  3630. }
  3631. #endif
  3632. #if BUTTON_EXISTS(RT)
  3633. else if (BUTTON_PRESSED(RT)) {
  3634. encoderDiff = ENCODER_LR_PULSES;
  3635. next_button_update_ms = now + 300;
  3636. }
  3637. #endif
  3638. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  3639. buttons = newbutton;
  3640. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3641. buttons |= slow_buttons;
  3642. #endif
  3643. #if ENABLED(REPRAPWORLD_KEYPAD)
  3644. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  3645. #endif
  3646. #else
  3647. GET_BUTTON_STATES(buttons);
  3648. #endif // !NEWPANEL
  3649. } // next_button_update_ms
  3650. // Manage encoder rotation
  3651. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  3652. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  3653. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  3654. #elif ENABLED(REVERSE_MENU_DIRECTION)
  3655. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  3656. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  3657. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  3658. #define ENCODER_DIFF_CW (encoderDiff--)
  3659. #define ENCODER_DIFF_CCW (encoderDiff++)
  3660. #else
  3661. #define ENCODER_DIFF_CW (encoderDiff++)
  3662. #define ENCODER_DIFF_CCW (encoderDiff--)
  3663. #endif
  3664. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  3665. uint8_t enc = 0;
  3666. if (buttons & EN_A) enc |= B01;
  3667. if (buttons & EN_B) enc |= B10;
  3668. if (enc != lastEncoderBits) {
  3669. switch (enc) {
  3670. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  3671. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  3672. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  3673. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  3674. }
  3675. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3676. if (ubl.has_control_of_lcd_panel) {
  3677. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  3678. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  3679. // knob has not turned.
  3680. }
  3681. #endif
  3682. lastEncoderBits = enc;
  3683. }
  3684. }
  3685. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  3686. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  3687. #else
  3688. bool lcd_detected() { return true; }
  3689. #endif
  3690. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3691. void chirp_at_user() {
  3692. #if ENABLED(LCD_USE_I2C_BUZZER)
  3693. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3694. #elif PIN_EXISTS(BEEPER)
  3695. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3696. #endif
  3697. }
  3698. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  3699. #endif
  3700. #endif // ULTIPANEL
  3701. #endif // ULTRA_LCD