ultralcd.cpp 212 KB

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