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

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