ultralcd.cpp 198 KB

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