ultralcd.cpp 199 KB

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