ultralcd.cpp 243 KB

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