ultralcd.cpp 246 KB

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