ultralcd.cpp 210 KB

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