ultralcd.cpp 204 KB

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