ultralcd.cpp 270 KB

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