ultralcd.cpp 246 KB

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