ultralcd.cpp 271 KB

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