ultralcd.cpp 269 KB

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