ultralcd.cpp 262 KB

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