ultralcd.cpp 264 KB

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