ultralcd.cpp 269 KB

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