ultralcd.cpp 270 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905
  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 = usb_timer.running()?_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. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1801. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=18
  1802. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=18
  1803. MENU_ITEM_SUBMENU_P(_i("Sensor info"), lcd_menu_show_sensors_state);////MSG_INFO_SENSORS c=18
  1804. #ifdef TMC2130
  1805. MENU_ITEM_SUBMENU_P(_T(MSG_BELT_STATUS), lcd_menu_belt_status);////MSG_BELT_STATUS c=18
  1806. #endif //TMC2130
  1807. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=18
  1808. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1809. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=18
  1810. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1811. #ifdef MENU_DUMP
  1812. MENU_ITEM_FUNCTION_P(_i("Dump memory"), lcd_dump_memory);
  1813. #endif //MENU_DUMP
  1814. #ifdef MENU_SERIAL_DUMP
  1815. if (emergency_serial_dump)
  1816. MENU_ITEM_FUNCTION_P(_i("Dump to serial"), lcd_serial_dump);
  1817. #endif
  1818. #ifdef DEBUG_BUILD
  1819. #ifdef EMERGENCY_HANDLERS
  1820. #ifdef WATCHDOG
  1821. MENU_ITEM_FUNCTION_P(PSTR("WDR crash"), lcd_wdr_crash);
  1822. #endif //WATCHDOG
  1823. MENU_ITEM_FUNCTION_P(PSTR("Stack crash"), lcd_stack_crash);
  1824. #endif //EMERGENCY_HANDLERS
  1825. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////MSG_DEBUG c=18
  1826. #endif /* DEBUG_BUILD */
  1827. MENU_END();
  1828. }
  1829. void lcd_set_fan_check() {
  1830. fans_check_enabled = !fans_check_enabled;
  1831. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1832. #ifdef FANCHECK
  1833. if (fans_check_enabled == false) fan_check_error = EFCE_OK; //reset error if fanCheck is disabled during error. Allows resuming print.
  1834. #endif //FANCHECK
  1835. }
  1836. #ifdef MMU_HAS_CUTTER
  1837. void lcd_cutter_enabled()
  1838. {
  1839. if (EEPROM_MMU_CUTTER_ENABLED_enabled == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1840. {
  1841. #ifndef MMU_ALWAYS_CUT
  1842. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1843. }
  1844. #else //MMU_ALWAYS_CUT
  1845. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_always);
  1846. }
  1847. else if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
  1848. {
  1849. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, 0);
  1850. }
  1851. #endif //MMU_ALWAYS_CUT
  1852. else
  1853. {
  1854. eeprom_update_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED, EEPROM_MMU_CUTTER_ENABLED_enabled);
  1855. }
  1856. }
  1857. #endif //MMU_HAS_CUTTER
  1858. void lcd_set_filament_autoload() {
  1859. fsensor_autoload_set(!fsensor_autoload_enabled);
  1860. }
  1861. #if defined(FILAMENT_SENSOR) && defined(PAT9125)
  1862. void lcd_set_filament_oq_meass()
  1863. {
  1864. fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled);
  1865. }
  1866. #endif
  1867. FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad'
  1868. bool bFilamentFirstRun;
  1869. bool bFilamentPreheatState;
  1870. bool bFilamentAction=false;
  1871. static bool bFilamentWaitingFlag=false;
  1872. static void mFilamentPrompt()
  1873. {
  1874. uint8_t nLevel;
  1875. lcd_set_cursor(0,0);
  1876. lcdui_print_temp(LCD_STR_THERMOMETER[0],(int)degHotend(0),(int)degTargetHotend(0));
  1877. lcd_puts_at_P(0,1, _i("Press the knob")); ////MSG_PRESS_KNOB c=20
  1878. lcd_set_cursor(0,2);
  1879. switch(eFilamentAction)
  1880. {
  1881. case FilamentAction::Load:
  1882. case FilamentAction::AutoLoad:
  1883. case FilamentAction::MmuLoad:
  1884. lcd_puts_P(_i("to load filament")); ////MSG_TO_LOAD_FIL c=20
  1885. break;
  1886. case FilamentAction::UnLoad:
  1887. case FilamentAction::MmuUnLoad:
  1888. lcd_puts_P(_i("to unload filament")); ////MSG_TO_UNLOAD_FIL c=20
  1889. break;
  1890. case FilamentAction::MmuEject:
  1891. case FilamentAction::MmuCut:
  1892. case FilamentAction::None:
  1893. case FilamentAction::Preheat:
  1894. case FilamentAction::Lay1Cal:
  1895. break;
  1896. }
  1897. if(lcd_clicked())
  1898. {
  1899. nLevel=2;
  1900. if(!bFilamentPreheatState)
  1901. {
  1902. nLevel++;
  1903. // setTargetHotend0(0.0); // uncoment if return to base-state is required
  1904. }
  1905. menu_back(nLevel);
  1906. switch(eFilamentAction)
  1907. {
  1908. case FilamentAction::AutoLoad:
  1909. eFilamentAction=FilamentAction::None; // i.e. non-autoLoad
  1910. // FALLTHRU
  1911. case FilamentAction::Load:
  1912. loading_flag=true;
  1913. enquecommand_P(PSTR("M701")); // load filament
  1914. break;
  1915. case FilamentAction::UnLoad:
  1916. enquecommand_P(PSTR("M702")); // unload filament
  1917. break;
  1918. case FilamentAction::MmuLoad:
  1919. case FilamentAction::MmuUnLoad:
  1920. case FilamentAction::MmuEject:
  1921. case FilamentAction::MmuCut:
  1922. case FilamentAction::None:
  1923. case FilamentAction::Preheat:
  1924. case FilamentAction::Lay1Cal:
  1925. break;
  1926. }
  1927. }
  1928. }
  1929. void mFilamentItem(uint16_t nTemp, uint16_t nTempBed)
  1930. {
  1931. static int nTargetOld;
  1932. static int nTargetBedOld;
  1933. uint8_t nLevel;
  1934. nTargetOld = target_temperature[0];
  1935. nTargetBedOld = target_temperature_bed;
  1936. setTargetHotend0((float )nTemp);
  1937. setTargetBed((float) nTempBed);
  1938. {
  1939. const FilamentAction action = eFilamentAction;
  1940. if (action == FilamentAction::Preheat || action == FilamentAction::Lay1Cal)
  1941. {
  1942. lcd_return_to_status();
  1943. if (action == FilamentAction::Lay1Cal)
  1944. {
  1945. lcd_commands_type = LcdCommands::Layer1Cal;
  1946. }
  1947. else
  1948. {
  1949. raise_z_above(MIN_Z_FOR_PREHEAT);
  1950. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  1951. lcd_wizard(WizState::LoadFilHot);
  1952. }
  1953. return;
  1954. }
  1955. }
  1956. lcd_timeoutToStatus.stop();
  1957. if (current_temperature[0] > (target_temperature[0] * 0.95))
  1958. {
  1959. switch (eFilamentAction)
  1960. {
  1961. case FilamentAction::Load:
  1962. case FilamentAction::AutoLoad:
  1963. case FilamentAction::UnLoad:
  1964. if (bFilamentWaitingFlag) menu_submenu(mFilamentPrompt);
  1965. else
  1966. {
  1967. nLevel = bFilamentPreheatState ? 1 : 2;
  1968. menu_back(nLevel);
  1969. if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad))
  1970. {
  1971. loading_flag = true;
  1972. enquecommand_P(PSTR("M701")); // load filament
  1973. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  1974. }
  1975. if (eFilamentAction == FilamentAction::UnLoad)
  1976. enquecommand_P(PSTR("M702")); // unload filament
  1977. }
  1978. break;
  1979. case FilamentAction::MmuLoad:
  1980. nLevel = bFilamentPreheatState ? 1 : 2;
  1981. bFilamentAction = true;
  1982. menu_back(nLevel);
  1983. menu_submenu(mmu_load_to_nozzle_menu);
  1984. break;
  1985. case FilamentAction::MmuUnLoad:
  1986. nLevel = bFilamentPreheatState ? 1 : 2;
  1987. bFilamentAction = true;
  1988. menu_back(nLevel);
  1989. extr_unload();
  1990. break;
  1991. case FilamentAction::MmuEject:
  1992. nLevel = bFilamentPreheatState ? 1 : 2;
  1993. bFilamentAction = true;
  1994. menu_back(nLevel);
  1995. menu_submenu(mmu_fil_eject_menu);
  1996. break;
  1997. case FilamentAction::MmuCut:
  1998. #ifdef MMU_HAS_CUTTER
  1999. nLevel=bFilamentPreheatState?1:2;
  2000. bFilamentAction=true;
  2001. menu_back(nLevel);
  2002. menu_submenu(mmu_cut_filament_menu);
  2003. #endif //MMU_HAS_CUTTER
  2004. break;
  2005. case FilamentAction::None:
  2006. case FilamentAction::Preheat:
  2007. case FilamentAction::Lay1Cal:
  2008. // handled earlier
  2009. break;
  2010. }
  2011. if (bFilamentWaitingFlag) Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  2012. bFilamentWaitingFlag = false;
  2013. }
  2014. else
  2015. {
  2016. if (!bFilamentWaitingFlag || lcd_draw_update)
  2017. {
  2018. // First entry from another menu OR first run after the filament preheat selection. Use
  2019. // bFilamentWaitingFlag to distinguish: this flag is reset exactly once when entering
  2020. // the menu and is used to raise the carriage *once*. In other cases, the LCD has been
  2021. // modified elsewhere and needs to be redrawn in full.
  2022. // reset bFilamentWaitingFlag immediately to avoid re-entry from raise_z_above()!
  2023. bool once = !bFilamentWaitingFlag;
  2024. bFilamentWaitingFlag = true;
  2025. // also force-enable lcd_draw_update (might be 0 when called from outside a menu)
  2026. lcd_draw_update = 1;
  2027. lcd_clear();
  2028. lcd_puts_at_P(0, 3, _T(MSG_CANCEL)); ////MSG_CANCEL
  2029. lcd_set_cursor(0, 1);
  2030. switch (eFilamentAction)
  2031. {
  2032. case FilamentAction::Load:
  2033. case FilamentAction::AutoLoad:
  2034. case FilamentAction::MmuLoad:
  2035. lcd_puts_P(_i("Preheating to load")); ////MSG_PREHEATING_TO_LOAD c=20
  2036. if (once) raise_z_above(MIN_Z_FOR_LOAD);
  2037. break;
  2038. case FilamentAction::UnLoad:
  2039. case FilamentAction::MmuUnLoad:
  2040. lcd_puts_P(_i("Preheating to unload")); ////MSG_PREHEATING_TO_UNLOAD c=20
  2041. if (once) raise_z_above(MIN_Z_FOR_UNLOAD);
  2042. break;
  2043. case FilamentAction::MmuEject:
  2044. lcd_puts_P(_i("Preheating to eject")); ////MSG_PREHEATING_TO_EJECT c=20
  2045. break;
  2046. case FilamentAction::MmuCut:
  2047. lcd_puts_P(_i("Preheating to cut")); ////MSG_PREHEATING_TO_CUT c=20
  2048. break;
  2049. case FilamentAction::None:
  2050. case FilamentAction::Preheat:
  2051. case FilamentAction::Lay1Cal:
  2052. // handled earlier
  2053. break;
  2054. }
  2055. }
  2056. if (bFilamentWaitingFlag) {
  2057. lcd_set_cursor(0, 0);
  2058. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int) degHotend(0), (int) degTargetHotend(0));
  2059. }
  2060. if (lcd_clicked())
  2061. {
  2062. bFilamentWaitingFlag = false;
  2063. if (!bFilamentPreheatState)
  2064. {
  2065. setTargetHotend0(0.0);
  2066. setTargetBed(0.0);
  2067. menu_back();
  2068. }
  2069. else
  2070. {
  2071. setTargetHotend0((float )nTargetOld);
  2072. setTargetBed((float) nTargetBedOld);
  2073. }
  2074. menu_back();
  2075. if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2076. }
  2077. }
  2078. }
  2079. static void mFilamentItem_farm()
  2080. {
  2081. bFilamentPreheatState = false;
  2082. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, FARM_PREHEAT_HPB_TEMP);
  2083. }
  2084. static void mFilamentItem_farm_nozzle()
  2085. {
  2086. bFilamentPreheatState = false;
  2087. mFilamentItem(FARM_PREHEAT_HOTEND_TEMP, 0);
  2088. }
  2089. static void mFilamentItem_PLA()
  2090. {
  2091. bFilamentPreheatState = false;
  2092. mFilamentItem(PLA_PREHEAT_HOTEND_TEMP, PLA_PREHEAT_HPB_TEMP);
  2093. }
  2094. static void mFilamentItem_PET()
  2095. {
  2096. bFilamentPreheatState = false;
  2097. mFilamentItem(PET_PREHEAT_HOTEND_TEMP, PET_PREHEAT_HPB_TEMP);
  2098. }
  2099. static void mFilamentItem_ASA()
  2100. {
  2101. bFilamentPreheatState = false;
  2102. mFilamentItem(ASA_PREHEAT_HOTEND_TEMP, ASA_PREHEAT_HPB_TEMP);
  2103. }
  2104. static void mFilamentItem_PC()
  2105. {
  2106. bFilamentPreheatState = false;
  2107. mFilamentItem(PC_PREHEAT_HOTEND_TEMP, PC_PREHEAT_HPB_TEMP);
  2108. }
  2109. static void mFilamentItem_ABS()
  2110. {
  2111. bFilamentPreheatState = false;
  2112. mFilamentItem(ABS_PREHEAT_HOTEND_TEMP, ABS_PREHEAT_HPB_TEMP);
  2113. }
  2114. static void mFilamentItem_HIPS()
  2115. {
  2116. bFilamentPreheatState = false;
  2117. mFilamentItem(HIPS_PREHEAT_HOTEND_TEMP, HIPS_PREHEAT_HPB_TEMP);
  2118. }
  2119. static void mFilamentItem_PP()
  2120. {
  2121. bFilamentPreheatState = false;
  2122. mFilamentItem(PP_PREHEAT_HOTEND_TEMP, PP_PREHEAT_HPB_TEMP);
  2123. }
  2124. static void mFilamentItem_FLEX()
  2125. {
  2126. bFilamentPreheatState = false;
  2127. mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP, FLEX_PREHEAT_HPB_TEMP);
  2128. }
  2129. static void mFilamentItem_PVB()
  2130. {
  2131. bFilamentPreheatState = false;
  2132. mFilamentItem(PVB_PREHEAT_HOTEND_TEMP, PVB_PREHEAT_HPB_TEMP);
  2133. }
  2134. void mFilamentBack()
  2135. {
  2136. if (eFilamentAction == FilamentAction::AutoLoad ||
  2137. eFilamentAction == FilamentAction::Preheat ||
  2138. eFilamentAction == FilamentAction::Lay1Cal)
  2139. {
  2140. eFilamentAction = FilamentAction::None; // i.e. non-autoLoad
  2141. }
  2142. }
  2143. void lcd_generic_preheat_menu()
  2144. {
  2145. MENU_BEGIN();
  2146. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE))
  2147. {
  2148. ON_MENU_LEAVE(
  2149. mFilamentBack();
  2150. );
  2151. MENU_ITEM_BACK_P(_T(eFilamentAction == FilamentAction::Lay1Cal ? MSG_BACK : MSG_MAIN));
  2152. }
  2153. if (farm_mode)
  2154. {
  2155. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), mFilamentItem_farm);
  2156. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), mFilamentItem_farm_nozzle);
  2157. }
  2158. else
  2159. {
  2160. MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA);
  2161. MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET);
  2162. MENU_ITEM_SUBMENU_P(PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)),mFilamentItem_ASA);
  2163. MENU_ITEM_SUBMENU_P(PSTR("PC - " STRINGIFY(PC_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PC_PREHEAT_HPB_TEMP)),mFilamentItem_PC);
  2164. MENU_ITEM_SUBMENU_P(PSTR("PVB - " STRINGIFY(PVB_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PVB_PREHEAT_HPB_TEMP)),mFilamentItem_PVB);
  2165. MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS);
  2166. MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS);
  2167. MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP);
  2168. MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX);
  2169. }
  2170. if (!eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) && eFilamentAction == FilamentAction::Preheat) MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  2171. MENU_END();
  2172. }
  2173. void mFilamentItemForce()
  2174. {
  2175. mFilamentItem(target_temperature[0],target_temperature_bed);
  2176. }
  2177. void lcd_unLoadFilament()
  2178. {
  2179. eFilamentAction=FilamentAction::UnLoad;
  2180. preheat_or_continue();
  2181. }
  2182. static void mmu_unload_filament()
  2183. {
  2184. eFilamentAction = FilamentAction::MmuUnLoad;
  2185. preheat_or_continue();
  2186. }
  2187. void lcd_wait_interact() {
  2188. lcd_clear();
  2189. lcd_set_cursor(0, 1);
  2190. #ifdef SNMM
  2191. lcd_puts_P(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20
  2192. #else
  2193. lcd_puts_P(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20
  2194. #endif
  2195. if (!fsensor_autoload_enabled) {
  2196. lcd_puts_at_P(0, 2, _i("and press the knob"));////MSG_PRESS c=20 r=2
  2197. }
  2198. }
  2199. void lcd_change_success() {
  2200. lcd_clear();
  2201. lcd_puts_at_P(0, 2, _i("Change success!"));////MSG_CHANGE_SUCCESS c=20
  2202. }
  2203. static void lcd_loading_progress_bar(uint16_t loading_time_ms) {
  2204. for (uint_least8_t i = 0; i < LCD_WIDTH; i++) {
  2205. lcd_putc_at(i, 3, '.');
  2206. //loading_time_ms/20 delay
  2207. for (uint_least8_t j = 0; j < 5; j++) {
  2208. delay_keep_alive(loading_time_ms / 100);
  2209. }
  2210. }
  2211. }
  2212. void lcd_loading_color() {
  2213. //we are extruding 25mm with feedrate 200mm/min -> 7.5 seconds for whole action, 0.375 s for one character
  2214. lcd_clear();
  2215. lcd_puts_at_P(0, 0, _i("Loading color"));////MSG_LOADING_COLOR c=20
  2216. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2217. lcd_loading_progress_bar((FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL); //show progress bar during filament loading slow sequence
  2218. }
  2219. void lcd_loading_filament() {
  2220. lcd_clear();
  2221. lcd_puts_at_P(0, 0, _T(MSG_LOADING_FILAMENT));
  2222. lcd_puts_at_P(0, 2, _T(MSG_PLEASE_WAIT));
  2223. #ifdef SNMM
  2224. for (int i = 0; i < 20; i++) {
  2225. lcd_set_cursor(i, 3);
  2226. lcd_print('.');
  2227. for (int j = 0; j < 10 ; j++) {
  2228. manage_heater();
  2229. manage_inactivity(true);
  2230. _delay(153);
  2231. }
  2232. }
  2233. #else //SNMM
  2234. uint16_t slow_seq_time = (FILAMENTCHANGE_FINALFEED * 1000ul) / FILAMENTCHANGE_EFEED_FINAL;
  2235. uint16_t fast_seq_time = (FILAMENTCHANGE_FIRSTFEED * 1000ul) / FILAMENTCHANGE_EFEED_FIRST;
  2236. lcd_loading_progress_bar(slow_seq_time + fast_seq_time); //show progress bar for total time of filament loading fast + slow sequence
  2237. #endif //SNMM
  2238. }
  2239. void lcd_alright() {
  2240. int enc_dif = 0;
  2241. int cursor_pos = 1;
  2242. lcd_clear();
  2243. lcd_puts_at_P(0, 0, _i("Changed correctly?"));////MSG_CORRECTLY c=20
  2244. lcd_puts_at_P(1, 1, _T(MSG_YES));
  2245. lcd_puts_at_P(1, 2, _i("Filament not loaded"));////MSG_NOT_LOADED c=19
  2246. lcd_puts_at_P(1, 3, _i("Color not correct"));////MSG_NOT_COLOR c=19
  2247. lcd_putc_at(0, 1, '>');
  2248. enc_dif = lcd_encoder_diff;
  2249. lcd_consume_click();
  2250. while (lcd_change_fil_state == 0) {
  2251. manage_heater();
  2252. manage_inactivity(true);
  2253. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2254. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2255. if (enc_dif > lcd_encoder_diff ) {
  2256. cursor_pos --;
  2257. }
  2258. if (enc_dif < lcd_encoder_diff ) {
  2259. cursor_pos ++;
  2260. }
  2261. if (cursor_pos > 3) {
  2262. cursor_pos = 3;
  2263. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2264. }
  2265. if (cursor_pos < 1) {
  2266. cursor_pos = 1;
  2267. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  2268. }
  2269. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  2270. lcd_putc_at(0, cursor_pos, '>');
  2271. enc_dif = lcd_encoder_diff;
  2272. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  2273. _delay(100);
  2274. }
  2275. }
  2276. if (lcd_clicked()) {
  2277. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  2278. lcd_change_fil_state = cursor_pos;
  2279. _delay(500);
  2280. }
  2281. };
  2282. lcd_clear();
  2283. lcd_return_to_status();
  2284. }
  2285. void show_preheat_nozzle_warning()
  2286. {
  2287. lcd_clear();
  2288. lcd_puts_at_P(0, 0, _T(MSG_ERROR));
  2289. lcd_puts_at_P(0, 2, _T(MSG_PREHEAT_NOZZLE));
  2290. _delay(2000);
  2291. lcd_clear();
  2292. }
  2293. void lcd_load_filament_color_check()
  2294. {
  2295. bool clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2296. while (!clean) {
  2297. lcd_update_enable(true);
  2298. lcd_update(2);
  2299. load_filament_final_feed();
  2300. st_synchronize();
  2301. clean = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_FILAMENT_CLEAN), false, true);
  2302. }
  2303. }
  2304. #ifdef FILAMENT_SENSOR
  2305. static void lcd_menu_AutoLoadFilament()
  2306. {
  2307. uint8_t nlines;
  2308. 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
  2309. menu_back_if_clicked();
  2310. }
  2311. #endif //FILAMENT_SENSOR
  2312. static void preheat_or_continue()
  2313. {
  2314. bFilamentFirstRun = false;
  2315. if (target_temperature[0] >= EXTRUDE_MINTEMP)
  2316. {
  2317. bFilamentPreheatState = true;
  2318. mFilamentItem(target_temperature[0], target_temperature_bed);
  2319. }
  2320. else lcd_generic_preheat_menu();
  2321. }
  2322. static void lcd_LoadFilament()
  2323. {
  2324. eFilamentAction = FilamentAction::Load;
  2325. preheat_or_continue();
  2326. }
  2327. //! @brief Show filament used a print time
  2328. //!
  2329. //! If printing current print statistics are shown
  2330. //!
  2331. //! @code{.unparsed}
  2332. //! |01234567890123456789|
  2333. //! |Filament used: | MSG_FILAMENT_USED c=19
  2334. //! | 0000.00m |
  2335. //! |Print time: | MSG_PRINT_TIME c=19
  2336. //! | 00h 00m 00s |
  2337. //! ----------------------
  2338. //! @endcode
  2339. //!
  2340. //! If not printing, total statistics are shown
  2341. //!
  2342. //! @code{.unparsed}
  2343. //! |01234567890123456789|
  2344. //! |Total filament: | MSG_TOTAL_FILAMENT c=19
  2345. //! | 0000.00m |
  2346. //! |Total print time: | MSG_TOTAL_PRINT_TIME c=19
  2347. //! | 00d 00h 00m |
  2348. //! ----------------------
  2349. //! @endcode
  2350. //! @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".
  2351. void lcd_menu_statistics()
  2352. {
  2353. lcd_timeoutToStatus.stop(); //infinite timeout
  2354. if (IS_SD_PRINTING)
  2355. {
  2356. const float _met = ((float)total_filament_used) / (100000.f);
  2357. const uint32_t _t = (_millis() - starttime) / 1000ul;
  2358. const uint32_t _h = _t / 3600;
  2359. const uint8_t _m = (_t - (_h * 3600ul)) / 60ul;
  2360. const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul));
  2361. lcd_home();
  2362. lcd_printf_P(_N(
  2363. "%S:\n"
  2364. "%18.2fm \n"
  2365. "%S:\n"
  2366. "%10ldh %02dm %02ds"
  2367. ),
  2368. _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19
  2369. _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19
  2370. menu_back_if_clicked_fb();
  2371. }
  2372. else
  2373. {
  2374. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2375. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2376. uint8_t _hours, _minutes;
  2377. uint32_t _days;
  2378. float _filament_m = (float)_filament/100;
  2379. _days = _time / 1440;
  2380. _hours = (_time - (_days * 1440)) / 60;
  2381. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2382. lcd_home();
  2383. lcd_printf_P(_N(
  2384. "%S:\n"
  2385. "%18.2fm \n"
  2386. "%S:\n"
  2387. "%10ldd %02dh %02dm"
  2388. ),
  2389. _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19
  2390. _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19
  2391. menu_back_if_clicked_fb();
  2392. }
  2393. }
  2394. static void _lcd_move(const char *name, uint8_t axis, int min, int max)
  2395. {
  2396. if (homing_flag || mesh_bed_leveling_flag)
  2397. {
  2398. // printer entered a new state where axis move is forbidden
  2399. menu_back();
  2400. return;
  2401. }
  2402. typedef struct
  2403. { // 2bytes total
  2404. bool initialized; // 1byte
  2405. bool endstopsEnabledPrevious; // 1byte
  2406. } _menu_data_t;
  2407. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2408. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2409. if (!_md->initialized)
  2410. {
  2411. _md->endstopsEnabledPrevious = enable_endstops(false);
  2412. _md->initialized = true;
  2413. }
  2414. if (lcd_encoder != 0)
  2415. {
  2416. refresh_cmd_timeout();
  2417. if (! planner_queue_full())
  2418. {
  2419. current_position[axis] += float((int)lcd_encoder);
  2420. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2421. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2422. lcd_encoder = 0;
  2423. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2424. plan_buffer_line_curposXYZE(manual_feedrate[axis] / 60);
  2425. lcd_draw_update = 1;
  2426. }
  2427. }
  2428. if (lcd_draw_update)
  2429. {
  2430. lcd_set_cursor(0, 1);
  2431. menu_draw_float31(name, current_position[axis]);
  2432. }
  2433. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2434. if (LCD_CLICKED) menu_back();
  2435. }
  2436. void lcd_move_e()
  2437. {
  2438. if (degHotend0() > EXTRUDE_MINTEMP)
  2439. {
  2440. if (lcd_encoder != 0)
  2441. {
  2442. refresh_cmd_timeout();
  2443. if (! planner_queue_full())
  2444. {
  2445. current_position[E_AXIS] += float((int)lcd_encoder);
  2446. lcd_encoder = 0;
  2447. plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
  2448. lcd_draw_update = 1;
  2449. }
  2450. }
  2451. if (lcd_draw_update)
  2452. {
  2453. lcd_set_cursor(0, 1);
  2454. // Note: the colon behind the text is necessary to greatly shorten
  2455. // the implementation of menu_draw_float31
  2456. menu_draw_float31(PSTR("Extruder:"), current_position[E_AXIS]);
  2457. }
  2458. if (LCD_CLICKED) menu_back();
  2459. }
  2460. else
  2461. {
  2462. show_preheat_nozzle_warning();
  2463. lcd_return_to_status();
  2464. }
  2465. }
  2466. //! @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2467. //! If those points are detected too close to edge of reachable area, their confidence is lowered.
  2468. //! This functionality is applied more often for MK2 printers.
  2469. //! @code{.unparsed}
  2470. //! |01234567890123456789|
  2471. //! |Y distance from min | MSG_Y_DIST_FROM_MIN
  2472. //! | -------------- | STR_SEPARATOR
  2473. //! |Left: 00.00mm| MSG_LEFT c=10, c=8
  2474. //! |Right: 00.00mm| MSG_RIGHT c=10, c=8
  2475. //! ----------------------
  2476. //! @endcode
  2477. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2478. static void lcd_menu_xyz_y_min()
  2479. {
  2480. float distanceMin[2];
  2481. count_xyz_details(distanceMin);
  2482. lcd_home();
  2483. lcd_printf_P(_N(
  2484. "%S\n"
  2485. "%S\n"
  2486. "%S:\n"
  2487. "%S:"
  2488. ),
  2489. _i("Y distance from min"), ////MSG_Y_DIST_FROM_MIN c=20
  2490. separator,
  2491. _i("Left"), ////MSG_LEFT c=10
  2492. _i("Right") ////MSG_RIGHT c=10
  2493. );
  2494. for (uint8_t i = 0; i < 2; i++)
  2495. {
  2496. lcd_set_cursor(11,2+i);
  2497. if (distanceMin[i] >= 200) lcd_puts_P(_T(MSG_NA));
  2498. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2499. }
  2500. if (lcd_clicked())
  2501. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2502. }
  2503. //@brief Show measured axis skewness
  2504. float _deg(float rad)
  2505. {
  2506. return rad * 180 / M_PI;
  2507. }
  2508. //! @brief Show Measured XYZ Skew
  2509. //!
  2510. //! @code{.unparsed}
  2511. //! |01234567890123456789|
  2512. //! |Measured skew :0.00D| MSG_MEASURED_SKEW c=14, c=4
  2513. //! | -------------- | STR_SEPARATOR
  2514. //! |Slight skew :0.12D| MSG_SLIGHT_SKEW c=14, c=4
  2515. //! |Severe skew :0.25D| MSG_SEVERE_SKEW c=14, c=4
  2516. //! ----------------------
  2517. //! D - Degree sysmbol LCD_STR_DEGREE
  2518. //! @endcode
  2519. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2520. static void lcd_menu_xyz_skew()
  2521. {
  2522. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2523. lcd_home();
  2524. lcd_printf_P(_N(
  2525. "%-14.14S:\n"
  2526. "%S\n"
  2527. "%-14.14S:%3.2f\x01\n"
  2528. "%-14.14S:%3.2f\x01"
  2529. ),
  2530. _i("Measured skew"), ////MSG_MEASURED_SKEW c=14
  2531. separator,
  2532. _i("Slight skew"), _deg(bed_skew_angle_mild), ////MSG_SLIGHT_SKEW c=14, c=4
  2533. _i("Severe skew"), _deg(bed_skew_angle_extreme) ////MSG_SEVERE_SKEW c=14, c=4
  2534. );
  2535. if (angleDiff < 100){
  2536. lcd_set_cursor(15,0);
  2537. lcd_printf_P(_N("%3.2f\x01"), _deg(angleDiff));
  2538. }
  2539. else{
  2540. lcd_puts_at_P(15,0, _T(MSG_NA));
  2541. }
  2542. if (lcd_clicked())
  2543. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2544. }
  2545. //! @brief Show measured bed offset from expected position
  2546. //!
  2547. //! @code{.unparsed}
  2548. //! |01234567890123456789|
  2549. //! |[0;0] point offset | MSG_MEASURED_OFFSET c=20
  2550. //! | -------------- | STR_SEPARATOR
  2551. //! |X 00.00mm| c=10
  2552. //! |Y 00.00mm| c=10
  2553. //! ----------------------
  2554. //! @endcode
  2555. //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations.
  2556. static void lcd_menu_xyz_offset()
  2557. {
  2558. lcd_puts_at_P(0, 0, _i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=20
  2559. lcd_puts_at_P(0, 1, separator);
  2560. lcd_puts_at_P(0, 2, PSTR("X"));
  2561. lcd_puts_at_P(0, 3, PSTR("Y"));
  2562. float vec_x[2];
  2563. float vec_y[2];
  2564. float cntr[2];
  2565. world2machine_read_valid(vec_x, vec_y, cntr);
  2566. for (uint_least8_t i = 0; i < 2; i++)
  2567. {
  2568. lcd_set_cursor((cntr[i] < 0) ? 13 : 14, i+2);
  2569. lcd_print(cntr[i]);
  2570. lcd_puts_at_P(18, i + 2, PSTR("mm"));
  2571. }
  2572. menu_back_if_clicked();
  2573. }
  2574. // Note: the colon behind the text (X, Y, Z) is necessary to greatly shorten
  2575. // the implementation of menu_draw_float31
  2576. static void lcd_move_x() {
  2577. _lcd_move(PSTR("X:"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2578. }
  2579. static void lcd_move_y() {
  2580. _lcd_move(PSTR("Y:"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2581. }
  2582. static void lcd_move_z() {
  2583. _lcd_move(PSTR("Z:"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2584. }
  2585. /**
  2586. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2587. *
  2588. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2589. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2590. * Purpose of this function for other axis then Z is unknown.
  2591. *
  2592. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2593. * other value leads to storing Z_AXIS
  2594. * @param msg text to be displayed
  2595. */
  2596. static void lcd_babystep_z()
  2597. {
  2598. if (homing_flag || mesh_bed_leveling_flag)
  2599. {
  2600. // printer changed to a new state where live Z is forbidden
  2601. menu_back();
  2602. return;
  2603. }
  2604. typedef struct
  2605. {
  2606. int8_t status;
  2607. int16_t babystepMemZ;
  2608. float babystepMemMMZ;
  2609. } _menu_data_t;
  2610. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2611. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2612. if (_md->status == 0)
  2613. {
  2614. // Menu was entered.
  2615. // Initialize its status.
  2616. _md->status = 1;
  2617. check_babystep();
  2618. if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){
  2619. _md->babystepMemZ = 0;
  2620. }
  2621. else{
  2622. _md->babystepMemZ = eeprom_read_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->
  2623. s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)));
  2624. }
  2625. // same logic as in babystep_load
  2626. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2627. _md->babystepMemZ = 0;
  2628. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2629. lcd_draw_update = 1;
  2630. //SERIAL_ECHO("Z baby step: ");
  2631. //SERIAL_ECHO(_md->babystepMem[2]);
  2632. // Wait 90 seconds before closing the live adjust dialog.
  2633. lcd_timeoutToStatus.start();
  2634. }
  2635. if (lcd_encoder != 0)
  2636. {
  2637. _md->babystepMemZ += (int)lcd_encoder;
  2638. if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2639. else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0
  2640. else babystepsTodoZadd(lcd_encoder);
  2641. _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS];
  2642. _delay(50);
  2643. lcd_encoder = 0;
  2644. lcd_draw_update = 1;
  2645. }
  2646. if (lcd_draw_update)
  2647. {
  2648. SheetFormatBuffer buffer;
  2649. menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer);
  2650. lcd_set_cursor(0, 0);
  2651. lcd_print(buffer.c);
  2652. lcd_set_cursor(0, 1);
  2653. menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 Beware: must include the ':' as its last character
  2654. }
  2655. if (LCD_CLICKED || menu_leaving)
  2656. {
  2657. // Only update the EEPROM when leaving the menu.
  2658. uint8_t active_sheet=eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  2659. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[active_sheet].z_offset)),_md->babystepMemZ);
  2660. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].bed_temp),target_temperature_bed);
  2661. #ifdef PINDA_THERMISTOR
  2662. eeprom_update_byte(&(EEPROM_Sheets_base->s[active_sheet].pinda_temp),current_temperature_pinda);
  2663. #endif //PINDA_THERMISTOR
  2664. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2665. }
  2666. if (LCD_CLICKED) menu_back();
  2667. }
  2668. typedef struct
  2669. { // 12bytes + 9bytes = 21bytes total
  2670. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2671. int8_t status; // 1byte
  2672. int16_t left; // 2byte
  2673. int16_t right; // 2byte
  2674. int16_t front; // 2byte
  2675. int16_t rear; // 2byte
  2676. } _menu_data_adjust_bed_t;
  2677. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2678. void lcd_adjust_bed_reset(void)
  2679. {
  2680. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2681. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2682. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2683. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2684. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2685. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2686. _md->status = 0;
  2687. }
  2688. //! @brief Show Bed level correct
  2689. //!
  2690. //! @code{.unparsed}
  2691. //! |01234567890123456789|
  2692. //! |Settings: | MSG_SETTINGS
  2693. //! |Left side [um]: | MSG_BED_CORRECTION_LEFT
  2694. //! |Right side[um]: | MSG_BED_CORRECTION_RIGHT
  2695. //! |Front side[um]: | MSG_BED_CORRECTION_FRONT
  2696. //! |Rear side [um]: | MSG_BED_CORRECTION_REAR
  2697. //! |Reset | MSG_BED_CORRECTION_RESET
  2698. //! ----------------------
  2699. //! @endcode
  2700. void lcd_adjust_bed(void)
  2701. {
  2702. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2703. if (_md->status == 0)
  2704. {
  2705. // Menu was entered.
  2706. _md->left = 0;
  2707. _md->right = 0;
  2708. _md->front = 0;
  2709. _md->rear = 0;
  2710. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2711. {
  2712. _md->left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2713. _md->right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2714. _md->front = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2715. _md->rear = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2716. }
  2717. _md->status = 1;
  2718. }
  2719. MENU_BEGIN();
  2720. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2721. ON_MENU_LEAVE(
  2722. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left);
  2723. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right);
  2724. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front);
  2725. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear);
  2726. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2727. );
  2728. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2729. 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
  2730. 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
  2731. 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
  2732. 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
  2733. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_adjust_bed_reset);////MSG_RESET c=14
  2734. MENU_END();
  2735. }
  2736. //! @brief Show PID Extruder
  2737. //!
  2738. //! @code{.unparsed}
  2739. //! |01234567890123456789|
  2740. //! |Set temperature: | MSG_SET_TEMPERATURE c=20
  2741. //! | |
  2742. //! | 210 |
  2743. //! | |
  2744. //! ----------------------
  2745. //! @endcode
  2746. void pid_extruder()
  2747. {
  2748. lcd_clear();
  2749. lcd_puts_at_P(0, 0, _i("Set temperature:"));////MSG_SET_TEMPERATURE
  2750. pid_temp += int(lcd_encoder);
  2751. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2752. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2753. lcd_encoder = 0;
  2754. lcd_set_cursor(1, 2);
  2755. lcd_print(ftostr3(pid_temp));
  2756. if (lcd_clicked()) {
  2757. lcd_commands_type = LcdCommands::PidExtruder;
  2758. lcd_return_to_status();
  2759. lcd_update(2);
  2760. }
  2761. }
  2762. /*
  2763. void lcd_adjust_z() {
  2764. int enc_dif = 0;
  2765. int cursor_pos = 1;
  2766. int fsm = 0;
  2767. lcd_clear();
  2768. lcd_set_cursor(0, 0);
  2769. lcd_puts_P(_i("Auto adjust Z?"));////MSG_ADJUSTZ
  2770. lcd_set_cursor(1, 1);
  2771. lcd_puts_P(_T(MSG_YES));
  2772. lcd_set_cursor(1, 2);
  2773. lcd_puts_P(_T(MSG_NO));
  2774. lcd_set_cursor(0, 1);
  2775. lcd_print('>');
  2776. enc_dif = lcd_encoder_diff;
  2777. while (fsm == 0) {
  2778. manage_heater();
  2779. manage_inactivity(true);
  2780. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2781. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2782. if (enc_dif > lcd_encoder_diff ) {
  2783. cursor_pos --;
  2784. }
  2785. if (enc_dif < lcd_encoder_diff ) {
  2786. cursor_pos ++;
  2787. }
  2788. if (cursor_pos > 2) {
  2789. cursor_pos = 2;
  2790. }
  2791. if (cursor_pos < 1) {
  2792. cursor_pos = 1;
  2793. }
  2794. lcd_set_cursor(0, 1);
  2795. lcd_print(' ');
  2796. lcd_set_cursor(0, 2);
  2797. lcd_print(' ');
  2798. lcd_set_cursor(0, cursor_pos);
  2799. lcd_print('>');
  2800. enc_dif = lcd_encoder_diff;
  2801. _delay(100);
  2802. }
  2803. }
  2804. if (lcd_clicked()) {
  2805. fsm = cursor_pos;
  2806. if (fsm == 1) {
  2807. int babystepLoadZ = 0;
  2808. babystepLoadZ = eeprom_read_word((uint16_t*)EEPROM_BABYSTEP_Z);
  2809. CRITICAL_SECTION_START
  2810. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2811. CRITICAL_SECTION_END
  2812. } else {
  2813. int zero = 0;
  2814. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_X, zero);
  2815. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Y, zero);
  2816. eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Z, zero);
  2817. }
  2818. _delay(500);
  2819. }
  2820. };
  2821. lcd_clear();
  2822. lcd_return_to_status();
  2823. }*/
  2824. #ifdef PINDA_THERMISTOR
  2825. bool lcd_wait_for_pinda(float temp) {
  2826. setAllTargetHotends(0);
  2827. setTargetBed(0);
  2828. LongTimer pinda_timeout;
  2829. pinda_timeout.start();
  2830. bool target_temp_reached = true;
  2831. while (current_temperature_pinda > temp){
  2832. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2833. lcd_set_cursor(0, 4);
  2834. lcd_print(LCD_STR_THERMOMETER[0]);
  2835. lcd_print(ftostr3(current_temperature_pinda));
  2836. lcd_print('/');
  2837. lcd_print(ftostr3(temp));
  2838. lcd_print(LCD_STR_DEGREE[0]);
  2839. delay_keep_alive(1000);
  2840. serialecho_temperatures();
  2841. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2842. target_temp_reached = false;
  2843. break;
  2844. }
  2845. }
  2846. lcd_update_enable(true);
  2847. return target_temp_reached;
  2848. }
  2849. #endif //PINDA_THERMISTOR
  2850. void lcd_wait_for_heater() {
  2851. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2852. lcd_set_cursor(0, 4);
  2853. lcd_print(LCD_STR_THERMOMETER[0]);
  2854. lcd_print(ftostr3(degHotend(active_extruder)));
  2855. lcd_print('/');
  2856. lcd_print(ftostr3(degTargetHotend(active_extruder)));
  2857. lcd_print(LCD_STR_DEGREE[0]);
  2858. }
  2859. void lcd_wait_for_cool_down() {
  2860. setAllTargetHotends(0);
  2861. setTargetBed(0);
  2862. int fanSpeedBckp = fanSpeed;
  2863. fanSpeed = 255;
  2864. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2865. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=4
  2866. lcd_set_cursor(0, 4);
  2867. lcd_print(LCD_STR_THERMOMETER[0]);
  2868. lcd_print(ftostr3(degHotend(0)));
  2869. lcd_print("/0");
  2870. lcd_print(LCD_STR_DEGREE[0]);
  2871. lcd_set_cursor(9, 4);
  2872. lcd_print(LCD_STR_BEDTEMP[0]);
  2873. lcd_print(ftostr3(degBed()));
  2874. lcd_print("/0");
  2875. lcd_print(LCD_STR_DEGREE[0]);
  2876. delay_keep_alive(1000);
  2877. serialecho_temperatures();
  2878. }
  2879. fanSpeed = fanSpeedBckp;
  2880. lcd_update_enable(true);
  2881. }
  2882. // Lets the user move the Z carriage up to the end stoppers.
  2883. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2884. // Otherwise the Z calibration is not changed and false is returned.
  2885. #ifndef TMC2130
  2886. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2887. {
  2888. // 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.
  2889. current_position[Z_AXIS] = 0;
  2890. plan_set_position_curposXYZE();
  2891. // Until confirmed by the confirmation dialog.
  2892. for (;;) {
  2893. 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
  2894. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2895. const bool multi_screen = msg_next != NULL;
  2896. unsigned long previous_millis_msg = _millis();
  2897. // Until the user finishes the z up movement.
  2898. lcd_encoder_diff = 0;
  2899. lcd_encoder = 0;
  2900. for (;;) {
  2901. manage_heater();
  2902. manage_inactivity(true);
  2903. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2904. _delay(50);
  2905. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2906. lcd_encoder_diff = 0;
  2907. if (! planner_queue_full()) {
  2908. // Only move up, whatever direction the user rotates the encoder.
  2909. current_position[Z_AXIS] += fabs(lcd_encoder);
  2910. lcd_encoder = 0;
  2911. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  2912. }
  2913. }
  2914. if (lcd_clicked()) {
  2915. // Abort a move if in progress.
  2916. planner_abort_hard();
  2917. while (lcd_clicked()) ;
  2918. _delay(10);
  2919. while (lcd_clicked()) ;
  2920. break;
  2921. }
  2922. if (multi_screen && _millis() - previous_millis_msg > 5000) {
  2923. if (msg_next == NULL)
  2924. msg_next = msg;
  2925. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2926. previous_millis_msg = _millis();
  2927. }
  2928. }
  2929. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2930. 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
  2931. if (result == -1)
  2932. goto canceled;
  2933. else if (result == 1)
  2934. goto calibrated;
  2935. // otherwise perform another round of the Z up dialog.
  2936. }
  2937. calibrated:
  2938. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2939. // during the search for the induction points.
  2940. if ((PRINTER_TYPE == PRINTER_MK25) || (PRINTER_TYPE == PRINTER_MK2) || (PRINTER_TYPE == PRINTER_MK2_SNMM)) {
  2941. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2942. }
  2943. else {
  2944. current_position[Z_AXIS] = Z_MAX_POS+4.f;
  2945. }
  2946. plan_set_position_curposXYZE();
  2947. return true;
  2948. canceled:
  2949. return false;
  2950. }
  2951. #endif // TMC2130
  2952. static inline bool pgm_is_whitespace(const char *c_addr)
  2953. {
  2954. const char c = pgm_read_byte(c_addr);
  2955. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2956. }
  2957. static inline bool pgm_is_interpunction(const char *c_addr)
  2958. {
  2959. const char c = pgm_read_byte(c_addr);
  2960. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2961. }
  2962. /**
  2963. * @brief show full screen message
  2964. *
  2965. * This function is non-blocking
  2966. * @param msg message to be displayed from PROGMEM
  2967. * @param nlines
  2968. * @return rest of the text (to be displayed on next page)
  2969. */
  2970. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2971. {
  2972. lcd_set_cursor(0, 0);
  2973. const char *msgend = msg;
  2974. uint8_t row = 0;
  2975. bool multi_screen = false;
  2976. for (; row < 4; ++ row) {
  2977. while (pgm_is_whitespace(msg))
  2978. ++ msg;
  2979. if (pgm_read_byte(msg) == 0)
  2980. // End of the message.
  2981. break;
  2982. lcd_set_cursor(0, row);
  2983. uint8_t linelen = min(strlen_P(msg), LCD_WIDTH);
  2984. const char *msgend2 = msg + linelen;
  2985. msgend = msgend2;
  2986. if (row == 3 && linelen == LCD_WIDTH) {
  2987. // Last line of the display, full line shall be displayed.
  2988. // Find out, whether this message will be split into multiple screens.
  2989. while (pgm_is_whitespace(msgend))
  2990. ++ msgend;
  2991. multi_screen = pgm_read_byte(msgend) != 0;
  2992. if (multi_screen)
  2993. msgend = (msgend2 -= 2);
  2994. }
  2995. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2996. // Splitting a word. Find the start of the current word.
  2997. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2998. -- msgend;
  2999. if (msgend == msg)
  3000. // Found a single long word, which cannot be split. Just cut it.
  3001. msgend = msgend2;
  3002. }
  3003. for (; msg < msgend; ++ msg) {
  3004. char c = char(pgm_read_byte(msg));
  3005. if (c == '~')
  3006. c = ' ';
  3007. lcd_print(c);
  3008. }
  3009. }
  3010. if (multi_screen) {
  3011. // Display the "next screen" indicator character.
  3012. lcd_set_custom_characters_nextpage();
  3013. lcd_set_cursor(19, 3);
  3014. // Display the double down arrow.
  3015. lcd_print(LCD_STR_ARROW_2_DOWN[0]);
  3016. }
  3017. nlines = row;
  3018. return multi_screen ? msgend : NULL;
  3019. }
  3020. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  3021. {
  3022. // Disable update of the screen by the usual lcd_update(0) routine.
  3023. lcd_update_enable(false);
  3024. lcd_clear();
  3025. // uint8_t nlines;
  3026. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  3027. }
  3028. const char* lcd_display_message_fullscreen_P(const char *msg)
  3029. {
  3030. uint8_t nlines;
  3031. return lcd_display_message_fullscreen_P(msg, nlines);
  3032. }
  3033. /**
  3034. * @brief show full screen message and wait
  3035. *
  3036. * This function is blocking.
  3037. * @param msg message to be displayed from PROGMEM
  3038. */
  3039. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  3040. {
  3041. LcdUpdateDisabler lcdUpdateDisabler;
  3042. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3043. bool multi_screen = msg_next != NULL;
  3044. lcd_set_custom_characters_nextpage();
  3045. lcd_consume_click();
  3046. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3047. // Until confirmed by a button click.
  3048. for (;;) {
  3049. if (!multi_screen) {
  3050. lcd_set_cursor(19, 3);
  3051. // Display the confirm char.
  3052. lcd_print(LCD_STR_CONFIRM[0]);
  3053. }
  3054. // Wait for 5 seconds before displaying the next text.
  3055. for (uint8_t i = 0; i < 100; ++ i) {
  3056. delay_keep_alive(50);
  3057. if (lcd_clicked()) {
  3058. if (msg_next == NULL) {
  3059. KEEPALIVE_STATE(IN_HANDLER);
  3060. lcd_set_custom_characters();
  3061. lcd_update_enable(true);
  3062. lcd_update(2);
  3063. return;
  3064. }
  3065. else {
  3066. break;
  3067. }
  3068. }
  3069. }
  3070. if (multi_screen) {
  3071. if (msg_next == NULL)
  3072. msg_next = msg;
  3073. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3074. if (msg_next == NULL) {
  3075. lcd_set_cursor(19, 3);
  3076. // Display the confirm char.
  3077. lcd_print(LCD_STR_CONFIRM[0]);
  3078. }
  3079. }
  3080. }
  3081. }
  3082. bool lcd_wait_for_click_delay(uint16_t nDelay)
  3083. // nDelay :: timeout [s] (0 ~ no timeout)
  3084. // true ~ clicked, false ~ delayed
  3085. {
  3086. bool bDelayed;
  3087. long nTime0 = _millis()/1000;
  3088. lcd_consume_click();
  3089. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3090. for (;;) {
  3091. manage_heater();
  3092. manage_inactivity(true);
  3093. bDelayed = ((_millis()/1000-nTime0) > nDelay);
  3094. bDelayed = (bDelayed && (nDelay != 0)); // 0 ~ no timeout, always waiting for click
  3095. if (lcd_clicked() || bDelayed) {
  3096. KEEPALIVE_STATE(IN_HANDLER);
  3097. return(!bDelayed);
  3098. }
  3099. }
  3100. }
  3101. void lcd_wait_for_click()
  3102. {
  3103. lcd_wait_for_click_delay(0);
  3104. }
  3105. //! @brief Show multiple screen message with yes and no possible choices and wait with possible timeout
  3106. //! @param msg Message to show
  3107. //! @param allow_timeouting if true, allows time outing of the screen
  3108. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3109. //! @retval 1 yes choice selected by user
  3110. //! @retval 0 no choice selected by user
  3111. //! @retval -1 screen timed out
  3112. 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)
  3113. {
  3114. return lcd_show_multiscreen_message_two_choices_and_wait_P(msg, allow_timeouting, default_yes, _T(MSG_YES), _T(MSG_NO));
  3115. }
  3116. //! @brief Show multiple screen message with two possible choices and wait with possible timeout
  3117. //! @param msg Message to show
  3118. //! @param allow_timeouting if true, allows time outing of the screen
  3119. //! @param default_first if true, fist choice is selected by default, otherwise second choice is preselected
  3120. //! @param first_choice text caption of first possible choice
  3121. //! @param second_choice text caption of second possible choice
  3122. //! @retval 1 first choice selected by user
  3123. //! @retval 0 second choice selected by user
  3124. //! @retval -1 screen timed out
  3125. int8_t lcd_show_multiscreen_message_two_choices_and_wait_P(const char *msg, bool allow_timeouting, bool default_first,
  3126. const char *first_choice, const char *second_choice)
  3127. {
  3128. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  3129. bool multi_screen = msg_next != NULL;
  3130. bool yes = default_first ? true : false;
  3131. // Wait for user confirmation or a timeout.
  3132. unsigned long previous_millis_cmd = _millis();
  3133. int8_t enc_dif = lcd_encoder_diff;
  3134. lcd_consume_click();
  3135. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  3136. for (;;) {
  3137. for (uint8_t i = 0; i < 100; ++i) {
  3138. delay_keep_alive(50);
  3139. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3140. return -1;
  3141. manage_heater();
  3142. manage_inactivity(true);
  3143. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3144. if (msg_next == NULL) {
  3145. lcd_set_cursor(0, 3);
  3146. if (enc_dif < lcd_encoder_diff && yes) {
  3147. lcd_print(' ');
  3148. lcd_putc_at(7, 3, '>');
  3149. yes = false;
  3150. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3151. }
  3152. else if (enc_dif > lcd_encoder_diff && !yes) {
  3153. lcd_print('>');
  3154. lcd_putc_at(7, 3, ' ');
  3155. yes = true;
  3156. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3157. }
  3158. enc_dif = lcd_encoder_diff;
  3159. }
  3160. else {
  3161. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  3162. break; //turning knob skips waiting loop
  3163. }
  3164. }
  3165. if (lcd_clicked()) {
  3166. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3167. if (msg_next == NULL) {
  3168. //KEEPALIVE_STATE(IN_HANDLER);
  3169. lcd_set_custom_characters();
  3170. return yes;
  3171. }
  3172. else break;
  3173. }
  3174. }
  3175. if (multi_screen) {
  3176. if (msg_next == NULL) {
  3177. msg_next = msg;
  3178. }
  3179. msg_next = lcd_display_message_fullscreen_P(msg_next);
  3180. }
  3181. if (msg_next == NULL) {
  3182. lcd_set_cursor(0, 3);
  3183. if (yes) lcd_print('>');
  3184. lcd_puts_at_P(1, 3, first_choice);
  3185. lcd_set_cursor(7, 3);
  3186. if (!yes) lcd_print('>');
  3187. lcd_puts_at_P(8, 3, second_choice);
  3188. }
  3189. }
  3190. }
  3191. //! @brief Display and wait for a Yes/No choice using the last two lines of the LCD
  3192. //! @param allow_timeouting if true, allows time outing of the screen
  3193. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3194. //! @retval 1 yes choice selected by user
  3195. //! @retval 0 no choice selected by user
  3196. //! @retval -1 screen timed out
  3197. int8_t lcd_show_yes_no_and_wait(bool allow_timeouting, bool default_yes)
  3198. {
  3199. if (default_yes) {
  3200. lcd_putc_at(0, 2, '>');
  3201. lcd_puts_P(_T(MSG_YES));
  3202. lcd_puts_at_P(1, 3, _T(MSG_NO));
  3203. }
  3204. else {
  3205. lcd_puts_at_P(1, 2, _T(MSG_YES));
  3206. lcd_putc_at(0, 3, '>');
  3207. lcd_puts_P(_T(MSG_NO));
  3208. }
  3209. int8_t retval = default_yes ? true : false;
  3210. // Wait for user confirmation or a timeout.
  3211. unsigned long previous_millis_cmd = _millis();
  3212. int8_t enc_dif = lcd_encoder_diff;
  3213. lcd_consume_click();
  3214. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3215. for (;;) {
  3216. if (allow_timeouting && _millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  3217. {
  3218. retval = -1;
  3219. break;
  3220. }
  3221. manage_heater();
  3222. manage_inactivity(true);
  3223. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  3224. lcd_set_cursor(0, 2);
  3225. if (enc_dif < lcd_encoder_diff && retval) {
  3226. lcd_print(' ');
  3227. lcd_putc_at(0, 3, '>');
  3228. retval = 0;
  3229. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3230. }
  3231. else if (enc_dif > lcd_encoder_diff && !retval) {
  3232. lcd_print('>');
  3233. lcd_putc_at(0, 3, ' ');
  3234. retval = 1;
  3235. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  3236. }
  3237. enc_dif = lcd_encoder_diff;
  3238. }
  3239. if (lcd_clicked()) {
  3240. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  3241. KEEPALIVE_STATE(IN_HANDLER);
  3242. break;
  3243. }
  3244. }
  3245. lcd_encoder_diff = 0;
  3246. return retval;
  3247. }
  3248. //! @brief Show single screen message with yes and no possible choices and wait with possible timeout
  3249. //! @param msg Message to show
  3250. //! @param allow_timeouting if true, allows time outing of the screen
  3251. //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected
  3252. //! @retval 1 yes choice selected by user
  3253. //! @retval 0 no choice selected by user
  3254. //! @retval -1 screen timed out
  3255. //! @relates lcd_show_yes_no_and_wait
  3256. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  3257. {
  3258. lcd_display_message_fullscreen_P(msg);
  3259. return lcd_show_yes_no_and_wait(allow_timeouting, default_yes);
  3260. }
  3261. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  3262. {
  3263. const char *msg = NULL;
  3264. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  3265. 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
  3266. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  3267. if (point_too_far_mask == 0)
  3268. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3269. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3270. // Only the center point or all the three front points.
  3271. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=6
  3272. else if ((point_too_far_mask & 1) == 0)
  3273. // The right and maybe the center point out of reach.
  3274. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=6
  3275. else
  3276. // The left and maybe the center point out of reach.
  3277. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  3278. lcd_show_fullscreen_message_and_wait_P(msg);
  3279. } else {
  3280. if (point_too_far_mask != 0) {
  3281. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3282. // Only the center point or all the three front points.
  3283. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  3284. else if ((point_too_far_mask & 1) == 0)
  3285. // The right and maybe the center point out of reach.
  3286. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  3287. else
  3288. // The left and maybe the center point out of reach.
  3289. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  3290. lcd_show_fullscreen_message_and_wait_P(msg);
  3291. }
  3292. if (point_too_far_mask == 0 || result > 0) {
  3293. switch (result) {
  3294. default:
  3295. // should not happen
  3296. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3297. break;
  3298. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  3299. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  3300. break;
  3301. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  3302. 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
  3303. break;
  3304. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  3305. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  3306. break;
  3307. }
  3308. lcd_show_fullscreen_message_and_wait_P(msg);
  3309. }
  3310. }
  3311. }
  3312. void lcd_temp_cal_show_result(bool result) {
  3313. custom_message_type = CustomMsg::Status;
  3314. disable_x();
  3315. disable_y();
  3316. disable_z();
  3317. disable_e0();
  3318. disable_e1();
  3319. disable_e2();
  3320. setTargetBed(0); //set bed target temperature back to 0
  3321. if (result == true) {
  3322. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3323. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  3324. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  3325. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3326. }
  3327. else {
  3328. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3329. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  3330. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  3331. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3332. }
  3333. lcd_update_enable(true);
  3334. lcd_update(2);
  3335. }
  3336. static void lcd_show_end_stops() {
  3337. lcd_puts_at_P(0, 0, (PSTR("End stops diag")));
  3338. lcd_puts_at_P(0, 1, (READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3339. lcd_puts_at_P(0, 2, (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3340. lcd_puts_at_P(0, 3, (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3341. }
  3342. #ifndef TMC2130
  3343. static void menu_show_end_stops() {
  3344. lcd_show_end_stops();
  3345. if (LCD_CLICKED) menu_back();
  3346. }
  3347. #endif // not defined TMC2130
  3348. // Lets the user move the Z carriage up to the end stoppers.
  3349. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3350. // Otherwise the Z calibration is not changed and false is returned.
  3351. void lcd_diag_show_end_stops()
  3352. {
  3353. lcd_clear();
  3354. lcd_consume_click();
  3355. for (;;) {
  3356. manage_heater();
  3357. manage_inactivity(true);
  3358. lcd_show_end_stops();
  3359. if (lcd_clicked()) {
  3360. break;
  3361. }
  3362. }
  3363. lcd_clear();
  3364. lcd_return_to_status();
  3365. }
  3366. static void lcd_print_state(uint8_t state)
  3367. {
  3368. switch (state) {
  3369. case STATE_ON:
  3370. lcd_puts_P(_N(" 1"));
  3371. break;
  3372. case STATE_OFF:
  3373. lcd_puts_P(_N(" 0"));
  3374. break;
  3375. default:
  3376. lcd_puts_P(_T(MSG_NA));
  3377. break;
  3378. }
  3379. }
  3380. //! @brief Show sensor state
  3381. //!
  3382. //! @code{.unparsed}
  3383. //! |01234567890123456789|
  3384. //! |PINDA N/A FINDA N/A| MSG_PINDA c=5 MSG_FINDA c=5
  3385. //! |Fil. sensor N/A| MSG_FSENSOR
  3386. //! | Int: 000 Xd:+00000|
  3387. //! |Shut: 000 Yd:+00000|
  3388. //! ----------------------
  3389. //! @endcode
  3390. static void lcd_show_sensors_state()
  3391. {
  3392. //0: N/A; 1: OFF; 2: ON
  3393. uint8_t pinda_state = STATE_NA;
  3394. uint8_t finda_state = STATE_NA;
  3395. uint8_t idler_state = STATE_NA;
  3396. pinda_state = READ(Z_MIN_PIN);
  3397. if (mmu_enabled && mmu_last_finda_response.expired(1000))
  3398. {
  3399. finda_state = mmu_finda;
  3400. }
  3401. //lcd_puts_at_P(0, 0, _i("Sensor state"));
  3402. lcd_puts_at_P(0, 0, _T(MSG_PINDA));
  3403. lcd_set_cursor(LCD_WIDTH - 14, 0);
  3404. lcd_print_state(pinda_state);
  3405. if (mmu_enabled == true)
  3406. {
  3407. lcd_puts_at_P(10, 0, _n("FINDA"));////MSG_FINDA c=5
  3408. lcd_set_cursor(LCD_WIDTH - 3, 0);
  3409. lcd_print_state(finda_state);
  3410. }
  3411. if (ir_sensor_detected) {
  3412. idler_state = !READ(IR_SENSOR_PIN);
  3413. lcd_puts_at_P(0, 1, _i("Fil. sensor"));
  3414. lcd_set_cursor(LCD_WIDTH - 3, 1);
  3415. lcd_print_state(idler_state);
  3416. }
  3417. #ifdef PAT9125
  3418. // Display X and Y difference from Filament sensor
  3419. // Display Light intensity from Filament sensor
  3420. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  3421. // value ranges from 0(darkest) to 255(brightest).
  3422. // Display LASER shutter time from Filament sensor
  3423. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  3424. // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  3425. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46.
  3426. if (mmu_enabled == false)
  3427. {
  3428. // pat9125_update is already called while printing: only update manually when idling
  3429. if (!moves_planned() && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal))
  3430. pat9125_update();
  3431. lcd_set_cursor(0, 2);
  3432. lcd_printf_P(_N(" Int: %3d Xd:%6d\n"
  3433. "Shut: %3d Yd:%6d"),
  3434. pat9125_b, pat9125_x,
  3435. pat9125_s, pat9125_y);
  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 || usb_timer.running() || (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. // MK2
  5097. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=18
  5098. // "Calibrate Z" with storing the reference values to EEPROM.
  5099. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  5100. #ifndef SNMM
  5101. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20
  5102. #endif
  5103. // "Mesh Bed Leveling"
  5104. MENU_ITEM_SUBMENU_P(_T(MSG_MESH_BED_LEVELING), lcd_mesh_bedleveling);
  5105. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=18
  5106. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17
  5107. #ifndef TMC2130
  5108. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=18
  5109. #endif
  5110. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=18
  5111. #ifndef SNMM
  5112. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  5113. #endif
  5114. if(has_temperature_compensation())
  5115. {
  5116. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17
  5117. }
  5118. }
  5119. MENU_END();
  5120. }
  5121. void bowden_menu() {
  5122. int enc_dif = lcd_encoder_diff;
  5123. int cursor_pos = 0;
  5124. lcd_clear();
  5125. lcd_putc_at(0, 0, '>');
  5126. for (uint_least8_t i = 0; i < 4; i++) {
  5127. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5128. lcd_print(i);
  5129. lcd_print(": ");
  5130. bowden_length[i] = eeprom_read_word((uint16_t*)EEPROM_BOWDEN_LENGTH + i);
  5131. lcd_print(bowden_length[i] - 48);
  5132. }
  5133. enc_dif = lcd_encoder_diff;
  5134. lcd_consume_click();
  5135. while (1) {
  5136. manage_heater();
  5137. manage_inactivity(true);
  5138. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5139. if (enc_dif > lcd_encoder_diff) {
  5140. cursor_pos--;
  5141. }
  5142. if (enc_dif < lcd_encoder_diff) {
  5143. cursor_pos++;
  5144. }
  5145. if (cursor_pos > 3) {
  5146. cursor_pos = 3;
  5147. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5148. }
  5149. if (cursor_pos < 0) {
  5150. cursor_pos = 0;
  5151. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5152. }
  5153. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5154. lcd_putc_at(0, cursor_pos, '>');
  5155. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5156. enc_dif = lcd_encoder_diff;
  5157. _delay(100);
  5158. }
  5159. if (lcd_clicked()) {
  5160. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5161. lcd_clear();
  5162. while (1) {
  5163. manage_heater();
  5164. manage_inactivity(true);
  5165. lcd_puts_at_P(1, 1, PSTR("Extruder "));
  5166. lcd_print(cursor_pos);
  5167. lcd_print(": ");
  5168. lcd_set_cursor(13, 1);
  5169. lcd_print(bowden_length[cursor_pos] - 48);
  5170. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5171. if (enc_dif > lcd_encoder_diff) {
  5172. bowden_length[cursor_pos]--;
  5173. lcd_set_cursor(13, 1);
  5174. lcd_print(bowden_length[cursor_pos] - 48);
  5175. enc_dif = lcd_encoder_diff;
  5176. }
  5177. if (enc_dif < lcd_encoder_diff) {
  5178. bowden_length[cursor_pos]++;
  5179. lcd_set_cursor(13, 1);
  5180. lcd_print(bowden_length[cursor_pos] - 48);
  5181. enc_dif = lcd_encoder_diff;
  5182. }
  5183. }
  5184. _delay(100);
  5185. if (lcd_clicked()) {
  5186. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5187. eeprom_update_word((uint16_t*)EEPROM_BOWDEN_LENGTH + cursor_pos, bowden_length[cursor_pos]);
  5188. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  5189. lcd_update_enable(true);
  5190. lcd_clear();
  5191. enc_dif = lcd_encoder_diff;
  5192. lcd_putc_at(0, cursor_pos, '>');
  5193. for (uint_least8_t i = 0; i < 4; i++) {
  5194. lcd_puts_at_P(1, i, PSTR("Extruder "));
  5195. lcd_print(i);
  5196. lcd_print(": ");
  5197. bowden_length[i] = eeprom_read_word((uint16_t*)EEPROM_BOWDEN_LENGTH + i);
  5198. lcd_print(bowden_length[i] - 48);
  5199. }
  5200. break;
  5201. }
  5202. else return;
  5203. }
  5204. }
  5205. }
  5206. }
  5207. }
  5208. #ifdef SNMM
  5209. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  5210. lcd_clear();
  5211. lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(':');
  5212. lcd_set_cursor(0, 1); lcd_print('>');
  5213. lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19
  5214. lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19
  5215. char cursor_pos = 1;
  5216. int enc_dif = 0;
  5217. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5218. lcd_consume_click();
  5219. while (1) {
  5220. manage_heater();
  5221. manage_inactivity(true);
  5222. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5223. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5224. if (enc_dif > lcd_encoder_diff) cursor_pos--;
  5225. if (enc_dif < lcd_encoder_diff) cursor_pos++;
  5226. if (cursor_pos > 3) {
  5227. cursor_pos = 3;
  5228. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5229. }
  5230. if (cursor_pos < 1){
  5231. cursor_pos = 1;
  5232. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5233. }
  5234. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5235. lcd_set_cursor(0, cursor_pos);
  5236. lcd_print('>');
  5237. enc_dif = lcd_encoder_diff;
  5238. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5239. _delay(100);
  5240. }
  5241. }
  5242. if (lcd_clicked()) {
  5243. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5244. KEEPALIVE_STATE(IN_HANDLER);
  5245. return(cursor_pos - 1);
  5246. }
  5247. }
  5248. }
  5249. #endif //SNMM
  5250. //! @brief Select one of numbered items
  5251. //!
  5252. //! Create list of items with header. Header can not be selected.
  5253. //! Each item has text description passed by function parameter and
  5254. //! number. There are 5 numbered items, if mmu_enabled, 4 otherwise.
  5255. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  5256. //! There can be last item with different text and no number.
  5257. //!
  5258. //! @param header Header text
  5259. //! @param item Item text
  5260. //! @param last_item Last item text, or nullptr if there is no Last item
  5261. //! @return selected item index, first item index is 0
  5262. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  5263. {
  5264. //following code should handle 3 to 127 number of items well
  5265. const int8_t items_no = last_item?(mmu_enabled?6:5):(mmu_enabled?5:4);
  5266. const uint8_t item_len = item?strlen_P(item):0;
  5267. int8_t first = 0;
  5268. int8_t enc_dif = lcd_encoder_diff;
  5269. int8_t cursor_pos = 1;
  5270. lcd_clear();
  5271. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5272. while (1)
  5273. {
  5274. manage_heater();
  5275. manage_inactivity(true);
  5276. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  5277. {
  5278. if (enc_dif > lcd_encoder_diff)
  5279. {
  5280. cursor_pos--;
  5281. }
  5282. if (enc_dif < lcd_encoder_diff)
  5283. {
  5284. cursor_pos++;
  5285. }
  5286. enc_dif = lcd_encoder_diff;
  5287. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5288. }
  5289. if (cursor_pos > 3)
  5290. {
  5291. cursor_pos = 3;
  5292. if (first < items_no - 3)
  5293. {
  5294. first++;
  5295. lcd_clear();
  5296. } else { // here we are at the very end of the list
  5297. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5298. }
  5299. }
  5300. if (cursor_pos < 1)
  5301. {
  5302. cursor_pos = 1;
  5303. if (first > 0)
  5304. {
  5305. first--;
  5306. lcd_clear();
  5307. } else { // here we are at the very end of the list
  5308. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5309. }
  5310. }
  5311. if (header) lcd_puts_at_P(0,0,header);
  5312. const bool last_visible = (first == items_no - 3);
  5313. const uint_least8_t ordinary_items = (last_item&&last_visible)?2:3;
  5314. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5315. {
  5316. if (item) lcd_puts_at_P(1, i + 1, item);
  5317. }
  5318. for (uint_least8_t i = 0; i < ordinary_items; i++)
  5319. {
  5320. lcd_set_cursor(2 + item_len, i+1);
  5321. lcd_print(first + i + 1);
  5322. }
  5323. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  5324. lcd_puts_at_P(0, 1, PSTR(" \n \n "));
  5325. lcd_putc_at(0, cursor_pos, '>');
  5326. _delay(100);
  5327. if (lcd_clicked())
  5328. {
  5329. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5330. KEEPALIVE_STATE(IN_HANDLER);
  5331. lcd_encoder_diff = 0;
  5332. return(cursor_pos + first - 1);
  5333. }
  5334. }
  5335. }
  5336. char reset_menu() {
  5337. const uint8_t items_no =
  5338. #ifdef SNMM
  5339. 6;
  5340. #else
  5341. 5;
  5342. #endif
  5343. static int8_t first = 0;
  5344. int8_t enc_dif = 0;
  5345. char cursor_pos = 0;
  5346. const char *const item[items_no] = {PSTR("Language"), PSTR("Statistics"), PSTR("Shipping prep"), PSTR("Service prep"), PSTR("All Data")
  5347. #ifdef SNMM
  5348. , PSTR("Bowden length")
  5349. #endif
  5350. };
  5351. enc_dif = lcd_encoder_diff;
  5352. lcd_clear();
  5353. lcd_set_cursor(0, 0);
  5354. lcd_putc('>');
  5355. lcd_consume_click();
  5356. while (1) {
  5357. for (uint_least8_t i = 0; i < 4; i++) {
  5358. lcd_puts_at_P(1, i, item[first + i]);
  5359. }
  5360. manage_heater();
  5361. manage_inactivity(true);
  5362. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  5363. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  5364. if (enc_dif > lcd_encoder_diff) {
  5365. cursor_pos--;
  5366. }
  5367. if (enc_dif < lcd_encoder_diff) {
  5368. cursor_pos++;
  5369. }
  5370. if (cursor_pos > 3) {
  5371. cursor_pos = 3;
  5372. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5373. if (first < items_no - 4) {
  5374. first++;
  5375. lcd_clear();
  5376. }
  5377. }
  5378. if (cursor_pos < 0) {
  5379. cursor_pos = 0;
  5380. Sound_MakeSound(e_SOUND_TYPE_BlindAlert);
  5381. if (first > 0) {
  5382. first--;
  5383. lcd_clear();
  5384. }
  5385. }
  5386. lcd_puts_at_P(0, 0, PSTR(" \n \n \n "));
  5387. lcd_set_cursor(0, cursor_pos);
  5388. lcd_putc('>');
  5389. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  5390. enc_dif = lcd_encoder_diff;
  5391. _delay(100);
  5392. }
  5393. }
  5394. if (lcd_clicked()) {
  5395. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  5396. return(cursor_pos + first);
  5397. }
  5398. }
  5399. }
  5400. static void lcd_disable_farm_mode()
  5401. {
  5402. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  5403. if (disable)
  5404. {
  5405. enquecommand_P(PSTR("G99"));
  5406. lcd_return_to_status();
  5407. }
  5408. lcd_update_enable(true);
  5409. lcd_draw_update = 2;
  5410. }
  5411. static void fil_load_menu()
  5412. {
  5413. MENU_BEGIN();
  5414. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5415. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all); ////MSG_LOAD_ALL c=17
  5416. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', extr_adj, 0); ////MSG_LOAD_FILAMENT_1 c=16
  5417. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', extr_adj, 1); ////MSG_LOAD_FILAMENT_2 c=17
  5418. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', extr_adj, 2); ////MSG_LOAD_FILAMENT_3 c=17
  5419. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', extr_adj, 3); ////MSG_LOAD_FILAMENT_4 c=17
  5420. if (mmu_enabled)
  5421. {
  5422. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', extr_adj, 4);
  5423. }
  5424. MENU_END();
  5425. }
  5426. static void mmu_load_to_nozzle_menu()
  5427. {
  5428. if (bFilamentAction)
  5429. {
  5430. MENU_BEGIN();
  5431. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5432. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '1', lcd_mmu_load_to_nozzle, 0);
  5433. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '2', lcd_mmu_load_to_nozzle, 1);
  5434. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '3', lcd_mmu_load_to_nozzle, 2);
  5435. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '4', lcd_mmu_load_to_nozzle, 3);
  5436. MENU_ITEM_FUNCTION_NR_P(_T(MSG_LOAD_FILAMENT), '5', lcd_mmu_load_to_nozzle, 4);
  5437. MENU_END();
  5438. }
  5439. else
  5440. {
  5441. eFilamentAction = FilamentAction::MmuLoad;
  5442. preheat_or_continue();
  5443. }
  5444. }
  5445. static void mmu_eject_filament(uint8_t filament)
  5446. {
  5447. menu_back();
  5448. mmu_eject_filament(filament, true);
  5449. }
  5450. static void mmu_fil_eject_menu()
  5451. {
  5452. if (bFilamentAction)
  5453. {
  5454. MENU_BEGIN();
  5455. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5456. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '1', mmu_eject_filament, 0);
  5457. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '2', mmu_eject_filament, 1);
  5458. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '3', mmu_eject_filament, 2);
  5459. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '4', mmu_eject_filament, 3);
  5460. MENU_ITEM_FUNCTION_NR_P(_T(MSG_EJECT_FILAMENT), '5', mmu_eject_filament, 4);
  5461. MENU_END();
  5462. }
  5463. else
  5464. {
  5465. eFilamentAction = FilamentAction::MmuEject;
  5466. preheat_or_continue();
  5467. }
  5468. }
  5469. #ifdef MMU_HAS_CUTTER
  5470. static void mmu_cut_filament_menu()
  5471. {
  5472. if(bFilamentAction)
  5473. {
  5474. MENU_BEGIN();
  5475. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5476. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '1', mmu_cut_filament, 0);
  5477. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '2', mmu_cut_filament, 1);
  5478. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '3', mmu_cut_filament, 2);
  5479. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '4', mmu_cut_filament, 3);
  5480. MENU_ITEM_FUNCTION_NR_P(_T(MSG_CUT_FILAMENT), '5', mmu_cut_filament, 4);
  5481. MENU_END();
  5482. }
  5483. else
  5484. {
  5485. eFilamentAction=FilamentAction::MmuCut;
  5486. bFilamentFirstRun=false;
  5487. if(target_temperature[0]>=EXTRUDE_MINTEMP)
  5488. {
  5489. bFilamentPreheatState=true;
  5490. mFilamentItem(target_temperature[0],target_temperature_bed);
  5491. }
  5492. else lcd_generic_preheat_menu();
  5493. }
  5494. }
  5495. #endif //MMU_HAS_CUTTER
  5496. #ifdef SNMM
  5497. static void fil_unload_menu()
  5498. {
  5499. MENU_BEGIN();
  5500. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5501. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=17
  5502. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17
  5503. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17
  5504. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17
  5505. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17
  5506. if (mmu_enabled)
  5507. MENU_ITEM_FUNCTION_P(_i("Unload filament 5"), extr_unload_4);////MSG_UNLOAD_FILAMENT_5 c=17
  5508. MENU_END();
  5509. }
  5510. static void change_extr_menu(){
  5511. MENU_BEGIN();
  5512. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5513. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17
  5514. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17
  5515. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17
  5516. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17
  5517. MENU_END();
  5518. }
  5519. #endif //SNMM
  5520. // unload filament for single material printer (used in M702 gcode)
  5521. // @param automatic: If true, unload_filament is part of a unload+load sequence (M600)
  5522. void unload_filament(bool automatic)
  5523. {
  5524. custom_message_type = CustomMsg::FilamentLoading;
  5525. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  5526. raise_z_above(automatic? MIN_Z_FOR_SWAP: MIN_Z_FOR_UNLOAD);
  5527. // extr_unload2();
  5528. current_position[E_AXIS] -= 45;
  5529. plan_buffer_line_curposXYZE(5200 / 60);
  5530. st_synchronize();
  5531. current_position[E_AXIS] -= 15;
  5532. plan_buffer_line_curposXYZE(1000 / 60);
  5533. st_synchronize();
  5534. current_position[E_AXIS] -= 20;
  5535. plan_buffer_line_curposXYZE(1000 / 60);
  5536. st_synchronize();
  5537. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  5538. //disable extruder steppers so filament can be removed
  5539. disable_e0();
  5540. disable_e1();
  5541. disable_e2();
  5542. _delay(100);
  5543. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  5544. uint8_t counterBeep = 0;
  5545. while (!lcd_clicked() && (counterBeep < 50)) {
  5546. delay_keep_alive(100);
  5547. counterBeep++;
  5548. }
  5549. st_synchronize();
  5550. while (lcd_clicked()) delay_keep_alive(100);
  5551. lcd_update_enable(true);
  5552. lcd_setstatuspgm(MSG_WELCOME);
  5553. custom_message_type = CustomMsg::Status;
  5554. }
  5555. #include "xflash.h"
  5556. #ifdef LCD_TEST
  5557. static void lcd_test_menu()
  5558. {
  5559. XFLASH_SPI_ENTER();
  5560. xflash_enable_wr();
  5561. xflash_chip_erase();
  5562. xflash_disable_wr();
  5563. }
  5564. #endif //LCD_TEST
  5565. static bool fan_error_selftest()
  5566. {
  5567. #ifdef FANCHECK
  5568. if (!fans_check_enabled) return 0;
  5569. fanSpeed = 255;
  5570. #ifdef FAN_SOFT_PWM
  5571. fanSpeedSoftPwm = 255;
  5572. #endif //FAN_SOFT_PWM
  5573. manage_heater(); //enables print fan
  5574. setExtruderAutoFanState(3); //force enables the extruder fan
  5575. #ifdef FAN_SOFT_PWM
  5576. extruder_autofan_last_check = _millis();
  5577. fan_measuring = true;
  5578. #endif //FAN_SOFT_PWM
  5579. _delay(1000); //delay_keep_alive would turn off extruder fan, because temerature is too low (maybe)
  5580. manage_heater();
  5581. fanSpeed = 0;
  5582. setExtruderAutoFanState(1); //releases lock on the extruder fan
  5583. #ifdef FAN_SOFT_PWM
  5584. fanSpeedSoftPwm = 0;
  5585. #endif //FAN_SOFT_PWM
  5586. manage_heater();
  5587. #ifdef TACH_0
  5588. if (fan_speed[0] <= 20) { //extruder fan error
  5589. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_EXTRUDER);
  5590. return 1;
  5591. }
  5592. #endif
  5593. #ifdef TACH_1
  5594. if (fan_speed[1] <= 20) { //print fan error
  5595. LCD_ALERTMESSAGERPGM(MSG_FANCHECK_PRINT);
  5596. return 1;
  5597. }
  5598. #endif
  5599. #endif //FANCHECK
  5600. return 0;
  5601. }
  5602. //! @brief Resume paused print, send host action "resumed"
  5603. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  5604. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  5605. void lcd_resume_print()
  5606. {
  5607. lcd_return_to_status();
  5608. lcd_reset_alert_level(); //for fan speed error
  5609. if (fan_error_selftest()) {
  5610. if (usb_timer.running()) SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED);
  5611. return; //abort if error persists
  5612. }
  5613. cmdqueue_serial_disabled = false;
  5614. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5615. st_synchronize();
  5616. custom_message_type = CustomMsg::Resuming;
  5617. isPrintPaused = false;
  5618. restore_print_from_ram_and_continue(default_retraction);
  5619. pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  5620. refresh_cmd_timeout();
  5621. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint
  5622. custom_message_type = CustomMsg::Status;
  5623. }
  5624. //! @brief Resume paused USB/host print, send host action "resume"
  5625. void lcd_resume_usb_print()
  5626. {
  5627. SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUME); //resume octoprint
  5628. }
  5629. static void change_sheet()
  5630. {
  5631. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5632. menu_back(3);
  5633. }
  5634. static void lcd_rename_sheet_menu()
  5635. {
  5636. struct MenuData
  5637. {
  5638. bool initialized;
  5639. uint8_t selected;
  5640. char name[sizeof(Sheet::name)];
  5641. };
  5642. static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data");
  5643. MenuData* menuData = (MenuData*)&(menu_data[0]);
  5644. if (!menuData->initialized)
  5645. {
  5646. eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name));
  5647. lcd_encoder = menuData->name[0];
  5648. menuData->initialized = true;
  5649. }
  5650. if (lcd_encoder < '\x20') lcd_encoder = '\x20';
  5651. if (lcd_encoder > '\x7F') lcd_encoder = '\x7F';
  5652. menuData->name[menuData->selected] = lcd_encoder;
  5653. lcd_set_cursor(0,0);
  5654. for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i)
  5655. {
  5656. lcd_putc(menuData->name[i]);
  5657. }
  5658. lcd_set_cursor(menuData->selected, 1);
  5659. lcd_putc('^');
  5660. if (lcd_clicked())
  5661. {
  5662. if ((menuData->selected + 1u) < sizeof(Sheet::name))
  5663. {
  5664. lcd_encoder = menuData->name[++(menuData->selected)];
  5665. }
  5666. else
  5667. {
  5668. eeprom_update_block(menuData->name,
  5669. EEPROM_Sheets_base->s[selected_sheet].name,
  5670. sizeof(Sheet::name));
  5671. menu_back();
  5672. }
  5673. }
  5674. }
  5675. static void lcd_reset_sheet()
  5676. {
  5677. SheetName sheetName;
  5678. eeprom_default_sheet_name(selected_sheet, sheetName);
  5679. eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),EEPROM_EMPTY_VALUE16);
  5680. eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name));
  5681. if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))
  5682. {
  5683. eeprom_switch_to_next_sheet();
  5684. if((-1 == eeprom_next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status()))
  5685. {
  5686. calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
  5687. }
  5688. }
  5689. menu_back();
  5690. }
  5691. //! @brief Activate selected_sheet and run first layer calibration
  5692. static void activate_calibrate_sheet()
  5693. {
  5694. eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet);
  5695. lcd_first_layer_calibration_reset();
  5696. }
  5697. static void lcd_sheet_menu()
  5698. {
  5699. MENU_BEGIN();
  5700. MENU_ITEM_BACK_P(_T(MSG_STEEL_SHEETS));
  5701. if(eeprom_is_sheet_initialized(selected_sheet)){
  5702. MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); ////MSG_SELECT c=18
  5703. }
  5704. if (lcd_commands_type == LcdCommands::Idle)
  5705. {
  5706. MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet);////MSG_V2_CALIBRATION c=18
  5707. }
  5708. MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); ////MSG_RENAME c=18
  5709. MENU_ITEM_FUNCTION_P(_T(MSG_RESET), lcd_reset_sheet); ////MSG_RESET c=14
  5710. MENU_END();
  5711. }
  5712. //! @brief Show Main Menu
  5713. //!
  5714. //! @code{.unparsed}
  5715. //! |01234567890123456789|
  5716. //! | Info screen | allways
  5717. //!
  5718. //! | tst - Save | ifdef RESUME_DEBUG
  5719. //! | tst - Restore | ifdef RESUME_DEBUG
  5720. //!
  5721. //! | recover print | ifdef TMC2130_DEBUG
  5722. //! | power panic | ifdef TMC2130_DEBUG
  5723. //!
  5724. //! | Live adjust Z | printing + Z low
  5725. //!
  5726. //! | Change filament | farm mode
  5727. //!
  5728. //! | Tune | printing + paused
  5729. //! | Pause print | printing + not paused
  5730. //! | Resume print | printing + paused
  5731. //! | Stop print | printing or paused + NOT MBL
  5732. //! | Preheat | not printing + not paused
  5733. //! | Print from SD | not printing or paused
  5734. //!
  5735. //! | Switch sheet | farm mode
  5736. //!
  5737. //! | AutoLoad filament | not printing + not mmu or paused
  5738. //! | Load filament | not printing + mmu or paused
  5739. //! | Load to nozzle | not printing + mmu or paused
  5740. //! | Unload filament | not printing or paused
  5741. //! | Eject filament | not printing + mmu or paused
  5742. //! | Cut filament | not printing + mmu or paused + cut atctive
  5743. //! | Settings | not printing or paused
  5744. //! | Calibration | not printing
  5745. //! | Statistics | not printing
  5746. //! | Fail stats | allways
  5747. //! | Fail stats MMU | mmu
  5748. //! | Support | allways
  5749. //! @endcode
  5750. static void lcd_main_menu()
  5751. {
  5752. MENU_BEGIN();
  5753. // Majkl superawesome menu
  5754. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  5755. #ifdef RESUME_DEBUG
  5756. if (!saved_printing)
  5757. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  5758. else
  5759. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  5760. #endif //RESUME_DEBUG
  5761. #ifdef TMC2130_DEBUG
  5762. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  5763. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  5764. #endif //TMC2130_DEBUG
  5765. if ( ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) {
  5766. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  5767. }
  5768. if (farm_mode)
  5769. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5770. if ( moves_planned() || PRINTER_ACTIVE ) {
  5771. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=18
  5772. } else {
  5773. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18
  5774. }
  5775. if (mesh_bed_leveling_flag == false && homing_flag == false && !isPrintPaused) {
  5776. if (usb_timer.running()) {
  5777. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_usb_print);////MSG_PAUSE_PRINT c=18
  5778. } else if (IS_SD_PRINTING) {
  5779. MENU_ITEM_FUNCTION_P(_T(MSG_PAUSE_PRINT), lcd_pause_print);////MSG_PAUSE_PRINT c=18
  5780. }
  5781. }
  5782. if(isPrintPaused)
  5783. {
  5784. #ifdef FANCHECK
  5785. if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK))
  5786. #endif //FANCHECK
  5787. {
  5788. if (usb_timer.running()) {
  5789. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print);////MSG_RESUME_PRINT c=18
  5790. } else {
  5791. MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print);////MSG_RESUME_PRINT c=18
  5792. }
  5793. }
  5794. }
  5795. if((IS_SD_PRINTING || usb_timer.running() || isPrintPaused) && (custom_message_type != CustomMsg::MeshBedLeveling)) {
  5796. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  5797. }
  5798. #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
  5799. if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) {
  5800. if (!card.isFileOpen()) {
  5801. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5802. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  5803. /*else*/{
  5804. bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
  5805. MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  5806. }
  5807. }
  5808. #if SDCARDDETECT < 1
  5809. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD
  5810. #endif //SDCARDDETECT
  5811. }
  5812. } else {
  5813. bMain=true; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  5814. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=18
  5815. #if SDCARDDETECT < 1
  5816. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD
  5817. #endif //SDCARDDETECT
  5818. }
  5819. #endif //SDSUPPORT
  5820. if(!isPrintPaused && !IS_SD_PRINTING && !usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5821. if (!farm_mode) {
  5822. const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
  5823. const int8_t nextSheet = eeprom_next_initialized_sheet(sheet);
  5824. if ((nextSheet >= 0) && (sheet != nextSheet)) { // show menu only if we have 2 or more sheets initialized
  5825. MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet);
  5826. }
  5827. }
  5828. }
  5829. if ( ! ( IS_SD_PRINTING || usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal) ) ) {
  5830. if (mmu_enabled) {
  5831. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  5832. MENU_ITEM_SUBMENU_P(_i("Load to nozzle"), mmu_load_to_nozzle_menu);////MSG_LOAD_TO_NOZZLE c=18
  5833. //-// MENU_ITEM_FUNCTION_P(_T(MSG_UNLOAD_FILAMENT), extr_unload);
  5834. //bFilamentFirstRun=true;
  5835. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), mmu_unload_filament);
  5836. MENU_ITEM_SUBMENU_P(_T(MSG_EJECT_FILAMENT), mmu_fil_eject_menu);
  5837. #ifdef MMU_HAS_CUTTER
  5838. MENU_ITEM_SUBMENU_P(_T(MSG_CUT_FILAMENT), mmu_cut_filament_menu);
  5839. #endif //MMU_HAS_CUTTER
  5840. } else {
  5841. #ifdef SNMM
  5842. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  5843. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20
  5844. #endif
  5845. #ifdef FILAMENT_SENSOR
  5846. if ((fsensor_autoload_enabled == true) && (fsensor_enabled == true) && (mmu_enabled == false))
  5847. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=18
  5848. else
  5849. #endif //FILAMENT_SENSOR
  5850. {
  5851. bFilamentFirstRun=true;
  5852. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  5853. }
  5854. bFilamentFirstRun=true;
  5855. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  5856. }
  5857. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  5858. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  5859. }
  5860. if (!usb_timer.running() && (lcd_commands_type != LcdCommands::Layer1Cal)) {
  5861. MENU_ITEM_SUBMENU_P(_i("Statistics"), lcd_menu_statistics);////MSG_STATISTICS c=18
  5862. }
  5863. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  5864. MENU_ITEM_SUBMENU_P(_i("Fail stats"), lcd_menu_fails_stats);////MSG_FAIL_STATS c=18
  5865. #endif
  5866. if (mmu_enabled) {
  5867. MENU_ITEM_SUBMENU_P(_i("Fail stats MMU"), lcd_menu_fails_stats_mmu);////MSG_MMU_FAIL_STATS c=18
  5868. }
  5869. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=18
  5870. #ifdef LCD_TEST
  5871. MENU_ITEM_SUBMENU_P(_i("XFLASH init"), lcd_test_menu);////MSG_SUPPORT
  5872. #endif //LCD_TEST
  5873. MENU_END();
  5874. }
  5875. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5876. bool stepper_timer_overflow_state = false;
  5877. uint16_t stepper_timer_overflow_max = 0;
  5878. uint16_t stepper_timer_overflow_last = 0;
  5879. uint16_t stepper_timer_overflow_cnt = 0;
  5880. void stepper_timer_overflow() {
  5881. char msg[28];
  5882. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5883. lcd_setstatus(msg);
  5884. stepper_timer_overflow_state = false;
  5885. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5886. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5887. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5888. MYSERIAL.print(msg);
  5889. SERIAL_ECHOLNPGM("");
  5890. WRITE(BEEPER, LOW);
  5891. }
  5892. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5893. static void lcd_colorprint_change() {
  5894. enquecommand_P(PSTR("M600"));
  5895. custom_message_type = CustomMsg::FilamentLoading; //just print status message
  5896. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5897. lcd_return_to_status();
  5898. lcd_draw_update = 3;
  5899. }
  5900. #ifdef LA_LIVE_K
  5901. // @wavexx: looks like there's no generic float editing function in menu.cpp so we
  5902. // redefine our custom handling functions to mimick other tunables
  5903. const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S";
  5904. static void lcd_advance_draw_K(char chr, float val)
  5905. {
  5906. if (val <= 0)
  5907. lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, _T(MSG_OFF));
  5908. else
  5909. lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val);
  5910. }
  5911. static void lcd_advance_edit_K(void)
  5912. {
  5913. if (lcd_draw_update)
  5914. {
  5915. if (lcd_encoder < 0) lcd_encoder = 0;
  5916. if (lcd_encoder > 999) lcd_encoder = 999;
  5917. lcd_set_cursor(0, 1);
  5918. lcd_advance_draw_K(' ', 0.01 * lcd_encoder);
  5919. }
  5920. if (LCD_CLICKED)
  5921. {
  5922. extruder_advance_K = 0.01 * lcd_encoder;
  5923. menu_back_no_reset();
  5924. }
  5925. }
  5926. static uint8_t lcd_advance_K()
  5927. {
  5928. if (menu_item == menu_line)
  5929. {
  5930. if (lcd_draw_update)
  5931. {
  5932. lcd_set_cursor(0, menu_row);
  5933. lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K);
  5934. }
  5935. if (menu_clicked && (lcd_encoder == menu_item))
  5936. {
  5937. menu_submenu_no_reset(lcd_advance_edit_K);
  5938. lcd_encoder = 100. * extruder_advance_K;
  5939. return menu_item_ret();
  5940. }
  5941. }
  5942. menu_item++;
  5943. return 0;
  5944. }
  5945. #define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0)
  5946. #endif
  5947. static void lcd_tune_menu()
  5948. {
  5949. typedef struct
  5950. {
  5951. menu_data_edit_t reserved; //!< reserved for number editing functions
  5952. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5953. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  5954. //! it needs to be applied.
  5955. int16_t extrudemultiply;
  5956. } _menu_data_t;
  5957. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5958. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5959. if (_md->status == 0)
  5960. {
  5961. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5962. _md->status = 1;
  5963. _md->extrudemultiply = extrudemultiply;
  5964. }
  5965. else if (_md->extrudemultiply != extrudemultiply)
  5966. {
  5967. // extrudemultiply has been changed from the child menu. Apply the new value.
  5968. _md->extrudemultiply = extrudemultiply;
  5969. calculate_extruder_multipliers();
  5970. }
  5971. SilentModeMenu = eeprom_read_byte((uint8_t*) EEPROM_SILENT);
  5972. MENU_BEGIN();
  5973. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5974. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=15
  5975. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5976. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  5977. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5978. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=15
  5979. #ifdef LA_LIVE_K
  5980. MENU_ITEM_EDIT_advance_K();//7
  5981. #endif
  5982. #ifdef FILAMENTCHANGEENABLE
  5983. if (!farm_mode)
  5984. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8
  5985. #endif
  5986. #ifdef FILAMENT_SENSOR
  5987. if (FSensorStateMenu == 0) {
  5988. if (fsensor_not_responding && (mmu_enabled == false)) {
  5989. /* Filament sensor not working*/
  5990. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), lcd_fsensor_state_set);
  5991. }
  5992. else {
  5993. /* Filament sensor turned off, working, no problems*/
  5994. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_OFF), lcd_fsensor_state_set);
  5995. }
  5996. }
  5997. else {
  5998. MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_ON), lcd_fsensor_state_set);
  5999. }
  6000. #ifdef IR_SENSOR_ANALOG
  6001. FSENSOR_ACTION_NA;
  6002. #endif //IR_SENSOR_ANALOG
  6003. #endif //FILAMENT_SENSOR
  6004. SETTINGS_AUTO_DEPLETE;
  6005. SETTINGS_CUTTER;
  6006. MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check);
  6007. #ifdef TMC2130
  6008. if(!farm_mode)
  6009. {
  6010. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);
  6011. else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);
  6012. if (SilentModeMenu == SILENT_MODE_NORMAL)
  6013. {
  6014. if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);
  6015. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch);
  6016. }
  6017. else MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info);
  6018. }
  6019. #else //TMC2130
  6020. if (!farm_mode) { //dont show in menu if we are in farm mode
  6021. switch (SilentModeMenu) {
  6022. case SILENT_MODE_POWER: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break;
  6023. case SILENT_MODE_SILENT: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_SILENT), lcd_silent_mode_set); break;
  6024. case SILENT_MODE_AUTO: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_AUTO_POWER), lcd_silent_mode_set); break;
  6025. default: MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_HIGH_POWER), lcd_silent_mode_set); break; // (probably) not needed
  6026. }
  6027. }
  6028. #endif //TMC2130
  6029. SETTINGS_MMU_MODE;
  6030. SETTINGS_SOUND;
  6031. #ifdef LCD_BL_PIN
  6032. if (backlightSupport)
  6033. {
  6034. MENU_ITEM_SUBMENU_P(_T(MSG_BRIGHTNESS), lcd_backlight_menu);
  6035. }
  6036. #endif //LCD_BL_PIN
  6037. MENU_END();
  6038. }
  6039. static void mbl_magnets_elimination_toggle() {
  6040. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6041. magnet_elimination = !magnet_elimination;
  6042. eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination);
  6043. }
  6044. static void mbl_mesh_toggle() {
  6045. uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6046. if(mesh_nr == 3) mesh_nr = 7;
  6047. else mesh_nr = 3;
  6048. eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr);
  6049. }
  6050. static void mbl_probe_nr_toggle() {
  6051. mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR);
  6052. switch (mbl_z_probe_nr) {
  6053. case 1: mbl_z_probe_nr = 3; break;
  6054. case 3: mbl_z_probe_nr = 5; break;
  6055. case 5: mbl_z_probe_nr = 1; break;
  6056. default: mbl_z_probe_nr = 3; break;
  6057. }
  6058. eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr);
  6059. }
  6060. static void lcd_mesh_bed_leveling_settings()
  6061. {
  6062. bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0);
  6063. uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR);
  6064. char sToggle[4]; //enough for nxn format
  6065. MENU_BEGIN();
  6066. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6067. sToggle[0] = points_nr + '0';
  6068. sToggle[1] = 'x';
  6069. sToggle[2] = points_nr + '0';
  6070. sToggle[3] = 0;
  6071. MENU_ITEM_TOGGLE(_T(MSG_MESH), sToggle, mbl_mesh_toggle);
  6072. sToggle[0] = mbl_z_probe_nr + '0';
  6073. sToggle[1] = 0;
  6074. MENU_ITEM_TOGGLE(_T(MSG_Z_PROBE_NR), sToggle, mbl_probe_nr_toggle);
  6075. 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);
  6076. MENU_END();
  6077. //SETTINGS_MBL_MODE;
  6078. }
  6079. #ifdef LCD_BL_PIN
  6080. static void backlight_mode_toggle()
  6081. {
  6082. switch (backlightMode)
  6083. {
  6084. case BACKLIGHT_MODE_BRIGHT: backlightMode = BACKLIGHT_MODE_DIM; break;
  6085. case BACKLIGHT_MODE_DIM: backlightMode = BACKLIGHT_MODE_AUTO; break;
  6086. case BACKLIGHT_MODE_AUTO: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6087. default: backlightMode = BACKLIGHT_MODE_BRIGHT; break;
  6088. }
  6089. backlight_save();
  6090. }
  6091. static void lcd_backlight_menu()
  6092. {
  6093. MENU_BEGIN();
  6094. ON_MENU_LEAVE(
  6095. backlight_save();
  6096. );
  6097. MENU_ITEM_BACK_P(_T(MSG_BACK));
  6098. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_HIGH), &backlightLevel_HIGH, backlightLevel_LOW, 255);
  6099. MENU_ITEM_EDIT_int3_P(_T(MSG_BL_LOW), &backlightLevel_LOW, 0, backlightLevel_HIGH);
  6100. 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);
  6101. MENU_ITEM_EDIT_int3_P(_T(MSG_TIMEOUT), &backlightTimer_period, 1, 999);
  6102. MENU_END();
  6103. }
  6104. #endif //LCD_BL_PIN
  6105. static void lcd_control_temperature_menu()
  6106. {
  6107. #ifdef PIDTEMP
  6108. // set up temp variables - undo the default scaling
  6109. // raw_Ki = unscalePID_i(Ki);
  6110. // raw_Kd = unscalePID_d(Kd);
  6111. #endif
  6112. MENU_BEGIN();
  6113. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  6114. #if TEMP_SENSOR_0 != 0
  6115. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  6116. #endif
  6117. #if TEMP_SENSOR_1 != 0
  6118. MENU_ITEM_EDIT_int3_P(_i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1
  6119. #endif
  6120. #if TEMP_SENSOR_2 != 0
  6121. MENU_ITEM_EDIT_int3_P(_i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2
  6122. #endif
  6123. #if TEMP_SENSOR_BED != 0
  6124. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  6125. #endif
  6126. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  6127. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  6128. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  6129. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  6130. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN
  6131. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX
  6132. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR
  6133. #endif
  6134. MENU_END();
  6135. }
  6136. static void lcd_sd_refresh()
  6137. {
  6138. #if SDCARDDETECT == -1
  6139. card.initsd();
  6140. #else
  6141. card.presort();
  6142. #endif
  6143. menu_top = 0;
  6144. lcd_encoder = 0;
  6145. menu_data_reset(); //Forces reloading of cached variables.
  6146. }
  6147. static void lcd_sd_updir()
  6148. {
  6149. card.updir();
  6150. menu_top = 0;
  6151. lcd_encoder = 0;
  6152. menu_data_reset(); //Forces reloading of cached variables.
  6153. }
  6154. void lcd_print_stop()
  6155. {
  6156. if (!card.sdprinting) {
  6157. SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
  6158. }
  6159. UnconditionalStop();
  6160. // TODO: all the following should be moved in the main marlin loop!
  6161. #ifdef MESH_BED_LEVELING
  6162. mbl.active = false; //also prevents undoing the mbl compensation a second time in the second planner_abort_hard()
  6163. #endif
  6164. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  6165. stoptime = _millis();
  6166. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  6167. pause_time = 0;
  6168. save_statistics(total_filament_used, t);
  6169. // reset current command
  6170. lcd_commands_step = 0;
  6171. lcd_commands_type = LcdCommands::Idle;
  6172. lcd_cooldown(); //turns off heaters and fan; goes to status screen.
  6173. current_position[Z_AXIS] += 10; //lift Z.
  6174. plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60);
  6175. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) //if axis are homed, move to parked position.
  6176. {
  6177. current_position[X_AXIS] = X_CANCEL_POS;
  6178. current_position[Y_AXIS] = Y_CANCEL_POS;
  6179. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6180. }
  6181. st_synchronize();
  6182. if (mmu_enabled) extr_unload(); //M702 C
  6183. finishAndDisableSteppers(); //M84
  6184. lcd_setstatuspgm(MSG_WELCOME);
  6185. custom_message_type = CustomMsg::Status;
  6186. 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.
  6187. axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative
  6188. isPrintPaused = false; //clear isPrintPaused flag to allow starting next print after pause->stop scenario.
  6189. }
  6190. void lcd_sdcard_stop()
  6191. {
  6192. lcd_puts_at_P(0, 0, _T(MSG_STOP_PRINT));
  6193. lcd_puts_at_P(2, 2, _T(MSG_NO));
  6194. lcd_puts_at_P(2, 3, _T(MSG_YES));
  6195. lcd_putc_at(0, 2, ' ');
  6196. lcd_putc_at(0, 3, ' ');
  6197. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  6198. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  6199. lcd_putc_at(0, 1 + lcd_encoder, '>');
  6200. if (lcd_clicked())
  6201. {
  6202. Sound_MakeSound(e_SOUND_TYPE_ButtonEcho);
  6203. if ((int32_t)lcd_encoder == 1)
  6204. {
  6205. lcd_return_to_status();
  6206. }
  6207. if ((int32_t)lcd_encoder == 2)
  6208. {
  6209. lcd_print_stop();
  6210. }
  6211. }
  6212. }
  6213. void lcd_sdcard_menu()
  6214. {
  6215. enum menuState_t : uint8_t {_uninitialized, _standard, _scrolling};
  6216. typedef struct
  6217. {
  6218. menuState_t menuState = _uninitialized;
  6219. uint8_t offset;
  6220. bool isDir;
  6221. const char* scrollPointer;
  6222. uint16_t selectedFileID;
  6223. uint16_t fileCnt;
  6224. int8_t row;
  6225. uint8_t sdSort;
  6226. ShortTimer lcd_scrollTimer;
  6227. } _menu_data_sdcard_t;
  6228. static_assert(sizeof(menu_data)>= sizeof(_menu_data_sdcard_t),"_menu_data_sdcard_t doesn't fit into menu_data");
  6229. _menu_data_sdcard_t* _md = (_menu_data_sdcard_t*)&(menu_data[0]);
  6230. switch(_md->menuState)
  6231. {
  6232. case _uninitialized: //Initialize menu data
  6233. {
  6234. if (card.presort_flag == true) //used to force resorting if sorting type is changed.
  6235. {
  6236. card.presort_flag = false;
  6237. card.presort();
  6238. }
  6239. _md->fileCnt = card.getnrfilenames();
  6240. _md->sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  6241. _md->menuState = _standard;
  6242. }
  6243. // FALLTHRU
  6244. case _standard: //normal menu structure.
  6245. {
  6246. if (!_md->lcd_scrollTimer.running()) //if the timer is not running, then the menu state was just switched, so redraw the screen.
  6247. {
  6248. _md->lcd_scrollTimer.start();
  6249. lcd_draw_update = 1;
  6250. }
  6251. if (_md->lcd_scrollTimer.expired(500) && (_md->row != -1)) //switch to the scrolling state on timeout if a file/dir is selected.
  6252. {
  6253. _md->menuState = _scrolling;
  6254. _md->offset = 0;
  6255. _md->scrollPointer = NULL;
  6256. _md->lcd_scrollTimer.start();
  6257. lcd_draw_update = 1; //forces last load before switching to scrolling.
  6258. }
  6259. if (lcd_draw_update == 0 && !LCD_CLICKED)
  6260. return; // nothing to do (so don't thrash the SD card)
  6261. _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.
  6262. //if we reached this point it means that the encoder moved or clicked or the state is being switched. Reset the scrollTimer.
  6263. _md->lcd_scrollTimer.start();
  6264. MENU_BEGIN();
  6265. MENU_ITEM_BACK_P(_T(bMain?MSG_MAIN:MSG_BACK)); // i.e. default menu-item / menu-item after card insertion
  6266. card.getWorkDirName();
  6267. if (card.filename[0] == '/')
  6268. {
  6269. #if SDCARDDETECT == -1
  6270. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  6271. #else
  6272. if (card.ToshibaFlashAir_isEnabled())
  6273. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); //show the refresh option if in flashAir mode.
  6274. #endif
  6275. }
  6276. else
  6277. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); //Show the updir button if in a subdir.
  6278. for (uint16_t i = _md->fileCnt; i-- > 0;) // Every file, from top to bottom.
  6279. {
  6280. if (menu_item == menu_line) //If the file is on the screen.
  6281. {
  6282. //load filename to memory.
  6283. #ifdef SDCARD_SORT_ALPHA
  6284. if (_md->sdSort == SD_SORT_NONE)
  6285. card.getfilename(i);
  6286. else
  6287. card.getfilename_sorted(i, _md->sdSort);
  6288. #else
  6289. card.getfilename(i);
  6290. #endif
  6291. if (lcd_encoder == menu_item) //If the file is selected.
  6292. {
  6293. _md->selectedFileID = i;
  6294. _md->isDir = card.filenameIsDir;
  6295. _md->row = menu_row;
  6296. }
  6297. if (card.filenameIsDir)
  6298. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  6299. else
  6300. MENU_ITEM_SDFILE(card.filename, card.longFilename);
  6301. }
  6302. else MENU_ITEM_DUMMY(); //dummy item that just increments the internal menu counters.
  6303. }
  6304. MENU_END();
  6305. } break;
  6306. case _scrolling: //scrolling filename
  6307. {
  6308. const bool rewindFlag = LCD_CLICKED || lcd_draw_update; //flag that says whether the menu should return to _standard state.
  6309. if (_md->scrollPointer == NULL)
  6310. {
  6311. //load filename to memory.
  6312. #ifdef SDCARD_SORT_ALPHA
  6313. if (_md->sdSort == SD_SORT_NONE)
  6314. card.getfilename(_md->selectedFileID);
  6315. else
  6316. card.getfilename_sorted(_md->selectedFileID, _md->sdSort);
  6317. #else
  6318. card.getfilename(_md->selectedFileID);
  6319. #endif
  6320. _md->scrollPointer = (card.longFilename[0] == '\0') ? card.filename : card.longFilename;
  6321. }
  6322. if (rewindFlag == 1)
  6323. _md->offset = 0; //redraw once again from the beginning.
  6324. if (_md->lcd_scrollTimer.expired(300) || rewindFlag)
  6325. {
  6326. uint8_t i = LCD_WIDTH - ((_md->isDir)?2:1);
  6327. lcd_set_cursor(0, _md->row);
  6328. lcd_print('>');
  6329. if (_md->isDir)
  6330. lcd_print(LCD_STR_FOLDER[0]);
  6331. for (; i != 0; i--)
  6332. {
  6333. const char* c = (_md->scrollPointer + _md->offset + ((LCD_WIDTH - ((_md->isDir)?2:1)) - i));
  6334. lcd_print(c[0]);
  6335. if (c[1])
  6336. _md->lcd_scrollTimer.start();
  6337. else
  6338. {
  6339. _md->lcd_scrollTimer.stop();
  6340. break; //stop at the end of the string
  6341. }
  6342. }
  6343. if (i != 0) //adds spaces if string is incomplete or at the end (instead of null).
  6344. {
  6345. lcd_space(i);
  6346. }
  6347. _md->offset++;
  6348. }
  6349. if (rewindFlag) //go back to sd_menu.
  6350. {
  6351. _md->lcd_scrollTimer.stop(); //forces redraw in _standard state
  6352. _md->menuState = _standard;
  6353. }
  6354. } break;
  6355. default: _md->menuState = _uninitialized; //shouldn't ever happen. Anyways, initialize the menu.
  6356. }
  6357. }
  6358. #ifdef TMC2130
  6359. static void lcd_belttest_v()
  6360. {
  6361. lcd_belttest();
  6362. menu_back_if_clicked();
  6363. }
  6364. void lcd_belttest()
  6365. {
  6366. lcd_clear();
  6367. // Belttest requires high power mode. Enable it.
  6368. FORCE_HIGH_POWER_START;
  6369. uint16_t X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6370. uint16_t Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6371. lcd_printf_P(_T(MSG_CHECKING_X));
  6372. lcd_set_cursor(0,1), lcd_printf_P(PSTR("X: %u -> ..."),X);
  6373. KEEPALIVE_STATE(IN_HANDLER);
  6374. // N.B: it doesn't make sense to handle !lcd_selfcheck...() because selftest_sg throws its own error screen
  6375. // that clobbers ours, with more info than we could provide. So on fail we just fall through to take us back to status.
  6376. if (lcd_selfcheck_axis_sg(X_AXIS)){
  6377. X = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X));
  6378. lcd_set_cursor(10,1), lcd_printf_P(PSTR("%u"),X); // Show new X value next to old one.
  6379. lcd_puts_at_P(0,2,_T(MSG_CHECKING_Y));
  6380. lcd_set_cursor(0,3), lcd_printf_P(PSTR("Y: %u -> ..."),Y);
  6381. if (lcd_selfcheck_axis_sg(Y_AXIS))
  6382. {
  6383. Y = eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y));
  6384. lcd_set_cursor(10,3),lcd_printf_P(PSTR("%u"),Y);
  6385. lcd_set_cursor(19, 3);
  6386. lcd_print(LCD_STR_UPLEVEL[0]);
  6387. lcd_wait_for_click_delay(10);
  6388. }
  6389. }
  6390. FORCE_HIGH_POWER_END;
  6391. KEEPALIVE_STATE(NOT_BUSY);
  6392. }
  6393. #endif //TMC2130
  6394. #ifdef IR_SENSOR_ANALOG
  6395. // called also from marlin_main.cpp
  6396. void printf_IRSensorAnalogBoardChange(){
  6397. printf_P(PSTR("Filament sensor board change detected: revision%S\n"), FsensorIRVersionText());
  6398. }
  6399. static bool lcd_selftest_IRsensor(bool bStandalone)
  6400. {
  6401. bool bPCBrev04;
  6402. uint16_t volt_IR_int;
  6403. volt_IR_int = current_voltage_raw_IR;
  6404. bPCBrev04=(volt_IR_int < IRsensor_Hopen_TRESHOLD);
  6405. printf_P(PSTR("Measured filament sensor high level: %4.2fV\n"), Raw2Voltage(volt_IR_int) );
  6406. if(volt_IR_int < IRsensor_Hmin_TRESHOLD){
  6407. if(!bStandalone)
  6408. lcd_selftest_error(TestError::FsensorLevel,"HIGH","");
  6409. return(false);
  6410. }
  6411. 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
  6412. volt_IR_int = current_voltage_raw_IR;
  6413. printf_P(PSTR("Measured filament sensor low level: %4.2fV\n"), Raw2Voltage(volt_IR_int));
  6414. if(volt_IR_int > (IRsensor_Lmax_TRESHOLD)){
  6415. if(!bStandalone)
  6416. lcd_selftest_error(TestError::FsensorLevel,"LOW","");
  6417. return(false);
  6418. }
  6419. if((bPCBrev04 ? 1 : 0) != (uint8_t)oFsensorPCB){ // safer then "(uint8_t)bPCBrev04"
  6420. oFsensorPCB=bPCBrev04 ? ClFsensorPCB::_Rev04 : ClFsensorPCB::_Old;
  6421. printf_IRSensorAnalogBoardChange();
  6422. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,(uint8_t)oFsensorPCB);
  6423. }
  6424. return(true);
  6425. }
  6426. static void lcd_detect_IRsensor(){
  6427. bool bAction;
  6428. bool loaded;
  6429. bMenuFSDetect = true; // inhibits some code inside "manage_inactivity()"
  6430. /// Check if filament is loaded. If it is loaded stop detection.
  6431. /// @todo Add autodetection with MMU2s
  6432. loaded = ! READ(IR_SENSOR_PIN);
  6433. if(loaded ){
  6434. 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
  6435. return;
  6436. } else {
  6437. 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
  6438. bAction = lcd_selftest_IRsensor(true);
  6439. }
  6440. if(bAction){
  6441. lcd_show_fullscreen_message_and_wait_P(_i("Sensor verified, remove the filament now."));////MSG_FS_VERIFIED c=20 r=3
  6442. // the fsensor board has been successfully identified, any previous "not responding" may be cleared now
  6443. fsensor_not_responding = false;
  6444. } else {
  6445. lcd_show_fullscreen_message_and_wait_P(_i("Verification failed, remove the filament and try again."));////MSG_FIL_FAILED c=20 r=5
  6446. // here it is unclear what to to with the fsensor_not_responding flag
  6447. }
  6448. bMenuFSDetect=false; // de-inhibits some code inside "manage_inactivity()"
  6449. }
  6450. #endif //IR_SENSOR_ANALOG
  6451. static void lcd_selftest_v()
  6452. {
  6453. (void)lcd_selftest();
  6454. }
  6455. bool lcd_selftest()
  6456. {
  6457. uint8_t _progress = 0;
  6458. bool _result = true;
  6459. bool _swapped_fan = false;
  6460. #ifdef IR_SENSOR_ANALOG
  6461. //! Check if IR sensor is in unknown state, if so run Fsensor Detection
  6462. //! As the Fsensor Detection isn't yet ready for the mmu2s we set temporarily the IR sensor 0.3 or older for mmu2s
  6463. //! @todo Don't forget to remove this as soon Fsensor Detection works with mmu
  6464. if( oFsensorPCB == ClFsensorPCB::_Undef) {
  6465. if (!mmu_enabled) {
  6466. lcd_detect_IRsensor();
  6467. }
  6468. else {
  6469. eeprom_update_byte((uint8_t*)EEPROM_FSENSOR_PCB,0);
  6470. }
  6471. }
  6472. #endif //IR_SENSOR_ANALOG
  6473. lcd_wait_for_cool_down();
  6474. lcd_clear();
  6475. lcd_puts_at_P(0, 0, _i("Self test start"));////MSG_SELFTEST_START c=20
  6476. #ifdef TMC2130
  6477. FORCE_HIGH_POWER_START;
  6478. #endif // TMC2130
  6479. FORCE_BL_ON_START;
  6480. _delay(2000);
  6481. KEEPALIVE_STATE(IN_HANDLER);
  6482. _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000);
  6483. #if (defined(FANCHECK) && defined(TACH_0))
  6484. switch (lcd_selftest_fan_auto(0)){ // check extruder Fan
  6485. case FanCheck::ExtruderFan:
  6486. _result = false;
  6487. break;
  6488. case FanCheck::SwappedFan:
  6489. _swapped_fan = true;
  6490. // FALLTHRU
  6491. default:
  6492. _result = true;
  6493. break;
  6494. }
  6495. #else //defined(TACH_0)
  6496. _result = lcd_selftest_manual_fan_check(0, false);
  6497. #endif //defined(TACH_0)
  6498. if (!_result)
  6499. {
  6500. lcd_selftest_error(TestError::ExtruderFan, "", "");
  6501. }
  6502. if (_result)
  6503. {
  6504. _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000);
  6505. #if (defined(FANCHECK) && defined(TACH_1))
  6506. switch (lcd_selftest_fan_auto(1)){ // check print fan
  6507. case FanCheck::PrintFan:
  6508. _result = false;
  6509. break;
  6510. case FanCheck::SwappedFan:
  6511. _swapped_fan = true;
  6512. // FALLTHRU
  6513. default:
  6514. _result = true;
  6515. break;
  6516. }
  6517. #else //defined(TACH_1)
  6518. _result = lcd_selftest_manual_fan_check(1, false);
  6519. #endif //defined(TACH_1)
  6520. if (!_result)
  6521. {
  6522. lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning
  6523. }
  6524. }
  6525. if (_swapped_fan) {
  6526. //turn on print fan and check that left extruder fan is not spinning
  6527. _result = lcd_selftest_manual_fan_check(1, true);
  6528. if (_result) {
  6529. //print fan is stil turned on; check that it is spinning
  6530. _result = lcd_selftest_manual_fan_check(1, false, true);
  6531. if (!_result){
  6532. lcd_selftest_error(TestError::PrintFan, "", "");
  6533. }
  6534. }
  6535. else {
  6536. // fans are swapped
  6537. lcd_selftest_error(TestError::SwappedFan, "", "");
  6538. }
  6539. }
  6540. if (_result)
  6541. {
  6542. _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000);
  6543. _result = lcd_selfcheck_endstops(); //With TMC2130, only the Z probe is tested.
  6544. }
  6545. if (_result)
  6546. {
  6547. //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
  6548. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000);
  6549. #ifdef TMC2130
  6550. _result = lcd_selfcheck_axis_sg(X_AXIS);
  6551. #else
  6552. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  6553. #endif //TMC2130
  6554. }
  6555. if (_result)
  6556. {
  6557. _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0);
  6558. #ifndef TMC2130
  6559. _result = lcd_selfcheck_pulleys(X_AXIS);
  6560. #endif
  6561. }
  6562. if (_result)
  6563. {
  6564. _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500);
  6565. #ifdef TMC2130
  6566. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  6567. #else
  6568. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  6569. #endif // TMC2130
  6570. }
  6571. if (_result)
  6572. {
  6573. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0);
  6574. #ifndef TMC2130
  6575. _result = lcd_selfcheck_pulleys(Y_AXIS);
  6576. #endif // TMC2130
  6577. }
  6578. if (_result)
  6579. {
  6580. #ifdef TMC2130
  6581. tmc2130_home_exit();
  6582. enable_endstops(false);
  6583. #endif
  6584. //homeaxis(X_AXIS);
  6585. //homeaxis(Y_AXIS);
  6586. current_position[X_AXIS] = pgm_read_float(bed_ref_points_4);
  6587. current_position[Y_AXIS] = pgm_read_float(bed_ref_points_4+1);
  6588. #ifdef TMC2130
  6589. //current_position[X_AXIS] += 0;
  6590. current_position[Y_AXIS] += 4;
  6591. #endif //TMC2130
  6592. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6593. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6594. st_synchronize();
  6595. set_destination_to_current();
  6596. _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500);
  6597. #ifdef TMC2130
  6598. homeaxis(Z_AXIS); //In case of failure, the code gets stuck in this function.
  6599. #else
  6600. _result = lcd_selfcheck_axis(Z_AXIS, Z_MAX_POS);
  6601. #endif //TMC2130
  6602. //raise Z to not damage the bed during and hotend testing
  6603. current_position[Z_AXIS] += 20;
  6604. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6605. st_synchronize();
  6606. }
  6607. #ifdef TMC2130
  6608. if (_result)
  6609. {
  6610. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  6611. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6612. st_synchronize();
  6613. _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0);
  6614. bool bres = tmc2130_home_calibrate(X_AXIS);
  6615. _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0);
  6616. bres &= tmc2130_home_calibrate(Y_AXIS);
  6617. _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0);
  6618. if (bres)
  6619. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  6620. _result = bres;
  6621. }
  6622. #endif //TMC2130
  6623. if (_result)
  6624. {
  6625. _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000);
  6626. _result = lcd_selfcheck_check_heater(true);
  6627. }
  6628. if (_result)
  6629. {
  6630. _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000);
  6631. _result = lcd_selfcheck_check_heater(false);
  6632. }
  6633. if (_result)
  6634. {
  6635. _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok
  6636. }
  6637. #ifdef FILAMENT_SENSOR
  6638. if (_result)
  6639. {
  6640. if (mmu_enabled)
  6641. {
  6642. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6643. _result = selftest_irsensor();
  6644. if (_result)
  6645. {
  6646. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6647. }
  6648. } else
  6649. {
  6650. #ifdef PAT9125
  6651. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor
  6652. _result = lcd_selftest_fsensor();
  6653. if (_result)
  6654. {
  6655. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK
  6656. }
  6657. #endif //PAT9125
  6658. #if 0
  6659. // Intentionally disabled - that's why we moved the detection to runtime by just checking the two voltages.
  6660. // The idea is not to force the user to remove and insert the filament on an assembled printer.
  6661. //def IR_SENSOR_ANALOG
  6662. _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filament sensor
  6663. _result = lcd_selftest_IRsensor();
  6664. if (_result)
  6665. {
  6666. _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //filament sensor OK
  6667. }
  6668. #endif //IR_SENSOR_ANALOG
  6669. }
  6670. }
  6671. #endif //FILAMENT_SENSOR
  6672. if (_result)
  6673. {
  6674. _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct
  6675. }
  6676. else
  6677. {
  6678. _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000);
  6679. }
  6680. lcd_reset_alert_level();
  6681. enquecommand_P(PSTR("M84"));
  6682. lcd_update_enable(true);
  6683. if (_result)
  6684. {
  6685. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=20
  6686. }
  6687. else
  6688. {
  6689. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  6690. }
  6691. #ifdef TMC2130
  6692. FORCE_HIGH_POWER_END;
  6693. #endif // TMC2130
  6694. FORCE_BL_ON_END;
  6695. KEEPALIVE_STATE(NOT_BUSY);
  6696. return(_result);
  6697. }
  6698. #ifdef TMC2130
  6699. static void reset_crash_det(uint8_t axis) {
  6700. current_position[axis] += 10;
  6701. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6702. st_synchronize();
  6703. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  6704. }
  6705. static bool lcd_selfcheck_axis_sg(uint8_t axis) {
  6706. // each axis length is measured twice
  6707. float axis_length, current_position_init, current_position_final;
  6708. float measured_axis_length[2];
  6709. float margin = 60;
  6710. float max_error_mm = 5;
  6711. switch (axis) {
  6712. case 0: axis_length = X_MAX_POS; break;
  6713. case 1: axis_length = Y_MAX_POS + 8; break;
  6714. default: axis_length = 210; break;
  6715. }
  6716. tmc2130_sg_stop_on_crash = false;
  6717. tmc2130_home_exit();
  6718. enable_endstops(true);
  6719. raise_z_above(MESH_HOME_Z_SEARCH);
  6720. st_synchronize();
  6721. tmc2130_home_enter(1 << axis);
  6722. // first axis length measurement begin
  6723. current_position[axis] -= (axis_length + margin);
  6724. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6725. st_synchronize();
  6726. tmc2130_sg_meassure_start(axis);
  6727. current_position_init = st_get_position_mm(axis);
  6728. current_position[axis] += 2 * margin;
  6729. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6730. st_synchronize();
  6731. current_position[axis] += axis_length;
  6732. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6733. st_synchronize();
  6734. uint16_t sg1 = tmc2130_sg_meassure_stop();
  6735. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  6736. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  6737. current_position_final = st_get_position_mm(axis);
  6738. measured_axis_length[0] = fabs(current_position_final - current_position_init);
  6739. // first measurement end and second measurement begin
  6740. current_position[axis] -= margin;
  6741. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6742. st_synchronize();
  6743. current_position[axis] -= (axis_length + margin);
  6744. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6745. st_synchronize();
  6746. current_position_init = st_get_position_mm(axis);
  6747. measured_axis_length[1] = fabs(current_position_final - current_position_init);
  6748. tmc2130_home_exit();
  6749. //end of second measurement, now check for possible errors:
  6750. for(uint_least8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  6751. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  6752. if (fabs(measured_axis_length[i] - axis_length) > max_error_mm) {
  6753. enable_endstops(false);
  6754. const char *_error_1;
  6755. if (axis == X_AXIS) _error_1 = "X";
  6756. if (axis == Y_AXIS) _error_1 = "Y";
  6757. if (axis == Z_AXIS) _error_1 = "Z";
  6758. lcd_selftest_error(TestError::Axis, _error_1, "");
  6759. current_position[axis] = 0;
  6760. plan_set_position_curposXYZE();
  6761. reset_crash_det(axis);
  6762. enable_endstops(true);
  6763. endstops_hit_on_purpose();
  6764. return false;
  6765. }
  6766. }
  6767. printf_P(_N("Axis length difference:%.3f\n"), fabs(measured_axis_length[0] - measured_axis_length[1]));
  6768. if (fabs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  6769. //loose pulleys
  6770. const char *_error_1;
  6771. if (axis == X_AXIS) _error_1 = "X";
  6772. if (axis == Y_AXIS) _error_1 = "Y";
  6773. if (axis == Z_AXIS) _error_1 = "Z";
  6774. lcd_selftest_error(TestError::Pulley, _error_1, "");
  6775. current_position[axis] = 0;
  6776. plan_set_position_curposXYZE();
  6777. reset_crash_det(axis);
  6778. endstops_hit_on_purpose();
  6779. return false;
  6780. }
  6781. current_position[axis] = 0;
  6782. plan_set_position_curposXYZE();
  6783. reset_crash_det(axis);
  6784. endstops_hit_on_purpose();
  6785. return true;
  6786. }
  6787. #endif //TMC2130
  6788. #ifndef TMC2130
  6789. static bool lcd_selfcheck_axis(int _axis, int _travel)
  6790. {
  6791. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  6792. bool _stepdone = false;
  6793. bool _stepresult = false;
  6794. uint8_t _progress = 0;
  6795. int _travel_done = 0;
  6796. int _err_endstop = 0;
  6797. int _lcd_refresh = 0;
  6798. _travel = _travel + (_travel / 10);
  6799. if (_axis == X_AXIS) {
  6800. current_position[Z_AXIS] += 17;
  6801. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6802. }
  6803. do {
  6804. current_position[_axis] = current_position[_axis] - 1;
  6805. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6806. st_synchronize();
  6807. #ifdef TMC2130
  6808. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6809. #else //TMC2130
  6810. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  6811. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  6812. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  6813. #endif //TMC2130
  6814. {
  6815. if (_axis == 0)
  6816. {
  6817. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6818. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  6819. }
  6820. if (_axis == 1)
  6821. {
  6822. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6823. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  6824. }
  6825. if (_axis == 2)
  6826. {
  6827. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  6828. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  6829. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  6830. /*disable_x();
  6831. disable_y();
  6832. disable_z();*/
  6833. }
  6834. _stepdone = true;
  6835. }
  6836. if (_lcd_refresh < 6)
  6837. {
  6838. _lcd_refresh++;
  6839. }
  6840. else
  6841. {
  6842. _progress = lcd_selftest_screen(static_cast<TestScreen>(static_cast<int>(TestScreen::AxisX) + _axis), _progress, 3, false, 0);
  6843. _lcd_refresh = 0;
  6844. }
  6845. manage_heater();
  6846. manage_inactivity(true);
  6847. //_delay(100);
  6848. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  6849. } while (!_stepdone);
  6850. //current_position[_axis] = current_position[_axis] + 15;
  6851. //plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder);
  6852. if (!_stepresult)
  6853. {
  6854. const char *_error_1;
  6855. const char *_error_2;
  6856. if (_axis == X_AXIS) _error_1 = "X";
  6857. if (_axis == Y_AXIS) _error_1 = "Y";
  6858. if (_axis == Z_AXIS) _error_1 = "Z";
  6859. if (_err_endstop == 0) _error_2 = "X";
  6860. if (_err_endstop == 1) _error_2 = "Y";
  6861. if (_err_endstop == 2) _error_2 = "Z";
  6862. if (_travel_done >= _travel)
  6863. {
  6864. lcd_selftest_error(TestError::Endstop, _error_1, _error_2);
  6865. }
  6866. else
  6867. {
  6868. lcd_selftest_error(TestError::Motor, _error_1, _error_2);
  6869. }
  6870. }
  6871. current_position[_axis] = 0; //simulate axis home to avoid negative numbers for axis position, especially Z.
  6872. plan_set_position_curposXYZE();
  6873. return _stepresult;
  6874. }
  6875. static bool lcd_selfcheck_pulleys(int axis)
  6876. {
  6877. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  6878. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  6879. float current_position_init;
  6880. float move;
  6881. bool endstop_triggered = false;
  6882. int i;
  6883. unsigned long timeout_counter;
  6884. refresh_cmd_timeout();
  6885. manage_inactivity(true);
  6886. if (axis == 0) move = 50; //X_AXIS
  6887. else move = 50; //Y_AXIS
  6888. current_position_init = current_position[axis];
  6889. current_position[axis] += 2;
  6890. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6891. for (i = 0; i < 5; i++) {
  6892. refresh_cmd_timeout();
  6893. current_position[axis] = current_position[axis] + move;
  6894. st_current_set(0, 850); //set motor current higher
  6895. plan_buffer_line_curposXYZE(200);
  6896. st_synchronize();
  6897. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  6898. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  6899. current_position[axis] = current_position[axis] - move;
  6900. plan_buffer_line_curposXYZE(50);
  6901. st_synchronize();
  6902. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6903. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6904. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6905. return(false);
  6906. }
  6907. }
  6908. timeout_counter = _millis() + 2500;
  6909. endstop_triggered = false;
  6910. manage_inactivity(true);
  6911. while (!endstop_triggered) {
  6912. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6913. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  6914. endstop_triggered = true;
  6915. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  6916. current_position[axis] += 10;
  6917. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6918. st_synchronize();
  6919. return(true);
  6920. }
  6921. else {
  6922. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6923. return(false);
  6924. }
  6925. }
  6926. else {
  6927. current_position[axis] -= 1;
  6928. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6929. st_synchronize();
  6930. if (_millis() > timeout_counter) {
  6931. lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", "");
  6932. return(false);
  6933. }
  6934. }
  6935. }
  6936. return(true);
  6937. }
  6938. #endif //not defined TMC2130
  6939. static bool lcd_selfcheck_endstops()
  6940. {
  6941. bool _result = true;
  6942. if (
  6943. #ifndef TMC2130
  6944. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6945. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6946. #endif //!TMC2130
  6947. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6948. {
  6949. #ifndef TMC2130
  6950. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  6951. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  6952. #endif //!TMC2130
  6953. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  6954. }
  6955. plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
  6956. st_synchronize();
  6957. if (
  6958. #ifndef TMC2130
  6959. ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  6960. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  6961. #endif //!TMC2130
  6962. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  6963. {
  6964. _result = false;
  6965. char _error[4] = "";
  6966. #ifndef TMC2130
  6967. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  6968. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  6969. #endif //!TMC2130
  6970. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  6971. lcd_selftest_error(TestError::Endstops, _error, "");
  6972. }
  6973. manage_heater();
  6974. manage_inactivity(true);
  6975. return _result;
  6976. }
  6977. static bool lcd_selfcheck_check_heater(bool _isbed)
  6978. {
  6979. uint8_t _counter = 0;
  6980. uint8_t _progress = 0;
  6981. bool _stepresult = false;
  6982. bool _docycle = true;
  6983. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  6984. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  6985. uint8_t _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  6986. target_temperature[0] = (_isbed) ? 0 : 200;
  6987. target_temperature_bed = (_isbed) ? 100 : 0;
  6988. manage_heater();
  6989. manage_inactivity(true);
  6990. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  6991. do {
  6992. _counter++;
  6993. _docycle = (_counter < _cycles) ? true : false;
  6994. manage_heater();
  6995. manage_inactivity(true);
  6996. _progress = (_isbed) ? lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) : lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400);
  6997. /*if (_isbed) {
  6998. MYSERIAL.print("Bed temp:");
  6999. MYSERIAL.println(degBed());
  7000. }
  7001. else {
  7002. MYSERIAL.print("Hotend temp:");
  7003. MYSERIAL.println(degHotend(0));
  7004. }*/
  7005. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  7006. } while (_docycle);
  7007. target_temperature[0] = 0;
  7008. target_temperature_bed = 0;
  7009. manage_heater();
  7010. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  7011. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  7012. /*
  7013. MYSERIAL.println("");
  7014. MYSERIAL.print("Checked result:");
  7015. MYSERIAL.println(_checked_result);
  7016. MYSERIAL.print("Opposite result:");
  7017. MYSERIAL.println(_opposite_result);
  7018. */
  7019. if (_opposite_result < ((_isbed) ? 30 : 9))
  7020. {
  7021. if (_checked_result >= ((_isbed) ? 9 : 30))
  7022. {
  7023. _stepresult = true;
  7024. }
  7025. else
  7026. {
  7027. lcd_selftest_error(TestError::Heater, "", "");
  7028. }
  7029. }
  7030. else
  7031. {
  7032. lcd_selftest_error(TestError::Bed, "", "");
  7033. }
  7034. manage_heater();
  7035. manage_inactivity(true);
  7036. KEEPALIVE_STATE(IN_HANDLER);
  7037. return _stepresult;
  7038. }
  7039. static void lcd_selftest_error(TestError testError, const char *_error_1, const char *_error_2)
  7040. {
  7041. lcd_beeper_quick_feedback();
  7042. FORCE_BL_ON_END;
  7043. target_temperature[0] = 0;
  7044. target_temperature_bed = 0;
  7045. manage_heater();
  7046. manage_inactivity();
  7047. lcd_clear();
  7048. lcd_puts_at_P(0, 0, _i("Selftest error!"));////MSG_SELFTEST_ERROR c=20
  7049. lcd_puts_at_P(0, 1, _i("Please check:"));////MSG_SELFTEST_PLEASECHECK c=20
  7050. switch (testError)
  7051. {
  7052. case TestError::Heater:
  7053. lcd_puts_at_P(0, 2, _i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=20
  7054. lcd_puts_at_P(0, 3, _i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=20
  7055. break;
  7056. case TestError::Bed:
  7057. lcd_puts_at_P(0, 2, _i("Bed/Heater"));////MSG_SELFTEST_BEDHEATER c=20
  7058. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7059. break;
  7060. case TestError::Endstops:
  7061. lcd_puts_at_P(0, 2, _i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=20
  7062. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7063. lcd_set_cursor(18, 3);
  7064. lcd_print(_error_1);
  7065. break;
  7066. case TestError::Motor:
  7067. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_MOTOR));
  7068. lcd_set_cursor(18, 2);
  7069. lcd_print(_error_1);
  7070. lcd_puts_at_P(0, 3, _i("Endstop"));////MSG_SELFTEST_ENDSTOP c=16
  7071. lcd_set_cursor(18, 3);
  7072. lcd_print(_error_2);
  7073. break;
  7074. case TestError::Endstop:
  7075. lcd_puts_at_P(0, 2, _i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20
  7076. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7077. lcd_set_cursor(18, 3);
  7078. lcd_print(_error_1);
  7079. break;
  7080. case TestError::PrintFan:
  7081. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_COOLING_FAN));
  7082. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7083. lcd_set_cursor(18, 3);
  7084. lcd_print(_error_1);
  7085. break;
  7086. case TestError::ExtruderFan:
  7087. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_EXTRUDER_FAN));
  7088. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7089. lcd_set_cursor(18, 3);
  7090. lcd_print(_error_1);
  7091. break;
  7092. case TestError::Pulley:
  7093. lcd_puts_at_P(0, 2, _i("Loose pulley"));////MSG_LOOSE_PULLEY c=20
  7094. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_MOTOR));
  7095. lcd_set_cursor(18, 3);
  7096. lcd_print(_error_1);
  7097. break;
  7098. case TestError::Axis:
  7099. lcd_puts_at_P(0, 2, _i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=20
  7100. lcd_puts_at_P(0, 3, _i("Axis"));////MSG_SELFTEST_AXIS c=16
  7101. lcd_set_cursor(18, 3);
  7102. lcd_print(_error_1);
  7103. break;
  7104. case TestError::SwappedFan:
  7105. lcd_puts_at_P(0, 2, _i("Front/left fans"));////MSG_SELFTEST_FANS c=20
  7106. lcd_puts_at_P(0, 3, _i("Swapped"));////MSG_SELFTEST_SWAPPED c=16
  7107. lcd_set_cursor(18, 3);
  7108. lcd_print(_error_1);
  7109. break;
  7110. case TestError::WiringFsensor:
  7111. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7112. lcd_puts_at_P(0, 3, _T(MSG_SELFTEST_WIRINGERROR));
  7113. break;
  7114. case TestError::TriggeringFsensor:
  7115. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7116. lcd_puts_at_P(0, 3, _i("False triggering"));////MSG_FALSE_TRIGGERING c=20
  7117. break;
  7118. case TestError::FsensorLevel:
  7119. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7120. lcd_set_cursor(0, 3);
  7121. lcd_printf_P(_i("%s level expected"),_error_1);////MSG_SELFTEST_FS_LEVEL c=20
  7122. break;
  7123. }
  7124. _delay(1000);
  7125. lcd_beeper_quick_feedback();
  7126. do {
  7127. _delay(100);
  7128. manage_heater();
  7129. manage_inactivity();
  7130. } while (!lcd_clicked());
  7131. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  7132. lcd_return_to_status();
  7133. }
  7134. #ifdef FILAMENT_SENSOR
  7135. #ifdef PAT9125
  7136. static bool lcd_selftest_fsensor(void)
  7137. {
  7138. fsensor_init();
  7139. if (fsensor_not_responding)
  7140. {
  7141. lcd_selftest_error(TestError::WiringFsensor, "", "");
  7142. }
  7143. return (!fsensor_not_responding);
  7144. }
  7145. #endif //PAT9125
  7146. //! @brief Self-test of infrared barrier filament sensor mounted on MK3S with MMUv2 printer
  7147. //!
  7148. //! Test whether sensor is not triggering filament presence when extruder idler is moving without filament.
  7149. //!
  7150. //! Steps:
  7151. //! * Backup current active extruder temperature
  7152. //! * Pre-heat to PLA extrude temperature.
  7153. //! * Unload filament possibly present.
  7154. //! * Move extruder idler same way as during filament load
  7155. //! and sample IR_SENSOR_PIN.
  7156. //! * Check that pin doesn't go low.
  7157. //!
  7158. //! @retval true passed
  7159. //! @retval false failed
  7160. static bool selftest_irsensor()
  7161. {
  7162. class TempBackup
  7163. {
  7164. public:
  7165. TempBackup():
  7166. m_temp(degTargetHotend(active_extruder)),
  7167. m_extruder(active_extruder){}
  7168. ~TempBackup(){setTargetHotend(m_temp,m_extruder);}
  7169. private:
  7170. float m_temp;
  7171. uint8_t m_extruder;
  7172. };
  7173. uint8_t progress;
  7174. {
  7175. TempBackup tempBackup;
  7176. setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder);
  7177. mmu_wait_for_heater_blocking();
  7178. progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0);
  7179. mmu_filament_ramming();
  7180. }
  7181. progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7182. mmu_command(MmuCmd::U0);
  7183. manage_response(false, false);
  7184. for(uint_least8_t i = 0; i < 200; ++i)
  7185. {
  7186. if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0);
  7187. mmu_load_step(false);
  7188. while (blocks_queued())
  7189. {
  7190. if (READ(IR_SENSOR_PIN) == 0)
  7191. {
  7192. lcd_selftest_error(TestError::TriggeringFsensor, "", "");
  7193. return false;
  7194. }
  7195. #ifdef TMC2130
  7196. manage_heater();
  7197. // Vojtech: Don't disable motors inside the planner!
  7198. if (!tmc2130_update_sg())
  7199. {
  7200. manage_inactivity(true);
  7201. }
  7202. #else //TMC2130
  7203. manage_heater();
  7204. // Vojtech: Don't disable motors inside the planner!
  7205. manage_inactivity(true);
  7206. #endif //TMC2130
  7207. }
  7208. }
  7209. return true;
  7210. }
  7211. #endif //FILAMENT_SENSOR
  7212. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite,
  7213. bool _default)
  7214. {
  7215. bool _result = check_opposite;
  7216. lcd_clear();
  7217. lcd_puts_at_P(0, 0, _T(MSG_SELFTEST_FAN));
  7218. switch (_fan)
  7219. {
  7220. case 0:
  7221. // extruder cooling fan
  7222. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_COOLING_FAN) : _T(MSG_SELFTEST_EXTRUDER_FAN));
  7223. setExtruderAutoFanState(3);
  7224. break;
  7225. case 1:
  7226. // object cooling fan
  7227. lcd_puts_at_P(0, 1, check_opposite ? _T(MSG_SELFTEST_EXTRUDER_FAN) : _T(MSG_SELFTEST_COOLING_FAN));
  7228. SET_OUTPUT(FAN_PIN);
  7229. #ifdef FAN_SOFT_PWM
  7230. fanSpeedSoftPwm = 255;
  7231. #else //FAN_SOFT_PWM
  7232. analogWrite(FAN_PIN, 255);
  7233. #endif //FAN_SOFT_PWM
  7234. break;
  7235. }
  7236. _delay(500);
  7237. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7238. lcd_putc_at(0, 3, '>');
  7239. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7240. int8_t enc_dif = int(_default)*3;
  7241. KEEPALIVE_STATE(PAUSED_FOR_USER);
  7242. lcd_button_pressed = false;
  7243. do
  7244. {
  7245. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  7246. if (enc_dif > lcd_encoder_diff) {
  7247. _result = !check_opposite;
  7248. lcd_putc_at(0, 2, '>');
  7249. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7250. lcd_putc_at(0, 3, ' ');
  7251. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7252. }
  7253. if (enc_dif < lcd_encoder_diff) {
  7254. _result = check_opposite;
  7255. lcd_putc_at(0, 2, ' ');
  7256. lcd_puts_at_P(1, 2, _T(MSG_SELFTEST_FAN_YES));
  7257. lcd_putc_at(0, 3, '>');
  7258. lcd_puts_at_P(1, 3, _T(MSG_SELFTEST_FAN_NO));
  7259. }
  7260. enc_dif = 0;
  7261. lcd_encoder_diff = 0;
  7262. }
  7263. manage_heater();
  7264. _delay(100);
  7265. } while (!lcd_clicked());
  7266. KEEPALIVE_STATE(IN_HANDLER);
  7267. setExtruderAutoFanState(0);
  7268. SET_OUTPUT(FAN_PIN);
  7269. #ifdef FAN_SOFT_PWM
  7270. fanSpeedSoftPwm = 0;
  7271. #else //FAN_SOFT_PWM
  7272. analogWrite(FAN_PIN, 0);
  7273. #endif //FAN_SOFT_PWM
  7274. fanSpeed = 0;
  7275. manage_heater();
  7276. return _result;
  7277. }
  7278. #ifdef FANCHECK
  7279. static FanCheck lcd_selftest_fan_auto(int _fan)
  7280. {
  7281. switch (_fan) {
  7282. case 0:
  7283. fanSpeed = 0;
  7284. manage_heater(); //turn off fan
  7285. setExtruderAutoFanState(3); //extruder fan
  7286. #ifdef FAN_SOFT_PWM
  7287. extruder_autofan_last_check = _millis();
  7288. fan_measuring = true;
  7289. #endif //FAN_SOFT_PWM
  7290. _delay(2000);
  7291. setExtruderAutoFanState(0); //extruder fan
  7292. manage_heater(); //count average fan speed from 2s delay and turn off fans
  7293. puts_P(PSTR("Test 1:"));
  7294. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7295. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7296. if (fan_speed[0] < 20) { // < 1200 RPM would mean either a faulty Noctua or Altfan
  7297. return FanCheck::ExtruderFan;
  7298. }
  7299. #ifdef FAN_SOFT_PWM
  7300. else if (fan_speed[0] > 50 ) { // printerFan is faster
  7301. return FanCheck::SwappedFan;
  7302. }
  7303. break;
  7304. #endif
  7305. case 1:
  7306. //will it work with Thotend > 50 C ?
  7307. #ifdef FAN_SOFT_PWM
  7308. fanSpeed = 255;
  7309. fanSpeedSoftPwm = 255;
  7310. extruder_autofan_last_check = _millis(); //store time when measurement starts
  7311. fan_measuring = true; //start fan measuring, rest is on manage_heater
  7312. #else //FAN_SOFT_PWM
  7313. fanSpeed = 150; //print fan
  7314. #endif //FAN_SOFT_PWM
  7315. for (uint8_t i = 0; i < 5; i++) {
  7316. delay_keep_alive(1000);
  7317. lcd_putc_at(18, 3, '-');
  7318. delay_keep_alive(1000);
  7319. lcd_putc_at(18, 3, '|');
  7320. }
  7321. fanSpeed = 0;
  7322. #ifdef FAN_SOFT_PWM
  7323. fanSpeedSoftPwm = 0;
  7324. #else //FAN_SOFT_PWM
  7325. manage_heater(); //turn off fan
  7326. manage_inactivity(true); //to turn off print fan
  7327. #endif //FAN_SOFT_PWM
  7328. puts_P(PSTR("Test 2:"));
  7329. printf_P(PSTR("Print fan speed: %d\n"), fan_speed[1]);
  7330. printf_P(PSTR("Extr fan speed: %d\n"), fan_speed[0]);
  7331. if (!fan_speed[1]) {
  7332. return FanCheck::PrintFan;
  7333. }
  7334. #ifdef FAN_SOFT_PWM
  7335. fanSpeed = 80;
  7336. fanSpeedSoftPwm = 80;
  7337. for (uint8_t i = 0; i < 5; i++) {
  7338. delay_keep_alive(1000);
  7339. lcd_putc_at(18, 3, '-');
  7340. delay_keep_alive(1000);
  7341. lcd_putc_at(18, 3, '|');
  7342. }
  7343. fanSpeed = 0;
  7344. // noctua speed is between 17 and 24, turbine more then 30
  7345. if (fan_speed[1] < 30) {
  7346. return FanCheck::SwappedFan;
  7347. }
  7348. #else
  7349. // fan is spinning, but measured RPM are too low for print fan, it must
  7350. // be left extruder fan
  7351. else if (fan_speed[1] < 34) {
  7352. return FanCheck::SwappedFan;
  7353. }
  7354. #endif //FAN_SOFT_PWM
  7355. break;
  7356. }
  7357. return FanCheck::Success;
  7358. }
  7359. #endif //FANCHECK
  7360. static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay)
  7361. {
  7362. lcd_update_enable(false);
  7363. const char *_indicator = (_progress >= _progress_scale) ? "-" : "|";
  7364. if (_clear) lcd_clear();
  7365. lcd_set_cursor(0, 0);
  7366. if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7367. if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7368. if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  7369. if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20
  7370. if (screen == TestScreen::AxisX) lcd_puts_P(_T(MSG_CHECKING_X));
  7371. if (screen == TestScreen::AxisY) lcd_puts_P(_T(MSG_CHECKING_Y));
  7372. if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis"));////MSG_SELFTEST_CHECK_Z c=20
  7373. if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  7374. if (screen == TestScreen::Hotend
  7375. || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend"));////MSG_SELFTEST_CHECK_HOTEND c=20
  7376. if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7377. if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  7378. if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct"));////MSG_SELFTEST_CHECK_ALLCORRECT c=20
  7379. if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  7380. if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////MSG_CALIBRATING_HOME c=20
  7381. lcd_puts_at_P(0, 1, separator);
  7382. if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk))
  7383. {
  7384. //SERIAL_ECHOLNPGM("Fan test");
  7385. lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18
  7386. lcd_set_cursor(18, 2);
  7387. (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK");
  7388. lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18
  7389. lcd_set_cursor(18, 3);
  7390. (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK");
  7391. }
  7392. else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk)
  7393. {
  7394. lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR));
  7395. lcd_putc(':');
  7396. lcd_set_cursor(18, 2);
  7397. (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK");
  7398. }
  7399. else if (screen < TestScreen::Fsensor)
  7400. {
  7401. //SERIAL_ECHOLNPGM("Other tests");
  7402. TestScreen _step_block = TestScreen::AxisX;
  7403. lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("X"), _indicator);
  7404. _step_block = TestScreen::AxisY;
  7405. lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Y"), _indicator);
  7406. _step_block = TestScreen::AxisZ;
  7407. lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Z"), _indicator);
  7408. _step_block = TestScreen::Bed;
  7409. lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Bed"), _indicator);
  7410. _step_block = TestScreen::Hotend;
  7411. lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), PSTR("Hotend"), _indicator);
  7412. }
  7413. if (_delay > 0) delay_keep_alive(_delay);
  7414. _progress++;
  7415. return (_progress >= _progress_scale * 2) ? 0 : _progress;
  7416. }
  7417. static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name_PROGMEM, const char *_indicator)
  7418. {
  7419. lcd_set_cursor(_col, _row);
  7420. uint8_t strlenNameP = strlen_P(_name_PROGMEM);
  7421. switch (_state)
  7422. {
  7423. case 1:
  7424. lcd_puts_P(_name_PROGMEM);
  7425. lcd_putc_at(_col + strlenNameP, _row, ':');
  7426. lcd_set_cursor(_col + strlenNameP + 1, _row);
  7427. lcd_print(_indicator);
  7428. break;
  7429. case 2:
  7430. lcd_puts_P(_name_PROGMEM);
  7431. lcd_putc_at(_col + strlenNameP, _row, ':');
  7432. lcd_puts_at_P(_col + strlenNameP + 1, _row, PSTR("OK"));
  7433. break;
  7434. default:
  7435. lcd_puts_P(_name_PROGMEM);
  7436. }
  7437. }
  7438. /** End of menus **/
  7439. /** Menu action functions **/
  7440. static bool check_file(const char* filename) {
  7441. if (farm_mode) return true;
  7442. card.openFileReadFilteredGcode(filename, true);
  7443. bool result = false;
  7444. const uint32_t filesize = card.getFileSize();
  7445. uint32_t startPos = 0;
  7446. const uint16_t bytesToCheck = min(END_FILE_SECTION, filesize);
  7447. if (filesize > END_FILE_SECTION) {
  7448. startPos = filesize - END_FILE_SECTION;
  7449. card.setIndex(startPos);
  7450. }
  7451. cmdqueue_reset();
  7452. cmdqueue_serial_disabled = true;
  7453. menu_progressbar_init(bytesToCheck, _i("Checking file"));////MSG_CHECKING_FILE c=17
  7454. while (!card.eof() && !result) {
  7455. menu_progressbar_update(card.get_sdpos() - startPos);
  7456. card.sdprinting = true;
  7457. get_command();
  7458. result = check_commands();
  7459. }
  7460. menu_progressbar_finish();
  7461. cmdqueue_serial_disabled = false;
  7462. card.printingHasFinished();
  7463. lcd_setstatuspgm(MSG_WELCOME);
  7464. lcd_finishstatus();
  7465. return result;
  7466. }
  7467. static void menu_action_sdfile(const char* filename)
  7468. {
  7469. loading_flag = false;
  7470. char cmd[30];
  7471. char* c;
  7472. bool result = true;
  7473. sprintf_P(cmd, PSTR("M23 %s"), filename);
  7474. for (c = &cmd[4]; *c; c++)
  7475. *c = tolower(*c);
  7476. const char end[5] = ".gco";
  7477. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  7478. for (uint_least8_t i = 0; i < 8; i++) {
  7479. if (strcmp((cmd + i + 4), end) == 0) {
  7480. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  7481. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  7482. break;
  7483. }
  7484. else {
  7485. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  7486. }
  7487. }
  7488. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  7489. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  7490. for (uint_least8_t i = 0; i < depth; i++) {
  7491. for (uint_least8_t j = 0; j < 8; j++) {
  7492. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, card.dir_names[i][j]);
  7493. }
  7494. }
  7495. //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
  7496. //to open a file. Instead, the cached filename in cmd is used as that one is static for the whole lifetime of this function.
  7497. if (!check_file(cmd + 4)) {
  7498. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=3
  7499. lcd_update_enable(true);
  7500. }
  7501. if (result) {
  7502. enquecommand(cmd);
  7503. enquecommand_P(PSTR("M24"));
  7504. }
  7505. lcd_return_to_status();
  7506. }
  7507. void menu_action_sddirectory(const char* filename)
  7508. {
  7509. card.chdir(filename, true);
  7510. lcd_encoder = 0;
  7511. menu_data_reset(); //Forces reloading of cached variables.
  7512. }
  7513. /** LCD API **/
  7514. void ultralcd_init()
  7515. {
  7516. {
  7517. uint8_t autoDepleteRaw = eeprom_read_byte(reinterpret_cast<uint8_t*>(EEPROM_AUTO_DEPLETE));
  7518. if (0xff == autoDepleteRaw) lcd_autoDeplete = false;
  7519. else lcd_autoDeplete = autoDepleteRaw;
  7520. }
  7521. backlight_init();
  7522. lcd_init();
  7523. lcd_refresh();
  7524. lcd_longpress_func = menu_lcd_longpress_func;
  7525. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  7526. menu_menu = lcd_status_screen;
  7527. SET_INPUT(BTN_EN1);
  7528. SET_INPUT(BTN_EN2);
  7529. WRITE(BTN_EN1, HIGH);
  7530. WRITE(BTN_EN2, HIGH);
  7531. #if BTN_ENC > 0
  7532. SET_INPUT(BTN_ENC);
  7533. WRITE(BTN_ENC, HIGH);
  7534. #endif
  7535. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  7536. SET_INPUT(SDCARDDETECT);
  7537. WRITE(SDCARDDETECT, HIGH);
  7538. lcd_oldcardstatus = IS_SD_INSERTED;
  7539. #endif//(SDCARDDETECT > 0)
  7540. lcd_encoder_diff = 0;
  7541. }
  7542. void lcd_printer_connected() {
  7543. printer_connected = true;
  7544. }
  7545. static void lcd_send_status() {
  7546. if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) {
  7547. //send important status messages periodicaly
  7548. prusa_statistics(important_status, saved_filament_type);
  7549. NcTime.start();
  7550. #ifdef FARM_CONNECT_MESSAGE
  7551. lcd_connect_printer();
  7552. #endif //FARM_CONNECT_MESSAGE
  7553. }
  7554. }
  7555. #ifdef FARM_CONNECT_MESSAGE
  7556. static void lcd_connect_printer() {
  7557. lcd_update_enable(false);
  7558. lcd_clear();
  7559. int i = 0;
  7560. int t = 0;
  7561. lcd_puts_at_P(0, 0, _i("Connect printer to"));
  7562. lcd_puts_at_P(0, 1, _i("monitoring or hold"));
  7563. lcd_puts_at_P(0, 2, _i("the knob to continue"));
  7564. while (no_response) {
  7565. i++;
  7566. t++;
  7567. delay_keep_alive(100);
  7568. proc_commands();
  7569. if (t == 10) {
  7570. prusa_statistics(important_status, saved_filament_type);
  7571. t = 0;
  7572. }
  7573. if (READ(BTN_ENC)) { //if button is not pressed
  7574. i = 0;
  7575. lcd_puts_at_P(0, 3, PSTR(" "));
  7576. }
  7577. if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, LCD_STR_SOLID_BLOCK[0]);
  7578. if (i == NC_BUTTON_LONG_PRESS * 10) {
  7579. no_response = false;
  7580. }
  7581. }
  7582. lcd_update_enable(true);
  7583. lcd_update(2);
  7584. }
  7585. #endif //FARM_CONNECT_MESSAGE
  7586. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  7587. if (farm_mode) {
  7588. bool empty = cmd_buffer_empty();
  7589. if ((_millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  7590. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  7591. //therefore longer period is used
  7592. printer_connected = false;
  7593. }
  7594. else {
  7595. lcd_printer_connected();
  7596. }
  7597. }
  7598. }
  7599. void lcd_ignore_click(bool b)
  7600. {
  7601. ignore_click = b;
  7602. wait_for_unclick = false;
  7603. }
  7604. void lcd_finishstatus() {
  7605. SERIAL_PROTOCOLLNRPGM(MSG_LCD_STATUS_CHANGED);
  7606. int len = strlen(lcd_status_message);
  7607. if (len > 0) {
  7608. while (len < LCD_WIDTH) {
  7609. lcd_status_message[len++] = ' ';
  7610. }
  7611. }
  7612. lcd_status_message[LCD_WIDTH] = '\0';
  7613. lcd_draw_update = 2;
  7614. }
  7615. void lcd_setstatus(const char* message)
  7616. {
  7617. if (lcd_status_message_level > 0)
  7618. return;
  7619. lcd_updatestatus(message);
  7620. }
  7621. void lcd_updatestatuspgm(const char *message){
  7622. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  7623. lcd_status_message[LCD_WIDTH] = 0;
  7624. lcd_finishstatus();
  7625. // hack lcd_draw_update to 1, i.e. without clear
  7626. lcd_draw_update = 1;
  7627. }
  7628. void lcd_setstatuspgm(const char* message)
  7629. {
  7630. if (lcd_status_message_level > 0)
  7631. return;
  7632. lcd_updatestatuspgm(message);
  7633. }
  7634. void lcd_updatestatus(const char *message){
  7635. strncpy(lcd_status_message, message, LCD_WIDTH);
  7636. lcd_status_message[LCD_WIDTH] = 0;
  7637. lcd_finishstatus();
  7638. // hack lcd_draw_update to 1, i.e. without clear
  7639. lcd_draw_update = 1;
  7640. }
  7641. void lcd_setalertstatuspgm(const char* message, uint8_t severity)
  7642. {
  7643. if (severity > lcd_status_message_level) {
  7644. lcd_updatestatuspgm(message);
  7645. lcd_status_message_level = severity;
  7646. lcd_return_to_status();
  7647. }
  7648. }
  7649. void lcd_setalertstatus(const char* message, uint8_t severity)
  7650. {
  7651. if (severity > lcd_status_message_level) {
  7652. lcd_updatestatus(message);
  7653. lcd_status_message_level = severity;
  7654. lcd_return_to_status();
  7655. }
  7656. }
  7657. void lcd_reset_alert_level()
  7658. {
  7659. lcd_status_message_level = 0;
  7660. }
  7661. uint8_t get_message_level()
  7662. {
  7663. return lcd_status_message_level;
  7664. }
  7665. void menu_lcd_longpress_func(void)
  7666. {
  7667. backlight_wake();
  7668. if (homing_flag || mesh_bed_leveling_flag || menu_menu == lcd_babystep_z || menu_menu == lcd_move_z)
  7669. {
  7670. // disable longpress during re-entry, while homing or calibration
  7671. lcd_quick_feedback();
  7672. return;
  7673. }
  7674. if (menu_menu == lcd_hw_setup_menu)
  7675. {
  7676. // only toggle the experimental menu visibility flag
  7677. lcd_quick_feedback();
  7678. lcd_experimental_toggle();
  7679. return;
  7680. }
  7681. // explicitely listed menus which are allowed to rise the move-z or live-adj-z functions
  7682. // The lists are not the same for both functions, so first decide which function is to be performed
  7683. if ( (moves_planned() || IS_SD_PRINTING || usb_timer.running() )){ // long press as live-adj-z
  7684. if(( current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU ) // only allow live-adj-z up to 2mm of print height
  7685. && ( menu_menu == lcd_status_screen // and in listed menus...
  7686. || menu_menu == lcd_main_menu
  7687. || menu_menu == lcd_tune_menu
  7688. || menu_menu == lcd_support_menu
  7689. )
  7690. ){
  7691. lcd_clear();
  7692. menu_submenu(lcd_babystep_z);
  7693. } else {
  7694. // otherwise consume the long press as normal click
  7695. if( menu_menu != lcd_status_screen )
  7696. menu_back();
  7697. }
  7698. } else { // long press as move-z
  7699. if(menu_menu == lcd_status_screen
  7700. || menu_menu == lcd_main_menu
  7701. || menu_menu == lcd_preheat_menu
  7702. || menu_menu == lcd_sdcard_menu
  7703. || menu_menu == lcd_settings_menu
  7704. || menu_menu == lcd_control_temperature_menu
  7705. #if (LANG_MODE != 0)
  7706. || menu_menu == lcd_language
  7707. #endif
  7708. || menu_menu == lcd_support_menu
  7709. ){
  7710. menu_submenu(lcd_move_z);
  7711. } else {
  7712. // otherwise consume the long press as normal click
  7713. if( menu_menu != lcd_status_screen )
  7714. menu_back();
  7715. }
  7716. }
  7717. }
  7718. static inline bool z_menu_expired()
  7719. {
  7720. return (menu_menu == lcd_babystep_z
  7721. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  7722. }
  7723. static inline bool other_menu_expired()
  7724. {
  7725. return (menu_menu != lcd_status_screen
  7726. && menu_menu != lcd_babystep_z
  7727. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  7728. }
  7729. static inline bool forced_menu_expire()
  7730. {
  7731. bool retval = (menu_menu != lcd_status_screen
  7732. && forceMenuExpire);
  7733. forceMenuExpire = false;
  7734. return retval;
  7735. }
  7736. void menu_lcd_lcdupdate_func(void)
  7737. {
  7738. #if (SDCARDDETECT > 0)
  7739. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  7740. {
  7741. if(menu_menu == lcd_sdcard_menu) {
  7742. // If the user is either inside the submenus
  7743. // 1. 'Print from SD' --> and SD card is removed
  7744. // 2. 'No SD card' --> and SD card is inserted
  7745. //
  7746. // 1. 'Print from SD': We want to back out of this submenu
  7747. // and instead show the submenu title 'No SD card'.
  7748. //
  7749. // 2. 'No SD card': When the user inserts the SD card we want
  7750. // to back out of this submenu. Not only to show
  7751. // 'Print from SD' submenu title but also because the user
  7752. // will be prompted with another menu with the sorted list of files.
  7753. // Without backing out of the menu, the list will appear empty and
  7754. // The user will need to back out of two nested submenus.
  7755. menu_back();
  7756. }
  7757. lcd_draw_update = 2;
  7758. lcd_oldcardstatus = IS_SD_INSERTED;
  7759. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  7760. backlight_wake();
  7761. if (lcd_oldcardstatus)
  7762. {
  7763. if (!card.cardOK)
  7764. {
  7765. card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back()
  7766. card.presort_flag = true; //force sorting of the SD menu
  7767. }
  7768. LCD_MESSAGERPGM(MSG_WELCOME);
  7769. bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function
  7770. menu_submenu(lcd_sdcard_menu);
  7771. lcd_timeoutToStatus.start();
  7772. }
  7773. else
  7774. {
  7775. card.release();
  7776. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=20
  7777. }
  7778. }
  7779. #endif//CARDINSERTED
  7780. backlight_update();
  7781. if (lcd_next_update_millis < _millis())
  7782. {
  7783. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  7784. {
  7785. if (lcd_draw_update == 0)
  7786. lcd_draw_update = 1;
  7787. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  7788. Sound_MakeSound(e_SOUND_TYPE_EncoderMove);
  7789. lcd_encoder_diff = 0;
  7790. lcd_timeoutToStatus.start();
  7791. backlight_wake();
  7792. }
  7793. if (LCD_CLICKED)
  7794. {
  7795. lcd_timeoutToStatus.start();
  7796. backlight_wake();
  7797. }
  7798. (*menu_menu)();
  7799. if (z_menu_expired() || other_menu_expired() || forced_menu_expire())
  7800. {
  7801. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  7802. // to give it a chance to save its state.
  7803. // This is useful for example, when the babystep value has to be written into EEPROM.
  7804. if (menu_menu != NULL)
  7805. {
  7806. menu_leaving = 1;
  7807. (*menu_menu)();
  7808. menu_leaving = 0;
  7809. }
  7810. lcd_clear();
  7811. lcd_return_to_status();
  7812. lcd_draw_update = 2;
  7813. }
  7814. if (lcd_draw_update == 2) lcd_clear();
  7815. if (lcd_draw_update) lcd_draw_update--;
  7816. lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
  7817. }
  7818. lcd_ping(); //check that we have received ping command if we are in farm mode
  7819. lcd_send_status();
  7820. if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
  7821. }
  7822. #ifdef TMC2130
  7823. //! @brief Is crash detection enabled?
  7824. //!
  7825. //! @retval true crash detection enabled
  7826. //! @retval false crash detection disabled
  7827. bool lcd_crash_detect_enabled()
  7828. {
  7829. return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
  7830. }
  7831. void lcd_crash_detect_enable()
  7832. {
  7833. tmc2130_sg_stop_on_crash = true;
  7834. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF);
  7835. }
  7836. void lcd_crash_detect_disable()
  7837. {
  7838. tmc2130_sg_stop_on_crash = false;
  7839. tmc2130_sg_crash = 0;
  7840. eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00);
  7841. }
  7842. #endif
  7843. void lcd_experimental_toggle()
  7844. {
  7845. uint8_t oldVal = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY);
  7846. if (oldVal == EEPROM_EMPTY_VALUE)
  7847. oldVal = 0;
  7848. else
  7849. oldVal = !oldVal;
  7850. eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, oldVal);
  7851. }
  7852. #ifdef TMC2130
  7853. void UserECool_toggle(){
  7854. // 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
  7855. // 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)
  7856. bool enable = ! UserECoolEnabled();
  7857. eeprom_update_byte((uint8_t *)EEPROM_ECOOL_ENABLE, enable ? EEPROM_ECOOL_MAGIC_NUMBER : EEPROM_EMPTY_VALUE);
  7858. // @@TODO I don't like this - disabling the experimental menu shall disable ECool mode, but it will not reinit the TMC
  7859. // 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.
  7860. tmc2130_init(TMCInitParams(enable));
  7861. }
  7862. #endif
  7863. /// Enable experimental support for cooler operation of the extruder motor
  7864. /// Beware - REQUIRES original Prusa MK3/S/+ extruder motor with adequate maximal current
  7865. /// Therefore we don't want to allow general usage of this feature in public as the community likes to
  7866. /// change motors for various reasons and unless the motor is rotating, we cannot verify its properties
  7867. /// (which would be obviously too late for an improperly sized motor)
  7868. /// For farm printing, the cooler E-motor is enabled by default.
  7869. bool UserECoolEnabled(){
  7870. // We enable E-cool mode for non-farm prints IFF the experimental menu is visible AND the EEPROM_ECOOL variable has
  7871. // a value of the universal answer to all problems of the universe
  7872. return ( eeprom_read_byte((uint8_t *)EEPROM_ECOOL_ENABLE) == EEPROM_ECOOL_MAGIC_NUMBER )
  7873. && ( eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY) == 1 );
  7874. }
  7875. bool FarmOrUserECool(){
  7876. return farm_mode || UserECoolEnabled();
  7877. }
  7878. void lcd_experimental_menu()
  7879. {
  7880. MENU_BEGIN();
  7881. MENU_ITEM_BACK_P(_T(MSG_BACK));
  7882. #ifdef EXTRUDER_ALTFAN_DETECT
  7883. MENU_ITEM_TOGGLE_P(_N("ALTFAN det."), altfanOverride_get()?_T(MSG_OFF):_T(MSG_ON), altfanOverride_toggle);////MSG_MENU_ALTFAN c=18
  7884. #endif //EXTRUDER_ALTFAN_DETECT
  7885. #ifdef TMC2130
  7886. MENU_ITEM_TOGGLE_P(_N("E-cool mode"), UserECoolEnabled()?_T(MSG_ON):_T(MSG_OFF), UserECool_toggle);////MSG_MENU_ECOOL c=18
  7887. #endif
  7888. MENU_END();
  7889. }
  7890. #ifdef PINDA_TEMP_COMP
  7891. void lcd_pinda_temp_compensation_toggle()
  7892. {
  7893. uint8_t pinda_temp_compensation = eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION);
  7894. if (pinda_temp_compensation == EEPROM_EMPTY_VALUE) // On MK2.5/S the EEPROM_EMPTY_VALUE will be set to 0 during eeprom_init.
  7895. pinda_temp_compensation = 1; // But for MK3/S it should be 1 so SuperPINDA is "active"
  7896. else
  7897. pinda_temp_compensation = !pinda_temp_compensation;
  7898. eeprom_update_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION, pinda_temp_compensation);
  7899. SERIAL_ECHOLNPGM("SuperPINDA:");
  7900. SERIAL_ECHOLN(pinda_temp_compensation);
  7901. }
  7902. #endif //PINDA_TEMP_COMP