ultralcd.cpp 265 KB

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