ultralcd.cpp 206 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #include "fsensor.h"
  4. #include "Marlin.h"
  5. #include "language.h"
  6. #include "cardreader.h"
  7. #include "temperature.h"
  8. #include "stepper.h"
  9. #include "ConfigurationStore.h"
  10. #include <string.h>
  11. #include "lcd.h"
  12. #include "menu.h"
  13. #include "util.h"
  14. #include "mesh_bed_leveling.h"
  15. #include "mesh_bed_calibration.h"
  16. //#include "Configuration.h"
  17. #include "cmdqueue.h"
  18. #include "SdFatUtil.h"
  19. #ifdef FILAMENT_SENSOR
  20. #include "pat9125.h"
  21. #include "fsensor.h"
  22. #endif //FILAMENT_SENSOR
  23. #ifdef TMC2130
  24. #include "tmc2130.h"
  25. #endif //TMC2130
  26. #include "sound.h"
  27. #include "mmu.h"
  28. extern bool fans_check_enabled;
  29. int scrollstuff = 0;
  30. char longFilenameOLD[LONG_FILENAME_LENGTH];
  31. static void lcd_sd_updir();
  32. int8_t ReInitLCD = 0;
  33. int8_t SilentModeMenu = SILENT_MODE_OFF;
  34. int8_t FSensorStateMenu = 1;
  35. int8_t CrashDetectMenu = 1;
  36. extern bool fsensor_enable();
  37. extern void fsensor_disable();
  38. #ifdef TMC2130
  39. extern void crashdet_enable();
  40. extern void crashdet_disable();
  41. #endif //TMC2130
  42. #ifdef SDCARD_SORT_ALPHA
  43. bool presort_flag = false;
  44. #endif
  45. int lcd_commands_type = LCD_COMMAND_IDLE;
  46. int lcd_commands_step = 0;
  47. unsigned int custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  48. unsigned int custom_message_state = 0;
  49. bool isPrintPaused = false;
  50. uint8_t farm_mode = 0;
  51. int farm_no = 0;
  52. int farm_timer = 8;
  53. int farm_status = 0;
  54. bool printer_connected = true;
  55. unsigned long display_time; //just timer for showing pid finished message on lcd;
  56. float pid_temp = DEFAULT_PID_TEMP;
  57. static bool forceMenuExpire = false;
  58. bool lcd_autoDeplete;
  59. static float manual_feedrate[] = MANUAL_FEEDRATE;
  60. /* !Configuration settings */
  61. uint8_t lcd_status_message_level;
  62. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  63. unsigned char firstrun = 1;
  64. static const char separator[] PROGMEM = "--------------------";
  65. /** forward declarations **/
  66. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines);
  67. // void copy_and_scalePID_i();
  68. // void copy_and_scalePID_d();
  69. /* Different menus */
  70. static void lcd_status_screen();
  71. static void lcd_language_menu();
  72. static void lcd_main_menu();
  73. static void lcd_tune_menu();
  74. //static void lcd_move_menu();
  75. static void lcd_settings_menu();
  76. static void lcd_calibration_menu();
  77. #ifdef LINEARITY_CORRECTION
  78. static void lcd_settings_menu_back();
  79. #endif //LINEARITY_CORRECTION
  80. static void lcd_control_temperature_menu();
  81. static void lcd_control_temperature_preheat_pla_settings_menu();
  82. static void lcd_control_temperature_preheat_abs_settings_menu();
  83. static void lcd_control_motion_menu();
  84. static void lcd_control_volumetric_menu();
  85. static void lcd_settings_linearity_correction_menu_save();
  86. static void prusa_stat_printerstatus(int _status);
  87. static void prusa_stat_farm_number();
  88. static void prusa_stat_temperatures();
  89. static void prusa_stat_printinfo();
  90. static void lcd_farm_no();
  91. static void lcd_menu_extruder_info();
  92. static void lcd_menu_xyz_y_min();
  93. static void lcd_menu_xyz_skew();
  94. static void lcd_menu_xyz_offset();
  95. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  96. static void lcd_menu_fails_stats();
  97. #endif //TMC2130 or FILAMENT_SENSOR
  98. static void lcd_selftest_v();
  99. #ifdef TMC2130
  100. static void reset_crash_det(unsigned char axis);
  101. static bool lcd_selfcheck_axis_sg(unsigned char axis);
  102. static bool lcd_selfcheck_axis(int _axis, int _travel);
  103. #else
  104. static bool lcd_selfcheck_endstops();
  105. static bool lcd_selfcheck_axis(int _axis, int _travel);
  106. static bool lcd_selfcheck_pulleys(int axis);
  107. #endif //TMC2130
  108. static bool lcd_selfcheck_check_heater(bool _isbed);
  109. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay);
  110. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator);
  111. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite);
  112. static bool lcd_selftest_fan_dialog(int _fan);
  113. static bool lcd_selftest_fsensor();
  114. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2);
  115. static void lcd_colorprint_change();
  116. #ifdef SNMM
  117. static int get_ext_nr();
  118. #endif //SNMM
  119. #if defined (SNMM) || defined(SNMM_V2)
  120. static void fil_load_menu();
  121. static void fil_unload_menu();
  122. #endif // SNMM || SNMM_V2
  123. static void lcd_disable_farm_mode();
  124. static void lcd_set_fan_check();
  125. static char snmm_stop_print_menu();
  126. #ifdef SDCARD_SORT_ALPHA
  127. static void lcd_sort_type_set();
  128. #endif
  129. static float count_e(float layer_heigth, float extrusion_width, float extrusion_length);
  130. static void lcd_babystep_z();
  131. static void lcd_send_status();
  132. #ifdef FARM_CONNECT_MESSAGE
  133. static void lcd_connect_printer();
  134. #endif //FARM_CONNECT_MESSAGE
  135. void lcd_finishstatus();
  136. static void lcd_sdcard_menu();
  137. #ifdef DELTA_CALIBRATION_MENU
  138. static void lcd_delta_calibrate_menu();
  139. #endif // DELTA_CALIBRATION_MENU
  140. /* Different types of actions that can be used in menu items. */
  141. static void menu_action_sdfile(const char* filename);
  142. static void menu_action_sddirectory(const char* filename);
  143. #define ENCODER_FEEDRATE_DEADZONE 10
  144. /*
  145. #define MENU_ITEM(type, label, args...) do { \
  146. if (menu_item == menu_line) { \
  147. if (lcd_draw_update) { \
  148. const char* _label_pstr = (label); \
  149. if (lcd_encoder == menu_item) { \
  150. lcd_implementation_drawmenu_ ## type ## _selected (menu_row, _label_pstr , ## args ); \
  151. }else{\
  152. lcd_implementation_drawmenu_ ## type (menu_row, _label_pstr , ## args ); \
  153. }\
  154. }\
  155. if (menu_clicked && (lcd_encoder == menu_item)) {\
  156. lcd_quick_feedback(); \
  157. menu_action_ ## type ( args ); \
  158. return;\
  159. }\
  160. }\
  161. menu_item++;\
  162. } while(0)
  163. */
  164. #if (SDCARDDETECT > 0)
  165. bool lcd_oldcardstatus;
  166. #endif
  167. bool ignore_click = false;
  168. bool wait_for_unclick;
  169. // place-holders for Ki and Kd edits
  170. #ifdef PIDTEMP
  171. // float raw_Ki, raw_Kd;
  172. #endif
  173. const char STR_SEPARATOR[] PROGMEM = "------------";
  174. static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, char* longFilename)
  175. {
  176. char c;
  177. int enc_dif = lcd_encoder_diff;
  178. uint8_t n = LCD_WIDTH - 1;
  179. for(int g = 0; g<4;g++){
  180. lcd_set_cursor(0, g);
  181. lcd_print(' ');
  182. }
  183. lcd_set_cursor(0, row);
  184. lcd_print('>');
  185. int i = 1;
  186. int j = 0;
  187. char* longFilenameTMP = longFilename;
  188. while((c = *longFilenameTMP) != '\0')
  189. {
  190. lcd_set_cursor(i, row);
  191. lcd_print(c);
  192. i++;
  193. longFilenameTMP++;
  194. if(i==LCD_WIDTH){
  195. i=1;
  196. j++;
  197. longFilenameTMP = longFilename + j;
  198. n = LCD_WIDTH - 1;
  199. for(int g = 0; g<300 ;g++){
  200. manage_heater();
  201. if(LCD_CLICKED || ( enc_dif != lcd_encoder_diff )){
  202. longFilenameTMP = longFilename;
  203. *(longFilenameTMP + LCD_WIDTH - 2) = '\0';
  204. i = 1;
  205. j = 0;
  206. break;
  207. }else{
  208. if (j == 1) delay(3); //wait around 1.2 s to start scrolling text
  209. delay(1); //then scroll with redrawing every 300 ms
  210. }
  211. }
  212. }
  213. }
  214. if(c!='\0'){
  215. lcd_set_cursor(i, row);
  216. lcd_print(c);
  217. i++;
  218. }
  219. n=n-i+1;
  220. while(n--)
  221. lcd_print(' ');
  222. }
  223. static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* filename, char* longFilename)
  224. {
  225. char c;
  226. uint8_t n = LCD_WIDTH - 1;
  227. lcd_set_cursor(0, row);
  228. lcd_print(' ');
  229. if (longFilename[0] != '\0')
  230. {
  231. filename = longFilename;
  232. longFilename[LCD_WIDTH-1] = '\0';
  233. }
  234. while( ((c = *filename) != '\0') && (n>0) )
  235. {
  236. lcd_print(c);
  237. filename++;
  238. n--;
  239. }
  240. while(n--)
  241. lcd_print(' ');
  242. }
  243. static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* filename, char* longFilename)
  244. {
  245. char c;
  246. uint8_t n = LCD_WIDTH - 2;
  247. lcd_set_cursor(0, row);
  248. lcd_print('>');
  249. lcd_print(LCD_STR_FOLDER[0]);
  250. if (longFilename[0] != '\0')
  251. {
  252. filename = longFilename;
  253. longFilename[LCD_WIDTH-2] = '\0';
  254. }
  255. while( ((c = *filename) != '\0') && (n>0) )
  256. {
  257. lcd_print(c);
  258. filename++;
  259. n--;
  260. }
  261. while(n--)
  262. lcd_print(' ');
  263. }
  264. static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* filename, char* longFilename)
  265. {
  266. char c;
  267. uint8_t n = LCD_WIDTH - 2;
  268. lcd_set_cursor(0, row);
  269. lcd_print(' ');
  270. lcd_print(LCD_STR_FOLDER[0]);
  271. if (longFilename[0] != '\0')
  272. {
  273. filename = longFilename;
  274. longFilename[LCD_WIDTH-2] = '\0';
  275. }
  276. while( ((c = *filename) != '\0') && (n>0) )
  277. {
  278. lcd_print(c);
  279. filename++;
  280. n--;
  281. }
  282. while(n--)
  283. lcd_print(' ');
  284. }
  285. #define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0)
  286. //#define MENU_ITEM_SDDIR(str, str_fn, str_fnl) MENU_ITEM(sddirectory, str, str_fn, str_fnl)
  287. //extern uint8_t menu_item_sddir(const char* str, const char* str_fn, char* str_fnl);
  288. #define MENU_ITEM_SDFILE(str, str_fn, str_fnl) do { if (menu_item_sdfile(str, str_fn, str_fnl)) return; } while (0)
  289. //#define MENU_ITEM_SDFILE(str, str_fn, str_fnl) MENU_ITEM(sdfile, str, str_fn, str_fnl)
  290. //extern uint8_t menu_item_sdfile(const char* str, const char* str_fn, char* str_fnl);
  291. uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
  292. {
  293. #ifdef NEW_SD_MENU
  294. // str_fnl[18] = 0;
  295. // printf_P(PSTR("menu dir %d '%s' '%s'\n"), menu_row, str_fn, str_fnl);
  296. if (menu_item == menu_line)
  297. {
  298. if (lcd_draw_update)
  299. {
  300. lcd_set_cursor(0, menu_row);
  301. int cnt = lcd_printf_P(PSTR("%c%c%-18s"), (lcd_encoder == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fnl[0]?str_fnl:str_fn);
  302. // int cnt = lcd_printf_P(PSTR("%c%c%-18s"), (lcd_encoder == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fn);
  303. }
  304. if (menu_clicked && (lcd_encoder == menu_item))
  305. {
  306. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  307. strcpy(dir_names[depth], str_fn);
  308. // printf_P(PSTR("%s\n"), dir_names[depth]);
  309. card.chdir(str_fn);
  310. lcd_encoder = 0;
  311. return menu_item_ret();
  312. }
  313. }
  314. menu_item++;
  315. return 0;
  316. #else //NEW_SD_MENU
  317. if (menu_item == menu_line)
  318. {
  319. if (lcd_draw_update)
  320. {
  321. if (lcd_encoder == menu_item)
  322. lcd_implementation_drawmenu_sddirectory_selected(menu_row, str_fn, str_fnl);
  323. else
  324. lcd_implementation_drawmenu_sddirectory(menu_row, str_fn, str_fnl);
  325. }
  326. if (menu_clicked && (lcd_encoder == menu_item))
  327. {
  328. menu_clicked = false;
  329. lcd_update_enabled = 0;
  330. menu_action_sddirectory(str_fn);
  331. lcd_update_enabled = 1;
  332. return menu_item_ret();
  333. }
  334. }
  335. menu_item++;
  336. return 0;
  337. #endif //NEW_SD_MENU
  338. }
  339. static uint8_t menu_item_sdfile(const char*
  340. #ifdef NEW_SD_MENU
  341. str
  342. #endif //NEW_SD_MENU
  343. ,const char* str_fn, char* str_fnl)
  344. {
  345. #ifdef NEW_SD_MENU
  346. // printf_P(PSTR("menu sdfile\n"));
  347. // str_fnl[19] = 0;
  348. // printf_P(PSTR("menu file %d '%s' '%s'\n"), menu_row, str_fn, str_fnl);
  349. if (menu_item == menu_line)
  350. {
  351. if (lcd_draw_update)
  352. {
  353. // printf_P(PSTR("menu file %d %d '%s'\n"), menu_row, menuData.sdcard_menu.viewState, str_fnl[0]?str_fnl:str_fn);
  354. lcd_set_cursor(0, menu_row);
  355. /* if (lcd_encoder == menu_item)
  356. {
  357. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1);
  358. if (menuData.sdcard_menu.viewState == 0)
  359. {
  360. menuData.sdcard_menu.viewState++;
  361. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1);
  362. }
  363. else if (menuData.sdcard_menu.viewState == 1)
  364. {
  365. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 2);
  366. }
  367. }
  368. else*/
  369. {
  370. str_fnl[19] = 0;
  371. lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', str_fnl[0]?str_fnl:str_fn);
  372. }
  373. // int cnt = lcd_printf_P(PSTR("%c%-19s"), (lcd_encoder == menu_item)?'>':' ', str_fnl);
  374. // int cnt = lcd_printf_P(PSTR("%cTESTIK.gcode"), (lcd_encoder == menu_item)?'>':' ');
  375. }
  376. if (menu_clicked && (lcd_encoder == menu_item))
  377. {
  378. return menu_item_ret();
  379. }
  380. }
  381. menu_item++;
  382. return 0;
  383. #else //NEW_SD_MENU
  384. if (menu_item == menu_line)
  385. {
  386. if (lcd_draw_update)
  387. {
  388. if (lcd_encoder == menu_item)
  389. lcd_implementation_drawmenu_sdfile_selected(menu_row, str_fnl);
  390. else
  391. lcd_implementation_drawmenu_sdfile(menu_row, str_fn, str_fnl);
  392. }
  393. if (menu_clicked && (lcd_encoder == menu_item))
  394. {
  395. menu_action_sdfile(str_fn);
  396. return menu_item_ret();
  397. }
  398. }
  399. menu_item++;
  400. return 0;
  401. #endif //NEW_SD_MENU
  402. }
  403. // Print temperature (nozzle/bed) (9 chars total)
  404. void lcdui_print_temp(char type, int val_current, int val_target)
  405. {
  406. int chars = lcd_printf_P(_N("%c%3d/%d%c"), type, val_current, val_target, LCD_STR_DEGREE[0]);
  407. lcd_space(9 - chars);
  408. }
  409. // Print Z-coordinate (8 chars total)
  410. void lcdui_print_Z_coord(void)
  411. {
  412. if (custom_message_type == CUSTOM_MSG_TYPE_MESHBL)
  413. lcd_puts_P(_N("Z --- "));
  414. else
  415. lcd_printf_P(_N("Z%6.2f "), current_position[Z_AXIS]);
  416. }
  417. #ifdef PLANNER_DIAGNOSTICS
  418. // Print planner diagnostics (8 chars total)
  419. void lcdui_print_planner_diag(void)
  420. {
  421. lcd_set_cursor(LCD_WIDTH - 8-2, 1);
  422. lcd_print(LCD_STR_FEEDRATE[0]);
  423. lcd_print(itostr3(feedmultiply));
  424. lcd_puts_P(PSTR("% Q"));
  425. {
  426. uint8_t queue = planner_queue_min();
  427. if (queue < (BLOCK_BUFFER_SIZE >> 1))
  428. lcd_putc('!');
  429. else
  430. {
  431. lcd_putc((char)(queue / 10) + '0');
  432. queue %= 10;
  433. }
  434. lcd_putc((char)queue + '0');
  435. planner_queue_min_reset();
  436. }
  437. }
  438. #endif // PLANNER_DIAGNOSTICS
  439. // Print feedrate (8 chars total)
  440. void lcdui_print_feedrate(void)
  441. {
  442. int chars = lcd_printf_P(_N("%c%3d%%"), LCD_STR_FEEDRATE[0], feedmultiply);
  443. lcd_space(8 - chars);
  444. }
  445. // Print percent done in form "USB---%", " SD---%", " ---%" (7 chars total)
  446. void lcdui_print_percent_done(void)
  447. {
  448. const char* src = is_usb_printing?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" "));
  449. char per[4];
  450. bool num = IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
  451. sprintf_P(per, num?_N("%3hhd"):_N("---"), calc_percent_done());
  452. lcd_printf_P(_N("%3S%3s%%"), src, per);
  453. }
  454. // Print extruder status (5 chars total)
  455. void lcdui_print_extruder(void)
  456. {
  457. int chars = 0;
  458. if (mmu_extruder == tmp_extruder)
  459. chars = lcd_printf_P(_N(" F%u"), mmu_extruder+1);
  460. else
  461. chars = lcd_printf_P(_N(" %u>%u"), mmu_extruder+1, tmp_extruder+1);
  462. lcd_space(5 - chars);
  463. }
  464. // Print farm number (5 chars total)
  465. void lcdui_print_farm(void)
  466. {
  467. int chars = lcd_printf_P(_N(" F0 "));
  468. // lcd_space(5 - chars);
  469. /*
  470. // Farm number display
  471. if (farm_mode)
  472. {
  473. lcd_set_cursor(6, 2);
  474. lcd_puts_P(PSTR(" F"));
  475. lcd_print(farm_no);
  476. lcd_puts_P(PSTR(" "));
  477. // Beat display
  478. lcd_set_cursor(LCD_WIDTH - 1, 0);
  479. if ( (millis() - kicktime) < 60000 ) {
  480. lcd_puts_P(PSTR("L"));
  481. }else{
  482. lcd_puts_P(PSTR(" "));
  483. }
  484. }
  485. else {
  486. #ifdef SNMM
  487. lcd_puts_P(PSTR(" E"));
  488. lcd_print(get_ext_nr() + 1);
  489. #else
  490. lcd_set_cursor(LCD_WIDTH - 8 - 2, 2);
  491. lcd_puts_P(PSTR(" "));
  492. #endif
  493. }
  494. */
  495. }
  496. #ifdef CMD_DIAGNOSTICS
  497. // Print CMD queue diagnostic (8 chars total)
  498. void lcdui_print_cmd_diag(void)
  499. {
  500. lcd_set_cursor(LCD_WIDTH - 8 -1, 2);
  501. lcd_puts_P(PSTR(" C"));
  502. lcd_print(buflen); // number of commands in cmd buffer
  503. if (buflen < 9) lcd_puts_P(" ");
  504. }
  505. #endif //CMD_DIAGNOSTICS
  506. // Print time (8 chars total)
  507. void lcdui_print_time(void)
  508. {
  509. //if remaining print time estimation is available print it else print elapsed time
  510. uint16_t print_t = 0;
  511. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  512. print_t = print_time_remaining();
  513. else if(starttime != 0)
  514. print_t = millis() / 60000 - starttime / 60000;
  515. int chars = 0;
  516. if ((PRINTER_ACTIVE) && ((print_time_remaining_normal != PRINT_TIME_REMAINING_INIT) || (starttime != 0)))
  517. {
  518. char suff = ' ';
  519. char suff_doubt = ' ';
  520. if (print_time_remaining_normal != PRINT_TIME_REMAINING_INIT)
  521. {
  522. suff = 'R';
  523. if (feedmultiply != 100)
  524. suff_doubt = '?';
  525. }
  526. chars = lcd_printf_P(_N("%c%02u:%02u%c%c"), LCD_STR_CLOCK[0], print_t / 60, print_t % 60, suff, suff_doubt);
  527. }
  528. else
  529. chars = lcd_printf_P(_N("%c--:-- "), LCD_STR_CLOCK[0]);
  530. lcd_space(8 - chars);
  531. }
  532. //Print status line on status screen
  533. void lcdui_print_status_line(void)
  534. {
  535. if (IS_SD_PRINTING)
  536. {
  537. if (strcmp(longFilenameOLD, card.longFilename) != 0)
  538. {
  539. memset(longFilenameOLD, '\0', strlen(longFilenameOLD));
  540. sprintf_P(longFilenameOLD, PSTR("%s"), card.longFilename);
  541. scrollstuff = 0;
  542. }
  543. }
  544. if (heating_status)
  545. { // If heating flag, show progress of heating
  546. heating_status_counter++;
  547. if (heating_status_counter > 13)
  548. {
  549. heating_status_counter = 0;
  550. }
  551. lcd_set_cursor(7, 3);
  552. lcd_puts_P(PSTR(" "));
  553. for (unsigned int dots = 0; dots < heating_status_counter; dots++)
  554. {
  555. lcd_set_cursor(7 + dots, 3);
  556. lcd_print('.');
  557. }
  558. switch (heating_status)
  559. {
  560. case 1:
  561. lcd_set_cursor(0, 3);
  562. lcd_puts_P(_T(MSG_HEATING));
  563. break;
  564. case 2:
  565. lcd_set_cursor(0, 3);
  566. lcd_puts_P(_T(MSG_HEATING_COMPLETE));
  567. heating_status = 0;
  568. heating_status_counter = 0;
  569. break;
  570. case 3:
  571. lcd_set_cursor(0, 3);
  572. lcd_puts_P(_T(MSG_BED_HEATING));
  573. break;
  574. case 4:
  575. lcd_set_cursor(0, 3);
  576. lcd_puts_P(_T(MSG_BED_DONE));
  577. heating_status = 0;
  578. heating_status_counter = 0;
  579. break;
  580. default:
  581. break;
  582. }
  583. }
  584. else if ((IS_SD_PRINTING) && (custom_message_type == CUSTOM_MSG_TYPE_STATUS))
  585. { // If printing from SD, show what we are printing
  586. if(strlen(card.longFilename) > LCD_WIDTH)
  587. {
  588. int inters = 0;
  589. int gh = scrollstuff;
  590. while (((gh - scrollstuff) < LCD_WIDTH) && (inters == 0))
  591. {
  592. if (card.longFilename[gh] == '\0')
  593. {
  594. lcd_set_cursor(gh - scrollstuff, 3);
  595. lcd_print(card.longFilename[gh - 1]);
  596. scrollstuff = 0;
  597. gh = scrollstuff;
  598. inters = 1;
  599. }
  600. else
  601. {
  602. lcd_set_cursor(gh - scrollstuff, 3);
  603. lcd_print(card.longFilename[gh - 1]);
  604. gh++;
  605. }
  606. }
  607. scrollstuff++;
  608. }
  609. else
  610. {
  611. lcd_print(longFilenameOLD);
  612. }
  613. }
  614. else
  615. { // Otherwise check for other special events
  616. switch (custom_message_type)
  617. {
  618. case CUSTOM_MSG_TYPE_STATUS: // Nothing special, print status message normally
  619. lcd_print(lcd_status_message);
  620. break;
  621. case CUSTOM_MSG_TYPE_MESHBL: // If mesh bed leveling in progress, show the status
  622. if (custom_message_state > 10)
  623. {
  624. lcd_set_cursor(0, 3);
  625. lcd_puts_P(PSTR(" "));
  626. lcd_set_cursor(0, 3);
  627. lcd_puts_P(_T(MSG_CALIBRATE_Z_AUTO));
  628. lcd_puts_P(PSTR(" : "));
  629. lcd_print(custom_message_state-10);
  630. }
  631. else
  632. {
  633. if (custom_message_state == 3)
  634. {
  635. lcd_puts_P(_T(WELCOME_MSG));
  636. lcd_setstatuspgm(_T(WELCOME_MSG));
  637. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  638. }
  639. if (custom_message_state > 3 && custom_message_state <= 10 )
  640. {
  641. lcd_set_cursor(0, 3);
  642. lcd_puts_P(PSTR(" "));
  643. lcd_set_cursor(0, 3);
  644. lcd_puts_P(_i("Calibration done"));////MSG_HOMEYZ_DONE c=0 r=0
  645. custom_message_state--;
  646. }
  647. }
  648. break;
  649. case CUSTOM_MSG_TYPE_F_LOAD: // If loading filament, print status
  650. lcd_print(lcd_status_message);
  651. break;
  652. case CUSTOM_MSG_TYPE_PIDCAL: // PID tuning in progress
  653. lcd_print(lcd_status_message);
  654. if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0)
  655. {
  656. lcd_set_cursor(10, 3);
  657. lcd_print(itostr3(pid_cycle));
  658. lcd_print('/');
  659. lcd_print(itostr3left(pid_number_of_cycles));
  660. }
  661. break;
  662. case CUSTOM_MSG_TYPE_TEMCAL: // PINDA temp calibration in progress
  663. {
  664. char progress[4];
  665. lcd_set_cursor(0, 3);
  666. lcd_puts_P(_T(MSG_TEMP_CALIBRATION));
  667. lcd_set_cursor(12, 3);
  668. sprintf(progress, "%d/6", custom_message_state);
  669. lcd_print(progress);
  670. }
  671. break;
  672. case CUSTOM_MSG_TYPE_TEMPRE: // temp compensation preheat
  673. lcd_set_cursor(0, 3);
  674. lcd_puts_P(_i("PINDA Heating"));////MSG_PINDA_PREHEAT c=20 r=1
  675. if (custom_message_state <= PINDA_HEAT_T)
  676. {
  677. lcd_puts_P(PSTR(": "));
  678. lcd_print(custom_message_state); //seconds
  679. lcd_print(' ');
  680. }
  681. break;
  682. }
  683. }
  684. // Fill the rest of line to have nice and clean output
  685. for(int fillspace = 0; fillspace < 20; fillspace++)
  686. if ((lcd_status_message[fillspace] <= 31 ))
  687. lcd_print(' ');
  688. }
  689. void lcdui_print_status_screen(void)
  690. {
  691. //|01234567890123456789|
  692. //|N 000/000D Z000.0 |
  693. //|B 000/000D F100% |
  694. //|USB100% T0 t--:-- |
  695. //|Status line.........|
  696. //----------------------
  697. //N - nozzle temp symbol LCD_STR_THERMOMETER
  698. //B - bed temp symbol LCD_STR_BEDTEMP
  699. //F - feedrate symbol LCD_STR_FEEDRATE
  700. //t - clock symbol LCD_STR_THERMOMETER
  701. lcd_set_cursor(0, 0); //line 0
  702. //Print the hotend temperature (9 chars total)
  703. lcdui_print_temp(LCD_STR_THERMOMETER[0], (int)(degHotend(0) + 0.5), (int)(degTargetHotend(0) + 0.5));
  704. lcd_space(3); //3 spaces
  705. //Print Z-coordinate (8 chars total)
  706. lcdui_print_Z_coord();
  707. lcd_set_cursor(0, 1); //line 1
  708. //Print the Bed temperature (9 chars total)
  709. lcdui_print_temp(LCD_STR_BEDTEMP[0], (int)(degBed() + 0.5), (int)(degTargetBed() + 0.5));
  710. lcd_space(3); //3 spaces
  711. #ifdef PLANNER_DIAGNOSTICS
  712. //Print planner diagnostics (8 chars)
  713. lcdui_print_planner_diag();
  714. #else // PLANNER_DIAGNOSTICS
  715. //Print Feedrate (8 chars)
  716. lcdui_print_feedrate();
  717. #endif // PLANNER_DIAGNOSTICS
  718. lcd_set_cursor(0, 2); //line 2
  719. //Print SD status (7 chars)
  720. lcdui_print_percent_done();
  721. if (mmu_enabled)
  722. //Print extruder status (5 chars)
  723. lcdui_print_extruder();
  724. else if (farm_mode)
  725. //Print farm number (5 chars)
  726. lcdui_print_farm();
  727. else
  728. lcd_space(5); //5 spaces
  729. #ifdef CMD_DIAGNOSTICS
  730. //Print cmd queue diagnostics (8chars)
  731. lcdui_print_cmd_diag();
  732. #else
  733. //Print time (8chars)
  734. lcdui_print_time();
  735. #endif //CMD_DIAGNOSTICS
  736. lcd_set_cursor(0, 3); //line 3
  737. #ifndef DEBUG_DISABLE_LCD_STATUS_LINE
  738. lcdui_print_status_line();
  739. #endif //DEBUG_DISABLE_LCD_STATUS_LINE
  740. }
  741. // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent
  742. static void lcd_status_screen()
  743. {
  744. if (firstrun == 1)
  745. {
  746. firstrun = 0;
  747. if(lcd_status_message_level == 0)
  748. {
  749. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  750. lcd_finishstatus();
  751. }
  752. 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)
  753. {
  754. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  755. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  756. }
  757. }
  758. if (lcd_status_update_delay)
  759. lcd_status_update_delay--;
  760. else
  761. lcd_draw_update = 1;
  762. if (lcd_draw_update)
  763. {
  764. ReInitLCD++;
  765. if (ReInitLCD == 30)
  766. {
  767. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  768. ReInitLCD = 0 ;
  769. }
  770. else
  771. {
  772. if ((ReInitLCD % 10) == 0)
  773. lcd_refresh_noclear(); //to maybe revive the LCD if static electricity killed it.
  774. }
  775. lcdui_print_status_screen();
  776. if (farm_mode)
  777. {
  778. farm_timer--;
  779. if (farm_timer < 1)
  780. {
  781. farm_timer = 10;
  782. prusa_statistics(0);
  783. }
  784. switch (farm_timer)
  785. {
  786. case 8:
  787. prusa_statistics(21);
  788. break;
  789. case 5:
  790. if (IS_SD_PRINTING)
  791. prusa_statistics(20);
  792. break;
  793. }
  794. } // end of farm_mode
  795. 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 */
  796. if (lcd_commands_type != LCD_COMMAND_IDLE)
  797. lcd_commands();
  798. } // end of lcd_draw_update
  799. bool current_click = LCD_CLICKED;
  800. if (ignore_click)
  801. {
  802. if (wait_for_unclick)
  803. {
  804. if (!current_click)
  805. ignore_click = wait_for_unclick = false;
  806. else
  807. current_click = false;
  808. }
  809. else if (current_click)
  810. {
  811. lcd_quick_feedback();
  812. wait_for_unclick = true;
  813. current_click = false;
  814. }
  815. }
  816. if (current_click && (lcd_commands_type != LCD_COMMAND_STOP_PRINT)) //click is aborted unless stop print finishes
  817. {
  818. menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
  819. menu_submenu(lcd_main_menu);
  820. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  821. }
  822. #ifdef ULTIPANEL_FEEDMULTIPLY
  823. // Dead zone at 100% feedrate
  824. if ((feedmultiply < 100 && (feedmultiply + int(lcd_encoder)) > 100) ||
  825. (feedmultiply > 100 && (feedmultiply + int(lcd_encoder)) < 100))
  826. {
  827. lcd_encoder = 0;
  828. feedmultiply = 100;
  829. }
  830. if (feedmultiply == 100 && int(lcd_encoder) > ENCODER_FEEDRATE_DEADZONE)
  831. {
  832. feedmultiply += int(lcd_encoder) - ENCODER_FEEDRATE_DEADZONE;
  833. lcd_encoder = 0;
  834. }
  835. else if (feedmultiply == 100 && int(lcd_encoder) < -ENCODER_FEEDRATE_DEADZONE)
  836. {
  837. feedmultiply += int(lcd_encoder) + ENCODER_FEEDRATE_DEADZONE;
  838. lcd_encoder = 0;
  839. }
  840. else if (feedmultiply != 100)
  841. {
  842. feedmultiply += int(lcd_encoder);
  843. lcd_encoder = 0;
  844. }
  845. #endif //ULTIPANEL_FEEDMULTIPLY
  846. if (feedmultiply < 10)
  847. feedmultiply = 10;
  848. else if (feedmultiply > 999)
  849. feedmultiply = 999;
  850. }
  851. void lcd_commands()
  852. {
  853. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE)
  854. {
  855. if (!blocks_queued() && !homing_flag)
  856. {
  857. lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20 r=1
  858. long_pause();
  859. lcd_commands_type = 0;
  860. lcd_commands_step = 0;
  861. }
  862. }
  863. #ifdef SNMM
  864. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  865. {
  866. char cmd1[30];
  867. float width = 0.4;
  868. float length = 20 - width;
  869. float extr = count_e(0.2, width, length);
  870. float extr_short_segment = count_e(0.2, width, width);
  871. 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
  872. if (lcd_commands_step == 0)
  873. {
  874. lcd_commands_step = 10;
  875. }
  876. if (lcd_commands_step == 10 && !blocks_queued() && cmd_buffer_empty())
  877. {
  878. enquecommand_P(PSTR("M107"));
  879. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  880. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  881. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  882. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  883. enquecommand_P(PSTR("T0"));
  884. enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  885. enquecommand_P(PSTR("G87")); //sets calibration status
  886. enquecommand_P(PSTR("G28"));
  887. enquecommand_P(PSTR("G21")); //set units to millimeters
  888. enquecommand_P(PSTR("G90")); //use absolute coordinates
  889. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  890. enquecommand_P(PSTR("G92 E0"));
  891. enquecommand_P(PSTR("M203 E100"));
  892. enquecommand_P(PSTR("M92 E140"));
  893. lcd_commands_step = 9;
  894. }
  895. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  896. {
  897. lcd_timeoutToStatus.start();
  898. enquecommand_P(PSTR("G1 Z0.250 F7200.000"));
  899. enquecommand_P(PSTR("G1 X50.0 E80.0 F1000.0"));
  900. enquecommand_P(PSTR("G1 X160.0 E20.0 F1000.0"));
  901. enquecommand_P(PSTR("G1 Z0.200 F7200.000"));
  902. enquecommand_P(PSTR("G1 X220.0 E13 F1000.0"));
  903. enquecommand_P(PSTR("G1 X240.0 E0 F1000.0"));
  904. enquecommand_P(PSTR("G92 E0.0"));
  905. enquecommand_P(PSTR("G21"));
  906. enquecommand_P(PSTR("G90"));
  907. enquecommand_P(PSTR("M83"));
  908. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  909. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  910. enquecommand_P(PSTR("M204 S1000"));
  911. enquecommand_P(PSTR("G1 F4000"));
  912. lcd_clear();
  913. menu_goto(lcd_babystep_z, 0, false, true);
  914. lcd_commands_step = 8;
  915. }
  916. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  917. {
  918. lcd_timeoutToStatus.start();
  919. enquecommand_P(PSTR("G1 X50 Y155"));
  920. enquecommand_P(PSTR("G1 X60 Y155 E4"));
  921. enquecommand_P(PSTR("G1 F1080"));
  922. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  923. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  924. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  925. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  926. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  927. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  928. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  929. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  930. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  931. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  932. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  933. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  934. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  935. lcd_commands_step = 7;
  936. }
  937. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty())
  938. {
  939. lcd_timeoutToStatus.start();
  940. strcpy(cmd1, "G1 X50 Y35 E");
  941. strcat(cmd1, ftostr43(extr));
  942. enquecommand(cmd1);
  943. for (int i = 0; i < 4; i++) {
  944. strcpy(cmd1, "G1 X70 Y");
  945. strcat(cmd1, ftostr32(35 - i*width * 2));
  946. strcat(cmd1, " E");
  947. strcat(cmd1, ftostr43(extr));
  948. enquecommand(cmd1);
  949. strcpy(cmd1, "G1 Y");
  950. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  951. strcat(cmd1, " E");
  952. strcat(cmd1, ftostr43(extr_short_segment));
  953. enquecommand(cmd1);
  954. strcpy(cmd1, "G1 X50 Y");
  955. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  956. strcat(cmd1, " E");
  957. strcat(cmd1, ftostr43(extr));
  958. enquecommand(cmd1);
  959. strcpy(cmd1, "G1 Y");
  960. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  961. strcat(cmd1, " E");
  962. strcat(cmd1, ftostr43(extr_short_segment));
  963. enquecommand(cmd1);
  964. }
  965. lcd_commands_step = 6;
  966. }
  967. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  968. {
  969. lcd_timeoutToStatus.start();
  970. for (int i = 4; i < 8; i++) {
  971. strcpy(cmd1, "G1 X70 Y");
  972. strcat(cmd1, ftostr32(35 - i*width * 2));
  973. strcat(cmd1, " E");
  974. strcat(cmd1, ftostr43(extr));
  975. enquecommand(cmd1);
  976. strcpy(cmd1, "G1 Y");
  977. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  978. strcat(cmd1, " E");
  979. strcat(cmd1, ftostr43(extr_short_segment));
  980. enquecommand(cmd1);
  981. strcpy(cmd1, "G1 X50 Y");
  982. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  983. strcat(cmd1, " E");
  984. strcat(cmd1, ftostr43(extr));
  985. enquecommand(cmd1);
  986. strcpy(cmd1, "G1 Y");
  987. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  988. strcat(cmd1, " E");
  989. strcat(cmd1, ftostr43(extr_short_segment));
  990. enquecommand(cmd1);
  991. }
  992. lcd_commands_step = 5;
  993. }
  994. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  995. {
  996. lcd_timeoutToStatus.start();
  997. for (int i = 8; i < 12; i++) {
  998. strcpy(cmd1, "G1 X70 Y");
  999. strcat(cmd1, ftostr32(35 - i*width * 2));
  1000. strcat(cmd1, " E");
  1001. strcat(cmd1, ftostr43(extr));
  1002. enquecommand(cmd1);
  1003. strcpy(cmd1, "G1 Y");
  1004. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1005. strcat(cmd1, " E");
  1006. strcat(cmd1, ftostr43(extr_short_segment));
  1007. enquecommand(cmd1);
  1008. strcpy(cmd1, "G1 X50 Y");
  1009. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1010. strcat(cmd1, " E");
  1011. strcat(cmd1, ftostr43(extr));
  1012. enquecommand(cmd1);
  1013. strcpy(cmd1, "G1 Y");
  1014. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1015. strcat(cmd1, " E");
  1016. strcat(cmd1, ftostr43(extr_short_segment));
  1017. enquecommand(cmd1);
  1018. }
  1019. lcd_commands_step = 4;
  1020. }
  1021. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  1022. {
  1023. lcd_timeoutToStatus.start();
  1024. for (int i = 12; i < 16; i++) {
  1025. strcpy(cmd1, "G1 X70 Y");
  1026. strcat(cmd1, ftostr32(35 - i*width * 2));
  1027. strcat(cmd1, " E");
  1028. strcat(cmd1, ftostr43(extr));
  1029. enquecommand(cmd1);
  1030. strcpy(cmd1, "G1 Y");
  1031. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1032. strcat(cmd1, " E");
  1033. strcat(cmd1, ftostr43(extr_short_segment));
  1034. enquecommand(cmd1);
  1035. strcpy(cmd1, "G1 X50 Y");
  1036. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1037. strcat(cmd1, " E");
  1038. strcat(cmd1, ftostr43(extr));
  1039. enquecommand(cmd1);
  1040. strcpy(cmd1, "G1 Y");
  1041. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1042. strcat(cmd1, " E");
  1043. strcat(cmd1, ftostr43(extr_short_segment));
  1044. enquecommand(cmd1);
  1045. }
  1046. lcd_commands_step = 3;
  1047. }
  1048. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  1049. {
  1050. lcd_timeoutToStatus.start();
  1051. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000"));
  1052. enquecommand_P(PSTR("G4 S0"));
  1053. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  1054. enquecommand_P(PSTR("G1 Z0.5 F7200.000"));
  1055. enquecommand_P(PSTR("G1 X245 Y1"));
  1056. enquecommand_P(PSTR("G1 X240 E4"));
  1057. enquecommand_P(PSTR("G1 F4000"));
  1058. enquecommand_P(PSTR("G1 X190 E2.7"));
  1059. enquecommand_P(PSTR("G1 F4600"));
  1060. enquecommand_P(PSTR("G1 X110 E2.8"));
  1061. enquecommand_P(PSTR("G1 F5200"));
  1062. enquecommand_P(PSTR("G1 X40 E3"));
  1063. enquecommand_P(PSTR("G1 E-15.0000 F5000"));
  1064. enquecommand_P(PSTR("G1 E-50.0000 F5400"));
  1065. enquecommand_P(PSTR("G1 E-15.0000 F3000"));
  1066. enquecommand_P(PSTR("G1 E-12.0000 F2000"));
  1067. enquecommand_P(PSTR("G1 F1600"));
  1068. lcd_commands_step = 2;
  1069. }
  1070. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  1071. {
  1072. lcd_timeoutToStatus.start();
  1073. enquecommand_P(PSTR("G1 X0 Y1 E3.0000"));
  1074. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1075. enquecommand_P(PSTR("G1 F2000"));
  1076. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1077. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1078. enquecommand_P(PSTR("G1 F2400"));
  1079. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1080. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1081. enquecommand_P(PSTR("G1 F2400"));
  1082. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1083. enquecommand_P(PSTR("G1 X50 Y1 E-3.0000"));
  1084. enquecommand_P(PSTR("G4 S0"));
  1085. enquecommand_P(PSTR("M107"));
  1086. enquecommand_P(PSTR("M104 S0"));
  1087. enquecommand_P(PSTR("M140 S0"));
  1088. enquecommand_P(PSTR("G1 X10 Y180 F4000"));
  1089. enquecommand_P(PSTR("G1 Z10 F1300.000"));
  1090. enquecommand_P(PSTR("M84"));
  1091. lcd_commands_step = 1;
  1092. }
  1093. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1094. {
  1095. lcd_setstatuspgm(_T(WELCOME_MSG));
  1096. lcd_commands_step = 0;
  1097. lcd_commands_type = 0;
  1098. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1099. lcd_wizard(WizState::RepeatLay1Cal);
  1100. }
  1101. }
  1102. }
  1103. #else //if not SNMM
  1104. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  1105. {
  1106. char cmd1[30];
  1107. uint8_t filament = 0;
  1108. float width = 0.4;
  1109. float length = 20 - width;
  1110. float extr = count_e(0.2, width, length);
  1111. float extr_short_segment = count_e(0.2, width, width);
  1112. 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
  1113. if (lcd_commands_step == 0 && !blocks_queued() && cmd_buffer_empty())
  1114. {
  1115. lcd_commands_step = 10;
  1116. }
  1117. if (lcd_commands_step == 20 && !blocks_queued() && cmd_buffer_empty())
  1118. {
  1119. filament = 0;
  1120. lcd_commands_step = 10;
  1121. }
  1122. if (lcd_commands_step == 21 && !blocks_queued() && cmd_buffer_empty())
  1123. {
  1124. filament = 1;
  1125. lcd_commands_step = 10;
  1126. }
  1127. if (lcd_commands_step == 22 && !blocks_queued() && cmd_buffer_empty())
  1128. {
  1129. filament = 2;
  1130. lcd_commands_step = 10;
  1131. }
  1132. if (lcd_commands_step == 23 && !blocks_queued() && cmd_buffer_empty())
  1133. {
  1134. filament = 3;
  1135. lcd_commands_step = 10;
  1136. }
  1137. if (lcd_commands_step == 24 && !blocks_queued() && cmd_buffer_empty())
  1138. {
  1139. filament = 4;
  1140. lcd_commands_step = 10;
  1141. }
  1142. if (lcd_commands_step == 10)
  1143. {
  1144. enquecommand_P(PSTR("M107"));
  1145. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  1146. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  1147. if (mmu_enabled)
  1148. {
  1149. strcpy(cmd1, "T");
  1150. strcat(cmd1, itostr3left(filament));
  1151. enquecommand(cmd1);
  1152. }
  1153. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  1154. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  1155. enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  1156. enquecommand_P(PSTR("G28"));
  1157. enquecommand_P(PSTR("G92 E0.0"));
  1158. lcd_commands_step = 9;
  1159. }
  1160. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  1161. {
  1162. lcd_clear();
  1163. menu_depth = 0;
  1164. menu_submenu(lcd_babystep_z);
  1165. if (mmu_enabled)
  1166. {
  1167. enquecommand_P(PSTR("M83")); //intro line
  1168. enquecommand_P(PSTR("G1 Y-3.0 F1000.0")); //intro line
  1169. enquecommand_P(PSTR("G1 Z0.4 F1000.0")); //intro line
  1170. enquecommand_P(PSTR("G1 X55.0 E32.0 F1073.0")); //intro line
  1171. enquecommand_P(PSTR("G1 X5.0 E32.0 F1800.0")); //intro line
  1172. enquecommand_P(PSTR("G1 X55.0 E8.0 F2000.0")); //intro line
  1173. enquecommand_P(PSTR("G1 Z0.3 F1000.0")); //intro line
  1174. enquecommand_P(PSTR("G92 E0.0")); //intro line
  1175. enquecommand_P(PSTR("G1 X240.0 E25.0 F2200.0")); //intro line
  1176. enquecommand_P(PSTR("G1 Y-2.0 F1000.0")); //intro line
  1177. enquecommand_P(PSTR("G1 X55.0 E25 F1400.0")); //intro line
  1178. enquecommand_P(PSTR("G1 Z0.20 F1000.0")); //intro line
  1179. enquecommand_P(PSTR("G1 X5.0 E4.0 F1000.0")); //intro line
  1180. } else
  1181. {
  1182. enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0")); //intro line
  1183. enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0")); //intro line
  1184. }
  1185. lcd_commands_step = 8;
  1186. }
  1187. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty())
  1188. {
  1189. enquecommand_P(PSTR("G92 E0.0"));
  1190. enquecommand_P(PSTR("G21")); //set units to millimeters
  1191. enquecommand_P(PSTR("G90")); //use absolute coordinates
  1192. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  1193. enquecommand_P(PSTR("G1 E-1.50000 F2100.00000"));
  1194. enquecommand_P(PSTR("G1 Z5 F7200.000"));
  1195. enquecommand_P(PSTR("M204 S1000")); //set acceleration
  1196. enquecommand_P(PSTR("G1 F4000"));
  1197. lcd_commands_step = 7;
  1198. }
  1199. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  1200. {
  1201. lcd_timeoutToStatus.start();
  1202. //just opposite direction
  1203. /*enquecommand_P(PSTR("G1 X50 Y55"));
  1204. enquecommand_P(PSTR("G1 F1080"));
  1205. enquecommand_P(PSTR("G1 X200 Y55 E3.62773"));
  1206. enquecommand_P(PSTR("G1 X200 Y75 E0.49386"));
  1207. enquecommand_P(PSTR("G1 X50 Y75 E3.62773"));
  1208. enquecommand_P(PSTR("G1 X50 Y95 E0.49386"));
  1209. enquecommand_P(PSTR("G1 X200 Y95 E3.62773"));
  1210. enquecommand_P(PSTR("G1 X200 Y115 E0.49386"));
  1211. enquecommand_P(PSTR("G1 X50 Y115 E3.62773"));
  1212. enquecommand_P(PSTR("G1 X50 Y135 E0.49386"));
  1213. enquecommand_P(PSTR("G1 X200 Y135 E3.62773"));
  1214. enquecommand_P(PSTR("G1 X200 Y155 E0.66174"));
  1215. enquecommand_P(PSTR("G1 X100 Y155 E2.62773"));
  1216. enquecommand_P(PSTR("G1 X75 Y155 E2"));
  1217. enquecommand_P(PSTR("G1 X50 Y155 E2.5"));
  1218. enquecommand_P(PSTR("G1 E - 0.07500 F2100.00000"));*/
  1219. enquecommand_P(PSTR("G1 X50 Y155"));
  1220. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  1221. enquecommand_P(PSTR("G1 F1080"));
  1222. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  1223. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  1224. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  1225. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  1226. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  1227. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  1228. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  1229. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  1230. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  1231. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  1232. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  1233. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  1234. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  1235. strcpy(cmd1, "G1 X50 Y35 E");
  1236. strcat(cmd1, ftostr43(extr));
  1237. enquecommand(cmd1);
  1238. lcd_commands_step = 6;
  1239. }
  1240. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  1241. {
  1242. lcd_timeoutToStatus.start();
  1243. for (int i = 0; i < 4; i++) {
  1244. strcpy(cmd1, "G1 X70 Y");
  1245. strcat(cmd1, ftostr32(35 - i*width * 2));
  1246. strcat(cmd1, " E");
  1247. strcat(cmd1, ftostr43(extr));
  1248. enquecommand(cmd1);
  1249. strcpy(cmd1, "G1 Y");
  1250. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1251. strcat(cmd1, " E");
  1252. strcat(cmd1, ftostr43(extr_short_segment));
  1253. enquecommand(cmd1);
  1254. strcpy(cmd1, "G1 X50 Y");
  1255. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1256. strcat(cmd1, " E");
  1257. strcat(cmd1, ftostr43(extr));
  1258. enquecommand(cmd1);
  1259. strcpy(cmd1, "G1 Y");
  1260. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1261. strcat(cmd1, " E");
  1262. strcat(cmd1, ftostr43(extr_short_segment));
  1263. enquecommand(cmd1);
  1264. }
  1265. lcd_commands_step = 5;
  1266. }
  1267. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  1268. {
  1269. lcd_timeoutToStatus.start();
  1270. for (int i = 4; i < 8; i++) {
  1271. strcpy(cmd1, "G1 X70 Y");
  1272. strcat(cmd1, ftostr32(35 - i*width * 2));
  1273. strcat(cmd1, " E");
  1274. strcat(cmd1, ftostr43(extr));
  1275. enquecommand(cmd1);
  1276. strcpy(cmd1, "G1 Y");
  1277. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1278. strcat(cmd1, " E");
  1279. strcat(cmd1, ftostr43(extr_short_segment));
  1280. enquecommand(cmd1);
  1281. strcpy(cmd1, "G1 X50 Y");
  1282. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1283. strcat(cmd1, " E");
  1284. strcat(cmd1, ftostr43(extr));
  1285. enquecommand(cmd1);
  1286. strcpy(cmd1, "G1 Y");
  1287. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1288. strcat(cmd1, " E");
  1289. strcat(cmd1, ftostr43(extr_short_segment));
  1290. enquecommand(cmd1);
  1291. }
  1292. lcd_commands_step = 4;
  1293. }
  1294. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  1295. {
  1296. lcd_timeoutToStatus.start();
  1297. for (int i = 8; i < 12; i++) {
  1298. strcpy(cmd1, "G1 X70 Y");
  1299. strcat(cmd1, ftostr32(35 - i*width * 2));
  1300. strcat(cmd1, " E");
  1301. strcat(cmd1, ftostr43(extr));
  1302. enquecommand(cmd1);
  1303. strcpy(cmd1, "G1 Y");
  1304. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1305. strcat(cmd1, " E");
  1306. strcat(cmd1, ftostr43(extr_short_segment));
  1307. enquecommand(cmd1);
  1308. strcpy(cmd1, "G1 X50 Y");
  1309. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1310. strcat(cmd1, " E");
  1311. strcat(cmd1, ftostr43(extr));
  1312. enquecommand(cmd1);
  1313. strcpy(cmd1, "G1 Y");
  1314. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1315. strcat(cmd1, " E");
  1316. strcat(cmd1, ftostr43(extr_short_segment));
  1317. enquecommand(cmd1);
  1318. }
  1319. lcd_commands_step = 3;
  1320. }
  1321. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  1322. {
  1323. lcd_timeoutToStatus.start();
  1324. for (int i = 12; i < 16; i++) {
  1325. strcpy(cmd1, "G1 X70 Y");
  1326. strcat(cmd1, ftostr32(35 - i*width * 2));
  1327. strcat(cmd1, " E");
  1328. strcat(cmd1, ftostr43(extr));
  1329. enquecommand(cmd1);
  1330. strcpy(cmd1, "G1 Y");
  1331. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1332. strcat(cmd1, " E");
  1333. strcat(cmd1, ftostr43(extr_short_segment));
  1334. enquecommand(cmd1);
  1335. strcpy(cmd1, "G1 X50 Y");
  1336. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1337. strcat(cmd1, " E");
  1338. strcat(cmd1, ftostr43(extr));
  1339. enquecommand(cmd1);
  1340. strcpy(cmd1, "G1 Y");
  1341. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1342. strcat(cmd1, " E");
  1343. strcat(cmd1, ftostr43(extr_short_segment));
  1344. enquecommand(cmd1);
  1345. }
  1346. lcd_commands_step = 2;
  1347. }
  1348. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  1349. {
  1350. lcd_timeoutToStatus.start();
  1351. enquecommand_P(PSTR("M107")); //turn off printer fan
  1352. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract
  1353. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  1354. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  1355. enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z
  1356. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position
  1357. if (mmu_enabled) enquecommand_P(PSTR("M702 C")); //unload from nozzle
  1358. enquecommand_P(PSTR("M84"));// disable motors
  1359. forceMenuExpire = true; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  1360. lcd_commands_step = 1;
  1361. }
  1362. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1363. {
  1364. lcd_setstatuspgm(_T(WELCOME_MSG));
  1365. lcd_commands_step = 0;
  1366. lcd_commands_type = 0;
  1367. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1368. lcd_wizard(WizState::RepeatLay1Cal);
  1369. }
  1370. }
  1371. }
  1372. #endif // not SNMM
  1373. if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print
  1374. {
  1375. if (lcd_commands_step == 0)
  1376. {
  1377. lcd_commands_step = 6;
  1378. }
  1379. if (lcd_commands_step == 1 && !blocks_queued())
  1380. {
  1381. lcd_commands_step = 0;
  1382. lcd_commands_type = 0;
  1383. lcd_setstatuspgm(_T(WELCOME_MSG));
  1384. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  1385. isPrintPaused = false;
  1386. }
  1387. if (lcd_commands_step == 2 && !blocks_queued())
  1388. {
  1389. setTargetBed(0);
  1390. enquecommand_P(PSTR("M104 S0")); //set hotend temp to 0
  1391. manage_heater();
  1392. lcd_setstatuspgm(_T(WELCOME_MSG));
  1393. cancel_heatup = false;
  1394. lcd_commands_step = 1;
  1395. }
  1396. if (lcd_commands_step == 3 && !blocks_queued())
  1397. {
  1398. // M84: Disable steppers.
  1399. enquecommand_P(PSTR("M84"));
  1400. autotempShutdown();
  1401. lcd_commands_step = 2;
  1402. }
  1403. if (lcd_commands_step == 4 && !blocks_queued())
  1404. {
  1405. lcd_setstatuspgm(_T(MSG_PLEASE_WAIT));
  1406. // G90: Absolute positioning.
  1407. enquecommand_P(PSTR("G90"));
  1408. // M83: Set extruder to relative mode.
  1409. enquecommand_P(PSTR("M83"));
  1410. #ifdef X_CANCEL_POS
  1411. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1412. #else
  1413. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  1414. #endif
  1415. lcd_ignore_click(false);
  1416. if (mmu_enabled)
  1417. lcd_commands_step = 8;
  1418. else
  1419. lcd_commands_step = 3;
  1420. }
  1421. if (lcd_commands_step == 5 && !blocks_queued())
  1422. {
  1423. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  1424. // G91: Set to relative positioning.
  1425. enquecommand_P(PSTR("G91"));
  1426. // Lift up.
  1427. enquecommand_P(PSTR("G1 Z15 F1500"));
  1428. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) lcd_commands_step = 4;
  1429. else lcd_commands_step = 3;
  1430. }
  1431. if (lcd_commands_step == 6 && !blocks_queued())
  1432. {
  1433. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  1434. cancel_heatup = true;
  1435. setTargetBed(0);
  1436. if (mmu_enabled)
  1437. setAllTargetHotends(0);
  1438. manage_heater();
  1439. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
  1440. lcd_commands_step = 5;
  1441. }
  1442. if (lcd_commands_step == 7 && !blocks_queued())
  1443. {
  1444. if (mmu_enabled)
  1445. enquecommand_P(PSTR("M702 C")); //current
  1446. else
  1447. switch(snmm_stop_print_menu())
  1448. {
  1449. case 0: enquecommand_P(PSTR("M702")); break;//all
  1450. case 1: enquecommand_P(PSTR("M702 U")); break; //used
  1451. case 2: enquecommand_P(PSTR("M702 C")); break; //current
  1452. default: enquecommand_P(PSTR("M702")); break;
  1453. }
  1454. lcd_commands_step = 3;
  1455. }
  1456. 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)
  1457. lcd_commands_step = 7;
  1458. }
  1459. }
  1460. if (lcd_commands_type == 3)
  1461. {
  1462. lcd_commands_type = 0;
  1463. }
  1464. if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
  1465. {
  1466. if (lcd_commands_step == 0) { lcd_commands_step = 6; }
  1467. if (lcd_commands_step == 1 && !blocks_queued())
  1468. {
  1469. lcd_confirm_print();
  1470. lcd_commands_step = 0;
  1471. lcd_commands_type = 0;
  1472. }
  1473. if (lcd_commands_step == 2 && !blocks_queued())
  1474. {
  1475. lcd_commands_step = 1;
  1476. }
  1477. if (lcd_commands_step == 3 && !blocks_queued())
  1478. {
  1479. lcd_commands_step = 2;
  1480. }
  1481. if (lcd_commands_step == 4 && !blocks_queued())
  1482. {
  1483. enquecommand_P(PSTR("G90"));
  1484. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1485. lcd_commands_step = 3;
  1486. }
  1487. if (lcd_commands_step == 5 && !blocks_queued())
  1488. {
  1489. lcd_commands_step = 4;
  1490. }
  1491. if (lcd_commands_step == 6 && !blocks_queued())
  1492. {
  1493. enquecommand_P(PSTR("G91"));
  1494. enquecommand_P(PSTR("G1 Z15 F1500"));
  1495. st_synchronize();
  1496. #ifdef SNMM
  1497. lcd_commands_step = 7;
  1498. #else
  1499. lcd_commands_step = 5;
  1500. #endif
  1501. }
  1502. }
  1503. if (lcd_commands_type == LCD_COMMAND_PID_EXTRUDER) {
  1504. char cmd1[30];
  1505. if (lcd_commands_step == 0) {
  1506. custom_message_type = CUSTOM_MSG_TYPE_PIDCAL;
  1507. custom_message_state = 1;
  1508. lcd_draw_update = 3;
  1509. lcd_commands_step = 3;
  1510. }
  1511. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  1512. strcpy(cmd1, "M303 E0 S");
  1513. strcat(cmd1, ftostr3(pid_temp));
  1514. enquecommand(cmd1);
  1515. lcd_setstatuspgm(_i("PID cal. "));////MSG_PID_RUNNING c=20 r=1
  1516. lcd_commands_step = 2;
  1517. }
  1518. if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom
  1519. pid_tuning_finished = false;
  1520. custom_message_state = 0;
  1521. lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20 r=1
  1522. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  1523. strcpy(cmd1, "M301 P");
  1524. strcat(cmd1, ftostr32(_Kp));
  1525. strcat(cmd1, " I");
  1526. strcat(cmd1, ftostr32(_Ki));
  1527. strcat(cmd1, " D");
  1528. strcat(cmd1, ftostr32(_Kd));
  1529. enquecommand(cmd1);
  1530. enquecommand_P(PSTR("M500"));
  1531. }
  1532. else {
  1533. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  1534. }
  1535. display_time = millis();
  1536. lcd_commands_step = 1;
  1537. }
  1538. if ((lcd_commands_step == 1) && ((millis()- display_time)>2000)) { //calibration finished message
  1539. lcd_setstatuspgm(_T(WELCOME_MSG));
  1540. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  1541. pid_temp = DEFAULT_PID_TEMP;
  1542. lcd_commands_step = 0;
  1543. lcd_commands_type = 0;
  1544. }
  1545. }
  1546. }
  1547. static float count_e(float layer_heigth, float extrusion_width, float extrusion_length) {
  1548. //returns filament length in mm which needs to be extrude to form line with extrusion_length * extrusion_width * layer heigth dimensions
  1549. float extr = extrusion_length * layer_heigth * extrusion_width / (M_PI * pow(1.75, 2) / 4);
  1550. return extr;
  1551. }
  1552. void lcd_return_to_status()
  1553. {
  1554. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  1555. menu_goto(lcd_status_screen, 0, false, true);
  1556. menu_depth = 0;
  1557. }
  1558. //! @brief Pause print, disable nozzle heater, move to park position
  1559. void lcd_pause_print()
  1560. {
  1561. lcd_return_to_status();
  1562. stop_and_save_print_to_ram(0.0,0.0);
  1563. setAllTargetHotends(0);
  1564. isPrintPaused = true;
  1565. if (LCD_COMMAND_IDLE == lcd_commands_type)
  1566. {
  1567. lcd_commands_type = LCD_COMMAND_LONG_PAUSE;
  1568. }
  1569. }
  1570. float move_menu_scale;
  1571. static void lcd_move_menu_axis();
  1572. /* Menu implementation */
  1573. void lcd_preheat_farm()
  1574. {
  1575. setTargetHotend0(FARM_PREHEAT_HOTEND_TEMP);
  1576. setTargetBed(FARM_PREHEAT_HPB_TEMP);
  1577. fanSpeed = 0;
  1578. lcd_return_to_status();
  1579. setWatch(); // heater sanity check timer
  1580. }
  1581. void lcd_preheat_farm_nozzle()
  1582. {
  1583. setTargetHotend0(FARM_PREHEAT_HOTEND_TEMP);
  1584. setTargetBed(0);
  1585. fanSpeed = 0;
  1586. lcd_return_to_status();
  1587. setWatch(); // heater sanity check timer
  1588. }
  1589. void lcd_preheat_pla()
  1590. {
  1591. setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);
  1592. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  1593. fanSpeed = 0;
  1594. lcd_return_to_status();
  1595. setWatch(); // heater sanity check timer
  1596. }
  1597. void lcd_preheat_abs()
  1598. {
  1599. setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);
  1600. setTargetBed(ABS_PREHEAT_HPB_TEMP);
  1601. fanSpeed = 0;
  1602. lcd_return_to_status();
  1603. setWatch(); // heater sanity check timer
  1604. }
  1605. void lcd_preheat_pp()
  1606. {
  1607. setTargetHotend0(PP_PREHEAT_HOTEND_TEMP);
  1608. setTargetBed(PP_PREHEAT_HPB_TEMP);
  1609. fanSpeed = 0;
  1610. lcd_return_to_status();
  1611. setWatch(); // heater sanity check timer
  1612. }
  1613. void lcd_preheat_pet()
  1614. {
  1615. setTargetHotend0(PET_PREHEAT_HOTEND_TEMP);
  1616. setTargetBed(PET_PREHEAT_HPB_TEMP);
  1617. fanSpeed = 0;
  1618. lcd_return_to_status();
  1619. setWatch(); // heater sanity check timer
  1620. }
  1621. void lcd_preheat_hips()
  1622. {
  1623. setTargetHotend0(HIPS_PREHEAT_HOTEND_TEMP);
  1624. setTargetBed(HIPS_PREHEAT_HPB_TEMP);
  1625. fanSpeed = 0;
  1626. lcd_return_to_status();
  1627. setWatch(); // heater sanity check timer
  1628. }
  1629. void lcd_preheat_flex()
  1630. {
  1631. setTargetHotend0(FLEX_PREHEAT_HOTEND_TEMP);
  1632. setTargetBed(FLEX_PREHEAT_HPB_TEMP);
  1633. fanSpeed = 0;
  1634. lcd_return_to_status();
  1635. setWatch(); // heater sanity check timer
  1636. }
  1637. void lcd_cooldown()
  1638. {
  1639. setAllTargetHotends(0);
  1640. setTargetBed(0);
  1641. fanSpeed = 0;
  1642. lcd_return_to_status();
  1643. }
  1644. static void lcd_menu_extruder_info()
  1645. {
  1646. //|01234567890123456789|
  1647. //|Nozzle FAN: RPM|
  1648. //|Print FAN: RPM|
  1649. //|Fil. Xd: Yd: |
  1650. //|Int: Shut: |
  1651. //----------------------
  1652. int fan_speed_RPM[2];
  1653. // Display Nozzle fan RPM
  1654. fan_speed_RPM[0] = 60*fan_speed[0];
  1655. fan_speed_RPM[1] = 60*fan_speed[1];
  1656. lcd_timeoutToStatus.stop(); //infinite timeout
  1657. lcd_printf_P(_N(
  1658. ESC_H(0,0)
  1659. "Nozzle FAN: %4d RPM\n"
  1660. "Print FAN: %4d RPM\n"
  1661. ),
  1662. fan_speed_RPM[0],
  1663. fan_speed_RPM[1]
  1664. );
  1665. #ifdef FILAMENT_SENSOR
  1666. // Display X and Y difference from Filament sensor
  1667. // Display Light intensity from Filament sensor
  1668. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  1669. // value ranges from 0(darkest) to 255(brightest).
  1670. // Display LASER shutter time from Filament sensor
  1671. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  1672. // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  1673. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46.
  1674. if (mmu_enabled == false)
  1675. {
  1676. if (!fsensor_enabled)
  1677. lcd_puts_P(_N("Filament sensor\n" "is disabled."));
  1678. else
  1679. {
  1680. if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  1681. pat9125_update();
  1682. lcd_printf_P(_N(
  1683. "Fil. Xd:%3d Yd:%3d\n"
  1684. "Int: %3d Shut: %3d"
  1685. ),
  1686. pat9125_x, pat9125_y,
  1687. pat9125_b, pat9125_s
  1688. );
  1689. }
  1690. }
  1691. #endif //FILAMENT_SENSOR
  1692. menu_back_if_clicked();
  1693. }
  1694. #if defined(TMC2130) && defined(FILAMENT_SENSOR)
  1695. static void lcd_menu_fails_stats_total()
  1696. {
  1697. //01234567890123456789
  1698. //Total failures
  1699. // Power failures 000
  1700. // Filam. runouts 000
  1701. // Crash X 000 Y 000
  1702. //////////////////////
  1703. lcd_timeoutToStatus.stop(); //infinite timeout
  1704. uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT);
  1705. uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1706. uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT);
  1707. uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT);
  1708. lcd_printf_P(PSTR(ESC_H(0,0) "Total failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1709. menu_back_if_clicked_fb();
  1710. }
  1711. static void lcd_menu_fails_stats_print()
  1712. {
  1713. //01234567890123456789
  1714. //Last print failures
  1715. // Power failures 000
  1716. // Filam. runouts 000
  1717. // Crash X 000 Y 000
  1718. //////////////////////
  1719. lcd_timeoutToStatus.stop(); //infinite timeout
  1720. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1721. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1722. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1723. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1724. lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1725. menu_back_if_clicked_fb();
  1726. }
  1727. /**
  1728. * @brief Open fail statistics menu
  1729. *
  1730. * This version of function is used, when there is filament sensor,
  1731. * power failure and crash detection.
  1732. * There are Last print and Total menu items.
  1733. */
  1734. static void lcd_menu_fails_stats()
  1735. {
  1736. MENU_BEGIN();
  1737. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1738. MENU_ITEM_SUBMENU_P(PSTR("Last print"), lcd_menu_fails_stats_print);
  1739. MENU_ITEM_SUBMENU_P(PSTR("Total"), lcd_menu_fails_stats_total);
  1740. MENU_END();
  1741. }
  1742. #elif defined(FILAMENT_SENSOR)
  1743. /**
  1744. * @brief Print last print and total filament run outs
  1745. *
  1746. * This version of function is used, when there is filament sensor,
  1747. * but no other sensors (e.g. power failure, crash detection).
  1748. *
  1749. * Example screen:
  1750. * @code
  1751. * 01234567890123456789
  1752. * Last print failures
  1753. * Filam. runouts 0
  1754. * Total failures
  1755. * Filam. runouts 5
  1756. * @endcode
  1757. */
  1758. static void lcd_menu_fails_stats()
  1759. {
  1760. lcd_timeoutToStatus.stop(); //infinite timeout
  1761. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1762. uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1763. lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal);
  1764. menu_back_if_clicked();
  1765. }
  1766. #else
  1767. static void lcd_menu_fails_stats()
  1768. {
  1769. lcd_timeoutToStatus.stop(); //infinite timeout
  1770. MENU_BEGIN();
  1771. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1772. MENU_END();
  1773. }
  1774. #endif //TMC2130
  1775. #ifdef DEBUG_BUILD
  1776. #ifdef DEBUG_STACK_MONITOR
  1777. extern uint16_t SP_min;
  1778. extern char* __malloc_heap_start;
  1779. extern char* __malloc_heap_end;
  1780. #endif //DEBUG_STACK_MONITOR
  1781. static void lcd_menu_debug()
  1782. {
  1783. #ifdef DEBUG_STACK_MONITOR
  1784. lcd_printf_P(PSTR(ESC_H(1,1) "RAM statistics" ESC_H(5,1) "SP_min: 0x%04x" ESC_H(1,2) "heap_start: 0x%04x" ESC_H(3,3) "heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end);
  1785. #endif //DEBUG_STACK_MONITOR
  1786. menu_back_if_clicked_fb();
  1787. }
  1788. #endif /* DEBUG_BUILD */
  1789. static void lcd_menu_temperatures()
  1790. {
  1791. lcd_timeoutToStatus.stop(); //infinite timeout
  1792. lcd_printf_P(PSTR(ESC_H(1,0) "Nozzle: %d%c" ESC_H(1,1) "Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01');
  1793. #ifdef AMBIENT_THERMISTOR
  1794. lcd_printf_P(PSTR(ESC_H(1,2) "Ambient: %d%c" ESC_H(1,3) "PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01');
  1795. #else //AMBIENT_THERMISTOR
  1796. lcd_printf_P(PSTR(ESC_H(1,2) "PINDA: %d%c"), (int)current_temperature_pinda, '\x01');
  1797. #endif //AMBIENT_THERMISTOR
  1798. menu_back_if_clicked();
  1799. }
  1800. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1801. #define VOLT_DIV_R1 10000
  1802. #define VOLT_DIV_R2 2370
  1803. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1804. #define VOLT_DIV_REF 5
  1805. static void lcd_menu_voltages()
  1806. {
  1807. lcd_timeoutToStatus.stop(); //infinite timeout
  1808. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1809. // float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1810. // lcd_printf_P(PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"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)));
  1811. lcd_printf_P(PSTR( ESC_H(1,1)"PWR: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ;
  1812. menu_back_if_clicked();
  1813. }
  1814. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1815. #ifdef TMC2130
  1816. static void lcd_menu_belt_status()
  1817. {
  1818. lcd_printf_P(PSTR(ESC_H(1,0) "Belt status" ESC_H(2,1) "X %d" ESC_H(2,2) "Y %d" ), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1819. menu_back_if_clicked();
  1820. }
  1821. #endif //TMC2130
  1822. #ifdef RESUME_DEBUG
  1823. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1824. extern void restore_print_from_ram_and_continue(float e_move);
  1825. static void lcd_menu_test_save()
  1826. {
  1827. stop_and_save_print_to_ram(10, -0.8);
  1828. }
  1829. static void lcd_menu_test_restore()
  1830. {
  1831. restore_print_from_ram_and_continue(0.8);
  1832. }
  1833. #endif //RESUME_DEBUG
  1834. static void lcd_preheat_menu()
  1835. {
  1836. MENU_BEGIN();
  1837. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1838. if (farm_mode) {
  1839. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), lcd_preheat_farm);
  1840. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), lcd_preheat_farm_nozzle);
  1841. MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1842. MENU_ITEM_FUNCTION_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  1843. } else {
  1844. MENU_ITEM_FUNCTION_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  1845. MENU_ITEM_FUNCTION_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  1846. MENU_ITEM_FUNCTION_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  1847. MENU_ITEM_FUNCTION_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  1848. MENU_ITEM_FUNCTION_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  1849. MENU_ITEM_FUNCTION_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  1850. MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1851. }
  1852. MENU_END();
  1853. }
  1854. static void lcd_support_menu()
  1855. {
  1856. typedef struct
  1857. { // 22bytes total
  1858. int8_t status; // 1byte
  1859. bool is_flash_air; // 1byte
  1860. uint8_t ip[4]; // 4bytes
  1861. char ip_str[3*4+3+1]; // 16bytes
  1862. } _menu_data_t;
  1863. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  1864. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  1865. if (_md->status == 0 || lcd_draw_update == 2)
  1866. {
  1867. // Menu was entered or SD card status has changed (plugged in or removed).
  1868. // Initialize its status.
  1869. _md->status = 1;
  1870. _md->is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(_md->ip);
  1871. if (_md->is_flash_air)
  1872. sprintf_P(_md->ip_str, PSTR("%d.%d.%d.%d"),
  1873. _md->ip[0], _md->ip[1],
  1874. _md->ip[2], _md->ip[3]);
  1875. } else if (_md->is_flash_air &&
  1876. _md->ip[0] == 0 && _md->ip[1] == 0 &&
  1877. _md->ip[2] == 0 && _md->ip[3] == 0 &&
  1878. ++ _md->status == 16)
  1879. {
  1880. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1881. _md->status = 0;
  1882. }
  1883. MENU_BEGIN();
  1884. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1885. MENU_ITEM_BACK_P(PSTR("Firmware:"));
  1886. MENU_ITEM_BACK_P(PSTR(" " FW_VERSION_FULL));
  1887. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1888. MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
  1889. #endif
  1890. // Ideally this block would be optimized out by the compiler.
  1891. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1892. if (fw_string_len < 6) {
  1893. MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
  1894. } else {
  1895. MENU_ITEM_BACK_P(PSTR("FW - " FW_version));
  1896. }*/
  1897. MENU_ITEM_BACK_P(_i("prusa3d.com"));////MSG_PRUSA3D c=0 r=0
  1898. MENU_ITEM_BACK_P(_i("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=0 r=0
  1899. MENU_ITEM_BACK_P(_i("howto.prusa3d.com"));////MSG_PRUSA3D_HOWTO c=0 r=0
  1900. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1901. MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
  1902. MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
  1903. MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
  1904. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1905. MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1
  1906. MENU_ITEM_BACK_P(PSTR(__DATE__));
  1907. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1908. if (mmu_enabled)
  1909. {
  1910. MENU_ITEM_BACK_P(PSTR("MMU2 connected"));
  1911. MENU_ITEM_BACK_P(PSTR(" FW:"));
  1912. if (((menu_item - 1) == menu_line) && lcd_draw_update)
  1913. {
  1914. lcd_set_cursor(6, menu_row);
  1915. if ((mmu_version > 0) && (mmu_buildnr > 0))
  1916. lcd_printf_P(PSTR("%d.%d.%d-%d"), mmu_version/100, mmu_version%100/10, mmu_version%10, mmu_buildnr);
  1917. else
  1918. lcd_puts_P(PSTR("unknown"));
  1919. }
  1920. }
  1921. else
  1922. MENU_ITEM_BACK_P(PSTR("MMU2 N/A"));
  1923. // Show the FlashAir IP address, if the card is available.
  1924. if (_md->is_flash_air) {
  1925. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1926. MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:"));
  1927. ///! MENU_ITEM(back_RAM, _md->ip_str, 0);
  1928. }
  1929. #ifndef MK1BP
  1930. MENU_ITEM_BACK_P(STR_SEPARATOR);
  1931. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1
  1932. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1
  1933. #ifdef TMC2130
  1934. MENU_ITEM_SUBMENU_P(_i("Belt status"), lcd_menu_belt_status);////MSG_MENU_BELT_STATUS c=15 r=1
  1935. #endif //TMC2130
  1936. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=15 r=1
  1937. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1938. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=15 r=1
  1939. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1940. #ifdef DEBUG_BUILD
  1941. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);
  1942. #endif /* DEBUG_BUILD */
  1943. #endif //MK1BP
  1944. MENU_END();
  1945. }
  1946. void lcd_set_fan_check() {
  1947. fans_check_enabled = !fans_check_enabled;
  1948. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1949. }
  1950. void lcd_set_filament_autoload() {
  1951. fsensor_autoload_set(!fsensor_autoload_enabled);
  1952. }
  1953. void lcd_unLoadFilament()
  1954. {
  1955. if (degHotend0() > EXTRUDE_MINTEMP) {
  1956. enquecommand_P(PSTR("M702")); //unload filament
  1957. } else {
  1958. lcd_clear();
  1959. lcd_set_cursor(0, 0);
  1960. lcd_puts_P(_T(MSG_ERROR));
  1961. lcd_set_cursor(0, 2);
  1962. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  1963. delay(2000);
  1964. lcd_clear();
  1965. }
  1966. menu_back();
  1967. }
  1968. void lcd_change_filament() {
  1969. lcd_clear();
  1970. lcd_set_cursor(0, 1);
  1971. lcd_puts_P(_i("Changing filament!"));////MSG_CHANGING_FILAMENT c=20 r=0
  1972. }
  1973. void lcd_wait_interact() {
  1974. lcd_clear();
  1975. lcd_set_cursor(0, 1);
  1976. #ifdef SNMM
  1977. lcd_puts_P(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20 r=1
  1978. #else
  1979. lcd_puts_P(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20 r=0
  1980. #endif
  1981. lcd_set_cursor(0, 2);
  1982. lcd_puts_P(_i("and press the knob"));////MSG_PRESS c=20 r=0
  1983. }
  1984. void lcd_change_success() {
  1985. lcd_clear();
  1986. lcd_set_cursor(0, 2);
  1987. lcd_puts_P(_i("Change success!"));////MSG_CHANGE_SUCCESS c=0 r=0
  1988. }
  1989. void lcd_loading_color() {
  1990. lcd_clear();
  1991. lcd_set_cursor(0, 0);
  1992. lcd_puts_P(_i("Loading color"));////MSG_LOADING_COLOR c=0 r=0
  1993. lcd_set_cursor(0, 2);
  1994. lcd_puts_P(_T(MSG_PLEASE_WAIT));
  1995. for (int i = 0; i < 20; i++) {
  1996. lcd_set_cursor(i, 3);
  1997. lcd_print(".");
  1998. for (int j = 0; j < 10 ; j++) {
  1999. manage_heater();
  2000. manage_inactivity(true);
  2001. delay(85);
  2002. }
  2003. }
  2004. }
  2005. void lcd_loading_filament() {
  2006. lcd_clear();
  2007. lcd_set_cursor(0, 0);
  2008. lcd_puts_P(_T(MSG_LOADING_FILAMENT));
  2009. lcd_set_cursor(0, 2);
  2010. lcd_puts_P(_T(MSG_PLEASE_WAIT));
  2011. for (int i = 0; i < 20; i++) {
  2012. lcd_set_cursor(i, 3);
  2013. lcd_print(".");
  2014. for (int j = 0; j < 10 ; j++) {
  2015. manage_heater();
  2016. manage_inactivity(true);
  2017. #ifdef SNMM
  2018. delay(153);
  2019. #else
  2020. delay(137);
  2021. #endif
  2022. }
  2023. }
  2024. }
  2025. void lcd_alright() {
  2026. int enc_dif = 0;
  2027. int cursor_pos = 1;
  2028. lcd_clear();
  2029. lcd_set_cursor(0, 0);
  2030. lcd_puts_P(_i("Changed correctly?"));////MSG_CORRECTLY c=20 r=0
  2031. lcd_set_cursor(1, 1);
  2032. lcd_puts_P(_T(MSG_YES));
  2033. lcd_set_cursor(1, 2);
  2034. lcd_puts_P(_i("Filament not loaded"));////MSG_NOT_LOADED c=19 r=0
  2035. lcd_set_cursor(1, 3);
  2036. lcd_puts_P(_i("Color not correct"));////MSG_NOT_COLOR c=0 r=0
  2037. lcd_set_cursor(0, 1);
  2038. lcd_print(">");
  2039. enc_dif = lcd_encoder_diff;
  2040. while (lcd_change_fil_state == 0) {
  2041. manage_heater();
  2042. manage_inactivity(true);
  2043. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2044. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2045. if (enc_dif > lcd_encoder_diff ) {
  2046. cursor_pos --;
  2047. }
  2048. if (enc_dif < lcd_encoder_diff ) {
  2049. cursor_pos ++;
  2050. }
  2051. if (cursor_pos > 3) {
  2052. cursor_pos = 3;
  2053. }
  2054. if (cursor_pos < 1) {
  2055. cursor_pos = 1;
  2056. }
  2057. lcd_set_cursor(0, 1);
  2058. lcd_print(" ");
  2059. lcd_set_cursor(0, 2);
  2060. lcd_print(" ");
  2061. lcd_set_cursor(0, 3);
  2062. lcd_print(" ");
  2063. lcd_set_cursor(0, cursor_pos);
  2064. lcd_print(">");
  2065. enc_dif = lcd_encoder_diff;
  2066. delay(100);
  2067. }
  2068. }
  2069. if (lcd_clicked()) {
  2070. lcd_change_fil_state = cursor_pos;
  2071. delay(500);
  2072. }
  2073. };
  2074. lcd_clear();
  2075. lcd_return_to_status();
  2076. }
  2077. #ifdef FILAMENT_SENSOR
  2078. static void lcd_menu_AutoLoadFilament()
  2079. {
  2080. if (degHotend0() > EXTRUDE_MINTEMP)
  2081. {
  2082. uint8_t nlines;
  2083. 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
  2084. }
  2085. else
  2086. {
  2087. static_assert(sizeof(menu_data)>=sizeof(ShortTimer), "ShortTimer doesn't fit into menu_data");
  2088. ShortTimer* ptimer = (ShortTimer*)&(menu_data[0]);
  2089. if (!ptimer->running()) ptimer->start();
  2090. lcd_set_cursor(0, 0);
  2091. lcd_puts_P(_T(MSG_ERROR));
  2092. lcd_set_cursor(0, 2);
  2093. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  2094. if (ptimer->expired(2000ul)) menu_back();
  2095. }
  2096. menu_back_if_clicked();
  2097. }
  2098. #endif //FILAMENT_SENSOR
  2099. static void lcd_LoadFilament()
  2100. {
  2101. if (degHotend0() > EXTRUDE_MINTEMP)
  2102. {
  2103. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
  2104. loading_flag = true;
  2105. enquecommand_P(PSTR("M701")); //load filament
  2106. SERIAL_ECHOLN("Loading filament");
  2107. lcd_return_to_status();
  2108. }
  2109. else
  2110. {
  2111. lcd_clear();
  2112. lcd_set_cursor(0, 0);
  2113. lcd_puts_P(_T(MSG_ERROR));
  2114. lcd_set_cursor(0, 2);
  2115. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  2116. delay(2000);
  2117. lcd_clear();
  2118. }
  2119. }
  2120. void lcd_menu_statistics()
  2121. {
  2122. if (IS_SD_PRINTING)
  2123. {
  2124. float _met = ((float)total_filament_used) / (100000.f);
  2125. int _t = (millis() - starttime) / 1000;
  2126. int _h = _t / 3600;
  2127. int _m = (_t - (_h * 3600)) / 60;
  2128. int _s = _t - ((_h * 3600) + (_m * 60));
  2129. //|01234567890123456789|
  2130. //|Filament used: |
  2131. //| 000m 00.000cm |
  2132. //|Print time: |
  2133. //| 00h 00m 00s |
  2134. //----------------------
  2135. lcd_printf_P(_N(
  2136. ESC_2J
  2137. "%S:"
  2138. ESC_H(6,1) "%8.2fm \n"
  2139. "%S :"
  2140. ESC_H(8,3) "%2dh %02dm %02d"
  2141. ),
  2142. _i("Filament used"),
  2143. _met,
  2144. _i("Print time"),
  2145. _h, _m, _s
  2146. );
  2147. menu_back_if_clicked_fb();
  2148. }
  2149. else
  2150. {
  2151. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  2152. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  2153. uint8_t _hours, _minutes;
  2154. uint32_t _days;
  2155. float _filament_m = (float)_filament/100;
  2156. // int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  2157. // if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  2158. _days = _time / 1440;
  2159. _hours = (_time - (_days * 1440)) / 60;
  2160. _minutes = _time - ((_days * 1440) + (_hours * 60));
  2161. //|01234567890123456789|
  2162. //|Total filament : |
  2163. //| 000.00 m |
  2164. //|Total print time : |
  2165. //| 00d :00h :00 m |
  2166. //----------------------
  2167. lcd_printf_P(_N(
  2168. ESC_2J
  2169. "%S :"
  2170. ESC_H(9,1) "%8.2f m\n"
  2171. "%S :\n"
  2172. "%7ldd :%2hhdh :%02hhd m"
  2173. ),
  2174. _i("Total filament"),
  2175. _filament_m,
  2176. _i("Total print time"),
  2177. _days, _hours, _minutes
  2178. );
  2179. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2180. while (!lcd_clicked())
  2181. {
  2182. manage_heater();
  2183. manage_inactivity(true);
  2184. delay(100);
  2185. }
  2186. KEEPALIVE_STATE(NOT_BUSY);
  2187. lcd_quick_feedback();
  2188. menu_back();
  2189. }
  2190. }
  2191. static void _lcd_move(const char *name, int axis, int min, int max)
  2192. {
  2193. typedef struct
  2194. { // 2bytes total
  2195. bool initialized; // 1byte
  2196. bool endstopsEnabledPrevious; // 1byte
  2197. } _menu_data_t;
  2198. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2199. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2200. if (!_md->initialized)
  2201. {
  2202. _md->endstopsEnabledPrevious = enable_endstops(false);
  2203. _md->initialized = true;
  2204. }
  2205. if (lcd_encoder != 0)
  2206. {
  2207. refresh_cmd_timeout();
  2208. if (! planner_queue_full())
  2209. {
  2210. current_position[axis] += float((int)lcd_encoder) * move_menu_scale;
  2211. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2212. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2213. lcd_encoder = 0;
  2214. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2215. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis] / 60, active_extruder);
  2216. lcd_draw_update = 1;
  2217. }
  2218. }
  2219. if (lcd_draw_update)
  2220. {
  2221. lcd_set_cursor(0, 1);
  2222. menu_draw_float31(' ', name, current_position[axis]);
  2223. }
  2224. if (menu_leaving || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious);
  2225. if (LCD_CLICKED) menu_back();
  2226. }
  2227. static void lcd_move_e()
  2228. {
  2229. if (degHotend0() > EXTRUDE_MINTEMP)
  2230. {
  2231. if (lcd_encoder != 0)
  2232. {
  2233. refresh_cmd_timeout();
  2234. if (! planner_queue_full())
  2235. {
  2236. current_position[E_AXIS] += float((int)lcd_encoder) * move_menu_scale;
  2237. lcd_encoder = 0;
  2238. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS] / 60, active_extruder);
  2239. lcd_draw_update = 1;
  2240. }
  2241. }
  2242. if (lcd_draw_update)
  2243. {
  2244. lcd_set_cursor(0, 1);
  2245. menu_draw_float31(' ', PSTR("Extruder"), current_position[E_AXIS]);
  2246. }
  2247. if (LCD_CLICKED) menu_back();
  2248. }
  2249. else
  2250. {
  2251. lcd_clear();
  2252. lcd_set_cursor(0, 0);
  2253. lcd_puts_P(_T(MSG_ERROR));
  2254. lcd_set_cursor(0, 2);
  2255. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  2256. delay(2000);
  2257. lcd_return_to_status();
  2258. }
  2259. }
  2260. //@brief Show measured Y distance of front calibration points from Y_MIN_POS
  2261. //If those points are detected too close to edge of reachable area, their confidence is lowered.
  2262. //This functionality is applied more often for MK2 printers.
  2263. static void lcd_menu_xyz_y_min()
  2264. {
  2265. //|01234567890123456789|
  2266. //|Y distance from min:|
  2267. //|--------------------|
  2268. //|Left: N/A |
  2269. //|Right: N/A |
  2270. //----------------------
  2271. float distanceMin[2];
  2272. count_xyz_details(distanceMin);
  2273. lcd_printf_P(_N(
  2274. ESC_H(0,0)
  2275. "%S:\n"
  2276. "%S\n"
  2277. "%S:\n"
  2278. "%S:"
  2279. ),
  2280. _i("Y distance from min"),
  2281. separator,
  2282. _i("Left"),
  2283. _i("Right")
  2284. );
  2285. for (uint8_t i = 0; i < 2; i++)
  2286. {
  2287. lcd_set_cursor(11,2+i);
  2288. if (distanceMin[i] >= 200) lcd_puts_P(_N("N/A"));
  2289. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2290. }
  2291. if (lcd_clicked())
  2292. menu_goto(lcd_menu_xyz_skew, 0, true, true);
  2293. }
  2294. //@brief Show measured axis skewness
  2295. float _deg(float rad)
  2296. {
  2297. return rad * 180 / M_PI;
  2298. }
  2299. static void lcd_menu_xyz_skew()
  2300. {
  2301. //|01234567890123456789|
  2302. //|Measured skew: N/A |
  2303. //|--------------------|
  2304. //|Slight skew: 0.12d|
  2305. //|Severe skew: 0.25d|
  2306. //----------------------
  2307. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2308. lcd_printf_P(_N(
  2309. ESC_H(0,0)
  2310. "%S:\n"
  2311. "%S\n"
  2312. "%S: %5.2f\x01\n"
  2313. "%S: %5.2f\x01"
  2314. ),
  2315. _i("Measured skew"),
  2316. separator,
  2317. _i("Slight skew"), _deg(bed_skew_angle_mild),
  2318. _i("Severe skew"), _deg(bed_skew_angle_extreme)
  2319. );
  2320. if (angleDiff < 100)
  2321. lcd_printf_P(_N(ESC_H(15,0)"%4.2f\x01"), _deg(angleDiff));
  2322. else
  2323. lcd_puts_P(_N(ESC_H(15,0)"N/A"));
  2324. if (lcd_clicked())
  2325. menu_goto(lcd_menu_xyz_offset, 0, true, true);
  2326. }
  2327. /**
  2328. * @brief Show measured bed offset from expected position
  2329. */
  2330. static void lcd_menu_xyz_offset()
  2331. {
  2332. lcd_set_cursor(0,0);
  2333. lcd_puts_P(_i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=0 r=0
  2334. lcd_puts_at_P(0, 1, separator);
  2335. lcd_puts_at_P(0, 2, PSTR("X"));
  2336. lcd_puts_at_P(0, 3, PSTR("Y"));
  2337. float vec_x[2];
  2338. float vec_y[2];
  2339. float cntr[2];
  2340. world2machine_read_valid(vec_x, vec_y, cntr);
  2341. for (int i = 0; i < 2; i++)
  2342. {
  2343. lcd_puts_at_P(11, i + 2, PSTR(""));
  2344. lcd_print(cntr[i]);
  2345. lcd_puts_at_P((cntr[i] < 0) ? 17 : 16, i + 2, PSTR("mm"));
  2346. }
  2347. menu_back_if_clicked();
  2348. }
  2349. // Save a single axis babystep value.
  2350. void EEPROM_save_B(int pos, int* value)
  2351. {
  2352. eeprom_update_byte((unsigned char*)pos, (unsigned char)((*value) & 0xff));
  2353. eeprom_update_byte((unsigned char*)pos + 1, (unsigned char)((*value) >> 8));
  2354. }
  2355. // Read a single axis babystep value.
  2356. void EEPROM_read_B(int pos, int* value)
  2357. {
  2358. *value = (int)eeprom_read_byte((unsigned char*)pos) | (int)(eeprom_read_byte((unsigned char*)pos + 1) << 8);
  2359. }
  2360. static void lcd_move_x() {
  2361. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2362. }
  2363. static void lcd_move_y() {
  2364. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2365. }
  2366. static void lcd_move_z() {
  2367. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2368. }
  2369. /**
  2370. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2371. *
  2372. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2373. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2374. * Purpose of this function for other axis then Z is unknown.
  2375. *
  2376. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2377. * other value leads to storing Z_AXIS
  2378. * @param msg text to be displayed
  2379. */
  2380. static void _lcd_babystep(int axis, const char *msg)
  2381. {
  2382. typedef struct
  2383. { // 19bytes total
  2384. int8_t status; // 1byte
  2385. int babystepMem[3]; // 6bytes
  2386. float babystepMemMM[3]; // 12bytes
  2387. } _menu_data_t;
  2388. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  2389. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  2390. if (_md->status == 0)
  2391. {
  2392. // Menu was entered.
  2393. // Initialize its status.
  2394. _md->status = 1;
  2395. check_babystep();
  2396. EEPROM_read_B(EEPROM_BABYSTEP_X, &_md->babystepMem[0]);
  2397. EEPROM_read_B(EEPROM_BABYSTEP_Y, &_md->babystepMem[1]);
  2398. EEPROM_read_B(EEPROM_BABYSTEP_Z, &_md->babystepMem[2]);
  2399. // same logic as in babystep_load
  2400. if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST)
  2401. _md->babystepMem[2] = 0;
  2402. _md->babystepMemMM[0] = _md->babystepMem[0]/axis_steps_per_unit[X_AXIS];
  2403. _md->babystepMemMM[1] = _md->babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  2404. _md->babystepMemMM[2] = _md->babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  2405. lcd_draw_update = 1;
  2406. //SERIAL_ECHO("Z baby step: ");
  2407. //SERIAL_ECHO(_md->babystepMem[2]);
  2408. // Wait 90 seconds before closing the live adjust dialog.
  2409. lcd_timeoutToStatus.start();
  2410. }
  2411. if (lcd_encoder != 0)
  2412. {
  2413. if (homing_flag) lcd_encoder = 0;
  2414. _md->babystepMem[axis] += (int)lcd_encoder;
  2415. if (axis == 2)
  2416. {
  2417. if (_md->babystepMem[axis] < Z_BABYSTEP_MIN) _md->babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2418. else if (_md->babystepMem[axis] > Z_BABYSTEP_MAX) _md->babystepMem[axis] = Z_BABYSTEP_MAX; //0
  2419. else
  2420. {
  2421. CRITICAL_SECTION_START
  2422. babystepsTodo[axis] += (int)lcd_encoder;
  2423. CRITICAL_SECTION_END
  2424. }
  2425. }
  2426. _md->babystepMemMM[axis] = _md->babystepMem[axis]/axis_steps_per_unit[axis];
  2427. delay(50);
  2428. lcd_encoder = 0;
  2429. lcd_draw_update = 1;
  2430. }
  2431. if (lcd_draw_update)
  2432. {
  2433. lcd_set_cursor(0, 1);
  2434. menu_draw_float13(' ', msg, _md->babystepMemMM[axis]);
  2435. }
  2436. if (LCD_CLICKED || menu_leaving)
  2437. {
  2438. // Only update the EEPROM when leaving the menu.
  2439. EEPROM_save_B(
  2440. (axis == X_AXIS) ? EEPROM_BABYSTEP_X : ((axis == Y_AXIS) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  2441. &_md->babystepMem[axis]);
  2442. if(Z_AXIS == axis) calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2443. }
  2444. if (LCD_CLICKED) menu_back();
  2445. }
  2446. static void lcd_babystep_z()
  2447. {
  2448. _lcd_babystep(Z_AXIS, (_i("Adjusting Z")));////MSG_BABYSTEPPING_Z c=20 r=0
  2449. }
  2450. typedef struct
  2451. { // 12bytes + 9bytes = 21bytes total
  2452. menu_data_edit_t reserved; //12 bytes reserved for number editing functions
  2453. int8_t status; // 1byte
  2454. int16_t left; // 2byte
  2455. int16_t right; // 2byte
  2456. int16_t front; // 2byte
  2457. int16_t rear; // 2byte
  2458. } _menu_data_adjust_bed_t;
  2459. static_assert(sizeof(menu_data)>= sizeof(_menu_data_adjust_bed_t),"_menu_data_adjust_bed_t doesn't fit into menu_data");
  2460. void lcd_adjust_bed_reset(void)
  2461. {
  2462. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2463. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2464. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2465. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2466. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2467. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2468. _md->status = 0;
  2469. }
  2470. #define BED_ADJUSTMENT_UM_MAX 50
  2471. void lcd_adjust_bed(void)
  2472. {
  2473. _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]);
  2474. if (_md->status == 0)
  2475. {
  2476. // Menu was entered.
  2477. _md->left = 0;
  2478. _md->right = 0;
  2479. _md->front = 0;
  2480. _md->rear = 0;
  2481. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1)
  2482. {
  2483. _md->left = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2484. _md->right = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2485. _md->front = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2486. _md->rear = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2487. }
  2488. _md->status = 1;
  2489. }
  2490. MENU_BEGIN();
  2491. // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P
  2492. if (((menu_item == menu_line) && menu_clicked && (lcd_encoder == menu_item)) || menu_leaving)
  2493. {
  2494. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left);
  2495. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right);
  2496. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front);
  2497. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear);
  2498. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2499. }
  2500. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2501. 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
  2502. 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
  2503. 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
  2504. 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
  2505. MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_adjust_bed_reset);////MSG_BED_CORRECTION_RESET c=0 r=0
  2506. MENU_END();
  2507. }
  2508. void pid_extruder()
  2509. {
  2510. lcd_clear();
  2511. lcd_set_cursor(1, 0);
  2512. lcd_puts_P(_i("Set temperature:"));////MSG_SET_TEMPERATURE c=19 r=1
  2513. pid_temp += int(lcd_encoder);
  2514. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2515. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2516. lcd_encoder = 0;
  2517. lcd_set_cursor(1, 2);
  2518. lcd_print(ftostr3(pid_temp));
  2519. if (lcd_clicked()) {
  2520. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  2521. lcd_return_to_status();
  2522. lcd_update(2);
  2523. }
  2524. }
  2525. /*
  2526. void lcd_adjust_z() {
  2527. int enc_dif = 0;
  2528. int cursor_pos = 1;
  2529. int fsm = 0;
  2530. lcd_clear();
  2531. lcd_set_cursor(0, 0);
  2532. lcd_puts_P(_i("Auto adjust Z?"));////MSG_ADJUSTZ c=0 r=0
  2533. lcd_set_cursor(1, 1);
  2534. lcd_puts_P(_T(MSG_YES));
  2535. lcd_set_cursor(1, 2);
  2536. lcd_puts_P(_T(MSG_NO));
  2537. lcd_set_cursor(0, 1);
  2538. lcd_print(">");
  2539. enc_dif = lcd_encoder_diff;
  2540. while (fsm == 0) {
  2541. manage_heater();
  2542. manage_inactivity(true);
  2543. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  2544. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  2545. if (enc_dif > lcd_encoder_diff ) {
  2546. cursor_pos --;
  2547. }
  2548. if (enc_dif < lcd_encoder_diff ) {
  2549. cursor_pos ++;
  2550. }
  2551. if (cursor_pos > 2) {
  2552. cursor_pos = 2;
  2553. }
  2554. if (cursor_pos < 1) {
  2555. cursor_pos = 1;
  2556. }
  2557. lcd_set_cursor(0, 1);
  2558. lcd_print(" ");
  2559. lcd_set_cursor(0, 2);
  2560. lcd_print(" ");
  2561. lcd_set_cursor(0, cursor_pos);
  2562. lcd_print(">");
  2563. enc_dif = lcd_encoder_diff;
  2564. delay(100);
  2565. }
  2566. }
  2567. if (lcd_clicked()) {
  2568. fsm = cursor_pos;
  2569. if (fsm == 1) {
  2570. int babystepLoadZ = 0;
  2571. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2572. CRITICAL_SECTION_START
  2573. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2574. CRITICAL_SECTION_END
  2575. } else {
  2576. int zero = 0;
  2577. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2578. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2579. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2580. }
  2581. delay(500);
  2582. }
  2583. };
  2584. lcd_clear();
  2585. lcd_return_to_status();
  2586. }*/
  2587. bool lcd_wait_for_pinda(float temp) {
  2588. lcd_set_custom_characters_degree();
  2589. setAllTargetHotends(0);
  2590. setTargetBed(0);
  2591. LongTimer pinda_timeout;
  2592. pinda_timeout.start();
  2593. bool target_temp_reached = true;
  2594. while (current_temperature_pinda > temp){
  2595. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2596. lcd_set_cursor(0, 4);
  2597. lcd_print(LCD_STR_THERMOMETER[0]);
  2598. lcd_print(ftostr3(current_temperature_pinda));
  2599. lcd_print("/");
  2600. lcd_print(ftostr3(temp));
  2601. lcd_print(LCD_STR_DEGREE);
  2602. delay_keep_alive(1000);
  2603. serialecho_temperatures();
  2604. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2605. target_temp_reached = false;
  2606. break;
  2607. }
  2608. }
  2609. lcd_set_custom_characters_arrows();
  2610. lcd_update_enable(true);
  2611. return target_temp_reached;
  2612. }
  2613. void lcd_wait_for_heater() {
  2614. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2615. lcd_set_degree();
  2616. lcd_set_cursor(0, 4);
  2617. lcd_print(LCD_STR_THERMOMETER[0]);
  2618. lcd_print(ftostr3(degHotend(active_extruder)));
  2619. lcd_print("/");
  2620. lcd_print(ftostr3(degTargetHotend(active_extruder)));
  2621. lcd_print(LCD_STR_DEGREE);
  2622. }
  2623. void lcd_wait_for_cool_down() {
  2624. lcd_set_custom_characters_degree();
  2625. setAllTargetHotends(0);
  2626. setTargetBed(0);
  2627. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2628. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=3
  2629. lcd_set_cursor(0, 4);
  2630. lcd_print(LCD_STR_THERMOMETER[0]);
  2631. lcd_print(ftostr3(degHotend(0)));
  2632. lcd_print("/0");
  2633. lcd_print(LCD_STR_DEGREE);
  2634. lcd_set_cursor(9, 4);
  2635. lcd_print(LCD_STR_BEDTEMP[0]);
  2636. lcd_print(ftostr3(degBed()));
  2637. lcd_print("/0");
  2638. lcd_print(LCD_STR_DEGREE);
  2639. lcd_set_custom_characters();
  2640. delay_keep_alive(1000);
  2641. serialecho_temperatures();
  2642. }
  2643. lcd_set_custom_characters_arrows();
  2644. lcd_update_enable(true);
  2645. }
  2646. // Lets the user move the Z carriage up to the end stoppers.
  2647. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2648. // Otherwise the Z calibration is not changed and false is returned.
  2649. #ifndef TMC2130
  2650. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2651. {
  2652. bool clean_nozzle_asked = false;
  2653. // 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.
  2654. current_position[Z_AXIS] = 0;
  2655. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2656. // Until confirmed by the confirmation dialog.
  2657. for (;;) {
  2658. unsigned long previous_millis_cmd = millis();
  2659. 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
  2660. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2661. const bool multi_screen = msg_next != NULL;
  2662. unsigned long previous_millis_msg = millis();
  2663. // Until the user finishes the z up movement.
  2664. lcd_encoder_diff = 0;
  2665. lcd_encoder = 0;
  2666. for (;;) {
  2667. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2668. // goto canceled;
  2669. manage_heater();
  2670. manage_inactivity(true);
  2671. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
  2672. delay(50);
  2673. previous_millis_cmd = millis();
  2674. lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  2675. lcd_encoder_diff = 0;
  2676. if (! planner_queue_full()) {
  2677. // Only move up, whatever direction the user rotates the encoder.
  2678. current_position[Z_AXIS] += fabs(lcd_encoder);
  2679. lcd_encoder = 0;
  2680. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS] / 60, active_extruder);
  2681. }
  2682. }
  2683. if (lcd_clicked()) {
  2684. // Abort a move if in progress.
  2685. planner_abort_hard();
  2686. while (lcd_clicked()) ;
  2687. delay(10);
  2688. while (lcd_clicked()) ;
  2689. break;
  2690. }
  2691. if (multi_screen && millis() - previous_millis_msg > 5000) {
  2692. if (msg_next == NULL)
  2693. msg_next = msg;
  2694. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2695. previous_millis_msg = millis();
  2696. }
  2697. }
  2698. if (! clean_nozzle_asked) {
  2699. lcd_show_fullscreen_message_and_wait_P(_T(MSG_CONFIRM_NOZZLE_CLEAN));
  2700. clean_nozzle_asked = true;
  2701. }
  2702. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2703. 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
  2704. if (result == -1)
  2705. goto canceled;
  2706. else if (result == 1)
  2707. goto calibrated;
  2708. // otherwise perform another round of the Z up dialog.
  2709. }
  2710. calibrated:
  2711. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2712. // during the search for the induction points.
  2713. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2714. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2715. if(only_z){
  2716. lcd_display_message_fullscreen_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1));
  2717. lcd_set_cursor(0, 3);
  2718. lcd_print(1);
  2719. lcd_puts_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2));
  2720. }else{
  2721. //lcd_show_fullscreen_message_and_wait_P(_T(MSG_PAPER));
  2722. lcd_display_message_fullscreen_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1));
  2723. lcd_set_cursor(0, 2);
  2724. lcd_print(1);
  2725. lcd_puts_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2));
  2726. }
  2727. return true;
  2728. canceled:
  2729. return false;
  2730. }
  2731. #endif // TMC2130
  2732. static inline bool pgm_is_whitespace(const char *c_addr)
  2733. {
  2734. const char c = pgm_read_byte(c_addr);
  2735. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2736. }
  2737. static inline bool pgm_is_interpunction(const char *c_addr)
  2738. {
  2739. const char c = pgm_read_byte(c_addr);
  2740. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2741. }
  2742. /**
  2743. * @brief show full screen message
  2744. *
  2745. * This function is non-blocking
  2746. * @param msg message to be displayed from PROGMEM
  2747. * @param nlines
  2748. * @return rest of the text (to be displayed on next page)
  2749. */
  2750. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2751. {
  2752. lcd_set_cursor(0, 0);
  2753. const char *msgend = msg;
  2754. uint8_t row = 0;
  2755. bool multi_screen = false;
  2756. for (; row < 4; ++ row) {
  2757. while (pgm_is_whitespace(msg))
  2758. ++ msg;
  2759. if (pgm_read_byte(msg) == 0)
  2760. // End of the message.
  2761. break;
  2762. lcd_set_cursor(0, row);
  2763. uint8_t linelen = min(strlen_P(msg), 20);
  2764. const char *msgend2 = msg + linelen;
  2765. msgend = msgend2;
  2766. if (row == 3 && linelen == 20) {
  2767. // Last line of the display, full line shall be displayed.
  2768. // Find out, whether this message will be split into multiple screens.
  2769. while (pgm_is_whitespace(msgend))
  2770. ++ msgend;
  2771. multi_screen = pgm_read_byte(msgend) != 0;
  2772. if (multi_screen)
  2773. msgend = (msgend2 -= 2);
  2774. }
  2775. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2776. // Splitting a word. Find the start of the current word.
  2777. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2778. -- msgend;
  2779. if (msgend == msg)
  2780. // Found a single long word, which cannot be split. Just cut it.
  2781. msgend = msgend2;
  2782. }
  2783. for (; msg < msgend; ++ msg) {
  2784. char c = char(pgm_read_byte(msg));
  2785. if (c == '~')
  2786. c = ' ';
  2787. lcd_print(c);
  2788. }
  2789. }
  2790. if (multi_screen) {
  2791. // Display the "next screen" indicator character.
  2792. // lcd_set_custom_characters_arrows();
  2793. lcd_set_custom_characters_nextpage();
  2794. lcd_set_cursor(19, 3);
  2795. // Display the down arrow.
  2796. lcd_print(char(1));
  2797. }
  2798. nlines = row;
  2799. return multi_screen ? msgend : NULL;
  2800. }
  2801. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2802. {
  2803. // Disable update of the screen by the usual lcd_update(0) routine.
  2804. lcd_update_enable(false);
  2805. lcd_clear();
  2806. // uint8_t nlines;
  2807. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  2808. }
  2809. const char* lcd_display_message_fullscreen_P(const char *msg)
  2810. {
  2811. uint8_t nlines;
  2812. return lcd_display_message_fullscreen_P(msg, nlines);
  2813. }
  2814. /**
  2815. * @brief show full screen message and wait
  2816. *
  2817. * This function is blocking.
  2818. * @param msg message to be displayed from PROGMEM
  2819. */
  2820. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2821. {
  2822. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2823. bool multi_screen = msg_next != NULL;
  2824. lcd_set_custom_characters_nextpage();
  2825. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2826. // Until confirmed by a button click.
  2827. for (;;) {
  2828. if (!multi_screen) {
  2829. lcd_set_cursor(19, 3);
  2830. // Display the confirm char.
  2831. lcd_print(char(2));
  2832. }
  2833. // Wait for 5 seconds before displaying the next text.
  2834. for (uint8_t i = 0; i < 100; ++ i) {
  2835. delay_keep_alive(50);
  2836. if (lcd_clicked()) {
  2837. while (lcd_clicked()) ;
  2838. delay(10);
  2839. while (lcd_clicked()) ;
  2840. if (msg_next == NULL) {
  2841. KEEPALIVE_STATE(IN_HANDLER);
  2842. lcd_set_custom_characters();
  2843. lcd_update_enable(true);
  2844. lcd_update(2);
  2845. return;
  2846. }
  2847. else {
  2848. break;
  2849. }
  2850. }
  2851. }
  2852. if (multi_screen) {
  2853. if (msg_next == NULL)
  2854. msg_next = msg;
  2855. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2856. if (msg_next == NULL) {
  2857. lcd_set_cursor(19, 3);
  2858. // Display the confirm char.
  2859. lcd_print(char(2));
  2860. }
  2861. }
  2862. }
  2863. }
  2864. void lcd_wait_for_click()
  2865. {
  2866. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2867. for (;;) {
  2868. manage_heater();
  2869. manage_inactivity(true);
  2870. if (lcd_clicked()) {
  2871. while (lcd_clicked()) ;
  2872. delay(10);
  2873. while (lcd_clicked()) ;
  2874. KEEPALIVE_STATE(IN_HANDLER);
  2875. return;
  2876. }
  2877. }
  2878. }
  2879. 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)
  2880. {
  2881. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2882. bool multi_screen = msg_next != NULL;
  2883. bool yes = default_yes ? true : false;
  2884. // Wait for user confirmation or a timeout.
  2885. unsigned long previous_millis_cmd = millis();
  2886. int8_t enc_dif = lcd_encoder_diff;
  2887. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  2888. for (;;) {
  2889. for (uint8_t i = 0; i < 100; ++i) {
  2890. delay_keep_alive(50);
  2891. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2892. return -1;
  2893. manage_heater();
  2894. manage_inactivity(true);
  2895. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  2896. if (msg_next == NULL) {
  2897. lcd_set_cursor(0, 3);
  2898. if (enc_dif < lcd_encoder_diff && yes) {
  2899. lcd_puts_P((PSTR(" ")));
  2900. lcd_set_cursor(7, 3);
  2901. lcd_puts_P((PSTR(">")));
  2902. yes = false;
  2903. }
  2904. else if (enc_dif > lcd_encoder_diff && !yes) {
  2905. lcd_puts_P((PSTR(">")));
  2906. lcd_set_cursor(7, 3);
  2907. lcd_puts_P((PSTR(" ")));
  2908. yes = true;
  2909. }
  2910. enc_dif = lcd_encoder_diff;
  2911. }
  2912. else {
  2913. break; //turning knob skips waiting loop
  2914. }
  2915. }
  2916. if (lcd_clicked()) {
  2917. while (lcd_clicked());
  2918. delay(10);
  2919. while (lcd_clicked());
  2920. if (msg_next == NULL) {
  2921. //KEEPALIVE_STATE(IN_HANDLER);
  2922. lcd_set_custom_characters();
  2923. return yes;
  2924. }
  2925. else break;
  2926. }
  2927. }
  2928. if (multi_screen) {
  2929. if (msg_next == NULL) {
  2930. msg_next = msg;
  2931. }
  2932. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2933. }
  2934. if (msg_next == NULL) {
  2935. lcd_set_cursor(0, 3);
  2936. if (yes) lcd_puts_P(PSTR(">"));
  2937. lcd_set_cursor(1, 3);
  2938. lcd_puts_P(_T(MSG_YES));
  2939. lcd_set_cursor(7, 3);
  2940. if (!yes) lcd_puts_P(PSTR(">"));
  2941. lcd_set_cursor(8, 3);
  2942. lcd_puts_P(_T(MSG_NO));
  2943. }
  2944. }
  2945. }
  2946. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  2947. {
  2948. lcd_display_message_fullscreen_P(msg);
  2949. if (default_yes) {
  2950. lcd_set_cursor(0, 2);
  2951. lcd_puts_P(PSTR(">"));
  2952. lcd_puts_P(_T(MSG_YES));
  2953. lcd_set_cursor(1, 3);
  2954. lcd_puts_P(_T(MSG_NO));
  2955. }
  2956. else {
  2957. lcd_set_cursor(1, 2);
  2958. lcd_puts_P(_T(MSG_YES));
  2959. lcd_set_cursor(0, 3);
  2960. lcd_puts_P(PSTR(">"));
  2961. lcd_puts_P(_T(MSG_NO));
  2962. }
  2963. bool yes = default_yes ? true : false;
  2964. // Wait for user confirmation or a timeout.
  2965. unsigned long previous_millis_cmd = millis();
  2966. int8_t enc_dif = lcd_encoder_diff;
  2967. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2968. for (;;) {
  2969. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2970. return -1;
  2971. manage_heater();
  2972. manage_inactivity(true);
  2973. if (abs(enc_dif - lcd_encoder_diff) > 4) {
  2974. lcd_set_cursor(0, 2);
  2975. if (enc_dif < lcd_encoder_diff && yes) {
  2976. lcd_puts_P((PSTR(" ")));
  2977. lcd_set_cursor(0, 3);
  2978. lcd_puts_P((PSTR(">")));
  2979. yes = false;
  2980. }
  2981. else if (enc_dif > lcd_encoder_diff && !yes) {
  2982. lcd_puts_P((PSTR(">")));
  2983. lcd_set_cursor(0, 3);
  2984. lcd_puts_P((PSTR(" ")));
  2985. yes = true;
  2986. }
  2987. enc_dif = lcd_encoder_diff;
  2988. }
  2989. if (lcd_clicked()) {
  2990. while (lcd_clicked());
  2991. delay(10);
  2992. while (lcd_clicked());
  2993. KEEPALIVE_STATE(IN_HANDLER);
  2994. return yes;
  2995. }
  2996. }
  2997. }
  2998. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2999. {
  3000. const char *msg = NULL;
  3001. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  3002. 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
  3003. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  3004. if (point_too_far_mask == 0)
  3005. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3006. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3007. // Only the center point or all the three front points.
  3008. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8
  3009. else if ((point_too_far_mask & 1) == 0)
  3010. // The right and maybe the center point out of reach.
  3011. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8
  3012. else
  3013. // The left and maybe the center point out of reach.
  3014. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  3015. lcd_show_fullscreen_message_and_wait_P(msg);
  3016. } else {
  3017. if (point_too_far_mask != 0) {
  3018. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  3019. // Only the center point or all the three front points.
  3020. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  3021. else if ((point_too_far_mask & 1) == 0)
  3022. // The right and maybe the center point out of reach.
  3023. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  3024. else
  3025. // The left and maybe the center point out of reach.
  3026. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  3027. lcd_show_fullscreen_message_and_wait_P(msg);
  3028. }
  3029. if (point_too_far_mask == 0 || result > 0) {
  3030. switch (result) {
  3031. default:
  3032. // should not happen
  3033. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  3034. break;
  3035. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  3036. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  3037. break;
  3038. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  3039. 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
  3040. break;
  3041. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  3042. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  3043. break;
  3044. }
  3045. lcd_show_fullscreen_message_and_wait_P(msg);
  3046. }
  3047. }
  3048. }
  3049. void lcd_temp_cal_show_result(bool result) {
  3050. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  3051. disable_x();
  3052. disable_y();
  3053. disable_z();
  3054. disable_e0();
  3055. disable_e1();
  3056. disable_e2();
  3057. setTargetBed(0); //set bed target temperature back to 0
  3058. if (result == true) {
  3059. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  3060. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  3061. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  3062. temp_cal_active = true;
  3063. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  3064. }
  3065. else {
  3066. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  3067. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  3068. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  3069. temp_cal_active = false;
  3070. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  3071. }
  3072. lcd_update_enable(true);
  3073. lcd_update(2);
  3074. }
  3075. static void lcd_show_end_stops() {
  3076. lcd_set_cursor(0, 0);
  3077. lcd_puts_P((PSTR("End stops diag")));
  3078. lcd_set_cursor(0, 1);
  3079. lcd_puts_P((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
  3080. lcd_set_cursor(0, 2);
  3081. lcd_puts_P((READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
  3082. lcd_set_cursor(0, 3);
  3083. lcd_puts_P((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
  3084. }
  3085. #ifndef TMC2130
  3086. static void menu_show_end_stops() {
  3087. lcd_show_end_stops();
  3088. if (LCD_CLICKED) menu_back();
  3089. }
  3090. #endif // not defined TMC2130
  3091. // Lets the user move the Z carriage up to the end stoppers.
  3092. // When done, it sets the current Z to Z_MAX_POS and returns true.
  3093. // Otherwise the Z calibration is not changed and false is returned.
  3094. void lcd_diag_show_end_stops()
  3095. {
  3096. lcd_clear();
  3097. for (;;) {
  3098. manage_heater();
  3099. manage_inactivity(true);
  3100. lcd_show_end_stops();
  3101. if (lcd_clicked()) {
  3102. while (lcd_clicked()) ;
  3103. delay(10);
  3104. while (lcd_clicked()) ;
  3105. break;
  3106. }
  3107. }
  3108. lcd_clear();
  3109. lcd_return_to_status();
  3110. }
  3111. #ifdef TMC2130
  3112. static void lcd_show_pinda_state()
  3113. {
  3114. lcd_set_cursor(0, 0);
  3115. lcd_puts_P((PSTR("P.I.N.D.A. state")));
  3116. lcd_set_cursor(0, 2);
  3117. lcd_puts_P(READ(Z_MIN_PIN)?(PSTR("Z1 (LED off)")):(PSTR("Z0 (LED on) "))); // !!! both strings must have same length (due to dynamic refreshing)
  3118. }
  3119. static void menu_show_pinda_state()
  3120. {
  3121. lcd_timeoutToStatus.stop();
  3122. lcd_show_pinda_state();
  3123. if(LCD_CLICKED)
  3124. {
  3125. lcd_timeoutToStatus.start();
  3126. menu_back();
  3127. }
  3128. }
  3129. #endif // defined TMC2130
  3130. void prusa_statistics(int _message, uint8_t _fil_nr) {
  3131. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  3132. return;
  3133. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  3134. switch (_message)
  3135. {
  3136. case 0: // default message
  3137. if (IS_SD_PRINTING)
  3138. {
  3139. SERIAL_ECHO("{");
  3140. prusa_stat_printerstatus(4);
  3141. prusa_stat_farm_number();
  3142. prusa_stat_printinfo();
  3143. SERIAL_ECHOLN("}");
  3144. status_number = 4;
  3145. }
  3146. else
  3147. {
  3148. SERIAL_ECHO("{");
  3149. prusa_stat_printerstatus(1);
  3150. prusa_stat_farm_number();
  3151. SERIAL_ECHOLN("}");
  3152. status_number = 1;
  3153. }
  3154. break;
  3155. case 1: // 1 heating
  3156. farm_status = 2;
  3157. SERIAL_ECHO("{");
  3158. prusa_stat_printerstatus(2);
  3159. prusa_stat_farm_number();
  3160. SERIAL_ECHOLN("}");
  3161. status_number = 2;
  3162. farm_timer = 1;
  3163. break;
  3164. case 2: // heating done
  3165. farm_status = 3;
  3166. SERIAL_ECHO("{");
  3167. prusa_stat_printerstatus(3);
  3168. prusa_stat_farm_number();
  3169. SERIAL_ECHOLN("}");
  3170. status_number = 3;
  3171. farm_timer = 1;
  3172. if (IS_SD_PRINTING)
  3173. {
  3174. farm_status = 4;
  3175. SERIAL_ECHO("{");
  3176. prusa_stat_printerstatus(4);
  3177. prusa_stat_farm_number();
  3178. SERIAL_ECHOLN("}");
  3179. status_number = 4;
  3180. }
  3181. else
  3182. {
  3183. SERIAL_ECHO("{");
  3184. prusa_stat_printerstatus(3);
  3185. prusa_stat_farm_number();
  3186. SERIAL_ECHOLN("}");
  3187. status_number = 3;
  3188. }
  3189. farm_timer = 1;
  3190. break;
  3191. case 3: // filament change
  3192. break;
  3193. case 4: // print succesfull
  3194. SERIAL_ECHO("{[RES:1][FIL:");
  3195. MYSERIAL.print(int(_fil_nr));
  3196. SERIAL_ECHO("]");
  3197. prusa_stat_printerstatus(status_number);
  3198. prusa_stat_farm_number();
  3199. SERIAL_ECHOLN("}");
  3200. farm_timer = 2;
  3201. break;
  3202. case 5: // print not succesfull
  3203. SERIAL_ECHO("{[RES:0][FIL:");
  3204. MYSERIAL.print(int(_fil_nr));
  3205. SERIAL_ECHO("]");
  3206. prusa_stat_printerstatus(status_number);
  3207. prusa_stat_farm_number();
  3208. SERIAL_ECHOLN("}");
  3209. farm_timer = 2;
  3210. break;
  3211. case 6: // print done
  3212. SERIAL_ECHO("{[PRN:8]");
  3213. prusa_stat_farm_number();
  3214. SERIAL_ECHOLN("}");
  3215. status_number = 8;
  3216. farm_timer = 2;
  3217. break;
  3218. case 7: // print done - stopped
  3219. SERIAL_ECHO("{[PRN:9]");
  3220. prusa_stat_farm_number();
  3221. SERIAL_ECHOLN("}");
  3222. status_number = 9;
  3223. farm_timer = 2;
  3224. break;
  3225. case 8: // printer started
  3226. SERIAL_ECHO("{[PRN:0][PFN:");
  3227. status_number = 0;
  3228. SERIAL_ECHO(farm_no);
  3229. SERIAL_ECHOLN("]}");
  3230. farm_timer = 2;
  3231. break;
  3232. case 20: // echo farm no
  3233. SERIAL_ECHO("{");
  3234. prusa_stat_printerstatus(status_number);
  3235. prusa_stat_farm_number();
  3236. SERIAL_ECHOLN("}");
  3237. farm_timer = 4;
  3238. break;
  3239. case 21: // temperatures
  3240. SERIAL_ECHO("{");
  3241. prusa_stat_temperatures();
  3242. prusa_stat_farm_number();
  3243. prusa_stat_printerstatus(status_number);
  3244. SERIAL_ECHOLN("}");
  3245. break;
  3246. case 22: // waiting for filament change
  3247. SERIAL_ECHO("{[PRN:5]");
  3248. prusa_stat_farm_number();
  3249. SERIAL_ECHOLN("}");
  3250. status_number = 5;
  3251. break;
  3252. case 90: // Error - Thermal Runaway
  3253. SERIAL_ECHO("{[ERR:1]");
  3254. prusa_stat_farm_number();
  3255. SERIAL_ECHOLN("}");
  3256. break;
  3257. case 91: // Error - Thermal Runaway Preheat
  3258. SERIAL_ECHO("{[ERR:2]");
  3259. prusa_stat_farm_number();
  3260. SERIAL_ECHOLN("}");
  3261. break;
  3262. case 92: // Error - Min temp
  3263. SERIAL_ECHO("{[ERR:3]");
  3264. prusa_stat_farm_number();
  3265. SERIAL_ECHOLN("}");
  3266. break;
  3267. case 93: // Error - Max temp
  3268. SERIAL_ECHO("{[ERR:4]");
  3269. prusa_stat_farm_number();
  3270. SERIAL_ECHOLN("}");
  3271. break;
  3272. case 99: // heartbeat
  3273. SERIAL_ECHO("{[PRN:99]");
  3274. prusa_stat_temperatures();
  3275. SERIAL_ECHO("[PFN:");
  3276. SERIAL_ECHO(farm_no);
  3277. SERIAL_ECHO("]");
  3278. SERIAL_ECHOLN("}");
  3279. break;
  3280. }
  3281. }
  3282. static void prusa_stat_printerstatus(int _status)
  3283. {
  3284. SERIAL_ECHO("[PRN:");
  3285. SERIAL_ECHO(_status);
  3286. SERIAL_ECHO("]");
  3287. }
  3288. static void prusa_stat_farm_number() {
  3289. SERIAL_ECHO("[PFN:");
  3290. SERIAL_ECHO(farm_no);
  3291. SERIAL_ECHO("]");
  3292. }
  3293. static void prusa_stat_temperatures()
  3294. {
  3295. SERIAL_ECHO("[ST0:");
  3296. SERIAL_ECHO(target_temperature[0]);
  3297. SERIAL_ECHO("][STB:");
  3298. SERIAL_ECHO(target_temperature_bed);
  3299. SERIAL_ECHO("][AT0:");
  3300. SERIAL_ECHO(current_temperature[0]);
  3301. SERIAL_ECHO("][ATB:");
  3302. SERIAL_ECHO(current_temperature_bed);
  3303. SERIAL_ECHO("]");
  3304. }
  3305. static void prusa_stat_printinfo()
  3306. {
  3307. SERIAL_ECHO("[TFU:");
  3308. SERIAL_ECHO(total_filament_used);
  3309. SERIAL_ECHO("][PCD:");
  3310. SERIAL_ECHO(itostr3(card.percentDone()));
  3311. SERIAL_ECHO("][FEM:");
  3312. SERIAL_ECHO(itostr3(feedmultiply));
  3313. SERIAL_ECHO("][FNM:");
  3314. SERIAL_ECHO(longFilenameOLD);
  3315. SERIAL_ECHO("][TIM:");
  3316. if (starttime != 0)
  3317. {
  3318. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  3319. }
  3320. else
  3321. {
  3322. SERIAL_ECHO(0);
  3323. }
  3324. SERIAL_ECHO("][FWR:");
  3325. SERIAL_ECHO(FW_VERSION);
  3326. SERIAL_ECHO("]");
  3327. }
  3328. /*
  3329. void lcd_pick_babystep(){
  3330. int enc_dif = 0;
  3331. int cursor_pos = 1;
  3332. int fsm = 0;
  3333. lcd_clear();
  3334. lcd_set_cursor(0, 0);
  3335. lcd_puts_P(_i("Pick print"));////MSG_PICK_Z c=0 r=0
  3336. lcd_set_cursor(3, 2);
  3337. lcd_print("1");
  3338. lcd_set_cursor(3, 3);
  3339. lcd_print("2");
  3340. lcd_set_cursor(12, 2);
  3341. lcd_print("3");
  3342. lcd_set_cursor(12, 3);
  3343. lcd_print("4");
  3344. lcd_set_cursor(1, 2);
  3345. lcd_print(">");
  3346. enc_dif = lcd_encoder_diff;
  3347. while (fsm == 0) {
  3348. manage_heater();
  3349. manage_inactivity(true);
  3350. if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
  3351. if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
  3352. if (enc_dif > lcd_encoder_diff ) {
  3353. cursor_pos --;
  3354. }
  3355. if (enc_dif < lcd_encoder_diff ) {
  3356. cursor_pos ++;
  3357. }
  3358. if (cursor_pos > 4) {
  3359. cursor_pos = 4;
  3360. }
  3361. if (cursor_pos < 1) {
  3362. cursor_pos = 1;
  3363. }
  3364. lcd_set_cursor(1, 2);
  3365. lcd_print(" ");
  3366. lcd_set_cursor(1, 3);
  3367. lcd_print(" ");
  3368. lcd_set_cursor(10, 2);
  3369. lcd_print(" ");
  3370. lcd_set_cursor(10, 3);
  3371. lcd_print(" ");
  3372. if (cursor_pos < 3) {
  3373. lcd_set_cursor(1, cursor_pos+1);
  3374. lcd_print(">");
  3375. }else{
  3376. lcd_set_cursor(10, cursor_pos-1);
  3377. lcd_print(">");
  3378. }
  3379. enc_dif = lcd_encoder_diff;
  3380. delay(100);
  3381. }
  3382. }
  3383. if (lcd_clicked()) {
  3384. fsm = cursor_pos;
  3385. int babyStepZ;
  3386. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  3387. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  3388. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3389. delay(500);
  3390. }
  3391. };
  3392. lcd_clear();
  3393. lcd_return_to_status();
  3394. }
  3395. */
  3396. void lcd_move_menu_axis()
  3397. {
  3398. MENU_BEGIN();
  3399. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3400. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=0 r=0
  3401. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=0 r=0
  3402. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=0 r=0
  3403. MENU_ITEM_SUBMENU_P(_i("Extruder"), lcd_move_e);////MSG_MOVE_E c=0 r=0
  3404. MENU_END();
  3405. }
  3406. static void lcd_move_menu_1mm()
  3407. {
  3408. move_menu_scale = 1.0;
  3409. lcd_move_menu_axis();
  3410. }
  3411. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  3412. {
  3413. do
  3414. {
  3415. eeprom_write_byte((unsigned char*)pos, *value);
  3416. pos++;
  3417. value++;
  3418. } while (--size);
  3419. }
  3420. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  3421. {
  3422. do
  3423. {
  3424. *value = eeprom_read_byte((unsigned char*)pos);
  3425. pos++;
  3426. value++;
  3427. } while (--size);
  3428. }
  3429. #ifdef SDCARD_SORT_ALPHA
  3430. static void lcd_sort_type_set() {
  3431. uint8_t sdSort;
  3432. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3433. switch (sdSort) {
  3434. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3435. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3436. default: sdSort = SD_SORT_TIME;
  3437. }
  3438. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  3439. presort_flag = true;
  3440. }
  3441. #endif //SDCARD_SORT_ALPHA
  3442. #ifdef TMC2130
  3443. static void lcd_crash_mode_info()
  3444. {
  3445. lcd_update_enable(true);
  3446. static uint32_t tim = 0;
  3447. if ((tim + 1000) < millis())
  3448. {
  3449. fputs_P(_i("\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3450. tim = millis();
  3451. }
  3452. menu_back_if_clicked();
  3453. }
  3454. static void lcd_crash_mode_info2()
  3455. {
  3456. lcd_update_enable(true);
  3457. static uint32_t tim = 0;
  3458. if ((tim + 1000) < millis())
  3459. {
  3460. fputs_P(_i("\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3461. tim = millis();
  3462. }
  3463. menu_back_if_clicked();
  3464. }
  3465. #endif //TMC2130
  3466. #ifdef FILAMENT_SENSOR
  3467. static void lcd_filament_autoload_info()
  3468. {
  3469. uint8_t nlines;
  3470. lcd_update_enable(true);
  3471. static uint32_t tim = 0;
  3472. if ((tim + 1000) < millis())
  3473. {
  3474. 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
  3475. tim = millis();
  3476. }
  3477. menu_back_if_clicked();
  3478. }
  3479. static void lcd_fsensor_fail()
  3480. {
  3481. uint8_t nlines;
  3482. lcd_update_enable(true);
  3483. static uint32_t tim = 0;
  3484. if ((tim + 1000) < millis())
  3485. {
  3486. 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
  3487. tim = millis();
  3488. }
  3489. menu_back_if_clicked();
  3490. }
  3491. #endif //FILAMENT_SENSOR
  3492. //-//
  3493. static void lcd_sound_state_set(void)
  3494. {
  3495. Sound_CycleState();
  3496. }
  3497. static void lcd_silent_mode_set() {
  3498. switch (SilentModeMenu) {
  3499. #ifdef TMC2130
  3500. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3501. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3502. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3503. #else
  3504. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3505. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3506. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3507. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3508. #endif //TMC2130
  3509. }
  3510. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3511. #ifdef TMC2130
  3512. // Wait until the planner queue is drained and the stepper routine achieves
  3513. // an idle state.
  3514. st_synchronize();
  3515. if (tmc2130_wait_standstill_xy(1000)) {}
  3516. // MYSERIAL.print("standstill OK");
  3517. // else
  3518. // MYSERIAL.print("standstill NG!");
  3519. cli();
  3520. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3521. update_mode_profile();
  3522. tmc2130_init();
  3523. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3524. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3525. st_reset_timer();
  3526. sei();
  3527. #endif //TMC2130
  3528. st_current_init();
  3529. #ifdef TMC2130
  3530. if (CrashDetectMenu && (SilentModeMenu != SILENT_MODE_NORMAL))
  3531. menu_submenu(lcd_crash_mode_info2);
  3532. #endif //TMC2130
  3533. }
  3534. #ifdef TMC2130
  3535. static void lcd_crash_mode_set()
  3536. {
  3537. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  3538. if (CrashDetectMenu==0) {
  3539. crashdet_disable();
  3540. }else{
  3541. crashdet_enable();
  3542. }
  3543. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) menu_goto(lcd_tune_menu, 9, true, true);
  3544. else menu_goto(lcd_settings_menu, 9, true, true);
  3545. }
  3546. #endif //TMC2130
  3547. #ifdef FILAMENT_SENSOR
  3548. static void lcd_fsensor_state_set()
  3549. {
  3550. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3551. if (!FSensorStateMenu) {
  3552. fsensor_disable();
  3553. if (fsensor_autoload_enabled && !mmu_enabled)
  3554. menu_submenu(lcd_filament_autoload_info);
  3555. }
  3556. else {
  3557. fsensor_enable();
  3558. if (fsensor_not_responding && !mmu_enabled)
  3559. menu_submenu(lcd_fsensor_fail);
  3560. }
  3561. }
  3562. #endif //FILAMENT_SENSOR
  3563. #if !SDSORT_USES_RAM
  3564. void lcd_set_degree() {
  3565. lcd_set_custom_characters_degree();
  3566. }
  3567. void lcd_set_progress() {
  3568. lcd_set_custom_characters_progress();
  3569. }
  3570. #endif
  3571. #if (LANG_MODE != 0)
  3572. void menu_setlang(unsigned char lang)
  3573. {
  3574. if (!lang_select(lang))
  3575. {
  3576. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language from XFLASH?"), false, true))
  3577. lang_boot_update_start(lang);
  3578. lcd_update_enable(true);
  3579. lcd_clear();
  3580. menu_goto(lcd_language_menu, 0, true, true);
  3581. lcd_timeoutToStatus.stop(); //infinite timeout
  3582. lcd_draw_update = 2;
  3583. }
  3584. }
  3585. static void lcd_language_menu()
  3586. {
  3587. MENU_BEGIN();
  3588. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3589. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3590. {
  3591. menu_setlang(0);
  3592. return;
  3593. }
  3594. uint8_t cnt = lang_get_count();
  3595. #ifdef W25X20CL
  3596. if (cnt == 2) //display secondary language in case of clear xflash
  3597. {
  3598. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3599. {
  3600. menu_setlang(1);
  3601. return;
  3602. }
  3603. }
  3604. else
  3605. for (int i = 2; i < cnt; i++) //skip seconday language - solved in lang_select (MK3)
  3606. #else //W25X20CL
  3607. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3608. #endif //W25X20CL
  3609. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3610. {
  3611. menu_setlang(i);
  3612. return;
  3613. }
  3614. MENU_END();
  3615. }
  3616. #endif //(LANG_MODE != 0)
  3617. void lcd_mesh_bedleveling()
  3618. {
  3619. mesh_bed_run_from_menu = true;
  3620. enquecommand_P(PSTR("G80"));
  3621. lcd_return_to_status();
  3622. }
  3623. void lcd_mesh_calibration()
  3624. {
  3625. enquecommand_P(PSTR("M45"));
  3626. lcd_return_to_status();
  3627. }
  3628. void lcd_mesh_calibration_z()
  3629. {
  3630. enquecommand_P(PSTR("M45 Z"));
  3631. lcd_return_to_status();
  3632. }
  3633. void lcd_pinda_calibration_menu()
  3634. {
  3635. MENU_BEGIN();
  3636. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3637. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3638. MENU_END();
  3639. }
  3640. void lcd_temp_calibration_set() {
  3641. temp_cal_active = !temp_cal_active;
  3642. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3643. st_current_init();
  3644. }
  3645. #ifdef HAS_SECOND_SERIAL_PORT
  3646. void lcd_second_serial_set() {
  3647. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3648. else selectedSerialPort = 1;
  3649. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3650. MYSERIAL.begin(BAUDRATE);
  3651. }
  3652. #endif //HAS_SECOND_SERIAL_PORT
  3653. void lcd_calibrate_pinda() {
  3654. enquecommand_P(PSTR("G76"));
  3655. lcd_return_to_status();
  3656. }
  3657. #ifndef SNMM
  3658. /*void lcd_calibrate_extruder() {
  3659. if (degHotend0() > EXTRUDE_MINTEMP)
  3660. {
  3661. current_position[E_AXIS] = 0; //set initial position to zero
  3662. plan_set_e_position(current_position[E_AXIS]);
  3663. //long steps_start = st_get_position(E_AXIS);
  3664. long steps_final;
  3665. float e_steps_per_unit;
  3666. 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)
  3667. 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
  3668. 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
  3669. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3670. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3671. unsigned long msg_millis;
  3672. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3673. lcd_clear();
  3674. lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_PLEASE_WAIT));
  3675. current_position[E_AXIS] += e_shift_calibration;
  3676. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3677. st_synchronize();
  3678. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3679. msg_millis = millis();
  3680. while (!LCD_CLICKED) {
  3681. if (multi_screen && millis() - msg_millis > 5000) {
  3682. if (msg_next_e_cal_knob == NULL)
  3683. msg_next_e_cal_knob = msg_e_cal_knob;
  3684. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3685. msg_millis = millis();
  3686. }
  3687. //manage_inactivity(true);
  3688. manage_heater();
  3689. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3690. delay_keep_alive(50);
  3691. //previous_millis_cmd = millis();
  3692. lcd_encoder += (lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
  3693. lcd_encoder_diff = 0;
  3694. if (!planner_queue_full()) {
  3695. current_position[E_AXIS] += float(abs((int)lcd_encoder)) * 0.01; //0.05
  3696. lcd_encoder = 0;
  3697. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3698. }
  3699. }
  3700. }
  3701. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3702. //steps_final = st_get_position(E_AXIS);
  3703. lcd_draw_update = 1;
  3704. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3705. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3706. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3707. lcd_clear();
  3708. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3709. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3710. //lcd_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3711. //delay_keep_alive(2000);
  3712. delay_keep_alive(500);
  3713. 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
  3714. lcd_update_enable(true);
  3715. lcd_draw_update = 2;
  3716. }
  3717. else
  3718. {
  3719. lcd_clear();
  3720. lcd_set_cursor(0, 0);
  3721. lcd_puts_P(_T(MSG_ERROR));
  3722. lcd_set_cursor(0, 2);
  3723. lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
  3724. delay(2000);
  3725. lcd_clear();
  3726. }
  3727. lcd_return_to_status();
  3728. }
  3729. void lcd_extr_cal_reset() {
  3730. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3731. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3732. //extrudemultiply = 100;
  3733. enquecommand_P(PSTR("M500"));
  3734. }*/
  3735. #endif
  3736. void lcd_toshiba_flash_air_compatibility_toggle()
  3737. {
  3738. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3739. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3740. }
  3741. void lcd_v2_calibration()
  3742. {
  3743. if (mmu_enabled)
  3744. {
  3745. const uint8_t filament = choose_menu_P(_i("Select PLA filament:"),_T(MSG_FILAMENT),_i("Cancel")); ////c=20 r=1 ////c=19 r=1
  3746. if (filament < 5)
  3747. {
  3748. lcd_commands_step = 20 + filament;
  3749. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3750. }
  3751. }
  3752. else
  3753. {
  3754. bool loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is PLA filament loaded?"), false, true);////MSG_PLA_FILAMENT_LOADED c=20 r=2
  3755. if (loaded) {
  3756. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3757. }
  3758. else {
  3759. lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3760. for (int i = 0; i < 20; i++) { //wait max. 2s
  3761. delay_keep_alive(100);
  3762. if (lcd_clicked()) {
  3763. while (lcd_clicked());
  3764. delay(10);
  3765. while (lcd_clicked());
  3766. break;
  3767. }
  3768. }
  3769. }
  3770. }
  3771. lcd_return_to_status();
  3772. lcd_update_enable(true);
  3773. }
  3774. void lcd_wizard() {
  3775. bool result = true;
  3776. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3777. 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
  3778. }
  3779. if (result) {
  3780. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3781. lcd_wizard(WizState::Run);
  3782. }
  3783. else {
  3784. lcd_return_to_status();
  3785. lcd_update_enable(true);
  3786. lcd_update(2);
  3787. }
  3788. }
  3789. void lcd_language()
  3790. {
  3791. lcd_update_enable(true);
  3792. lcd_clear();
  3793. menu_goto(lcd_language_menu, 0, true, true);
  3794. lcd_timeoutToStatus.stop(); //infinite timeout
  3795. lcd_draw_update = 2;
  3796. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  3797. {
  3798. delay(50);
  3799. lcd_update(0);
  3800. manage_heater();
  3801. manage_inactivity(true);
  3802. }
  3803. if (lang_is_selected())
  3804. lcd_return_to_status();
  3805. else
  3806. lang_select(LANG_ID_PRI);
  3807. }
  3808. void lcd_wizard(WizState state)
  3809. {
  3810. using S = WizState;
  3811. bool end = false;
  3812. int wizard_event;
  3813. const char *msg = NULL;
  3814. while (!end) {
  3815. printf_P(PSTR("Wizard state: %d"), state);
  3816. switch (state) {
  3817. case S::Run: //Run wizard?
  3818. wizard_active = true;
  3819. 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
  3820. if (wizard_event) {
  3821. state = S::Restore;
  3822. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3823. }
  3824. else {
  3825. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3826. end = true;
  3827. }
  3828. break;
  3829. case S::Restore: // restore calibration status
  3830. switch (calibration_status()) {
  3831. case CALIBRATION_STATUS_ASSEMBLED: state = S::Selftest; break; //run selftest
  3832. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = S::Xyz; break; //run xyz cal.
  3833. case CALIBRATION_STATUS_Z_CALIBRATION: state = S::Z; break; //run z cal.
  3834. case CALIBRATION_STATUS_LIVE_ADJUST: state = S::IsFil; break; //run live adjust
  3835. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3836. default: state = S::Selftest; break; //if calibration status is unknown, run wizard from the beginning
  3837. }
  3838. break;
  3839. case S::Selftest:
  3840. 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
  3841. wizard_event = lcd_selftest();
  3842. if (wizard_event) {
  3843. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3844. state = S::Xyz;
  3845. }
  3846. else end = true;
  3847. break;
  3848. case S::Xyz: //xyz calibration
  3849. 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
  3850. wizard_event = gcode_M45(false, 0);
  3851. if (wizard_event) state = S::IsFil;
  3852. else end = true;
  3853. break;
  3854. case S::Z: //z calibration
  3855. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3856. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  3857. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3858. wizard_event = gcode_M45(true, 0);
  3859. if (wizard_event) state = S::Finish; //shipped, no need to set first layer, go to final message directly
  3860. else end = true;
  3861. break;
  3862. case S::IsFil: //is filament loaded?
  3863. //start to preheat nozzle and bed to save some time later
  3864. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3865. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3866. if (mmu_enabled)
  3867. {
  3868. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament 1 loaded?"), false);////c=20 r=2
  3869. } else
  3870. {
  3871. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament loaded?"), false);////MSG_WIZARD_FILAMENT_LOADED c=20 r=2
  3872. }
  3873. if (wizard_event) state = S::IsPla;
  3874. else
  3875. {
  3876. if(mmu_enabled) state = S::LoadFil;
  3877. else state = S::Preheat;
  3878. }
  3879. break;
  3880. case S::Preheat:
  3881. #ifndef SNMM
  3882. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3883. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3884. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 60, active_extruder);
  3885. delay_keep_alive(2000);
  3886. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3887. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3888. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3889. lcd_set_cursor(0, 4);
  3890. lcd_print(LCD_STR_THERMOMETER[0]);
  3891. lcd_print(ftostr3(degHotend(0)));
  3892. lcd_print("/");
  3893. lcd_print(PLA_PREHEAT_HOTEND_TEMP);
  3894. lcd_print(LCD_STR_DEGREE);
  3895. lcd_set_custom_characters();
  3896. delay_keep_alive(1000);
  3897. }
  3898. #endif //not SNMM
  3899. state = S::LoadFil;
  3900. break;
  3901. case S::LoadFil: //load filament
  3902. if (mmu_enabled)
  3903. {
  3904. lcd_show_fullscreen_message_and_wait_P(_i("Please insert PLA filament to the first tube of MMU, then press the knob to load it."));////c=20 r=8
  3905. } else
  3906. {
  3907. lcd_show_fullscreen_message_and_wait_P(_i("Please insert PLA filament to the extruder, then press knob to load it."));////MSG_WIZARD_LOAD_FILAMENT c=20 r=8
  3908. }
  3909. lcd_update_enable(false);
  3910. lcd_clear();
  3911. lcd_puts_at_P(0, 2, _T(MSG_LOADING_FILAMENT));
  3912. #ifdef SNMM
  3913. change_extr(0);
  3914. #endif
  3915. loading_flag = true;
  3916. gcode_M701();
  3917. state = S::Lay1Cal;
  3918. break;
  3919. case S::IsPla:
  3920. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is it PLA filament?"), false, true);////MSG_WIZARD_PLA_FILAMENT c=20 r=2
  3921. if (wizard_event) state = S::Lay1Cal;
  3922. else end = true;
  3923. break;
  3924. case S::Lay1Cal:
  3925. lcd_show_fullscreen_message_and_wait_P(_i("Now I will calibrate distance between tip of the nozzle and heatbed surface."));////MSG_WIZARD_V2_CAL c=20 r=8
  3926. lcd_show_fullscreen_message_and_wait_P(_i("I will start to print line and you will gradually lower the nozzle by rotating the knob, until you reach optimal height. Check the pictures in our handbook in chapter Calibration."));////MSG_WIZARD_V2_CAL_2 c=20 r=12
  3927. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3928. end = true;
  3929. break;
  3930. case S::RepeatLay1Cal: //repeat first layer cal.?
  3931. 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
  3932. if (wizard_event) {
  3933. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3934. state = S::Lay1Cal;
  3935. }
  3936. else {
  3937. state = S::Finish;
  3938. }
  3939. break;
  3940. case S::Finish: //we are finished
  3941. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3942. end = true;
  3943. break;
  3944. default: break;
  3945. }
  3946. }
  3947. printf_P(_N("Wizard end state: %d\n"), state);
  3948. switch (state) { //final message
  3949. case S::Run: //user dont want to use wizard
  3950. msg = _T(MSG_WIZARD_QUIT);
  3951. break;
  3952. case S::Restore: //printer was already calibrated
  3953. msg = _T(MSG_WIZARD_DONE);
  3954. break;
  3955. case S::Selftest: //selftest
  3956. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3957. break;
  3958. case S::Xyz: //xyz cal.
  3959. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3960. break;
  3961. case S::Z: //z cal.
  3962. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3963. break;
  3964. case S::IsPla:
  3965. msg = _i("Please load PLA filament and then resume Wizard by rebooting the printer.");////MSG_WIZARD_INSERT_CORRECT_FILAMENT c=20 r=8
  3966. break;
  3967. case S::Lay1Cal: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3968. case S::Finish: //we are finished
  3969. msg = _T(MSG_WIZARD_DONE);
  3970. lcd_reset_alert_level();
  3971. lcd_setstatuspgm(_T(WELCOME_MSG));
  3972. break;
  3973. default:
  3974. msg = _T(MSG_WIZARD_QUIT);
  3975. break;
  3976. }
  3977. if (state != S::Lay1Cal) {
  3978. lcd_show_fullscreen_message_and_wait_P(msg);
  3979. wizard_active = false;
  3980. }
  3981. lcd_update_enable(true);
  3982. lcd_return_to_status();
  3983. lcd_update(2);
  3984. }
  3985. #ifdef TMC2130
  3986. void lcd_settings_linearity_correction_menu(void)
  3987. {
  3988. MENU_BEGIN();
  3989. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3990. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3991. //tmc2130_wave_fac[X_AXIS]
  3992. 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=9 r=0
  3993. 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=9 r=0
  3994. 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=9 r=0
  3995. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3996. 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=9 r=0
  3997. MENU_END();
  3998. if(menu_leaving)
  3999. {
  4000. lcd_settings_linearity_correction_menu_save();
  4001. }
  4002. }
  4003. #endif // TMC2130
  4004. #ifdef FILAMENT_SENSOR
  4005. #define SETTINGS_FILAMENT_SENSOR \
  4006. do\
  4007. {\
  4008. if (FSensorStateMenu == 0)\
  4009. {\
  4010. if (fsensor_not_responding)\
  4011. {\
  4012. /* Filament sensor not working*/\
  4013. MENU_ITEM_FUNCTION_P(_i("Fil. sensor [N/A]"), lcd_fsensor_state_set);/*////MSG_FSENSOR_NA c=0 r=0*/\
  4014. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail);\
  4015. }\
  4016. else\
  4017. {\
  4018. /* Filament sensor turned off, working, no problems*/\
  4019. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);\
  4020. if (mmu_enabled == false)if (mmu_enabled == false)\
  4021. {\
  4022. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info);\
  4023. }\
  4024. }\
  4025. }\
  4026. else\
  4027. {\
  4028. /* Filament sensor turned on, working, no problems*/\
  4029. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);\
  4030. if (mmu_enabled == false)\
  4031. {\
  4032. if (fsensor_autoload_enabled)\
  4033. MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_ON c=17 r=1*/\
  4034. else\
  4035. MENU_ITEM_FUNCTION_P(_i("F. autoload [off]"), lcd_set_filament_autoload);/*////MSG_FSENS_AUTOLOAD_OFF c=17 r=1*/\
  4036. }\
  4037. }\
  4038. }\
  4039. while(0)
  4040. #else //FILAMENT_SENSOR
  4041. #define SETTINGS_FILAMENT_SENSOR do{}while(0)
  4042. #endif //FILAMENT_SENSOR
  4043. #ifdef TMC2130
  4044. #define SETTINGS_SILENT_MODE \
  4045. do\
  4046. {\
  4047. if(!farm_mode)\
  4048. {\
  4049. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4050. {\
  4051. MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);\
  4052. }\
  4053. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);\
  4054. if (SilentModeMenu == SILENT_MODE_NORMAL)\
  4055. {\
  4056. if (CrashDetectMenu == 0)\
  4057. {\
  4058. MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);\
  4059. }\
  4060. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);\
  4061. }\
  4062. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);\
  4063. }\
  4064. }\
  4065. while (0)
  4066. #else //TMC2130
  4067. #define SETTINGS_SILENT_MODE \
  4068. do\
  4069. {\
  4070. if(!farm_mode)\
  4071. {\
  4072. switch (SilentModeMenu)\
  4073. {\
  4074. case SILENT_MODE_POWER:\
  4075. MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set);\
  4076. break;\
  4077. case SILENT_MODE_SILENT:\
  4078. MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set);\
  4079. break;\
  4080. case SILENT_MODE_AUTO:\
  4081. MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set);\
  4082. break;\
  4083. default:\
  4084. MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set);\
  4085. break; /* (probably) not needed*/\
  4086. }\
  4087. }\
  4088. }\
  4089. while (0)
  4090. #endif //TMC2130
  4091. #ifdef SDCARD_SORT_ALPHA
  4092. #define SETTINGS_SD \
  4093. do\
  4094. {\
  4095. if (card.ToshibaFlashAir_isEnabled())\
  4096. MENU_ITEM_FUNCTION_P(_i("SD card [flshAir]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1*/\
  4097. else\
  4098. MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1*/\
  4099. \
  4100. if (!farm_mode)\
  4101. {\
  4102. uint8_t sdSort;\
  4103. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));\
  4104. switch (sdSort)\
  4105. {\
  4106. case SD_SORT_TIME: MENU_ITEM_FUNCTION_P(_i("Sort: [time]"), lcd_sort_type_set); break;/*////MSG_SORT_TIME c=17 r=1*/\
  4107. case SD_SORT_ALPHA: MENU_ITEM_FUNCTION_P(_i("Sort: [alphabet]"), lcd_sort_type_set); break;/*////MSG_SORT_ALPHA c=17 r=1*/\
  4108. default: MENU_ITEM_FUNCTION_P(_i("Sort: [none]"), lcd_sort_type_set);/*////MSG_SORT_NONE c=17 r=1*/\
  4109. }\
  4110. }\
  4111. }\
  4112. while (0)
  4113. #else // SDCARD_SORT_ALPHA
  4114. #define SETTINGS_SD \
  4115. do\
  4116. {\
  4117. if (card.ToshibaFlashAir_isEnabled())\
  4118. MENU_ITEM_FUNCTION_P(_i("SD card [flshAir]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1*/\
  4119. else\
  4120. MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);/*////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1*/\
  4121. }\
  4122. while (0)
  4123. #endif // SDCARD_SORT_ALPHA
  4124. #define SETTINGS_SOUND \
  4125. do\
  4126. {\
  4127. switch(eSoundMode)\
  4128. {\
  4129. case e_SOUND_MODE_LOUD:\
  4130. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);\
  4131. break;\
  4132. case e_SOUND_MODE_ONCE:\
  4133. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_ONCE),lcd_sound_state_set);\
  4134. break;\
  4135. case e_SOUND_MODE_SILENT:\
  4136. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);\
  4137. break;\
  4138. case e_SOUND_MODE_MUTE:\
  4139. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);\
  4140. break;\
  4141. default:\
  4142. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);\
  4143. }\
  4144. }\
  4145. while (0)
  4146. static void auto_deplete_switch()
  4147. {
  4148. lcd_autoDeplete = !lcd_autoDeplete;
  4149. eeprom_update_byte((unsigned char *)EEPROM_AUTO_DEPLETE, lcd_autoDeplete);
  4150. }
  4151. static void lcd_settings_menu()
  4152. {
  4153. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4154. MENU_BEGIN();
  4155. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4156. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0
  4157. if (!homing_flag)
  4158. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0
  4159. if (!isPrintPaused)
  4160. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0
  4161. SETTINGS_FILAMENT_SENSOR;
  4162. if (mmu_enabled)
  4163. {
  4164. if (lcd_autoDeplete) MENU_ITEM_FUNCTION_P(_i("Auto deplete [on]"), auto_deplete_switch);
  4165. else MENU_ITEM_FUNCTION_P(_i("Auto deplete[off]"), auto_deplete_switch);
  4166. }
  4167. if (fans_check_enabled == true)
  4168. MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
  4169. else
  4170. MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1
  4171. SETTINGS_SILENT_MODE;
  4172. #if defined (TMC2130) && defined (LINEARITY_CORRECTION)
  4173. MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu);
  4174. #endif //LINEARITY_CORRECTION && TMC2130
  4175. if (temp_cal_active == false)
  4176. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1
  4177. else
  4178. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1
  4179. #ifdef HAS_SECOND_SERIAL_PORT
  4180. if (selectedSerialPort == 0)
  4181. MENU_ITEM_FUNCTION_P(_i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1
  4182. else
  4183. MENU_ITEM_FUNCTION_P(_i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1
  4184. #endif //HAS_SECOND_SERIAL
  4185. if (!isPrintPaused && !homing_flag)
  4186. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  4187. #if (LANG_MODE != 0)
  4188. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0
  4189. #endif //(LANG_MODE != 0)
  4190. SETTINGS_SD;
  4191. SETTINGS_SOUND;
  4192. if (farm_mode)
  4193. {
  4194. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  4195. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  4196. }
  4197. MENU_END();
  4198. }
  4199. #ifdef TMC2130
  4200. static void lcd_ustep_linearity_menu_save()
  4201. {
  4202. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  4203. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  4204. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  4205. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  4206. }
  4207. #endif //TMC2130
  4208. static void lcd_settings_linearity_correction_menu_save()
  4209. {
  4210. #ifdef TMC2130
  4211. bool changed = false;
  4212. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  4213. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  4214. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  4215. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  4216. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  4217. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  4218. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  4219. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  4220. lcd_ustep_linearity_menu_save();
  4221. if (changed) tmc2130_init();
  4222. #endif //TMC2130
  4223. }
  4224. static void lcd_calibration_menu()
  4225. {
  4226. MENU_BEGIN();
  4227. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4228. if (!isPrintPaused)
  4229. {
  4230. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  4231. MENU_ITEM_SUBMENU_P(_i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1
  4232. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  4233. MENU_ITEM_FUNCTION_P(_i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=0 r=0
  4234. #ifdef MK1BP
  4235. // MK1
  4236. // "Calibrate Z"
  4237. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  4238. #else //MK1BP
  4239. // MK2
  4240. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=0 r=0
  4241. // "Calibrate Z" with storing the reference values to EEPROM.
  4242. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  4243. #ifndef SNMM
  4244. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  4245. #endif
  4246. // "Mesh Bed Leveling"
  4247. MENU_ITEM_SUBMENU_P(_i("Mesh Bed Leveling"), lcd_mesh_bedleveling);////MSG_MESH_BED_LEVELING c=0 r=0
  4248. #endif //MK1BP
  4249. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=0 r=0
  4250. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  4251. #ifdef TMC2130
  4252. MENU_ITEM_SUBMENU_P(_i("Show pinda state"), menu_show_pinda_state);
  4253. #else
  4254. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=17 r=1
  4255. #endif
  4256. #ifndef MK1BP
  4257. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=0 r=0
  4258. #endif //MK1BP
  4259. #ifndef SNMM
  4260. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  4261. #endif
  4262. #ifndef MK1BP
  4263. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  4264. #endif //MK1BP
  4265. }
  4266. MENU_END();
  4267. }
  4268. void bowden_menu() {
  4269. int enc_dif = lcd_encoder_diff;
  4270. int cursor_pos = 0;
  4271. lcd_clear();
  4272. lcd_set_cursor(0, 0);
  4273. lcd_print(">");
  4274. for (int i = 0; i < 4; i++) {
  4275. lcd_set_cursor(1, i);
  4276. lcd_print("Extruder ");
  4277. lcd_print(i);
  4278. lcd_print(": ");
  4279. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4280. lcd_print(bowden_length[i] - 48);
  4281. }
  4282. enc_dif = lcd_encoder_diff;
  4283. while (1) {
  4284. manage_heater();
  4285. manage_inactivity(true);
  4286. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4287. if (enc_dif > lcd_encoder_diff) {
  4288. cursor_pos--;
  4289. }
  4290. if (enc_dif < lcd_encoder_diff) {
  4291. cursor_pos++;
  4292. }
  4293. if (cursor_pos > 3) {
  4294. cursor_pos = 3;
  4295. }
  4296. if (cursor_pos < 0) {
  4297. cursor_pos = 0;
  4298. }
  4299. lcd_set_cursor(0, 0);
  4300. lcd_print(" ");
  4301. lcd_set_cursor(0, 1);
  4302. lcd_print(" ");
  4303. lcd_set_cursor(0, 2);
  4304. lcd_print(" ");
  4305. lcd_set_cursor(0, 3);
  4306. lcd_print(" ");
  4307. lcd_set_cursor(0, cursor_pos);
  4308. lcd_print(">");
  4309. enc_dif = lcd_encoder_diff;
  4310. delay(100);
  4311. }
  4312. if (lcd_clicked()) {
  4313. while (lcd_clicked());
  4314. delay(10);
  4315. while (lcd_clicked());
  4316. lcd_clear();
  4317. while (1) {
  4318. manage_heater();
  4319. manage_inactivity(true);
  4320. lcd_set_cursor(1, 1);
  4321. lcd_print("Extruder ");
  4322. lcd_print(cursor_pos);
  4323. lcd_print(": ");
  4324. lcd_set_cursor(13, 1);
  4325. lcd_print(bowden_length[cursor_pos] - 48);
  4326. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4327. if (enc_dif > lcd_encoder_diff) {
  4328. bowden_length[cursor_pos]--;
  4329. lcd_set_cursor(13, 1);
  4330. lcd_print(bowden_length[cursor_pos] - 48);
  4331. enc_dif = lcd_encoder_diff;
  4332. }
  4333. if (enc_dif < lcd_encoder_diff) {
  4334. bowden_length[cursor_pos]++;
  4335. lcd_set_cursor(13, 1);
  4336. lcd_print(bowden_length[cursor_pos] - 48);
  4337. enc_dif = lcd_encoder_diff;
  4338. }
  4339. }
  4340. delay(100);
  4341. if (lcd_clicked()) {
  4342. while (lcd_clicked());
  4343. delay(10);
  4344. while (lcd_clicked());
  4345. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  4346. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  4347. lcd_update_enable(true);
  4348. lcd_clear();
  4349. enc_dif = lcd_encoder_diff;
  4350. lcd_set_cursor(0, cursor_pos);
  4351. lcd_print(">");
  4352. for (int i = 0; i < 4; i++) {
  4353. lcd_set_cursor(1, i);
  4354. lcd_print("Extruder ");
  4355. lcd_print(i);
  4356. lcd_print(": ");
  4357. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4358. lcd_print(bowden_length[i] - 48);
  4359. }
  4360. break;
  4361. }
  4362. else return;
  4363. }
  4364. }
  4365. }
  4366. }
  4367. }
  4368. //#ifdef SNMM
  4369. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  4370. lcd_clear();
  4371. lcd_puts_at_P(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd_print(":");
  4372. lcd_set_cursor(0, 1); lcd_print(">");
  4373. lcd_puts_at_P(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  4374. lcd_puts_at_P(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  4375. char cursor_pos = 1;
  4376. int enc_dif = 0;
  4377. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4378. while (1) {
  4379. manage_heater();
  4380. manage_inactivity(true);
  4381. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4382. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4383. if (enc_dif > lcd_encoder_diff) cursor_pos--;
  4384. if (enc_dif < lcd_encoder_diff) cursor_pos++;
  4385. if (cursor_pos > 3) cursor_pos = 3;
  4386. if (cursor_pos < 1) cursor_pos = 1;
  4387. lcd_set_cursor(0, 1);
  4388. lcd_print(" ");
  4389. lcd_set_cursor(0, 2);
  4390. lcd_print(" ");
  4391. lcd_set_cursor(0, 3);
  4392. lcd_print(" ");
  4393. lcd_set_cursor(0, cursor_pos);
  4394. lcd_print(">");
  4395. enc_dif = lcd_encoder_diff;
  4396. delay(100);
  4397. }
  4398. }
  4399. if (lcd_clicked()) {
  4400. while (lcd_clicked());
  4401. delay(10);
  4402. while (lcd_clicked());
  4403. KEEPALIVE_STATE(IN_HANDLER);
  4404. return(cursor_pos - 1);
  4405. }
  4406. }
  4407. }
  4408. //! @brief Select one of numbered items
  4409. //!
  4410. //! Create list of items with header. Header can not be selected.
  4411. //! Each item has text description passed by function parameter and
  4412. //! number. There are 5 numbered items, if mmu_enabled, 4 otherwise.
  4413. //! Items are numbered from 1 to 4 or 5. But index returned starts at 0.
  4414. //! There can be last item with different text and no number.
  4415. //!
  4416. //! @param header Header text
  4417. //! @param item Item text
  4418. //! @param last_item Last item text, or nullptr if there is no Last item
  4419. //! @return selected item index, first item index is 0
  4420. uint8_t choose_menu_P(const char *header, const char *item, const char *last_item)
  4421. {
  4422. //following code should handle 3 to 127 number of items well
  4423. const int8_t items_no = last_item?(mmu_enabled?6:5):(mmu_enabled?5:4);
  4424. const uint8_t item_len = item?strlen_P(item):0;
  4425. int8_t first = 0;
  4426. int8_t enc_dif = lcd_encoder_diff;
  4427. int8_t cursor_pos = 1;
  4428. lcd_clear();
  4429. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4430. while (1)
  4431. {
  4432. manage_heater();
  4433. manage_inactivity(true);
  4434. if (abs((enc_dif - lcd_encoder_diff)) > 4)
  4435. {
  4436. if (enc_dif > lcd_encoder_diff)
  4437. {
  4438. cursor_pos--;
  4439. }
  4440. if (enc_dif < lcd_encoder_diff)
  4441. {
  4442. cursor_pos++;
  4443. }
  4444. enc_dif = lcd_encoder_diff;
  4445. }
  4446. if (cursor_pos > 3)
  4447. {
  4448. cursor_pos = 3;
  4449. if (first < items_no - 3)
  4450. {
  4451. first++;
  4452. lcd_clear();
  4453. }
  4454. }
  4455. if (cursor_pos < 1)
  4456. {
  4457. cursor_pos = 1;
  4458. if (first > 0)
  4459. {
  4460. first--;
  4461. lcd_clear();
  4462. }
  4463. }
  4464. if (header) lcd_puts_at_P(0,0,header);
  4465. const bool last_visible = (first == items_no - 3);
  4466. const int8_t ordinary_items = (last_item&&last_visible)?2:3;
  4467. for (int i = 0; i < ordinary_items; i++)
  4468. {
  4469. if (item) lcd_puts_at_P(1, i + 1, item);
  4470. }
  4471. for (int i = 0; i < ordinary_items; i++)
  4472. {
  4473. lcd_set_cursor(2 + item_len, i+1);
  4474. lcd_print(first + i + 1);
  4475. }
  4476. if (last_item&&last_visible) lcd_puts_at_P(1, 3, last_item);
  4477. lcd_set_cursor(0, 1);
  4478. lcd_print(" ");
  4479. lcd_set_cursor(0, 2);
  4480. lcd_print(" ");
  4481. lcd_set_cursor(0, 3);
  4482. lcd_print(" ");
  4483. lcd_set_cursor(0, cursor_pos);
  4484. lcd_print(">");
  4485. delay(100);
  4486. if (lcd_clicked())
  4487. {
  4488. KEEPALIVE_STATE(IN_HANDLER);
  4489. return(cursor_pos + first - 1);
  4490. }
  4491. }
  4492. }
  4493. //#endif
  4494. char reset_menu() {
  4495. #ifdef SNMM
  4496. int items_no = 5;
  4497. #else
  4498. int items_no = 4;
  4499. #endif
  4500. static int first = 0;
  4501. int enc_dif = 0;
  4502. char cursor_pos = 0;
  4503. const char *item [items_no];
  4504. item[0] = "Language";
  4505. item[1] = "Statistics";
  4506. item[2] = "Shipping prep";
  4507. item[3] = "All Data";
  4508. #ifdef SNMM
  4509. item[4] = "Bowden length";
  4510. #endif // SNMM
  4511. enc_dif = lcd_encoder_diff;
  4512. lcd_clear();
  4513. lcd_set_cursor(0, 0);
  4514. lcd_print(">");
  4515. while (1) {
  4516. for (int i = 0; i < 4; i++) {
  4517. lcd_set_cursor(1, i);
  4518. lcd_print(item[first + i]);
  4519. }
  4520. manage_heater();
  4521. manage_inactivity(true);
  4522. if (abs((enc_dif - lcd_encoder_diff)) > 4) {
  4523. if ((abs(enc_dif - lcd_encoder_diff)) > 1) {
  4524. if (enc_dif > lcd_encoder_diff) {
  4525. cursor_pos--;
  4526. }
  4527. if (enc_dif < lcd_encoder_diff) {
  4528. cursor_pos++;
  4529. }
  4530. if (cursor_pos > 3) {
  4531. cursor_pos = 3;
  4532. if (first < items_no - 4) {
  4533. first++;
  4534. lcd_clear();
  4535. }
  4536. }
  4537. if (cursor_pos < 0) {
  4538. cursor_pos = 0;
  4539. if (first > 0) {
  4540. first--;
  4541. lcd_clear();
  4542. }
  4543. }
  4544. lcd_set_cursor(0, 0);
  4545. lcd_print(" ");
  4546. lcd_set_cursor(0, 1);
  4547. lcd_print(" ");
  4548. lcd_set_cursor(0, 2);
  4549. lcd_print(" ");
  4550. lcd_set_cursor(0, 3);
  4551. lcd_print(" ");
  4552. lcd_set_cursor(0, cursor_pos);
  4553. lcd_print(">");
  4554. enc_dif = lcd_encoder_diff;
  4555. delay(100);
  4556. }
  4557. }
  4558. if (lcd_clicked()) {
  4559. while (lcd_clicked());
  4560. delay(10);
  4561. while (lcd_clicked());
  4562. return(cursor_pos + first);
  4563. }
  4564. }
  4565. }
  4566. static void lcd_disable_farm_mode()
  4567. {
  4568. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4569. if (disable)
  4570. {
  4571. enquecommand_P(PSTR("G99"));
  4572. lcd_return_to_status();
  4573. }
  4574. lcd_update_enable(true);
  4575. lcd_draw_update = 2;
  4576. }
  4577. static void fil_load_menu()
  4578. {
  4579. MENU_BEGIN();
  4580. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4581. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all);////MSG_LOAD_ALL c=17 r=0
  4582. MENU_ITEM_FUNCTION_P(_i("Load filament 1"), extr_adj_0);////MSG_LOAD_FILAMENT_1 c=17 r=0
  4583. MENU_ITEM_FUNCTION_P(_i("Load filament 2"), extr_adj_1);////MSG_LOAD_FILAMENT_2 c=17 r=0
  4584. MENU_ITEM_FUNCTION_P(_i("Load filament 3"), extr_adj_2);////MSG_LOAD_FILAMENT_3 c=17 r=0
  4585. MENU_ITEM_FUNCTION_P(_i("Load filament 4"), extr_adj_3);////MSG_LOAD_FILAMENT_4 c=17 r=0
  4586. if (mmu_enabled)
  4587. MENU_ITEM_FUNCTION_P(_i("Load filament 5"), extr_adj_4);
  4588. MENU_END();
  4589. }
  4590. static void mmu_fil_eject_menu()
  4591. {
  4592. MENU_BEGIN();
  4593. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4594. MENU_ITEM_FUNCTION_P(_i("Eject filament 1"), mmu_eject_fil_0);
  4595. MENU_ITEM_FUNCTION_P(_i("Eject filament 2"), mmu_eject_fil_1);
  4596. MENU_ITEM_FUNCTION_P(_i("Eject filament 3"), mmu_eject_fil_2);
  4597. MENU_ITEM_FUNCTION_P(_i("Eject filament 4"), mmu_eject_fil_3);
  4598. MENU_ITEM_FUNCTION_P(_i("Eject filament 5"), mmu_eject_fil_4);
  4599. MENU_END();
  4600. }
  4601. static void fil_unload_menu()
  4602. {
  4603. MENU_BEGIN();
  4604. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4605. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=17 r=0
  4606. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17 r=0
  4607. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17 r=0
  4608. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17 r=0
  4609. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4610. if (mmu_enabled)
  4611. MENU_ITEM_FUNCTION_P(_i("Unload filament 5"), extr_unload_4);////MSG_UNLOAD_FILAMENT_5 c=17 r=0
  4612. MENU_END();
  4613. }
  4614. static void change_extr_menu(){
  4615. MENU_BEGIN();
  4616. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4617. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  4618. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  4619. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  4620. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  4621. MENU_END();
  4622. }
  4623. //unload filament for single material printer (used in M702 gcode)
  4624. void unload_filament()
  4625. {
  4626. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
  4627. lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));
  4628. // extr_unload2();
  4629. current_position[E_AXIS] -= 45;
  4630. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 5200 / 60, active_extruder);
  4631. st_synchronize();
  4632. current_position[E_AXIS] -= 15;
  4633. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder);
  4634. st_synchronize();
  4635. current_position[E_AXIS] -= 20;
  4636. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder);
  4637. st_synchronize();
  4638. lcd_display_message_fullscreen_P(_T(MSG_PULL_OUT_FILAMENT));
  4639. //disable extruder steppers so filament can be removed
  4640. disable_e0();
  4641. disable_e1();
  4642. disable_e2();
  4643. delay(100);
  4644. Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
  4645. uint8_t counterBeep = 0;
  4646. while (!lcd_clicked() && (counterBeep < 50)) {
  4647. delay_keep_alive(100);
  4648. counterBeep++;
  4649. }
  4650. st_synchronize();
  4651. while (lcd_clicked()) delay_keep_alive(100);
  4652. lcd_update_enable(true);
  4653. lcd_setstatuspgm(_T(WELCOME_MSG));
  4654. custom_message_type = CUSTOM_MSG_TYPE_STATUS;
  4655. }
  4656. static void lcd_farm_no()
  4657. {
  4658. char step = 0;
  4659. int enc_dif = 0;
  4660. int _farmno = farm_no;
  4661. int _ret = 0;
  4662. lcd_clear();
  4663. lcd_set_cursor(0, 0);
  4664. lcd_print("Farm no");
  4665. do
  4666. {
  4667. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  4668. if (enc_dif > lcd_encoder_diff) {
  4669. switch (step) {
  4670. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4671. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4672. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4673. default: break;
  4674. }
  4675. }
  4676. if (enc_dif < lcd_encoder_diff) {
  4677. switch (step) {
  4678. case(0): if (_farmno < 900) _farmno += 100; break;
  4679. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4680. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4681. default: break;
  4682. }
  4683. }
  4684. enc_dif = 0;
  4685. lcd_encoder_diff = 0;
  4686. }
  4687. lcd_set_cursor(0, 2);
  4688. if (_farmno < 100) lcd_print("0");
  4689. if (_farmno < 10) lcd_print("0");
  4690. lcd_print(_farmno);
  4691. lcd_print(" ");
  4692. lcd_set_cursor(0, 3);
  4693. lcd_print(" ");
  4694. lcd_set_cursor(step, 3);
  4695. lcd_print("^");
  4696. delay(100);
  4697. if (lcd_clicked())
  4698. {
  4699. delay(200);
  4700. step++;
  4701. if(step == 3) {
  4702. _ret = 1;
  4703. farm_no = _farmno;
  4704. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4705. prusa_statistics(20);
  4706. lcd_return_to_status();
  4707. }
  4708. }
  4709. manage_heater();
  4710. } while (_ret == 0);
  4711. }
  4712. unsigned char lcd_choose_color() {
  4713. //function returns index of currently chosen item
  4714. //following part can be modified from 2 to 255 items:
  4715. //-----------------------------------------------------
  4716. unsigned char items_no = 2;
  4717. const char *item[items_no];
  4718. item[0] = "Orange";
  4719. item[1] = "Black";
  4720. //-----------------------------------------------------
  4721. unsigned char active_rows;
  4722. static int first = 0;
  4723. int enc_dif = 0;
  4724. unsigned char cursor_pos = 1;
  4725. enc_dif = lcd_encoder_diff;
  4726. lcd_clear();
  4727. lcd_set_cursor(0, 1);
  4728. lcd_print(">");
  4729. active_rows = items_no < 3 ? items_no : 3;
  4730. while (1) {
  4731. lcd_puts_at_P(0, 0, PSTR("Choose color:"));
  4732. for (int i = 0; i < active_rows; i++) {
  4733. lcd_set_cursor(1, i+1);
  4734. lcd_print(item[first + i]);
  4735. }
  4736. manage_heater();
  4737. manage_inactivity(true);
  4738. proc_commands();
  4739. if (abs((enc_dif - lcd_encoder_diff)) > 12) {
  4740. if (enc_dif > lcd_encoder_diff) {
  4741. cursor_pos--;
  4742. }
  4743. if (enc_dif < lcd_encoder_diff) {
  4744. cursor_pos++;
  4745. }
  4746. if (cursor_pos > active_rows) {
  4747. cursor_pos = active_rows;
  4748. if (first < items_no - active_rows) {
  4749. first++;
  4750. lcd_clear();
  4751. }
  4752. }
  4753. if (cursor_pos < 1) {
  4754. cursor_pos = 1;
  4755. if (first > 0) {
  4756. first--;
  4757. lcd_clear();
  4758. }
  4759. }
  4760. lcd_set_cursor(0, 1);
  4761. lcd_print(" ");
  4762. lcd_set_cursor(0, 2);
  4763. lcd_print(" ");
  4764. lcd_set_cursor(0, 3);
  4765. lcd_print(" ");
  4766. lcd_set_cursor(0, cursor_pos);
  4767. lcd_print(">");
  4768. enc_dif = lcd_encoder_diff;
  4769. delay(100);
  4770. }
  4771. if (lcd_clicked()) {
  4772. while (lcd_clicked());
  4773. delay(10);
  4774. while (lcd_clicked());
  4775. switch(cursor_pos + first - 1) {
  4776. case 0: return 1; break;
  4777. case 1: return 0; break;
  4778. default: return 99; break;
  4779. }
  4780. }
  4781. }
  4782. }
  4783. void lcd_confirm_print()
  4784. {
  4785. uint8_t filament_type;
  4786. int enc_dif = 0;
  4787. int cursor_pos = 1;
  4788. int _ret = 0;
  4789. int _t = 0;
  4790. enc_dif = lcd_encoder_diff;
  4791. lcd_clear();
  4792. lcd_set_cursor(0, 0);
  4793. lcd_print("Print ok ?");
  4794. do
  4795. {
  4796. if (abs(enc_dif - lcd_encoder_diff) > 12) {
  4797. if (enc_dif > lcd_encoder_diff) {
  4798. cursor_pos--;
  4799. }
  4800. if (enc_dif < lcd_encoder_diff) {
  4801. cursor_pos++;
  4802. }
  4803. enc_dif = lcd_encoder_diff;
  4804. }
  4805. if (cursor_pos > 2) { cursor_pos = 2; }
  4806. if (cursor_pos < 1) { cursor_pos = 1; }
  4807. lcd_set_cursor(0, 2); lcd_print(" ");
  4808. lcd_set_cursor(0, 3); lcd_print(" ");
  4809. lcd_set_cursor(2, 2);
  4810. lcd_puts_P(_T(MSG_YES));
  4811. lcd_set_cursor(2, 3);
  4812. lcd_puts_P(_T(MSG_NO));
  4813. lcd_set_cursor(0, 1 + cursor_pos);
  4814. lcd_print(">");
  4815. delay(100);
  4816. _t = _t + 1;
  4817. if (_t>100)
  4818. {
  4819. prusa_statistics(99);
  4820. _t = 0;
  4821. }
  4822. if (lcd_clicked())
  4823. {
  4824. if (cursor_pos == 1)
  4825. {
  4826. _ret = 1;
  4827. filament_type = lcd_choose_color();
  4828. prusa_statistics(4, filament_type);
  4829. no_response = true; //we need confirmation by recieving PRUSA thx
  4830. important_status = 4;
  4831. saved_filament_type = filament_type;
  4832. NcTime = millis();
  4833. }
  4834. if (cursor_pos == 2)
  4835. {
  4836. _ret = 2;
  4837. filament_type = lcd_choose_color();
  4838. prusa_statistics(5, filament_type);
  4839. no_response = true; //we need confirmation by recieving PRUSA thx
  4840. important_status = 5;
  4841. saved_filament_type = filament_type;
  4842. NcTime = millis();
  4843. }
  4844. }
  4845. manage_heater();
  4846. manage_inactivity();
  4847. proc_commands();
  4848. } while (_ret == 0);
  4849. }
  4850. #include "w25x20cl.h"
  4851. #ifdef LCD_TEST
  4852. static void lcd_test_menu()
  4853. {
  4854. W25X20CL_SPI_ENTER();
  4855. w25x20cl_enable_wr();
  4856. w25x20cl_chip_erase();
  4857. w25x20cl_disable_wr();
  4858. }
  4859. #endif //LCD_TEST
  4860. //! @brief Resume paused print
  4861. //! @todo It is not good to call restore_print_from_ram_and_continue() from function called by lcd_update(),
  4862. //! as restore_print_from_ram_and_continue() calls lcd_update() internally.
  4863. void lcd_resume_print()
  4864. {
  4865. lcd_return_to_status();
  4866. lcd_setstatuspgm(_T(MSG_RESUMING_PRINT));
  4867. lcd_reset_alert_level(); //for fan speed error
  4868. restore_print_from_ram_and_continue(0.0);
  4869. pause_time += (millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  4870. isPrintPaused = false;
  4871. }
  4872. static void lcd_main_menu()
  4873. {
  4874. MENU_BEGIN();
  4875. // Majkl superawesome menu
  4876. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  4877. #ifdef RESUME_DEBUG
  4878. if (!saved_printing)
  4879. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4880. else
  4881. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4882. #endif //RESUME_DEBUG
  4883. #ifdef TMC2130_DEBUG
  4884. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4885. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4886. #endif //TMC2130_DEBUG
  4887. /* if (farm_mode && !IS_SD_PRINTING )
  4888. {
  4889. int tempScrool = 0;
  4890. if (lcd_draw_update == 0 && LCD_CLICKED == 0)
  4891. //delay(100);
  4892. return; // nothing to do (so don't thrash the SD card)
  4893. uint16_t fileCnt = card.getnrfilenames();
  4894. card.getWorkDirName();
  4895. if (card.filename[0] == '/')
  4896. {
  4897. #if SDCARDDETECT == -1
  4898. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  4899. #endif
  4900. } else {
  4901. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4902. }
  4903. for (uint16_t i = 0; i < fileCnt; i++)
  4904. {
  4905. if (menu_item == menu_line)
  4906. {
  4907. #ifndef SDCARD_RATHERRECENTFIRST
  4908. card.getfilename(i);
  4909. #else
  4910. card.getfilename(fileCnt - 1 - i);
  4911. #endif
  4912. if (card.filenameIsDir)
  4913. {
  4914. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4915. } else {
  4916. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4917. }
  4918. } else {
  4919. MENU_ITEM_DUMMY();
  4920. }
  4921. }
  4922. MENU_ITEM_BACK_P(PSTR("- - - - - - - - -"));
  4923. }*/
  4924. if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  4925. {
  4926. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4927. }
  4928. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4929. {
  4930. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=0 r=0
  4931. } else
  4932. {
  4933. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=0 r=0
  4934. }
  4935. #ifdef SDSUPPORT
  4936. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4937. {
  4938. if (card.isFileOpen())
  4939. {
  4940. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4941. if (card.sdprinting)
  4942. {
  4943. MENU_ITEM_FUNCTION_P(_i("Pause print"), lcd_pause_print);////MSG_PAUSE_PRINT c=0 r=0
  4944. }
  4945. else
  4946. {
  4947. MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT c=0 r=0
  4948. }
  4949. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4950. }
  4951. }
  4952. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4953. //MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4954. }
  4955. else
  4956. {
  4957. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4958. {
  4959. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4960. /*else*/ MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  4961. }
  4962. #if SDCARDDETECT < 1
  4963. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD c=0 r=0
  4964. #endif
  4965. }
  4966. } else
  4967. {
  4968. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=0 r=0
  4969. #if SDCARDDETECT < 1
  4970. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD c=0 r=0
  4971. #endif
  4972. }
  4973. #endif
  4974. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4975. {
  4976. if (farm_mode)
  4977. {
  4978. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  4979. }
  4980. }
  4981. else
  4982. {
  4983. if (mmu_enabled)
  4984. {
  4985. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  4986. MENU_ITEM_SUBMENU_P(_i("Eject filament"), mmu_fil_eject_menu);
  4987. if (mmu_enabled)
  4988. MENU_ITEM_GCODE_P(_T(MSG_UNLOAD_FILAMENT), PSTR("M702 C"));
  4989. else
  4990. {
  4991. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  4992. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  4993. }
  4994. }
  4995. else
  4996. {
  4997. #ifdef FILAMENT_SENSOR
  4998. if ((fsensor_autoload_enabled == true) && (fsensor_enabled == true) && (mmu_enabled == false))
  4999. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
  5000. else
  5001. #endif //FILAMENT_SENSOR
  5002. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  5003. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  5004. }
  5005. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  5006. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  5007. }
  5008. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  5009. {
  5010. MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0
  5011. }
  5012. #if defined(TMC2130) || defined(FILAMENT_SENSOR)
  5013. MENU_ITEM_SUBMENU_P(PSTR("Fail stats"), lcd_menu_fails_stats);
  5014. #endif
  5015. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
  5016. #ifdef LCD_TEST
  5017. MENU_ITEM_SUBMENU_P(_i("W25x20CL init"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
  5018. #endif //LCD_TEST
  5019. MENU_END();
  5020. }
  5021. void stack_error() {
  5022. SET_OUTPUT(BEEPER);
  5023. if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
  5024. WRITE(BEEPER, HIGH);
  5025. delay(1000);
  5026. WRITE(BEEPER, LOW);
  5027. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  5028. //err_triggered = 1;
  5029. while (1) delay_keep_alive(1000);
  5030. }
  5031. #ifdef DEBUG_STEPPER_TIMER_MISSED
  5032. bool stepper_timer_overflow_state = false;
  5033. uint16_t stepper_timer_overflow_max = 0;
  5034. uint16_t stepper_timer_overflow_last = 0;
  5035. uint16_t stepper_timer_overflow_cnt = 0;
  5036. void stepper_timer_overflow() {
  5037. char msg[28];
  5038. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  5039. lcd_setstatus(msg);
  5040. stepper_timer_overflow_state = false;
  5041. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  5042. stepper_timer_overflow_max = stepper_timer_overflow_last;
  5043. SERIAL_ECHOPGM("Stepper timer overflow: ");
  5044. MYSERIAL.print(msg);
  5045. SERIAL_ECHOLNPGM("");
  5046. WRITE(BEEPER, LOW);
  5047. }
  5048. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  5049. static void lcd_colorprint_change() {
  5050. enquecommand_P(PSTR("M600"));
  5051. custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; //just print status message
  5052. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  5053. lcd_return_to_status();
  5054. lcd_draw_update = 3;
  5055. }
  5056. static void lcd_tune_menu()
  5057. {
  5058. typedef struct
  5059. {
  5060. menu_data_edit_t reserved; //!< reserved for number editing functions
  5061. int8_t status; //!< To recognize, whether the menu has been just initialized.
  5062. //! Backup of extrudemultiply, to recognize, that the value has been changed and
  5063. //! it needs to be applied.
  5064. int16_t extrudemultiply;
  5065. } _menu_data_t;
  5066. static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
  5067. _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
  5068. if (_md->status == 0)
  5069. {
  5070. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  5071. _md->status = 1;
  5072. _md->extrudemultiply = extrudemultiply;
  5073. }
  5074. else if (_md->extrudemultiply != extrudemultiply)
  5075. {
  5076. // extrudemultiply has been changed from the child menu. Apply the new value.
  5077. _md->extrudemultiply = extrudemultiply;
  5078. calculate_extruder_multipliers();
  5079. }
  5080. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  5081. MENU_BEGIN();
  5082. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  5083. MENU_ITEM_EDIT_int3_P(_i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=0 r=0
  5084. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  5085. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  5086. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  5087. MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=0 r=0
  5088. #ifdef FILAMENTCHANGEENABLE
  5089. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7
  5090. #endif
  5091. #ifdef FILAMENT_SENSOR
  5092. if (FSensorStateMenu == 0) {
  5093. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  5094. }
  5095. else {
  5096. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  5097. }
  5098. #endif //FILAMENT_SENSOR
  5099. #ifdef TMC2130
  5100. if(!farm_mode)
  5101. {
  5102. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  5103. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  5104. if (SilentModeMenu == SILENT_MODE_NORMAL)
  5105. {
  5106. if (CrashDetectMenu == 0) MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  5107. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  5108. }
  5109. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  5110. }
  5111. #else //TMC2130
  5112. if (!farm_mode) { //dont show in menu if we are in farm mode
  5113. switch (SilentModeMenu) {
  5114. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  5115. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  5116. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  5117. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  5118. }
  5119. }
  5120. #endif //TMC2130
  5121. switch(eSoundMode)
  5122. {
  5123. case e_SOUND_MODE_LOUD:
  5124. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  5125. break;
  5126. case e_SOUND_MODE_ONCE:
  5127. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_ONCE),lcd_sound_state_set);
  5128. break;
  5129. case e_SOUND_MODE_SILENT:
  5130. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);
  5131. break;
  5132. case e_SOUND_MODE_MUTE:
  5133. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);
  5134. break;
  5135. default:
  5136. MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
  5137. }
  5138. MENU_END();
  5139. }
  5140. static void lcd_control_temperature_menu()
  5141. {
  5142. #ifdef PIDTEMP
  5143. // set up temp variables - undo the default scaling
  5144. // raw_Ki = unscalePID_i(Ki);
  5145. // raw_Kd = unscalePID_d(Kd);
  5146. #endif
  5147. MENU_BEGIN();
  5148. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  5149. #if TEMP_SENSOR_0 != 0
  5150. MENU_ITEM_EDIT_int3_P(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  5151. #endif
  5152. #if TEMP_SENSOR_1 != 0
  5153. MENU_ITEM_EDIT_int3_P(_i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1 c=0 r=0
  5154. #endif
  5155. #if TEMP_SENSOR_2 != 0
  5156. MENU_ITEM_EDIT_int3_P(_i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2 c=0 r=0
  5157. #endif
  5158. #if TEMP_SENSOR_BED != 0
  5159. MENU_ITEM_EDIT_int3_P(_T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  5160. #endif
  5161. MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  5162. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  5163. //MENU_ITEM_EDIT removed, following code must be redesigned if AUTOTEMP enabled
  5164. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  5165. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN c=0 r=0
  5166. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX c=0 r=0
  5167. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR c=0 r=0
  5168. #endif
  5169. MENU_END();
  5170. }
  5171. #if SDCARDDETECT == -1
  5172. static void lcd_sd_refresh()
  5173. {
  5174. card.initsd();
  5175. menu_top = 0;
  5176. }
  5177. #endif
  5178. static void lcd_sd_updir()
  5179. {
  5180. card.updir();
  5181. menu_top = 0;
  5182. }
  5183. void lcd_print_stop()
  5184. {
  5185. cancel_heatup = true;
  5186. #ifdef MESH_BED_LEVELING
  5187. mbl.active = false;
  5188. #endif
  5189. // Stop the stoppers, update the position from the stoppers.
  5190. if (mesh_bed_leveling_flag == false && homing_flag == false)
  5191. {
  5192. planner_abort_hard();
  5193. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  5194. // Z baystep is no more applied. Reset it.
  5195. babystep_reset();
  5196. }
  5197. // Clean the input command queue.
  5198. cmdqueue_reset();
  5199. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  5200. card.sdprinting = false;
  5201. card.closefile();
  5202. stoptime = millis();
  5203. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5204. pause_time = 0;
  5205. save_statistics(total_filament_used, t);
  5206. lcd_return_to_status();
  5207. lcd_ignore_click(true);
  5208. lcd_commands_step = 0;
  5209. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  5210. // Turn off the print fan
  5211. SET_OUTPUT(FAN_PIN);
  5212. WRITE(FAN_PIN, 0);
  5213. fanSpeed = 0;
  5214. }
  5215. void lcd_sdcard_stop()
  5216. {
  5217. lcd_set_cursor(0, 0);
  5218. lcd_puts_P(_T(MSG_STOP_PRINT));
  5219. lcd_set_cursor(2, 2);
  5220. lcd_puts_P(_T(MSG_NO));
  5221. lcd_set_cursor(2, 3);
  5222. lcd_puts_P(_T(MSG_YES));
  5223. lcd_set_cursor(0, 2); lcd_print(" ");
  5224. lcd_set_cursor(0, 3); lcd_print(" ");
  5225. if ((int32_t)lcd_encoder > 2) { lcd_encoder = 2; }
  5226. if ((int32_t)lcd_encoder < 1) { lcd_encoder = 1; }
  5227. lcd_set_cursor(0, 1 + lcd_encoder);
  5228. lcd_print(">");
  5229. if (lcd_clicked())
  5230. {
  5231. if ((int32_t)lcd_encoder == 1)
  5232. {
  5233. lcd_return_to_status();
  5234. }
  5235. if ((int32_t)lcd_encoder == 2)
  5236. {
  5237. lcd_print_stop();
  5238. }
  5239. }
  5240. }
  5241. void lcd_sdcard_menu()
  5242. {
  5243. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5244. if (presort_flag == true) {
  5245. presort_flag = false;
  5246. card.presort();
  5247. }
  5248. if (lcd_draw_update == 0 && LCD_CLICKED == 0)
  5249. //delay(100);
  5250. return; // nothing to do (so don't thrash the SD card)
  5251. uint16_t fileCnt = card.getnrfilenames();
  5252. MENU_BEGIN();
  5253. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5254. card.getWorkDirName();
  5255. if (card.filename[0] == '/')
  5256. {
  5257. #if SDCARDDETECT == -1
  5258. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5259. #endif
  5260. } else {
  5261. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5262. }
  5263. for (uint16_t i = 0; i < fileCnt; i++)
  5264. {
  5265. if (menu_item == menu_line)
  5266. {
  5267. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  5268. /*#ifdef SDCARD_RATHERRECENTFIRST
  5269. #ifndef SDCARD_SORT_ALPHA
  5270. fileCnt - 1 -
  5271. #endif
  5272. #endif
  5273. i;*/
  5274. #ifdef SDCARD_SORT_ALPHA
  5275. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  5276. else card.getfilename_sorted(nr);
  5277. #else
  5278. card.getfilename(nr);
  5279. #endif
  5280. if (card.filenameIsDir)
  5281. MENU_ITEM_SDDIR(card.filename, card.longFilename);
  5282. else
  5283. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  5284. } else {
  5285. MENU_ITEM_DUMMY();
  5286. }
  5287. }
  5288. MENU_END();
  5289. }
  5290. static void lcd_selftest_v()
  5291. {
  5292. (void)lcd_selftest();
  5293. }
  5294. bool lcd_selftest()
  5295. {
  5296. int _progress = 0;
  5297. bool _result = true;
  5298. lcd_wait_for_cool_down();
  5299. lcd_clear();
  5300. lcd_set_cursor(0, 0); lcd_puts_P(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0
  5301. #ifdef TMC2130
  5302. FORCE_HIGH_POWER_START;
  5303. #endif // TMC2130
  5304. delay(2000);
  5305. KEEPALIVE_STATE(IN_HANDLER);
  5306. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  5307. #if (defined(FANCHECK) && defined(TACH_0))
  5308. _result = lcd_selftest_fan_dialog(0);
  5309. #else //defined(TACH_0)
  5310. _result = lcd_selftest_manual_fan_check(0, false);
  5311. if (!_result)
  5312. {
  5313. const char *_err;
  5314. lcd_selftest_error(7, _err, _err); //extruder fan not spinning
  5315. }
  5316. #endif //defined(TACH_0)
  5317. if (_result)
  5318. {
  5319. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  5320. #if (defined(FANCHECK) && defined(TACH_1))
  5321. _result = lcd_selftest_fan_dialog(1);
  5322. #else //defined(TACH_1)
  5323. _result = lcd_selftest_manual_fan_check(1, false);
  5324. if (!_result)
  5325. {
  5326. const char *_err;
  5327. lcd_selftest_error(6, _err, _err); //print fan not spinning
  5328. }
  5329. #endif //defined(TACH_1)
  5330. }
  5331. if (_result)
  5332. {
  5333. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  5334. #ifndef TMC2130
  5335. _result = lcd_selfcheck_endstops();
  5336. #else
  5337. _result = true;
  5338. #endif
  5339. }
  5340. if (_result)
  5341. {
  5342. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  5343. _result = lcd_selfcheck_check_heater(false);
  5344. }
  5345. if (_result)
  5346. {
  5347. //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
  5348. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  5349. #ifdef TMC2130
  5350. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5351. #else
  5352. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5353. #endif //TMC2130
  5354. }
  5355. if (_result)
  5356. {
  5357. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  5358. #ifndef TMC2130
  5359. _result = lcd_selfcheck_pulleys(X_AXIS);
  5360. #endif
  5361. }
  5362. if (_result)
  5363. {
  5364. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  5365. #ifdef TMC2130
  5366. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5367. #else
  5368. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5369. #endif // TMC2130
  5370. }
  5371. if (_result)
  5372. {
  5373. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  5374. #ifndef TMC2130
  5375. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5376. #endif // TMC2130
  5377. }
  5378. if (_result)
  5379. {
  5380. #ifdef TMC2130
  5381. tmc2130_home_exit();
  5382. enable_endstops(false);
  5383. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  5384. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  5385. #endif
  5386. //homeaxis(X_AXIS);
  5387. //homeaxis(Y_AXIS);
  5388. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5389. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5390. st_synchronize();
  5391. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  5392. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  5393. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  5394. enquecommand_P(PSTR("G28 W"));
  5395. enquecommand_P(PSTR("G1 Z15 F1000"));
  5396. }
  5397. }
  5398. #ifdef TMC2130
  5399. if (_result)
  5400. {
  5401. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5402. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5403. st_synchronize();
  5404. _progress = lcd_selftest_screen(13, 0, 2, true, 0);
  5405. bool bres = tmc2130_home_calibrate(X_AXIS);
  5406. _progress = lcd_selftest_screen(13, 1, 2, true, 0);
  5407. bres &= tmc2130_home_calibrate(Y_AXIS);
  5408. _progress = lcd_selftest_screen(13, 2, 2, true, 0);
  5409. if (bres)
  5410. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5411. _result = bres;
  5412. }
  5413. #endif //TMC2130
  5414. if (_result)
  5415. {
  5416. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  5417. _result = lcd_selfcheck_check_heater(true);
  5418. }
  5419. if (_result)
  5420. {
  5421. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5422. #ifdef FILAMENT_SENSOR
  5423. if (mmu_enabled == false) {
  5424. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5425. _result = lcd_selftest_fsensor();
  5426. }
  5427. #endif // FILAMENT_SENSOR
  5428. }
  5429. if (_result)
  5430. {
  5431. #ifdef FILAMENT_SENSOR
  5432. if (mmu_enabled == false)
  5433. {
  5434. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5435. }
  5436. #endif // FILAMENT_SENSOR
  5437. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5438. }
  5439. else
  5440. {
  5441. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5442. }
  5443. lcd_reset_alert_level();
  5444. enquecommand_P(PSTR("M84"));
  5445. lcd_update_enable(true);
  5446. if (_result)
  5447. {
  5448. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=0 r=0
  5449. }
  5450. else
  5451. {
  5452. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5453. }
  5454. #ifdef TMC2130
  5455. FORCE_HIGH_POWER_END;
  5456. #endif // TMC2130
  5457. KEEPALIVE_STATE(NOT_BUSY);
  5458. return(_result);
  5459. }
  5460. #ifdef TMC2130
  5461. static void reset_crash_det(unsigned char axis) {
  5462. current_position[axis] += 10;
  5463. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5464. st_synchronize();
  5465. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5466. }
  5467. static bool lcd_selfcheck_axis_sg(unsigned char axis) {
  5468. // each axis length is measured twice
  5469. float axis_length, current_position_init, current_position_final;
  5470. float measured_axis_length[2];
  5471. float margin = 60;
  5472. float max_error_mm = 5;
  5473. switch (axis) {
  5474. case 0: axis_length = X_MAX_POS; break;
  5475. case 1: axis_length = Y_MAX_POS + 8; break;
  5476. default: axis_length = 210; break;
  5477. }
  5478. tmc2130_sg_stop_on_crash = false;
  5479. tmc2130_home_exit();
  5480. enable_endstops(true);
  5481. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5482. current_position[Z_AXIS] += 17;
  5483. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5484. tmc2130_home_enter(Z_AXIS_MASK);
  5485. st_synchronize();
  5486. tmc2130_home_exit();
  5487. }
  5488. // first axis length measurement begin
  5489. current_position[axis] -= (axis_length + margin);
  5490. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5491. st_synchronize();
  5492. tmc2130_sg_meassure_start(axis);
  5493. current_position_init = st_get_position_mm(axis);
  5494. current_position[axis] += 2 * margin;
  5495. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5496. st_synchronize();
  5497. current_position[axis] += axis_length;
  5498. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5499. st_synchronize();
  5500. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5501. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5502. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5503. current_position_final = st_get_position_mm(axis);
  5504. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5505. // first measurement end and second measurement begin
  5506. current_position[axis] -= margin;
  5507. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5508. st_synchronize();
  5509. current_position[axis] -= (axis_length + margin);
  5510. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5511. st_synchronize();
  5512. current_position_init = st_get_position_mm(axis);
  5513. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5514. //end of second measurement, now check for possible errors:
  5515. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5516. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5517. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5518. enable_endstops(false);
  5519. const char *_error_1;
  5520. if (axis == X_AXIS) _error_1 = "X";
  5521. if (axis == Y_AXIS) _error_1 = "Y";
  5522. if (axis == Z_AXIS) _error_1 = "Z";
  5523. lcd_selftest_error(9, _error_1, NULL);
  5524. current_position[axis] = 0;
  5525. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5526. reset_crash_det(axis);
  5527. return false;
  5528. }
  5529. }
  5530. printf_P(_N("Axis length difference:%.3f\n"), abs(measured_axis_length[0] - measured_axis_length[1]));
  5531. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5532. //loose pulleys
  5533. const char *_error_1;
  5534. if (axis == X_AXIS) _error_1 = "X";
  5535. if (axis == Y_AXIS) _error_1 = "Y";
  5536. if (axis == Z_AXIS) _error_1 = "Z";
  5537. lcd_selftest_error(8, _error_1, NULL);
  5538. current_position[axis] = 0;
  5539. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5540. reset_crash_det(axis);
  5541. return false;
  5542. }
  5543. current_position[axis] = 0;
  5544. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5545. reset_crash_det(axis);
  5546. return true;
  5547. }
  5548. #endif //TMC2130
  5549. //#ifndef TMC2130
  5550. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5551. {
  5552. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5553. bool _stepdone = false;
  5554. bool _stepresult = false;
  5555. int _progress = 0;
  5556. int _travel_done = 0;
  5557. int _err_endstop = 0;
  5558. int _lcd_refresh = 0;
  5559. _travel = _travel + (_travel / 10);
  5560. if (_axis == X_AXIS) {
  5561. current_position[Z_AXIS] += 17;
  5562. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5563. }
  5564. do {
  5565. current_position[_axis] = current_position[_axis] - 1;
  5566. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5567. st_synchronize();
  5568. #ifdef TMC2130
  5569. if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5570. #else //TMC2130
  5571. if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
  5572. (READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
  5573. (READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
  5574. #endif //TMC2130
  5575. {
  5576. if (_axis == 0)
  5577. {
  5578. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5579. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5580. }
  5581. if (_axis == 1)
  5582. {
  5583. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5584. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5585. }
  5586. if (_axis == 2)
  5587. {
  5588. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5589. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5590. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5591. /*disable_x();
  5592. disable_y();
  5593. disable_z();*/
  5594. }
  5595. _stepdone = true;
  5596. }
  5597. if (_lcd_refresh < 6)
  5598. {
  5599. _lcd_refresh++;
  5600. }
  5601. else
  5602. {
  5603. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  5604. _lcd_refresh = 0;
  5605. }
  5606. manage_heater();
  5607. manage_inactivity(true);
  5608. //delay(100);
  5609. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5610. } while (!_stepdone);
  5611. //current_position[_axis] = current_position[_axis] + 15;
  5612. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5613. if (!_stepresult)
  5614. {
  5615. const char *_error_1;
  5616. const char *_error_2;
  5617. if (_axis == X_AXIS) _error_1 = "X";
  5618. if (_axis == Y_AXIS) _error_1 = "Y";
  5619. if (_axis == Z_AXIS) _error_1 = "Z";
  5620. if (_err_endstop == 0) _error_2 = "X";
  5621. if (_err_endstop == 1) _error_2 = "Y";
  5622. if (_err_endstop == 2) _error_2 = "Z";
  5623. if (_travel_done >= _travel)
  5624. {
  5625. lcd_selftest_error(5, _error_1, _error_2);
  5626. }
  5627. else
  5628. {
  5629. lcd_selftest_error(4, _error_1, _error_2);
  5630. }
  5631. }
  5632. return _stepresult;
  5633. }
  5634. #ifndef TMC2130
  5635. static bool lcd_selfcheck_pulleys(int axis)
  5636. {
  5637. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5638. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5639. float current_position_init;
  5640. float move;
  5641. bool endstop_triggered = false;
  5642. int i;
  5643. unsigned long timeout_counter;
  5644. refresh_cmd_timeout();
  5645. manage_inactivity(true);
  5646. if (axis == 0) move = 50; //X_AXIS
  5647. else move = 50; //Y_AXIS
  5648. current_position_init = current_position[axis];
  5649. current_position[axis] += 2;
  5650. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5651. for (i = 0; i < 5; i++) {
  5652. refresh_cmd_timeout();
  5653. current_position[axis] = current_position[axis] + move;
  5654. st_current_set(0, 850); //set motor current higher
  5655. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5656. st_synchronize();
  5657. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5658. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5659. current_position[axis] = current_position[axis] - move;
  5660. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5661. st_synchronize();
  5662. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5663. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5664. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5665. return(false);
  5666. }
  5667. }
  5668. timeout_counter = millis() + 2500;
  5669. endstop_triggered = false;
  5670. manage_inactivity(true);
  5671. while (!endstop_triggered) {
  5672. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5673. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5674. endstop_triggered = true;
  5675. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5676. current_position[axis] += (axis == X_AXIS) ? 13 : 9;
  5677. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5678. st_synchronize();
  5679. return(true);
  5680. }
  5681. else {
  5682. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5683. return(false);
  5684. }
  5685. }
  5686. else {
  5687. current_position[axis] -= 1;
  5688. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5689. st_synchronize();
  5690. if (millis() > timeout_counter) {
  5691. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5692. return(false);
  5693. }
  5694. }
  5695. }
  5696. return(true);
  5697. }
  5698. static bool lcd_selfcheck_endstops()
  5699. {
  5700. bool _result = true;
  5701. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5702. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5703. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5704. {
  5705. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5706. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5707. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5708. }
  5709. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[0] / 60, active_extruder);
  5710. delay(500);
  5711. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5712. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5713. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5714. {
  5715. _result = false;
  5716. char _error[4] = "";
  5717. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5718. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5719. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5720. lcd_selftest_error(3, _error, "");
  5721. }
  5722. manage_heater();
  5723. manage_inactivity(true);
  5724. return _result;
  5725. }
  5726. #endif //not defined TMC2130
  5727. static bool lcd_selfcheck_check_heater(bool _isbed)
  5728. {
  5729. int _counter = 0;
  5730. int _progress = 0;
  5731. bool _stepresult = false;
  5732. bool _docycle = true;
  5733. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5734. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5735. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5736. target_temperature[0] = (_isbed) ? 0 : 200;
  5737. target_temperature_bed = (_isbed) ? 100 : 0;
  5738. manage_heater();
  5739. manage_inactivity(true);
  5740. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5741. do {
  5742. _counter++;
  5743. _docycle = (_counter < _cycles) ? true : false;
  5744. manage_heater();
  5745. manage_inactivity(true);
  5746. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5747. /*if (_isbed) {
  5748. MYSERIAL.print("Bed temp:");
  5749. MYSERIAL.println(degBed());
  5750. }
  5751. else {
  5752. MYSERIAL.print("Hotend temp:");
  5753. MYSERIAL.println(degHotend(0));
  5754. }*/
  5755. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5756. } while (_docycle);
  5757. target_temperature[0] = 0;
  5758. target_temperature_bed = 0;
  5759. manage_heater();
  5760. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5761. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5762. /*
  5763. MYSERIAL.println("");
  5764. MYSERIAL.print("Checked result:");
  5765. MYSERIAL.println(_checked_result);
  5766. MYSERIAL.print("Opposite result:");
  5767. MYSERIAL.println(_opposite_result);
  5768. */
  5769. if (_opposite_result < ((_isbed) ? 10 : 3))
  5770. {
  5771. if (_checked_result >= ((_isbed) ? 3 : 10))
  5772. {
  5773. _stepresult = true;
  5774. }
  5775. else
  5776. {
  5777. lcd_selftest_error(1, "", "");
  5778. }
  5779. }
  5780. else
  5781. {
  5782. lcd_selftest_error(2, "", "");
  5783. }
  5784. manage_heater();
  5785. manage_inactivity(true);
  5786. KEEPALIVE_STATE(IN_HANDLER);
  5787. return _stepresult;
  5788. }
  5789. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5790. {
  5791. lcd_beeper_quick_feedback();
  5792. target_temperature[0] = 0;
  5793. target_temperature_bed = 0;
  5794. manage_heater();
  5795. manage_inactivity();
  5796. lcd_clear();
  5797. lcd_set_cursor(0, 0);
  5798. lcd_puts_P(_i("Selftest error !"));////MSG_SELFTEST_ERROR c=0 r=0
  5799. lcd_set_cursor(0, 1);
  5800. lcd_puts_P(_i("Please check :"));////MSG_SELFTEST_PLEASECHECK c=0 r=0
  5801. switch (_error_no)
  5802. {
  5803. case 1:
  5804. lcd_set_cursor(0, 2);
  5805. lcd_puts_P(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=0 r=0
  5806. lcd_set_cursor(0, 3);
  5807. lcd_puts_P(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=0 r=0
  5808. break;
  5809. case 2:
  5810. lcd_set_cursor(0, 2);
  5811. lcd_puts_P(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER c=0 r=0
  5812. lcd_set_cursor(0, 3);
  5813. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5814. break;
  5815. case 3:
  5816. lcd_set_cursor(0, 2);
  5817. lcd_puts_P(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=0 r=0
  5818. lcd_set_cursor(0, 3);
  5819. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5820. lcd_set_cursor(17, 3);
  5821. lcd_print(_error_1);
  5822. break;
  5823. case 4:
  5824. lcd_set_cursor(0, 2);
  5825. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5826. lcd_set_cursor(18, 2);
  5827. lcd_print(_error_1);
  5828. lcd_set_cursor(0, 3);
  5829. lcd_puts_P(_i("Endstop"));////MSG_SELFTEST_ENDSTOP c=0 r=0
  5830. lcd_set_cursor(18, 3);
  5831. lcd_print(_error_2);
  5832. break;
  5833. case 5:
  5834. lcd_set_cursor(0, 2);
  5835. lcd_puts_P(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1
  5836. lcd_set_cursor(0, 3);
  5837. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5838. lcd_set_cursor(18, 3);
  5839. lcd_print(_error_1);
  5840. break;
  5841. case 6:
  5842. lcd_set_cursor(0, 2);
  5843. lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5844. lcd_set_cursor(0, 3);
  5845. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5846. lcd_set_cursor(18, 3);
  5847. lcd_print(_error_1);
  5848. break;
  5849. case 7:
  5850. lcd_set_cursor(0, 2);
  5851. lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5852. lcd_set_cursor(0, 3);
  5853. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5854. lcd_set_cursor(18, 3);
  5855. lcd_print(_error_1);
  5856. break;
  5857. case 8:
  5858. lcd_set_cursor(0, 2);
  5859. lcd_puts_P(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1
  5860. lcd_set_cursor(0, 3);
  5861. lcd_puts_P(_T(MSG_SELFTEST_MOTOR));
  5862. lcd_set_cursor(18, 3);
  5863. lcd_print(_error_1);
  5864. break;
  5865. case 9:
  5866. lcd_set_cursor(0, 2);
  5867. lcd_puts_P(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=0 r=0
  5868. lcd_set_cursor(0, 3);
  5869. lcd_puts_P(_i("Axis"));////MSG_SELFTEST_AXIS c=0 r=0
  5870. lcd_set_cursor(18, 3);
  5871. lcd_print(_error_1);
  5872. break;
  5873. case 10:
  5874. lcd_set_cursor(0, 2);
  5875. lcd_puts_P(_i("Front/left fans"));////MSG_SELFTEST_FANS c=0 r=0
  5876. lcd_set_cursor(0, 3);
  5877. lcd_puts_P(_i("Swapped"));////MSG_SELFTEST_SWAPPED c=0 r=0
  5878. lcd_set_cursor(18, 3);
  5879. lcd_print(_error_1);
  5880. break;
  5881. case 11:
  5882. lcd_set_cursor(0, 2);
  5883. lcd_puts_P(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0
  5884. lcd_set_cursor(0, 3);
  5885. lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR));
  5886. break;
  5887. }
  5888. delay(1000);
  5889. lcd_beeper_quick_feedback();
  5890. do {
  5891. delay(100);
  5892. manage_heater();
  5893. manage_inactivity();
  5894. } while (!lcd_clicked());
  5895. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5896. lcd_return_to_status();
  5897. }
  5898. #ifdef FILAMENT_SENSOR
  5899. static bool lcd_selftest_fsensor(void)
  5900. {
  5901. fsensor_init();
  5902. if (fsensor_not_responding)
  5903. {
  5904. lcd_selftest_error(11, NULL, NULL);
  5905. }
  5906. return (!fsensor_not_responding);
  5907. }
  5908. #endif //FILAMENT_SENSOR
  5909. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5910. {
  5911. bool _result = check_opposite;
  5912. lcd_clear();
  5913. lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_SELFTEST_FAN));
  5914. switch (_fan)
  5915. {
  5916. case 0:
  5917. // extruder cooling fan
  5918. lcd_set_cursor(0, 1);
  5919. if(check_opposite == true) lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5920. else lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5921. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5922. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5923. break;
  5924. case 1:
  5925. // object cooling fan
  5926. lcd_set_cursor(0, 1);
  5927. if (check_opposite == true) lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5928. else lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN));
  5929. SET_OUTPUT(FAN_PIN);
  5930. analogWrite(FAN_PIN, 255);
  5931. break;
  5932. }
  5933. delay(500);
  5934. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5935. lcd_set_cursor(0, 3); lcd_print(">");
  5936. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5937. int8_t enc_dif = 0;
  5938. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5939. lcd_button_pressed = false;
  5940. do
  5941. {
  5942. switch (_fan)
  5943. {
  5944. case 0:
  5945. // extruder cooling fan
  5946. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5947. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5948. break;
  5949. case 1:
  5950. // object cooling fan
  5951. SET_OUTPUT(FAN_PIN);
  5952. analogWrite(FAN_PIN, 255);
  5953. break;
  5954. }
  5955. if (abs((enc_dif - lcd_encoder_diff)) > 2) {
  5956. if (enc_dif > lcd_encoder_diff) {
  5957. _result = !check_opposite;
  5958. lcd_set_cursor(0, 2); lcd_print(">");
  5959. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5960. lcd_set_cursor(0, 3); lcd_print(" ");
  5961. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5962. }
  5963. if (enc_dif < lcd_encoder_diff) {
  5964. _result = check_opposite;
  5965. lcd_set_cursor(0, 2); lcd_print(" ");
  5966. lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
  5967. lcd_set_cursor(0, 3); lcd_print(">");
  5968. lcd_set_cursor(1, 3); lcd_puts_P(_T(MSG_SELFTEST_FAN_NO));
  5969. }
  5970. enc_dif = 0;
  5971. lcd_encoder_diff = 0;
  5972. }
  5973. manage_heater();
  5974. delay(100);
  5975. } while (!lcd_clicked());
  5976. KEEPALIVE_STATE(IN_HANDLER);
  5977. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5978. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5979. SET_OUTPUT(FAN_PIN);
  5980. analogWrite(FAN_PIN, 0);
  5981. fanSpeed = 0;
  5982. manage_heater();
  5983. return _result;
  5984. }
  5985. static bool lcd_selftest_fan_dialog(int _fan)
  5986. {
  5987. bool _result = true;
  5988. int _errno = 7;
  5989. switch (_fan) {
  5990. case 0:
  5991. fanSpeed = 0;
  5992. manage_heater(); //turn off fan
  5993. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5994. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5995. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5996. if (!fan_speed[0]) _result = false;
  5997. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5998. //MYSERIAL.println(fan_speed[0]);
  5999. //SERIAL_ECHOPGM("Print fan speed: ");
  6000. //MYSERIAL.print(fan_speed[1]);
  6001. break;
  6002. case 1:
  6003. //will it work with Thotend > 50 C ?
  6004. fanSpeed = 150; //print fan
  6005. for (uint8_t i = 0; i < 5; i++) {
  6006. delay_keep_alive(1000);
  6007. lcd_set_cursor(18, 3);
  6008. lcd_print("-");
  6009. delay_keep_alive(1000);
  6010. lcd_set_cursor(18, 3);
  6011. lcd_print("|");
  6012. }
  6013. fanSpeed = 0;
  6014. manage_heater(); //turn off fan
  6015. manage_inactivity(true); //to turn off print fan
  6016. if (!fan_speed[1]) {
  6017. _result = false; _errno = 6; //print fan not spinning
  6018. }
  6019. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  6020. //check fans manually
  6021. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  6022. if (_result) {
  6023. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  6024. if (!_result) _errno = 6; //print fan not spinning
  6025. }
  6026. else {
  6027. _errno = 10; //swapped fans
  6028. }
  6029. }
  6030. //SERIAL_ECHOPGM("Extruder fan speed: ");
  6031. //MYSERIAL.println(fan_speed[0]);
  6032. //SERIAL_ECHOPGM("Print fan speed: ");
  6033. //MYSERIAL.println(fan_speed[1]);
  6034. break;
  6035. }
  6036. if (!_result)
  6037. {
  6038. lcd_selftest_error(_errno, NULL, NULL);
  6039. }
  6040. return _result;
  6041. }
  6042. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  6043. {
  6044. lcd_update_enable(false);
  6045. int _step_block = 0;
  6046. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  6047. if (_clear) lcd_clear();
  6048. lcd_set_cursor(0, 0);
  6049. if (_step == -1) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6050. if (_step == 0) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6051. if (_step == 1) lcd_puts_P(_T(MSG_SELFTEST_FAN));
  6052. if (_step == 2) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0
  6053. if (_step == 3) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0
  6054. if (_step == 4) lcd_puts_P(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0
  6055. if (_step == 5) lcd_puts_P(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0
  6056. if (_step == 6) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0
  6057. if (_step == 7) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  6058. if (_step == 8) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED));
  6059. if (_step == 9) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6060. if (_step == 10) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6061. if (_step == 11) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0
  6062. if (_step == 12) lcd_puts_P(_T(MSG_SELFTEST_FAILED));
  6063. if (_step == 13) lcd_puts_P(PSTR("Calibrating home"));
  6064. lcd_set_cursor(0, 1);
  6065. lcd_puts_P(separator);
  6066. if ((_step >= -1) && (_step <= 1))
  6067. {
  6068. //SERIAL_ECHOLNPGM("Fan test");
  6069. lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 r=0
  6070. lcd_set_cursor(18, 2);
  6071. (_step < 0) ? lcd_print(_indicator) : lcd_print("OK");
  6072. lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 r=0
  6073. lcd_set_cursor(18, 3);
  6074. (_step < 1) ? lcd_print(_indicator) : lcd_print("OK");
  6075. }
  6076. else if (_step >= 9 && _step <= 10)
  6077. {
  6078. lcd_puts_at_P(0, 2, _i("Filament sensor:"));////MSG_SELFTEST_FILAMENT_SENSOR c=18 r=0
  6079. lcd_set_cursor(18, 2);
  6080. (_step == 9) ? lcd_print(_indicator) : lcd_print("OK");
  6081. }
  6082. else if (_step < 9)
  6083. {
  6084. //SERIAL_ECHOLNPGM("Other tests");
  6085. _step_block = 3;
  6086. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  6087. _step_block = 4;
  6088. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  6089. _step_block = 5;
  6090. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  6091. _step_block = 6;
  6092. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  6093. _step_block = 7;
  6094. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  6095. }
  6096. if (_delay > 0) delay_keep_alive(_delay);
  6097. _progress++;
  6098. return (_progress > _progress_scale * 2) ? 0 : _progress;
  6099. }
  6100. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  6101. {
  6102. lcd_set_cursor(_col, _row);
  6103. switch (_state)
  6104. {
  6105. case 1:
  6106. lcd_print(_name);
  6107. lcd_set_cursor(_col + strlen(_name), _row);
  6108. lcd_print(":");
  6109. lcd_set_cursor(_col + strlen(_name) + 1, _row);
  6110. lcd_print(_indicator);
  6111. break;
  6112. case 2:
  6113. lcd_print(_name);
  6114. lcd_set_cursor(_col + strlen(_name), _row);
  6115. lcd_print(":");
  6116. lcd_set_cursor(_col + strlen(_name) + 1, _row);
  6117. lcd_print("OK");
  6118. break;
  6119. default:
  6120. lcd_print(_name);
  6121. }
  6122. }
  6123. /** End of menus **/
  6124. /** Menu action functions **/
  6125. static bool check_file(const char* filename) {
  6126. if (farm_mode) return true;
  6127. bool result = false;
  6128. uint32_t filesize;
  6129. card.openFile((char*)filename, true);
  6130. filesize = card.getFileSize();
  6131. if (filesize > END_FILE_SECTION) {
  6132. card.setIndex(filesize - END_FILE_SECTION);
  6133. }
  6134. while (!card.eof() && !result) {
  6135. card.sdprinting = true;
  6136. get_command();
  6137. result = check_commands();
  6138. }
  6139. card.printingHasFinished();
  6140. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  6141. lcd_finishstatus();
  6142. return result;
  6143. }
  6144. static void menu_action_sdfile(const char* filename)
  6145. {
  6146. loading_flag = false;
  6147. char cmd[30];
  6148. char* c;
  6149. bool result = true;
  6150. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6151. for (c = &cmd[4]; *c; c++)
  6152. *c = tolower(*c);
  6153. const char end[5] = ".gco";
  6154. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6155. for (int i = 0; i < 8; i++) {
  6156. if (strcmp((cmd + i + 4), end) == 0) {
  6157. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6158. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6159. break;
  6160. }
  6161. else {
  6162. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6163. }
  6164. }
  6165. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6166. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6167. for (uint8_t i = 0; i < depth; i++) {
  6168. for (int j = 0; j < 8; j++) {
  6169. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  6170. }
  6171. }
  6172. if (!check_file(filename)) {
  6173. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=2
  6174. lcd_update_enable(true);
  6175. }
  6176. if (result) {
  6177. enquecommand(cmd);
  6178. enquecommand_P(PSTR("M24"));
  6179. }
  6180. lcd_return_to_status();
  6181. }
  6182. void menu_action_sddirectory(const char* filename)
  6183. {
  6184. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6185. strcpy(dir_names[depth], filename);
  6186. MYSERIAL.println(dir_names[depth]);
  6187. card.chdir(filename);
  6188. lcd_encoder = 0;
  6189. }
  6190. /** LCD API **/
  6191. void ultralcd_init()
  6192. {
  6193. {
  6194. uint8_t autoDepleteRaw = eeprom_read_byte(reinterpret_cast<uint8_t*>(EEPROM_AUTO_DEPLETE));
  6195. if (0xff == autoDepleteRaw) lcd_autoDeplete = false;
  6196. else lcd_autoDeplete = autoDepleteRaw;
  6197. }
  6198. lcd_init();
  6199. lcd_refresh();
  6200. lcd_longpress_func = menu_lcd_longpress_func;
  6201. lcd_charsetup_func = menu_lcd_charsetup_func;
  6202. lcd_lcdupdate_func = menu_lcd_lcdupdate_func;
  6203. menu_menu = lcd_status_screen;
  6204. menu_lcd_charsetup_func();
  6205. SET_INPUT(BTN_EN1);
  6206. SET_INPUT(BTN_EN2);
  6207. WRITE(BTN_EN1, HIGH);
  6208. WRITE(BTN_EN2, HIGH);
  6209. #if BTN_ENC > 0
  6210. SET_INPUT(BTN_ENC);
  6211. WRITE(BTN_ENC, HIGH);
  6212. #endif
  6213. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6214. pinMode(SDCARDDETECT, INPUT);
  6215. WRITE(SDCARDDETECT, HIGH);
  6216. lcd_oldcardstatus = IS_SD_INSERTED;
  6217. #endif//(SDCARDDETECT > 0)
  6218. lcd_buttons_update();
  6219. lcd_encoder_diff = 0;
  6220. }
  6221. void lcd_printer_connected() {
  6222. printer_connected = true;
  6223. }
  6224. static void lcd_send_status() {
  6225. if (farm_mode && no_response && ((millis() - NcTime) > (NC_TIME * 1000))) {
  6226. //send important status messages periodicaly
  6227. prusa_statistics(important_status, saved_filament_type);
  6228. NcTime = millis();
  6229. #ifdef FARM_CONNECT_MESSAGE
  6230. lcd_connect_printer();
  6231. #endif //FARM_CONNECT_MESSAGE
  6232. }
  6233. }
  6234. #ifdef FARM_CONNECT_MESSAGE
  6235. static void lcd_connect_printer() {
  6236. lcd_update_enable(false);
  6237. lcd_clear();
  6238. int i = 0;
  6239. int t = 0;
  6240. lcd_set_custom_characters_progress();
  6241. lcd_puts_at_P(0, 0, _i("Connect printer to"));
  6242. lcd_puts_at_P(0, 1, _i("monitoring or hold"));
  6243. lcd_puts_at_P(0, 2, _i("the knob to continue"));
  6244. while (no_response) {
  6245. i++;
  6246. t++;
  6247. delay_keep_alive(100);
  6248. proc_commands();
  6249. if (t == 10) {
  6250. prusa_statistics(important_status, saved_filament_type);
  6251. t = 0;
  6252. }
  6253. if (READ(BTN_ENC)) { //if button is not pressed
  6254. i = 0;
  6255. lcd_puts_at_P(0, 3, PSTR(" "));
  6256. }
  6257. if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
  6258. if (i == NC_BUTTON_LONG_PRESS * 10) {
  6259. no_response = false;
  6260. }
  6261. }
  6262. lcd_set_custom_characters_degree();
  6263. lcd_update_enable(true);
  6264. lcd_update(2);
  6265. }
  6266. #endif //FARM_CONNECT_MESSAGE
  6267. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6268. if (farm_mode) {
  6269. bool empty = is_buffer_empty();
  6270. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6271. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6272. //therefore longer period is used
  6273. printer_connected = false;
  6274. }
  6275. else {
  6276. lcd_printer_connected();
  6277. }
  6278. }
  6279. }
  6280. void lcd_ignore_click(bool b)
  6281. {
  6282. ignore_click = b;
  6283. wait_for_unclick = false;
  6284. }
  6285. void lcd_finishstatus() {
  6286. int len = strlen(lcd_status_message);
  6287. if (len > 0) {
  6288. while (len < LCD_WIDTH) {
  6289. lcd_status_message[len++] = ' ';
  6290. }
  6291. }
  6292. lcd_status_message[LCD_WIDTH] = '\0';
  6293. lcd_draw_update = 2;
  6294. }
  6295. void lcd_setstatus(const char* message)
  6296. {
  6297. if (lcd_status_message_level > 0)
  6298. return;
  6299. strncpy(lcd_status_message, message, LCD_WIDTH);
  6300. lcd_finishstatus();
  6301. }
  6302. void lcd_setstatuspgm(const char* message)
  6303. {
  6304. if (lcd_status_message_level > 0)
  6305. return;
  6306. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6307. lcd_status_message[LCD_WIDTH] = 0;
  6308. lcd_finishstatus();
  6309. }
  6310. void lcd_setalertstatuspgm(const char* message)
  6311. {
  6312. lcd_setstatuspgm(message);
  6313. lcd_status_message_level = 1;
  6314. lcd_return_to_status();
  6315. }
  6316. void lcd_reset_alert_level()
  6317. {
  6318. lcd_status_message_level = 0;
  6319. }
  6320. uint8_t get_message_level()
  6321. {
  6322. return lcd_status_message_level;
  6323. }
  6324. void menu_lcd_longpress_func(void)
  6325. {
  6326. move_menu_scale = 1.0;
  6327. menu_submenu(lcd_move_z);
  6328. }
  6329. void menu_lcd_charsetup_func(void)
  6330. {
  6331. if (menu_menu == lcd_status_screen)
  6332. lcd_set_custom_characters_degree();
  6333. else
  6334. lcd_set_custom_characters_arrows();
  6335. }
  6336. static inline bool z_menu_expired()
  6337. {
  6338. return (menu_menu == lcd_babystep_z
  6339. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS_BABYSTEP_Z));
  6340. }
  6341. static inline bool other_menu_expired()
  6342. {
  6343. return (menu_menu != lcd_status_screen
  6344. && menu_menu != lcd_babystep_z
  6345. && lcd_timeoutToStatus.expired(LCD_TIMEOUT_TO_STATUS));
  6346. }
  6347. static inline bool forced_menu_expire()
  6348. {
  6349. bool retval = (menu_menu != lcd_status_screen
  6350. && forceMenuExpire);
  6351. forceMenuExpire = false;
  6352. return retval;
  6353. }
  6354. void menu_lcd_lcdupdate_func(void)
  6355. {
  6356. #if (SDCARDDETECT > 0)
  6357. if ((IS_SD_INSERTED != lcd_oldcardstatus))
  6358. {
  6359. lcd_draw_update = 2;
  6360. lcd_oldcardstatus = IS_SD_INSERTED;
  6361. lcd_refresh(); // to maybe revive the LCD if static electricity killed it.
  6362. if (lcd_oldcardstatus)
  6363. {
  6364. card.initsd();
  6365. LCD_MESSAGERPGM(_i("Card inserted"));////MSG_SD_INSERTED c=0 r=0
  6366. //get_description();
  6367. }
  6368. else
  6369. {
  6370. card.release();
  6371. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=0 r=0
  6372. }
  6373. }
  6374. #endif//CARDINSERTED
  6375. if (lcd_next_update_millis < millis())
  6376. {
  6377. if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP)
  6378. {
  6379. if (lcd_draw_update == 0)
  6380. lcd_draw_update = 1;
  6381. lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
  6382. lcd_encoder_diff = 0;
  6383. lcd_timeoutToStatus.start();
  6384. }
  6385. if (LCD_CLICKED) lcd_timeoutToStatus.start();
  6386. (*menu_menu)();
  6387. if (z_menu_expired() || other_menu_expired() || forced_menu_expire())
  6388. {
  6389. // Exiting a menu. Let's call the menu function the last time with menu_leaving flag set to true
  6390. // to give it a chance to save its state.
  6391. // This is useful for example, when the babystep value has to be written into EEPROM.
  6392. if (menu_menu != NULL)
  6393. {
  6394. menu_leaving = 1;
  6395. (*menu_menu)();
  6396. menu_leaving = 0;
  6397. }
  6398. lcd_clear();
  6399. lcd_return_to_status();
  6400. lcd_draw_update = 2;
  6401. }
  6402. if (lcd_draw_update == 2) lcd_clear();
  6403. if (lcd_draw_update) lcd_draw_update--;
  6404. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  6405. }
  6406. if (!SdFatUtil::test_stack_integrity()) stack_error();
  6407. lcd_ping(); //check that we have received ping command if we are in farm mode
  6408. lcd_send_status();
  6409. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6410. }