ultralcd.cpp 270 KB

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