ultralcd.cpp 204 KB

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