ultralcd.cpp 201 KB

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