ultralcd.cpp 262 KB

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