ultralcd.cpp 264 KB

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