ultralcd.cpp 243 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681
  1. //! @file
  2. //! @date Aug 28, 2019
  3. //! @author mkbel
  4. //! @brief LCD
  5. #include "temperature.h"
  6. #include "ultralcd.h"
  7. #include "conv2str.h"
  8. #include "Marlin.h"
  9. #include "language.h"
  10. #include "cardreader.h"
  11. #include "fancheck.h"
  12. #include "stepper.h"
  13. #include "ConfigurationStore.h"
  14. #include "printers.h"
  15. #include <string.h>
  16. #include "lcd.h"
  17. #include "menu.h"
  18. #include "backlight.h"
  19. #include "util.h"
  20. #include "mesh_bed_leveling.h"
  21. #include "mesh_bed_calibration.h"
  22. //#include "Configuration.h"
  23. #include "cmdqueue.h"
  24. #include "Filament_sensor.h"
  25. #ifdef TMC2130
  26. #include "tmc2130.h"
  27. #endif //TMC2130
  28. #include "sound.h"
  29. #include "mmu2.h"
  30. #include "SpoolJoin.h"
  31. #include "static_assert.h"
  32. #include "first_lay_cal.h"
  33. #include "adc.h"
  34. #include "config.h"
  35. #ifndef LA_NOCOMPAT
  36. #include "la10compat.h"
  37. #endif
  38. #include "Prusa_farm.h"
  39. int clock_interval = 0;
  40. static void lcd_sd_updir();
  41. static void lcd_mesh_bed_leveling_settings();
  42. #ifdef LCD_BL_PIN
  43. static void lcd_backlight_menu();
  44. #endif
  45. int8_t ReInitLCD = 0;
  46. uint8_t scrollstuff = 0;
  47. int8_t SilentModeMenu = SILENT_MODE_OFF;
  48. uint8_t SilentModeMenu_MMU = 1; //activate mmu unit stealth mode
  49. int8_t FSensorStateMenu = 1;
  50. LcdCommands lcd_commands_type = LcdCommands::Idle;
  51. static uint8_t lcd_commands_step = 0;
  52. CustomMsg custom_message_type = CustomMsg::Status;
  53. uint8_t custom_message_state = 0;
  54. bool isPrintPaused = false;
  55. static ShortTimer display_time; //just timer for showing pid finished message on lcd;
  56. static uint16_t pid_temp = DEFAULT_PID_TEMP;
  57. static float manual_feedrate[] = MANUAL_FEEDRATE;
  58. /* LCD message status */
  59. static LongTimer lcd_status_message_timeout;
  60. static uint8_t lcd_status_message_level;
  61. static char lcd_status_message[LCD_WIDTH + 1];
  62. /* !Configuration settings */
  63. static uint8_t lay1cal_filament = 0;
  64. static const char separator[] PROGMEM = "--------------------";
  65. /** forward declarations **/
  66. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg);
  67. // void copy_and_scalePID_i();
  68. // void copy_and_scalePID_d();
  69. /* Different menus */
  70. //static void lcd_status_screen(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  71. #if (LANG_MODE != 0)
  72. static void lcd_language_menu();
  73. #endif
  74. static void lcd_main_menu();
  75. static void lcd_tune_menu();
  76. //static void lcd_move_menu();
  77. static void lcd_settings_menu();
  78. static void lcd_calibration_menu();
  79. static void lcd_control_temperature_menu();
  80. #ifdef TMC2130
  81. static void lcd_settings_linearity_correction_menu_save();
  82. #endif
  83. static void lcd_menu_xyz_y_min();
  84. static void lcd_menu_xyz_skew();
  85. static void lcd_menu_xyz_offset();
  86. static void lcd_menu_fails_stats_mmu();
  87. static void lcd_menu_fails_stats_mmu_print();
  88. static void lcd_menu_fails_stats_mmu_total();
  89. static void lcd_menu_toolchange_stats_mmu_total();
  90. static void mmu_unload_filament();
  91. static void lcd_v2_calibration();
  92. //static void lcd_menu_show_sensors_state(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  93. static void mmu_fil_eject_menu();
  94. static void mmu_load_to_nozzle_menu();
  95. static void mmu_loading_test_menu();
  96. static void preheat_or_continue();
  97. #ifdef MMU_HAS_CUTTER
  98. static void mmu_cut_filament_menu();
  99. #endif //MMU_HAS_CUTTER
  100. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  101. static void lcd_menu_fails_stats();
  102. #endif //TMC2130 or FILAMENT_SENSOR
  103. #ifdef TMC2130
  104. static void lcd_belttest_v();
  105. #endif //TMC2130
  106. static void lcd_selftest_v();
  107. #ifdef TMC2130
  108. static void reset_crash_det(uint8_t axis);
  109. static bool lcd_selfcheck_axis_sg(uint8_t axis);
  110. #else
  111. static bool lcd_selfcheck_axis(int _axis, int _travel);
  112. static bool lcd_selfcheck_pulleys(int axis);
  113. #endif //TMC2130
  114. static bool lcd_selfcheck_endstops();
  115. static bool lcd_selfcheck_check_heater(bool _isbed);
  116. enum class TestScreen : uint_least8_t
  117. {
  118. ExtruderFan,
  119. PrintFan,
  120. FansOk,
  121. EndStops,
  122. AxisX,
  123. AxisY,
  124. AxisZ,
  125. Bed,
  126. Hotend,
  127. HotendOk,
  128. Fsensor,
  129. FsensorOk,
  130. AllCorrect,
  131. Failed,
  132. Home,
  133. };
  134. enum class TestError : uint_least8_t
  135. {
  136. Heater,
  137. Bed,
  138. Endstops,
  139. Motor,
  140. Endstop,
  141. PrintFan,
  142. ExtruderFan,
  143. Pulley,
  144. Axis,
  145. SwappedFan,
  146. WiringFsensor,
  147. TriggeringFsensor,
  148. FsensorLevel
  149. };
  150. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay);
  151. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name, const char *_indicator);
  152. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  153. bool _default=false);
  154. #ifdef FANCHECK
  155. /** Enumerate for lcd_selftest_fan_auto function.
  156. */
  157. enum class FanCheck : uint_least8_t {
  158. Success,
  159. PrintFan,
  160. ExtruderFan,
  161. SwappedFan,
  162. };
  163. /**
  164. * Try to check fan working and wiring.
  165. *
  166. * @param _fan i fan number 0 means hotend fan, 1 means print fan.
  167. *
  168. * @returns a TestError noerror, extruderFan, printFan or swappedFan.
  169. */
  170. static FanCheck lcd_selftest_fan_auto(uint8_t _fan);
  171. #endif //FANCHECK
  172. #ifdef FILAMENT_SENSOR
  173. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  174. static bool lcd_selftest_fsensor();
  175. #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR
  176. static bool selftest_irsensor();
  177. #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG
  178. static bool selftest_irsensor();
  179. static bool lcd_selftest_IRsensor(bool bStandalone=false);
  180. static void lcd_detect_IRsensor();
  181. #endif
  182. #endif //FILAMENT_SENSOR
  183. static void lcd_selftest_error(TestError error, const char *_error_1, const char *_error_2);
  184. static void lcd_colorprint_change();
  185. static void lcd_disable_farm_mode();
  186. static void lcd_set_fan_check();
  187. #ifdef MMU_HAS_CUTTER
  188. static void lcd_cutter_enabled();
  189. #endif
  190. #ifdef SDCARD_SORT_ALPHA
  191. static void lcd_sort_type_set();
  192. #endif
  193. static void lcd_babystep_z();
  194. static void lcd_sdcard_menu();
  195. static void lcd_sheet_menu();
  196. #ifdef DELTA_CALIBRATION_MENU
  197. static void lcd_delta_calibrate_menu();
  198. #endif // DELTA_CALIBRATION_MENU
  199. /* Different types of actions that can be used in menu items. */
  200. static void menu_action_sdfile(const char* filename);
  201. static void menu_action_sddirectory(const char* filename);
  202. #define ENCODER_FEEDRATE_DEADZONE 10
  203. #define STATE_NA 255
  204. #define STATE_OFF 0
  205. #define STATE_ON 1
  206. /*
  207. #define MENU_ITEM(type, label, args...) do { \
  208. if (menu_item == menu_line) { \
  209. if (lcd_draw_update) { \
  210. const char* _label_pstr = (label); \
  211. if (lcd_encoder == menu_item) { \
  212. lcd_implementation_drawmenu_ ## type ## _selected (menu_row, _label_pstr , ## args ); \
  213. }else{\
  214. lcd_implementation_drawmenu_ ## type (menu_row, _label_pstr , ## args ); \
  215. }\
  216. }\
  217. if (menu_clicked && (lcd_encoder == menu_item)) {\
  218. lcd_quick_feedback(); \
  219. menu_action_ ## type ( args ); \
  220. return;\
  221. }\
  222. }\
  223. menu_item++;\
  224. } while(0)
  225. */
  226. #if (SDCARDDETECT > 0)
  227. bool lcd_oldcardstatus;
  228. #endif
  229. uint8_t selected_sheet = 0;
  230. bool ignore_click = false;
  231. bool wait_for_unclick;
  232. // place-holders for Ki and Kd edits
  233. #ifdef PIDTEMP
  234. // float raw_Ki, raw_Kd;
  235. #endif
  236. bool bMain; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  237. bool bSettings; // flag (i.e. 'fake parameter') for 'lcd_hw_setup_menu()' function
  238. const char STR_SEPARATOR[] PROGMEM = "------------";
  239. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* longFilename)
  240. {
  241. uint8_t len = LCD_WIDTH - 1;
  242. lcd_set_cursor(0, row);
  243. lcd_print((lcd_encoder == menu_item)?'>':' ');
  244. lcd_print_pad(longFilename, len);
  245. }
  246. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* longFilename)
  247. {
  248. uint8_t len = LCD_WIDTH - 2;
  249. lcd_set_cursor(0, row);
  250. lcd_print((lcd_encoder == menu_item)?'>':' ');
  251. lcd_print(LCD_STR_FOLDER[0]);
  252. lcd_print_pad(longFilename, len);
  253. }
  254. #define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0)
  255. #define MENU_ITEM_SDFILE(str_fn, str_fnl) do { if (menu_item_sdfile(str_fn, str_fnl)) return; } while (0)
  256. uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
  257. {
  258. if (menu_item == menu_line)
  259. {
  260. if (lcd_draw_update)
  261. {
  262. lcd_implementation_drawmenu_sddirectory(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  263. }
  264. if (menu_clicked && (lcd_encoder == menu_item))
  265. {
  266. menu_clicked = false;
  267. lcd_consume_click();
  268. lcd_update_enabled = false;
  269. menu_action_sddirectory(str_fn);
  270. lcd_update_enabled = true;
  271. return menu_item_ret();
  272. }
  273. }
  274. menu_item++;
  275. return 0;
  276. }
  277. static uint8_t menu_item_sdfile(const char* str_fn, char* str_fnl)
  278. {
  279. if (menu_item == menu_line)
  280. {
  281. if (lcd_draw_update)
  282. {
  283. lcd_implementation_drawmenu_sdfile(menu_row, (str_fnl[0] == '\0') ? str_fn : str_fnl);
  284. }
  285. if (menu_clicked && (lcd_encoder == menu_item))
  286. {
  287. menu_clicked = false;
  288. lcd_consume_click();
  289. lcd_update_enabled = false;
  290. menu_action_sdfile(str_fn);
  291. lcd_update_enabled = true;
  292. return menu_item_ret();
  293. }
  294. }
  295. menu_item++;
  296. return 0;
  297. }
  298. // Print temperature (nozzle/bed) (9 chars total)
  299. void lcdui_print_temp(char type, int val_current, int val_target)
  300. {
  301. int chars = lcd_printf_P(_N("%c%3d/%d%c"), type, val_current, val_target, LCD_STR_DEGREE[0]);
  302. lcd_space(9 - chars);
  303. }
  304. // Print Z-coordinate (8 chars total)
  305. void lcdui_print_Z_coord(void)
  306. {
  307. if (custom_message_type == CustomMsg::MeshBedLeveling)
  308. lcd_puts_P(_N("Z --- "));
  309. else
  310. lcd_printf_P(_N("Z%6.2f%c"), current_position[Z_AXIS], axis_known_position[Z_AXIS]?' ':'?');
  311. }
  312. #ifdef PLANNER_DIAGNOSTICS
  313. // Print planner diagnostics (8 chars total)
  314. void lcdui_print_planner_diag(void)
  315. {
  316. lcd_set_cursor(LCD_WIDTH - 8-2, 1);
  317. lcd_print(LCD_STR_FEEDRATE[0]);
  318. lcd_print(itostr3(feedmultiply));
  319. lcd_puts_P(PSTR("% Q"));
  320. {
  321. uint8_t queue = planner_queue_min();
  322. if (queue < (BLOCK_BUFFER_SIZE >> 1))
  323. lcd_putc('!');
  324. else
  325. {
  326. lcd_putc((char)(queue / 10) + '0');
  327. queue %= 10;
  328. }
  329. lcd_putc((char)queue + '0');
  330. planner_queue_min_reset();
  331. }
  332. }
  333. #endif // PLANNER_DIAGNOSTICS
  334. // Print feedrate (8 chars total)
  335. void lcdui_print_feedrate(void)
  336. {
  337. int chars = lcd_printf_P(_N("%c%3d%%"), LCD_STR_FEEDRATE[0], feedmultiply);
  338. lcd_space(8 - chars);
  339. }
  340. // Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total)
  341. void lcdui_print_percent_done(void)
  342. {
  343. const char* src = usb_timer.running()?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
  344. char per[4];
  345. bool num = IS_SD_PRINTING || (printer_active() && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
  346. if (!num || heating_status != HeatingStatus::NO_HEATING) // either not printing or heating
  347. {
  348. const int8_t sheetNR = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  349. const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR);
  350. if ((nextSheet >= 0) && (sheetNR != nextSheet))
  351. {
  352. char sheet[8];
  353. eeprom_read_block(sheet, EEPROM_Sheets_base->s[sheetNR].name, 7);
  354. sheet[7] = '\0';
  355. lcd_printf_P(PSTR("%-7s"),sheet);
  356. return; //do not also print the percentage
  357. }
  358. }
  359. sprintf_P(per, num?_N("%3d"):_N("---"), calc_percent_done());
  360. lcd_printf_P(_N("%3S%3s%%"), src, per);
  361. }
  362. // Print extruder status (5 chars total)
  363. // Scenario 1: "F?"
  364. // There is no filament loaded and no tool change is in progress
  365. // Scenario 2: "F[nr.]"
  366. // [nr.] ranges from 1 to 5.
  367. // Shows which filament is loaded. No tool change is in progress
  368. // Scenario 3: "?>[nr.]"
  369. // [nr.] ranges from 1 to 5.
  370. // There is no filament currently loaded, but [nr.] is currently being loaded via tool change
  371. // Scenario 4: "[nr.]>?"
  372. // [nr.] ranges from 1 to 5.
  373. // This scenario indicates a bug in the firmware if ? is on the right side
  374. // Scenario 5: "[nr1.]>[nr2.]"
  375. // [nr1.] ranges from 1 to 5.
  376. // [nr2.] ranges from 1 to 5.
  377. // Filament [nr1.] was loaded, but [nr2.] is currently being loaded via tool change
  378. // Scenario 6: "?>?"
  379. // This scenario should not be possible and indicates a bug in the firmware
  380. uint8_t lcdui_print_extruder(void) {
  381. uint8_t chars = 1;
  382. lcd_space(1);
  383. if (MMU2::mmu2.get_current_tool() == MMU2::mmu2.get_tool_change_tool()) {
  384. lcd_putc('F');
  385. lcd_putc(MMU2::mmu2.get_current_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN ? '?' : MMU2::mmu2.get_current_tool() + '1');
  386. chars += 2;
  387. } else {
  388. lcd_putc(MMU2::mmu2.get_current_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN ? '?' : MMU2::mmu2.get_current_tool() + '1');
  389. lcd_putc('>');
  390. lcd_putc(MMU2::mmu2.get_tool_change_tool() == (uint8_t)MMU2::FILAMENT_UNKNOWN ? '?' : MMU2::mmu2.get_tool_change_tool() + '1');
  391. chars += 3;
  392. }
  393. return chars;
  394. }
  395. // Print farm number (5 chars total)
  396. static void lcdui_print_farm(void)
  397. {
  398. lcd_printf_P(_N(" FRM "));
  399. }
  400. #ifdef CMD_DIAGNOSTICS
  401. // Print CMD queue diagnostic (8 chars total)
  402. void lcdui_print_cmd_diag(void)
  403. {
  404. lcd_set_cursor(LCD_WIDTH - 8 -1, 2);
  405. lcd_puts_P(PSTR(" C"));
  406. lcd_print(buflen); // number of commands in cmd buffer
  407. if (buflen < 9) lcd_print(' ');
  408. }
  409. #endif //CMD_DIAGNOSTICS
  410. // Print time (8 chars total)
  411. void lcdui_print_time(void)
  412. {
  413. //if remaining print time estimation is available print it else print elapsed time
  414. int chars = 0;
  415. if (printer_active()) {
  416. uint16_t print_t = PRINT_TIME_REMAINING_INIT;
  417. uint16_t print_tr = PRINT_TIME_REMAINING_INIT;
  418. uint16_t print_tc = PRINT_TIME_REMAINING_INIT;
  419. char suff = ' ';
  420. char suff_doubt = ' ';
  421. #ifdef TMC2130
  422. if (SilentModeMenu != SILENT_MODE_OFF) {
  423. if (print_time_remaining_silent != PRINT_TIME_REMAINING_INIT)
  424. print_tr = print_time_remaining_silent;
  425. //#ifdef CLOCK_INTERVAL_TIME
  426. if (print_time_to_change_silent != PRINT_TIME_REMAINING_INIT)
  427. print_tc = print_time_to_change_silent;
  428. //#endif //CLOCK_INTERVAL_TIME
  429. } else {
  430. #endif //TMC2130
  431. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  432. print_tr = print_time_remaining_normal;
  433. //#ifdef CLOCK_INTERVAL_TIME
  434. if (print_time_to_change_normal != PRINT_TIME_REMAINING_INIT)
  435. print_tc = print_time_to_change_normal;
  436. //#endif //CLOCK_INTERVAL_TIME
  437. #ifdef TMC2130
  438. }
  439. #endif //TMC2130
  440. //#ifdef CLOCK_INTERVAL_TIME
  441. if (clock_interval == CLOCK_INTERVAL_TIME*2)
  442. clock_interval = 0;
  443. clock_interval++;
  444. if (print_tc != PRINT_TIME_REMAINING_INIT && clock_interval > CLOCK_INTERVAL_TIME) {
  445. print_t = print_tc;
  446. suff = 'C';
  447. } else
  448. //#endif //CLOCK_INTERVAL_TIME
  449. if (print_tr != PRINT_TIME_REMAINING_INIT) {
  450. print_t = print_tr;
  451. suff = 'R';
  452. } else
  453. print_t = _millis() / 60000 - starttime / 60000;
  454. if (feedmultiply != 100 && (print_t == print_tr || print_t == print_tc)) {
  455. suff_doubt = '?';
  456. print_t = 100ul * print_t / feedmultiply;
  457. }
  458. if (print_t < 6000) //time<100h
  459. chars = lcd_printf_P(_N("%c%02u:%02u%c%c"), LCD_STR_CLOCK[0], print_t / 60, print_t % 60, suff, suff_doubt);
  460. else //time>=100h
  461. chars = lcd_printf_P(_N("%c%3uh %c%c"), LCD_STR_CLOCK[0], print_t / 60, suff, suff_doubt);
  462. }
  463. else
  464. chars = lcd_printf_P(_N("%c--:-- "), LCD_STR_CLOCK[0]);
  465. lcd_space(8 - chars);
  466. }
  467. //! @Brief Print status line on status screen
  468. void lcdui_print_status_line(void) {
  469. if (heating_status != HeatingStatus::NO_HEATING) { // If heating flag, show progress of heating
  470. heating_status_counter++;
  471. if (heating_status_counter > 13) {
  472. heating_status_counter = 0;
  473. }
  474. lcd_set_cursor(7, 3);
  475. lcd_space(13);
  476. for (uint8_t dots = 0; dots < heating_status_counter; dots++) {
  477. lcd_putc_at(7 + dots, 3, '.');
  478. }
  479. switch (heating_status) {
  480. case HeatingStatus::EXTRUDER_HEATING:
  481. lcd_puts_at_P(0, 3, _T(MSG_HEATING));
  482. break;
  483. case HeatingStatus::EXTRUDER_HEATING_COMPLETE:
  484. lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE));
  485. heating_status = HeatingStatus::NO_HEATING;
  486. heating_status_counter = 0;
  487. break;
  488. case HeatingStatus::BED_HEATING:
  489. lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING));
  490. break;
  491. case HeatingStatus::BED_HEATING_COMPLETE:
  492. lcd_puts_at_P(0, 3, _T(MSG_BED_DONE));
  493. heating_status = HeatingStatus::NO_HEATING;
  494. heating_status_counter = 0;
  495. break;
  496. default:
  497. break;
  498. }
  499. }
  500. else if ((IS_SD_PRINTING) &&
  501. (custom_message_type == CustomMsg::Status) &&
  502. (lcd_status_message_level <= LCD_STATUS_INFO) &&
  503. lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT))
  504. {
  505. // If printing from SD, show what we are printing
  506. const char* longFilenameOLD = (card.longFilename[0] ? card.longFilename : card.filename);
  507. if( lcd_print_pad(&longFilenameOLD[scrollstuff], LCD_WIDTH) )
  508. {
  509. scrollstuff++;
  510. } else {
  511. scrollstuff = 0;
  512. }
  513. } else { // Otherwise check for other special events
  514. switch (custom_message_type) {
  515. case CustomMsg::M117: // M117 Set the status line message on the LCD
  516. case CustomMsg::Status: // Nothing special, print status message normally
  517. case CustomMsg::M0Wait: // M0/M1 Wait command working even from SD
  518. case CustomMsg::FilamentLoading: // If loading filament, print status
  519. case CustomMsg::MMUProgress: // MMU Progress Codes
  520. lcd_print_pad(lcd_status_message, LCD_WIDTH);
  521. break;
  522. case CustomMsg::MeshBedLeveling: // If mesh bed leveling in progress, show the status
  523. if (custom_message_state > 10) {
  524. lcd_set_cursor(0, 3);
  525. lcd_space(LCD_WIDTH);
  526. lcd_puts_at_P(0, 3, _T(MSG_CALIBRATE_Z_AUTO));
  527. lcd_puts_P(PSTR(" : "));
  528. lcd_print(custom_message_state - 10);
  529. } else {
  530. if (custom_message_state == 3) {
  531. lcd_setstatuspgm(MSG_WELCOME);
  532. custom_message_type = CustomMsg::Status;
  533. }
  534. if (custom_message_state > 3 && custom_message_state <= 10) {
  535. lcd_set_cursor(0, 3);
  536. lcd_space(19);
  537. lcd_puts_at_P(0, 3, _i("Calibration done")); ////MSG_HOMEYZ_DONE c=20
  538. custom_message_state--;
  539. }
  540. }
  541. break;
  542. case CustomMsg::PidCal: // PID tuning in progress
  543. lcd_print_pad(lcd_status_message, LCD_WIDTH);
  544. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) {
  545. lcd_set_cursor(10, 3);
  546. lcd_print(itostr3(pid_cycle));
  547. lcd_print('/');
  548. lcd_print(itostr3left(pid_number_of_cycles));
  549. }
  550. break;
  551. case CustomMsg::TempCal: // PINDA temp calibration in progress
  552. lcd_set_cursor(0, 3);
  553. lcd_printf_P(PSTR("%-12.12S%-d/6"), _T(MSG_PINDA_CALIBRATION), custom_message_state);
  554. break;
  555. case CustomMsg::TempCompPreheat: // temp compensation preheat
  556. lcd_puts_at_P(0, 3, _i("PINDA Heating")); ////MSG_PINDA_PREHEAT c=20
  557. if (custom_message_state <= PINDA_HEAT_T) {
  558. lcd_puts_P(PSTR(": "));
  559. lcd_print(custom_message_state); // seconds
  560. lcd_print(' ');
  561. }
  562. break;
  563. case CustomMsg::Resuming: // Resuming
  564. lcd_puts_at_P(0, 3, _T(MSG_RESUMING_PRINT));
  565. break;
  566. }
  567. }
  568. }
  569. //! @brief Show Status Screen
  570. //!
  571. //! @code{.unparsed}
  572. //! |01234567890123456789|
  573. //! |N 000/000D Z000.0 |
  574. //! |B 000/000D F100% |
  575. //! |USB100% T0 t--:-- |
  576. //! |Status line.........|
  577. //! ----------------------
  578. //! N - nozzle temp symbol LCD_STR_THERMOMETER
  579. //! D - Degree sysmbol LCD_STR_DEGREE
  580. //! B - bed temp symbol LCD_STR_BEDTEMP
  581. //! F - feedrate symbol LCD_STR_FEEDRATE
  582. //! t - clock symbol LCD_STR_THERMOMETER
  583. //! @endcode
  584. void lcdui_print_status_screen(void)
  585. {
  586. lcd_set_cursor(0, 0); //line 0
  587. //Print the hotend temperature (9 chars total)
  588. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  589. lcd_space(3); //3 spaces
  590. //Print Z-coordinate (8 chars total)
  591. lcdui_print_Z_coord();
  592. lcd_set_cursor(0, 1); //line 1
  593. //Print the Bed temperature (9 chars total)
  594. lcdui_print_temp(LCD_STR_BEDTEMP[0], (int)(degBed() + 0.5), (int)(degTargetBed() + 0.5));
  595. lcd_space(3); //3 spaces
  596. #ifdef PLANNER_DIAGNOSTICS
  597. //Print planner diagnostics (8 chars)
  598. lcdui_print_planner_diag();
  599. #else // PLANNER_DIAGNOSTICS
  600. //Print Feedrate (8 chars)
  601. lcdui_print_feedrate();
  602. #endif // PLANNER_DIAGNOSTICS
  603. lcd_set_cursor(0, 2); //line 2
  604. //Print SD status (7 chars)
  605. lcdui_print_percent_done();
  606. if (MMU2::mmu2.Enabled()) {
  607. // Print extruder status (5 chars)
  608. lcd_space(5 - lcdui_print_extruder());
  609. } else if (farm_mode) {
  610. // Print farm number (5 chars)
  611. lcdui_print_farm();
  612. } else {
  613. lcd_space(5); // 5 spaces
  614. }
  615. #ifdef CMD_DIAGNOSTICS
  616. //Print cmd queue diagnostics (8chars)
  617. lcdui_print_cmd_diag();
  618. #else
  619. //Print time (8chars)
  620. lcdui_print_time();
  621. #endif //CMD_DIAGNOSTICS
  622. lcd_set_cursor(0, 3); //line 3
  623. #ifndef DEBUG_DISABLE_LCD_STATUS_LINE
  624. lcdui_print_status_line();
  625. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  626. }
  627. // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent
  628. void lcd_status_screen() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  629. {
  630. static uint8_t lcd_status_update_delay = 0;
  631. #ifdef ULTIPANEL_FEEDMULTIPLY
  632. // Dead zone at 100% feedrate
  633. if ((feedmultiply < 100 && (feedmultiply + int(lcd_encoder)) > 100) ||
  634. (feedmultiply > 100 && (feedmultiply + int(lcd_encoder)) < 100))
  635. {
  636. lcd_encoder = 0;
  637. feedmultiply = 100;
  638. }
  639. if (feedmultiply == 100 && int(lcd_encoder) > ENCODER_FEEDRATE_DEADZONE)
  640. {
  641. feedmultiply += int(lcd_encoder) - ENCODER_FEEDRATE_DEADZONE;
  642. lcd_encoder = 0;
  643. }
  644. else if (feedmultiply == 100 && int(lcd_encoder) < -ENCODER_FEEDRATE_DEADZONE)
  645. {
  646. feedmultiply += int(lcd_encoder) + ENCODER_FEEDRATE_DEADZONE;
  647. lcd_encoder = 0;
  648. }
  649. else if (feedmultiply != 100)
  650. {
  651. feedmultiply += int(lcd_encoder);
  652. lcd_encoder = 0;
  653. }
  654. #endif //ULTIPANEL_FEEDMULTIPLY
  655. if (feedmultiply < 10)
  656. feedmultiply = 10;
  657. else if (feedmultiply > 999)
  658. feedmultiply = 999;
  659. if (lcd_draw_update) {
  660. // Update the status screen immediately
  661. lcd_status_update_delay = 0;
  662. }
  663. if (lcd_status_update_delay)
  664. lcd_status_update_delay--;
  665. else
  666. { // Redraw the main screen every second (see LCD_UPDATE_INTERVAL).
  667. // This is easier then trying keep track of all things that change on the screen
  668. lcd_status_update_delay = 10;
  669. ReInitLCD++;
  670. if (ReInitLCD == 30)
  671. {
  672. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  673. ReInitLCD = 0 ;
  674. }
  675. else
  676. {
  677. if ((ReInitLCD % 10) == 0)
  678. lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
  679. }
  680. lcdui_print_status_screen();
  681. prusa_statistics_update_from_status_screen();
  682. if (lcd_commands_type != LcdCommands::Idle)
  683. lcd_commands();
  684. }
  685. bool current_click = LCD_CLICKED;
  686. if (ignore_click)
  687. {
  688. if (wait_for_unclick)
  689. {
  690. if (!current_click)
  691. ignore_click = wait_for_unclick = false;
  692. else
  693. current_click = false;
  694. }
  695. else if (current_click)
  696. {
  697. lcd_quick_feedback();
  698. wait_for_unclick = true;
  699. current_click = false;
  700. }
  701. }
  702. if (current_click
  703. && ( menu_block_mask == MENU_BLOCK_NONE ) // or a serious error blocks entering the menu
  704. )
  705. {
  706. menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
  707. menu_submenu(lcd_main_menu);
  708. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  709. }
  710. }
  711. void print_stop();
  712. void lcd_commands()
  713. {
  714. if (planner_aborted) {
  715. // we are still within an aborted command. do not process any LCD command until we return
  716. return;
  717. }
  718. if (lcd_commands_type == LcdCommands::StopPrint)
  719. {
  720. if (!blocks_queued() && !homing_flag)
  721. {
  722. custom_message_type = CustomMsg::Status;
  723. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  724. lcd_commands_type = LcdCommands::Idle;
  725. lcd_commands_step = 0;
  726. print_stop();
  727. }
  728. }
  729. if (lcd_commands_type == LcdCommands::LongPause)
  730. {
  731. if (!blocks_queued() && !homing_flag)
  732. {
  733. if (custom_message_type != CustomMsg::M117)
  734. {
  735. custom_message_type = CustomMsg::Status;
  736. lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20
  737. }
  738. lcd_commands_type = LcdCommands::Idle;
  739. lcd_commands_step = 0;
  740. long_pause();
  741. }
  742. }
  743. if (lcd_commands_type == LcdCommands::Layer1Cal)
  744. {
  745. char cmd1[30];
  746. if(lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  747. if (!blocks_queued() && cmd_buffer_empty() && !saved_printing)
  748. {
  749. switch(lcd_commands_step)
  750. {
  751. case 0:
  752. lcd_commands_step = 11;
  753. break;
  754. case 11:
  755. lay1cal_wait_preheat();
  756. lcd_commands_step = 10;
  757. break;
  758. case 10:
  759. lay1cal_load_filament(cmd1, lay1cal_filament);
  760. lcd_commands_step = 9;
  761. break;
  762. case 9:
  763. lcd_clear();
  764. menu_depth = 0;
  765. menu_submenu(lcd_babystep_z);
  766. lay1cal_intro_line();
  767. lcd_commands_step = 8;
  768. break;
  769. case 8:
  770. lay1cal_before_meander();
  771. lcd_commands_step = 7;
  772. break;
  773. case 7:
  774. lay1cal_meander(cmd1);
  775. lcd_commands_step = 6;
  776. break;
  777. case 6:
  778. for (uint8_t i = 0; i < 4; i++)
  779. {
  780. lay1cal_square(cmd1, i);
  781. }
  782. lcd_commands_step = 5;
  783. break;
  784. case 5:
  785. for (uint8_t i = 4; i < 8; i++)
  786. {
  787. lay1cal_square(cmd1, i);
  788. }
  789. lcd_commands_step = 4;
  790. break;
  791. case 4:
  792. for (uint8_t i = 8; i < 12; i++)
  793. {
  794. lay1cal_square(cmd1, i);
  795. }
  796. lcd_commands_step = 3;
  797. break;
  798. case 3:
  799. for (uint8_t i = 12; i < 16; i++)
  800. {
  801. lay1cal_square(cmd1, i);
  802. }
  803. lcd_commands_step = 2;
  804. break;
  805. case 2:
  806. enquecommand_P(PSTR("M107")); //turn off printer fan
  807. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract
  808. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  809. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  810. enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z
  811. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position
  812. if (MMU2::mmu2.Enabled()) enquecommand_P(PSTR("M702")); //unload from nozzle
  813. enquecommand_P(PSTR("M84"));// disable motors
  814. lcd_return_to_status(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  815. lcd_commands_step = 1;
  816. break;
  817. case 1:
  818. lcd_setstatuspgm(MSG_WELCOME);
  819. lcd_commands_step = 0;
  820. lcd_commands_type = LcdCommands::Idle;
  821. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1)
  822. {
  823. lcd_wizard(WizState::RepeatLay1Cal);
  824. }
  825. break;
  826. }
  827. }
  828. }
  829. if (lcd_commands_type == LcdCommands::PidExtruder) {
  830. char cmd1[30];
  831. if (lcd_commands_step == 0) {
  832. custom_message_type = CustomMsg::PidCal;
  833. custom_message_state = 1;
  834. lcd_draw_update = 3;
  835. lcd_commands_step = 3;
  836. }
  837. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  838. preparePidTuning(); // ensure we don't move to the next step early
  839. sprintf_P(cmd1, PSTR("M303 E0 S%3u"), pid_temp);
  840. // setting the correct target temperature (for visualization) is done in PID_autotune
  841. enquecommand(cmd1);
  842. lcd_setstatuspgm(_i("PID cal."));////MSG_PID_RUNNING c=20
  843. lcd_commands_step = 2;
  844. }
  845. if (lcd_commands_step == 2 && !pidTuningRunning()) { //saving to eeprom
  846. custom_message_state = 0;
  847. lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20
  848. setAllTargetHotends(0); // reset all hotends temperature including the number displayed on the main screen
  849. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  850. sprintf_P(cmd1, PSTR("M301 P%.2f I%.2f D%.2f"), _Kp, _Ki, _Kd);
  851. enquecommand(cmd1);
  852. enquecommand_P(PSTR("M500"));
  853. }
  854. else {
  855. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  856. }
  857. display_time.start();
  858. lcd_commands_step = 1;
  859. }
  860. if ((lcd_commands_step == 1) && display_time.expired(2000)) { //calibration finished message
  861. lcd_setstatuspgm(MSG_WELCOME);
  862. custom_message_type = CustomMsg::Status;
  863. pid_temp = DEFAULT_PID_TEMP;
  864. lcd_commands_step = 0;
  865. lcd_commands_type = LcdCommands::Idle;
  866. }
  867. }
  868. #ifdef TEMP_MODEL
  869. if (lcd_commands_type == LcdCommands::TempModel) {
  870. if (lcd_commands_step == 0) {
  871. lcd_commands_step = 3;
  872. }
  873. if (lcd_commands_step == 3) {
  874. enquecommand_P(PSTR("M310 A F0"));
  875. lcd_commands_step = 2;
  876. }
  877. if (lcd_commands_step ==2 && temp_model_valid()) {
  878. enquecommand_P(PSTR("M310 S1"));
  879. lcd_commands_step = 1;
  880. }
  881. //if (lcd_commands_step == 1 && calibrated()) {
  882. if (lcd_commands_step == 1 && temp_model_valid()) {
  883. enquecommand_P(PSTR("M500"));
  884. lcd_commands_step = 0;
  885. lcd_commands_type = LcdCommands::Idle;
  886. }
  887. }
  888. #endif //TEMP_MODEL
  889. }
  890. void lcd_return_to_status()
  891. {
  892. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  893. menu_goto(lcd_status_screen, 0, false, true);
  894. menu_depth = 0;
  895. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  896. }
  897. //! @brief Pause print, disable nozzle heater, move to park position, send host action "paused"
  898. void lcd_pause_print()
  899. {
  900. stop_and_save_print_to_ram(0.0, -default_retraction);
  901. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_PAUSED);
  902. isPrintPaused = true;
  903. // return to status is required to continue processing in the main loop!
  904. lcd_commands_type = LcdCommands::LongPause;
  905. lcd_return_to_status();
  906. }
  907. //! @brief Send host action "pause"
  908. void lcd_pause_usb_print()
  909. {
  910. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_PAUSE);
  911. }
  912. static void lcd_move_menu_axis();
  913. /* Menu implementation */
  914. static void lcd_cooldown()
  915. {
  916. setAllTargetHotends(0);
  917. setTargetBed(0);
  918. fanSpeed = 0;
  919. lcd_return_to_status();
  920. }
  921. //! @brief append text label with a colon and format it into a fixed size output buffer
  922. //! It would have been much easier if there was a ':' in the labels.
  923. //! But since the texts like Bed, Nozzle and PINDA are used in other places
  924. //! it is better to reuse these texts even though it requires some extra formatting code.
  925. //! @param [in] ipgmLabel pointer to string in PROGMEM
  926. //! @param [out] pointer to string in RAM which will receive the formatted text. Must be allocated to appropriate size
  927. //! @param [in] dstSize allocated length of dst
  928. static void pgmtext_with_colon(const char *ipgmLabel, char *dst, uint8_t dstSize){
  929. uint8_t i = 0;
  930. for(; i < dstSize - 2; ++i){ // 2 byte less than buffer, we'd be adding a ':' to the end
  931. uint8_t b = pgm_read_byte(ipgmLabel + i);
  932. if( ! b )
  933. break;
  934. dst[i] = b;
  935. }
  936. dst[i] = ':'; // append the colon
  937. ++i;
  938. for(; i < dstSize - 1; ++i) // fill the rest with spaces
  939. dst[i] = ' ';
  940. dst[dstSize-1] = '\0'; // terminate the string properly
  941. }
  942. //! @brief Show Extruder Info
  943. //!
  944. //! @code{.unparsed}
  945. //! |01234567890123456789|
  946. //! |Hotend fan: 0000| MSG_HOTEND_FAN_SPEED c=15
  947. //! |Print fan: 0000| MSG_PRINT_FAN_SPEED c=15
  948. //! | |
  949. //! | |
  950. //! ----------------------
  951. //! @endcode
  952. void lcd_menu_extruder_info() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  953. {
  954. lcd_timeoutToStatus.stop(); //infinite timeout
  955. lcd_home();
  956. lcd_printf_P(PSTR("%-15.15S%-5d\n" "%-15.15S%-5d\n"), _T(MSG_HOTEND_FAN_SPEED), 60*fan_speed[0], _T(MSG_PRINT_FAN_SPEED), 60*fan_speed[1] );
  957. menu_back_if_clicked();
  958. }
  959. static uint16_t __attribute__((noinline)) clamp999(uint16_t v){
  960. return v > 999 ? 999 : v;
  961. }
  962. //! @brief Show Fails Statistics MMU
  963. //!
  964. //! @code{.unparsed}
  965. //! |01234567890123456789|
  966. //! | Main | MSG_MAIN c=18
  967. //! | Last print | MSG_LAST_PRINT c=18
  968. //! | Total | MSG_TOTAL c=6
  969. //! | |
  970. //! ----------------------
  971. //! @endcode
  972. static void lcd_menu_fails_stats_mmu()
  973. {
  974. MENU_BEGIN();
  975. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  976. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_mmu_print);
  977. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_mmu_total);
  978. MENU_ITEM_SUBMENU_P(_O(PSTR("Toolchange count")), lcd_menu_toolchange_stats_mmu_total);
  979. MENU_END();
  980. }
  981. //! @brief Show Last Print Failures Statistics MMU
  982. //!
  983. //! @code{.unparsed}
  984. //! |01234567890123456789|
  985. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  986. //! | MMU fails 000| MSG_MMU_FAILS c=15
  987. //! | MMU load fails 000| MSG_MMU_LOAD_FAILS c=15
  988. //! | |
  989. //! ----------------------
  990. //! @endcode
  991. static void lcd_menu_fails_stats_mmu_print() {
  992. lcd_timeoutToStatus.stop(); //infinite timeout
  993. lcd_home();
  994. lcd_printf_P(
  995. PSTR("%S\n"
  996. " %-16.16S%-3d\n"
  997. " %-16.16S%-3d"
  998. ),
  999. _T(MSG_LAST_PRINT_FAILURES),
  1000. _T(MSG_MMU_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) ),
  1001. _T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) ));
  1002. menu_back_if_clicked_fb();
  1003. }
  1004. //! @brief Show Total Failures Statistics MMU
  1005. //!
  1006. //! @code{.unparsed}
  1007. //! |01234567890123456789|
  1008. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1009. //! | MMU fails 000| MSG_MMU_FAILS c=15
  1010. //! | MMU load fails 000| MSG_MMU_LOAD_FAILS c=15
  1011. //! | MMU power fails 000| MSG_MMU_POWER_FAILS c=15
  1012. //! ----------------------
  1013. //! @endcode
  1014. static void lcd_menu_fails_stats_mmu_total() {
  1015. lcd_timeoutToStatus.stop(); //infinite timeout
  1016. lcd_home();
  1017. lcd_printf_P(
  1018. PSTR("%S\n"
  1019. " %-16.16S%-3d\n"
  1020. " %-16.16S%-3d\n"
  1021. " %-16.16S%-3d"
  1022. ),
  1023. _T(MSG_TOTAL_FAILURES),
  1024. _T(MSG_MMU_FAILS), clamp999( eeprom_read_word((uint16_t*)EEPROM_MMU_FAIL_TOT) ),
  1025. _T(MSG_MMU_LOAD_FAILS), clamp999( eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) ),
  1026. _T(MSG_MMU_POWER_FAILS), clamp999( MMU2::mmu2.TMCFailures() ));
  1027. menu_back_if_clicked_fb();
  1028. }
  1029. //! @brief Show Total Failures Statistics MMU
  1030. //!
  1031. //! @code{.unparsed}
  1032. //! |01234567890123456789|
  1033. //! |Toolchange count: |
  1034. //! | 4294967295|
  1035. //! | |
  1036. //! | |
  1037. //! ----------------------
  1038. //! @endcode
  1039. static void lcd_menu_toolchange_stats_mmu_total()
  1040. {
  1041. typedef struct
  1042. {
  1043. bool initialized; // 1byte
  1044. } _menu_data_t;
  1045. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1046. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1047. if(!_md->initialized) {
  1048. lcd_set_cursor(0, 0);
  1049. lcd_puts_P(PSTR("Toolchange count:"));
  1050. lcd_set_cursor(10, 1);
  1051. lcd_print(eeprom_read_dword((uint32_t*)EEPROM_TOTAL_TOOLCHANGE_COUNT));
  1052. _md->initialized = true;
  1053. }
  1054. menu_back_if_clicked_fb();
  1055. }
  1056. #if defined(TMC2130) && defined(FILAMENT_SENSOR)
  1057. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" " %-16.16S%-3d\n" " %-7.7SX %-3d Y %-3d";
  1058. //! @brief Show Total Failures Statistics MMU
  1059. //!
  1060. //! @code{.unparsed}
  1061. //! |01234567890123456789|
  1062. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1063. //! | Power failures 000| MSG_POWER_FAILURES c=15
  1064. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1065. //! | Crash X:000 Y:000| MSG_CRASH c=7
  1066. //! ----------------------
  1067. //! @endcode
  1068. static void lcd_menu_fails_stats_total()
  1069. {
  1070. lcd_timeoutToStatus.stop(); //infinite timeout
  1071. lcd_home();
  1072. lcd_printf_P(failStatsFmt,
  1073. _T(MSG_TOTAL_FAILURES),
  1074. _T(MSG_POWER_FAILURES), clamp999( eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) ),
  1075. _T(MSG_FIL_RUNOUTS), clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) ),
  1076. _T(MSG_CRASH),
  1077. clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) ),
  1078. clamp999( eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) ));
  1079. menu_back_if_clicked_fb();
  1080. }
  1081. //! @brief Show Last Print Failures Statistics
  1082. //!
  1083. //! @code{.unparsed}
  1084. //! |01234567890123456789|
  1085. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1086. //! | Power failures 000| MSG_POWER_FAILURES c=15
  1087. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1088. //! | Crash X 000 Y 000| MSG_CRASH c=7
  1089. //! ----------------------
  1090. //! @endcode
  1091. //! @todo leptun refactor this piece of code please
  1092. static void lcd_menu_fails_stats_print()
  1093. {
  1094. lcd_timeoutToStatus.stop(); //infinite timeout
  1095. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1096. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1097. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1098. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1099. lcd_home();
  1100. lcd_printf_P(failStatsFmt,
  1101. _T(MSG_LAST_PRINT_FAILURES),
  1102. _T(MSG_POWER_FAILURES), power,
  1103. _T(MSG_FIL_RUNOUTS), filam,
  1104. _T(MSG_CRASH), crashX, crashY);
  1105. menu_back_if_clicked_fb();
  1106. }
  1107. //! @brief Open fail statistics menu
  1108. //!
  1109. //! This version of function is used, when there is filament sensor,
  1110. //! power failure and crash detection.
  1111. //! There are Last print and Total menu items.
  1112. //!
  1113. //! @code{.unparsed}
  1114. //! |01234567890123456789|
  1115. //! | Main | MSG_MAIN c=18
  1116. //! | Last print | MSG_LAST_PRINT c=18
  1117. //! | Total | MSG_TOTAL c=6
  1118. //! | |
  1119. //! ----------------------
  1120. //! @endcode
  1121. static void lcd_menu_fails_stats()
  1122. {
  1123. MENU_BEGIN();
  1124. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1125. MENU_ITEM_SUBMENU_P(_T(MSG_LAST_PRINT), lcd_menu_fails_stats_print);
  1126. MENU_ITEM_SUBMENU_P(_T(MSG_TOTAL), lcd_menu_fails_stats_total);
  1127. MENU_END();
  1128. }
  1129. #elif defined(FILAMENT_SENSOR)
  1130. static const char failStatsFmt[] PROGMEM = "%S\n" " %-16.16S%-3d\n" "%S\n" " %-16.16S%-3d\n";
  1131. //!
  1132. //! @brief Print last print and total filament run outs
  1133. //!
  1134. //! This version of function is used, when there is filament sensor,
  1135. //! but no other sensors (e.g. power failure, crash detection).
  1136. //!
  1137. //! Example screen:
  1138. //! @code{.unparsed}
  1139. //! |01234567890123456789|
  1140. //! |Last print failures | MSG_LAST_PRINT_FAILURES c=20
  1141. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1142. //! |Total failures | MSG_TOTAL_FAILURES c=20
  1143. //! | Fil. runouts 000| MSG_FIL_RUNOUTS c=15
  1144. //! ----------------------
  1145. //! @endcode
  1146. static void lcd_menu_fails_stats()
  1147. {
  1148. lcd_timeoutToStatus.stop(); //infinite timeout
  1149. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1150. uint16_t filamentTotal = clamp999( eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) );
  1151. lcd_home();
  1152. lcd_printf_P(failStatsFmt,
  1153. _T(MSG_LAST_PRINT_FAILURES),
  1154. _T(MSG_FIL_RUNOUTS), filamentLast,
  1155. _T(MSG_TOTAL_FAILURES),
  1156. _T(MSG_FIL_RUNOUTS), filamentTotal);
  1157. menu_back_if_clicked();
  1158. }
  1159. #else
  1160. static void lcd_menu_fails_stats()
  1161. {
  1162. lcd_timeoutToStatus.stop(); //infinite timeout
  1163. MENU_BEGIN();
  1164. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1165. MENU_END();
  1166. }
  1167. #endif //TMC2130
  1168. #ifdef DEBUG_BUILD
  1169. #ifdef DEBUG_STACK_MONITOR
  1170. extern uint16_t SP_min;
  1171. extern char* __malloc_heap_start;
  1172. extern char* __malloc_heap_end;
  1173. #endif //DEBUG_STACK_MONITOR
  1174. //! @brief Show Debug Information
  1175. //!
  1176. //! @code{.unparsed}
  1177. //! |01234567890123456789|
  1178. //! |RAM statistics | c=20
  1179. //! | SP_min: 0000| c=14
  1180. //! | heap_start: 0000| c=14
  1181. //! | heap_end: 0000| c=14
  1182. //! ----------------------
  1183. //! @endcode
  1184. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  1185. static void lcd_menu_debug()
  1186. {
  1187. #ifdef DEBUG_STACK_MONITOR
  1188. lcd_home();
  1189. lcd_printf_P(PSTR("RAM statistics\n" ////c=20
  1190. " SP_min: 0x%04x\n" ////c=14
  1191. " heap_start: 0x%04x\n" ////c=14
  1192. " heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); ////c=14
  1193. #endif //DEBUG_STACK_MONITOR
  1194. menu_back_if_clicked_fb();
  1195. }
  1196. #endif /* DEBUG_BUILD */
  1197. //! @brief common line print for lcd_menu_temperatures
  1198. //! @param [in] ipgmLabel pointer to string in PROGMEM
  1199. //! @param [in] value to be printed behind the label
  1200. static void lcd_menu_temperatures_line(const char *ipgmLabel, int value){
  1201. static const size_t maxChars = 15;
  1202. char tmp[maxChars];
  1203. pgmtext_with_colon(ipgmLabel, tmp, maxChars);
  1204. lcd_printf_P(PSTR(" %s%3d\x01 \n"), tmp, value); // no need to add -14.14 to string alignment
  1205. }
  1206. //! @brief Show Temperatures
  1207. //!
  1208. //! @code{.unparsed}
  1209. //! |01234567890123456789|
  1210. //! | Nozzle: 000D| MSG_NOZZLE c=10
  1211. //! | Bed: 000D| MSG_BED c=13
  1212. //! | Ambient: 000D| MSG_AMBIENTc=14
  1213. //! | PINDA: 000D| MSG_PINDA c=14
  1214. //! ----------------------
  1215. //! D - Degree sysmbol LCD_STR_DEGREE
  1216. //! @endcode
  1217. static void lcd_menu_temperatures()
  1218. {
  1219. lcd_timeoutToStatus.stop(); //infinite timeout
  1220. lcd_home();
  1221. lcd_menu_temperatures_line( _T(MSG_NOZZLE), (int)current_temperature[0] );
  1222. lcd_menu_temperatures_line( _T(MSG_BED), (int)current_temperature_bed );
  1223. #ifdef AMBIENT_THERMISTOR
  1224. lcd_menu_temperatures_line( _i("Ambient"), (int)current_temperature_ambient ); ////MSG_AMBIENT c=14
  1225. #endif //AMBIENT_THERMISTOR
  1226. #ifdef PINDA_THERMISTOR
  1227. lcd_menu_temperatures_line(MSG_PINDA, (int)current_temperature_pinda ); ////MSG_PINDA
  1228. #endif //PINDA_THERMISTOR
  1229. menu_back_if_clicked();
  1230. }
  1231. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || (defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG))
  1232. #define VOLT_DIV_R1 10000
  1233. #define VOLT_DIV_R2 2370
  1234. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1235. //! @brief Show Voltages
  1236. //!
  1237. //! @code{.unparsed}
  1238. //! |01234567890123456789|
  1239. //! | |
  1240. //! | PWR: 00.0V | c=12
  1241. //! | Bed: 00.0V | c=12
  1242. //! | IR : 00.0V | c=12 optional
  1243. //! ----------------------
  1244. //! @endcode
  1245. static void lcd_menu_voltages()
  1246. {
  1247. lcd_timeoutToStatus.stop(); //infinite timeout
  1248. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1249. float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1250. lcd_home();
  1251. lcd_printf_P(PSTR(" PWR: %4.1fV\n" " BED: %4.1fV"), volt_pwr, volt_bed);
  1252. #ifdef IR_SENSOR_ANALOG
  1253. lcd_printf_P(PSTR("\n IR : %3.1fV"), fsensor.Raw2Voltage(fsensor.getVoltRaw()));
  1254. #endif //IR_SENSOR_ANALOG
  1255. menu_back_if_clicked();
  1256. }
  1257. #endif //defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN) || defined(IR_SENSOR_ANALOG)
  1258. #ifdef TMC2130
  1259. //! @brief Show Belt Status
  1260. //!
  1261. //! @code{.unparsed}
  1262. //! |01234567890123456789|
  1263. //! | Belt status | c=18
  1264. //! | X: 000 |
  1265. //! | Y: 000 |
  1266. //! | |
  1267. //! ----------------------
  1268. //! @endcode
  1269. static void lcd_menu_belt_status()
  1270. {
  1271. lcd_home();
  1272. lcd_printf_P(PSTR("%S\n" " X %d\n" " Y %d"), _T(MSG_BELT_STATUS), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1273. menu_back_if_clicked();
  1274. }
  1275. #endif //TMC2130
  1276. #ifdef RESUME_DEBUG
  1277. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1278. extern void restore_print_from_ram_and_continue(float e_move);
  1279. static void lcd_menu_test_save()
  1280. {
  1281. stop_and_save_print_to_ram(10, -0.8);
  1282. }
  1283. static void lcd_menu_test_restore()
  1284. {
  1285. restore_print_from_ram_and_continue(0.8);
  1286. }
  1287. #endif //RESUME_DEBUG
  1288. //! @brief Show Preheat Menu
  1289. static void lcd_preheat_menu()
  1290. {
  1291. eFilamentAction = FilamentAction::Preheat;
  1292. lcd_generic_preheat_menu();
  1293. }
  1294. #ifdef MENU_DUMP
  1295. #include "xflash_dump.h"
  1296. static void lcd_dump_memory()
  1297. {
  1298. lcd_beeper_quick_feedback();
  1299. xfdump_dump();
  1300. lcd_return_to_status();
  1301. }
  1302. #endif //MENU_DUMP
  1303. #ifdef MENU_SERIAL_DUMP
  1304. #include "Dcodes.h"
  1305. static void lcd_serial_dump()
  1306. {
  1307. serial_dump_and_reset(dump_crash_reason::manual);
  1308. }
  1309. #endif //MENU_SERIAL_DUMP
  1310. #if defined(DEBUG_BUILD) && defined(EMERGENCY_HANDLERS)
  1311. #include <avr/wdt.h>
  1312. #ifdef WATCHDOG
  1313. static void lcd_wdr_crash()
  1314. {
  1315. while (1);
  1316. }
  1317. #endif
  1318. static uint8_t lcd_stack_crash_(uint8_t arg, uint32_t sp = 0)
  1319. {
  1320. // populate the stack with an increasing value for ease of testing
  1321. volatile uint16_t tmp __attribute__((unused)) = sp;
  1322. _delay(arg);
  1323. uint8_t ret = lcd_stack_crash_(arg, SP);
  1324. // required to avoid tail call elimination and to slow down the stack growth
  1325. _delay(ret);
  1326. return ret;
  1327. }
  1328. static void lcd_stack_crash()
  1329. {
  1330. #ifdef WATCHDOG
  1331. wdt_disable();
  1332. #endif
  1333. // delay choosen in order to hit the stack-check in the temperature isr reliably
  1334. lcd_stack_crash_(10);
  1335. }
  1336. #endif
  1337. #ifdef DEBUG_PULLUP_CRASH
  1338. void TestPullupCrash() {
  1339. PORTF |= 0x01;
  1340. }
  1341. #endif // DEBUG_PULLUP_CRASH
  1342. //! @brief Show Support Menu
  1343. //!
  1344. //! @code{.unparsed}
  1345. //! |01234567890123456789|
  1346. //! | Main | MSG_MAIN c=18
  1347. //! | Firmware: | c=18
  1348. //! | 3.7.2.-2363 | c=16
  1349. //! | prusa3d.com | MSG_PRUSA3D
  1350. //! | forum.prusa3d.com | MSG_PRUSA3D_FORUM
  1351. //! | help.prusa3d.com | MSG_PRUSA3D_HELP
  1352. //! | -------------- | STR_SEPARATOR
  1353. //! | 1_75mm_MK3 | FILAMENT_SIZE
  1354. //! | help.prusa3d.com | ELECTRONICS
  1355. //! | help.prusa3d.com | NOZZLE_TYPE
  1356. //! | -------------- | STR_SEPARATOR
  1357. //! | Date: | c=17
  1358. //! | MMM DD YYYY | __DATE__
  1359. //! | -------------- | STR_SEPARATOR
  1360. //! @endcode
  1361. //!
  1362. //! If MMU is connected
  1363. //!
  1364. //! @code{.unparsed}
  1365. //! | MMU2 connected | c=18
  1366. //! | FW: 1.0.6-7064523 |
  1367. //! @endcode
  1368. //!
  1369. //! If MMU is not connected
  1370. //!
  1371. //! @code{.unparsed}
  1372. //! | MMU2 N/A | c=18
  1373. //! @endcode
  1374. //!
  1375. //! If Flash Air is connected
  1376. //!
  1377. //! @code{.unparsed}
  1378. //! | -------------- | STR_SEPARATOR
  1379. //! | FlashAir IP Addr: | c=18
  1380. //! | 192.168.1.100 |
  1381. //! @endcode
  1382. //!
  1383. //! @code{.unparsed}
  1384. //! | -------------- | STR_SEPARATOR
  1385. //! | XYZ cal. details | MSG_XYZ_DETAILS c=18
  1386. //! | Extruder info | MSG_INFO_EXTRUDER
  1387. //! | XYZ cal. details | MSG_INFO_SENSORS
  1388. //! @endcode
  1389. //!
  1390. //! If TMC2130 defined
  1391. //!
  1392. //! @code{.unparsed}
  1393. //! | Belt status | MSG_BELT_STATUS
  1394. //! @endcode
  1395. //!
  1396. //! @code{.unparsed}
  1397. //! | Temperatures | MSG_MENU_TEMPERATURES
  1398. //! @endcode
  1399. //!
  1400. //! If Voltage Bed and PWR Pin are defined
  1401. //!
  1402. //! @code{.unparsed}
  1403. //! | Voltages | MSG_MENU_VOLTAGES
  1404. //! @endcode
  1405. //!
  1406. //!
  1407. //! If DEBUG_BUILD is defined
  1408. //!
  1409. //! @code{.unparsed}
  1410. //! | Debug | c=18
  1411. //! @endcode
  1412. //! ----------------------
  1413. //! @endcode
  1414. static void lcd_support_menu()
  1415. {
  1416. typedef struct
  1417. { // 22bytes total
  1418. int8_t status; // 1byte
  1419. bool is_flash_air; // 1byte
  1420. uint32_t ip; // 4bytes
  1421. char ip_str[IP4_STR_SIZE]; // 16bytes
  1422. } _menu_data_t;
  1423. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1424. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1425. if (_md->status == 0 || lcd_draw_update == 2)
  1426. {
  1427. // Menu was entered or SD card status has changed (plugged in or removed).
  1428. // Initialize its status.
  1429. _md->status = 1;
  1430. _md->is_flash_air = card.ToshibaFlashAir_isEnabled();
  1431. if (_md->is_flash_air) {
  1432. card.ToshibaFlashAir_GetIP((uint8_t*)(&_md->ip)); // ip == 0 if it failed
  1433. }
  1434. } else if (_md->is_flash_air && _md->ip == 0 && ++ _md->status == 16)
  1435. {
  1436. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1437. _md->status = 0;
  1438. }
  1439. MENU_BEGIN();
  1440. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1441. MENU_ITEM_BACK_P(PSTR("Firmware:"));
  1442. MENU_ITEM_BACK_P(PSTR(" " FW_VERSION_FULL));
  1443. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1444. MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
  1445. #endif
  1446. // Ideally this block would be optimized out by the compiler.
  1447. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1448. if (fw_string_len < 6) {
  1449. MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
  1450. } else {
  1451. MENU_ITEM_BACK_P(PSTR("FW - " FW_version));
  1452. }*/
  1453. MENU_ITEM_BACK_P(_n("prusa3d.com"));////MSG_PRUSA3D c=18
  1454. MENU_ITEM_BACK_P(_n("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=18
  1455. MENU_ITEM_BACK_P(_n("help.prusa3d.com"));////MSG_PRUSA3D_HELP c=18
  1456. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1457. MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
  1458. MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
  1459. MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
  1460. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1461. MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17
  1462. MENU_ITEM_BACK_P(PSTR(SOURCE_DATE_EPOCH));
  1463. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  1464. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1465. MENU_ITEM_BACK_P(PSTR("Fil. sensor v.:"));
  1466. MENU_ITEM_BACK_P(fsensor.getIRVersionText());
  1467. #endif // IR_SENSOR_ANALOG
  1468. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1469. if (MMU2::mmu2.Enabled())
  1470. {
  1471. MENU_ITEM_BACK_P(_i("MMU2 connected")); ////MSG_MMU_CONNECTED c=18
  1472. MENU_ITEM_BACK_P(PSTR(" FW:")); ////c=17
  1473. if (((menu_item - 1) == menu_line) && lcd_draw_update)
  1474. {
  1475. lcd_set_cursor(6, menu_row);
  1476. MMU2::Version mmu_version = MMU2::mmu2.GetMMUFWVersion();
  1477. if (mmu_version.major > 0)
  1478. lcd_printf_P(PSTR("%d.%d.%d"), mmu_version.major, mmu_version.minor, mmu_version.build);
  1479. else
  1480. lcd_puts_P(_i("unknown")); ////MSG_UNKNOWN c=13
  1481. }
  1482. }
  1483. else
  1484. MENU_ITEM_BACK_P(PSTR("MMU2 N/A"));
  1485. // Show the FlashAir IP address, if the card is available.
  1486. if (_md->is_flash_air) {
  1487. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1488. MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:")); ////MSG_FLASHAIR c=18
  1489. MENU_ITEM_BACK_P(PSTR(" "));
  1490. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1491. lcd_set_cursor(2, menu_row);
  1492. ip4_to_str(_md->ip_str, (uint8_t*)(&_md->ip));
  1493. lcd_print(_md->ip_str);
  1494. }
  1495. }
  1496. // Show the printer IP address, if it is available.
  1497. if (IP_address) {
  1498. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1499. MENU_ITEM_BACK_P(_i("Printer IP Addr:")); ////MSG_PRINTER_IP c=18
  1500. MENU_ITEM_BACK_P(PSTR(" "));
  1501. if (((menu_item - 1) == menu_line) && lcd_draw_update) {
  1502. lcd_set_cursor(2, menu_row);
  1503. ip4_to_str(_md->ip_str, (uint8_t*)(&IP_address));
  1504. lcd_print(_md->ip_str);
  1505. }
  1506. }
  1507. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1508. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=18
  1509. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=18
  1510. MENU_ITEM_SUBMENU_P(_i("Sensor info"), lcd_menu_show_sensors_state);////MSG_INFO_SENSORS c=18
  1511. #ifdef TMC2130
  1512. MENU_ITEM_SUBMENU_P(_T(MSG_BELT_STATUS), lcd_menu_belt_status);
  1513. #endif //TMC2130
  1514. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=18
  1515. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1516. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=18
  1517. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1518. #ifdef MENU_DUMP
  1519. MENU_ITEM_FUNCTION_P(_n("Dump memory"), lcd_dump_memory);
  1520. #endif //MENU_DUMP
  1521. #ifdef MENU_SERIAL_DUMP
  1522. if (emergency_serial_dump)
  1523. MENU_ITEM_FUNCTION_P(_n("Dump to serial"), lcd_serial_dump);
  1524. #endif
  1525. #ifdef DEBUG_BUILD
  1526. #ifdef EMERGENCY_HANDLERS
  1527. #ifdef WATCHDOG
  1528. MENU_ITEM_FUNCTION_P(PSTR("WDR crash"), lcd_wdr_crash);
  1529. #endif //WATCHDOG
  1530. MENU_ITEM_FUNCTION_P(PSTR("Stack crash"), lcd_stack_crash);
  1531. #endif //EMERGENCY_HANDLERS
  1532. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////MSG_DEBUG c=18
  1533. #endif /* DEBUG_BUILD */
  1534. MENU_END();
  1535. }
  1536. void lcd_set_fan_check() {
  1537. fans_check_enabled = !fans_check_enabled;
  1538. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1539. #ifdef FANCHECK
  1540. if (fans_check_enabled == false) fan_check_error = EFCE_OK; //reset error if fanCheck is disabled during error. Allows resuming print.
  1541. #endif //FANCHECK
  1542. }
  1543. #ifdef MMU_HAS_CUTTER
  1544. void lcd_cutter_enabled()
  1545. {
  1546. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1547. {
  1548. #ifndef MMU_ALWAYS_CUT
  1549. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1550. }
  1551. #else //MMU_ALWAYS_CUT
  1552. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_always);
  1553. }
  1554. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1555. {
  1556. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1557. }
  1558. #endif //MMU_ALWAYS_CUT
  1559. else
  1560. {
  1561. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_enabled);
  1562. }
  1563. }
  1564. #endif //MMU_HAS_CUTTER
  1565. void lcd_set_filament_autoload() {
  1566. fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled());
  1567. }
  1568. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  1569. void lcd_set_filament_oq_meass()
  1570. {
  1571. fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled);
  1572. }
  1573. #endif
  1574. FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
  1575. bool bFilamentPreheatState;
  1576. bool bFilamentAction=false;
  1577. static bool bFilamentWaitingFlag=false;
  1578. static void mFilamentPrompt()
  1579. {
  1580. uint8_t nLevel;
  1581. lcd_set_cursor(0,0);
  1582. lcdui_print_temp(LCD_STR_THERMOMETER[0],(int)degHotend(0),(int)degTargetHotend(0));
  1583. lcd_puts_at_P(0,1, _i("Press the knob")); ////MSG_PRESS_KNOB c=20
  1584. lcd_set_cursor(0,2);
  1585. switch(eFilamentAction)
  1586. {
  1587. case FilamentAction::Load:
  1588. case FilamentAction::AutoLoad:
  1589. case FilamentAction::MmuLoad:
  1590. case FilamentAction::MmuLoadingTest:
  1591. lcd_puts_P(_i("to load filament")); ////MSG_TO_LOAD_FIL c=20
  1592. break;
  1593. case FilamentAction::UnLoad:
  1594. case FilamentAction::MmuUnLoad:
  1595. lcd_puts_P(_i("to unload filament")); ////MSG_TO_UNLOAD_FIL c=20
  1596. break;
  1597. case FilamentAction::MmuEject:
  1598. case FilamentAction::MmuCut:
  1599. case FilamentAction::None:
  1600. case FilamentAction::Preheat:
  1601. case FilamentAction::Lay1Cal:
  1602. break;
  1603. }
  1604. if(lcd_clicked()
  1605. #ifdef FILAMENT_SENSOR
  1606. /// @todo leptun - add this as a specific retest item
  1607. || (((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) && fsensor.getFilamentLoadEvent())
  1608. #endif //FILAMENT_SENSOR
  1609. ) {
  1610. nLevel=2;
  1611. if(!bFilamentPreheatState)
  1612. {
  1613. nLevel++;
  1614. // setTargetHotend0(0.0); // uncoment if return to base-state is required
  1615. }
  1616. menu_back(nLevel);
  1617. switch(eFilamentAction)
  1618. {
  1619. case FilamentAction::AutoLoad:
  1620. eFilamentAction=FilamentAction::None; // i.e. non-autoLoad
  1621. // FALLTHRU
  1622. case FilamentAction::Load:
  1623. loading_flag=true;
  1624. enquecommand_P(PSTR("M701")); // load filament
  1625. break;
  1626. case FilamentAction::UnLoad:
  1627. enquecommand_P(PSTR("M702")); // unload filament
  1628. break;
  1629. case FilamentAction::MmuLoad:
  1630. case FilamentAction::MmuLoadingTest:
  1631. case FilamentAction::MmuUnLoad:
  1632. case FilamentAction::MmuEject:
  1633. case FilamentAction::MmuCut:
  1634. case FilamentAction::None:
  1635. case FilamentAction::Preheat:
  1636. case FilamentAction::Lay1Cal:
  1637. break;
  1638. }
  1639. }
  1640. }
  1641. void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
  1642. {
  1643. static int nTargetOld;
  1644. static int nTargetBedOld;
  1645. uint8_t nLevel;
  1646. nTargetOld = target_temperature[0];
  1647. nTargetBedOld = target_temperature_bed;
  1648. setTargetHotend0((float )nTemp);
  1649. setTargetBed((float) nTempBed);
  1650. {
  1651. const FilamentAction action = eFilamentAction;
  1652. if (action == FilamentAction::Preheat || action == FilamentAction::Lay1Cal)
  1653. {
  1654. lcd_return_to_status();
  1655. if (action == FilamentAction::Lay1Cal)
  1656. {
  1657. lcd_commands_type = LcdCommands::Layer1Cal;
  1658. }
  1659. else
  1660. {
  1661. raise_z_above(MIN_Z_FOR_PREHEAT);
  1662. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1663. lcd_wizard(WizState::LoadFilHot);
  1664. }
  1665. return;
  1666. }
  1667. }
  1668. lcd_timeoutToStatus.stop();
  1669. if (current_temperature[0] > (target_temperature[0] * 0.95))
  1670. {
  1671. switch (eFilamentAction)
  1672. {
  1673. case FilamentAction::Load:
  1674. case FilamentAction::AutoLoad:
  1675. case FilamentAction::UnLoad:
  1676. if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt);
  1677. else
  1678. {
  1679. nLevel = bFilamentPreheatState ? 1 : 2;
  1680. menu_back(nLevel);
  1681. if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
  1682. {
  1683. loading_flag = true;
  1684. enquecommand_P(PSTR("M701")); // load filament
  1685. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1686. }
  1687. if (eFilamentAction == FilamentAction::UnLoad)
  1688. enquecommand_P(PSTR("M702")); // unload filament
  1689. }
  1690. break;
  1691. case FilamentAction::MmuLoad:
  1692. nLevel = bFilamentPreheatState ? 1 : 2;
  1693. bFilamentAction = true;
  1694. menu_back(nLevel);
  1695. menu_submenu(mmu_load_to_nozzle_menu);
  1696. break;
  1697. case FilamentAction::MmuLoadingTest:
  1698. nLevel = bFilamentPreheatState ? 1 : 2;
  1699. bFilamentAction = true;
  1700. menu_back(nLevel);
  1701. menu_submenu(mmu_loading_test_menu);
  1702. break;
  1703. case FilamentAction::MmuUnLoad:
  1704. nLevel = bFilamentPreheatState ? 1 : 2;
  1705. bFilamentAction = true;
  1706. menu_back(nLevel);
  1707. MMU2::mmu2.unload();
  1708. break;
  1709. case FilamentAction::MmuEject:
  1710. nLevel = bFilamentPreheatState ? 1 : 2;
  1711. bFilamentAction = true;
  1712. menu_back(nLevel);
  1713. menu_submenu(mmu_fil_eject_menu);
  1714. break;
  1715. case FilamentAction::MmuCut:
  1716. #ifdef MMU_HAS_CUTTER
  1717. nLevel=bFilamentPreheatState?1:2;
  1718. bFilamentAction=true;
  1719. menu_back(nLevel);
  1720. menu_submenu(mmu_cut_filament_menu);
  1721. #endif //MMU_HAS_CUTTER
  1722. break;
  1723. case FilamentAction::None:
  1724. case FilamentAction::Preheat:
  1725. case FilamentAction::Lay1Cal:
  1726. // handled earlier
  1727. break;
  1728. }
  1729. if (bFilamentWaitingFlag) Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  1730. bFilamentWaitingFlag = false;
  1731. }
  1732. else
  1733. {
  1734. if (!bFilamentWaitingFlag || lcd_draw_update)
  1735. {
  1736. // First entry from another menu OR first run after the filament preheat selection. Use
  1737. // bFilamentWaitingFlag to distinguish: this flag is reset exactly once when entering
  1738. // the menu and is used to raise the carriage *once*. In other cases, the LCD has been
  1739. // modified elsewhere and needs to be redrawn in full.
  1740. // reset bFilamentWaitingFlag immediately to avoid re-entry from raise_z_above()!
  1741. bool once = !bFilamentWaitingFlag;
  1742. bFilamentWaitingFlag = true;
  1743. // also force-enable lcd_draw_update (might be 0 when called from outside a menu)
  1744. lcd_draw_update = 1;
  1745. lcd_clear();
  1746. lcd_puts_at_P(0, 3, _T(MSG_CANCEL));
  1747. lcd_set_cursor(0, 1);
  1748. switch (eFilamentAction)
  1749. {
  1750. case FilamentAction::Load:
  1751. case FilamentAction::AutoLoad:
  1752. case FilamentAction::MmuLoad:
  1753. case FilamentAction::MmuLoadingTest:
  1754. lcd_puts_P(_i("Preheating to load")); ////MSG_PREHEATING_TO_LOAD c=20
  1755. if (once) raise_z_above(MIN_Z_FOR_LOAD);
  1756. break;
  1757. case FilamentAction::UnLoad:
  1758. case FilamentAction::MmuUnLoad:
  1759. lcd_puts_P(_i("Preheating to unload")); ////MSG_PREHEATING_TO_UNLOAD c=20
  1760. if (once) raise_z_above(MIN_Z_FOR_UNLOAD);
  1761. break;
  1762. case FilamentAction::MmuEject:
  1763. lcd_puts_P(_i("Preheating to eject")); ////MSG_PREHEATING_TO_EJECT c=20
  1764. break;
  1765. case FilamentAction::MmuCut:
  1766. lcd_puts_P(_i("Preheating to cut")); ////MSG_PREHEATING_TO_CUT c=20
  1767. break;
  1768. case FilamentAction::None:
  1769. case FilamentAction::Preheat:
  1770. case FilamentAction::Lay1Cal:
  1771. // handled earlier
  1772. break;
  1773. }
  1774. }
  1775. if (bFilamentWaitingFlag) {
  1776. lcd_set_cursor(0, 0);
  1777. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int) degHotend(0), (int) degTargetHotend(0));
  1778. }
  1779. if (lcd_clicked())
  1780. {
  1781. bFilamentWaitingFlag = false;
  1782. if (!bFilamentPreheatState)
  1783. {
  1784. setTargetHotend0(0.0);
  1785. setTargetBed(0.0);
  1786. menu_back();
  1787. }
  1788. else
  1789. {
  1790. setTargetHotend0((float )nTargetOld);
  1791. setTargetBed((float) nTargetBedOld);
  1792. }
  1793. menu_back();
  1794. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1795. }
  1796. }
  1797. }
  1798. static void mFilamentItem_farm()
  1799. {
  1800. bFilamentPreheatState = false;
  1801. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, FARM_PREHEAT_HPB_TEMP);
  1802. }
  1803. static void mFilamentItem_farm_nozzle()
  1804. {
  1805. bFilamentPreheatState = false;
  1806. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, 0);
  1807. }
  1808. static void mFilamentItem_PLA()
  1809. {
  1810. bFilamentPreheatState = false;
  1811. mFilamentItem(PLA_PREHEAT_HOTEND_TEMP, PLA_PREHEAT_HPB_TEMP);
  1812. }
  1813. static void mFilamentItem_PET()
  1814. {
  1815. bFilamentPreheatState = false;
  1816. mFilamentItem(PET_PREHEAT_HOTEND_TEMP, PET_PREHEAT_HPB_TEMP);
  1817. }
  1818. static void mFilamentItem_ASA()
  1819. {
  1820. bFilamentPreheatState = false;
  1821. mFilamentItem(ASA_PREHEAT_HOTEND_TEMP, ASA_PREHEAT_HPB_TEMP);
  1822. }
  1823. static void mFilamentItem_PC()
  1824. {
  1825. bFilamentPreheatState = false;
  1826. mFilamentItem(PC_PREHEAT_HOTEND_TEMP, PC_PREHEAT_HPB_TEMP);
  1827. }
  1828. static void mFilamentItem_ABS()
  1829. {
  1830. bFilamentPreheatState = false;
  1831. mFilamentItem(ABS_PREHEAT_HOTEND_TEMP, ABS_PREHEAT_HPB_TEMP);
  1832. }
  1833. static void mFilamentItem_PA()
  1834. {
  1835. bFilamentPreheatState = false;
  1836. mFilamentItem(PA_PREHEAT_HOTEND_TEMP, PA_PREHEAT_HPB_TEMP);
  1837. }
  1838. static void mFilamentItem_HIPS()
  1839. {
  1840. bFilamentPreheatState = false;
  1841. mFilamentItem(HIPS_PREHEAT_HOTEND_TEMP, HIPS_PREHEAT_HPB_TEMP);
  1842. }
  1843. static void mFilamentItem_PP()
  1844. {
  1845. bFilamentPreheatState = false;
  1846. mFilamentItem(PP_PREHEAT_HOTEND_TEMP, PP_PREHEAT_HPB_TEMP);
  1847. }
  1848. static void mFilamentItem_FLEX()
  1849. {
  1850. bFilamentPreheatState = false;
  1851. mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP, FLEX_PREHEAT_HPB_TEMP);
  1852. }
  1853. static void mFilamentItem_PVB()
  1854. {
  1855. bFilamentPreheatState = false;
  1856. mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP);
  1857. }
  1858. void mFilamentBack()
  1859. {
  1860. if (eFilamentAction == FilamentAction::AutoLoad ||
  1861. eFilamentAction == FilamentAction::Preheat ||
  1862. eFilamentAction == FilamentAction::Lay1Cal)
  1863. {
  1864. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1865. }
  1866. }
  1867. void lcd_generic_preheat_menu()
  1868. {
  1869. MENU_BEGIN();
  1870. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1871. {
  1872. ON_MENU_LEAVE(
  1873. mFilamentBack();
  1874. );
  1875. MENU_ITEM_BACK_P(_T(eFilamentAction == FilamentAction::Lay1Cal ? MSG_BACK : MSG_MAIN));
  1876. }
  1877. if (farm_mode)
  1878. {
  1879. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), mFilamentItem_farm);
  1880. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), mFilamentItem_farm_nozzle);
  1881. }
  1882. else
  1883. {
  1884. MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA);
  1885. MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET);
  1886. MENU_ITEM_SUBMENU_P(PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)),mFilamentItem_ASA);
  1887. MENU_ITEM_SUBMENU_P(PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PC_PREHEAT_HPB_TEMP)),mFilamentItem_PC);
  1888. MENU_ITEM_SUBMENU_P(PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PVB_PREHEAT_HPB_TEMP)),mFilamentItem_PVB);
  1889. MENU_ITEM_SUBMENU_P(PSTR("PA - " STRINGIFY(PA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PA_PREHEAT_HPB_TEMP)),mFilamentItem_PA);
  1890. MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS);
  1891. MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS);
  1892. MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP);
  1893. MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX);
  1894. }
  1895. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) && eFilamentAction == FilamentAction::Preheat) MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1896. MENU_END();
  1897. }
  1898. void mFilamentItemForce()
  1899. {
  1900. mFilamentItem(target_temperature[0],target_temperature_bed);
  1901. }
  1902. void lcd_unLoadFilament()
  1903. {
  1904. eFilamentAction=FilamentAction::UnLoad;
  1905. preheat_or_continue();
  1906. }
  1907. static void mmu_unload_filament()
  1908. {
  1909. eFilamentAction = FilamentAction::MmuUnLoad;
  1910. preheat_or_continue();
  1911. }
  1912. void lcd_wait_interact() {
  1913. lcd_clear();
  1914. lcd_puts_at_P(0, 1, _i("Insert filament"));////MSG_INSERT_FILAMENT c=20
  1915. #ifdef FILAMENT_SENSOR
  1916. if (!fsensor.getAutoLoadEnabled())
  1917. #endif //FILAMENT_SENSOR
  1918. {
  1919. lcd_puts_at_P(0, 2, _i("and press the knob"));////MSG_PRESS c=20 r=2
  1920. }
  1921. }
  1922. void lcd_change_success() {
  1923. lcd_clear();
  1924. lcd_puts_at_P(0, 2, _i("Change success!"));////MSG_CHANGE_SUCCESS c=20
  1925. }
  1926. static void lcd_loading_progress_bar(uint16_t loading_time_ms) {
  1927. for (uint_least8_t i = 0; i < LCD_WIDTH; i++) {
  1928. lcd_putc_at(i, 3, '.');
  1929. //loading_time_ms/20 delay
  1930. for (uint_least8_t j = 0; j < 5; j++) {
  1931. delay_keep_alive(loading_time_ms / 100);
  1932. }
  1933. }
  1934. }
  1935. void lcd_loading_color() {
  1936. //we are extruding 25mm with feedrate 200mm/min -> 7.5 seconds for whole action, 0.375 s for one character
  1937. lcd_clear();
  1938. lcd_puts_at_P(0, 0, _i("Loading color"));////MSG_LOADING_COLOR c=20
  1939. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  1940. lcd_loading_progress_bar((FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL); //show progress bar during filament loading slow sequence
  1941. }
  1942. void lcd_loading_filament() {
  1943. lcd_clear();
  1944. lcd_puts_at_P(0, 0, _T(MSG_LOADING_FILAMENT));
  1945. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  1946. uint16_t slow_seq_time = (FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL;
  1947. uint16_t fast_seq_time = (FILAMENTCHANGE_FIRSTFEED * 1000ul) / FILAMENTCHANGE_EFEED_FIRST;
  1948. lcd_loading_progress_bar(slow_seq_time + fast_seq_time); //show progress bar for total time of filament loading fast + slow sequence
  1949. }
  1950. uint8_t lcd_alright() {
  1951. int8_t enc_dif = 0;
  1952. uint8_t cursor_pos = 1;
  1953. lcd_clear();
  1954. lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
  1955. lcd_puts_at_P(1, 1, _T(MSG_YES));
  1956. lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
  1957. lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
  1958. lcd_putc_at(0, 1, '>');
  1959. enc_dif = lcd_encoder_diff;
  1960. lcd_consume_click();
  1961. while (1)
  1962. {
  1963. manage_heater();
  1964. manage_inactivity(true);
  1965. if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  1966. {
  1967. if (enc_dif > lcd_encoder_diff ) {
  1968. // Rotating knob counter clockwise
  1969. cursor_pos--;
  1970. } else if (enc_dif < lcd_encoder_diff) {
  1971. // Rotating knob clockwise
  1972. cursor_pos++;
  1973. }
  1974. if (cursor_pos > 3) {
  1975. cursor_pos = 3;
  1976. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  1977. } else if (cursor_pos < 1) {
  1978. cursor_pos = 1;
  1979. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  1980. }
  1981. // Update '>' render only
  1982. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  1983. lcd_putc_at(0, cursor_pos, '>');
  1984. // Consume rotation event and make feedback sound
  1985. enc_dif = lcd_encoder_diff;
  1986. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  1987. _delay(100);
  1988. }
  1989. if (lcd_clicked())
  1990. {
  1991. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  1992. lcd_clear();
  1993. lcd_return_to_status();
  1994. return cursor_pos;
  1995. }
  1996. };
  1997. }
  1998. void show_preheat_nozzle_warning()
  1999. {
  2000. lcd_clear();
  2001. lcd_puts_at_P(0, 0, _T(MSG_ERROR));
  2002. lcd_puts_at_P(0, 2, _T(MSG_PREHEAT_NOZZLE));
  2003. _delay(2000);
  2004. lcd_clear();
  2005. }
  2006. void lcd_load_filament_color_check()
  2007. {
  2008. uint8_t clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE);
  2009. while (clean == LCD_MIDDLE_BUTTON_CHOICE) {
  2010. load_filament_final_feed();
  2011. st_synchronize();
  2012. clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, LCD_LEFT_BUTTON_CHOICE);
  2013. }
  2014. }
  2015. #ifdef FILAMENT_SENSOR
  2016. static void lcd_menu_AutoLoadFilament()
  2017. {
  2018. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament is active, just press the knob and insert filament..."));////MSG_AUTOLOADING_ENABLED c=20 r=4
  2019. menu_back_if_clicked();
  2020. }
  2021. #endif //FILAMENT_SENSOR
  2022. static void preheat_or_continue() {
  2023. if (target_temperature[0] >= extrude_min_temp) {
  2024. bFilamentPreheatState = true;
  2025. mFilamentItem(target_temperature[0], target_temperature_bed);
  2026. } else {
  2027. lcd_generic_preheat_menu();
  2028. }
  2029. }
  2030. static void lcd_LoadFilament()
  2031. {
  2032. eFilamentAction = FilamentAction::Load;
  2033. preheat_or_continue();
  2034. }
  2035. //! @brief Show filament used a print time
  2036. //!
  2037. //! If printing current print statistics are shown
  2038. //!
  2039. //! @code{.unparsed}
  2040. //! |01234567890123456789|
  2041. //! |Filament used: | MSG_FILAMENT_USED c=19
  2042. //! | 0000.00m |
  2043. //! |Print time: | MSG_PRINT_TIME c=19
  2044. //! | 00h 00m 00s |
  2045. //! ----------------------
  2046. //! @endcode
  2047. //!
  2048. //! If not printing, total statistics are shown
  2049. //!
  2050. //! @code{.unparsed}
  2051. //! |01234567890123456789|
  2052. //! |Total filament: | MSG_TOTAL_FILAMENT c=19
  2053. //! | 0000.00m |
  2054. //! |Total print time: | MSG_TOTAL_PRINT_TIME c=19
  2055. //! | 00d 00h 00m |
  2056. //! ----------------------
  2057. //! @endcode
  2058. void lcd_menu_statistics()
  2059. {
  2060. lcd_timeoutToStatus.stop(); //infinite timeout
  2061. if (IS_SD_PRINTING)
  2062. {
  2063. const float _met = ((float)total_filament_used) / (100000.f);
  2064. const uint32_t _t = (_millis() - starttime) / 1000ul;
  2065. const uint32_t _h = _t / 3600;
  2066. const uint8_t _m = (_t - (_h * 3600ul)) / 60ul;
  2067. const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul));
  2068. lcd_home();
  2069. lcd_printf_P(_N(
  2070. "%S:\n"
  2071. "%18.2fm \n"
  2072. "%S:\n"
  2073. "%10ldh %02dm %02ds"
  2074. ),
  2075. _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19
  2076. _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19
  2077. menu_back_if_clicked_fb();
  2078. }
  2079. else
  2080. {
  2081. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2082. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2083. uint8_t _hours, _minutes;
  2084. uint32_t _days;
  2085. float _filament_m = (float)_filament/100;
  2086. _days = _time / 1440;
  2087. _hours = (_time - (_days * 1440)) / 60;
  2088. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2089. lcd_home();
  2090. lcd_printf_P(_N(
  2091. "%S:\n"
  2092. "%18.2fm \n"
  2093. "%S:\n"
  2094. "%10ldd %02dh %02dm"
  2095. ),
  2096. _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19
  2097. _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19
  2098. menu_back_if_clicked_fb();
  2099. }
  2100. }
  2101. static void _lcd_move(const char *name, uint8_t axis, int min, int max)
  2102. {
  2103. if (homing_flag || mesh_bed_leveling_flag)
  2104. {
  2105. // printer entered a new state where axis move is forbidden
  2106. menu_back();
  2107. return;
  2108. }
  2109. typedef struct
  2110. { // 2bytes total
  2111. bool initialized; // 1byte
  2112. bool endstopsEnabledPrevious; // 1byte
  2113. } _menu_data_t;
  2114. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2115. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2116. if (!_md->initialized)
  2117. {
  2118. _md->endstopsEnabledPrevious = enable_endstops(false);
  2119. _md->initialized = true;
  2120. }
  2121. if (lcd_encoder != 0)
  2122. {
  2123. refresh_cmd_timeout();
  2124. if (! planner_queue_full())
  2125. {
  2126. current_position[axis] += float((int)lcd_encoder);
  2127. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2128. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2129. lcd_encoder = 0;
  2130. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2131. plan_buffer_line_curposXYZE(manual_feedrate[axis] / 60);
  2132. lcd_draw_update = 1;
  2133. }
  2134. }
  2135. if (lcd_draw_update)
  2136. {
  2137. lcd_set_cursor(0, 1);
  2138. menu_draw_float31(name, current_position[axis]);
  2139. }
  2140. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2141. if (LCD_CLICKED) menu_back();
  2142. }
  2143. void lcd_move_e()
  2144. {
  2145. if ((int)degHotend0() > extrude_min_temp)
  2146. {
  2147. if (lcd_encoder != 0)
  2148. {
  2149. refresh_cmd_timeout();
  2150. if (! planner_queue_full())
  2151. {
  2152. current_position[E_AXIS] += float((int)lcd_encoder);
  2153. lcd_encoder = 0;
  2154. plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
  2155. lcd_draw_update = 1;
  2156. }
  2157. }
  2158. if (lcd_draw_update)
  2159. {
  2160. lcd_set_cursor(0, 1);
  2161. // Note: the colon behind the text is necessary to greatly shorten
  2162. // the implementation of menu_draw_float31
  2163. menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]);
  2164. }
  2165. if (LCD_CLICKED) menu_back();
  2166. }
  2167. else
  2168. {
  2169. show_preheat_nozzle_warning();
  2170. lcd_return_to_status();
  2171. }
  2172. }
  2173. //! @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2174. //! If those points are detected too close to edge of reachable area, their confidence is lowered.
  2175. //! This functionality is applied more often for MK2 printers.
  2176. //! @code{.unparsed}
  2177. //! |01234567890123456789|
  2178. //! |Y distance from min | MSG_Y_DIST_FROM_MIN
  2179. //! | -------------- | STR_SEPARATOR
  2180. //! |Left: 00.00mm| MSG_LEFT c=10, c=8
  2181. //! |Right: 00.00mm| MSG_RIGHT c=10, c=8
  2182. //! ----------------------
  2183. //! @endcode
  2184. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2185. static void lcd_menu_xyz_y_min()
  2186. {
  2187. float distanceMin[2];
  2188. count_xyz_details(distanceMin);
  2189. lcd_home();
  2190. lcd_printf_P(_N(
  2191. "%S\n"
  2192. "%S\n"
  2193. "%S:\n"
  2194. "%S:"
  2195. ),
  2196. _i("Y distance from min"), ////MSG_Y_DIST_FROM_MIN c=20
  2197. separator,
  2198. _i("Left"), ////MSG_LEFT c=10
  2199. _i("Right") ////MSG_RIGHT c=10
  2200. );
  2201. for (uint8_t i = 0; i < 2; i++)
  2202. {
  2203. lcd_set_cursor(11,2+i);
  2204. if (distanceMin[i] >= 200) lcd_puts_P(_T(MSG_NA));
  2205. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2206. }
  2207. if (lcd_clicked())
  2208. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2209. }
  2210. //@brief Show measured axis skewness
  2211. float _deg(float rad)
  2212. {
  2213. return rad * 180 / M_PI;
  2214. }
  2215. //! @brief Show Measured XYZ Skew
  2216. //!
  2217. //! @code{.unparsed}
  2218. //! |01234567890123456789|
  2219. //! |Measured skew :0.00D| MSG_MEASURED_SKEW c=14
  2220. //! | -------------- | STR_SEPARATOR
  2221. //! |Slight skew :0.12D| MSG_SLIGHT_SKEW c=14
  2222. //! |Severe skew :0.25D| MSG_SEVERE_SKEW c=14
  2223. //! ----------------------
  2224. //! D - Degree sysmbol LCD_STR_DEGREE
  2225. //! @endcode
  2226. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2227. static void lcd_menu_xyz_skew()
  2228. {
  2229. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2230. lcd_home();
  2231. lcd_printf_P(_N(
  2232. "%-14.14S:\n"
  2233. "%S\n"
  2234. "%-14.14S:%3.2f\x01\n"
  2235. "%-14.14S:%3.2f\x01"
  2236. ),
  2237. _i("Measured skew"), ////MSG_MEASURED_SKEW c=14
  2238. separator,
  2239. _i("Slight skew"), _deg(bed_skew_angle_mild), ////MSG_SLIGHT_SKEW c=14
  2240. _i("Severe skew"), _deg(bed_skew_angle_extreme) ////MSG_SEVERE_SKEW c=14
  2241. );
  2242. if (angleDiff < 100){
  2243. lcd_set_cursor(15,0);
  2244. lcd_printf_P(_N("%3.2f\x01"), _deg(angleDiff));
  2245. }
  2246. else{
  2247. lcd_puts_at_P(15,0, _T(MSG_NA));
  2248. }
  2249. if (lcd_clicked())
  2250. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2251. }
  2252. //! @brief Show measured bed offset from expected position
  2253. //!
  2254. //! @code{.unparsed}
  2255. //! |01234567890123456789|
  2256. //! |[0;0] point offset | MSG_MEASURED_OFFSET c=20
  2257. //! | -------------- | STR_SEPARATOR
  2258. //! |X 00.00mm| c=10
  2259. //! |Y 00.00mm| c=10
  2260. //! ----------------------
  2261. //! @endcode
  2262. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2263. static void lcd_menu_xyz_offset()
  2264. {
  2265. lcd_puts_at_P(0, 0, _i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=20
  2266. lcd_puts_at_P(0, 1, separator);
  2267. lcd_puts_at_P(0, 2, PSTR("X"));
  2268. lcd_puts_at_P(0, 3, PSTR("Y"));
  2269. float vec_x[2];
  2270. float vec_y[2];
  2271. float cntr[2];
  2272. world2machine_read_valid(vec_x, vec_y, cntr);
  2273. for (uint_least8_t i = 0; i < 2; i++)
  2274. {
  2275. lcd_set_cursor((cntr[i] < 0) ? 13 : 14, i+2);
  2276. lcd_print(cntr[i]);
  2277. lcd_puts_at_P(18, i + 2, PSTR("mm"));
  2278. }
  2279. menu_back_if_clicked();
  2280. }
  2281. // Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten
  2282. // the implementation of menu_draw_float31
  2283. static void lcd_move_x() {
  2284. _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2285. }
  2286. static void lcd_move_y() {
  2287. _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2288. }
  2289. static void lcd_move_z() {
  2290. _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2291. }
  2292. /**
  2293. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2294. *
  2295. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2296. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2297. * Purpose of this function for other axis then Z is unknown.
  2298. *
  2299. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2300. * other value leads to storing Z_AXIS
  2301. * @param msg text to be displayed
  2302. */
  2303. static void lcd_babystep_z()
  2304. {
  2305. if (homing_flag || mesh_bed_leveling_flag)
  2306. {
  2307. // printer changed to a new state where live Z is forbidden
  2308. menu_back();
  2309. return;
  2310. }
  2311. typedef struct
  2312. {
  2313. int8_t status;
  2314. int16_t babystepMemZ;
  2315. float babystepMemMMZ;
  2316. } _menu_data_t;
  2317. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2318. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2319. if (_md->status == 0)
  2320. {
  2321. // Menu was entered.
  2322. // Initialize its status.
  2323. _md->status = 1;
  2324. check_babystep();
  2325. if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){
  2326. _md->babystepMemZ = 0;
  2327. }
  2328. else{
  2329. _md->babystepMemZ = eeprom_read_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->
  2330. s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)));
  2331. }
  2332. // same logic as in babystep_load
  2333. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2334. _md->babystepMemZ = 0;
  2335. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2336. lcd_draw_update = 1;
  2337. //SERIAL_ECHO("Z baby step: ");
  2338. //SERIAL_ECHO(_md->babystepMem[2]);
  2339. }
  2340. if (lcd_encoder != 0)
  2341. {
  2342. _md->babystepMemZ += (int)lcd_encoder;
  2343. if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2344. else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0
  2345. else babystepsTodoZadd(lcd_encoder);
  2346. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2347. _delay(50);
  2348. lcd_encoder = 0;
  2349. lcd_draw_update = 1;
  2350. }
  2351. if (lcd_draw_update)
  2352. {
  2353. SheetFormatBuffer buffer;
  2354. menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer);
  2355. lcd_set_cursor(0, 0);
  2356. lcd_print(buffer.c);
  2357. lcd_set_cursor(0, 1);
  2358. menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 // Beware: must include the ':' as its last character
  2359. }
  2360. if (LCD_CLICKED || menu_leaving)
  2361. {
  2362. // Only update the EEPROM when leaving the menu.
  2363. uint8_t active_sheet=eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  2364. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[active_sheet].z_offset)),_md->babystepMemZ);
  2365. // NOTE: bed_temp and pinda_temp are not currently read/used anywhere.
  2366. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].bed_temp),target_temperature_bed);
  2367. #ifdef PINDA_THERMISTOR
  2368. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].pinda_temp),current_temperature_pinda);
  2369. #endif //PINDA_THERMISTOR
  2370. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2371. }
  2372. if (LCD_CLICKED) menu_back();
  2373. }
  2374. typedef struct
  2375. { // 12bytes + 9bytes = 21bytes total
  2376. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2377. int8_t status; // 1byte
  2378. int16_t left; // 2byte
  2379. int16_t right; // 2byte
  2380. int16_t front; // 2byte
  2381. int16_t rear; // 2byte
  2382. } _menu_data_adjust_bed_t;
  2383. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2384. void lcd_adjust_bed_reset(void)
  2385. {
  2386. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2387. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2388. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2389. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2390. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2391. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2392. _md->status = 0;
  2393. }
  2394. //! @brief Show Bed level correct
  2395. //!
  2396. //! @code{.unparsed}
  2397. //! |01234567890123456789|
  2398. //! |Settings: | MSG_SETTINGS
  2399. //! |Left side [μm]: | MSG_BED_CORRECTION_LEFT
  2400. //! |Right side[μm]: | MSG_BED_CORRECTION_RIGHT
  2401. //! |Front side[μm]: | MSG_BED_CORRECTION_FRONT
  2402. //! |Rear side [μm]: | MSG_BED_CORRECTION_REAR
  2403. //! |Reset | MSG_BED_CORRECTION_RESET
  2404. //! ----------------------
  2405. //! @endcode
  2406. void lcd_adjust_bed(void)
  2407. {
  2408. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2409. if (_md->status == 0)
  2410. {
  2411. // Menu was entered.
  2412. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2413. {
  2414. _md->left = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_LEFT);
  2415. _md->right = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_RIGHT);
  2416. _md->front = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_FRONT);
  2417. _md->rear = (int8_t)eeprom_read_byte((uint8_t*)EEPROM_BED_CORRECTION_REAR);
  2418. }
  2419. _md->status = 1;
  2420. }
  2421. MENU_BEGIN();
  2422. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2423. ON_MENU_LEAVE(
  2424. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_LEFT, (uint8_t)_md->left);
  2425. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_FRONT, (uint8_t)_md->front);
  2426. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_REAR, (uint8_t)_md->rear);
  2427. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_RIGHT, (uint8_t)_md->right);
  2428. eeprom_update_byte((uint8_t*)EEPROM_BED_CORRECTION_VALID, 1);
  2429. );
  2430. MENU_ITEM_BACK_P(_T(MSG_BACK));
  2431. MENU_ITEM_EDIT_int3_P(_i("Left side [\xe4m]"), &_md->left, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14
  2432. MENU_ITEM_EDIT_int3_P(_i("Right side[\xe4m]"), &_md->right, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14
  2433. MENU_ITEM_EDIT_int3_P(_i("Front side[\xe4m]"), &_md->front, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14
  2434. MENU_ITEM_EDIT_int3_P(_i("Rear side [\xe4m]"), &_md->rear, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14
  2435. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_adjust_bed_reset);
  2436. MENU_END();
  2437. }
  2438. //! @brief Show PID Extruder
  2439. //!
  2440. //! @code{.unparsed}
  2441. //! |01234567890123456789|
  2442. //! |Set temperature: |
  2443. //! | |
  2444. //! | 210 |
  2445. //! | |
  2446. //! ----------------------
  2447. //! @endcode
  2448. void pid_extruder()
  2449. {
  2450. lcd_clear();
  2451. lcd_puts_at_P(0, 0, _i("Set temperature:"));////MSG_SET_TEMPERATURE c=20
  2452. pid_temp += int(lcd_encoder);
  2453. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2454. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2455. lcd_encoder = 0;
  2456. lcd_set_cursor(1, 2);
  2457. lcd_printf_P(PSTR("%3u"), pid_temp);
  2458. if (lcd_clicked()) {
  2459. lcd_commands_type = LcdCommands::PidExtruder;
  2460. lcd_return_to_status();
  2461. lcd_update(2);
  2462. }
  2463. }
  2464. #ifdef PINDA_THERMISTOR
  2465. bool lcd_wait_for_pinda(float temp) {
  2466. setAllTargetHotends(0);
  2467. setTargetBed(0);
  2468. LongTimer pinda_timeout;
  2469. pinda_timeout.start();
  2470. bool target_temp_reached = true;
  2471. while (current_temperature_pinda > temp){
  2472. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2473. lcd_set_cursor(0, 4);
  2474. lcd_print(LCD_STR_THERMOMETER[0]);
  2475. lcd_printf_P(PSTR("%3d/%3d"), (int16_t)current_temperature_pinda, (int16_t) temp);
  2476. lcd_print(LCD_STR_DEGREE[0]);
  2477. delay_keep_alive(1000);
  2478. serialecho_temperatures();
  2479. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2480. target_temp_reached = false;
  2481. break;
  2482. }
  2483. }
  2484. lcd_update_enable(true);
  2485. return target_temp_reached;
  2486. }
  2487. #endif //PINDA_THERMISTOR
  2488. void lcd_wait_for_heater() {
  2489. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2490. lcd_set_cursor(0, 4);
  2491. lcd_print(LCD_STR_THERMOMETER[0]);
  2492. lcd_printf_P(PSTR("%3d/%3d"), (int16_t)degHotend(active_extruder), (int16_t) degTargetHotend(active_extruder));
  2493. lcd_print(LCD_STR_DEGREE[0]);
  2494. }
  2495. void lcd_wait_for_cool_down() {
  2496. setAllTargetHotends(0);
  2497. setTargetBed(0);
  2498. int fanSpeedBckp = fanSpeed;
  2499. fanSpeed = 255;
  2500. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2501. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=4
  2502. lcd_set_cursor(0, 4);
  2503. lcd_print(LCD_STR_THERMOMETER[0]);
  2504. lcd_printf_P(PSTR("%3d/0"), (int16_t)degHotend(0));
  2505. lcd_print(LCD_STR_DEGREE[0]);
  2506. lcd_set_cursor(9, 4);
  2507. lcd_print(LCD_STR_BEDTEMP[0]);
  2508. lcd_printf_P(PSTR("%3d/0"), (int16_t)degBed());
  2509. lcd_print(LCD_STR_DEGREE[0]);
  2510. delay_keep_alive(1000);
  2511. serialecho_temperatures();
  2512. }
  2513. fanSpeed = fanSpeedBckp;
  2514. lcd_update_enable(true);
  2515. }
  2516. // Lets the user move the Z carriage up to the end stoppers.
  2517. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2518. // Otherwise the Z calibration is not changed and false is returned.
  2519. #ifndef TMC2130
  2520. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2521. {
  2522. // Don't know where we are. Let's claim we are Z=0, so the soft end stops will not be triggered when moving up.
  2523. current_position[Z_AXIS] = 0;
  2524. plan_set_position_curposXYZE();
  2525. // Until confirmed by the confirmation dialog.
  2526. for (;;) {
  2527. const char *msg = only_z
  2528. ? _i("Calibrating Z. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.")////MSG_MOVE_CARRIAGE_TO_THE_TOP_Z c=20 r=8
  2529. : _i("Calibrating XYZ. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.");////MSG_MOVE_CARRIAGE_TO_THE_TOP c=20 r=8
  2530. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2531. const bool multi_screen = msg_next != NULL;
  2532. unsigned long previous_millis_msg = _millis();
  2533. // Until the user finishes the z up movement.
  2534. lcd_encoder_diff = 0;
  2535. lcd_encoder = 0;
  2536. for (;;) {
  2537. manage_heater();
  2538. manage_inactivity(true);
  2539. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2540. _delay(50);
  2541. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2542. lcd_encoder_diff = 0;
  2543. if (! planner_queue_full()) {
  2544. // Only move up, whatever direction the user rotates the encoder.
  2545. current_position[Z_AXIS] += fabs(lcd_encoder);
  2546. lcd_encoder = 0;
  2547. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  2548. }
  2549. }
  2550. if (lcd_clicked()) {
  2551. // Abort a move if in progress.
  2552. planner_abort_hard();
  2553. planner_aborted = false;
  2554. while (lcd_clicked()) ;
  2555. _delay(10);
  2556. while (lcd_clicked()) ;
  2557. break;
  2558. }
  2559. if (multi_screen && _millis() - previous_millis_msg > 5000) {
  2560. if (msg_next == NULL)
  2561. msg_next = msg;
  2562. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2563. previous_millis_msg = _millis();
  2564. }
  2565. }
  2566. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2567. uint8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Are left and right Z~carriages all up?"), false);////MSG_CONFIRM_CARRIAGE_AT_THE_TOP c=20 r=2
  2568. if (result == LCD_BUTTON_TIMEOUT)
  2569. goto canceled;
  2570. else if (result == LCD_LEFT_BUTTON_CHOICE)
  2571. goto calibrated;
  2572. // otherwise perform another round of the Z up dialog.
  2573. }
  2574. calibrated:
  2575. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2576. // during the search for the induction points.
  2577. if ((PRINTER_TYPE == PRINTER_MK25) || (PRINTER_TYPE == PRINTER_MK2) || (PRINTER_TYPE == PRINTER_MK2_SNMM)) {
  2578. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2579. }
  2580. else {
  2581. current_position[Z_AXIS] = Z_MAX_POS+4.f;
  2582. }
  2583. plan_set_position_curposXYZE();
  2584. return true;
  2585. canceled:
  2586. return false;
  2587. }
  2588. #endif // TMC2130
  2589. static inline bool pgm_is_whitespace(const char *c_addr)
  2590. {
  2591. const char c = pgm_read_byte(c_addr);
  2592. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2593. }
  2594. static inline bool pgm_is_interpunction(const char *c_addr)
  2595. {
  2596. const char c = pgm_read_byte(c_addr);
  2597. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2598. }
  2599. /**
  2600. * @brief show full screen message
  2601. *
  2602. * This function is non-blocking
  2603. * @param msg message to be displayed from PROGMEM
  2604. * @return rest of the text (to be displayed on next page)
  2605. */
  2606. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg)
  2607. {
  2608. lcd_set_cursor(0, 0);
  2609. const char *msgend = msg;
  2610. uint8_t row = 0;
  2611. bool multi_screen = false;
  2612. for (; row < 4; ++ row) {
  2613. while (pgm_is_whitespace(msg))
  2614. ++ msg;
  2615. if (pgm_read_byte(msg) == 0)
  2616. // End of the message.
  2617. break;
  2618. lcd_set_cursor(0, row);
  2619. uint8_t linelen = min(strlen_P(msg), LCD_WIDTH);
  2620. const char *msgend2 = msg + linelen;
  2621. msgend = msgend2;
  2622. if (row == 3 && linelen == LCD_WIDTH) {
  2623. // Last line of the display, full line shall be displayed.
  2624. // Find out, whether this message will be split into multiple screens.
  2625. while (pgm_is_whitespace(msgend))
  2626. ++ msgend;
  2627. multi_screen = pgm_read_byte(msgend) != 0;
  2628. if (multi_screen)
  2629. msgend = (msgend2 -= 2);
  2630. }
  2631. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2632. // Splitting a word. Find the start of the current word.
  2633. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2634. -- msgend;
  2635. if (msgend == msg)
  2636. // Found a single long word, which cannot be split. Just cut it.
  2637. msgend = msgend2;
  2638. }
  2639. for (; msg < msgend; ++ msg) {
  2640. char c = char(pgm_read_byte(msg));
  2641. if (c == '~')
  2642. c = ' ';
  2643. lcd_print(c);
  2644. }
  2645. }
  2646. if (multi_screen) {
  2647. // Display the "next screen" indicator character.
  2648. lcd_set_custom_characters_nextpage();
  2649. lcd_set_cursor(19, 3);
  2650. // Display the double down arrow.
  2651. lcd_print(LCD_STR_ARROW_2_DOWN[0]);
  2652. }
  2653. return multi_screen ? msgend : NULL;
  2654. }
  2655. const char* lcd_display_message_fullscreen_P(const char *msg)
  2656. {
  2657. // Disable update of the screen by the usual lcd_update(0) routine.
  2658. lcd_update_enable(false);
  2659. lcd_clear();
  2660. return lcd_display_message_fullscreen_nonBlocking_P(msg);
  2661. }
  2662. /**
  2663. * @brief show full screen message and wait
  2664. *
  2665. * This function is blocking.
  2666. * @param msg message to be displayed from PROGMEM
  2667. */
  2668. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2669. {
  2670. LcdUpdateDisabler lcdUpdateDisabler;
  2671. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2672. bool multi_screen = msg_next != NULL;
  2673. lcd_set_custom_characters_nextpage();
  2674. lcd_consume_click();
  2675. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2676. // Until confirmed by a button click.
  2677. for (;;) {
  2678. if (!multi_screen) {
  2679. lcd_set_cursor(19, 3);
  2680. // Display the confirm char.
  2681. lcd_print(LCD_STR_CONFIRM[0]);
  2682. }
  2683. // Wait for 5 seconds before displaying the next text.
  2684. for (uint8_t i = 0; i < 100; ++ i) {
  2685. delay_keep_alive(50);
  2686. if (lcd_clicked()) {
  2687. if (msg_next == NULL) {
  2688. KEEPALIVE_STATE(IN_HANDLER);
  2689. lcd_set_custom_characters();
  2690. return;
  2691. }
  2692. else {
  2693. break;
  2694. }
  2695. }
  2696. }
  2697. if (multi_screen) {
  2698. if (msg_next == NULL)
  2699. msg_next = msg;
  2700. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2701. if (msg_next == NULL) {
  2702. lcd_set_cursor(19, 3);
  2703. // Display the confirm char.
  2704. lcd_print(LCD_STR_CONFIRM[0]);
  2705. }
  2706. }
  2707. }
  2708. }
  2709. bool lcd_wait_for_click_delay(uint16_t nDelay)
  2710. // nDelay :: timeout [s] (0 ~ no timeout)
  2711. // true ~ clicked, false ~ delayed
  2712. {
  2713. bool bDelayed;
  2714. long nTime0 = _millis()/1000;
  2715. lcd_consume_click();
  2716. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2717. for (;;) {
  2718. manage_heater();
  2719. manage_inactivity(true);
  2720. bDelayed = ((_millis()/1000-nTime0) > nDelay);
  2721. bDelayed = (bDelayed && (nDelay != 0)); // 0 ~ no timeout, always waiting for click
  2722. if (lcd_clicked() || bDelayed) {
  2723. KEEPALIVE_STATE(IN_HANDLER);
  2724. return(!bDelayed);
  2725. }
  2726. }
  2727. }
  2728. void lcd_wait_for_click()
  2729. {
  2730. lcd_wait_for_click_delay(0);
  2731. }
  2732. //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
  2733. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2734. //! @param allow_timeouting if true, allows time outing of the screen
  2735. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2736. //! @retval 0 yes choice selected by user
  2737. //! @retval 1 no choice selected by user
  2738. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2739. uint8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, uint8_t default_selection) //currently just max. n*4 + 3 lines supported (set in language header files)
  2740. {
  2741. return lcd_show_multiscreen_message_with_choices_and_wait_P(msg, allow_timeouting, default_selection, _T(MSG_YES), _T(MSG_NO), nullptr, 10);
  2742. }
  2743. //! @brief Show a two-choice prompt on the last line of the LCD
  2744. //! @param selected Show first choice as selected if true, the second otherwise
  2745. //! @param first_choice text caption of first possible choice
  2746. //! @param second_choice text caption of second possible choice
  2747. //! @param second_col column on LCD where second choice is rendered.
  2748. //! @param third_choice text caption of third, optional, choice.
  2749. void lcd_show_choices_prompt_P(uint8_t selected, const char *first_choice, const char *second_choice, uint8_t second_col, const char *third_choice)
  2750. {
  2751. lcd_set_cursor(0, 3);
  2752. lcd_print(selected == LCD_LEFT_BUTTON_CHOICE ? '>': ' ');
  2753. lcd_puts_P(first_choice);
  2754. lcd_set_cursor(second_col, 3);
  2755. lcd_print(selected == LCD_MIDDLE_BUTTON_CHOICE ? '>': ' ');
  2756. lcd_puts_P(second_choice);
  2757. if (third_choice)
  2758. {
  2759. lcd_set_cursor(18, 3);
  2760. lcd_print(selected == LCD_RIGHT_BUTTON_CHOICE ? '>': ' ');
  2761. lcd_puts_P(third_choice);
  2762. }
  2763. }
  2764. //! @brief Show single or multiple screen message with two possible choices and wait with possible timeout
  2765. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2766. //! @param allow_timeouting bool, if true, allows time outing of the screen
  2767. //! @param default_selection uint8_t, Control which choice is selected first. 0: left most, 1: middle, 2: right most choice. The left most choice is selected by default
  2768. //! @param first_choice text caption of first possible choice. Must be in PROGMEM
  2769. //! @param second_choice text caption of second possible choice. Must be in PROGMEM
  2770. //! @param third_choice text caption of second possible choice. Must be in PROGMEM. When not set to nullptr first_choice and second_choice may not be more than 5 characters long.
  2771. //! @param second_col column on LCD where second_choice starts
  2772. //! @retval 0 first choice selected by user
  2773. //! @retval 1 first choice selected by user
  2774. //! @retval 2 third choice selected by user
  2775. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2776. uint8_t lcd_show_multiscreen_message_with_choices_and_wait_P(
  2777. const char *const msg, bool allow_timeouting, uint8_t default_selection,
  2778. const char *const first_choice, const char *const second_choice, const char *const third_choice,
  2779. uint8_t second_col
  2780. ) {
  2781. const char *msg_next = msg ? lcd_display_message_fullscreen_P(msg) : NULL;
  2782. bool multi_screen = msg_next != NULL;
  2783. lcd_set_custom_characters_nextpage();
  2784. // Initial status/prompt on single-screen messages
  2785. uint8_t current_selection = default_selection;
  2786. if (!msg_next) {
  2787. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2788. }
  2789. // Wait for user confirmation or a timeout.
  2790. unsigned long previous_millis_cmd = _millis();
  2791. int8_t enc_dif = lcd_encoder_diff;
  2792. lcd_consume_click();
  2793. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2794. for (;;) {
  2795. for (uint8_t i = 0; i < 100; ++i) {
  2796. delay_keep_alive(50);
  2797. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS) {
  2798. return LCD_BUTTON_TIMEOUT;
  2799. }
  2800. manage_heater();
  2801. manage_inactivity(true);
  2802. if (abs(enc_dif - lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2803. if (msg_next == NULL) {
  2804. if (third_choice) { // third_choice is not nullptr, safe to dereference
  2805. if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) {
  2806. // Rotating knob counter clockwise
  2807. current_selection--;
  2808. } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_RIGHT_BUTTON_CHOICE) {
  2809. // Rotating knob clockwise
  2810. current_selection++;
  2811. }
  2812. } else {
  2813. if (enc_dif > lcd_encoder_diff && current_selection != LCD_LEFT_BUTTON_CHOICE) {
  2814. // Rotating knob counter clockwise
  2815. current_selection = LCD_LEFT_BUTTON_CHOICE;
  2816. } else if (enc_dif < lcd_encoder_diff && current_selection != LCD_MIDDLE_BUTTON_CHOICE) {
  2817. // Rotating knob clockwise
  2818. current_selection = LCD_MIDDLE_BUTTON_CHOICE;
  2819. }
  2820. }
  2821. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2822. enc_dif = lcd_encoder_diff;
  2823. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2824. } else {
  2825. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2826. break; // turning knob skips waiting loop
  2827. }
  2828. }
  2829. if (lcd_clicked()) {
  2830. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2831. if (msg_next == NULL) {
  2832. KEEPALIVE_STATE(IN_HANDLER);
  2833. lcd_set_custom_characters();
  2834. lcd_update_enable(true);
  2835. return current_selection;
  2836. } else
  2837. break;
  2838. }
  2839. }
  2840. if (multi_screen) {
  2841. if (msg_next == NULL) {
  2842. msg_next = msg;
  2843. }
  2844. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2845. }
  2846. if (msg_next == NULL) {
  2847. lcd_show_choices_prompt_P(current_selection, first_choice, second_choice, second_col, third_choice);
  2848. }
  2849. }
  2850. }
  2851. //! @brief Display and wait for a Yes/No choice using the last line of the LCD
  2852. //! @param allow_timeouting if true, allows time outing of the screen
  2853. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2854. //! @retval 0 yes choice selected by user
  2855. //! @retval 1 no choice selected by user
  2856. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2857. uint8_t lcd_show_yes_no_and_wait(bool allow_timeouting, uint8_t default_selection)
  2858. {
  2859. return lcd_show_multiscreen_message_yes_no_and_wait_P(NULL, allow_timeouting, default_selection);
  2860. }
  2861. //! @brief Show single screen message with yes and no possible choices and wait with possible timeout
  2862. //! @param msg Message to show. If NULL, do not clear the screen and handle choice selection only.
  2863. //! @param allow_timeouting if true, allows time outing of the screen
  2864. //! @param default_selection if 0, 'Yes' choice is selected by default, otherwise 'No' choice is preselected
  2865. //! @retval 0 yes choice selected by user
  2866. //! @retval 1 no choice selected by user
  2867. //! @retval 0xFF button timeout (only possible if allow_timeouting is true)
  2868. //! @relates lcd_show_yes_no_and_wait
  2869. uint8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, uint8_t default_selection)
  2870. {
  2871. return lcd_show_multiscreen_message_yes_no_and_wait_P(msg, allow_timeouting, default_selection);
  2872. }
  2873. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2874. {
  2875. const char *msg = NULL;
  2876. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2877. lcd_show_fullscreen_message_and_wait_P(_i("XYZ calibration failed. Bed calibration point was not found."));////MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND c=20 r=6
  2878. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2879. if (point_too_far_mask == 0)
  2880. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2881. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2882. // Only the center point or all the three front points.
  2883. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=6
  2884. else if ((point_too_far_mask & 1) == 0)
  2885. // The right and maybe the center point out of reach.
  2886. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=6
  2887. else
  2888. // The left and maybe the center point out of reach. //@todo Why isn't it found in the firmware.map
  2889. msg = _n("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  2890. lcd_show_fullscreen_message_and_wait_P(msg);
  2891. } else {
  2892. if (point_too_far_mask != 0) {
  2893. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2894. // Only the center point or all the three front points.
  2895. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  2896. else if ((point_too_far_mask & 1) == 0)
  2897. // The right and maybe the center point out of reach.
  2898. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  2899. else
  2900. // The left and maybe the center point out of reach. //@todo Why isn't it found in the firmware.map
  2901. msg = _n("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  2902. lcd_show_fullscreen_message_and_wait_P(msg);
  2903. }
  2904. if (point_too_far_mask == 0 || result > 0) {
  2905. switch (result) {
  2906. default:
  2907. // should not happen
  2908. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2909. break;
  2910. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  2911. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  2912. break;
  2913. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  2914. msg = _i("XYZ calibration all right. X/Y axes are slightly skewed. Good job!");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD c=20 r=8
  2915. break;
  2916. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  2917. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  2918. break;
  2919. }
  2920. lcd_show_fullscreen_message_and_wait_P(msg);
  2921. }
  2922. }
  2923. }
  2924. void lcd_temp_cal_show_result(bool result) {
  2925. custom_message_type = CustomMsg::Status;
  2926. disable_x();
  2927. disable_y();
  2928. disable_z();
  2929. disable_e0();
  2930. disable_e1();
  2931. disable_e2();
  2932. setTargetBed(0); //set bed target temperature back to 0
  2933. if (result == true) {
  2934. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  2935. SERIAL_ECHOLNPGM("PINDA calibration done. Continue with pressing the knob.");
  2936. lcd_show_fullscreen_message_and_wait_P(_T(MSG_PINDA_CALIBRATION_DONE));
  2937. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  2938. }
  2939. else {
  2940. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  2941. SERIAL_ECHOLNPGM("PINDA calibration failed. Continue with pressing the knob.");
  2942. lcd_show_fullscreen_message_and_wait_P(_i("PINDA calibration failed"));////MSG_PINDA_CAL_FAILED c=20 r=4
  2943. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  2944. }
  2945. lcd_update_enable(true);
  2946. lcd_update(2);
  2947. }
  2948. static void lcd_show_end_stops() {
  2949. lcd_puts_at_P(0, 0, (PSTR("End stops diag")));
  2950. lcd_puts_at_P(0, 1, (READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  2951. lcd_puts_at_P(0, 2, (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  2952. lcd_puts_at_P(0, 3, (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  2953. }
  2954. #ifndef TMC2130
  2955. static void menu_show_end_stops() {
  2956. lcd_show_end_stops();
  2957. if (LCD_CLICKED) menu_back();
  2958. }
  2959. #endif // not defined TMC2130
  2960. // Lets the user move the Z carriage up to the end stoppers.
  2961. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2962. // Otherwise the Z calibration is not changed and false is returned.
  2963. void lcd_diag_show_end_stops()
  2964. {
  2965. lcd_clear();
  2966. lcd_consume_click();
  2967. for (;;) {
  2968. manage_heater();
  2969. manage_inactivity(true);
  2970. lcd_show_end_stops();
  2971. if (lcd_clicked()) {
  2972. break;
  2973. }
  2974. }
  2975. lcd_clear();
  2976. lcd_return_to_status();
  2977. }
  2978. static void lcd_print_state(uint8_t state)
  2979. {
  2980. switch (state) {
  2981. case STATE_ON:
  2982. lcd_puts_P(_N(" 1"));
  2983. break;
  2984. case STATE_OFF:
  2985. lcd_puts_P(_N(" 0"));
  2986. break;
  2987. default:
  2988. lcd_puts_P(_T(MSG_NA));
  2989. break;
  2990. }
  2991. }
  2992. //! @brief Show sensor state
  2993. //!
  2994. //! @code{.unparsed}
  2995. //! |01234567890123456789|
  2996. //! |PINDA N/A FINDA N/A| MSG_PINDA c=5 MSG_FINDA c=5
  2997. //! |Fil. sensor N/A| MSG_FSENSOR
  2998. //! | Int: 000 Xd:+00000|
  2999. //! |Shut: 000 Yd:+00000|
  3000. //! ----------------------
  3001. //! @endcode
  3002. static void lcd_show_sensors_state()
  3003. {
  3004. //0: N/A; 1: OFF; 2: ON
  3005. uint8_t pinda_state = STATE_NA;
  3006. uint8_t finda_state = STATE_NA;
  3007. uint8_t idler_state = STATE_NA;
  3008. pinda_state = READ(Z_MIN_PIN);
  3009. if (MMU2::mmu2.Enabled())
  3010. {
  3011. finda_state = MMU2::mmu2.FindaDetectsFilament();
  3012. }
  3013. lcd_puts_at_P(0, 0, MSG_PINDA);
  3014. lcd_set_cursor(LCD_WIDTH - 14, 0);
  3015. lcd_print_state(pinda_state);
  3016. if (MMU2::mmu2.Enabled())
  3017. {
  3018. lcd_puts_at_P(10, 0, _n("FINDA"));////MSG_FINDA c=5
  3019. lcd_set_cursor(LCD_WIDTH - 3, 0);
  3020. lcd_print_state(finda_state);
  3021. }
  3022. #ifdef FILAMENT_SENSOR
  3023. idler_state = fsensor.getFilamentPresent();
  3024. lcd_puts_at_P(0, 1, _T(MSG_FSENSOR));
  3025. lcd_set_cursor(LCD_WIDTH - 3, 1);
  3026. lcd_print_state(idler_state);
  3027. #endif //FILAMENT_SENSOR
  3028. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3029. // Display X and Y difference from Filament sensor
  3030. // Display Light intensity from Filament sensor
  3031. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  3032. // value ranges from 0(darkest) to 255(brightest).
  3033. // Display LASER shutter time from Filament sensor
  3034. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  3035. // auto-exposure algorithm. When the chip is tracking on a reflective surface, the Shutter is small.
  3036. // When the chip is tracking on a surface that absorbs IR (or doesn't reflect it), the Shutter is large.
  3037. // The maximum value of the shutter is 17. The value of 16 seems to be reported as 17 even though the
  3038. // Brightness value changes correctly as if the shutter changed to 16 (probably some bug with the sensor).
  3039. // The shutter algorithm tries to keep the B value in the 70-110 range.
  3040. lcd_set_cursor(0, 2);
  3041. lcd_printf_P(_N("B: %3d Xd:%6d\n"
  3042. "S: %3d Yd:%6d"),
  3043. pat9125_b, pat9125_x,
  3044. pat9125_s, pat9125_y);
  3045. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3046. }
  3047. void lcd_menu_show_sensors_state() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()")
  3048. {
  3049. lcd_timeoutToStatus.stop();
  3050. lcd_show_sensors_state();
  3051. menu_back_if_clicked();
  3052. }
  3053. void lcd_move_menu_axis()
  3054. {
  3055. MENU_BEGIN();
  3056. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3057. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=18
  3058. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=18
  3059. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=18
  3060. MENU_ITEM_SUBMENU_P(_T(MSG_EXTRUDER), lcd_move_e);
  3061. MENU_END();
  3062. }
  3063. #ifdef SDCARD_SORT_ALPHA
  3064. static void lcd_sort_type_set() {
  3065. uint8_t sdSort;
  3066. sdSort = eeprom_read_byte((uint8_t*) EEPROM_SD_SORT);
  3067. switch (sdSort) {
  3068. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3069. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3070. default: sdSort = SD_SORT_TIME;
  3071. }
  3072. eeprom_update_byte((uint8_t*)EEPROM_SD_SORT, sdSort);
  3073. card.presort_flag = true;
  3074. }
  3075. #endif //SDCARD_SORT_ALPHA
  3076. #ifdef TMC2130
  3077. static void lcd_crash_mode_info()
  3078. {
  3079. lcd_update_enable(true);
  3080. static uint32_t tim = 0;
  3081. if ((tim + 1000) < _millis())
  3082. {
  3083. lcd_clear();
  3084. fputs_P(_i("Crash detection can\nbe turned on only in\nNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3085. tim = _millis();
  3086. }
  3087. menu_back_if_clicked();
  3088. }
  3089. static void lcd_crash_mode_info2()
  3090. {
  3091. lcd_update_enable(true);
  3092. static uint32_t tim = 0;
  3093. if ((tim + 1000) < _millis())
  3094. {
  3095. lcd_clear();
  3096. fputs_P(_i("WARNING:\nCrash detection\ndisabled in\nStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3097. tim = _millis();
  3098. }
  3099. menu_back_if_clicked();
  3100. }
  3101. #endif //TMC2130
  3102. //-//
  3103. static void lcd_sound_state_set(void)
  3104. {
  3105. Sound_CycleState();
  3106. }
  3107. #ifndef MMU_FORCE_STEALTH_MODE
  3108. static void lcd_silent_mode_mmu_set() {
  3109. if (SilentModeMenu_MMU == 1) SilentModeMenu_MMU = 0;
  3110. else SilentModeMenu_MMU = 1;
  3111. //saving to eeprom is done in mmu_loop() after mmu actually switches state and confirms with "ok"
  3112. }
  3113. #endif //MMU_FORCE_STEALTH_MODE
  3114. static void lcd_silent_mode_set() {
  3115. switch (SilentModeMenu) {
  3116. #ifdef TMC2130
  3117. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3118. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3119. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3120. #else
  3121. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3122. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3123. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3124. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3125. #endif //TMC2130
  3126. }
  3127. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3128. #ifdef TMC2130
  3129. lcd_display_message_fullscreen_P(_i("Mode change in progress..."));////MSG_MODE_CHANGE_IN_PROGRESS c=20 r=3
  3130. // Wait until the planner queue is drained and the stepper routine achieves
  3131. // an idle state.
  3132. st_synchronize();
  3133. if (tmc2130_wait_standstill_xy(1000)) {}
  3134. // MYSERIAL.print("standstill OK");
  3135. // else
  3136. // MYSERIAL.print("standstill NG!");
  3137. cli();
  3138. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3139. update_mode_profile();
  3140. tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  3141. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3142. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3143. st_reset_timer();
  3144. sei();
  3145. #endif //TMC2130
  3146. st_current_init();
  3147. #ifdef TMC2130
  3148. if (lcd_crash_detect_enabled() && (SilentModeMenu != SILENT_MODE_NORMAL))
  3149. menu_submenu(lcd_crash_mode_info2);
  3150. lcd_encoder_diff=0; // reset 'encoder buffer'
  3151. #endif //TMC2130
  3152. }
  3153. #ifdef TMC2130
  3154. static void crash_mode_switch()
  3155. {
  3156. if (lcd_crash_detect_enabled())
  3157. {
  3158. lcd_crash_detect_disable();
  3159. }
  3160. else
  3161. {
  3162. lcd_crash_detect_enable();
  3163. }
  3164. if (IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true);
  3165. else menu_goto(lcd_settings_menu, 9, true, true);
  3166. }
  3167. #endif //TMC2130
  3168. #if (LANG_MODE != 0)
  3169. void menu_setlang(unsigned char lang)
  3170. {
  3171. if (!lang_select(lang))
  3172. {
  3173. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language?"), false, LCD_LEFT_BUTTON_CHOICE) == LCD_LEFT_BUTTON_CHOICE)////MSG_COPY_SEL_LANG c=20 r=3
  3174. lang_boot_update_start(lang);
  3175. lcd_update_enable(true);
  3176. lcd_clear();
  3177. menu_goto(lcd_language_menu, 0, true, true);
  3178. lcd_timeoutToStatus.stop(); //infinite timeout
  3179. lcd_draw_update = 2;
  3180. }
  3181. }
  3182. #ifdef COMMUNITY_LANGUAGE_SUPPORT
  3183. #ifdef XFLASH
  3184. static void lcd_community_language_menu()
  3185. {
  3186. MENU_BEGIN();
  3187. uint8_t cnt = lang_get_count();
  3188. MENU_ITEM_BACK_P(_T(MSG_SELECT_LANGUAGE)); //Back to previous Menu
  3189. for (int i = 8; i < cnt; i++) //all community languages
  3190. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3191. {
  3192. menu_setlang(i);
  3193. return;
  3194. }
  3195. MENU_END();
  3196. }
  3197. #endif //XFLASH
  3198. #endif //COMMUNITY_LANGUAGE_SUPPORT && W52X20CL
  3199. static void lcd_language_menu()
  3200. {
  3201. MENU_BEGIN();
  3202. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3203. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3204. {
  3205. menu_setlang(0);
  3206. return;
  3207. }
  3208. uint8_t cnt = lang_get_count();
  3209. #ifdef XFLASH
  3210. if (cnt == 2) //display secondary language in case of clear xflash
  3211. {
  3212. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3213. {
  3214. menu_setlang(1);
  3215. return;
  3216. }
  3217. }
  3218. else
  3219. for (int i = 2; i < 8; i++) //skip seconday language - solved in lang_select (MK3) 'i < 8' for 7 official languages
  3220. #else //XFLASH
  3221. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3222. #endif //XFLASH
  3223. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3224. {
  3225. menu_setlang(i);
  3226. return;
  3227. }
  3228. #ifdef COMMUNITY_LANGUAGE_SUPPORT
  3229. #ifdef XFLASH
  3230. MENU_ITEM_SUBMENU_P(_T(MSG_COMMUNITY_MADE), lcd_community_language_menu);
  3231. #endif //XFLASH
  3232. #endif //COMMUNITY_LANGUAGE_SUPPORT && W52X20CL
  3233. MENU_END();
  3234. }
  3235. #endif //(LANG_MODE != 0)
  3236. void lcd_mesh_bedleveling()
  3237. {
  3238. enquecommand_P(PSTR("G80"));
  3239. lcd_return_to_status();
  3240. }
  3241. void lcd_mesh_calibration()
  3242. {
  3243. enquecommand_P(PSTR("M45"));
  3244. lcd_return_to_status();
  3245. }
  3246. void lcd_mesh_calibration_z()
  3247. {
  3248. enquecommand_P(PSTR("M45 Z"));
  3249. lcd_return_to_status();
  3250. }
  3251. void lcd_temp_calibration_set() {
  3252. bool temp_cal_active = eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE);
  3253. temp_cal_active = !temp_cal_active;
  3254. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3255. }
  3256. #ifdef HAS_SECOND_SERIAL_PORT
  3257. void lcd_second_serial_set() {
  3258. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3259. else selectedSerialPort = 1;
  3260. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3261. MYSERIAL.begin(BAUDRATE);
  3262. }
  3263. #endif //HAS_SECOND_SERIAL_PORT
  3264. void lcd_calibrate_pinda() {
  3265. enquecommand_P(PSTR("G76"));
  3266. lcd_return_to_status();
  3267. }
  3268. void lcd_toshiba_flash_air_compatibility_toggle()
  3269. {
  3270. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3271. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3272. }
  3273. //! @brief Continue first layer calibration with previous value or start from zero?
  3274. //!
  3275. //! @code{.unparsed}
  3276. //! |01234567890123456789|
  3277. //! |Sheet Smooth1| MSG_SHEET c=12, MSG_SHEET_NAME c=7
  3278. //! |Z offset: -1.480mm| MSG_Z_OFFSET c=11
  3279. //! |>Continue | MSG_CONTINUE
  3280. //! | Reset | MSG_RESET
  3281. //! ----------------------
  3282. //! @endcode
  3283. void lcd_first_layer_calibration_reset()
  3284. {
  3285. typedef struct
  3286. {
  3287. bool reset;
  3288. } MenuData;
  3289. static_assert(sizeof(menu_data)>= sizeof(MenuData),"_menu_data_t doesn't fit into menu_data");
  3290. MenuData* menuData = (MenuData*)&(menu_data[0]);
  3291. if(LCD_CLICKED || !eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) ||
  3292. (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) ||
  3293. (0 == static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>
  3294. (&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))))
  3295. {
  3296. if (menuData->reset)
  3297. {
  3298. eeprom_update_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset), 0xffff);
  3299. }
  3300. menu_goto(lcd_v2_calibration,0,true,true);
  3301. }
  3302. if (lcd_encoder > 0)
  3303. {
  3304. menuData->reset = true;
  3305. lcd_encoder = 1;
  3306. }
  3307. else if (lcd_encoder < 1)
  3308. {
  3309. menuData->reset = false;
  3310. lcd_encoder = 0;
  3311. }
  3312. char sheet_name[sizeof(Sheet::name)];
  3313. eeprom_read_block(sheet_name, &EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].name, sizeof(Sheet::name));
  3314. lcd_set_cursor(0, 0);
  3315. float offset = static_cast<int16_t>(eeprom_read_word(reinterpret_cast<uint16_t*>(&EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)))/cs.axis_steps_per_unit[Z_AXIS];
  3316. lcd_printf_P(_i("Sheet %.7s\nZ offset: %+1.3fmm\n%cContinue\n%cReset"),////MSG_SHEET_OFFSET c=20 r=4
  3317. sheet_name, offset, menuData->reset ? ' ' : '>', menuData->reset ? '>' : ' ');// \n denotes line break, %.7s is replaced by 7 character long sheet name, %+1.3f is replaced by 6 character long floating point number, %c is replaced by > or white space (one character) based on whether first or second option is selected. % denoted place holders can not be reordered.
  3318. }
  3319. void lcd_v2_calibration()
  3320. {
  3321. if (MMU2::mmu2.Enabled())
  3322. {
  3323. const uint8_t filament = choose_menu_P(
  3324. _T(MSG_SELECT_FILAMENT),
  3325. _T(MSG_FILAMENT),(_T(MSG_CANCEL)+1)); //Hack to reuse MSG but strip 1st char off
  3326. if (filament < 5)
  3327. {
  3328. lay1cal_filament = filament;
  3329. }
  3330. else
  3331. {
  3332. menu_back();
  3333. return;
  3334. }
  3335. }
  3336. #ifdef FILAMENT_SENSOR
  3337. else if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  3338. {
  3339. bool loaded = false;
  3340. if (fsensor.isReady())
  3341. {
  3342. loaded = fsensor.getFilamentPresent();
  3343. }
  3344. else
  3345. {
  3346. loaded = !lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), false, LCD_LEFT_BUTTON_CHOICE);
  3347. lcd_update_enabled = true;
  3348. }
  3349. if (!loaded)
  3350. {
  3351. lcd_display_message_fullscreen_P(_i("Please load filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3352. lcd_consume_click();
  3353. for (uint_least8_t i = 0; i < 20; i++) { //wait max. 2s
  3354. delay_keep_alive(100);
  3355. if (lcd_clicked()) {
  3356. break;
  3357. }
  3358. }
  3359. lcd_update_enabled = true;
  3360. menu_back();
  3361. return;
  3362. }
  3363. }
  3364. #endif //FILAMENT_SENSOR
  3365. eFilamentAction = FilamentAction::Lay1Cal;
  3366. menu_goto(lcd_generic_preheat_menu, 0, true, true);
  3367. }
  3368. void lcd_wizard() {
  3369. bool result = true;
  3370. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3371. result = !lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Running Wizard will delete current calibration results and start from the beginning. Continue?"), false);////MSG_WIZARD_RERUN c=20 r=7
  3372. }
  3373. if (result) {
  3374. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3375. lcd_wizard(WizState::Run);
  3376. }
  3377. else {
  3378. lcd_return_to_status();
  3379. lcd_update_enable(true);
  3380. lcd_update(2);
  3381. }
  3382. }
  3383. #if (LANG_MODE != 0)
  3384. void lcd_language()
  3385. {
  3386. lcd_update_enable(true);
  3387. lcd_clear();
  3388. menu_goto(lcd_language_menu, 0, true, true);
  3389. lcd_timeoutToStatus.stop(); //infinite timeout
  3390. lcd_draw_update = 2;
  3391. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  3392. {
  3393. _delay(50);
  3394. lcd_update(0);
  3395. manage_heater();
  3396. manage_inactivity(true);
  3397. }
  3398. if (lang_is_selected())
  3399. lcd_return_to_status();
  3400. else
  3401. lang_select(LANG_ID_PRI);
  3402. }
  3403. #endif
  3404. static void wait_preheat()
  3405. {
  3406. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3407. plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS] / 60);
  3408. delay_keep_alive(2000);
  3409. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3410. while (fabs(degHotend(0) - degTargetHotend(0)) > 3) {
  3411. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3412. lcd_set_cursor(0, 4);
  3413. //Print the hotend temperature (9 chars total)
  3414. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  3415. delay_keep_alive(1000);
  3416. }
  3417. }
  3418. static void lcd_wizard_load() {
  3419. if (MMU2::mmu2.Enabled()) {
  3420. lcd_show_fullscreen_message_and_wait_P(
  3421. _i("Please insert filament into the first tube of the MMU, then press the knob to load it.")); ////MSG_MMU_INSERT_FILAMENT_FIRST_TUBE c=20 r=6
  3422. } else {
  3423. lcd_show_fullscreen_message_and_wait_P(
  3424. _i("Please insert filament into the extruder, then press the knob to load it.")); ////MSG_WIZARD_LOAD_FILAMENT c=20 r=6
  3425. }
  3426. lcd_update_enable(false);
  3427. lcd_clear();
  3428. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  3429. loading_flag = true;
  3430. gcode_M701(FILAMENTCHANGE_FIRSTFEED, 0);
  3431. //enquecommand_P(PSTR("M701"));
  3432. }
  3433. static void wizard_lay1cal_message(bool cold)
  3434. {
  3435. lcd_show_fullscreen_message_and_wait_P(
  3436. _i("Now I will calibrate distance between tip of the nozzle and heatbed surface.")); ////MSG_WIZARD_V2_CAL c=20 r=8
  3437. if (MMU2::mmu2.Enabled())
  3438. {
  3439. lcd_show_fullscreen_message_and_wait_P(
  3440. _i("Select a filament for the First Layer Calibration and select it in the on-screen menu."));////MSG_SELECT_FIL_1ST_LAYERCAL c=20 r=7
  3441. }
  3442. else if (cold)
  3443. {
  3444. lcd_show_fullscreen_message_and_wait_P(
  3445. _i("Select temperature which matches your material."));////MSG_SELECT_TEMP_MATCHES_MATERIAL c=20 r=4
  3446. }
  3447. lcd_show_fullscreen_message_and_wait_P(
  3448. _i("The printer will start printing a zig-zag line. Rotate the knob until you reach the optimal height. Check the pictures in the handbook (Calibration chapter).")); ////MSG_WIZARD_V2_CAL_2 c=20 r=12
  3449. }
  3450. //! @brief Printer first run wizard (Selftest and calibration)
  3451. //!
  3452. //!
  3453. //! First layer calibration with MMU state diagram
  3454. //!
  3455. //! @startuml
  3456. //! [*] --> IsFil
  3457. //! IsFil : Is any filament loaded?
  3458. //! LoadFilCold : Push the button to start loading Filament 1
  3459. //!
  3460. //! IsFil --> Lay1CalCold : yes
  3461. //! IsFil --> LoadFilCold : no
  3462. //! LoadFilCold --> Lay1CalCold : click
  3463. //! @enduml
  3464. //!
  3465. //! First layer calibration without MMU state diagram
  3466. //!
  3467. //! @startuml
  3468. //! [*] --> IsFil
  3469. //! IsFil : Is filament loaded?
  3470. //! Preheat : Select nozle temperature which matches your material.
  3471. //! LoadFilHot : Insert filament to extruder and press the knob.
  3472. //!
  3473. //! IsFil --> Lay1CalCold : yes
  3474. //! IsFil --> Preheat : no
  3475. //! Preheat --> LoadFilHot : select
  3476. //! LoadFilHot --> Lay1CalHot : click
  3477. //! @enduml
  3478. //!
  3479. //! @param state Entry point of the wizard
  3480. //!
  3481. //! state | description
  3482. //! ---------------------- | ----------------
  3483. //! WizState::Run | Main entry point
  3484. //! WizState::RepeatLay1Cal | Entry point after passing 1st layer calibration
  3485. //! WizState::LoadFilHot | Entry point after temporarily left for preheat before load filament
  3486. void lcd_wizard(WizState state)
  3487. {
  3488. using S = WizState;
  3489. bool end = false;
  3490. uint8_t wizard_event;
  3491. const char *msg = NULL;
  3492. // Make sure EEPROM_WIZARD_ACTIVE is true if entering using different entry point
  3493. // other than WizState::Run - it is useful for debugging wizard.
  3494. if (state != S::Run) eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3495. FORCE_BL_ON_START;
  3496. while (!end) {
  3497. printf_P(PSTR("Wizard state: %d\n"), state);
  3498. switch (state) {
  3499. case S::Run: //Run wizard?
  3500. // 2019-08-07 brutal hack - solving the "viper" situation.
  3501. // It is caused by the fact, that tmc2130_st_isr makes a crash detection before the printers really starts.
  3502. // And thus it calles stop_and_save_print_to_ram which sets the saved_printing flag.
  3503. // Having this flag set during normal printing is lethal - mesh_plan_buffer_line exist in the middle of planning long travels
  3504. // which results in distorted print.
  3505. // This primarily happens when the printer is new and parked in 0,0
  3506. // So any new printer will fail the first layer calibration unless being reset or the Stop function gets called.
  3507. // We really must find a way to prevent the crash from happening before the printer is started - that would be the correct solution.
  3508. // Btw. the flag may even trigger the viper situation on normal start this way and the user won't be able to find out why.
  3509. saved_printing = false;
  3510. if( eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE)==2){
  3511. lcd_show_fullscreen_message_and_wait_P(_T(MSG_WIZARD_WELCOME_SHIPPING));
  3512. state = S::Restore;
  3513. } else {
  3514. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_T(MSG_WIZARD_WELCOME), false, LCD_LEFT_BUTTON_CHOICE);
  3515. if (wizard_event == LCD_LEFT_BUTTON_CHOICE) {
  3516. state = S::Restore;
  3517. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3518. } else { // MIDDLE_BUTTON_CHOICE
  3519. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3520. end = true;
  3521. }
  3522. }
  3523. break;
  3524. case S::Restore:
  3525. switch (calibration_status()) {
  3526. case CALIBRATION_STATUS_ASSEMBLED: state = S::Selftest; break; //run selftest
  3527. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = S::Xyz; break; //run xyz cal.
  3528. case CALIBRATION_STATUS_Z_CALIBRATION: state = S::Z; break; //run z cal.
  3529. case CALIBRATION_STATUS_LIVE_ADJUST: state = S::IsFil; break; //run live adjust
  3530. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3531. default: state = S::Selftest; break; //if calibration status is unknown, run wizard from the beginning
  3532. }
  3533. break;
  3534. case S::Selftest:
  3535. lcd_show_fullscreen_message_and_wait_P(_i("First, I will run the selftest to check most common assembly problems."));////MSG_WIZARD_SELFTEST c=20 r=8
  3536. wizard_event = lcd_selftest();
  3537. if (wizard_event) {
  3538. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3539. state = S::Xyz;
  3540. }
  3541. else end = true;
  3542. break;
  3543. case S::Xyz:
  3544. lcd_show_fullscreen_message_and_wait_P(_i("I will run xyz calibration now. It will take approx. 12 mins."));////MSG_WIZARD_XYZ_CAL c=20 r=8
  3545. wizard_event = gcode_M45(false, 0);
  3546. if (wizard_event) state = S::IsFil;
  3547. else end = true;
  3548. break;
  3549. case S::Z:
  3550. lcd_show_fullscreen_message_and_wait_P(_i("Please remove shipping helpers first."));////MSG_REMOVE_SHIPPING_HELPERS c=20 r=3
  3551. lcd_show_fullscreen_message_and_wait_P(_i("Now remove the test print from steel sheet."));////MSG_REMOVE_TEST_PRINT c=20 r=4
  3552. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3553. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false);
  3554. if (wizard_event == LCD_MIDDLE_BUTTON_CHOICE) {
  3555. lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3556. }
  3557. wizard_event = gcode_M45(true, 0);
  3558. if (wizard_event) {
  3559. //current filament needs to be unloaded and then new filament should be loaded
  3560. //start to preheat nozzle for unloading remaining PLA filament
  3561. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3562. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA.")); ////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3563. wait_preheat();
  3564. //unload current filament
  3565. unload_filament(FILAMENTCHANGE_FINALRETRACT, true);
  3566. //load filament
  3567. lcd_wizard_load();
  3568. setTargetHotend(0, 0); //we are finished, cooldown nozzle
  3569. state = S::Finish; //shipped, no need to set first layer, go to final message directly
  3570. }
  3571. else end = true;
  3572. break;
  3573. case S::IsFil:
  3574. //start to preheat nozzle and bed to save some time later
  3575. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3576. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3577. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_LOADED), true);
  3578. if (wizard_event == LCD_LEFT_BUTTON_CHOICE) {
  3579. state = S::Lay1CalCold;
  3580. } else { // MIDDLE_BUTTON_CHOICE
  3581. if(MMU2::mmu2.Enabled()) state = S::LoadFilCold;
  3582. else state = S::Preheat;
  3583. }
  3584. break;
  3585. case S::Preheat:
  3586. menu_goto(lcd_preheat_menu,0,false,true);
  3587. lcd_show_fullscreen_message_and_wait_P(_i("Select nozzle preheat temperature which matches your material."));////MSG_SEL_PREHEAT_TEMP c=20 r=6
  3588. end = true; // Leave wizard temporarily for lcd_preheat_menu
  3589. break;
  3590. case S::LoadFilHot:
  3591. wait_preheat();
  3592. lcd_wizard_load();
  3593. state = S::Lay1CalHot;
  3594. break;
  3595. case S::LoadFilCold:
  3596. lcd_wizard_load();
  3597. state = S::Lay1CalCold;
  3598. break;
  3599. case S::Lay1CalCold:
  3600. wizard_lay1cal_message(true);
  3601. menu_goto(lcd_v2_calibration,0,false,true);
  3602. end = true; // Leave wizard temporarily for lcd_v2_calibration
  3603. break;
  3604. case S::Lay1CalHot:
  3605. wizard_lay1cal_message(false);
  3606. lcd_commands_type = LcdCommands::Layer1Cal;
  3607. end = true; // Leave wizard temporarily for lcd_v2_calibration
  3608. break;
  3609. case S::RepeatLay1Cal:
  3610. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Do you want to repeat last step to readjust distance between nozzle and heatbed?"), false);////MSG_WIZARD_REPEAT_V2_CAL c=20 r=7
  3611. if (wizard_event == LCD_LEFT_BUTTON_CHOICE)
  3612. {
  3613. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3614. state = S::Lay1CalCold;
  3615. }
  3616. else
  3617. {
  3618. lcd_show_fullscreen_message_and_wait_P(_i("If you have additional steel sheets, calibrate their presets in Settings - HW Setup - Steel sheets."));////MSG_ADDITIONAL_SHEETS c=20 r=9
  3619. state = S::Finish;
  3620. }
  3621. break;
  3622. case S::Finish:
  3623. eeprom_update_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3624. end = true;
  3625. break;
  3626. default: break;
  3627. }
  3628. }
  3629. FORCE_BL_ON_END;
  3630. printf_P(_N("Wizard end state: %d\n"), state);
  3631. switch (state) { //final message
  3632. case S::Restore: //printer was already calibrated
  3633. msg = _T(MSG_WIZARD_DONE);
  3634. break;
  3635. case S::Selftest: //selftest
  3636. case S::Xyz: //xyz cal.
  3637. case S::Z: //z cal.
  3638. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3639. break;
  3640. case S::Finish: //we are finished
  3641. msg = _T(MSG_WIZARD_DONE);
  3642. lcd_reset_alert_level();
  3643. lcd_setstatuspgm(MSG_WELCOME);
  3644. lcd_return_to_status();
  3645. break;
  3646. default:
  3647. msg = _T(MSG_WIZARD_QUIT);
  3648. break;
  3649. }
  3650. if (!((S::Lay1CalCold == state) || (S::Lay1CalHot == state) || (S::Preheat == state)))
  3651. {
  3652. lcd_show_fullscreen_message_and_wait_P(msg);
  3653. }
  3654. lcd_update_enable(true);
  3655. lcd_update(2);
  3656. }
  3657. #ifdef TMC2130
  3658. void lcd_settings_linearity_correction_menu(void)
  3659. {
  3660. MENU_BEGIN();
  3661. ON_MENU_LEAVE(
  3662. lcd_settings_linearity_correction_menu_save();
  3663. );
  3664. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3665. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3666. //tmc2130_wave_fac[X_AXIS]
  3667. MENU_ITEM_EDIT_int3_P(_i("X-correct:"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_X_CORRECTION c=13
  3668. MENU_ITEM_EDIT_int3_P(_i("Y-correct:"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Y_CORRECTION c=13
  3669. MENU_ITEM_EDIT_int3_P(_i("Z-correct:"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_Z_CORRECTION c=13
  3670. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3671. MENU_ITEM_EDIT_int3_P(_i("E-correct:"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=13
  3672. MENU_END();
  3673. }
  3674. #endif // TMC2130
  3675. #ifdef FILAMENT_SENSOR
  3676. static void fsensor_reinit() {
  3677. fsensor.init();
  3678. }
  3679. static void lcd_fsensor_enabled_set(void) {
  3680. fsensor.setEnabled(!fsensor.isEnabled());
  3681. }
  3682. static void lcd_fsensor_runout_set() {
  3683. fsensor.setRunoutEnabled(!fsensor.getRunoutEnabled(), true);
  3684. }
  3685. static void lcd_fsensor_autoload_set() {
  3686. fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled(), true);
  3687. }
  3688. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  3689. static void lcd_fsensor_jam_detection_set() {
  3690. fsensor.setJamDetectionEnabled(!fsensor.getJamDetectionEnabled(), true);
  3691. }
  3692. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  3693. static void lcd_fsensor_actionNA_set(void)
  3694. {
  3695. Filament_sensor::SensorActionOnError act = fsensor.getActionOnError();
  3696. switch(act) {
  3697. case Filament_sensor::SensorActionOnError::_Continue:
  3698. act = Filament_sensor::SensorActionOnError::_Pause;
  3699. break;
  3700. case Filament_sensor::SensorActionOnError::_Pause:
  3701. act = Filament_sensor::SensorActionOnError::_Continue;
  3702. break;
  3703. default:
  3704. act = Filament_sensor::SensorActionOnError::_Continue;
  3705. }
  3706. fsensor.setActionOnError(act, true);
  3707. }
  3708. static void lcd_fsensor_settings_menu() {
  3709. MENU_BEGIN();
  3710. MENU_ITEM_BACK_P(_T(MSG_BACK));
  3711. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), fsensor.isEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_enabled_set);
  3712. if (fsensor.isEnabled()) {
  3713. if (fsensor.isError()) {
  3714. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), _T(MSG_NA), fsensor_reinit);
  3715. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_NA), fsensor_reinit);
  3716. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3717. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_JAM_DETECTION), _T(MSG_NA), fsensor_reinit);
  3718. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3719. }
  3720. else {
  3721. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), fsensor.getRunoutEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_runout_set);
  3722. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), fsensor.getAutoLoadEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_autoload_set);
  3723. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3724. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_JAM_DETECTION), fsensor.getJamDetectionEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_jam_detection_set);
  3725. #endif //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125)
  3726. }
  3727. switch(fsensor.getActionOnError()) {
  3728. case Filament_sensor::SensorActionOnError::_Continue:
  3729. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_CONTINUE_SHORT), lcd_fsensor_actionNA_set);
  3730. break;
  3731. case Filament_sensor::SensorActionOnError::_Pause:
  3732. MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_PAUSE), lcd_fsensor_actionNA_set);
  3733. break;
  3734. default:
  3735. lcd_fsensor_actionNA_set();
  3736. }
  3737. }
  3738. MENU_END();
  3739. }
  3740. #endif //FILAMENT_SENSOR
  3741. static void settingsSpoolJoin()
  3742. {
  3743. MENU_ITEM_TOGGLE_P(MSG_SPOOL_JOIN, SpoolJoin::spooljoin.isSpoolJoinEnabled() ? _T(MSG_ON) : _T(MSG_OFF), SpoolJoin::spooljoin.toggleSpoolJoin);
  3744. }
  3745. #define SETTINGS_SPOOLJOIN \
  3746. do\
  3747. {\
  3748. settingsSpoolJoin();\
  3749. }\
  3750. while(0)\
  3751. #ifdef MMU_HAS_CUTTER
  3752. static void settingsCutter()
  3753. {
  3754. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  3755. {
  3756. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ON), lcd_cutter_enabled);
  3757. }
  3758. #ifdef MMU_ALWAYS_CUT
  3759. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  3760. {
  3761. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_ALWAYS), lcd_cutter_enabled);
  3762. }
  3763. #endif
  3764. else
  3765. {
  3766. MENU_ITEM_TOGGLE_P(_T(MSG_CUTTER), _T(MSG_OFF), lcd_cutter_enabled);
  3767. }
  3768. }
  3769. #define SETTINGS_CUTTER \
  3770. do\
  3771. {\
  3772. settingsCutter();\
  3773. }\
  3774. while(0)
  3775. #else
  3776. #define SETTINGS_CUTTER
  3777. #endif //MMU_HAS_CUTTER
  3778. static void mmu_enable_switch()
  3779. {
  3780. uint8_t current_state = eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED);
  3781. // EEPROM update is handled by the stop and start functions.
  3782. if (current_state)
  3783. {
  3784. MMU2::mmu2.Stop();
  3785. }
  3786. else
  3787. {
  3788. MMU2::mmu2.Start();
  3789. }
  3790. }
  3791. static void mmu_reset()
  3792. {
  3793. MMU2::mmu2.Reset(MMU2::MMU2::ResetForm::Software);
  3794. }
  3795. #ifdef TMC2130
  3796. #define SETTINGS_SILENT_MODE \
  3797. do\
  3798. {\
  3799. if(!farm_mode)\
  3800. {\
  3801. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  3802. {\
  3803. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\
  3804. }\
  3805. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\
  3806. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  3807. {\
  3808. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\
  3809. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);\
  3810. }\
  3811. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);\
  3812. }\
  3813. }\
  3814. while (0)
  3815. #else //TMC2130
  3816. #define SETTINGS_SILENT_MODE \
  3817. do\
  3818. {\
  3819. if(!farm_mode)\
  3820. {\
  3821. switch (SilentModeMenu)\
  3822. {\
  3823. case SILENT_MODE_POWER:\
  3824. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  3825. break;\
  3826. case SILENT_MODE_SILENT:\
  3827. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set);\
  3828. break;\
  3829. case SILENT_MODE_AUTO:\
  3830. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set);\
  3831. break;\
  3832. default:\
  3833. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set);\
  3834. break; /* (probably) not needed*/\
  3835. }\
  3836. }\
  3837. }\
  3838. while (0)
  3839. #endif //TMC2130
  3840. #ifndef MMU_FORCE_STEALTH_MODE
  3841. #define SETTINGS_MMU_MODE \
  3842. do\
  3843. {\
  3844. if (MMU2::mmu2.Enabled())\
  3845. {\
  3846. if (SilentModeMenu_MMU == 0) MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_NORMAL), lcd_silent_mode_mmu_set);\
  3847. else MENU_ITEM_TOGGLE_P(_T(MSG_MMU_MODE), _T(MSG_STEALTH), lcd_silent_mode_mmu_set);\
  3848. }\
  3849. }\
  3850. while (0)
  3851. #else //MMU_FORCE_STEALTH_MODE
  3852. #define SETTINGS_MMU_MODE
  3853. #endif //MMU_FORCE_STEALTH_MODE
  3854. /*
  3855. #define SETTINGS_MBL_MODE \
  3856. do\
  3857. {\
  3858. switch(e_mbl_type)\
  3859. {\
  3860. case e_MBL_FAST:\
  3861. MENU_ITEM_FUNCTION_P(_n("Mode [Fast]"),mbl_mode_set);\
  3862. break; \
  3863. case e_MBL_OPTIMAL:\
  3864. MENU_ITEM_FUNCTION_P(_n("Mode [Optimal]"), mbl_mode_set); \
  3865. break; \
  3866. case e_MBL_PREC:\
  3867. MENU_ITEM_FUNCTION_P(_n("Mode [Precise]"), mbl_mode_set); \
  3868. break; \
  3869. default:\
  3870. MENU_ITEM_FUNCTION_P(_n("Mode [Optimal]"), mbl_mode_set); \
  3871. break; \
  3872. }\
  3873. }\
  3874. while (0)
  3875. */
  3876. #define SETTINGS_MMU_LOADING_TEST \
  3877. do\
  3878. {\
  3879. MENU_ITEM_SUBMENU_P(_T(MSG_LOADING_TEST), mmu_loading_test_menu); \
  3880. }\
  3881. while (0)
  3882. #define SETTINGS_SOUND \
  3883. do\
  3884. {\
  3885. switch(eSoundMode)\
  3886. {\
  3887. case e_SOUND_MODE_LOUD:\
  3888. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  3889. break;\
  3890. case e_SOUND_MODE_ONCE:\
  3891. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_ONCE), lcd_sound_state_set);\
  3892. break;\
  3893. case e_SOUND_MODE_SILENT:\
  3894. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SILENT), lcd_sound_state_set);\
  3895. break;\
  3896. case e_SOUND_MODE_BLIND:\
  3897. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_BLIND), lcd_sound_state_set);\
  3898. break;\
  3899. default:\
  3900. MENU_ITEM_TOGGLE_P(_T(MSG_SOUND), _T(MSG_SOUND_LOUD), lcd_sound_state_set);\
  3901. }\
  3902. }\
  3903. while (0)
  3904. //-//
  3905. static void lcd_check_mode_set(void)
  3906. {
  3907. switch(oCheckMode)
  3908. {
  3909. case ClCheckMode::_None:
  3910. oCheckMode=ClCheckMode::_Warn;
  3911. break;
  3912. case ClCheckMode::_Warn:
  3913. oCheckMode=ClCheckMode::_Strict;
  3914. break;
  3915. case ClCheckMode::_Strict:
  3916. oCheckMode=ClCheckMode::_None;
  3917. break;
  3918. default:
  3919. oCheckMode=ClCheckMode::_None;
  3920. }
  3921. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode);
  3922. }
  3923. #define SETTINGS_MODE \
  3924. do\
  3925. {\
  3926. switch(oCheckMode)\
  3927. {\
  3928. case ClCheckMode::_None:\
  3929. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  3930. break;\
  3931. case ClCheckMode::_Warn:\
  3932. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_WARN), lcd_check_mode_set);\
  3933. break;\
  3934. case ClCheckMode::_Strict:\
  3935. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_STRICT), lcd_check_mode_set);\
  3936. break;\
  3937. default:\
  3938. MENU_ITEM_TOGGLE_P(_T(MSG_NOZZLE), _T(MSG_NONE), lcd_check_mode_set);\
  3939. }\
  3940. }\
  3941. while (0)
  3942. static void lcd_nozzle_diameter_cycle(void) {
  3943. uint16_t nDiameter;
  3944. switch(oNozzleDiameter){
  3945. case ClNozzleDiameter::_Diameter_250:
  3946. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  3947. nDiameter=400;
  3948. break;
  3949. case ClNozzleDiameter::_Diameter_400:
  3950. oNozzleDiameter=ClNozzleDiameter::_Diameter_600;
  3951. nDiameter=600;
  3952. break;
  3953. case ClNozzleDiameter::_Diameter_600:
  3954. oNozzleDiameter=ClNozzleDiameter::_Diameter_800;
  3955. nDiameter=800;
  3956. break;
  3957. case ClNozzleDiameter::_Diameter_800:
  3958. oNozzleDiameter=ClNozzleDiameter::_Diameter_250;
  3959. nDiameter=250;
  3960. break;
  3961. default:
  3962. oNozzleDiameter=ClNozzleDiameter::_Diameter_400;
  3963. nDiameter=400;
  3964. }
  3965. eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter);
  3966. eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
  3967. }
  3968. #define SETTINGS_NOZZLE \
  3969. do\
  3970. {\
  3971. float fNozzleDiam;\
  3972. switch(oNozzleDiameter)\
  3973. {\
  3974. case ClNozzleDiameter::_Diameter_250: fNozzleDiam = 0.25f; break;\
  3975. case ClNozzleDiameter::_Diameter_400: fNozzleDiam = 0.4f; break;\
  3976. case ClNozzleDiameter::_Diameter_600: fNozzleDiam = 0.6f; break;\
  3977. case ClNozzleDiameter::_Diameter_800: fNozzleDiam = 0.8f; break;\
  3978. default: fNozzleDiam = 0.4f; break;\
  3979. }\
  3980. MENU_ITEM_TOGGLE(_T(MSG_NOZZLE_DIAMETER), ftostr12ns(fNozzleDiam), lcd_nozzle_diameter_cycle);\
  3981. }\
  3982. while (0)
  3983. static void lcd_check_model_set(void)
  3984. {
  3985. switch(oCheckModel)
  3986. {
  3987. case ClCheckModel::_None:
  3988. oCheckModel=ClCheckModel::_Warn;
  3989. break;
  3990. case ClCheckModel::_Warn:
  3991. oCheckModel=ClCheckModel::_Strict;
  3992. break;
  3993. case ClCheckModel::_Strict:
  3994. oCheckModel=ClCheckModel::_None;
  3995. break;
  3996. default:
  3997. oCheckModel=ClCheckModel::_None;
  3998. }
  3999. eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel);
  4000. }
  4001. #define SETTINGS_MODEL \
  4002. do\
  4003. {\
  4004. switch(oCheckModel)\
  4005. {\
  4006. case ClCheckModel::_None:\
  4007. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4008. break;\
  4009. case ClCheckModel::_Warn:\
  4010. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_WARN), lcd_check_model_set);\
  4011. break;\
  4012. case ClCheckModel::_Strict:\
  4013. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_STRICT), lcd_check_model_set);\
  4014. break;\
  4015. default:\
  4016. MENU_ITEM_TOGGLE_P(_T(MSG_MODEL), _T(MSG_NONE), lcd_check_model_set);\
  4017. }\
  4018. }\
  4019. while (0)
  4020. static void lcd_check_version_set(void)
  4021. {
  4022. switch(oCheckVersion)
  4023. {
  4024. case ClCheckVersion::_None:
  4025. oCheckVersion=ClCheckVersion::_Warn;
  4026. break;
  4027. case ClCheckVersion::_Warn:
  4028. oCheckVersion=ClCheckVersion::_Strict;
  4029. break;
  4030. case ClCheckVersion::_Strict:
  4031. oCheckVersion=ClCheckVersion::_None;
  4032. break;
  4033. default:
  4034. oCheckVersion=ClCheckVersion::_None;
  4035. }
  4036. eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion);
  4037. }
  4038. #define SETTINGS_VERSION \
  4039. do\
  4040. {\
  4041. switch(oCheckVersion)\
  4042. {\
  4043. case ClCheckVersion::_None:\
  4044. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_NONE), lcd_check_version_set);\
  4045. break;\
  4046. case ClCheckVersion::_Warn:\
  4047. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_WARN), lcd_check_version_set);\
  4048. break;\
  4049. case ClCheckVersion::_Strict:\
  4050. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_STRICT), lcd_check_version_set);\
  4051. break;\
  4052. default:\
  4053. MENU_ITEM_TOGGLE_P(MSG_FIRMWARE, _T(MSG_NONE), lcd_check_version_set);\
  4054. }\
  4055. }\
  4056. while (0)
  4057. static void lcd_checking_menu(void)
  4058. {
  4059. MENU_BEGIN();
  4060. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4061. SETTINGS_MODE;
  4062. SETTINGS_MODEL;
  4063. SETTINGS_VERSION;
  4064. MENU_END();
  4065. }
  4066. template <uint8_t number>
  4067. static void select_sheet_menu()
  4068. {
  4069. selected_sheet = number;
  4070. lcd_sheet_menu();
  4071. }
  4072. static void sheets_menu()
  4073. {
  4074. MENU_BEGIN();
  4075. MENU_ITEM_BACK_P(_T(MSG_HW_SETUP));
  4076. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], select_sheet_menu<0>);
  4077. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], select_sheet_menu<1>);
  4078. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], select_sheet_menu<2>);
  4079. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[3], select_sheet_menu<3>);
  4080. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[4], select_sheet_menu<4>);
  4081. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[5], select_sheet_menu<5>);
  4082. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[6], select_sheet_menu<6>);
  4083. MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[7], select_sheet_menu<7>);
  4084. MENU_END();
  4085. }
  4086. void lcd_hw_setup_menu(void) // can not be "static"
  4087. {
  4088. typedef struct
  4089. {// 2bytes total
  4090. int8_t status;
  4091. uint8_t experimental_menu_visibility;
  4092. } _menu_data_t;
  4093. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  4094. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  4095. if (_md->status == 0 || lcd_draw_update)
  4096. {
  4097. _md->status = 1;
  4098. _md->experimental_menu_visibility = eeprom_init_default_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, 0);
  4099. }
  4100. MENU_BEGIN();
  4101. MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch
  4102. MENU_ITEM_SUBMENU_P(_T(MSG_STEEL_SHEETS), sheets_menu);
  4103. SETTINGS_NOZZLE;
  4104. MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); ////MSG_CHECKS c=18
  4105. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  4106. //! Fsensor Detection isn't ready for mmu yet it is temporarily disabled.
  4107. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  4108. if(!MMU2::mmu2.Enabled()) MENU_ITEM_FUNCTION_P(PSTR("Fsensor Detection"), lcd_detect_IRsensor);
  4109. #endif //IR_SENSOR_ANALOG
  4110. if (_md->experimental_menu_visibility)
  4111. {
  4112. MENU_ITEM_SUBMENU_P(PSTR("Experimental"), lcd_experimental_menu);////MSG_MENU_EXPERIMENTAL c=18
  4113. }
  4114. #ifdef PINDA_TEMP_COMP
  4115. //! The SuperPINDA is detected when the PINDA temp is below its defined limit.
  4116. //! This works well on the EINSY board but not on the miniRAMBo board as
  4117. //! as a disconnected SuperPINDA will show higher temps compared to an EINSY board.
  4118. //!
  4119. //! This menu allows the user to en-/disable the SuperPINDA manualy
  4120. MENU_ITEM_TOGGLE_P(_N("SuperPINDA"), eeprom_read_byte((uint8_t *)EEPROM_PINDA_TEMP_COMPENSATION) ? _T(MSG_YES) : _T(MSG_NO), lcd_pinda_temp_compensation_toggle);
  4121. #endif //PINDA_TEMP_COMP
  4122. MENU_END();
  4123. }
  4124. static void lcd_settings_menu()
  4125. {
  4126. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  4127. MENU_BEGIN();
  4128. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4129. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=18
  4130. if (!printer_active() || isPrintPaused)
  4131. {
  4132. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18
  4133. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18
  4134. }
  4135. #ifdef FILAMENT_SENSOR
  4136. MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu);
  4137. #endif //FILAMENT_SENSOR
  4138. MENU_ITEM_TOGGLE_P(PSTR("MMU"), eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED) ? _T(MSG_ON) : _T(MSG_OFF), mmu_enable_switch);
  4139. if (MMU2::mmu2.Enabled())
  4140. { // Only show menus when communicating with MMU
  4141. SETTINGS_SPOOLJOIN;
  4142. SETTINGS_CUTTER;
  4143. SETTINGS_MMU_MODE;
  4144. SETTINGS_MMU_LOADING_TEST;
  4145. }
  4146. if (eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED))
  4147. { // Communication with MMU not required to reset MMU
  4148. MENU_ITEM_FUNCTION_P(PSTR("Reset MMU"), mmu_reset);
  4149. }
  4150. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  4151. SETTINGS_SILENT_MODE;
  4152. if(!farm_mode)
  4153. {
  4154. bSettings=true; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function
  4155. MENU_ITEM_SUBMENU_P(_T(MSG_HW_SETUP), lcd_hw_setup_menu);
  4156. }
  4157. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bed_leveling_settings);
  4158. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  4159. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);////MSG_LIN_CORRECTION c=18
  4160. #endif //LINEARITY_CORRECTION && TMC2130
  4161. if(has_temperature_compensation())
  4162. {
  4163. MENU_ITEM_TOGGLE_P(_T(MSG_PINDA_CALIBRATION), eeprom_read_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE) ? _T(MSG_ON) : _T(MSG_OFF), lcd_temp_calibration_set);
  4164. }
  4165. #ifdef HAS_SECOND_SERIAL_PORT
  4166. MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set);
  4167. #endif //HAS_SECOND_SERIAL
  4168. if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag)
  4169. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  4170. #if (LANG_MODE != 0)
  4171. MENU_ITEM_SUBMENU_P(_T(MSG_SELECT_LANGUAGE), lcd_language_menu);
  4172. #endif //(LANG_MODE != 0)
  4173. if (!farm_mode) { //SD related settings are not available in farm mode
  4174. if (card.ToshibaFlashAir_isEnabled())
  4175. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY, lcd_toshiba_flash_air_compatibility_toggle);
  4176. else
  4177. MENU_ITEM_TOGGLE_P(_T(MSG_SD_CARD), _T(MSG_NORMAL), lcd_toshiba_flash_air_compatibility_toggle);
  4178. #ifdef SDCARD_SORT_ALPHA
  4179. switch (eeprom_read_byte((uint8_t*) EEPROM_SD_SORT)) {
  4180. case SD_SORT_TIME: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_TIME), lcd_sort_type_set); break;
  4181. case SD_SORT_ALPHA: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_SORT_ALPHA), lcd_sort_type_set); break;
  4182. default: MENU_ITEM_TOGGLE_P(_T(MSG_SORT), _T(MSG_NONE), lcd_sort_type_set);
  4183. }
  4184. }
  4185. #endif //SDCARD_SORT_ALPHA
  4186. SETTINGS_SOUND;
  4187. #ifdef LCD_BL_PIN
  4188. if (backlightSupport)
  4189. {
  4190. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  4191. }
  4192. #endif //LCD_BL_PIN
  4193. if (farm_mode)
  4194. {
  4195. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  4196. }
  4197. MENU_END();
  4198. }
  4199. #ifdef TMC2130
  4200. static void lcd_ustep_linearity_menu_save()
  4201. {
  4202. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  4203. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  4204. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  4205. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  4206. }
  4207. #endif //TMC2130
  4208. #ifdef TMC2130
  4209. static void lcd_settings_linearity_correction_menu_save()
  4210. {
  4211. bool changed = false;
  4212. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  4213. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  4214. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  4215. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  4216. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  4217. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  4218. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  4219. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  4220. lcd_ustep_linearity_menu_save();
  4221. if (changed) tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
  4222. }
  4223. #endif //TMC2130
  4224. static void lcd_calibration_menu()
  4225. {
  4226. MENU_BEGIN();
  4227. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4228. if (!isPrintPaused)
  4229. {
  4230. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17
  4231. if (lcd_commands_type == LcdCommands::Idle)
  4232. {
  4233. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_first_layer_calibration_reset);
  4234. }
  4235. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  4236. #ifdef TMC2130
  4237. MENU_ITEM_FUNCTION_P(_i("Belt test"), lcd_belttest_v);////MSG_BELTTEST c=18
  4238. #endif //TMC2130
  4239. MENU_ITEM_FUNCTION_P(_i("Selftest"), lcd_selftest_v);////MSG_SELFTEST c=18
  4240. // MK2
  4241. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=18
  4242. // "Calibrate Z" with storing the reference values to EEPROM.
  4243. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  4244. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bedleveling); ////MSG_MESH_BED_LEVELING c=18
  4245. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=18
  4246. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17
  4247. #ifndef TMC2130
  4248. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=18
  4249. #endif
  4250. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=18
  4251. if(has_temperature_compensation())
  4252. {
  4253. MENU_ITEM_FUNCTION_P(_T(MSG_PINDA_CALIBRATION), lcd_calibrate_pinda);
  4254. }
  4255. }
  4256. #ifdef TEMP_MODEL
  4257. MENU_ITEM_SUBMENU_P(_n("Temp Model cal."), lcd_temp_model_cal);
  4258. #endif //TEMP_MODEL
  4259. MENU_END();
  4260. }
  4261. //! @brief Select one of numbered items
  4262. //!
  4263. //! Create list of items with header. Header can not be selected.
  4264. //! Each item has text description passed by function parameter and
  4265. //! number. There are 5 numbered items, if MMU2::mmu2.Enabled(), 4 otherwise.
  4266. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  4267. //! There can be last item with different text and no number.
  4268. //!
  4269. //! @param header Header text
  4270. //! @param item Item text
  4271. //! @param last_item Last item text, or nullptr if there is no Last item
  4272. //! @return selected item index, first item index is 0
  4273. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  4274. {
  4275. //following code should handle 3 to 127 number of items well
  4276. const int8_t items_no = last_item?(MMU2::mmu2.Enabled()?6:5):(MMU2::mmu2.Enabled()?5:4);
  4277. const uint8_t item_len = item?strlen_P(item):0;
  4278. int8_t first = 0;
  4279. int8_t enc_dif = lcd_encoder_diff;
  4280. int8_t cursor_pos = 1;
  4281. lcd_clear();
  4282. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4283. while (1)
  4284. {
  4285. manage_heater();
  4286. manage_inactivity(true);
  4287. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  4288. {
  4289. if (enc_dif > lcd_encoder_diff)
  4290. {
  4291. cursor_pos--;
  4292. }
  4293. if (enc_dif < lcd_encoder_diff)
  4294. {
  4295. cursor_pos++;
  4296. }
  4297. enc_dif = lcd_encoder_diff;
  4298. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  4299. }
  4300. if (cursor_pos > 3)
  4301. {
  4302. cursor_pos = 3;
  4303. if (first < items_no - 3)
  4304. {
  4305. first++;
  4306. lcd_clear();
  4307. } else { // here we are at the very end of the list
  4308. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4309. }
  4310. }
  4311. if (cursor_pos < 1)
  4312. {
  4313. cursor_pos = 1;
  4314. if (first > 0)
  4315. {
  4316. first--;
  4317. lcd_clear();
  4318. } else { // here we are at the very end of the list
  4319. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4320. }
  4321. }
  4322. if (header) lcd_puts_at_P(0,0,header);
  4323. const bool last_visible = (first == items_no - 3);
  4324. const uint_least8_t ordinary_items = (last_item&&last_visible)?2:3;
  4325. for (uint_least8_t i = 0; i < ordinary_items; i++)
  4326. {
  4327. if (item) lcd_puts_at_P(1, i + 1, item);
  4328. }
  4329. for (uint_least8_t i = 0; i < ordinary_items; i++)
  4330. {
  4331. lcd_set_cursor(2 + item_len, i+1);
  4332. lcd_print(first + i + 1);
  4333. }
  4334. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  4335. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  4336. lcd_putc_at(0, cursor_pos, '>');
  4337. _delay(100);
  4338. if (lcd_clicked())
  4339. {
  4340. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  4341. KEEPALIVE_STATE(IN_HANDLER);
  4342. lcd_encoder_diff = 0;
  4343. return(cursor_pos + first - 1);
  4344. }
  4345. }
  4346. }
  4347. char reset_menu() {
  4348. static int8_t first = 0;
  4349. int8_t enc_dif = 0;
  4350. char cursor_pos = 0;
  4351. const char *const item[] = {
  4352. PSTR("Language"),
  4353. PSTR("Statistics"),
  4354. PSTR("Shipping prep"),
  4355. PSTR("Service prep"),
  4356. PSTR("All Data"),
  4357. };
  4358. enc_dif = lcd_encoder_diff;
  4359. lcd_clear();
  4360. lcd_set_cursor(0, 0);
  4361. lcd_putc('>');
  4362. lcd_consume_click();
  4363. while (1) {
  4364. for (uint_least8_t i = 0; i < 4; i++) {
  4365. lcd_puts_at_P(1, i, item[first + i]);
  4366. }
  4367. manage_heater();
  4368. manage_inactivity(true);
  4369. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4370. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4371. if (enc_dif > lcd_encoder_diff) {
  4372. cursor_pos--;
  4373. }
  4374. if (enc_dif < lcd_encoder_diff) {
  4375. cursor_pos++;
  4376. }
  4377. if (cursor_pos > 3) {
  4378. cursor_pos = 3;
  4379. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4380. if (first < (uint8_t)(sizeof(item) / sizeof(item[0])) - 4) {
  4381. first++;
  4382. lcd_clear();
  4383. }
  4384. }
  4385. if (cursor_pos < 0) {
  4386. cursor_pos = 0;
  4387. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  4388. if (first > 0) {
  4389. first--;
  4390. lcd_clear();
  4391. }
  4392. }
  4393. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  4394. lcd_set_cursor(0, cursor_pos);
  4395. lcd_putc('>');
  4396. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  4397. enc_dif = lcd_encoder_diff;
  4398. _delay(100);
  4399. }
  4400. }
  4401. if (lcd_clicked()) {
  4402. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  4403. return(cursor_pos + first);
  4404. }
  4405. }
  4406. }
  4407. static void lcd_disable_farm_mode()
  4408. {
  4409. uint8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true); //allow timeouting, default no
  4410. if (disable == LCD_LEFT_BUTTON_CHOICE)
  4411. {
  4412. enquecommand_P(PSTR("G99"));
  4413. lcd_return_to_status();
  4414. }
  4415. lcd_update_enable(true);
  4416. lcd_draw_update = 2;
  4417. }
  4418. static inline void load_all_wrapper(){
  4419. for(uint8_t i = 0; i < 5; ++i){
  4420. MMU2::mmu2.load_filament(i);
  4421. }
  4422. }
  4423. static inline void load_filament_wrapper(uint8_t i){
  4424. MMU2::mmu2.load_filament(i);
  4425. }
  4426. static void mmu_load_filament_menu() {
  4427. MENU_BEGIN();
  4428. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4429. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_ALL), load_all_wrapper);
  4430. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4431. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', load_filament_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4432. MENU_END();
  4433. }
  4434. static inline void lcd_mmu_load_to_nozzle_wrapper(uint8_t index){
  4435. MMU2::mmu2.load_filament_to_nozzle(index);
  4436. // Ask user if the extruded color is correct:
  4437. lcd_return_to_status();
  4438. lcd_load_filament_color_check();
  4439. lcd_setstatuspgm(MSG_WELCOME);
  4440. custom_message_type = CustomMsg::Status;
  4441. }
  4442. static void mmu_load_to_nozzle_menu() {
  4443. if (bFilamentAction) {
  4444. MENU_BEGIN();
  4445. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4446. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4447. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', lcd_mmu_load_to_nozzle_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4448. MENU_END();
  4449. } else {
  4450. eFilamentAction = FilamentAction::MmuLoad;
  4451. preheat_or_continue();
  4452. }
  4453. }
  4454. static void mmu_eject_filament(uint8_t filament) {
  4455. menu_back();
  4456. MMU2::mmu2.eject_filament(filament, true);
  4457. }
  4458. static void mmu_fil_eject_menu() {
  4459. if (bFilamentAction) {
  4460. MENU_BEGIN();
  4461. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4462. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4463. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), i + '1', mmu_eject_filament, i); ////MSG_EJECT_FILAMENT c=16
  4464. MENU_END();
  4465. } else {
  4466. eFilamentAction = FilamentAction::MmuEject;
  4467. preheat_or_continue();
  4468. }
  4469. }
  4470. #ifdef MMU_HAS_CUTTER
  4471. static inline void mmu_cut_filament_wrapper(uint8_t index){
  4472. MMU2::mmu2.cut_filament(index);
  4473. }
  4474. static void mmu_cut_filament_menu() {
  4475. if (bFilamentAction) {
  4476. MENU_BEGIN();
  4477. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4478. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4479. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), i + '1', mmu_cut_filament_wrapper, i); ////MSG_CUT_FILAMENT c=16
  4480. MENU_END();
  4481. } else {
  4482. eFilamentAction=FilamentAction::MmuCut;
  4483. preheat_or_continue();
  4484. }
  4485. }
  4486. #endif //MMU_HAS_CUTTER
  4487. static inline void loading_test_all_wrapper(){
  4488. for(uint8_t i = 0; i < 5; ++i){
  4489. MMU2::mmu2.loading_test(i);
  4490. }
  4491. }
  4492. static inline void loading_test_wrapper(uint8_t i){
  4493. MMU2::mmu2.loading_test(i);
  4494. }
  4495. static void mmu_loading_test_menu() {
  4496. if (bFilamentAction) {
  4497. MENU_BEGIN();
  4498. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4499. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_ALL), loading_test_all_wrapper);
  4500. for (uint8_t i = 0; i < MMU_FILAMENT_COUNT; i++)
  4501. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), i + '1', loading_test_wrapper, i); ////MSG_LOAD_FILAMENT c=16
  4502. MENU_END();
  4503. } else {
  4504. eFilamentAction = FilamentAction::MmuLoadingTest;
  4505. preheat_or_continue();
  4506. }
  4507. }
  4508. // unload filament for single material printer (used in M702 gcode)
  4509. // @param automatic: If true, unload_filament is part of a unload+load sequence (M600)
  4510. void unload_filament(float unloadLength, bool automatic)
  4511. {
  4512. custom_message_type = CustomMsg::FilamentLoading;
  4513. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  4514. FSensorBlockRunout fsBlockRunout;
  4515. if (automatic)
  4516. {
  4517. // M600
  4518. raise_z_above(MIN_Z_FOR_SWAP);
  4519. }
  4520. // Retract filament
  4521. current_position[E_AXIS] += -FILAMENT_UNLOAD_PURGE_RETRACT;
  4522. plan_buffer_line_curposXYZE(PAUSE_PARK_RETRACT_FEEDRATE);
  4523. st_synchronize();
  4524. // Wait for filament to cool
  4525. delay_keep_alive(FILAMENT_UNLOAD_PURGE_DELAY);
  4526. // Quickly purge
  4527. current_position[E_AXIS] += (FILAMENT_UNLOAD_PURGE_RETRACT + FILAMENT_UNLOAD_PURGE_LENGTH);
  4528. plan_buffer_line_curposXYZE(FILAMENT_UNLOAD_PURGE_FEEDRATE);
  4529. st_synchronize();
  4530. // Configurable length
  4531. current_position[E_AXIS] += unloadLength;
  4532. plan_buffer_line_curposXYZE(FILAMENT_CHANGE_UNLOAD_FEEDRATE);
  4533. st_synchronize();
  4534. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  4535. //disable extruder steppers so filament can be removed
  4536. disable_e0();
  4537. disable_e1();
  4538. disable_e2();
  4539. _delay(100);
  4540. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  4541. uint8_t counterBeep = 0;
  4542. while (!lcd_clicked() && (counterBeep < 50)) {
  4543. delay_keep_alive(100);
  4544. counterBeep++;
  4545. }
  4546. st_synchronize();
  4547. while (lcd_clicked()) delay_keep_alive(100);
  4548. lcd_update_enable(true);
  4549. lcd_setstatuspgm(MSG_WELCOME);
  4550. custom_message_type = CustomMsg::Status;
  4551. eFilamentAction = FilamentAction::None;
  4552. }
  4553. #include "xflash.h"
  4554. #ifdef LCD_TEST
  4555. static void lcd_test_menu()
  4556. {
  4557. XFLASH_SPI_ENTER();
  4558. xflash_enable_wr();
  4559. xflash_chip_erase();
  4560. xflash_disable_wr();
  4561. }
  4562. #endif //LCD_TEST
  4563. static bool fan_error_selftest()
  4564. {
  4565. #ifdef FANCHECK
  4566. if (!fans_check_enabled) return 0;
  4567. fanSpeed = 255;
  4568. #ifdef FAN_SOFT_PWM
  4569. fanSpeedSoftPwm = 255;
  4570. #endif //FAN_SOFT_PWM
  4571. manage_heater(); //enables print fan
  4572. setExtruderAutoFanState(3); //force enables the hotend fan
  4573. #ifdef FAN_SOFT_PWM
  4574. extruder_autofan_last_check = _millis();
  4575. fan_measuring = true;
  4576. #endif //FAN_SOFT_PWM
  4577. _delay(1000); //delay_keep_alive would turn off hotend fan, because temerature is too low (maybe)
  4578. manage_heater();
  4579. fanSpeed = 0;
  4580. setExtruderAutoFanState(1); //releases lock on the hotend fan
  4581. #ifdef FAN_SOFT_PWM
  4582. fanSpeedSoftPwm = 0;
  4583. #endif //FAN_SOFT_PWM
  4584. manage_heater();
  4585. #ifdef TACH_0
  4586. if (fan_speed[0] <= 20) { //hotend fan error
  4587. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_HOTEND);
  4588. return 1;
  4589. }
  4590. #endif
  4591. #ifdef TACH_1
  4592. if (fan_speed[1] <= 20) { //print fan error
  4593. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_PRINT);
  4594. return 1;
  4595. }
  4596. #endif
  4597. #endif //FANCHECK
  4598. return 0;
  4599. }
  4600. bool resume_print_checks() {
  4601. // reset the lcd status so that a newer error will be shown
  4602. lcd_return_to_status();
  4603. lcd_reset_alert_level();
  4604. // ensure thermal issues (temp or fan) are resolved before we allow to resume
  4605. if (get_temp_error()
  4606. #ifdef FANCHECK
  4607. || fan_error_selftest()
  4608. #endif
  4609. ) {
  4610. return false; // abort if error persists
  4611. }
  4612. return true;
  4613. }
  4614. //! @brief Resume paused print, send host action "resumed"
  4615. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  4616. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  4617. void lcd_resume_print()
  4618. {
  4619. // reset lcd and ensure we can resume first
  4620. if (!resume_print_checks()) return;
  4621. cmdqueue_serial_disabled = false;
  4622. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4623. st_synchronize();
  4624. custom_message_type = CustomMsg::Resuming;
  4625. isPrintPaused = false;
  4626. Stopped = false; // resume processing USB commands again
  4627. restore_print_from_ram_and_continue(default_retraction);
  4628. pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  4629. refresh_cmd_timeout();
  4630. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint
  4631. custom_message_type = CustomMsg::Status;
  4632. }
  4633. //! @brief Resume paused USB/host print, send host action "resume"
  4634. void lcd_resume_usb_print()
  4635. {
  4636. // reset lcd and ensure we can resume first
  4637. if (!resume_print_checks()) return;
  4638. // resume the usb host
  4639. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_RESUME);
  4640. }
  4641. static void change_sheet()
  4642. {
  4643. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  4644. menu_back(3);
  4645. }
  4646. static void lcd_rename_sheet_menu()
  4647. {
  4648. struct MenuData
  4649. {
  4650. bool initialized;
  4651. uint8_t selected;
  4652. char name[sizeof(Sheet::name)];
  4653. };
  4654. static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data");
  4655. MenuData* menuData = (MenuData*)&(menu_data[0]);
  4656. if (!menuData->initialized)
  4657. {
  4658. eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name));
  4659. lcd_encoder = menuData->name[0];
  4660. menuData->initialized = true;
  4661. }
  4662. if (lcd_encoder < '\x20') lcd_encoder = '\x20';
  4663. if (lcd_encoder > '\x7F') lcd_encoder = '\x7F';
  4664. menuData->name[menuData->selected] = lcd_encoder;
  4665. lcd_set_cursor(0,0);
  4666. for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i)
  4667. {
  4668. lcd_putc(menuData->name[i]);
  4669. }
  4670. lcd_set_cursor(menuData->selected, 1);
  4671. lcd_putc('^');
  4672. if (lcd_clicked())
  4673. {
  4674. if ((menuData->selected + 1u) < sizeof(Sheet::name))
  4675. {
  4676. lcd_encoder = menuData->name[++(menuData->selected)];
  4677. }
  4678. else
  4679. {
  4680. eeprom_update_block(menuData->name,
  4681. EEPROM_Sheets_base->s[selected_sheet].name,
  4682. sizeof(Sheet::name));
  4683. menu_back();
  4684. }
  4685. }
  4686. }
  4687. static void lcd_reset_sheet()
  4688. {
  4689. SheetName sheetName;
  4690. eeprom_default_sheet_name(selected_sheet, sheetName);
  4691. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),EEPROM_EMPTY_VALUE16);
  4692. eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name));
  4693. if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))
  4694. {
  4695. eeprom_switch_to_next_sheet();
  4696. if((-1 == eeprom_next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status()))
  4697. {
  4698. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  4699. }
  4700. }
  4701. menu_back();
  4702. }
  4703. //! @brief Activate selected_sheet and run first layer calibration
  4704. static void activate_calibrate_sheet()
  4705. {
  4706. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  4707. lcd_first_layer_calibration_reset();
  4708. }
  4709. static void lcd_sheet_menu()
  4710. {
  4711. MENU_BEGIN();
  4712. MENU_ITEM_BACK_P(_T(MSG_STEEL_SHEETS));
  4713. if(eeprom_is_sheet_initialized(selected_sheet)){
  4714. MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); ////MSG_SELECT c=18
  4715. }
  4716. if (lcd_commands_type == LcdCommands::Idle)
  4717. {
  4718. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet);
  4719. }
  4720. MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); ////MSG_RENAME c=18
  4721. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_reset_sheet);
  4722. MENU_END();
  4723. }
  4724. //! @brief Show Main Menu
  4725. //!
  4726. //! @code{.unparsed}
  4727. //! |01234567890123456789|
  4728. //! | Info screen | allways
  4729. //!
  4730. //! | tst - Save | ifdef RESUME_DEBUG
  4731. //! | tst - Restore | ifdef RESUME_DEBUG
  4732. //!
  4733. //! | recover print | ifdef TMC2130_DEBUG
  4734. //! | power panic | ifdef TMC2130_DEBUG
  4735. //!
  4736. //! | Live adjust Z | printing + Z low
  4737. //!
  4738. //! | Change filament | farm mode
  4739. //!
  4740. //! | Tune | printing + paused
  4741. //! | Pause print | printing + not paused
  4742. //! | Resume print | printing + paused
  4743. //! | Stop print | printing or paused + NOT MBL
  4744. //! | Preheat | not printing + not paused
  4745. //! | Print from SD | not printing or paused
  4746. //!
  4747. //! | Switch sheet | farm mode
  4748. //!
  4749. //! | AutoLoad filament | not printing + not mmu or paused
  4750. //! | Load filament | not printing + mmu or paused
  4751. //! | Load to nozzle | not printing + mmu or paused
  4752. //! | Unload filament | not printing or paused
  4753. //! | Eject filament | not printing + mmu or paused
  4754. //! | Cut filament | not printing + mmu or paused + cut atctive
  4755. //! | Settings | not printing or paused
  4756. //! | Calibration | not printing
  4757. //! | Statistics | not printing
  4758. //! | Fail stats | allways
  4759. //! | Fail stats MMU | mmu
  4760. //! | Support | allways
  4761. //! @endcode
  4762. static void lcd_main_menu()
  4763. {
  4764. MENU_BEGIN();
  4765. // Majkl superawesome menu
  4766. MENU_ITEM_BACK_P(_T(MSG_INFO_SCREEN));
  4767. #ifdef RESUME_DEBUG
  4768. if (!saved_printing)
  4769. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4770. else
  4771. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4772. #endif //RESUME_DEBUG
  4773. #ifdef TMC2130_DEBUG
  4774. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4775. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4776. #endif //TMC2130_DEBUG
  4777. if ( ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) {
  4778. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4779. }
  4780. if (farm_mode)
  4781. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  4782. if ( moves_planned() || printer_active() ) {
  4783. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=18
  4784. } else {
  4785. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
  4786. }
  4787. if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused) {
  4788. if (usb_timer.running()) {
  4789. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_usb_print);
  4790. } else if (IS_SD_PRINTING) {
  4791. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);
  4792. }
  4793. }
  4794. if(isPrintPaused)
  4795. {
  4796. // only allow resuming if hardware errors (temperature or fan) are cleared
  4797. if(!get_temp_error()
  4798. #ifdef FANCHECK
  4799. && ((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  4800. #endif //FANCHECK
  4801. ) {
  4802. if (saved_printing) {
  4803. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);
  4804. } else {
  4805. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print);
  4806. }
  4807. }
  4808. }
  4809. if((IS_SD_PRINTING || usb_timer.running() || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
  4810. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4811. }
  4812. #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
  4813. if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) {
  4814. if (!card.isFileOpen()) {
  4815. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4816. bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
  4817. MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  4818. }
  4819. #if SDCARDDETECT < 1
  4820. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user ////MSG_CNG_SDCARD c=18
  4821. #endif //SDCARDDETECT
  4822. }
  4823. } else {
  4824. bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  4825. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu); ////MSG_NO_CARD c=18
  4826. #if SDCARDDETECT < 1
  4827. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface ////MSG_INIT_SDCARD c=18
  4828. #endif //SDCARDDETECT
  4829. }
  4830. #endif //SDSUPPORT
  4831. if(!isPrintPaused && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4832. if (!farm_mode) {
  4833. const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  4834. const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
  4835. if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
  4836. MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
  4837. }
  4838. }
  4839. }
  4840. if ( ! ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal) ) ) {
  4841. if (MMU2::mmu2.Enabled()) {
  4842. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), mmu_load_filament_menu);
  4843. MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
  4844. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), mmu_unload_filament);
  4845. MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FILAMENT), mmu_fil_eject_menu);
  4846. #ifdef MMU_HAS_CUTTER
  4847. if (eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED) != 0) {
  4848. MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), mmu_cut_filament_menu);
  4849. }
  4850. #endif //MMU_HAS_CUTTER
  4851. } else {
  4852. #ifdef FILAMENT_SENSOR
  4853. if (fsensor.getAutoLoadEnabled()) {
  4854. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
  4855. }
  4856. else
  4857. #endif //FILAMENT_SENSOR
  4858. {
  4859. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4860. }
  4861. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4862. }
  4863. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  4864. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_CALIBRATION), lcd_calibration_menu);
  4865. }
  4866. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  4867. MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
  4868. }
  4869. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  4870. MENU_ITEM_SUBMENU_P(_i("Fail stats"), lcd_menu_fails_stats);////MSG_FAIL_STATS c=18
  4871. #endif
  4872. if (MMU2::mmu2.Enabled()) {
  4873. MENU_ITEM_SUBMENU_P(_i("Fail stats MMU"), lcd_menu_fails_stats_mmu);////MSG_MMU_FAIL_STATS c=18
  4874. }
  4875. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=18
  4876. #ifdef LCD_TEST
  4877. MENU_ITEM_SUBMENU_P(_i("XFLASH init"), lcd_test_menu);////MSG_XFLASH c=18
  4878. #endif //LCD_TEST
  4879. MENU_END();
  4880. }
  4881. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4882. bool stepper_timer_overflow_state = false;
  4883. uint16_t stepper_timer_overflow_max = 0;
  4884. uint16_t stepper_timer_overflow_last = 0;
  4885. uint16_t stepper_timer_overflow_cnt = 0;
  4886. void stepper_timer_overflow() {
  4887. char msg[28];
  4888. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  4889. lcd_setstatus(msg);
  4890. stepper_timer_overflow_state = false;
  4891. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  4892. stepper_timer_overflow_max = stepper_timer_overflow_last;
  4893. SERIAL_ECHOPGM("Stepper timer overflow: ");
  4894. MYSERIAL.print(msg);
  4895. SERIAL_ECHOLNPGM("");
  4896. WRITE(BEEPER, LOW);
  4897. }
  4898. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4899. static void lcd_colorprint_change() {
  4900. enquecommand_P(PSTR("M600"));
  4901. custom_message_type = CustomMsg::FilamentLoading; //just print status message
  4902. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4903. lcd_return_to_status();
  4904. lcd_draw_update = 3;
  4905. }
  4906. #ifdef LA_LIVE_K
  4907. // @wavexx: looks like there's no generic float editing function in menu.cpp so we
  4908. // redefine our custom handling functions to mimick other tunables
  4909. const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S";
  4910. static void lcd_advance_draw_K(char chr, float val)
  4911. {
  4912. if (val <= 0)
  4913. lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, _T(MSG_OFF));
  4914. else
  4915. lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val);
  4916. }
  4917. static void lcd_advance_edit_K(void)
  4918. {
  4919. if (lcd_draw_update)
  4920. {
  4921. if (lcd_encoder < 0) lcd_encoder = 0;
  4922. if (lcd_encoder > 999) lcd_encoder = 999;
  4923. lcd_set_cursor(0, 1);
  4924. lcd_advance_draw_K(' ', 0.01 * lcd_encoder);
  4925. }
  4926. if (LCD_CLICKED)
  4927. {
  4928. extruder_advance_K = 0.01 * lcd_encoder;
  4929. menu_back_no_reset();
  4930. }
  4931. }
  4932. static uint8_t lcd_advance_K()
  4933. {
  4934. if (menu_item == menu_line)
  4935. {
  4936. if (lcd_draw_update)
  4937. {
  4938. lcd_set_cursor(0, menu_row);
  4939. lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K);
  4940. }
  4941. if (menu_clicked && (lcd_encoder == menu_item))
  4942. {
  4943. menu_submenu_no_reset(lcd_advance_edit_K);
  4944. lcd_encoder = 100. * extruder_advance_K;
  4945. return menu_item_ret();
  4946. }
  4947. }
  4948. menu_item++;
  4949. return 0;
  4950. }
  4951. #define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0)
  4952. #endif
  4953. static void lcd_tune_menu()
  4954. {
  4955. typedef struct
  4956. {
  4957. menu_data_edit_t reserved; //!< reserved for number editing functions
  4958. int8_t status; //!< To recognize, whether the menu has been just initialized.
  4959. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  4960. //! it needs to be applied.
  4961. int16_t extrudemultiply;
  4962. } _menu_data_t;
  4963. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  4964. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  4965. if (_md->status == 0)
  4966. {
  4967. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  4968. _md->status = 1;
  4969. _md->extrudemultiply = extrudemultiply;
  4970. }
  4971. else if (_md->extrudemultiply != extrudemultiply)
  4972. {
  4973. // extrudemultiply has been changed from the child menu. Apply the new value.
  4974. _md->extrudemultiply = extrudemultiply;
  4975. calculate_extruder_multipliers();
  4976. }
  4977. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  4978. MENU_BEGIN();
  4979. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  4980. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=15
  4981. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  4982. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);
  4983. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  4984. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=15
  4985. #ifdef LA_LIVE_K
  4986. MENU_ITEM_EDIT_advance_K();//7
  4987. #endif
  4988. #ifdef FILAMENTCHANGEENABLE
  4989. if (!farm_mode)
  4990. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  4991. #endif
  4992. #ifdef FILAMENT_SENSOR
  4993. MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu);
  4994. #endif //FILAMENT_SENSOR
  4995. if (MMU2::mmu2.Enabled())
  4996. {
  4997. SETTINGS_SPOOLJOIN;
  4998. SETTINGS_CUTTER;
  4999. }
  5000. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  5001. #ifdef TMC2130
  5002. if(!farm_mode)
  5003. {
  5004. if (SilentModeMenu == SILENT_MODE_NORMAL) {
  5005. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
  5006. if (lcd_crash_detect_enabled()) {
  5007. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
  5008. } else {
  5009. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
  5010. }
  5011. } else {
  5012. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
  5013. MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
  5014. }
  5015. }
  5016. #else //TMC2130
  5017. if (!farm_mode) { //dont show in menu if we are in farm mode
  5018. switch (SilentModeMenu) {
  5019. case SILENT_MODE_POWER: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break;
  5020. case SILENT_MODE_SILENT: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set); break;
  5021. case SILENT_MODE_AUTO: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set); break;
  5022. default: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break; // (probably) not needed
  5023. }
  5024. }
  5025. #endif //TMC2130
  5026. SETTINGS_MMU_MODE;
  5027. SETTINGS_SOUND;
  5028. #ifdef LCD_BL_PIN
  5029. if (backlightSupport)
  5030. {
  5031. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  5032. }
  5033. #endif //LCD_BL_PIN
  5034. MENU_END();
  5035. }
  5036. static void mbl_magnets_elimination_toggle() {
  5037. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  5038. magnet_elimination = !magnet_elimination;
  5039. eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination);
  5040. }
  5041. static void mbl_mesh_toggle() {
  5042. uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  5043. if(mesh_nr == 3) mesh_nr = 7;
  5044. else mesh_nr = 3;
  5045. eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr);
  5046. }
  5047. static void mbl_probe_nr_toggle() {
  5048. mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR);
  5049. switch (mbl_z_probe_nr) {
  5050. case 1: mbl_z_probe_nr = 3; break;
  5051. case 3: mbl_z_probe_nr = 5; break;
  5052. case 5: mbl_z_probe_nr = 1; break;
  5053. default: mbl_z_probe_nr = 3; break;
  5054. }
  5055. eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr);
  5056. }
  5057. static void lcd_mesh_bed_leveling_settings()
  5058. {
  5059. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  5060. uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  5061. char sToggle[4]; //enough for nxn format
  5062. MENU_BEGIN();
  5063. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5064. sToggle[0] = points_nr + '0';
  5065. sToggle[1] = 'x';
  5066. sToggle[2] = points_nr + '0';
  5067. sToggle[3] = 0;
  5068. MENU_ITEM_TOGGLE(_T(MSG_MESH), sToggle, mbl_mesh_toggle);
  5069. sToggle[0] = mbl_z_probe_nr + '0';
  5070. sToggle[1] = 0;
  5071. MENU_ITEM_TOGGLE(_T(MSG_Z_PROBE_NR), sToggle, mbl_probe_nr_toggle);
  5072. MENU_ITEM_TOGGLE_P(_T(MSG_MAGNETS_COMP), (points_nr == 7) ? (magnet_elimination ? _T(MSG_ON): _T(MSG_OFF)) : _T(MSG_NA), mbl_magnets_elimination_toggle);
  5073. MENU_END();
  5074. //SETTINGS_MBL_MODE;
  5075. }
  5076. #ifdef LCD_BL_PIN
  5077. static void backlight_mode_toggle()
  5078. {
  5079. switch (backlightMode)
  5080. {
  5081. case BACKLIGHT_MODE_BRIGHT: backlightMode = BACKLIGHT_MODE_DIM; break;
  5082. case BACKLIGHT_MODE_DIM: backlightMode = BACKLIGHT_MODE_AUTO; break;
  5083. case BACKLIGHT_MODE_AUTO: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  5084. default: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  5085. }
  5086. backlight_save();
  5087. }
  5088. static void lcd_backlight_menu()
  5089. {
  5090. MENU_BEGIN();
  5091. ON_MENU_LEAVE(
  5092. backlight_save();
  5093. );
  5094. MENU_ITEM_BACK_P(_T(MSG_BACK));
  5095. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
  5096. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
  5097. MENU_ITEM_TOGGLE_P(_T(MSG_MODE), ((backlightMode==BACKLIGHT_MODE_BRIGHT) ? _T(MSG_BRIGHT) : ((backlightMode==BACKLIGHT_MODE_DIM) ? _T(MSG_DIM) : _T(MSG_AUTO))), backlight_mode_toggle);
  5098. MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
  5099. MENU_END();
  5100. }
  5101. #endif //LCD_BL_PIN
  5102. static void lcd_control_temperature_menu()
  5103. {
  5104. #ifdef PIDTEMP
  5105. // set up temp variables - undo the default scaling
  5106. // raw_Ki = unscalePID_i(Ki);
  5107. // raw_Kd = unscalePID_d(Kd);
  5108. #endif
  5109. MENU_BEGIN();
  5110. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5111. #if TEMP_SENSOR_0 != 0
  5112. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5113. #endif
  5114. #if TEMP_SENSOR_1 != 0
  5115. MENU_ITEM_EDIT_int3_P(_n("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  5116. #endif
  5117. #if TEMP_SENSOR_2 != 0
  5118. MENU_ITEM_EDIT_int3_P(_n("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  5119. #endif
  5120. #if TEMP_SENSOR_BED != 0
  5121. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5122. #endif
  5123. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5124. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5125. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  5126. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5127. MENU_ITEM_EDIT(float3, _n(" \xdf Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  5128. MENU_ITEM_EDIT(float3, _n(" \xdf Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  5129. MENU_ITEM_EDIT(float32, _n(" \xdf Fact"), &autotemp_factor, 0.0, 1.0);
  5130. #endif
  5131. MENU_END();
  5132. }
  5133. static void lcd_sd_refresh()
  5134. {
  5135. #if SDCARDDETECT == -1
  5136. card.initsd();
  5137. #else
  5138. card.presort();
  5139. #endif
  5140. menu_top = 0;
  5141. lcd_encoder = 0;
  5142. menu_data_reset(); //Forces reloading of cached variables.
  5143. }
  5144. static void lcd_sd_updir()
  5145. {
  5146. card.updir();
  5147. menu_top = 0;
  5148. lcd_encoder = 0;
  5149. menu_data_reset(); //Forces reloading of cached variables.
  5150. }
  5151. // continue stopping the print from the main loop after lcd_print_stop() is called
  5152. void print_stop()
  5153. {
  5154. // save printing time
  5155. stoptime = _millis();
  5156. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5157. save_statistics(total_filament_used, t);
  5158. // lift Z
  5159. raise_z(10);
  5160. // if axis are homed, move to parking position.
  5161. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) {
  5162. current_position[X_AXIS] = X_CANCEL_POS;
  5163. current_position[Y_AXIS] = Y_CANCEL_POS;
  5164. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5165. }
  5166. st_synchronize();
  5167. // did we come here from a thermal error?
  5168. if(get_temp_error()) {
  5169. // time to stop the error beep
  5170. WRITE(BEEPER, LOW);
  5171. } else {
  5172. // Turn off the print fan
  5173. fanSpeed = 0;
  5174. }
  5175. if (MMU2::mmu2.Enabled())
  5176. {
  5177. if (isPrintPaused)
  5178. {
  5179. // Restore temperature saved in ram after pausing print
  5180. restore_extruder_temperature_from_ram();
  5181. }
  5182. MMU2::mmu2.unload(); //M702 C
  5183. }
  5184. lcd_cooldown(); //turns off heaters and fan; goes to status screen.
  5185. finishAndDisableSteppers(); //M84
  5186. axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative
  5187. }
  5188. void lcd_print_stop()
  5189. {
  5190. // UnconditionalStop() will internally cause planner_abort_hard(), meaning we _cannot_ plan
  5191. // any more move in this call! Any further move must happen inside print_stop(), which is called
  5192. // by the main loop one iteration later.
  5193. UnconditionalStop();
  5194. if (!card.sdprinting) {
  5195. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
  5196. }
  5197. #ifdef MESH_BED_LEVELING
  5198. mbl.active = false;
  5199. #endif
  5200. // clear any pending paused state immediately
  5201. pause_time = 0;
  5202. isPrintPaused = false;
  5203. // return to status is required to continue processing in the main loop!
  5204. lcd_commands_type = LcdCommands::StopPrint;
  5205. lcd_return_to_status();
  5206. }
  5207. #ifdef TEMP_MODEL
  5208. void lcd_temp_model_cal()
  5209. {
  5210. lcd_commands_type = LcdCommands::TempModel;
  5211. lcd_return_to_status();
  5212. }
  5213. #endif //TEMP_MODEL
  5214. void lcd_sdcard_stop()
  5215. {
  5216. lcd_puts_at_P(0, 0, _T(MSG_STOP_PRINT));
  5217. lcd_puts_at_P(2, 2, _T(MSG_NO));
  5218. lcd_puts_at_P(2, 3, _T(MSG_YES));
  5219. lcd_putc_at(0, 2, ' ');
  5220. lcd_putc_at(0, 3, ' ');
  5221. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  5222. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  5223. lcd_putc_at(0, 1 + lcd_encoder, '>');
  5224. if (lcd_clicked())
  5225. {
  5226. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5227. if ((int32_t)lcd_encoder == 1)
  5228. {
  5229. lcd_return_to_status();
  5230. }
  5231. if ((int32_t)lcd_encoder == 2)
  5232. {
  5233. lcd_print_stop();
  5234. }
  5235. }
  5236. }
  5237. void lcd_sdcard_menu()
  5238. {
  5239. enum menuState_t : uint8_t {_uninitialized, _standard, _scrolling};
  5240. typedef struct
  5241. {
  5242. menuState_t menuState = _uninitialized;
  5243. uint8_t offset;
  5244. bool isDir;
  5245. const char* scrollPointer;
  5246. uint16_t selectedFileID;
  5247. uint16_t fileCnt;
  5248. int8_t row;
  5249. uint8_t sdSort;
  5250. ShortTimer lcd_scrollTimer;
  5251. } _menu_data_sdcard_t;
  5252. static_assert(sizeof(menu_data)>= sizeof(_menu_data_sdcard_t),"_menu_data_sdcard_t doesn't fit into menu_data");
  5253. _menu_data_sdcard_t* _md = (_menu_data_sdcard_t*)&(menu_data[0]);
  5254. switch(_md->menuState)
  5255. {
  5256. case _uninitialized: //Initialize menu data
  5257. {
  5258. if (card.presort_flag == true) //used to force resorting if sorting type is changed.
  5259. {
  5260. card.presort_flag = false;
  5261. lcd_update_enabled = false;
  5262. card.presort();
  5263. lcd_update_enabled = true;
  5264. }
  5265. _md->fileCnt = card.getnrfilenames();
  5266. _md->sdSort = farm_mode ? SD_SORT_NONE : eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5267. _md->menuState = _standard;
  5268. _md->row = -1; // assume that no SD file/dir is currently selected. Once they are rendered, it will be changed to the correct row for the _scrolling state.
  5269. }
  5270. // FALLTHRU
  5271. case _standard: //normal menu structure.
  5272. {
  5273. if (!_md->lcd_scrollTimer.running()) //if the timer is not running, then the menu state was just switched, so redraw the screen.
  5274. {
  5275. _md->lcd_scrollTimer.start();
  5276. lcd_draw_update = 1;
  5277. }
  5278. if ((lcd_draw_update == 0) && _md->lcd_scrollTimer.expired(500) && (_md->row != -1)) //switch to the scrolling state on timeout if a file/dir is selected.
  5279. {
  5280. _md->menuState = _scrolling;
  5281. _md->offset = 0;
  5282. _md->scrollPointer = NULL;
  5283. _md->lcd_scrollTimer.start();
  5284. lcd_draw_update = 1; //forces last load before switching to scrolling.
  5285. }
  5286. if (lcd_draw_update == 0 && !LCD_CLICKED)
  5287. return; // nothing to do (so don't thrash the SD card)
  5288. _md->row = -1; // assume that no SD file/dir is currently selected. Once they are rendered, it will be changed to the correct row for the _scrolling state.
  5289. //if we reached this point it means that the encoder moved or clicked or the state is being switched. Reset the scrollTimer.
  5290. _md->lcd_scrollTimer.start();
  5291. MENU_BEGIN();
  5292. MENU_ITEM_BACK_P(_T(bMain?MSG_MAIN:MSG_BACK)); // i.e. default menu-item / menu-item after card insertion
  5293. card.getWorkDirName();
  5294. if (card.filename[0] == '/')
  5295. {
  5296. #if SDCARDDETECT == -1
  5297. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5298. #else
  5299. if (card.ToshibaFlashAir_isEnabled())
  5300. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); //show the refresh option if in flashAir mode.
  5301. #endif
  5302. }
  5303. else
  5304. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); //Show the updir button if in a subdir.
  5305. for (uint16_t i = _md->fileCnt; i-- > 0;) // Every file, from top to bottom.
  5306. {
  5307. if (menu_item == menu_line) //If the file is on the screen.
  5308. {
  5309. //load filename to memory.
  5310. #ifdef SDCARD_SORT_ALPHA
  5311. card.getfilename_sorted(i, _md->sdSort);
  5312. #else
  5313. card.getfilename(i);
  5314. #endif
  5315. if (lcd_encoder == menu_item) //If the file is selected.
  5316. {
  5317. _md->selectedFileID = i;
  5318. _md->isDir = card.filenameIsDir;
  5319. _md->row = menu_row;
  5320. }
  5321. if (card.filenameIsDir)
  5322. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  5323. else
  5324. MENU_ITEM_SDFILE(card.filename, card.longFilename);
  5325. }
  5326. else MENU_ITEM_DUMMY(); //dummy item that just increments the internal menu counters.
  5327. }
  5328. MENU_END();
  5329. } break;
  5330. case _scrolling: //scrolling filename
  5331. {
  5332. const bool rewindFlag = LCD_CLICKED || lcd_draw_update; //flag that says whether the menu should return to _standard state.
  5333. if (_md->scrollPointer == NULL)
  5334. {
  5335. //load filename to memory.
  5336. #ifdef SDCARD_SORT_ALPHA
  5337. card.getfilename_sorted(_md->selectedFileID, _md->sdSort);
  5338. #else
  5339. card.getfilename(_md->selectedFileID);
  5340. #endif
  5341. _md->scrollPointer = (card.longFilename[0] == '\0') ? card.filename : card.longFilename;
  5342. }
  5343. if (rewindFlag == 1)
  5344. _md->offset = 0; //redraw once again from the beginning.
  5345. if (_md->lcd_scrollTimer.expired(300) || rewindFlag)
  5346. {
  5347. uint8_t len = LCD_WIDTH - ((_md->isDir)? 2 : 1);
  5348. lcd_set_cursor(0, _md->row);
  5349. lcd_print('>');
  5350. if (_md->isDir)
  5351. lcd_print(LCD_STR_FOLDER[0]);
  5352. if( lcd_print_pad(&_md->scrollPointer[_md->offset], len) )
  5353. {
  5354. _md->lcd_scrollTimer.start();
  5355. _md->offset++;
  5356. } else {
  5357. // stop at the end of the string
  5358. _md->lcd_scrollTimer.stop();
  5359. }
  5360. }
  5361. if (rewindFlag) //go back to sd_menu.
  5362. {
  5363. _md->lcd_scrollTimer.stop(); //forces redraw in _standard state
  5364. _md->menuState = _standard;
  5365. }
  5366. } break;
  5367. default: _md->menuState = _uninitialized; //shouldn't ever happen. Anyways, initialize the menu.
  5368. }
  5369. }
  5370. #ifdef TMC2130
  5371. static void lcd_belttest_v()
  5372. {
  5373. lcd_belttest();
  5374. menu_back_if_clicked();
  5375. }
  5376. void lcd_belttest()
  5377. {
  5378. lcd_clear();
  5379. // Belttest requires high power mode. Enable it.
  5380. FORCE_HIGH_POWER_START;
  5381. uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  5382. uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  5383. lcd_printf_P(_T(MSG_CHECKING_X));
  5384. lcd_set_cursor(0,1), lcd_printf_P(PSTR("X: %u -> ..."),X);
  5385. KEEPALIVE_STATE(IN_HANDLER);
  5386. // N.B: it doesn't make sense to handle !lcd_selfcheck...() because selftest_sg throws its own error screen
  5387. // that clobbers ours, with more info than we could provide. So on fail we just fall through to take us back to status.
  5388. if (lcd_selfcheck_axis_sg(X_AXIS)){
  5389. X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  5390. lcd_set_cursor(10,1), lcd_printf_P(PSTR("%u"),X); // Show new X value next to old one.
  5391. lcd_puts_at_P(0,2,_T(MSG_CHECKING_Y));
  5392. lcd_set_cursor(0,3), lcd_printf_P(PSTR("Y: %u -> ..."),Y);
  5393. if (lcd_selfcheck_axis_sg(Y_AXIS))
  5394. {
  5395. Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  5396. lcd_set_cursor(10,3),lcd_printf_P(PSTR("%u"),Y);
  5397. lcd_set_cursor(19, 3);
  5398. lcd_print(LCD_STR_UPLEVEL[0]);
  5399. lcd_wait_for_click_delay(10);
  5400. }
  5401. }
  5402. FORCE_HIGH_POWER_END;
  5403. KEEPALIVE_STATE(NOT_BUSY);
  5404. }
  5405. #endif //TMC2130
  5406. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5407. // called also from marlin_main.cpp
  5408. void printf_IRSensorAnalogBoardChange(){
  5409. printf_P(PSTR("Filament sensor board change detected: revision%S\n"), fsensor.getIRVersionText());
  5410. }
  5411. static bool lcd_selftest_IRsensor(bool bStandalone)
  5412. {
  5413. FSensorBlockRunout fsBlockRunout;
  5414. IR_sensor_analog::SensorRevision oldSensorRevision = fsensor.getSensorRevision();
  5415. IR_sensor_analog::SensorRevision newSensorRevision;
  5416. uint16_t volt_IR_int = fsensor.getVoltRaw();
  5417. newSensorRevision = (volt_IR_int < fsensor.IRsensor_Hopen_TRESHOLD) ? IR_sensor_analog::SensorRevision::_Rev04 : IR_sensor_analog::SensorRevision::_Old;
  5418. printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"), Raw2Voltage(volt_IR_int) );
  5419. if(volt_IR_int < fsensor.IRsensor_Hmin_TRESHOLD){
  5420. if(!bStandalone)
  5421. lcd_selftest_error(TestError::FsensorLevel,"HIGH","");
  5422. return false;
  5423. }
  5424. lcd_show_fullscreen_message_and_wait_P(_i("Insert the filament (do not load it) into the extruder and then press the knob."));////MSG_INSERT_FIL c=20 r=6
  5425. volt_IR_int = fsensor.getVoltRaw();
  5426. printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"), Raw2Voltage(volt_IR_int));
  5427. if(volt_IR_int > (fsensor.IRsensor_Lmax_TRESHOLD)){
  5428. if(!bStandalone)
  5429. lcd_selftest_error(TestError::FsensorLevel,"LOW","");
  5430. return false;
  5431. }
  5432. if(newSensorRevision != oldSensorRevision) {
  5433. fsensor.setSensorRevision(newSensorRevision, true);
  5434. printf_IRSensorAnalogBoardChange();
  5435. }
  5436. return true;
  5437. }
  5438. static void lcd_detect_IRsensor(){
  5439. bool bAction;
  5440. bool loaded;
  5441. /// Check if filament is loaded. If it is loaded stop detection.
  5442. /// @todo Add autodetection with MMU2s
  5443. loaded = fsensor.getFilamentPresent();
  5444. if(loaded){
  5445. lcd_show_fullscreen_message_and_wait_P(_i("Please unload the filament first, then repeat this action."));////MSG_UNLOAD_FILAMENT_REPEAT c=20 r=4
  5446. return;
  5447. } else {
  5448. lcd_show_fullscreen_message_and_wait_P(_i("Please check the IR sensor connection, unload filament if present."));////MSG_CHECK_IR_CONNECTION c=20 r=4
  5449. bAction = lcd_selftest_IRsensor(true);
  5450. }
  5451. if(bAction){
  5452. lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now."));////MSG_FS_VERIFIED c=20 r=3
  5453. fsensor.init();
  5454. } else {
  5455. lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again."));////MSG_FIL_FAILED c=20 r=5
  5456. }
  5457. }
  5458. #endif //IR_SENSOR_ANALOG
  5459. static void lcd_selftest_v()
  5460. {
  5461. (void)lcd_selftest();
  5462. }
  5463. bool lcd_selftest()
  5464. {
  5465. uint8_t _progress = 0;
  5466. bool _result = true;
  5467. bool _swapped_fan = false;
  5468. #if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5469. //! Check if IR sensor is in unknown state, if so run Fsensor Detection
  5470. //! As the Fsensor Detection isn't yet ready for the mmu2s we set temporarily the IR sensor 0.3 or older for mmu2s
  5471. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  5472. if(fsensor.getSensorRevision() == IR_sensor_analog::SensorRevision::_Undef) {
  5473. if (!MMU2::mmu2.Enabled()) {
  5474. lcd_detect_IRsensor();
  5475. }
  5476. else {
  5477. fsensor.setSensorRevision(IR_sensor_analog::SensorRevision::_Old, true);
  5478. }
  5479. }
  5480. #endif
  5481. lcd_wait_for_cool_down();
  5482. lcd_clear();
  5483. lcd_puts_at_P(0, 0, _i("Self test start"));////MSG_SELFTEST_START c=20
  5484. #ifdef TMC2130
  5485. FORCE_HIGH_POWER_START;
  5486. #endif // TMC2130
  5487. FORCE_BL_ON_START;
  5488. _delay(2000);
  5489. KEEPALIVE_STATE(IN_HANDLER);
  5490. _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
  5491. #if (defined(FANCHECK) && defined(TACH_0))
  5492. switch (lcd_selftest_fan_auto(0)){ // check hotend fan
  5493. case FanCheck::SwappedFan:
  5494. _swapped_fan = true; // swapped is merely a hint (checked later)
  5495. // FALLTHRU
  5496. case FanCheck::Success:
  5497. _result = true;
  5498. break;
  5499. default:
  5500. _result = false;
  5501. break;
  5502. }
  5503. #else //defined(TACH_0)
  5504. _result = lcd_selftest_manual_fan_check(0, false);
  5505. #endif //defined(TACH_0)
  5506. if (!_result)
  5507. {
  5508. lcd_selftest_error(TestError::ExtruderFan, "", "");
  5509. }
  5510. if (_result)
  5511. {
  5512. _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
  5513. #if (defined(FANCHECK) && defined(TACH_1))
  5514. switch (lcd_selftest_fan_auto(1)){ // check print fan
  5515. case FanCheck::SwappedFan:
  5516. _swapped_fan = true; // swapped is merely a hint (checked later)
  5517. // FALLTHRU
  5518. case FanCheck::Success:
  5519. _result = true;
  5520. break;
  5521. default:
  5522. _result = false;
  5523. break;
  5524. }
  5525. #else //defined(TACH_1)
  5526. _result = lcd_selftest_manual_fan_check(1, false);
  5527. #endif //defined(TACH_1)
  5528. if (!_result)
  5529. {
  5530. lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning
  5531. }
  5532. }
  5533. if (_swapped_fan) {
  5534. //turn on print fan and check that left hotend fan is not spinning
  5535. _result = lcd_selftest_manual_fan_check(1, true);
  5536. if (_result) {
  5537. //print fan is stil turned on; check that it is spinning
  5538. _result = lcd_selftest_manual_fan_check(1, false, true);
  5539. if (!_result){
  5540. lcd_selftest_error(TestError::PrintFan, "", "");
  5541. }
  5542. }
  5543. else {
  5544. // fans are swapped
  5545. lcd_selftest_error(TestError::SwappedFan, "", "");
  5546. }
  5547. }
  5548. if (_result)
  5549. {
  5550. _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000);
  5551. _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested.
  5552. }
  5553. if (_result)
  5554. {
  5555. //current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed
  5556. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000);
  5557. #ifdef TMC2130
  5558. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5559. #else
  5560. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5561. #endif //TMC2130
  5562. }
  5563. if (_result)
  5564. {
  5565. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0);
  5566. #ifndef TMC2130
  5567. _result = lcd_selfcheck_pulleys(X_AXIS);
  5568. #endif
  5569. }
  5570. if (_result)
  5571. {
  5572. _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500);
  5573. #ifdef TMC2130
  5574. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5575. #else
  5576. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5577. #endif // TMC2130
  5578. }
  5579. if (_result)
  5580. {
  5581. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0);
  5582. #ifndef TMC2130
  5583. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5584. #endif // TMC2130
  5585. }
  5586. if (_result)
  5587. {
  5588. #ifdef TMC2130
  5589. tmc2130_home_exit();
  5590. enable_endstops(false);
  5591. #endif
  5592. //homeaxis(X_AXIS);
  5593. //homeaxis(Y_AXIS);
  5594. current_position[X_AXIS] = pgm_read_float(bed_ref_points_4);
  5595. current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+1);
  5596. #ifdef TMC2130
  5597. //current_position[X_AXIS] += 0;
  5598. current_position[Y_AXIS] += 4;
  5599. #endif //TMC2130
  5600. raise_z(10);
  5601. set_destination_to_current();
  5602. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500);
  5603. #ifdef TMC2130
  5604. homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function.
  5605. #else
  5606. _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS);
  5607. #endif //TMC2130
  5608. //raise Z to not damage the bed during and hotend testing
  5609. raise_z(20);
  5610. }
  5611. #ifdef TMC2130
  5612. if (_result)
  5613. {
  5614. raise_z(10);
  5615. _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0);
  5616. bool bres = tmc2130_home_calibrate(X_AXIS);
  5617. _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0);
  5618. bres &= tmc2130_home_calibrate(Y_AXIS);
  5619. _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0);
  5620. if (bres)
  5621. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5622. _result = bres;
  5623. }
  5624. #endif //TMC2130
  5625. if (_result)
  5626. {
  5627. _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000);
  5628. _result = lcd_selfcheck_check_heater(true);
  5629. }
  5630. if (_result)
  5631. {
  5632. _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000);
  5633. _result = lcd_selfcheck_check_heater(false);
  5634. }
  5635. if (_result)
  5636. {
  5637. _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok
  5638. }
  5639. #ifdef FILAMENT_SENSOR
  5640. if (_result)
  5641. {
  5642. #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5643. if (MMU2::mmu2.Enabled())
  5644. {
  5645. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  5646. _result = selftest_irsensor();
  5647. if (_result)
  5648. {
  5649. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  5650. }
  5651. } else
  5652. #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5653. {
  5654. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  5655. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  5656. _result = lcd_selftest_fsensor();
  5657. if (_result)
  5658. {
  5659. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  5660. }
  5661. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  5662. #if 0
  5663. // Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
  5664. // The idea is not to force the user to remove and insert the filament on an assembled printer.
  5665. //defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  5666. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor
  5667. _result = lcd_selftest_IRsensor();
  5668. if (_result)
  5669. {
  5670. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //filament sensor OK
  5671. }
  5672. #endif //IR_SENSOR_ANALOG
  5673. }
  5674. }
  5675. #endif //FILAMENT_SENSOR
  5676. if (_result)
  5677. {
  5678. _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct
  5679. }
  5680. else
  5681. {
  5682. _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000);
  5683. }
  5684. lcd_reset_alert_level();
  5685. enquecommand_P(PSTR("M84"));
  5686. lcd_update_enable(true);
  5687. if (_result)
  5688. {
  5689. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=20
  5690. }
  5691. else
  5692. {
  5693. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5694. }
  5695. #ifdef TMC2130
  5696. FORCE_HIGH_POWER_END;
  5697. #endif // TMC2130
  5698. FORCE_BL_ON_END;
  5699. KEEPALIVE_STATE(NOT_BUSY);
  5700. return(_result);
  5701. }
  5702. #ifdef TMC2130
  5703. static void reset_crash_det(uint8_t axis) {
  5704. current_position[axis] += 10;
  5705. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5706. st_synchronize();
  5707. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5708. }
  5709. static bool lcd_selfcheck_axis_sg(uint8_t axis) {
  5710. // each axis length is measured twice
  5711. float axis_length, current_position_init, current_position_final;
  5712. float measured_axis_length[2];
  5713. float margin = 60;
  5714. float max_error_mm = 5;
  5715. switch (axis) {
  5716. case 0: axis_length = X_MAX_POS; break;
  5717. case 1: axis_length = Y_MAX_POS + 8; break;
  5718. default: axis_length = 210; break;
  5719. }
  5720. tmc2130_sg_stop_on_crash = false;
  5721. tmc2130_home_exit();
  5722. enable_endstops(true);
  5723. raise_z_above(MESH_HOME_Z_SEARCH);
  5724. tmc2130_home_enter(1 << axis);
  5725. // first axis length measurement begin
  5726. current_position[axis] -= (axis_length + margin);
  5727. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5728. st_synchronize();
  5729. tmc2130_sg_meassure_start(axis);
  5730. current_position_init = st_get_position_mm(axis);
  5731. current_position[axis] += 2 * margin;
  5732. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5733. st_synchronize();
  5734. current_position[axis] += axis_length;
  5735. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5736. st_synchronize();
  5737. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5738. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5739. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5740. current_position_final = st_get_position_mm(axis);
  5741. measured_axis_length[0] = fabs(current_position_final - current_position_init);
  5742. // first measurement end and second measurement begin
  5743. current_position[axis] -= margin;
  5744. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5745. st_synchronize();
  5746. current_position[axis] -= (axis_length + margin);
  5747. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5748. st_synchronize();
  5749. current_position_init = st_get_position_mm(axis);
  5750. measured_axis_length[1] = fabs(current_position_final - current_position_init);
  5751. tmc2130_home_exit();
  5752. //end of second measurement, now check for possible errors:
  5753. for(uint_least8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5754. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5755. if (fabs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5756. enable_endstops(false);
  5757. const char *_error_1;
  5758. if (axis == X_AXIS) _error_1 = "X";
  5759. if (axis == Y_AXIS) _error_1 = "Y";
  5760. if (axis == Z_AXIS) _error_1 = "Z";
  5761. lcd_selftest_error(TestError::Axis, _error_1, "");
  5762. current_position[axis] = 0;
  5763. plan_set_position_curposXYZE();
  5764. reset_crash_det(axis);
  5765. enable_endstops(true);
  5766. endstops_hit_on_purpose();
  5767. return false;
  5768. }
  5769. }
  5770. printf_P(_N("Axis length difference:%.3f\n"), fabs(measured_axis_length[0] - measured_axis_length[1]));
  5771. if (fabs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5772. //loose pulleys
  5773. const char *_error_1;
  5774. if (axis == X_AXIS) _error_1 = "X";
  5775. if (axis == Y_AXIS) _error_1 = "Y";
  5776. if (axis == Z_AXIS) _error_1 = "Z";
  5777. lcd_selftest_error(TestError::Pulley, _error_1, "");
  5778. current_position[axis] = 0;
  5779. plan_set_position_curposXYZE();
  5780. reset_crash_det(axis);
  5781. endstops_hit_on_purpose();
  5782. return false;
  5783. }
  5784. current_position[axis] = 0;
  5785. plan_set_position_curposXYZE();
  5786. reset_crash_det(axis);
  5787. endstops_hit_on_purpose();
  5788. return true;
  5789. }
  5790. #endif //TMC2130
  5791. #ifndef TMC2130
  5792. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5793. {
  5794. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5795. bool _stepdone = false;
  5796. bool _stepresult = false;
  5797. uint8_t _progress = 0;
  5798. int _travel_done = 0;
  5799. int _err_endstop = 0;
  5800. int _lcd_refresh = 0;
  5801. _travel = _travel + (_travel / 10);
  5802. if (_axis == X_AXIS) {
  5803. current_position[Z_AXIS] += 17;
  5804. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5805. }
  5806. do {
  5807. current_position[_axis] = current_position[_axis] - 1;
  5808. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5809. st_synchronize();
  5810. #ifdef TMC2130
  5811. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5812. #else //TMC2130
  5813. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  5814. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  5815. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5816. #endif //TMC2130
  5817. {
  5818. if (_axis == 0)
  5819. {
  5820. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5821. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5822. }
  5823. if (_axis == 1)
  5824. {
  5825. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5826. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5827. }
  5828. if (_axis == 2)
  5829. {
  5830. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5831. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5832. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5833. /*disable_x();
  5834. disable_y();
  5835. disable_z();*/
  5836. }
  5837. _stepdone = true;
  5838. }
  5839. if (_lcd_refresh < 6)
  5840. {
  5841. _lcd_refresh++;
  5842. }
  5843. else
  5844. {
  5845. _progress = lcd_selftest_screen(static_cast<TestScreen>(static_cast<int>(TestScreen::AxisX) + _axis), _progress, 3, false, 0);
  5846. _lcd_refresh = 0;
  5847. }
  5848. manage_heater();
  5849. manage_inactivity(true);
  5850. //_delay(100);
  5851. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5852. } while (!_stepdone);
  5853. //current_position[_axis] = current_position[_axis] + 15;
  5854. //plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder);
  5855. if (!_stepresult)
  5856. {
  5857. const char *_error_1;
  5858. const char *_error_2;
  5859. if (_axis == X_AXIS) _error_1 = "X";
  5860. if (_axis == Y_AXIS) _error_1 = "Y";
  5861. if (_axis == Z_AXIS) _error_1 = "Z";
  5862. if (_err_endstop == 0) _error_2 = "X";
  5863. if (_err_endstop == 1) _error_2 = "Y";
  5864. if (_err_endstop == 2) _error_2 = "Z";
  5865. if (_travel_done >= _travel)
  5866. {
  5867. lcd_selftest_error(TestError::Endstop, _error_1, _error_2);
  5868. }
  5869. else
  5870. {
  5871. lcd_selftest_error(TestError::Motor, _error_1, _error_2);
  5872. }
  5873. }
  5874. current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z.
  5875. plan_set_position_curposXYZE();
  5876. return _stepresult;
  5877. }
  5878. static bool lcd_selfcheck_pulleys(int axis)
  5879. {
  5880. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5881. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5882. float current_position_init;
  5883. float move;
  5884. bool endstop_triggered = false;
  5885. int i;
  5886. unsigned long timeout_counter;
  5887. refresh_cmd_timeout();
  5888. manage_inactivity(true);
  5889. if (axis == 0) move = 50; //X_AXIS
  5890. else move = 50; //Y_AXIS
  5891. current_position_init = current_position[axis];
  5892. current_position[axis] += 2;
  5893. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5894. for (i = 0; i < 5; i++) {
  5895. refresh_cmd_timeout();
  5896. current_position[axis] = current_position[axis] + move;
  5897. st_current_set(0, 850); //set motor current higher
  5898. plan_buffer_line_curposXYZE(200);
  5899. st_synchronize();
  5900. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5901. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5902. current_position[axis] = current_position[axis] - move;
  5903. plan_buffer_line_curposXYZE(50);
  5904. st_synchronize();
  5905. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5906. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5907. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  5908. return(false);
  5909. }
  5910. }
  5911. timeout_counter = _millis() + 2500;
  5912. endstop_triggered = false;
  5913. manage_inactivity(true);
  5914. while (!endstop_triggered) {
  5915. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5916. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5917. endstop_triggered = true;
  5918. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5919. current_position[axis] += 10;
  5920. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5921. st_synchronize();
  5922. return(true);
  5923. }
  5924. else {
  5925. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  5926. return(false);
  5927. }
  5928. }
  5929. else {
  5930. current_position[axis] -= 1;
  5931. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5932. st_synchronize();
  5933. if (_millis() > timeout_counter) {
  5934. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  5935. return(false);
  5936. }
  5937. }
  5938. }
  5939. return(true);
  5940. }
  5941. #endif //not defined TMC2130
  5942. static bool lcd_selfcheck_endstops()
  5943. {
  5944. bool _result = true;
  5945. if (
  5946. #ifndef TMC2130
  5947. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5948. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5949. #endif //!TMC2130
  5950. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5951. {
  5952. #ifndef TMC2130
  5953. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5954. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5955. #endif //!TMC2130
  5956. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5957. }
  5958. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  5959. st_synchronize();
  5960. if (
  5961. #ifndef TMC2130
  5962. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5963. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5964. #endif //!TMC2130
  5965. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5966. {
  5967. _result = false;
  5968. char _error[4] = "";
  5969. #ifndef TMC2130
  5970. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5971. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5972. #endif //!TMC2130
  5973. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5974. lcd_selftest_error(TestError::Endstops, _error, "");
  5975. }
  5976. manage_heater();
  5977. manage_inactivity(true);
  5978. return _result;
  5979. }
  5980. static bool lcd_selfcheck_check_heater(bool _isbed)
  5981. {
  5982. uint8_t _counter = 0;
  5983. uint8_t _progress = 0;
  5984. bool _stepresult = false;
  5985. bool _docycle = true;
  5986. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5987. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5988. uint8_t _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5989. target_temperature[0] = (_isbed) ? 0 : 200;
  5990. target_temperature_bed = (_isbed) ? 100 : 0;
  5991. manage_heater();
  5992. manage_inactivity(true);
  5993. do {
  5994. _counter++;
  5995. _docycle = (_counter < _cycles) ? true : false;
  5996. manage_heater();
  5997. manage_inactivity(true);
  5998. _progress = (_isbed) ? lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) : lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400);
  5999. /*if (_isbed) {
  6000. MYSERIAL.print("Bed temp:");
  6001. MYSERIAL.println(degBed());
  6002. }
  6003. else {
  6004. MYSERIAL.print("Hotend temp:");
  6005. MYSERIAL.println(degHotend(0));
  6006. }*/
  6007. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  6008. } while (_docycle);
  6009. target_temperature[0] = 0;
  6010. target_temperature_bed = 0;
  6011. manage_heater();
  6012. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  6013. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  6014. /*
  6015. MYSERIAL.println("");
  6016. MYSERIAL.print("Checked result:");
  6017. MYSERIAL.println(_checked_result);
  6018. MYSERIAL.print("Opposite result:");
  6019. MYSERIAL.println(_opposite_result);
  6020. */
  6021. if (_opposite_result < ((_isbed) ? 30 : 9))
  6022. {
  6023. if (_checked_result >= ((_isbed) ? 9 : 30))
  6024. {
  6025. _stepresult = true;
  6026. }
  6027. else
  6028. {
  6029. lcd_selftest_error(TestError::Heater, "", "");
  6030. }
  6031. }
  6032. else
  6033. {
  6034. lcd_selftest_error(TestError::Bed, "", "");
  6035. }
  6036. manage_heater();
  6037. manage_inactivity(true);
  6038. return _stepresult;
  6039. }
  6040. static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2)
  6041. {
  6042. lcd_beeper_quick_feedback();
  6043. FORCE_BL_ON_END;
  6044. target_temperature[0] = 0;
  6045. target_temperature_bed = 0;
  6046. manage_heater();
  6047. manage_inactivity();
  6048. lcd_clear();
  6049. lcd_puts_at_P(0, 0, _i("Selftest error!"));////MSG_SELFTEST_ERROR c=20
  6050. lcd_puts_at_P(0, 1, _i("Please check:"));////MSG_SELFTEST_PLEASECHECK c=20
  6051. switch (testError)
  6052. {
  6053. case TestError::Heater:
  6054. lcd_puts_at_P(0, 2, _i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=20
  6055. lcd_puts_at_P(0, 3, _i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=20
  6056. break;
  6057. case TestError::Bed:
  6058. lcd_puts_at_P(0, 2, _i("Bed/Heater"));////MSG_SELFTEST_BEDHEATER c=20
  6059. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6060. break;
  6061. case TestError::Endstops:
  6062. lcd_puts_at_P(0, 2, _i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=20
  6063. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6064. lcd_set_cursor(18, 3);
  6065. lcd_print(_error_1);
  6066. break;
  6067. case TestError::Motor:
  6068. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_MOTOR));
  6069. lcd_set_cursor(18, 2);
  6070. lcd_print(_error_1);
  6071. lcd_puts_at_P(0, 3, _i("Endstop"));////MSG_SELFTEST_ENDSTOP c=16
  6072. lcd_set_cursor(18, 3);
  6073. lcd_print(_error_2);
  6074. break;
  6075. case TestError::Endstop:
  6076. lcd_puts_at_P(0, 2, _i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20
  6077. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  6078. lcd_set_cursor(18, 3);
  6079. lcd_print(_error_1);
  6080. break;
  6081. case TestError::PrintFan:
  6082. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_PART_FAN));
  6083. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6084. lcd_set_cursor(18, 3);
  6085. lcd_print(_error_1);
  6086. break;
  6087. case TestError::ExtruderFan:
  6088. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_HOTEND_FAN));
  6089. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6090. lcd_set_cursor(18, 3);
  6091. lcd_print(_error_1);
  6092. break;
  6093. case TestError::Pulley:
  6094. lcd_puts_at_P(0, 2, _i("Loose pulley"));////MSG_LOOSE_PULLEY c=20
  6095. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  6096. lcd_set_cursor(18, 3);
  6097. lcd_print(_error_1);
  6098. break;
  6099. case TestError::Axis:
  6100. lcd_puts_at_P(0, 2, _i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=20
  6101. lcd_puts_at_P(0, 3, _i("Axis"));////MSG_SELFTEST_AXIS c=16
  6102. lcd_set_cursor(18, 3);
  6103. lcd_print(_error_1);
  6104. break;
  6105. case TestError::SwappedFan:
  6106. lcd_puts_at_P(0, 2, _i("Front/left fans"));////MSG_SELFTEST_FANS c=20
  6107. lcd_puts_at_P(0, 3, _i("Swapped"));////MSG_SELFTEST_SWAPPED c=16
  6108. lcd_set_cursor(18, 3);
  6109. lcd_print(_error_1);
  6110. break;
  6111. case TestError::WiringFsensor:
  6112. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6113. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  6114. break;
  6115. case TestError::TriggeringFsensor:
  6116. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6117. lcd_puts_at_P(0, 3, _i("False triggering"));////MSG_FALSE_TRIGGERING c=20
  6118. break;
  6119. case TestError::FsensorLevel:
  6120. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6121. lcd_set_cursor(0, 3);
  6122. lcd_printf_P(_i("%s level expected"),_error_1);////MSG_SELFTEST_FS_LEVEL c=20
  6123. break;
  6124. }
  6125. _delay(1000);
  6126. lcd_beeper_quick_feedback();
  6127. do {
  6128. _delay(100);
  6129. manage_heater();
  6130. manage_inactivity();
  6131. } while (!lcd_clicked());
  6132. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6133. lcd_return_to_status();
  6134. }
  6135. #ifdef FILAMENT_SENSOR
  6136. #if FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  6137. static bool lcd_selftest_fsensor(void)
  6138. {
  6139. fsensor.init();
  6140. if (fsensor.isError())
  6141. {
  6142. lcd_selftest_error(TestError::WiringFsensor, "", "");
  6143. }
  6144. return (!fsensor.isError());
  6145. }
  6146. #endif //FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125
  6147. #if (FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  6148. //! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
  6149. //!
  6150. //! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
  6151. //!
  6152. //! Steps:
  6153. //! * Backup current active extruder temperature
  6154. //! * Pre-heat to PLA extrude temperature.
  6155. //! * Unload filament possibly present.
  6156. //! * Move extruder idler same way as during filament load
  6157. //! and sample the filament sensor.
  6158. //! * Check that pin doesn't go low.
  6159. //!
  6160. //! @retval true passed
  6161. //! @retval false failed
  6162. static bool selftest_irsensor()
  6163. {
  6164. class TempBackup
  6165. {
  6166. public:
  6167. TempBackup():
  6168. m_temp(degTargetHotend(active_extruder)),
  6169. m_extruder(active_extruder){}
  6170. ~TempBackup(){setTargetHotend(m_temp,m_extruder);}
  6171. private:
  6172. float m_temp;
  6173. uint8_t m_extruder;
  6174. };
  6175. uint8_t progress;
  6176. {
  6177. TempBackup tempBackup;
  6178. setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder);
  6179. progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0);
  6180. }
  6181. progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  6182. MMU2::mmu2.unload();
  6183. for(uint_least8_t i = 0; i < 200; ++i)
  6184. {
  6185. if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  6186. //@@TODO mmu_load_step(false);
  6187. while (blocks_queued())
  6188. {
  6189. if (fsensor.getFilamentPresent())
  6190. {
  6191. lcd_selftest_error(TestError::TriggeringFsensor, "", "");
  6192. return false;
  6193. }
  6194. #ifdef TMC2130
  6195. manage_heater();
  6196. // Vojtech: Don't disable motors inside the planner!
  6197. if (!tmc2130_update_sg())
  6198. {
  6199. manage_inactivity(true);
  6200. }
  6201. #else //TMC2130
  6202. manage_heater();
  6203. // Vojtech: Don't disable motors inside the planner!
  6204. manage_inactivity(true);
  6205. #endif //TMC2130
  6206. }
  6207. }
  6208. return true;
  6209. }
  6210. #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG)
  6211. #endif //FILAMENT_SENSOR
  6212. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  6213. bool _default)
  6214. {
  6215. bool _result = check_opposite;
  6216. lcd_clear();
  6217. lcd_puts_at_P(0, 0, _T(MSG_SELFTEST_FAN));
  6218. switch (_fan)
  6219. {
  6220. case 0:
  6221. // extruder cooling fan
  6222. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_PART_FAN) : _T(MSG_SELFTEST_HOTEND_FAN));
  6223. setExtruderAutoFanState(3);
  6224. break;
  6225. case 1:
  6226. // object cooling fan
  6227. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_HOTEND_FAN) : _T(MSG_SELFTEST_PART_FAN));
  6228. SET_OUTPUT(FAN_PIN);
  6229. #ifdef FAN_SOFT_PWM
  6230. fanSpeedSoftPwm = 255;
  6231. #else //FAN_SOFT_PWM
  6232. analogWrite(FAN_PIN, 255);
  6233. #endif //FAN_SOFT_PWM
  6234. break;
  6235. }
  6236. _delay(500);
  6237. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6238. lcd_putc_at(0, 3, '>');
  6239. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6240. int8_t enc_dif = int(_default)*3;
  6241. KEEPALIVE_STATE(PAUSED_FOR_USER);
  6242. lcd_button_pressed = false;
  6243. do
  6244. {
  6245. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  6246. if (enc_dif > lcd_encoder_diff) {
  6247. _result = !check_opposite;
  6248. lcd_putc_at(0, 2, '>');
  6249. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6250. lcd_putc_at(0, 3, ' ');
  6251. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6252. }
  6253. if (enc_dif < lcd_encoder_diff) {
  6254. _result = check_opposite;
  6255. lcd_putc_at(0, 2, ' ');
  6256. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  6257. lcd_putc_at(0, 3, '>');
  6258. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  6259. }
  6260. enc_dif = 0;
  6261. lcd_encoder_diff = 0;
  6262. }
  6263. manage_heater();
  6264. _delay(100);
  6265. } while (!lcd_clicked());
  6266. KEEPALIVE_STATE(IN_HANDLER);
  6267. setExtruderAutoFanState(0);
  6268. SET_OUTPUT(FAN_PIN);
  6269. #ifdef FAN_SOFT_PWM
  6270. fanSpeedSoftPwm = 0;
  6271. #else //FAN_SOFT_PWM
  6272. analogWrite(FAN_PIN, 0);
  6273. #endif //FAN_SOFT_PWM
  6274. fanSpeed = 0;
  6275. manage_heater();
  6276. return _result;
  6277. }
  6278. #ifdef FANCHECK
  6279. // Set print fan speed
  6280. static void lcd_selftest_setfan(uint8_t speed) {
  6281. // set the fan speed
  6282. fanSpeed = speed;
  6283. #ifdef FAN_SOFT_PWM
  6284. fanSpeedSoftPwm = speed;
  6285. #endif
  6286. manage_heater();
  6287. }
  6288. // Wait for the specified number of seconds while displaying some single-character indicator on the
  6289. // screen coordinate col/row, then perform fan measurement
  6290. static void lcd_selftest_measure_fans(uint8_t delay, uint8_t col, uint8_t row) {
  6291. // spin-up delay
  6292. static char symbols[] = {'-', '|'};
  6293. static_assert(1000 / sizeof(symbols) * sizeof(symbols) == 1000);
  6294. while(delay--) {
  6295. for(uint8_t i = 0; i != sizeof(symbols); ++i) {
  6296. lcd_putc_at(col, row, symbols[i]);
  6297. delay_keep_alive(1000 / sizeof(symbols));
  6298. }
  6299. }
  6300. #ifdef FANCHECK
  6301. extruder_autofan_last_check = _millis();
  6302. #endif
  6303. fan_measuring = true;
  6304. while(fan_measuring) {
  6305. delay_keep_alive(100);
  6306. }
  6307. gcode_M123();
  6308. }
  6309. static FanCheck lcd_selftest_fan_auto(uint8_t _fan)
  6310. {
  6311. // speed threshold to differentiate between extruder and print fan
  6312. static const int printFanThr = FANCHECK_AUTO_PRINT_FAN_THRS; // >= FANCHECK_AUTO_PRINT_FAN_THRS RPS
  6313. // speed threshold to mark a fan as failed
  6314. static const int failThr = FANCHECK_AUTO_FAIL_THRS; // < FANCHECK_AUTO_FAIL_THRS RPM would mean either a faulty Noctua, Altfan or print fan
  6315. switch (_fan) {
  6316. case 0:
  6317. setExtruderAutoFanState(3); // hotend fan
  6318. lcd_selftest_setfan(0); // print fan off
  6319. lcd_selftest_measure_fans(2, 18, 2);
  6320. setExtruderAutoFanState(0); // hotend fan off
  6321. if (fan_speed[0] < failThr) {
  6322. return FanCheck::ExtruderFan;
  6323. }
  6324. if (fan_speed[0] >= printFanThr ) {
  6325. return FanCheck::SwappedFan;
  6326. }
  6327. break;
  6328. case 1:
  6329. lcd_selftest_setfan(255);
  6330. lcd_selftest_measure_fans(5, 18, 3);
  6331. lcd_selftest_setfan(0);
  6332. if (fan_speed[1] < failThr) {
  6333. return FanCheck::PrintFan;
  6334. }
  6335. if (fan_speed[1] < printFanThr) {
  6336. return FanCheck::SwappedFan;
  6337. }
  6338. }
  6339. return FanCheck::Success;
  6340. }
  6341. #endif //FANCHECK
  6342. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay)
  6343. {
  6344. lcd_update_enable(false);
  6345. const char *_indicator = (_progress >= _progress_scale) ? "-" : "|";
  6346. if (_clear) lcd_clear();
  6347. lcd_set_cursor(0, 0);
  6348. if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6349. if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6350. if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6351. if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20
  6352. if (screen == TestScreen::AxisX) lcd_puts_P(_T(MSG_CHECKING_X));
  6353. if (screen == TestScreen::AxisY) lcd_puts_P(_T(MSG_CHECKING_Y));
  6354. if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis"));////MSG_SELFTEST_CHECK_Z c=20
  6355. if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  6356. if (screen == TestScreen::Hotend
  6357. || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend"));////MSG_SELFTEST_CHECK_HOTEND c=20
  6358. if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6359. if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6360. if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct"));////MSG_SELFTEST_CHECK_ALLCORRECT c=20
  6361. if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  6362. if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////MSG_CALIBRATING_HOME c=20
  6363. lcd_puts_at_P(0, 1, separator);
  6364. if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk))
  6365. {
  6366. //SERIAL_ECHOLNPGM("Fan test");
  6367. lcd_puts_at_P(0, 2, _T(MSG_HOTEND_FAN_SPEED));
  6368. lcd_set_cursor(18, 2);
  6369. (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK");
  6370. lcd_puts_at_P(0, 3, _T(MSG_PRINT_FAN_SPEED));
  6371. lcd_set_cursor(18, 3);
  6372. (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK");
  6373. }
  6374. else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk)
  6375. {
  6376. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  6377. lcd_putc(':');
  6378. lcd_set_cursor(18, 2);
  6379. (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK");
  6380. }
  6381. else if (screen < TestScreen::Fsensor)
  6382. {
  6383. //SERIAL_ECHOLNPGM("Other tests");
  6384. TestScreen _step_block = TestScreen::AxisX;
  6385. lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("X"), _indicator);
  6386. _step_block = TestScreen::AxisY;
  6387. lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Y"), _indicator);
  6388. _step_block = TestScreen::AxisZ;
  6389. lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Z"), _indicator);
  6390. _step_block = TestScreen::Bed;
  6391. lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Bed"), _indicator);
  6392. _step_block = TestScreen::Hotend;
  6393. lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Hotend"), _indicator);
  6394. }
  6395. if (_delay > 0) delay_keep_alive(_delay);
  6396. _progress++;
  6397. return (_progress >= _progress_scale * 2) ? 0 : _progress;
  6398. }
  6399. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name_PROGMEM, const char *_indicator)
  6400. {
  6401. lcd_set_cursor(_col, _row);
  6402. uint8_t strlenNameP = strlen_P(_name_PROGMEM);
  6403. switch (_state)
  6404. {
  6405. case 1:
  6406. lcd_puts_P(_name_PROGMEM);
  6407. lcd_putc_at(_col + strlenNameP, _row, ':');
  6408. lcd_set_cursor(_col + strlenNameP + 1, _row);
  6409. lcd_print(_indicator);
  6410. break;
  6411. case 2:
  6412. lcd_puts_P(_name_PROGMEM);
  6413. lcd_putc_at(_col + strlenNameP, _row, ':');
  6414. lcd_puts_at_P(_col + strlenNameP + 1, _row, PSTR("OK"));
  6415. break;
  6416. default:
  6417. lcd_puts_P(_name_PROGMEM);
  6418. }
  6419. }
  6420. /** End of menus **/
  6421. /** Menu action functions **/
  6422. static bool check_file(const char* filename) {
  6423. if (farm_mode) return true;
  6424. card.openFileReadFilteredGcode(filename, true);
  6425. bool result = false;
  6426. const uint32_t filesize = card.getFileSize();
  6427. uint32_t startPos = 0;
  6428. const uint16_t bytesToCheck = min(END_FILE_SECTION, filesize);
  6429. if (filesize > END_FILE_SECTION) {
  6430. startPos = filesize - END_FILE_SECTION;
  6431. card.setIndex(startPos);
  6432. }
  6433. cmdqueue_reset();
  6434. cmdqueue_serial_disabled = true;
  6435. menu_progressbar_init(bytesToCheck, _i("Checking file"));////MSG_CHECKING_FILE c=17
  6436. while (!card.eof() && !result) {
  6437. menu_progressbar_update(card.get_sdpos() - startPos);
  6438. card.sdprinting = true;
  6439. get_command();
  6440. result = check_commands();
  6441. #ifdef CMDBUFFER_DEBUG
  6442. // Kick watchdog because the file check is very slow
  6443. // with the CMDBUFFER_DEBUG enabled
  6444. manage_heater();
  6445. #endif // CMDBUFFER_DEBUG
  6446. }
  6447. menu_progressbar_finish();
  6448. cmdqueue_serial_disabled = false;
  6449. card.printingHasFinished();
  6450. lcd_setstatuspgm(MSG_WELCOME);
  6451. return result;
  6452. }
  6453. static void menu_action_sdfile(const char* filename)
  6454. {
  6455. loading_flag = false;
  6456. char cmd[30];
  6457. char* c;
  6458. bool result = true;
  6459. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6460. for (c = &cmd[4]; *c; c++)
  6461. *c = tolower(*c);
  6462. const char end[5] = ".gco";
  6463. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6464. for (uint_least8_t i = 0; i < 8; i++) {
  6465. if (strcmp((cmd + i + 4), end) == 0) {
  6466. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6467. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6468. break;
  6469. }
  6470. else {
  6471. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6472. }
  6473. }
  6474. uint8_t depth = card.getWorkDirDepth();
  6475. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6476. for (uint_least8_t i = 0; i < depth; i++) {
  6477. for (uint_least8_t j = 0; j < 8; j++) {
  6478. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
  6479. }
  6480. }
  6481. //filename is just a pointer to card.filename, which changes everytime you try to open a file by filename. So you can't use filename directly
  6482. //to open a file. Instead, the cached filename in cmd is used as that one is static for the whole lifetime of this function.
  6483. if (!check_file(cmd + 4)) {
  6484. result = !lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false);////MSG_FILE_INCOMPLETE c=20 r=3
  6485. lcd_update_enable(true);
  6486. }
  6487. if (result) {
  6488. enquecommand(cmd);
  6489. enquecommand_P(PSTR("M24"));
  6490. }
  6491. lcd_return_to_status();
  6492. }
  6493. void menu_action_sddirectory(const char* filename)
  6494. {
  6495. card.chdir(filename, true);
  6496. lcd_encoder = 0;
  6497. menu_data_reset(); //Forces reloading of cached variables.
  6498. }
  6499. /** LCD API **/
  6500. void ultralcd_init()
  6501. {
  6502. backlight_init();
  6503. lcd_init();
  6504. lcd_refresh();
  6505. lcd_longpress_func = menu_lcd_longpress_func;
  6506. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  6507. menu_menu = lcd_status_screen;
  6508. SET_INPUT(BTN_EN1);
  6509. SET_INPUT(BTN_EN2);
  6510. WRITE(BTN_EN1, HIGH);
  6511. WRITE(BTN_EN2, HIGH);
  6512. #if BTN_ENC > 0
  6513. SET_INPUT(BTN_ENC);
  6514. WRITE(BTN_ENC, HIGH);
  6515. #endif
  6516. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6517. SET_INPUT(SDCARDDETECT);
  6518. WRITE(SDCARDDETECT, HIGH);
  6519. _delay_ms(1); //wait for the pullups to raise the line
  6520. lcd_oldcardstatus = IS_SD_INSERTED;
  6521. #endif//(SDCARDDETECT > 0)
  6522. lcd_encoder_diff = 0;
  6523. // Initialise status line
  6524. strncpy_P(lcd_status_message, MSG_WELCOME, LCD_WIDTH);
  6525. }
  6526. void lcd_ignore_click(bool b)
  6527. {
  6528. ignore_click = b;
  6529. wait_for_unclick = false;
  6530. }
  6531. static bool lcd_message_check(uint8_t priority)
  6532. {
  6533. // regular priority check
  6534. if (priority >= lcd_status_message_level)
  6535. return true;
  6536. // check if we can override an info message yet
  6537. if (lcd_status_message_level == LCD_STATUS_INFO) {
  6538. return lcd_status_message_timeout.expired_cont(LCD_STATUS_INFO_TIMEOUT);
  6539. }
  6540. return false;
  6541. }
  6542. static void lcd_updatestatus(const char *message, bool progmem = false)
  6543. {
  6544. if (progmem)
  6545. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6546. else
  6547. strncpy(lcd_status_message, message, LCD_WIDTH);
  6548. lcd_status_message[LCD_WIDTH] = 0;
  6549. SERIAL_PROTOCOLLNRPGM(MSG_LCD_STATUS_CHANGED);
  6550. // hack lcd_draw_update to 1, i.e. without clear
  6551. lcd_draw_update = 1;
  6552. }
  6553. void lcd_setstatus(const char* message)
  6554. {
  6555. if (lcd_message_check(LCD_STATUS_NONE))
  6556. lcd_updatestatus(message);
  6557. }
  6558. void lcd_setstatuspgm(const char* message)
  6559. {
  6560. if (lcd_message_check(LCD_STATUS_NONE))
  6561. lcd_updatestatus(message, true);
  6562. }
  6563. void lcd_setstatus_serial(const char* message)
  6564. {
  6565. if (lcd_message_check(LCD_STATUS_NONE))
  6566. lcd_updatestatus(message);
  6567. SERIAL_ECHOLN(message);
  6568. }
  6569. void lcd_setalertstatus_(const char* message, uint8_t severity, bool progmem)
  6570. {
  6571. if (lcd_message_check(severity)) {
  6572. bool same = !(progmem?
  6573. strcmp_P(lcd_status_message, message):
  6574. strcmp(lcd_status_message, message));
  6575. lcd_updatestatus(message, progmem);
  6576. lcd_status_message_timeout.start();
  6577. lcd_status_message_level = severity;
  6578. custom_message_type = CustomMsg::Status;
  6579. custom_message_state = 0;
  6580. if (!same) {
  6581. // do not kick the user out of the menus if the message is unchanged
  6582. lcd_return_to_status();
  6583. }
  6584. }
  6585. }
  6586. void lcd_setalertstatus(const char* message, uint8_t severity)
  6587. {
  6588. lcd_setalertstatus_(message, severity, false);
  6589. }
  6590. void lcd_setalertstatuspgm(const char* message, uint8_t severity)
  6591. {
  6592. lcd_setalertstatus_(message, severity, true);
  6593. }
  6594. void lcd_reset_alert_level()
  6595. {
  6596. lcd_status_message_level = 0;
  6597. }
  6598. uint8_t get_message_level()
  6599. {
  6600. return lcd_status_message_level;
  6601. }
  6602. void menu_lcd_longpress_func(void)
  6603. {
  6604. // Wake up the LCD backlight and,
  6605. // start LCD inactivity timer
  6606. lcd_timeoutToStatus.start();
  6607. backlight_wake();
  6608. if (homing_flag || mesh_bed_leveling_flag || menu_menu == lcd_babystep_z || menu_menu == lcd_move_z || menu_block_mask != MENU_BLOCK_NONE)
  6609. {
  6610. // disable longpress during re-entry, while homing, calibration or if a serious error
  6611. lcd_quick_feedback();
  6612. return;
  6613. }
  6614. if (menu_menu == lcd_hw_setup_menu)
  6615. {
  6616. // only toggle the experimental menu visibility flag
  6617. lcd_quick_feedback();
  6618. eeprom_toggle((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  6619. return;
  6620. }
  6621. // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
  6622. // The lists are not the same for both functions, so first decide which function is to be performed
  6623. if ( (moves_planned() || IS_SD_PRINTING || usb_timer.running() )){ // long press as live-adj-z
  6624. if (( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
  6625. && ( menu_menu == lcd_status_screen // and in listed menus...
  6626. || menu_menu == lcd_main_menu
  6627. || menu_menu == lcd_tune_menu
  6628. || menu_menu == lcd_support_menu
  6629. )
  6630. ){
  6631. lcd_clear();
  6632. menu_submenu(lcd_babystep_z);
  6633. } else {
  6634. lcd_quick_feedback();
  6635. }
  6636. } else { // long press as move-z
  6637. if (menu_menu == lcd_status_screen
  6638. || menu_menu == lcd_main_menu
  6639. || menu_menu == lcd_preheat_menu
  6640. || menu_menu == lcd_sdcard_menu
  6641. || menu_menu == lcd_settings_menu
  6642. || menu_menu == lcd_control_temperature_menu
  6643. #if (LANG_MODE != 0)
  6644. || menu_menu == lcd_language
  6645. #endif
  6646. || menu_menu == lcd_support_menu
  6647. ){
  6648. menu_submenu(lcd_move_z);
  6649. } else {
  6650. lcd_quick_feedback();
  6651. }
  6652. }
  6653. }
  6654. static inline bool z_menu_expired()
  6655. {
  6656. return (menu_menu == lcd_babystep_z
  6657. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  6658. }
  6659. static inline bool other_menu_expired()
  6660. {
  6661. return (menu_menu != lcd_status_screen
  6662. && menu_menu != lcd_babystep_z
  6663. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  6664. }
  6665. void menu_lcd_lcdupdate_func(void)
  6666. {
  6667. #if (SDCARDDETECT > 0)
  6668. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  6669. {
  6670. if(menu_menu == lcd_sdcard_menu) {
  6671. // If the user is either inside the submenus
  6672. // 1. 'Print from SD' --> and SD card is removed
  6673. // 2. 'No SD card' --> and SD card is inserted
  6674. //
  6675. // 1. 'Print from SD': We want to back out of this submenu
  6676. // and instead show the submenu title 'No SD card'.
  6677. //
  6678. // 2. 'No SD card': When the user inserts the SD card we want
  6679. // to back out of this submenu. Not only to show
  6680. // 'Print from SD' submenu title but also because the user
  6681. // will be prompted with another menu with the sorted list of files.
  6682. // Without backing out of the menu, the list will appear empty and
  6683. // The user will need to back out of two nested submenus.
  6684. menu_back();
  6685. }
  6686. lcd_draw_update = 2;
  6687. lcd_oldcardstatus = IS_SD_INSERTED;
  6688. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  6689. backlight_wake();
  6690. if (lcd_oldcardstatus)
  6691. {
  6692. if (!card.cardOK)
  6693. {
  6694. card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back()
  6695. card.presort_flag = true; //force sorting of the SD menu
  6696. }
  6697. LCD_MESSAGERPGM(MSG_WELCOME);
  6698. bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  6699. menu_submenu(lcd_sdcard_menu);
  6700. lcd_timeoutToStatus.start();
  6701. }
  6702. else
  6703. {
  6704. card.release();
  6705. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=20
  6706. }
  6707. }
  6708. #endif//CARDINSERTED
  6709. backlight_update();
  6710. if (lcd_next_update_millis < _millis())
  6711. {
  6712. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  6713. {
  6714. if (lcd_draw_update == 0)
  6715. lcd_draw_update = 1;
  6716. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  6717. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  6718. lcd_encoder_diff = 0;
  6719. lcd_timeoutToStatus.start();
  6720. backlight_wake();
  6721. }
  6722. if (LCD_CLICKED)
  6723. {
  6724. lcd_timeoutToStatus.start();
  6725. backlight_wake();
  6726. }
  6727. (*menu_menu)();
  6728. if (z_menu_expired() || other_menu_expired())
  6729. {
  6730. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  6731. // to give it a chance to save its state.
  6732. // This is useful for example, when the babystep value has to be written into EEPROM.
  6733. if (menu_menu != NULL)
  6734. {
  6735. menu_leaving = 1;
  6736. (*menu_menu)();
  6737. menu_leaving = 0;
  6738. }
  6739. lcd_clear();
  6740. lcd_return_to_status();
  6741. lcd_draw_update = 2;
  6742. }
  6743. if (lcd_draw_update == 2) lcd_clear();
  6744. if (lcd_draw_update) lcd_draw_update--;
  6745. lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
  6746. }
  6747. prusa_statistics_update_from_lcd_update();
  6748. if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
  6749. }
  6750. #ifdef TMC2130
  6751. //! @brief Is crash detection enabled?
  6752. //!
  6753. //! @retval true crash detection enabled
  6754. //! @retval false crash detection disabled
  6755. bool lcd_crash_detect_enabled()
  6756. {
  6757. return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
  6758. }
  6759. void lcd_crash_detect_enable()
  6760. {
  6761. tmc2130_sg_stop_on_crash = true;
  6762. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
  6763. }
  6764. void lcd_crash_detect_disable()
  6765. {
  6766. tmc2130_sg_stop_on_crash = false;
  6767. tmc2130_sg_crash = 0;
  6768. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
  6769. }
  6770. #endif
  6771. #ifdef TMC2130
  6772. void UserECool_toggle(){
  6773. // this is only called when the experimental menu is visible, thus the first condition for enabling of the ECool mode is met in this place
  6774. // The condition is intentionally inverted as we are toggling the state (i.e. if it was enabled, we are disabling the feature and vice versa)
  6775. bool enable = ! UserECoolEnabled();
  6776. eeprom_update_byte((uint8_t *)EEPROM_ECOOL_ENABLE, enable ? EEPROM_ECOOL_MAGIC_NUMBER : EEPROM_EMPTY_VALUE);
  6777. // @@TODO I don't like this - disabling the experimental menu shall disable ECool mode, but it will not reinit the TMC
  6778. // and I don't want to add more code for this experimental feature ... ideally do not reinit the TMC here at all and let the user reset the printer.
  6779. tmc2130_init(TMCInitParams(enable));
  6780. }
  6781. #endif
  6782. /// Enable experimental support for cooler operation of the extruder motor
  6783. /// Beware - REQUIRES original Prusa MK3/S/+ extruder motor with adequate maximal current
  6784. /// Therefore we don't want to allow general usage of this feature in public as the community likes to
  6785. /// change motors for various reasons and unless the motor is rotating, we cannot verify its properties
  6786. /// (which would be obviously too late for an improperly sized motor)
  6787. /// For farm printing, the cooler E-motor is enabled by default.
  6788. bool UserECoolEnabled(){
  6789. // We enable E-cool mode for non-farm prints IFF the experimental menu is visible AND the EEPROM_ECOOL variable has
  6790. // a value of the universal answer to all problems of the universe
  6791. return ( eeprom_read_byte((uint8_t *)EEPROM_ECOOL_ENABLE) == EEPROM_ECOOL_MAGIC_NUMBER )
  6792. && ( eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY) == 1 );
  6793. }
  6794. bool FarmOrUserECool(){
  6795. return farm_mode || UserECoolEnabled();
  6796. }
  6797. #ifdef PRUSA_SN_SUPPORT
  6798. void WorkaroundPrusaSN() {
  6799. const char *SN = PSTR("CZPXInvalidSerialNr");
  6800. for (uint8_t i = 0; i < 20; i++) {
  6801. eeprom_update_byte((uint8_t*)EEPROM_PRUSA_SN + i, pgm_read_byte(SN++));
  6802. }
  6803. }
  6804. #endif //PRUSA_SN_SUPPORT
  6805. void lcd_experimental_menu()
  6806. {
  6807. MENU_BEGIN();
  6808. MENU_ITEM_BACK_P(_T(MSG_BACK));
  6809. #ifdef EXTRUDER_ALTFAN_DETECT
  6810. MENU_ITEM_TOGGLE_P(_N("ALTFAN det."), altfanOverride_get()?_T(MSG_OFF):_T(MSG_ON), altfanOverride_toggle);////MSG_MENU_ALTFAN c=18
  6811. #endif //EXTRUDER_ALTFAN_DETECT
  6812. #ifdef TMC2130
  6813. MENU_ITEM_TOGGLE_P(_N("E-cool mode"), UserECoolEnabled()?_T(MSG_ON):_T(MSG_OFF), UserECool_toggle);////MSG_MENU_ECOOL c=18
  6814. #endif
  6815. #ifdef DEBUG_PULLUP_CRASH
  6816. MENU_ITEM_FUNCTION_P(_N("Test Pullup Crash"), TestPullupCrash);
  6817. #endif // DEBUG_PULLUP_CRASH
  6818. #ifdef PRUSA_SN_SUPPORT
  6819. MENU_ITEM_FUNCTION_P(_N("Fake serial number"), WorkaroundPrusaSN);////MSG_WORKAROUND_PRUSA_SN c=18
  6820. #endif //PRUSA_SN_SUPPORT
  6821. MENU_END();
  6822. }
  6823. #ifdef PINDA_TEMP_COMP
  6824. void lcd_pinda_temp_compensation_toggle()
  6825. {
  6826. uint8_t pinda_temp_compensation = eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION);
  6827. if (pinda_temp_compensation == EEPROM_EMPTY_VALUE) // On MK2.5/S the EEPROM_EMPTY_VALUE will be set to 0 during eeprom_init.
  6828. pinda_temp_compensation = 1; // But for MK3/S it should be 1 so SuperPINDA is "active"
  6829. else
  6830. pinda_temp_compensation = !pinda_temp_compensation;
  6831. eeprom_update_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, pinda_temp_compensation);
  6832. SERIAL_ECHOLNPGM("SuperPINDA:");
  6833. SERIAL_ECHOLN(pinda_temp_compensation);
  6834. }
  6835. #endif //PINDA_TEMP_COMP