ultralcd.cpp 245 KB

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