ultralcd.cpp 243 KB

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