My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 167KB

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