ultralcd.cpp 262 KB

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