ultralcd.cpp 268 KB

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