ultralcd.cpp 255 KB

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