ultralcd.cpp 241 KB

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