ultralcd.cpp 202 KB

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