ultralcd.cpp 201 KB

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