ultralcd.cpp 271 KB

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