ultralcd.cpp 269 KB

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