ultralcd.cpp 210 KB

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