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

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