ultralcd.cpp 211 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714
  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, uint8_t* ptr, uint8_t minValue, uint8_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. if (selectedSerialPort == 0) {
  3350. MENU_ITEM(function, MSG_SECOND_SERIAL_OFF, lcd_second_serial_set);
  3351. }
  3352. else {
  3353. MENU_ITEM(function, MSG_SECOND_SERIAL_ON, lcd_second_serial_set);
  3354. }
  3355. if (!isPrintPaused && !homing_flag)
  3356. {
  3357. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  3358. }
  3359. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  3360. if (card.ToshibaFlashAir_isEnabled()) {
  3361. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  3362. } else {
  3363. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  3364. }
  3365. #ifdef SDCARD_SORT_ALPHA
  3366. if (!farm_mode) {
  3367. uint8_t sdSort;
  3368. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3369. switch (sdSort) {
  3370. case SD_SORT_TIME: MENU_ITEM(function, MSG_SORT_TIME, lcd_sort_type_set); break;
  3371. case SD_SORT_ALPHA: MENU_ITEM(function, MSG_SORT_ALPHA, lcd_sort_type_set); break;
  3372. default: MENU_ITEM(function, MSG_SORT_NONE, lcd_sort_type_set);
  3373. }
  3374. }
  3375. #endif // SDCARD_SORT_ALPHA
  3376. if (farm_mode)
  3377. {
  3378. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  3379. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  3380. }
  3381. END_MENU();
  3382. }
  3383. static void lcd_selftest_()
  3384. {
  3385. lcd_selftest();
  3386. }
  3387. #ifdef EXPERIMENTAL_FEATURES
  3388. static void lcd_experimantal_menu();
  3389. static void lcd_homing_accuracy_menu();
  3390. static void lcd_accurate_home_set()
  3391. {
  3392. tmc2130_home_enabled = tmc2130_home_enabled?0:1;
  3393. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  3394. }
  3395. static void lcd_homing_accuracy_menu_advanced_reset()
  3396. {
  3397. tmc2130_home_bsteps[X_AXIS] = 48;
  3398. tmc2130_home_fsteps[X_AXIS] = 48;
  3399. tmc2130_home_bsteps[Y_AXIS] = 48;
  3400. tmc2130_home_fsteps[Y_AXIS] = 48;
  3401. }
  3402. static void lcd_homing_accuracy_menu_advanced_save()
  3403. {
  3404. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_ORIGIN, tmc2130_home_origin[X_AXIS]);
  3405. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_BSTEPS, tmc2130_home_bsteps[X_AXIS]);
  3406. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_FSTEPS, tmc2130_home_fsteps[X_AXIS]);
  3407. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_ORIGIN, tmc2130_home_origin[Y_AXIS]);
  3408. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_BSTEPS, tmc2130_home_bsteps[Y_AXIS]);
  3409. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_FSTEPS, tmc2130_home_fsteps[Y_AXIS]);
  3410. }
  3411. static void lcd_homing_accuracy_menu_advanced_back()
  3412. {
  3413. lcd_homing_accuracy_menu_advanced_save();
  3414. currentMenu = lcd_homing_accuracy_menu;
  3415. lcd_homing_accuracy_menu();
  3416. }
  3417. static void lcd_homing_accuracy_menu_advanced()
  3418. {
  3419. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3420. START_MENU();
  3421. MENU_ITEM(back, PSTR("Homing accuracy"), lcd_homing_accuracy_menu_advanced_back);
  3422. MENU_ITEM(function, PSTR("Reset def. steps"), lcd_homing_accuracy_menu_advanced_reset);
  3423. MENU_ITEM_EDIT(byte3, PSTR("X-origin"), &tmc2130_home_origin[X_AXIS], 0, 63);
  3424. MENU_ITEM_EDIT(byte3, PSTR("Y-origin"), &tmc2130_home_origin[Y_AXIS], 0, 63);
  3425. MENU_ITEM_EDIT(byte3, PSTR("X-bsteps"), &tmc2130_home_bsteps[X_AXIS], 0, 128);
  3426. MENU_ITEM_EDIT(byte3, PSTR("Y-bsteps"), &tmc2130_home_bsteps[Y_AXIS], 0, 128);
  3427. MENU_ITEM_EDIT(byte3, PSTR("X-fsteps"), &tmc2130_home_fsteps[X_AXIS], 0, 128);
  3428. MENU_ITEM_EDIT(byte3, PSTR("Y-fsteps"), &tmc2130_home_fsteps[Y_AXIS], 0, 128);
  3429. END_MENU();
  3430. }
  3431. static void lcd_homing_accuracy_menu()
  3432. {
  3433. START_MENU();
  3434. MENU_ITEM(back, PSTR("Experimental"), lcd_experimantal_menu);
  3435. MENU_ITEM(function, tmc2130_home_enabled?PSTR("Accur. homing On"):PSTR("Accur. homing Off"), lcd_accurate_home_set);
  3436. MENU_ITEM(gcode, PSTR("Calibrate X"), PSTR("G28XC"));
  3437. MENU_ITEM(gcode, PSTR("Calibrate Y"), PSTR("G28YC"));
  3438. MENU_ITEM(submenu, PSTR("Advanced"), lcd_homing_accuracy_menu_advanced);
  3439. END_MENU();
  3440. }
  3441. static void lcd_ustep_resolution_menu_save()
  3442. {
  3443. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_X_MRES, tmc2130_mres[X_AXIS]);
  3444. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Y_MRES, tmc2130_mres[Y_AXIS]);
  3445. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Z_MRES, tmc2130_mres[Z_AXIS]);
  3446. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_E_MRES, tmc2130_mres[E_AXIS]);
  3447. }
  3448. static void lcd_ustep_resolution_menu_back()
  3449. {
  3450. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  3451. bool changed = false;
  3452. if (tmc2130_mres[X_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_X_MRES))
  3453. {
  3454. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS] * tmc2130_mres2usteps(tmc2130_mres[X_AXIS]) / TMC2130_USTEPS_XY;
  3455. changed = true;
  3456. }
  3457. if (tmc2130_mres[Y_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Y_MRES))
  3458. {
  3459. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Y_AXIS]) / TMC2130_USTEPS_XY;
  3460. changed = true;
  3461. }
  3462. if (tmc2130_mres[Z_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Z_MRES))
  3463. {
  3464. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Z_AXIS]) / TMC2130_USTEPS_Z;
  3465. changed = true;
  3466. }
  3467. if (tmc2130_mres[E_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_E_MRES))
  3468. {
  3469. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS] * tmc2130_mres2usteps(tmc2130_mres[E_AXIS]) / TMC2130_USTEPS_E;
  3470. changed = true;
  3471. }
  3472. if (changed)
  3473. {
  3474. lcd_ustep_resolution_menu_save();
  3475. Config_StoreSettings(EEPROM_OFFSET);
  3476. tmc2130_init();
  3477. }
  3478. currentMenu = lcd_experimantal_menu;
  3479. lcd_experimantal_menu();
  3480. }
  3481. static void lcd_ustep_resolution_reset_def_xyze()
  3482. {
  3483. tmc2130_mres[X_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  3484. tmc2130_mres[Y_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  3485. tmc2130_mres[Z_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_Z);
  3486. tmc2130_mres[E_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_E);
  3487. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  3488. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS];
  3489. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS];
  3490. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS];
  3491. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS];
  3492. }
  3493. static void lcd_ustep_resolution_menu()
  3494. {
  3495. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3496. START_MENU();
  3497. MENU_ITEM(back, PSTR("Experimental"), lcd_ustep_resolution_menu_back);
  3498. MENU_ITEM(function, PSTR("Reset defaults"), lcd_ustep_resolution_reset_def_xyze);
  3499. MENU_ITEM_EDIT(mres, PSTR("X-resolution"), &tmc2130_mres[X_AXIS], 4, 4);
  3500. MENU_ITEM_EDIT(mres, PSTR("Y-resolution"), &tmc2130_mres[Y_AXIS], 4, 4);
  3501. MENU_ITEM_EDIT(mres, PSTR("Z-resolution"), &tmc2130_mres[Z_AXIS], 4, 4);
  3502. MENU_ITEM_EDIT(mres, PSTR("E-resolution"), &tmc2130_mres[E_AXIS], 2, 5);
  3503. END_MENU();
  3504. }
  3505. static void lcd_ustep_linearity_menu_save()
  3506. {
  3507. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  3508. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  3509. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  3510. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  3511. }
  3512. static void lcd_ustep_linearity_menu_back()
  3513. {
  3514. bool changed = false;
  3515. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  3516. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  3517. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  3518. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC200_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  3519. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  3520. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  3521. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  3522. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  3523. lcd_ustep_linearity_menu_save();
  3524. if (changed) tmc2130_init();
  3525. currentMenu = lcd_experimantal_menu;
  3526. lcd_experimantal_menu();
  3527. }
  3528. static void lcd_ustep_linearity_menu_recomended()
  3529. {
  3530. tmc2130_wave_fac[X_AXIS] = 220;
  3531. tmc2130_wave_fac[Y_AXIS] = 220;
  3532. tmc2130_wave_fac[Z_AXIS] = 220;
  3533. tmc2130_wave_fac[E_AXIS] = 220;
  3534. }
  3535. static void lcd_ustep_linearity_menu_reset()
  3536. {
  3537. tmc2130_wave_fac[X_AXIS] = 0;
  3538. tmc2130_wave_fac[Y_AXIS] = 0;
  3539. tmc2130_wave_fac[Z_AXIS] = 0;
  3540. tmc2130_wave_fac[E_AXIS] = 0;
  3541. }
  3542. static void lcd_ustep_linearity_menu()
  3543. {
  3544. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3545. START_MENU();
  3546. MENU_ITEM(back, PSTR("Experimental"), lcd_ustep_linearity_menu_back);
  3547. MENU_ITEM(function, PSTR("Reset correction"), lcd_ustep_linearity_menu_reset);
  3548. MENU_ITEM(function, PSTR("Recomended config"), lcd_ustep_linearity_menu_recomended);
  3549. MENU_ITEM_EDIT(wfac, PSTR("X-correction"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
  3550. MENU_ITEM_EDIT(wfac, PSTR("Y-correction"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
  3551. MENU_ITEM_EDIT(wfac, PSTR("Z-correction"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
  3552. MENU_ITEM_EDIT(wfac, PSTR("E-correction"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC200_MIN-TMC2130_WAVE_FAC200_STP, TMC2130_WAVE_FAC200_MAX);
  3553. END_MENU();
  3554. }
  3555. static void lcd_experimantal_menu_save_all()
  3556. {
  3557. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  3558. lcd_ustep_resolution_menu_save();
  3559. lcd_ustep_linearity_menu_save();
  3560. Config_StoreSettings(EEPROM_OFFSET);
  3561. }
  3562. static void lcd_experimantal_menu_disable_all()
  3563. {
  3564. tmc2130_home_enabled = 0;
  3565. lcd_ustep_resolution_reset_def_xyze();
  3566. lcd_ustep_linearity_menu_reset();
  3567. lcd_experimantal_menu_save_all();
  3568. tmc2130_init();
  3569. }
  3570. static void lcd_experimantal_menu()
  3571. {
  3572. START_MENU();
  3573. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3574. MENU_ITEM(function, PSTR("All Xfeatures off"), lcd_experimantal_menu_disable_all);
  3575. MENU_ITEM(submenu, PSTR("Homing accuracy"), lcd_homing_accuracy_menu);
  3576. MENU_ITEM(submenu, PSTR("uStep resolution"), lcd_ustep_resolution_menu);
  3577. MENU_ITEM(submenu, PSTR("uStep linearity"), lcd_ustep_linearity_menu);
  3578. END_MENU();
  3579. }
  3580. #endif //EXPERIMENTAL_FEATURES
  3581. static void lcd_calibration_menu()
  3582. {
  3583. START_MENU();
  3584. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3585. if (!isPrintPaused)
  3586. {
  3587. MENU_ITEM(function, MSG_WIZARD, lcd_wizard);
  3588. MENU_ITEM(submenu, MSG_V2_CALIBRATION, lcd_v2_calibration);
  3589. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  3590. MENU_ITEM(function, MSG_SELFTEST, lcd_selftest_v);
  3591. #ifdef MK1BP
  3592. // MK1
  3593. // "Calibrate Z"
  3594. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  3595. #else //MK1BP
  3596. // MK2
  3597. MENU_ITEM(function, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  3598. // "Calibrate Z" with storing the reference values to EEPROM.
  3599. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  3600. #ifndef SNMM
  3601. //MENU_ITEM(function, MSG_CALIBRATE_E, lcd_calibrate_extruder);
  3602. #endif
  3603. // "Mesh Bed Leveling"
  3604. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  3605. #endif //MK1BP
  3606. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  3607. MENU_ITEM(submenu, MSG_PID_EXTRUDER, pid_extruder);
  3608. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  3609. #ifndef MK1BP
  3610. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  3611. #endif //MK1BP
  3612. #ifndef SNMM
  3613. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  3614. #endif
  3615. #ifndef MK1BP
  3616. MENU_ITEM(submenu, MSG_CALIBRATION_PINDA_MENU, lcd_pinda_calibration_menu);
  3617. #endif //MK1BP
  3618. }
  3619. END_MENU();
  3620. }
  3621. /*
  3622. void lcd_mylang_top(int hlaska) {
  3623. lcd.setCursor(0,0);
  3624. lcd.print(" ");
  3625. lcd.setCursor(0,0);
  3626. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  3627. }
  3628. void lcd_mylang_drawmenu(int cursor) {
  3629. int first = 0;
  3630. if (cursor>2) first = cursor-2;
  3631. if (cursor==LANG_NUM) first = LANG_NUM-3;
  3632. lcd.setCursor(0, 1);
  3633. lcd.print(" ");
  3634. lcd.setCursor(1, 1);
  3635. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  3636. lcd.setCursor(0, 2);
  3637. lcd.print(" ");
  3638. lcd.setCursor(1, 2);
  3639. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  3640. lcd.setCursor(0, 3);
  3641. lcd.print(" ");
  3642. lcd.setCursor(1, 3);
  3643. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  3644. if (cursor==1) lcd.setCursor(0, 1);
  3645. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  3646. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  3647. lcd.print(">");
  3648. if (cursor<LANG_NUM-1) {
  3649. lcd.setCursor(19,3);
  3650. lcd.print("\x01");
  3651. }
  3652. if (cursor>2) {
  3653. lcd.setCursor(19,1);
  3654. lcd.print("^");
  3655. }
  3656. }
  3657. */
  3658. void lcd_mylang_drawmenu(int cursor) {
  3659. int first = 0;
  3660. if (cursor>3) first = cursor-3;
  3661. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  3662. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  3663. lcd.setCursor(0, 0);
  3664. lcd.print(" ");
  3665. lcd.setCursor(1, 0);
  3666. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  3667. lcd.setCursor(0, 1);
  3668. lcd.print(" ");
  3669. lcd.setCursor(1, 1);
  3670. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  3671. lcd.setCursor(0, 2);
  3672. lcd.print(" ");
  3673. if (LANG_NUM > 2){
  3674. lcd.setCursor(1, 2);
  3675. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  3676. }
  3677. lcd.setCursor(0, 3);
  3678. lcd.print(" ");
  3679. if (LANG_NUM>3) {
  3680. lcd.setCursor(1, 3);
  3681. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  3682. }
  3683. if (cursor==1) lcd.setCursor(0, 0);
  3684. if (cursor==2) lcd.setCursor(0, 1);
  3685. if (cursor>2) lcd.setCursor(0, 2);
  3686. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  3687. lcd.print(">");
  3688. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  3689. lcd.setCursor(19,3);
  3690. lcd.print("\x01");
  3691. }
  3692. if (cursor>3 && LANG_NUM>4) {
  3693. lcd.setCursor(19,0);
  3694. lcd.print("^");
  3695. }
  3696. }
  3697. void lcd_mylang_drawcursor(int cursor) {
  3698. if (cursor==1) lcd.setCursor(0, 1);
  3699. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  3700. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  3701. lcd.print(">");
  3702. }
  3703. void lcd_mylang() {
  3704. int enc_dif = 0;
  3705. int cursor_pos = 1;
  3706. lang_selected=255;
  3707. int hlaska=1;
  3708. int counter=0;
  3709. lcd_set_custom_characters_arrows();
  3710. lcd_implementation_clear();
  3711. //lcd_mylang_top(hlaska);
  3712. lcd_mylang_drawmenu(cursor_pos);
  3713. enc_dif = encoderDiff;
  3714. while ( (lang_selected == 255) ) {
  3715. manage_heater();
  3716. manage_inactivity(true);
  3717. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  3718. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  3719. if (enc_dif > encoderDiff ) {
  3720. cursor_pos --;
  3721. }
  3722. if (enc_dif < encoderDiff ) {
  3723. cursor_pos ++;
  3724. }
  3725. if (cursor_pos > LANG_NUM) {
  3726. cursor_pos = LANG_NUM;
  3727. }
  3728. if (cursor_pos < 1) {
  3729. cursor_pos = 1;
  3730. }
  3731. lcd_mylang_drawmenu(cursor_pos);
  3732. enc_dif = encoderDiff;
  3733. delay(100);
  3734. //}
  3735. } else delay(20);
  3736. if (lcd_clicked()) {
  3737. lcd_set_lang(cursor_pos-1);
  3738. delay(500);
  3739. }
  3740. /*
  3741. if (++counter == 80) {
  3742. hlaska++;
  3743. if(hlaska>LANG_NUM) hlaska=1;
  3744. lcd_mylang_top(hlaska);
  3745. lcd_mylang_drawcursor(cursor_pos);
  3746. counter=0;
  3747. }
  3748. */
  3749. };
  3750. if(MYSERIAL.available() > 1){
  3751. lang_selected = 0;
  3752. firstrun = 0;
  3753. }
  3754. lcd_set_custom_characters_degree();
  3755. lcd_implementation_clear();
  3756. lcd_return_to_status();
  3757. }
  3758. void bowden_menu() {
  3759. int enc_dif = encoderDiff;
  3760. int cursor_pos = 0;
  3761. lcd_implementation_clear();
  3762. lcd.setCursor(0, 0);
  3763. lcd.print(">");
  3764. for (int i = 0; i < 4; i++) {
  3765. lcd.setCursor(1, i);
  3766. lcd.print("Extruder ");
  3767. lcd.print(i);
  3768. lcd.print(": ");
  3769. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3770. lcd.print(bowden_length[i] - 48);
  3771. }
  3772. enc_dif = encoderDiff;
  3773. while (1) {
  3774. manage_heater();
  3775. manage_inactivity(true);
  3776. if (abs((enc_dif - encoderDiff)) > 2) {
  3777. if (enc_dif > encoderDiff) {
  3778. cursor_pos--;
  3779. }
  3780. if (enc_dif < encoderDiff) {
  3781. cursor_pos++;
  3782. }
  3783. if (cursor_pos > 3) {
  3784. cursor_pos = 3;
  3785. }
  3786. if (cursor_pos < 0) {
  3787. cursor_pos = 0;
  3788. }
  3789. lcd.setCursor(0, 0);
  3790. lcd.print(" ");
  3791. lcd.setCursor(0, 1);
  3792. lcd.print(" ");
  3793. lcd.setCursor(0, 2);
  3794. lcd.print(" ");
  3795. lcd.setCursor(0, 3);
  3796. lcd.print(" ");
  3797. lcd.setCursor(0, cursor_pos);
  3798. lcd.print(">");
  3799. enc_dif = encoderDiff;
  3800. delay(100);
  3801. }
  3802. if (lcd_clicked()) {
  3803. while (lcd_clicked());
  3804. delay(10);
  3805. while (lcd_clicked());
  3806. lcd_implementation_clear();
  3807. while (1) {
  3808. manage_heater();
  3809. manage_inactivity(true);
  3810. lcd.setCursor(1, 1);
  3811. lcd.print("Extruder ");
  3812. lcd.print(cursor_pos);
  3813. lcd.print(": ");
  3814. lcd.setCursor(13, 1);
  3815. lcd.print(bowden_length[cursor_pos] - 48);
  3816. if (abs((enc_dif - encoderDiff)) > 2) {
  3817. if (enc_dif > encoderDiff) {
  3818. bowden_length[cursor_pos]--;
  3819. lcd.setCursor(13, 1);
  3820. lcd.print(bowden_length[cursor_pos] - 48);
  3821. enc_dif = encoderDiff;
  3822. }
  3823. if (enc_dif < encoderDiff) {
  3824. bowden_length[cursor_pos]++;
  3825. lcd.setCursor(13, 1);
  3826. lcd.print(bowden_length[cursor_pos] - 48);
  3827. enc_dif = encoderDiff;
  3828. }
  3829. }
  3830. delay(100);
  3831. if (lcd_clicked()) {
  3832. while (lcd_clicked());
  3833. delay(10);
  3834. while (lcd_clicked());
  3835. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  3836. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  3837. lcd_update_enable(true);
  3838. lcd_implementation_clear();
  3839. enc_dif = encoderDiff;
  3840. lcd.setCursor(0, cursor_pos);
  3841. lcd.print(">");
  3842. for (int i = 0; i < 4; i++) {
  3843. lcd.setCursor(1, i);
  3844. lcd.print("Extruder ");
  3845. lcd.print(i);
  3846. lcd.print(": ");
  3847. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3848. lcd.print(bowden_length[i] - 48);
  3849. }
  3850. break;
  3851. }
  3852. else return;
  3853. }
  3854. }
  3855. }
  3856. }
  3857. }
  3858. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  3859. lcd_implementation_clear();
  3860. lcd_print_at_PGM(0,0,MSG_UNLOAD_FILAMENT); lcd.print(":");
  3861. lcd.setCursor(0, 1); lcd.print(">");
  3862. lcd_print_at_PGM(1,1,MSG_ALL);
  3863. lcd_print_at_PGM(1,2,MSG_USED);
  3864. lcd_print_at_PGM(1,3,MSG_CURRENT);
  3865. char cursor_pos = 1;
  3866. int enc_dif = 0;
  3867. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3868. while (1) {
  3869. manage_heater();
  3870. manage_inactivity(true);
  3871. if (abs((enc_dif - encoderDiff)) > 4) {
  3872. if ((abs(enc_dif - encoderDiff)) > 1) {
  3873. if (enc_dif > encoderDiff) cursor_pos--;
  3874. if (enc_dif < encoderDiff) cursor_pos++;
  3875. if (cursor_pos > 3) cursor_pos = 3;
  3876. if (cursor_pos < 1) cursor_pos = 1;
  3877. lcd.setCursor(0, 1);
  3878. lcd.print(" ");
  3879. lcd.setCursor(0, 2);
  3880. lcd.print(" ");
  3881. lcd.setCursor(0, 3);
  3882. lcd.print(" ");
  3883. lcd.setCursor(0, cursor_pos);
  3884. lcd.print(">");
  3885. enc_dif = encoderDiff;
  3886. delay(100);
  3887. }
  3888. }
  3889. if (lcd_clicked()) {
  3890. while (lcd_clicked());
  3891. delay(10);
  3892. while (lcd_clicked());
  3893. KEEPALIVE_STATE(IN_HANDLER);
  3894. return(cursor_pos - 1);
  3895. }
  3896. }
  3897. }
  3898. char choose_extruder_menu() {
  3899. int items_no = 4;
  3900. int first = 0;
  3901. int enc_dif = 0;
  3902. char cursor_pos = 1;
  3903. enc_dif = encoderDiff;
  3904. lcd_implementation_clear();
  3905. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3906. lcd.setCursor(0, 1);
  3907. lcd.print(">");
  3908. for (int i = 0; i < 3; i++) {
  3909. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3910. }
  3911. KEEPALIVE_STATE(PAUSED_FOR_USER);
  3912. while (1) {
  3913. for (int i = 0; i < 3; i++) {
  3914. lcd.setCursor(2 + strlen_P(MSG_EXTRUDER), i+1);
  3915. lcd.print(first + i + 1);
  3916. }
  3917. manage_heater();
  3918. manage_inactivity(true);
  3919. if (abs((enc_dif - encoderDiff)) > 4) {
  3920. if ((abs(enc_dif - encoderDiff)) > 1) {
  3921. if (enc_dif > encoderDiff) {
  3922. cursor_pos--;
  3923. }
  3924. if (enc_dif < encoderDiff) {
  3925. cursor_pos++;
  3926. }
  3927. if (cursor_pos > 3) {
  3928. cursor_pos = 3;
  3929. if (first < items_no - 3) {
  3930. first++;
  3931. lcd_implementation_clear();
  3932. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3933. for (int i = 0; i < 3; i++) {
  3934. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3935. }
  3936. }
  3937. }
  3938. if (cursor_pos < 1) {
  3939. cursor_pos = 1;
  3940. if (first > 0) {
  3941. first--;
  3942. lcd_implementation_clear();
  3943. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  3944. for (int i = 0; i < 3; i++) {
  3945. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  3946. }
  3947. }
  3948. }
  3949. lcd.setCursor(0, 1);
  3950. lcd.print(" ");
  3951. lcd.setCursor(0, 2);
  3952. lcd.print(" ");
  3953. lcd.setCursor(0, 3);
  3954. lcd.print(" ");
  3955. lcd.setCursor(0, cursor_pos);
  3956. lcd.print(">");
  3957. enc_dif = encoderDiff;
  3958. delay(100);
  3959. }
  3960. }
  3961. if (lcd_clicked()) {
  3962. lcd_update(2);
  3963. while (lcd_clicked());
  3964. delay(10);
  3965. while (lcd_clicked());
  3966. KEEPALIVE_STATE(IN_HANDLER);
  3967. return(cursor_pos + first - 1);
  3968. }
  3969. }
  3970. }
  3971. char reset_menu() {
  3972. #ifdef SNMM
  3973. int items_no = 5;
  3974. #else
  3975. int items_no = 4;
  3976. #endif
  3977. static int first = 0;
  3978. int enc_dif = 0;
  3979. char cursor_pos = 0;
  3980. const char *item [items_no];
  3981. item[0] = "Language";
  3982. item[1] = "Statistics";
  3983. item[2] = "Shipping prep";
  3984. item[3] = "All Data";
  3985. #ifdef SNMM
  3986. item[4] = "Bowden length";
  3987. #endif // SNMM
  3988. enc_dif = encoderDiff;
  3989. lcd_implementation_clear();
  3990. lcd.setCursor(0, 0);
  3991. lcd.print(">");
  3992. while (1) {
  3993. for (int i = 0; i < 4; i++) {
  3994. lcd.setCursor(1, i);
  3995. lcd.print(item[first + i]);
  3996. }
  3997. manage_heater();
  3998. manage_inactivity(true);
  3999. if (abs((enc_dif - encoderDiff)) > 4) {
  4000. if ((abs(enc_dif - encoderDiff)) > 1) {
  4001. if (enc_dif > encoderDiff) {
  4002. cursor_pos--;
  4003. }
  4004. if (enc_dif < encoderDiff) {
  4005. cursor_pos++;
  4006. }
  4007. if (cursor_pos > 3) {
  4008. cursor_pos = 3;
  4009. if (first < items_no - 4) {
  4010. first++;
  4011. lcd_implementation_clear();
  4012. }
  4013. }
  4014. if (cursor_pos < 0) {
  4015. cursor_pos = 0;
  4016. if (first > 0) {
  4017. first--;
  4018. lcd_implementation_clear();
  4019. }
  4020. }
  4021. lcd.setCursor(0, 0);
  4022. lcd.print(" ");
  4023. lcd.setCursor(0, 1);
  4024. lcd.print(" ");
  4025. lcd.setCursor(0, 2);
  4026. lcd.print(" ");
  4027. lcd.setCursor(0, 3);
  4028. lcd.print(" ");
  4029. lcd.setCursor(0, cursor_pos);
  4030. lcd.print(">");
  4031. enc_dif = encoderDiff;
  4032. delay(100);
  4033. }
  4034. }
  4035. if (lcd_clicked()) {
  4036. while (lcd_clicked());
  4037. delay(10);
  4038. while (lcd_clicked());
  4039. return(cursor_pos + first);
  4040. }
  4041. }
  4042. }
  4043. static void lcd_disable_farm_mode() {
  4044. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4045. if (disable) {
  4046. enquecommand_P(PSTR("G99"));
  4047. lcd_return_to_status();
  4048. }
  4049. else {
  4050. lcd_goto_menu(lcd_settings_menu);
  4051. }
  4052. lcd_update_enable(true);
  4053. lcdDrawUpdate = 2;
  4054. }
  4055. static void lcd_ping_allert() {
  4056. if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
  4057. allert_timer = millis();
  4058. SET_OUTPUT(BEEPER);
  4059. for (int i = 0; i < 2; i++) {
  4060. WRITE(BEEPER, HIGH);
  4061. delay(50);
  4062. WRITE(BEEPER, LOW);
  4063. delay(100);
  4064. }
  4065. }
  4066. };
  4067. #ifdef SNMM
  4068. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  4069. set_extrude_min_temp(.0);
  4070. current_position[E_AXIS] += shift;
  4071. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  4072. set_extrude_min_temp(EXTRUDE_MINTEMP);
  4073. }
  4074. void change_extr(int extr) { //switches multiplexer for extruders
  4075. st_synchronize();
  4076. delay(100);
  4077. disable_e0();
  4078. disable_e1();
  4079. disable_e2();
  4080. #ifdef SNMM
  4081. snmm_extruder = extr;
  4082. #endif
  4083. pinMode(E_MUX0_PIN, OUTPUT);
  4084. pinMode(E_MUX1_PIN, OUTPUT);
  4085. pinMode(E_MUX2_PIN, OUTPUT);
  4086. switch (extr) {
  4087. case 1:
  4088. WRITE(E_MUX0_PIN, HIGH);
  4089. WRITE(E_MUX1_PIN, LOW);
  4090. WRITE(E_MUX2_PIN, LOW);
  4091. break;
  4092. case 2:
  4093. WRITE(E_MUX0_PIN, LOW);
  4094. WRITE(E_MUX1_PIN, HIGH);
  4095. WRITE(E_MUX2_PIN, LOW);
  4096. break;
  4097. case 3:
  4098. WRITE(E_MUX0_PIN, HIGH);
  4099. WRITE(E_MUX1_PIN, HIGH);
  4100. WRITE(E_MUX2_PIN, LOW);
  4101. break;
  4102. default:
  4103. WRITE(E_MUX0_PIN, LOW);
  4104. WRITE(E_MUX1_PIN, LOW);
  4105. WRITE(E_MUX2_PIN, LOW);
  4106. break;
  4107. }
  4108. delay(100);
  4109. }
  4110. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  4111. return(4 * READ(E_MUX2_PIN) + 2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  4112. }
  4113. void display_loading() {
  4114. switch (snmm_extruder) {
  4115. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  4116. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  4117. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  4118. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  4119. }
  4120. }
  4121. static void extr_adj(int extruder) //loading filament for SNMM
  4122. {
  4123. bool correct;
  4124. max_feedrate[E_AXIS] =80;
  4125. //max_feedrate[E_AXIS] = 50;
  4126. START:
  4127. lcd_implementation_clear();
  4128. lcd.setCursor(0, 0);
  4129. switch (extruder) {
  4130. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  4131. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  4132. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  4133. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  4134. }
  4135. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4136. do{
  4137. extr_mov(0.001,1000);
  4138. delay_keep_alive(2);
  4139. } while (!lcd_clicked());
  4140. //delay_keep_alive(500);
  4141. KEEPALIVE_STATE(IN_HANDLER);
  4142. st_synchronize();
  4143. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  4144. //if (!correct) goto START;
  4145. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  4146. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  4147. extr_mov(bowden_length[extruder], 500);
  4148. lcd_implementation_clear();
  4149. lcd.setCursor(0, 0); lcd_printPGM(MSG_LOADING_FILAMENT);
  4150. if(strlen(MSG_LOADING_FILAMENT)>18) lcd.setCursor(0, 1);
  4151. else lcd.print(" ");
  4152. lcd.print(snmm_extruder + 1);
  4153. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  4154. st_synchronize();
  4155. max_feedrate[E_AXIS] = 50;
  4156. lcd_update_enable(true);
  4157. lcd_return_to_status();
  4158. lcdDrawUpdate = 2;
  4159. }
  4160. void extr_unload() { //unloads filament
  4161. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  4162. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  4163. int8_t SilentMode;
  4164. if (degHotend0() > EXTRUDE_MINTEMP) {
  4165. lcd_implementation_clear();
  4166. lcd_display_message_fullscreen_P(PSTR(""));
  4167. max_feedrate[E_AXIS] = 50;
  4168. lcd.setCursor(0, 0); lcd_printPGM(MSG_UNLOADING_FILAMENT);
  4169. lcd.print(" ");
  4170. lcd.print(snmm_extruder + 1);
  4171. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  4172. if (current_position[Z_AXIS] < 15) {
  4173. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  4174. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  4175. }
  4176. current_position[E_AXIS] += 10; //extrusion
  4177. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  4178. digipot_current(2, E_MOTOR_HIGH_CURRENT);
  4179. if (current_temperature[0] < 230) { //PLA & all other filaments
  4180. current_position[E_AXIS] += 5.4;
  4181. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  4182. current_position[E_AXIS] += 3.2;
  4183. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4184. current_position[E_AXIS] += 3;
  4185. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  4186. }
  4187. else { //ABS
  4188. current_position[E_AXIS] += 3.1;
  4189. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  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], 2500 / 60, active_extruder);
  4192. current_position[E_AXIS] += 4;
  4193. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4194. /*current_position[X_AXIS] += 23; //delay
  4195. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  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. delay_keep_alive(4700);
  4199. }
  4200. max_feedrate[E_AXIS] = 80;
  4201. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4202. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  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. st_synchronize();
  4206. //digipot_init();
  4207. if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  4208. else digipot_current(2, tmp_motor_loud[2]);
  4209. lcd_update_enable(true);
  4210. lcd_return_to_status();
  4211. max_feedrate[E_AXIS] = 50;
  4212. }
  4213. else {
  4214. lcd_implementation_clear();
  4215. lcd.setCursor(0, 0);
  4216. lcd_printPGM(MSG_ERROR);
  4217. lcd.setCursor(0, 2);
  4218. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4219. delay(2000);
  4220. lcd_implementation_clear();
  4221. }
  4222. lcd_return_to_status();
  4223. }
  4224. //wrapper functions for loading filament
  4225. static void extr_adj_0(){
  4226. change_extr(0);
  4227. extr_adj(0);
  4228. }
  4229. static void extr_adj_1() {
  4230. change_extr(1);
  4231. extr_adj(1);
  4232. }
  4233. static void extr_adj_2() {
  4234. change_extr(2);
  4235. extr_adj(2);
  4236. }
  4237. static void extr_adj_3() {
  4238. change_extr(3);
  4239. extr_adj(3);
  4240. }
  4241. static void load_all() {
  4242. for (int i = 0; i < 4; i++) {
  4243. change_extr(i);
  4244. extr_adj(i);
  4245. }
  4246. }
  4247. //wrapper functions for changing extruders
  4248. static void extr_change_0() {
  4249. change_extr(0);
  4250. lcd_return_to_status();
  4251. }
  4252. static void extr_change_1() {
  4253. change_extr(1);
  4254. lcd_return_to_status();
  4255. }
  4256. static void extr_change_2() {
  4257. change_extr(2);
  4258. lcd_return_to_status();
  4259. }
  4260. static void extr_change_3() {
  4261. change_extr(3);
  4262. lcd_return_to_status();
  4263. }
  4264. //wrapper functions for unloading filament
  4265. void extr_unload_all() {
  4266. if (degHotend0() > EXTRUDE_MINTEMP) {
  4267. for (int i = 0; i < 4; i++) {
  4268. change_extr(i);
  4269. extr_unload();
  4270. }
  4271. }
  4272. else {
  4273. lcd_implementation_clear();
  4274. lcd.setCursor(0, 0);
  4275. lcd_printPGM(MSG_ERROR);
  4276. lcd.setCursor(0, 2);
  4277. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4278. delay(2000);
  4279. lcd_implementation_clear();
  4280. lcd_return_to_status();
  4281. }
  4282. }
  4283. //unloading just used filament (for snmm)
  4284. void extr_unload_used() {
  4285. if (degHotend0() > EXTRUDE_MINTEMP) {
  4286. for (int i = 0; i < 4; i++) {
  4287. if (snmm_filaments_used & (1 << i)) {
  4288. change_extr(i);
  4289. extr_unload();
  4290. }
  4291. }
  4292. snmm_filaments_used = 0;
  4293. }
  4294. else {
  4295. lcd_implementation_clear();
  4296. lcd.setCursor(0, 0);
  4297. lcd_printPGM(MSG_ERROR);
  4298. lcd.setCursor(0, 2);
  4299. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  4300. delay(2000);
  4301. lcd_implementation_clear();
  4302. lcd_return_to_status();
  4303. }
  4304. }
  4305. static void extr_unload_0() {
  4306. change_extr(0);
  4307. extr_unload();
  4308. }
  4309. static void extr_unload_1() {
  4310. change_extr(1);
  4311. extr_unload();
  4312. }
  4313. static void extr_unload_2() {
  4314. change_extr(2);
  4315. extr_unload();
  4316. }
  4317. static void extr_unload_3() {
  4318. change_extr(3);
  4319. extr_unload();
  4320. }
  4321. static void fil_load_menu()
  4322. {
  4323. START_MENU();
  4324. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4325. MENU_ITEM(function, MSG_LOAD_ALL, load_all);
  4326. MENU_ITEM(function, MSG_LOAD_FILAMENT_1, extr_adj_0);
  4327. MENU_ITEM(function, MSG_LOAD_FILAMENT_2, extr_adj_1);
  4328. MENU_ITEM(function, MSG_LOAD_FILAMENT_3, extr_adj_2);
  4329. MENU_ITEM(function, MSG_LOAD_FILAMENT_4, extr_adj_3);
  4330. END_MENU();
  4331. }
  4332. static void fil_unload_menu()
  4333. {
  4334. START_MENU();
  4335. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4336. MENU_ITEM(function, MSG_UNLOAD_ALL, extr_unload_all);
  4337. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_1, extr_unload_0);
  4338. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_2, extr_unload_1);
  4339. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_3, extr_unload_2);
  4340. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_4, extr_unload_3);
  4341. END_MENU();
  4342. }
  4343. static void change_extr_menu(){
  4344. START_MENU();
  4345. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4346. MENU_ITEM(function, MSG_EXTRUDER_1, extr_change_0);
  4347. MENU_ITEM(function, MSG_EXTRUDER_2, extr_change_1);
  4348. MENU_ITEM(function, MSG_EXTRUDER_3, extr_change_2);
  4349. MENU_ITEM(function, MSG_EXTRUDER_4, extr_change_3);
  4350. END_MENU();
  4351. }
  4352. #endif
  4353. static void lcd_farm_no()
  4354. {
  4355. char step = 0;
  4356. int enc_dif = 0;
  4357. int _farmno = farm_no;
  4358. int _ret = 0;
  4359. lcd_implementation_clear();
  4360. lcd.setCursor(0, 0);
  4361. lcd.print("Farm no");
  4362. do
  4363. {
  4364. if (abs((enc_dif - encoderDiff)) > 2) {
  4365. if (enc_dif > encoderDiff) {
  4366. switch (step) {
  4367. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4368. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4369. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4370. default: break;
  4371. }
  4372. }
  4373. if (enc_dif < encoderDiff) {
  4374. switch (step) {
  4375. case(0): if (_farmno < 900) _farmno += 100; break;
  4376. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4377. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4378. default: break;
  4379. }
  4380. }
  4381. enc_dif = 0;
  4382. encoderDiff = 0;
  4383. }
  4384. lcd.setCursor(0, 2);
  4385. if (_farmno < 100) lcd.print("0");
  4386. if (_farmno < 10) lcd.print("0");
  4387. lcd.print(_farmno);
  4388. lcd.print(" ");
  4389. lcd.setCursor(0, 3);
  4390. lcd.print(" ");
  4391. lcd.setCursor(step, 3);
  4392. lcd.print("^");
  4393. delay(100);
  4394. if (lcd_clicked())
  4395. {
  4396. delay(200);
  4397. step++;
  4398. if(step == 3) {
  4399. _ret = 1;
  4400. farm_no = _farmno;
  4401. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4402. prusa_statistics(20);
  4403. lcd_return_to_status();
  4404. }
  4405. }
  4406. manage_heater();
  4407. } while (_ret == 0);
  4408. }
  4409. void lcd_confirm_print()
  4410. {
  4411. int enc_dif = 0;
  4412. int cursor_pos = 1;
  4413. int _ret = 0;
  4414. int _t = 0;
  4415. lcd_implementation_clear();
  4416. lcd.setCursor(0, 0);
  4417. lcd.print("Print ok ?");
  4418. do
  4419. {
  4420. if (abs((enc_dif - encoderDiff)) > 2) {
  4421. if (enc_dif > encoderDiff) {
  4422. cursor_pos--;
  4423. }
  4424. if (enc_dif < encoderDiff) {
  4425. cursor_pos++;
  4426. }
  4427. }
  4428. if (cursor_pos > 2) { cursor_pos = 2; }
  4429. if (cursor_pos < 1) { cursor_pos = 1; }
  4430. lcd.setCursor(0, 2); lcd.print(" ");
  4431. lcd.setCursor(0, 3); lcd.print(" ");
  4432. lcd.setCursor(2, 2);
  4433. lcd_printPGM(MSG_YES);
  4434. lcd.setCursor(2, 3);
  4435. lcd_printPGM(MSG_NO);
  4436. lcd.setCursor(0, 1 + cursor_pos);
  4437. lcd.print(">");
  4438. delay(100);
  4439. _t = _t + 1;
  4440. if (_t>100)
  4441. {
  4442. prusa_statistics(99);
  4443. _t = 0;
  4444. }
  4445. if (lcd_clicked())
  4446. {
  4447. if (cursor_pos == 1)
  4448. {
  4449. _ret = 1;
  4450. prusa_statistics(20);
  4451. prusa_statistics(4);
  4452. }
  4453. if (cursor_pos == 2)
  4454. {
  4455. _ret = 2;
  4456. prusa_statistics(20);
  4457. prusa_statistics(5);
  4458. }
  4459. }
  4460. manage_heater();
  4461. manage_inactivity();
  4462. } while (_ret == 0);
  4463. }
  4464. extern bool saved_printing;
  4465. static void lcd_main_menu()
  4466. {
  4467. SDscrool = 0;
  4468. START_MENU();
  4469. // Majkl superawesome menu
  4470. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  4471. #ifdef RESUME_DEBUG
  4472. if (!saved_printing)
  4473. MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save);
  4474. else
  4475. MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore);
  4476. #endif //RESUME_DEBUG
  4477. #ifdef TMC2130_DEBUG
  4478. MENU_ITEM(function, PSTR("recover print"), recover_print);
  4479. MENU_ITEM(function, PSTR("power panic"), uvlo_);
  4480. #endif //TMC2130_DEBUG
  4481. /* if (farm_mode && !IS_SD_PRINTING )
  4482. {
  4483. int tempScrool = 0;
  4484. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4485. //delay(100);
  4486. return; // nothing to do (so don't thrash the SD card)
  4487. uint16_t fileCnt = card.getnrfilenames();
  4488. card.getWorkDirName();
  4489. if (card.filename[0] == '/')
  4490. {
  4491. #if SDCARDDETECT == -1
  4492. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4493. #endif
  4494. } else {
  4495. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4496. }
  4497. for (uint16_t i = 0; i < fileCnt; i++)
  4498. {
  4499. if (_menuItemNr == _lineNr)
  4500. {
  4501. #ifndef SDCARD_RATHERRECENTFIRST
  4502. card.getfilename(i);
  4503. #else
  4504. card.getfilename(fileCnt - 1 - i);
  4505. #endif
  4506. if (card.filenameIsDir)
  4507. {
  4508. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4509. } else {
  4510. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  4511. }
  4512. } else {
  4513. MENU_ITEM_DUMMY();
  4514. }
  4515. }
  4516. MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen);
  4517. }*/
  4518. 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)
  4519. {
  4520. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  4521. }
  4522. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4523. {
  4524. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  4525. } else
  4526. {
  4527. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  4528. }
  4529. #ifdef SDSUPPORT
  4530. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4531. {
  4532. if (card.isFileOpen())
  4533. {
  4534. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4535. if (card.sdprinting)
  4536. {
  4537. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  4538. }
  4539. else
  4540. {
  4541. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  4542. }
  4543. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  4544. }
  4545. }
  4546. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4547. //MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  4548. }
  4549. else
  4550. {
  4551. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4552. {
  4553. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4554. /*else*/ MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  4555. }
  4556. #if SDCARDDETECT < 1
  4557. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  4558. #endif
  4559. }
  4560. } else
  4561. {
  4562. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  4563. #if SDCARDDETECT < 1
  4564. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  4565. #endif
  4566. }
  4567. #endif
  4568. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4569. {
  4570. if (farm_mode)
  4571. {
  4572. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  4573. }
  4574. }
  4575. else
  4576. {
  4577. #ifndef SNMM
  4578. if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
  4579. MENU_ITEM(function, MSG_AUTOLOAD_FILAMENT, lcd_LoadFilament);
  4580. else
  4581. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  4582. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  4583. #endif
  4584. #ifdef SNMM
  4585. MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);
  4586. MENU_ITEM(submenu, MSG_UNLOAD_FILAMENT, fil_unload_menu);
  4587. MENU_ITEM(submenu, MSG_CHANGE_EXTR, change_extr_menu);
  4588. #endif
  4589. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  4590. if(!isPrintPaused) MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  4591. #ifdef EXPERIMENTAL_FEATURES
  4592. MENU_ITEM(submenu, PSTR("Experimantal"), lcd_experimantal_menu);
  4593. #endif //EXPERIMENTAL_FEATURES
  4594. }
  4595. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4596. {
  4597. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  4598. }
  4599. MENU_ITEM(submenu, PSTR("Fail stats"), lcd_menu_fails_stats);
  4600. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  4601. END_MENU();
  4602. }
  4603. void stack_error() {
  4604. SET_OUTPUT(BEEPER);
  4605. WRITE(BEEPER, HIGH);
  4606. delay(1000);
  4607. WRITE(BEEPER, LOW);
  4608. lcd_display_message_fullscreen_P(MSG_STACK_ERROR);
  4609. //err_triggered = 1;
  4610. while (1) delay_keep_alive(1000);
  4611. }
  4612. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4613. bool stepper_timer_overflow_state = false;
  4614. void stepper_timer_overflow() {
  4615. SET_OUTPUT(BEEPER);
  4616. WRITE(BEEPER, HIGH);
  4617. delay(1000);
  4618. WRITE(BEEPER, LOW);
  4619. lcd_display_message_fullscreen_P(MSG_STEPPER_TIMER_OVERFLOW_ERROR);
  4620. //err_triggered = 1;
  4621. while (1) delay_keep_alive(1000);
  4622. }
  4623. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4624. #ifdef SDSUPPORT
  4625. static void lcd_autostart_sd()
  4626. {
  4627. card.lastnr = 0;
  4628. card.setroot();
  4629. card.checkautostart(true);
  4630. }
  4631. #endif
  4632. static void lcd_colorprint_change() {
  4633. enquecommand_P(PSTR("M600"));
  4634. custom_message = true;
  4635. custom_message_type = 2; //just print status message
  4636. lcd_setstatuspgm(MSG_FINISHING_MOVEMENTS);
  4637. lcd_return_to_status();
  4638. lcdDrawUpdate = 3;
  4639. }
  4640. static void lcd_tune_menu()
  4641. {
  4642. if (menuData.tuneMenu.status == 0) {
  4643. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  4644. menuData.tuneMenu.status = 1;
  4645. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4646. } else if (menuData.tuneMenu.extrudemultiply != extrudemultiply) {
  4647. // extrudemultiply has been changed from the child menu. Apply the new value.
  4648. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4649. calculate_extruder_multipliers();
  4650. }
  4651. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4652. START_MENU();
  4653. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  4654. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  4655. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  4656. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  4657. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  4658. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  4659. #ifdef FILAMENTCHANGEENABLE
  4660. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
  4661. #endif
  4662. #ifndef DEBUG_DISABLE_FSENSORCHECK
  4663. if (FSensorStateMenu == 0) {
  4664. MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
  4665. } else {
  4666. MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
  4667. }
  4668. #endif //DEBUG_DISABLE_FSENSORCHECK
  4669. if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  4670. else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  4671. if (SilentModeMenu == 0)
  4672. {
  4673. if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
  4674. else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
  4675. }
  4676. else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
  4677. END_MENU();
  4678. }
  4679. static void lcd_move_menu_01mm()
  4680. {
  4681. move_menu_scale = 0.1;
  4682. lcd_move_menu_axis();
  4683. }
  4684. static void lcd_control_temperature_menu()
  4685. {
  4686. #ifdef PIDTEMP
  4687. // set up temp variables - undo the default scaling
  4688. // raw_Ki = unscalePID_i(Ki);
  4689. // raw_Kd = unscalePID_d(Kd);
  4690. #endif
  4691. START_MENU();
  4692. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  4693. #if TEMP_SENSOR_0 != 0
  4694. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  4695. #endif
  4696. #if TEMP_SENSOR_1 != 0
  4697. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  4698. #endif
  4699. #if TEMP_SENSOR_2 != 0
  4700. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  4701. #endif
  4702. #if TEMP_SENSOR_BED != 0
  4703. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  4704. #endif
  4705. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  4706. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  4707. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  4708. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  4709. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  4710. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  4711. #endif
  4712. END_MENU();
  4713. }
  4714. #if SDCARDDETECT == -1
  4715. static void lcd_sd_refresh()
  4716. {
  4717. card.initsd();
  4718. currentMenuViewOffset = 0;
  4719. }
  4720. #endif
  4721. static void lcd_sd_updir()
  4722. {
  4723. SDscrool = 0;
  4724. card.updir();
  4725. currentMenuViewOffset = 0;
  4726. }
  4727. void lcd_print_stop() {
  4728. cancel_heatup = true;
  4729. #ifdef MESH_BED_LEVELING
  4730. mbl.active = false;
  4731. #endif
  4732. // Stop the stoppers, update the position from the stoppers.
  4733. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4734. planner_abort_hard();
  4735. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  4736. // Z baystep is no more applied. Reset it.
  4737. babystep_reset();
  4738. }
  4739. // Clean the input command queue.
  4740. cmdqueue_reset();
  4741. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  4742. lcd_update(2);
  4743. card.sdprinting = false;
  4744. card.closefile();
  4745. stoptime = millis();
  4746. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  4747. pause_time = 0;
  4748. save_statistics(total_filament_used, t);
  4749. lcd_return_to_status();
  4750. lcd_ignore_click(true);
  4751. lcd_commands_step = 0;
  4752. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  4753. // Turn off the print fan
  4754. SET_OUTPUT(FAN_PIN);
  4755. WRITE(FAN_PIN, 0);
  4756. fanSpeed = 0;
  4757. }
  4758. void lcd_sdcard_stop()
  4759. {
  4760. lcd.setCursor(0, 0);
  4761. lcd_printPGM(MSG_STOP_PRINT);
  4762. lcd.setCursor(2, 2);
  4763. lcd_printPGM(MSG_NO);
  4764. lcd.setCursor(2, 3);
  4765. lcd_printPGM(MSG_YES);
  4766. lcd.setCursor(0, 2); lcd.print(" ");
  4767. lcd.setCursor(0, 3); lcd.print(" ");
  4768. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  4769. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  4770. lcd.setCursor(0, 1 + encoderPosition);
  4771. lcd.print(">");
  4772. if (lcd_clicked())
  4773. {
  4774. if ((int32_t)encoderPosition == 1)
  4775. {
  4776. lcd_return_to_status();
  4777. }
  4778. if ((int32_t)encoderPosition == 2)
  4779. {
  4780. lcd_print_stop();
  4781. }
  4782. }
  4783. }
  4784. /*
  4785. void getFileDescription(char *name, char *description) {
  4786. // get file description, ie the REAL filenam, ie the second line
  4787. card.openFile(name, true);
  4788. int i = 0;
  4789. // skip the first line (which is the version line)
  4790. while (true) {
  4791. uint16_t readByte = card.get();
  4792. if (readByte == '\n') {
  4793. break;
  4794. }
  4795. }
  4796. // read the second line (which is the description line)
  4797. while (true) {
  4798. uint16_t readByte = card.get();
  4799. if (i == 0) {
  4800. // skip the first '^'
  4801. readByte = card.get();
  4802. }
  4803. description[i] = readByte;
  4804. i++;
  4805. if (readByte == '\n') {
  4806. break;
  4807. }
  4808. }
  4809. card.closefile();
  4810. description[i-1] = 0;
  4811. }
  4812. */
  4813. void lcd_sdcard_menu()
  4814. {
  4815. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  4816. int tempScrool = 0;
  4817. if (presort_flag == true) {
  4818. presort_flag = false;
  4819. card.presort();
  4820. }
  4821. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4822. //delay(100);
  4823. return; // nothing to do (so don't thrash the SD card)
  4824. uint16_t fileCnt = card.getnrfilenames();
  4825. START_MENU();
  4826. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4827. card.getWorkDirName();
  4828. if (card.filename[0] == '/')
  4829. {
  4830. #if SDCARDDETECT == -1
  4831. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4832. #endif
  4833. } else {
  4834. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4835. }
  4836. for (uint16_t i = 0; i < fileCnt; i++)
  4837. {
  4838. if (_menuItemNr == _lineNr)
  4839. {
  4840. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  4841. /*#ifdef SDCARD_RATHERRECENTFIRST
  4842. #ifndef SDCARD_SORT_ALPHA
  4843. fileCnt - 1 -
  4844. #endif
  4845. #endif
  4846. i;*/
  4847. #ifdef SDCARD_SORT_ALPHA
  4848. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  4849. else card.getfilename_sorted(nr);
  4850. #else
  4851. card.getfilename(nr);
  4852. #endif
  4853. if (card.filenameIsDir)
  4854. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4855. else
  4856. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  4857. } else {
  4858. MENU_ITEM_DUMMY();
  4859. }
  4860. }
  4861. END_MENU();
  4862. }
  4863. //char description [10] [31];
  4864. /*void get_description() {
  4865. uint16_t fileCnt = card.getnrfilenames();
  4866. for (uint16_t i = 0; i < fileCnt; i++)
  4867. {
  4868. card.getfilename(fileCnt - 1 - i);
  4869. getFileDescription(card.filename, description[i]);
  4870. }
  4871. }*/
  4872. /*void lcd_farm_sdcard_menu()
  4873. {
  4874. static int i = 0;
  4875. if (i == 0) {
  4876. get_description();
  4877. i++;
  4878. }
  4879. //int j;
  4880. //char description[31];
  4881. int tempScrool = 0;
  4882. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4883. //delay(100);
  4884. return; // nothing to do (so don't thrash the SD card)
  4885. uint16_t fileCnt = card.getnrfilenames();
  4886. START_MENU();
  4887. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  4888. card.getWorkDirName();
  4889. if (card.filename[0] == '/')
  4890. {
  4891. #if SDCARDDETECT == -1
  4892. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  4893. #endif
  4894. }
  4895. else {
  4896. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4897. }
  4898. for (uint16_t i = 0; i < fileCnt; i++)
  4899. {
  4900. if (_menuItemNr == _lineNr)
  4901. {
  4902. #ifndef SDCARD_RATHERRECENTFIRST
  4903. card.getfilename(i);
  4904. #else
  4905. card.getfilename(fileCnt - 1 - i);
  4906. #endif
  4907. if (card.filenameIsDir)
  4908. {
  4909. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  4910. }
  4911. else {
  4912. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, description[i]);
  4913. }
  4914. }
  4915. else {
  4916. MENU_ITEM_DUMMY();
  4917. }
  4918. }
  4919. END_MENU();
  4920. }*/
  4921. #define menu_edit_type(_type, _name, _strFunc, scale) \
  4922. void menu_edit_ ## _name () \
  4923. { \
  4924. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  4925. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  4926. if (lcdDrawUpdate) \
  4927. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  4928. if (LCD_CLICKED) \
  4929. { \
  4930. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  4931. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  4932. } \
  4933. } \
  4934. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  4935. { \
  4936. asm("cli"); \
  4937. menuData.editMenuParentState.prevMenu = currentMenu; \
  4938. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  4939. asm("sei"); \
  4940. \
  4941. lcdDrawUpdate = 2; \
  4942. menuData.editMenuParentState.editLabel = pstr; \
  4943. menuData.editMenuParentState.editValue = ptr; \
  4944. menuData.editMenuParentState.minEditValue = minValue * scale; \
  4945. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  4946. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  4947. \
  4948. }\
  4949. /*
  4950. void menu_edit_callback_ ## _name () { \
  4951. menu_edit_ ## _name (); \
  4952. if (LCD_CLICKED) (*callbackFunc)(); \
  4953. } \
  4954. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  4955. { \
  4956. menuData.editMenuParentState.prevMenu = currentMenu; \
  4957. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  4958. \
  4959. lcdDrawUpdate = 2; \
  4960. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  4961. \
  4962. menuData.editMenuParentState.editLabel = pstr; \
  4963. menuData.editMenuParentState.editValue = ptr; \
  4964. menuData.editMenuParentState.minEditValue = minValue * scale; \
  4965. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  4966. callbackFunc = callback;\
  4967. }
  4968. */
  4969. // Convert tmc2130 mres to string
  4970. char *mres_to_str3(const uint8_t &x)
  4971. {
  4972. return itostr3(256 >> x);
  4973. }
  4974. extern char conv[8];
  4975. // Convert tmc2130 wfac to string
  4976. char *wfac_to_str5(const uint8_t &x)
  4977. {
  4978. if (x>=TMC2130_WAVE_FAC200_MIN) return ftostr43(((float)(x & 0xff))/200);
  4979. conv[0] = ' ';
  4980. conv[1] = ' ';
  4981. conv[2] = 'O';
  4982. conv[3] = 'f';
  4983. conv[4] = 'f';
  4984. conv[5] = 0;
  4985. return conv;
  4986. }
  4987. menu_edit_type(uint8_t, wfac, wfac_to_str5, 1)
  4988. menu_edit_type(uint8_t, mres, mres_to_str3, 1)
  4989. menu_edit_type(uint8_t, byte3, itostr3, 1)
  4990. menu_edit_type(int, int3, itostr3, 1)
  4991. menu_edit_type(float, float3, ftostr3, 1)
  4992. menu_edit_type(float, float32, ftostr32, 100)
  4993. menu_edit_type(float, float43, ftostr43, 1000)
  4994. menu_edit_type(float, float5, ftostr5, 0.01)
  4995. menu_edit_type(float, float51, ftostr51, 10)
  4996. menu_edit_type(float, float52, ftostr52, 100)
  4997. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  4998. static void lcd_selftest_v()
  4999. {
  5000. (void)lcd_selftest();
  5001. }
  5002. bool lcd_selftest()
  5003. {
  5004. int _progress = 0;
  5005. bool _result = true;
  5006. lcd_wait_for_cool_down();
  5007. lcd_implementation_clear();
  5008. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_START);
  5009. #ifdef TMC2130
  5010. FORCE_HIGH_POWER_START;
  5011. #endif // TMC2130
  5012. delay(2000);
  5013. KEEPALIVE_STATE(IN_HANDLER);
  5014. if (_result)
  5015. {
  5016. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  5017. _result = lcd_selftest_fan_dialog(0);
  5018. }
  5019. if (_result)
  5020. {
  5021. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  5022. _result = lcd_selftest_fan_dialog(1);
  5023. }
  5024. if (_result)
  5025. {
  5026. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  5027. //_progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  5028. _result = true;// lcd_selfcheck_endstops();
  5029. }
  5030. if (_result)
  5031. {
  5032. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  5033. _result = lcd_selfcheck_check_heater(false);
  5034. }
  5035. if (_result)
  5036. {
  5037. //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
  5038. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  5039. #ifdef TMC2130
  5040. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5041. #else
  5042. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5043. #endif //TMC2130
  5044. }
  5045. if (_result)
  5046. {
  5047. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  5048. #ifndef TMC2130
  5049. _result = lcd_selfcheck_pulleys(X_AXIS);
  5050. #endif
  5051. }
  5052. if (_result)
  5053. {
  5054. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  5055. #ifdef TMC2130
  5056. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5057. #else
  5058. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5059. #endif // TMC2130
  5060. }
  5061. if (_result)
  5062. {
  5063. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  5064. #ifndef TMC2130
  5065. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5066. #endif // TMC2130
  5067. }
  5068. if (_result)
  5069. {
  5070. #ifdef TMC2130
  5071. tmc2130_home_exit();
  5072. enable_endstops(false);
  5073. #endif
  5074. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  5075. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  5076. //homeaxis(X_AXIS);
  5077. //homeaxis(Y_AXIS);
  5078. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5079. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5080. st_synchronize();
  5081. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  5082. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  5083. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  5084. enquecommand_P(PSTR("G28 W"));
  5085. enquecommand_P(PSTR("G1 Z15 F1000"));
  5086. }
  5087. }
  5088. if (_result)
  5089. {
  5090. _progress = lcd_selftest_screen(13, 0, 2, true, 0);
  5091. bool bres = tmc2130_home_calibrate(X_AXIS);
  5092. _progress = lcd_selftest_screen(13, 1, 2, true, 0);
  5093. bres &= tmc2130_home_calibrate(Y_AXIS);
  5094. _progress = lcd_selftest_screen(13, 2, 2, true, 0);
  5095. if (bres)
  5096. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5097. _result = bres;
  5098. }
  5099. if (_result)
  5100. {
  5101. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  5102. _result = lcd_selfcheck_check_heater(true);
  5103. }
  5104. if (_result)
  5105. {
  5106. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5107. #ifdef PAT9125
  5108. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5109. _result = lcd_selftest_fsensor();
  5110. #endif // PAT9125
  5111. }
  5112. if (_result)
  5113. {
  5114. #ifdef PAT9125
  5115. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5116. #endif // PAT9125
  5117. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5118. }
  5119. else
  5120. {
  5121. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5122. }
  5123. lcd_reset_alert_level();
  5124. enquecommand_P(PSTR("M84"));
  5125. lcd_implementation_clear();
  5126. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5127. if (_result)
  5128. {
  5129. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  5130. }
  5131. else
  5132. {
  5133. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  5134. }
  5135. #ifdef TMC2130
  5136. FORCE_HIGH_POWER_END;
  5137. #endif // TMC2130
  5138. KEEPALIVE_STATE(NOT_BUSY);
  5139. return(_result);
  5140. }
  5141. #ifdef TMC2130
  5142. static void reset_crash_det(char axis) {
  5143. current_position[axis] += 10;
  5144. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5145. st_synchronize();
  5146. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5147. }
  5148. static bool lcd_selfcheck_axis_sg(char axis) {
  5149. // each axis length is measured twice
  5150. float axis_length, current_position_init, current_position_final;
  5151. float measured_axis_length[2];
  5152. float margin = 60;
  5153. float max_error_mm = 5;
  5154. switch (axis) {
  5155. case 0: axis_length = X_MAX_POS; break;
  5156. case 1: axis_length = Y_MAX_POS + 8; break;
  5157. default: axis_length = 210; break;
  5158. }
  5159. tmc2130_sg_stop_on_crash = false;
  5160. tmc2130_home_exit();
  5161. enable_endstops(true);
  5162. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5163. current_position[Z_AXIS] += 17;
  5164. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5165. tmc2130_home_enter(Z_AXIS_MASK);
  5166. st_synchronize();
  5167. tmc2130_home_exit();
  5168. }
  5169. // first axis length measurement begin
  5170. tmc2130_home_enter(X_AXIS_MASK << axis);
  5171. current_position[axis] -= (axis_length + margin);
  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. st_synchronize();
  5174. tmc2130_home_exit();
  5175. tmc2130_sg_meassure_start(axis);
  5176. current_position_init = st_get_position_mm(axis);
  5177. current_position[axis] += 2 * margin;
  5178. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5179. st_synchronize();
  5180. current_position[axis] += axis_length;
  5181. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5182. tmc2130_home_enter(X_AXIS_MASK << axis);
  5183. st_synchronize();
  5184. tmc2130_home_exit();
  5185. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5186. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5187. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5188. current_position_final = st_get_position_mm(axis);
  5189. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5190. // first measurement end and second measurement begin
  5191. current_position[axis] -= margin;
  5192. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5193. st_synchronize();
  5194. tmc2130_home_enter(X_AXIS_MASK << axis);
  5195. current_position[axis] -= (axis_length + 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. tmc2130_home_exit();
  5199. current_position_init = st_get_position_mm(axis);
  5200. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5201. //end of second measurement, now check for possible errors:
  5202. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5203. SERIAL_ECHOPGM("Measured axis length:");
  5204. MYSERIAL.println(measured_axis_length[i]);
  5205. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5206. enable_endstops(false);
  5207. const char *_error_1;
  5208. const char *_error_2;
  5209. if (axis == X_AXIS) _error_1 = "X";
  5210. if (axis == Y_AXIS) _error_1 = "Y";
  5211. if (axis == Z_AXIS) _error_1 = "Z";
  5212. lcd_selftest_error(9, _error_1, _error_2);
  5213. current_position[axis] = 0;
  5214. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5215. reset_crash_det(axis);
  5216. return false;
  5217. }
  5218. }
  5219. SERIAL_ECHOPGM("Axis length difference:");
  5220. MYSERIAL.println(abs(measured_axis_length[0] - measured_axis_length[1]));
  5221. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5222. //loose pulleys
  5223. const char *_error_1;
  5224. const char *_error_2;
  5225. if (axis == X_AXIS) _error_1 = "X";
  5226. if (axis == Y_AXIS) _error_1 = "Y";
  5227. if (axis == Z_AXIS) _error_1 = "Z";
  5228. lcd_selftest_error(8, _error_1, _error_2);
  5229. current_position[axis] = 0;
  5230. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5231. reset_crash_det(axis);
  5232. return false;
  5233. }
  5234. current_position[axis] = 0;
  5235. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5236. reset_crash_det(axis);
  5237. return true;
  5238. }
  5239. #endif //TMC2130
  5240. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5241. {
  5242. bool _stepdone = false;
  5243. bool _stepresult = false;
  5244. int _progress = 0;
  5245. int _travel_done = 0;
  5246. int _err_endstop = 0;
  5247. int _lcd_refresh = 0;
  5248. _travel = _travel + (_travel / 10);
  5249. do {
  5250. current_position[_axis] = current_position[_axis] - 1;
  5251. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5252. st_synchronize();
  5253. if (/*x_min_endstop || y_min_endstop || */(READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1))
  5254. {
  5255. if (_axis == 0)
  5256. {
  5257. _stepresult = (x_min_endstop) ? true : false;
  5258. _err_endstop = (y_min_endstop) ? 1 : 2;
  5259. }
  5260. if (_axis == 1)
  5261. {
  5262. _stepresult = (y_min_endstop) ? true : false;
  5263. _err_endstop = (x_min_endstop) ? 0 : 2;
  5264. }
  5265. if (_axis == 2)
  5266. {
  5267. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  5268. _err_endstop = (x_min_endstop) ? 0 : 1;
  5269. /*disable_x();
  5270. disable_y();
  5271. disable_z();*/
  5272. }
  5273. _stepdone = true;
  5274. }
  5275. #ifdef TMC2130
  5276. tmc2130_home_exit();
  5277. #endif
  5278. if (_lcd_refresh < 6)
  5279. {
  5280. _lcd_refresh++;
  5281. }
  5282. else
  5283. {
  5284. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  5285. _lcd_refresh = 0;
  5286. }
  5287. manage_heater();
  5288. manage_inactivity(true);
  5289. //delay(100);
  5290. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5291. } while (!_stepdone);
  5292. //current_position[_axis] = current_position[_axis] + 15;
  5293. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5294. if (!_stepresult)
  5295. {
  5296. const char *_error_1;
  5297. const char *_error_2;
  5298. if (_axis == X_AXIS) _error_1 = "X";
  5299. if (_axis == Y_AXIS) _error_1 = "Y";
  5300. if (_axis == Z_AXIS) _error_1 = "Z";
  5301. if (_err_endstop == 0) _error_2 = "X";
  5302. if (_err_endstop == 1) _error_2 = "Y";
  5303. if (_err_endstop == 2) _error_2 = "Z";
  5304. if (_travel_done >= _travel)
  5305. {
  5306. lcd_selftest_error(5, _error_1, _error_2);
  5307. }
  5308. else
  5309. {
  5310. lcd_selftest_error(4, _error_1, _error_2);
  5311. }
  5312. }
  5313. return _stepresult;
  5314. }
  5315. static bool lcd_selfcheck_pulleys(int axis)
  5316. {
  5317. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5318. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5319. float current_position_init, current_position_final;
  5320. float move;
  5321. bool endstop_triggered = false;
  5322. bool result = true;
  5323. int i;
  5324. unsigned long timeout_counter;
  5325. refresh_cmd_timeout();
  5326. manage_inactivity(true);
  5327. if (axis == 0) move = 50; //X_AXIS
  5328. else move = 50; //Y_AXIS
  5329. //current_position_init = current_position[axis];
  5330. current_position_init = st_get_position_mm(axis);
  5331. current_position[axis] += 5;
  5332. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5333. for (i = 0; i < 5; i++) {
  5334. refresh_cmd_timeout();
  5335. current_position[axis] = current_position[axis] + move;
  5336. //digipot_current(0, 850); //set motor current higher
  5337. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5338. st_synchronize();
  5339. //if (SilentModeMenu == 1) digipot_current(0, tmp_motor[0]); //set back to normal operation currents
  5340. //else digipot_current(0, tmp_motor_loud[0]); //set motor current back
  5341. current_position[axis] = current_position[axis] - move;
  5342. #ifdef TMC2130
  5343. tmc2130_home_enter(X_AXIS_MASK << axis);
  5344. #endif
  5345. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5346. st_synchronize();
  5347. if ((x_min_endstop) || (y_min_endstop)) {
  5348. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5349. return(false);
  5350. }
  5351. #ifdef TMC2130
  5352. tmc2130_home_exit();
  5353. #endif
  5354. }
  5355. timeout_counter = millis() + 2500;
  5356. endstop_triggered = false;
  5357. manage_inactivity(true);
  5358. while (!endstop_triggered) {
  5359. if ((x_min_endstop) || (y_min_endstop)) {
  5360. #ifdef TMC2130
  5361. tmc2130_home_exit();
  5362. #endif
  5363. endstop_triggered = true;
  5364. current_position_final = st_get_position_mm(axis);
  5365. SERIAL_ECHOPGM("current_pos_init:");
  5366. MYSERIAL.println(current_position_init);
  5367. SERIAL_ECHOPGM("current_pos:");
  5368. MYSERIAL.println(current_position_final);
  5369. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5370. if (current_position_init - 1 <= current_position_final && current_position_init + 1 >= current_position_final) {
  5371. current_position[axis] += 15;
  5372. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5373. st_synchronize();
  5374. return(true);
  5375. }
  5376. else {
  5377. return(false);
  5378. }
  5379. }
  5380. else {
  5381. #ifdef TMC2130
  5382. tmc2130_home_exit();
  5383. #endif
  5384. //current_position[axis] -= 1;
  5385. current_position[axis] += 50;
  5386. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5387. current_position[axis] -= 100;
  5388. #ifdef TMC2130
  5389. tmc2130_home_enter(X_AXIS_MASK << axis);
  5390. #endif
  5391. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5392. st_synchronize();
  5393. if (millis() > timeout_counter) {
  5394. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5395. return(false);
  5396. }
  5397. }
  5398. }
  5399. }
  5400. static bool lcd_selfcheck_endstops()
  5401. {/*
  5402. bool _result = true;
  5403. if (x_min_endstop || y_min_endstop || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  5404. {
  5405. current_position[0] = (x_min_endstop) ? current_position[0] = current_position[0] + 10 : current_position[0];
  5406. current_position[1] = (y_min_endstop) ? current_position[1] = current_position[1] + 10 : current_position[1];
  5407. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  5408. }
  5409. 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);
  5410. delay(500);
  5411. if (x_min_endstop || y_min_endstop || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  5412. {
  5413. _result = false;
  5414. char _error[4] = "";
  5415. if (x_min_endstop) strcat(_error, "X");
  5416. if (y_min_endstop) strcat(_error, "Y");
  5417. if (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) strcat(_error, "Z");
  5418. lcd_selftest_error(3, _error, "");
  5419. }
  5420. manage_heater();
  5421. manage_inactivity(true);
  5422. return _result;
  5423. */
  5424. }
  5425. static bool lcd_selfcheck_check_heater(bool _isbed)
  5426. {
  5427. int _counter = 0;
  5428. int _progress = 0;
  5429. bool _stepresult = false;
  5430. bool _docycle = true;
  5431. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5432. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5433. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5434. target_temperature[0] = (_isbed) ? 0 : 200;
  5435. target_temperature_bed = (_isbed) ? 100 : 0;
  5436. manage_heater();
  5437. manage_inactivity(true);
  5438. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5439. do {
  5440. _counter++;
  5441. _docycle = (_counter < _cycles) ? true : false;
  5442. manage_heater();
  5443. manage_inactivity(true);
  5444. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5445. /*if (_isbed) {
  5446. MYSERIAL.print("Bed temp:");
  5447. MYSERIAL.println(degBed());
  5448. }
  5449. else {
  5450. MYSERIAL.print("Hotend temp:");
  5451. MYSERIAL.println(degHotend(0));
  5452. }*/
  5453. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5454. } while (_docycle);
  5455. target_temperature[0] = 0;
  5456. target_temperature_bed = 0;
  5457. manage_heater();
  5458. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5459. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5460. /*
  5461. MYSERIAL.println("");
  5462. MYSERIAL.print("Checked result:");
  5463. MYSERIAL.println(_checked_result);
  5464. MYSERIAL.print("Opposite result:");
  5465. MYSERIAL.println(_opposite_result);
  5466. */
  5467. if (_opposite_result < ((_isbed) ? 10 : 3))
  5468. {
  5469. if (_checked_result >= ((_isbed) ? 3 : 10))
  5470. {
  5471. _stepresult = true;
  5472. }
  5473. else
  5474. {
  5475. lcd_selftest_error(1, "", "");
  5476. }
  5477. }
  5478. else
  5479. {
  5480. lcd_selftest_error(2, "", "");
  5481. }
  5482. manage_heater();
  5483. manage_inactivity(true);
  5484. KEEPALIVE_STATE(IN_HANDLER);
  5485. return _stepresult;
  5486. }
  5487. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5488. {
  5489. lcd_implementation_quick_feedback();
  5490. target_temperature[0] = 0;
  5491. target_temperature_bed = 0;
  5492. manage_heater();
  5493. manage_inactivity();
  5494. lcd_implementation_clear();
  5495. lcd.setCursor(0, 0);
  5496. lcd_printPGM(MSG_SELFTEST_ERROR);
  5497. lcd.setCursor(0, 1);
  5498. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  5499. switch (_error_no)
  5500. {
  5501. case 1:
  5502. lcd.setCursor(0, 2);
  5503. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  5504. lcd.setCursor(0, 3);
  5505. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  5506. break;
  5507. case 2:
  5508. lcd.setCursor(0, 2);
  5509. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  5510. lcd.setCursor(0, 3);
  5511. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5512. break;
  5513. case 3:
  5514. lcd.setCursor(0, 2);
  5515. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  5516. lcd.setCursor(0, 3);
  5517. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5518. lcd.setCursor(17, 3);
  5519. lcd.print(_error_1);
  5520. break;
  5521. case 4:
  5522. lcd.setCursor(0, 2);
  5523. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5524. lcd.setCursor(18, 2);
  5525. lcd.print(_error_1);
  5526. lcd.setCursor(0, 3);
  5527. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  5528. lcd.setCursor(18, 3);
  5529. lcd.print(_error_2);
  5530. break;
  5531. case 5:
  5532. lcd.setCursor(0, 2);
  5533. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  5534. lcd.setCursor(0, 3);
  5535. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5536. lcd.setCursor(18, 3);
  5537. lcd.print(_error_1);
  5538. break;
  5539. case 6:
  5540. lcd.setCursor(0, 2);
  5541. lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5542. lcd.setCursor(0, 3);
  5543. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5544. lcd.setCursor(18, 3);
  5545. lcd.print(_error_1);
  5546. break;
  5547. case 7:
  5548. lcd.setCursor(0, 2);
  5549. lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5550. lcd.setCursor(0, 3);
  5551. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5552. lcd.setCursor(18, 3);
  5553. lcd.print(_error_1);
  5554. break;
  5555. case 8:
  5556. lcd.setCursor(0, 2);
  5557. lcd_printPGM(MSG_LOOSE_PULLEY);
  5558. lcd.setCursor(0, 3);
  5559. lcd_printPGM(MSG_SELFTEST_MOTOR);
  5560. lcd.setCursor(18, 3);
  5561. lcd.print(_error_1);
  5562. break;
  5563. case 9:
  5564. lcd.setCursor(0, 2);
  5565. lcd_printPGM(MSG_SELFTEST_AXIS_LENGTH);
  5566. lcd.setCursor(0, 3);
  5567. lcd_printPGM(MSG_SELFTEST_AXIS);
  5568. lcd.setCursor(18, 3);
  5569. lcd.print(_error_1);
  5570. break;
  5571. case 10:
  5572. lcd.setCursor(0, 2);
  5573. lcd_printPGM(MSG_SELFTEST_FANS);
  5574. lcd.setCursor(0, 3);
  5575. lcd_printPGM(MSG_SELFTEST_SWAPPED);
  5576. lcd.setCursor(18, 3);
  5577. lcd.print(_error_1);
  5578. break;
  5579. case 11:
  5580. lcd.setCursor(0, 2);
  5581. lcd_printPGM(MSG_FILAMENT_SENSOR);
  5582. lcd.setCursor(0, 3);
  5583. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  5584. break;
  5585. }
  5586. delay(1000);
  5587. lcd_implementation_quick_feedback();
  5588. do {
  5589. delay(100);
  5590. manage_heater();
  5591. manage_inactivity();
  5592. } while (!lcd_clicked());
  5593. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  5594. lcd_return_to_status();
  5595. }
  5596. #ifdef PAT9125
  5597. static bool lcd_selftest_fsensor() {
  5598. fsensor_init();
  5599. if (fsensor_not_responding)
  5600. {
  5601. const char *_err;
  5602. lcd_selftest_error(11, _err, _err);
  5603. }
  5604. return(!fsensor_not_responding);
  5605. }
  5606. #endif //PAT9125
  5607. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5608. {
  5609. bool _result = check_opposite;
  5610. lcd_implementation_clear();
  5611. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_FAN);
  5612. switch (_fan)
  5613. {
  5614. case 1:
  5615. // extruder cooling fan
  5616. lcd.setCursor(0, 1);
  5617. if(check_opposite == true) lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5618. else lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5619. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5620. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5621. break;
  5622. case 2:
  5623. // object cooling fan
  5624. lcd.setCursor(0, 1);
  5625. if (check_opposite == true) lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  5626. else lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  5627. SET_OUTPUT(FAN_PIN);
  5628. analogWrite(FAN_PIN, 255);
  5629. break;
  5630. }
  5631. delay(500);
  5632. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5633. lcd.setCursor(0, 3); lcd.print(">");
  5634. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5635. int8_t enc_dif = 0;
  5636. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5637. do
  5638. {
  5639. switch (_fan)
  5640. {
  5641. case 1:
  5642. // extruder cooling fan
  5643. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5644. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5645. break;
  5646. case 2:
  5647. // object cooling fan
  5648. SET_OUTPUT(FAN_PIN);
  5649. analogWrite(FAN_PIN, 255);
  5650. break;
  5651. }
  5652. if (abs((enc_dif - encoderDiff)) > 2) {
  5653. if (enc_dif > encoderDiff) {
  5654. _result = !check_opposite;
  5655. lcd.setCursor(0, 2); lcd.print(">");
  5656. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5657. lcd.setCursor(0, 3); lcd.print(" ");
  5658. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5659. }
  5660. if (enc_dif < encoderDiff) {
  5661. _result = check_opposite;
  5662. lcd.setCursor(0, 2); lcd.print(" ");
  5663. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  5664. lcd.setCursor(0, 3); lcd.print(">");
  5665. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  5666. }
  5667. enc_dif = 0;
  5668. encoderDiff = 0;
  5669. }
  5670. manage_heater();
  5671. delay(100);
  5672. } while (!lcd_clicked());
  5673. KEEPALIVE_STATE(IN_HANDLER);
  5674. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5675. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5676. SET_OUTPUT(FAN_PIN);
  5677. analogWrite(FAN_PIN, 0);
  5678. fanSpeed = 0;
  5679. manage_heater();
  5680. return _result;
  5681. }
  5682. static bool lcd_selftest_fan_dialog(int _fan)
  5683. {
  5684. bool _result = true;
  5685. int _errno = 7;
  5686. switch (_fan) {
  5687. case 0:
  5688. fanSpeed = 0;
  5689. manage_heater(); //turn off fan
  5690. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5691. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5692. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5693. if (!fan_speed[0]) _result = false;
  5694. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5695. //MYSERIAL.println(fan_speed[0]);
  5696. //SERIAL_ECHOPGM("Print fan speed: ");
  5697. //MYSERIAL.print(fan_speed[1]);
  5698. break;
  5699. case 1:
  5700. //will it work with Thotend > 50 C ?
  5701. fanSpeed = 150; //print fan
  5702. for (uint8_t i = 0; i < 5; i++) {
  5703. delay_keep_alive(1000);
  5704. lcd.setCursor(18, 3);
  5705. lcd.print("-");
  5706. delay_keep_alive(1000);
  5707. lcd.setCursor(18, 3);
  5708. lcd.print("|");
  5709. }
  5710. fanSpeed = 0;
  5711. manage_heater(); //turn off fan
  5712. manage_inactivity(true); //to turn off print fan
  5713. if (!fan_speed[1]) {
  5714. _result = false; _errno = 6; //print fan not spinning
  5715. }
  5716. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  5717. //check fans manually
  5718. _result = lcd_selftest_manual_fan_check(2, true); //turn on print fan and check that left extruder fan is not spinning
  5719. if (_result) {
  5720. _result = lcd_selftest_manual_fan_check(2, false); //print fan is stil turned on; check that it is spinning
  5721. if (!_result) _errno = 6; //print fan not spinning
  5722. }
  5723. else {
  5724. _errno = 10; //swapped fans
  5725. }
  5726. }
  5727. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5728. //MYSERIAL.println(fan_speed[0]);
  5729. //SERIAL_ECHOPGM("Print fan speed: ");
  5730. //MYSERIAL.println(fan_speed[1]);
  5731. break;
  5732. }
  5733. if (!_result)
  5734. {
  5735. const char *_err;
  5736. lcd_selftest_error(_errno, _err, _err);
  5737. }
  5738. return _result;
  5739. }
  5740. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  5741. {
  5742. //SERIAL_ECHOPGM("Step:");
  5743. //MYSERIAL.println(_step);
  5744. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  5745. int _step_block = 0;
  5746. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  5747. if (_clear) lcd_implementation_clear();
  5748. lcd.setCursor(0, 0);
  5749. if (_step == -1) lcd_printPGM(MSG_SELFTEST_FAN);
  5750. if (_step == 0) lcd_printPGM(MSG_SELFTEST_FAN);
  5751. if (_step == 1) lcd_printPGM(MSG_SELFTEST_FAN);
  5752. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  5753. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  5754. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  5755. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  5756. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  5757. if (_step == 7) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  5758. if (_step == 8) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  5759. if (_step == 9) lcd_printPGM(MSG_SELFTEST_CHECK_FSENSOR);
  5760. if (_step == 10) lcd_printPGM(MSG_SELFTEST_CHECK_FSENSOR);
  5761. if (_step == 11) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  5762. if (_step == 12) lcd_printPGM(MSG_SELFTEST_FAILED);
  5763. if (_step == 13) lcd_printPGM(PSTR("Calibrating home"));
  5764. lcd.setCursor(0, 1);
  5765. lcd.print("--------------------");
  5766. if ((_step >= -1) && (_step <= 1))
  5767. {
  5768. //SERIAL_ECHOLNPGM("Fan test");
  5769. lcd_print_at_PGM(0, 2, MSG_SELFTEST_EXTRUDER_FAN_SPEED);
  5770. lcd.setCursor(18, 2);
  5771. (_step < 0) ? lcd.print(_indicator) : lcd.print("OK");
  5772. lcd_print_at_PGM(0, 3, MSG_SELFTEST_PRINT_FAN_SPEED);
  5773. lcd.setCursor(18, 3);
  5774. (_step < 1) ? lcd.print(_indicator) : lcd.print("OK");
  5775. }
  5776. else if (_step >= 9 && _step <= 10)
  5777. {
  5778. lcd_print_at_PGM(0, 2, MSG_SELFTEST_FILAMENT_SENSOR);
  5779. lcd.setCursor(18, 2);
  5780. (_step == 9) ? lcd.print(_indicator) : lcd.print("OK");
  5781. }
  5782. else if (_step < 9)
  5783. {
  5784. //SERIAL_ECHOLNPGM("Other tests");
  5785. _step_block = 3;
  5786. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  5787. _step_block = 4;
  5788. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  5789. _step_block = 5;
  5790. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  5791. _step_block = 6;
  5792. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  5793. _step_block = 7;
  5794. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  5795. }
  5796. if (_delay > 0) delay_keep_alive(_delay);
  5797. _progress++;
  5798. return (_progress > _progress_scale * 2) ? 0 : _progress;
  5799. }
  5800. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  5801. {
  5802. lcd.setCursor(_col, _row);
  5803. switch (_state)
  5804. {
  5805. case 1:
  5806. lcd.print(_name);
  5807. lcd.setCursor(_col + strlen(_name), _row);
  5808. lcd.print(":");
  5809. lcd.setCursor(_col + strlen(_name) + 1, _row);
  5810. lcd.print(_indicator);
  5811. break;
  5812. case 2:
  5813. lcd.print(_name);
  5814. lcd.setCursor(_col + strlen(_name), _row);
  5815. lcd.print(":");
  5816. lcd.setCursor(_col + strlen(_name) + 1, _row);
  5817. lcd.print("OK");
  5818. break;
  5819. default:
  5820. lcd.print(_name);
  5821. }
  5822. }
  5823. /** End of menus **/
  5824. static void lcd_quick_feedback()
  5825. {
  5826. lcdDrawUpdate = 2;
  5827. button_pressed = false;
  5828. lcd_implementation_quick_feedback();
  5829. }
  5830. /** Menu action functions **/
  5831. static void menu_action_back(menuFunc_t data) {
  5832. lcd_goto_menu(data);
  5833. }
  5834. static void menu_action_submenu(menuFunc_t data) {
  5835. lcd_goto_menu(data);
  5836. }
  5837. static void menu_action_gcode(const char* pgcode) {
  5838. enquecommand_P(pgcode);
  5839. }
  5840. static void menu_action_setlang(unsigned char lang) {
  5841. lcd_set_lang(lang);
  5842. }
  5843. static void menu_action_function(menuFunc_t data) {
  5844. (*data)();
  5845. }
  5846. static bool check_file(const char* filename) {
  5847. bool result = false;
  5848. uint32_t filesize;
  5849. card.openFile((char*)filename, true);
  5850. filesize = card.getFileSize();
  5851. if (filesize > END_FILE_SECTION) {
  5852. card.setIndex(filesize - END_FILE_SECTION);
  5853. }
  5854. while (!card.eof() && !result) {
  5855. card.sdprinting = true;
  5856. get_command();
  5857. result = check_commands();
  5858. }
  5859. card.printingHasFinished();
  5860. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  5861. lcd_finishstatus();
  5862. return result;
  5863. }
  5864. static void menu_action_sdfile(const char* filename, char* longFilename)
  5865. {
  5866. loading_flag = false;
  5867. char cmd[30];
  5868. char* c;
  5869. bool result = true;
  5870. sprintf_P(cmd, PSTR("M23 %s"), filename);
  5871. for (c = &cmd[4]; *c; c++)
  5872. *c = tolower(*c);
  5873. for (int i = 0; i < 8; i++) {
  5874. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, filename[i]);
  5875. }
  5876. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  5877. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  5878. for (uint8_t i = 0; i < depth; i++) {
  5879. for (int j = 0; j < 8; j++) {
  5880. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  5881. }
  5882. }
  5883. if (!check_file(filename)) {
  5884. result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FILE_INCOMPLETE, false, false);
  5885. lcd_update_enable(true);
  5886. }
  5887. if (result) {
  5888. enquecommand(cmd);
  5889. enquecommand_P(PSTR("M24"));
  5890. }
  5891. lcd_return_to_status();
  5892. }
  5893. static void menu_action_sddirectory(const char* filename, char* longFilename)
  5894. {
  5895. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  5896. strcpy(dir_names[depth], filename);
  5897. MYSERIAL.println(dir_names[depth]);
  5898. card.chdir(filename);
  5899. encoderPosition = 0;
  5900. }
  5901. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  5902. {
  5903. *ptr = !(*ptr);
  5904. }
  5905. /*
  5906. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  5907. {
  5908. menu_action_setting_edit_bool(pstr, ptr);
  5909. (*callback)();
  5910. }
  5911. */
  5912. #endif//ULTIPANEL
  5913. /** LCD API **/
  5914. void lcd_init()
  5915. {
  5916. lcd_implementation_init();
  5917. #ifdef NEWPANEL
  5918. SET_INPUT(BTN_EN1);
  5919. SET_INPUT(BTN_EN2);
  5920. WRITE(BTN_EN1, HIGH);
  5921. WRITE(BTN_EN2, HIGH);
  5922. #if BTN_ENC > 0
  5923. SET_INPUT(BTN_ENC);
  5924. WRITE(BTN_ENC, HIGH);
  5925. #endif
  5926. #ifdef REPRAPWORLD_KEYPAD
  5927. pinMode(SHIFT_CLK, OUTPUT);
  5928. pinMode(SHIFT_LD, OUTPUT);
  5929. pinMode(SHIFT_OUT, INPUT);
  5930. WRITE(SHIFT_OUT, HIGH);
  5931. WRITE(SHIFT_LD, HIGH);
  5932. #endif
  5933. #else // Not NEWPANEL
  5934. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  5935. pinMode (SR_DATA_PIN, OUTPUT);
  5936. pinMode (SR_CLK_PIN, OUTPUT);
  5937. #elif defined(SHIFT_CLK)
  5938. pinMode(SHIFT_CLK, OUTPUT);
  5939. pinMode(SHIFT_LD, OUTPUT);
  5940. pinMode(SHIFT_EN, OUTPUT);
  5941. pinMode(SHIFT_OUT, INPUT);
  5942. WRITE(SHIFT_OUT, HIGH);
  5943. WRITE(SHIFT_LD, HIGH);
  5944. WRITE(SHIFT_EN, LOW);
  5945. #else
  5946. #ifdef ULTIPANEL
  5947. #error ULTIPANEL requires an encoder
  5948. #endif
  5949. #endif // SR_LCD_2W_NL
  5950. #endif//!NEWPANEL
  5951. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  5952. pinMode(SDCARDDETECT, INPUT);
  5953. WRITE(SDCARDDETECT, HIGH);
  5954. lcd_oldcardstatus = IS_SD_INSERTED;
  5955. #endif//(SDCARDDETECT > 0)
  5956. #ifdef LCD_HAS_SLOW_BUTTONS
  5957. slow_buttons = 0;
  5958. #endif
  5959. lcd_buttons_update();
  5960. #ifdef ULTIPANEL
  5961. encoderDiff = 0;
  5962. #endif
  5963. }
  5964. //#include <avr/pgmspace.h>
  5965. static volatile bool lcd_update_enabled = true;
  5966. unsigned long lcd_timeoutToStatus = 0;
  5967. void lcd_update_enable(bool enabled)
  5968. {
  5969. if (lcd_update_enabled != enabled) {
  5970. lcd_update_enabled = enabled;
  5971. if (enabled) {
  5972. // Reset encoder position. This is equivalent to re-entering a menu.
  5973. encoderPosition = 0;
  5974. encoderDiff = 0;
  5975. // Enabling the normal LCD update procedure.
  5976. // Reset the timeout interval.
  5977. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  5978. // Force the keypad update now.
  5979. lcd_next_update_millis = millis() - 1;
  5980. // Full update.
  5981. lcd_implementation_clear();
  5982. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  5983. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  5984. #else
  5985. if (currentMenu == lcd_status_screen)
  5986. lcd_set_custom_characters_degree();
  5987. else
  5988. lcd_set_custom_characters_arrows();
  5989. #endif
  5990. lcd_update(2);
  5991. } else {
  5992. // Clear the LCD always, or let it to the caller?
  5993. }
  5994. }
  5995. }
  5996. void lcd_update(uint8_t lcdDrawUpdateOverride)
  5997. {
  5998. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  5999. lcdDrawUpdate = lcdDrawUpdateOverride;
  6000. if (!lcd_update_enabled)
  6001. return;
  6002. #ifdef LCD_HAS_SLOW_BUTTONS
  6003. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  6004. #endif
  6005. lcd_buttons_update();
  6006. #if (SDCARDDETECT > 0)
  6007. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  6008. {
  6009. lcdDrawUpdate = 2;
  6010. lcd_oldcardstatus = IS_SD_INSERTED;
  6011. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  6012. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6013. currentMenu == lcd_status_screen
  6014. #endif
  6015. );
  6016. if (lcd_oldcardstatus)
  6017. {
  6018. card.initsd();
  6019. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  6020. //get_description();
  6021. }
  6022. else
  6023. {
  6024. card.release();
  6025. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  6026. }
  6027. }
  6028. #endif//CARDINSERTED
  6029. if (lcd_next_update_millis < millis())
  6030. {
  6031. #ifdef DEBUG_BLINK_ACTIVE
  6032. static bool active_led = false;
  6033. active_led = !active_led;
  6034. pinMode(LED_PIN, OUTPUT);
  6035. digitalWrite(LED_PIN, active_led?HIGH:LOW);
  6036. #endif //DEBUG_BLINK_ACTIVE
  6037. #ifdef ULTIPANEL
  6038. #ifdef REPRAPWORLD_KEYPAD
  6039. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  6040. reprapworld_keypad_move_z_up();
  6041. }
  6042. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  6043. reprapworld_keypad_move_z_down();
  6044. }
  6045. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  6046. reprapworld_keypad_move_x_left();
  6047. }
  6048. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  6049. reprapworld_keypad_move_x_right();
  6050. }
  6051. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  6052. reprapworld_keypad_move_y_down();
  6053. }
  6054. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  6055. reprapworld_keypad_move_y_up();
  6056. }
  6057. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  6058. reprapworld_keypad_move_home();
  6059. }
  6060. #endif
  6061. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  6062. {
  6063. if (lcdDrawUpdate == 0)
  6064. lcdDrawUpdate = 1;
  6065. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  6066. encoderDiff = 0;
  6067. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6068. }
  6069. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6070. #endif//ULTIPANEL
  6071. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  6072. blink++; // Variable for fan animation and alive dot
  6073. u8g.firstPage();
  6074. do
  6075. {
  6076. u8g.setFont(u8g_font_6x10_marlin);
  6077. u8g.setPrintPos(125, 0);
  6078. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  6079. u8g.drawPixel(127, 63); // draw alive dot
  6080. u8g.setColorIndex(1); // black on white
  6081. (*currentMenu)();
  6082. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  6083. } while (u8g.nextPage());
  6084. #else
  6085. (*currentMenu)();
  6086. #endif
  6087. #ifdef LCD_HAS_STATUS_INDICATORS
  6088. lcd_implementation_update_indicators();
  6089. #endif
  6090. #ifdef ULTIPANEL
  6091. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  6092. {
  6093. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  6094. // to give it a chance to save its state.
  6095. // This is useful for example, when the babystep value has to be written into EEPROM.
  6096. if (currentMenu != NULL) {
  6097. menuExiting = true;
  6098. (*currentMenu)();
  6099. menuExiting = false;
  6100. }
  6101. lcd_implementation_clear();
  6102. lcd_return_to_status();
  6103. lcdDrawUpdate = 2;
  6104. }
  6105. #endif//ULTIPANEL
  6106. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  6107. if (lcdDrawUpdate) lcdDrawUpdate--;
  6108. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  6109. }
  6110. if (!SdFatUtil::test_stack_integrity()) stack_error();
  6111. #ifdef DEBUG_STEPPER_TIMER_MISSED
  6112. if (stepper_timer_overflow_state) stepper_timer_overflow();
  6113. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  6114. lcd_ping(); //check that we have received ping command if we are in farm mode
  6115. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6116. }
  6117. void lcd_printer_connected() {
  6118. printer_connected = true;
  6119. }
  6120. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6121. if (farm_mode) {
  6122. bool empty = is_buffer_empty();
  6123. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6124. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6125. //therefore longer period is used
  6126. printer_connected = false;
  6127. //lcd_ping_allert(); //acustic signals
  6128. }
  6129. else {
  6130. lcd_printer_connected();
  6131. }
  6132. }
  6133. }
  6134. void lcd_ignore_click(bool b)
  6135. {
  6136. ignore_click = b;
  6137. wait_for_unclick = false;
  6138. }
  6139. void lcd_finishstatus() {
  6140. int len = strlen(lcd_status_message);
  6141. if (len > 0) {
  6142. while (len < LCD_WIDTH) {
  6143. lcd_status_message[len++] = ' ';
  6144. }
  6145. }
  6146. lcd_status_message[LCD_WIDTH] = '\0';
  6147. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6148. #if PROGRESS_MSG_EXPIRE > 0
  6149. messageTick =
  6150. #endif
  6151. progressBarTick = millis();
  6152. #endif
  6153. lcdDrawUpdate = 2;
  6154. #ifdef FILAMENT_LCD_DISPLAY
  6155. message_millis = millis(); //get status message to show up for a while
  6156. #endif
  6157. }
  6158. void lcd_setstatus(const char* message)
  6159. {
  6160. if (lcd_status_message_level > 0)
  6161. return;
  6162. strncpy(lcd_status_message, message, LCD_WIDTH);
  6163. lcd_finishstatus();
  6164. }
  6165. void lcd_setstatuspgm(const char* message)
  6166. {
  6167. if (lcd_status_message_level > 0)
  6168. return;
  6169. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6170. lcd_status_message[LCD_WIDTH] = 0;
  6171. lcd_finishstatus();
  6172. }
  6173. void lcd_setalertstatuspgm(const char* message)
  6174. {
  6175. lcd_setstatuspgm(message);
  6176. lcd_status_message_level = 1;
  6177. #ifdef ULTIPANEL
  6178. lcd_return_to_status();
  6179. #endif//ULTIPANEL
  6180. }
  6181. void lcd_reset_alert_level()
  6182. {
  6183. lcd_status_message_level = 0;
  6184. }
  6185. uint8_t get_message_level()
  6186. {
  6187. return lcd_status_message_level;
  6188. }
  6189. #ifdef DOGLCD
  6190. void lcd_setcontrast(uint8_t value)
  6191. {
  6192. lcd_contrast = value & 63;
  6193. u8g.setContrast(lcd_contrast);
  6194. }
  6195. #endif
  6196. #ifdef ULTIPANEL
  6197. /* Warning: This function is called from interrupt context */
  6198. void lcd_buttons_update()
  6199. {
  6200. static bool _lock = false;
  6201. if (_lock) return;
  6202. _lock = true;
  6203. #ifdef NEWPANEL
  6204. uint8_t newbutton = 0;
  6205. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  6206. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  6207. #if BTN_ENC > 0
  6208. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  6209. if (READ(BTN_ENC) == 0) { //button is pressed
  6210. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6211. if (millis() > button_blanking_time) {
  6212. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6213. if (button_pressed == false && long_press_active == false) {
  6214. if (currentMenu != lcd_move_z) {
  6215. savedMenu = currentMenu;
  6216. savedEncoderPosition = encoderPosition;
  6217. }
  6218. long_press_timer = millis();
  6219. button_pressed = true;
  6220. }
  6221. else {
  6222. if (millis() - long_press_timer > LONG_PRESS_TIME) { //long press activated
  6223. long_press_active = true;
  6224. move_menu_scale = 1.0;
  6225. lcd_goto_menu(lcd_move_z);
  6226. }
  6227. }
  6228. }
  6229. }
  6230. else { //button not pressed
  6231. if (button_pressed) { //button was released
  6232. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6233. if (long_press_active == false) { //button released before long press gets activated
  6234. if (currentMenu == lcd_move_z) {
  6235. //return to previously active menu and previous encoder position
  6236. lcd_goto_menu(savedMenu, savedEncoderPosition);
  6237. }
  6238. else {
  6239. newbutton |= EN_C;
  6240. }
  6241. }
  6242. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  6243. //button_pressed is set back to false via lcd_quick_feedback function
  6244. }
  6245. else {
  6246. long_press_active = false;
  6247. }
  6248. }
  6249. }
  6250. else { //we are in modal mode
  6251. if (READ(BTN_ENC) == 0)
  6252. newbutton |= EN_C;
  6253. }
  6254. #endif
  6255. buttons = newbutton;
  6256. #ifdef LCD_HAS_SLOW_BUTTONS
  6257. buttons |= slow_buttons;
  6258. #endif
  6259. #ifdef REPRAPWORLD_KEYPAD
  6260. // for the reprapworld_keypad
  6261. uint8_t newbutton_reprapworld_keypad = 0;
  6262. WRITE(SHIFT_LD, LOW);
  6263. WRITE(SHIFT_LD, HIGH);
  6264. for (int8_t i = 0; i < 8; i++) {
  6265. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  6266. if (READ(SHIFT_OUT))
  6267. newbutton_reprapworld_keypad |= (1 << 7);
  6268. WRITE(SHIFT_CLK, HIGH);
  6269. WRITE(SHIFT_CLK, LOW);
  6270. }
  6271. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  6272. #endif
  6273. #else //read it from the shift register
  6274. uint8_t newbutton = 0;
  6275. WRITE(SHIFT_LD, LOW);
  6276. WRITE(SHIFT_LD, HIGH);
  6277. unsigned char tmp_buttons = 0;
  6278. for (int8_t i = 0; i < 8; i++)
  6279. {
  6280. newbutton = newbutton >> 1;
  6281. if (READ(SHIFT_OUT))
  6282. newbutton |= (1 << 7);
  6283. WRITE(SHIFT_CLK, HIGH);
  6284. WRITE(SHIFT_CLK, LOW);
  6285. }
  6286. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  6287. #endif//!NEWPANEL
  6288. //manage encoder rotation
  6289. uint8_t enc = 0;
  6290. if (buttons & EN_A) enc |= B01;
  6291. if (buttons & EN_B) enc |= B10;
  6292. if (enc != lastEncoderBits)
  6293. {
  6294. switch (enc)
  6295. {
  6296. case encrot0:
  6297. if (lastEncoderBits == encrot3)
  6298. encoderDiff++;
  6299. else if (lastEncoderBits == encrot1)
  6300. encoderDiff--;
  6301. break;
  6302. case encrot1:
  6303. if (lastEncoderBits == encrot0)
  6304. encoderDiff++;
  6305. else if (lastEncoderBits == encrot2)
  6306. encoderDiff--;
  6307. break;
  6308. case encrot2:
  6309. if (lastEncoderBits == encrot1)
  6310. encoderDiff++;
  6311. else if (lastEncoderBits == encrot3)
  6312. encoderDiff--;
  6313. break;
  6314. case encrot3:
  6315. if (lastEncoderBits == encrot2)
  6316. encoderDiff++;
  6317. else if (lastEncoderBits == encrot0)
  6318. encoderDiff--;
  6319. break;
  6320. }
  6321. }
  6322. lastEncoderBits = enc;
  6323. _lock = false;
  6324. }
  6325. bool lcd_detected(void)
  6326. {
  6327. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  6328. return lcd.LcdDetected() == 1;
  6329. #else
  6330. return true;
  6331. #endif
  6332. }
  6333. void lcd_buzz(long duration, uint16_t freq)
  6334. {
  6335. #ifdef LCD_USE_I2C_BUZZER
  6336. lcd.buzz(duration, freq);
  6337. #endif
  6338. }
  6339. bool lcd_clicked()
  6340. {
  6341. bool clicked = LCD_CLICKED;
  6342. if(clicked) button_pressed = false;
  6343. return clicked;
  6344. }
  6345. #endif//ULTIPANEL
  6346. /********************************/
  6347. /** Float conversion utilities **/
  6348. /********************************/
  6349. // convert float to string with +123.4 format
  6350. char conv[8];
  6351. char *ftostr3(const float &x)
  6352. {
  6353. return itostr3((int)x);
  6354. }
  6355. char *itostr2(const uint8_t &x)
  6356. {
  6357. //sprintf(conv,"%5.1f",x);
  6358. int xx = x;
  6359. conv[0] = (xx / 10) % 10 + '0';
  6360. conv[1] = (xx) % 10 + '0';
  6361. conv[2] = 0;
  6362. return conv;
  6363. }
  6364. // Convert float to string with 123.4 format, dropping sign
  6365. char *ftostr31(const float &x)
  6366. {
  6367. int xx = x * 10;
  6368. conv[0] = (xx >= 0) ? '+' : '-';
  6369. xx = abs(xx);
  6370. conv[1] = (xx / 1000) % 10 + '0';
  6371. conv[2] = (xx / 100) % 10 + '0';
  6372. conv[3] = (xx / 10) % 10 + '0';
  6373. conv[4] = '.';
  6374. conv[5] = (xx) % 10 + '0';
  6375. conv[6] = 0;
  6376. return conv;
  6377. }
  6378. // Convert float to string with 123.4 format
  6379. char *ftostr31ns(const float &x)
  6380. {
  6381. int xx = x * 10;
  6382. //conv[0]=(xx>=0)?'+':'-';
  6383. xx = abs(xx);
  6384. conv[0] = (xx / 1000) % 10 + '0';
  6385. conv[1] = (xx / 100) % 10 + '0';
  6386. conv[2] = (xx / 10) % 10 + '0';
  6387. conv[3] = '.';
  6388. conv[4] = (xx) % 10 + '0';
  6389. conv[5] = 0;
  6390. return conv;
  6391. }
  6392. char *ftostr32(const float &x)
  6393. {
  6394. long xx = x * 100;
  6395. if (xx >= 0)
  6396. conv[0] = (xx / 10000) % 10 + '0';
  6397. else
  6398. conv[0] = '-';
  6399. xx = abs(xx);
  6400. conv[1] = (xx / 1000) % 10 + '0';
  6401. conv[2] = (xx / 100) % 10 + '0';
  6402. conv[3] = '.';
  6403. conv[4] = (xx / 10) % 10 + '0';
  6404. conv[5] = (xx) % 10 + '0';
  6405. conv[6] = 0;
  6406. return conv;
  6407. }
  6408. //// Convert float to rj string with 123.45 format
  6409. char *ftostr32ns(const float &x) {
  6410. long xx = abs(x);
  6411. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6412. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6413. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  6414. conv[3] = '.';
  6415. conv[4] = (xx / 10) % 10 + '0';
  6416. conv[5] = xx % 10 + '0';
  6417. return conv;
  6418. }
  6419. // Convert float to string with 1.234 format
  6420. char *ftostr43(const float &x)
  6421. {
  6422. long xx = x * 1000;
  6423. if (xx >= 0)
  6424. conv[0] = (xx / 1000) % 10 + '0';
  6425. else
  6426. conv[0] = '-';
  6427. xx = abs(xx);
  6428. conv[1] = '.';
  6429. conv[2] = (xx / 100) % 10 + '0';
  6430. conv[3] = (xx / 10) % 10 + '0';
  6431. conv[4] = (xx) % 10 + '0';
  6432. conv[5] = 0;
  6433. return conv;
  6434. }
  6435. //Float to string with 1.23 format
  6436. char *ftostr12ns(const float &x)
  6437. {
  6438. long xx = x * 100;
  6439. xx = abs(xx);
  6440. conv[0] = (xx / 100) % 10 + '0';
  6441. conv[1] = '.';
  6442. conv[2] = (xx / 10) % 10 + '0';
  6443. conv[3] = (xx) % 10 + '0';
  6444. conv[4] = 0;
  6445. return conv;
  6446. }
  6447. //Float to string with 1.234 format
  6448. char *ftostr13ns(const float &x)
  6449. {
  6450. long xx = x * 1000;
  6451. if (xx >= 0)
  6452. conv[0] = ' ';
  6453. else
  6454. conv[0] = '-';
  6455. xx = abs(xx);
  6456. conv[1] = (xx / 1000) % 10 + '0';
  6457. conv[2] = '.';
  6458. conv[3] = (xx / 100) % 10 + '0';
  6459. conv[4] = (xx / 10) % 10 + '0';
  6460. conv[5] = (xx) % 10 + '0';
  6461. conv[6] = 0;
  6462. return conv;
  6463. }
  6464. // convert float to space-padded string with -_23.4_ format
  6465. char *ftostr32sp(const float &x) {
  6466. long xx = abs(x * 100);
  6467. uint8_t dig;
  6468. if (x < 0) { // negative val = -_0
  6469. conv[0] = '-';
  6470. dig = (xx / 1000) % 10;
  6471. conv[1] = dig ? '0' + dig : ' ';
  6472. }
  6473. else { // positive val = __0
  6474. dig = (xx / 10000) % 10;
  6475. if (dig) {
  6476. conv[0] = '0' + dig;
  6477. conv[1] = '0' + (xx / 1000) % 10;
  6478. }
  6479. else {
  6480. conv[0] = ' ';
  6481. dig = (xx / 1000) % 10;
  6482. conv[1] = dig ? '0' + dig : ' ';
  6483. }
  6484. }
  6485. conv[2] = '0' + (xx / 100) % 10; // lsd always
  6486. dig = xx % 10;
  6487. if (dig) { // 2 decimal places
  6488. conv[5] = '0' + dig;
  6489. conv[4] = '0' + (xx / 10) % 10;
  6490. conv[3] = '.';
  6491. }
  6492. else { // 1 or 0 decimal place
  6493. dig = (xx / 10) % 10;
  6494. if (dig) {
  6495. conv[4] = '0' + dig;
  6496. conv[3] = '.';
  6497. }
  6498. else {
  6499. conv[3] = conv[4] = ' ';
  6500. }
  6501. conv[5] = ' ';
  6502. }
  6503. conv[6] = '\0';
  6504. return conv;
  6505. }
  6506. char *itostr31(const int &xx)
  6507. {
  6508. conv[0] = (xx >= 0) ? '+' : '-';
  6509. conv[1] = (xx / 1000) % 10 + '0';
  6510. conv[2] = (xx / 100) % 10 + '0';
  6511. conv[3] = (xx / 10) % 10 + '0';
  6512. conv[4] = '.';
  6513. conv[5] = (xx) % 10 + '0';
  6514. conv[6] = 0;
  6515. return conv;
  6516. }
  6517. // Convert int to rj string with 123 or -12 format
  6518. char *itostr3(const int &x)
  6519. {
  6520. int xx = x;
  6521. if (xx < 0) {
  6522. conv[0] = '-';
  6523. xx = -xx;
  6524. } else if (xx >= 100)
  6525. conv[0] = (xx / 100) % 10 + '0';
  6526. else
  6527. conv[0] = ' ';
  6528. if (xx >= 10)
  6529. conv[1] = (xx / 10) % 10 + '0';
  6530. else
  6531. conv[1] = ' ';
  6532. conv[2] = (xx) % 10 + '0';
  6533. conv[3] = 0;
  6534. return conv;
  6535. }
  6536. // Convert int to lj string with 123 format
  6537. char *itostr3left(const int &xx)
  6538. {
  6539. if (xx >= 100)
  6540. {
  6541. conv[0] = (xx / 100) % 10 + '0';
  6542. conv[1] = (xx / 10) % 10 + '0';
  6543. conv[2] = (xx) % 10 + '0';
  6544. conv[3] = 0;
  6545. }
  6546. else if (xx >= 10)
  6547. {
  6548. conv[0] = (xx / 10) % 10 + '0';
  6549. conv[1] = (xx) % 10 + '0';
  6550. conv[2] = 0;
  6551. }
  6552. else
  6553. {
  6554. conv[0] = (xx) % 10 + '0';
  6555. conv[1] = 0;
  6556. }
  6557. return conv;
  6558. }
  6559. // Convert int to rj string with 1234 format
  6560. char *itostr4(const int &xx) {
  6561. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6562. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6563. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6564. conv[3] = xx % 10 + '0';
  6565. conv[4] = 0;
  6566. return conv;
  6567. }
  6568. // Convert float to rj string with 12345 format
  6569. char *ftostr5(const float &x) {
  6570. long xx = abs(x);
  6571. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6572. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6573. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6574. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6575. conv[4] = xx % 10 + '0';
  6576. conv[5] = 0;
  6577. return conv;
  6578. }
  6579. // Convert float to string with +1234.5 format
  6580. char *ftostr51(const float &x)
  6581. {
  6582. long xx = x * 10;
  6583. conv[0] = (xx >= 0) ? '+' : '-';
  6584. xx = abs(xx);
  6585. conv[1] = (xx / 10000) % 10 + '0';
  6586. conv[2] = (xx / 1000) % 10 + '0';
  6587. conv[3] = (xx / 100) % 10 + '0';
  6588. conv[4] = (xx / 10) % 10 + '0';
  6589. conv[5] = '.';
  6590. conv[6] = (xx) % 10 + '0';
  6591. conv[7] = 0;
  6592. return conv;
  6593. }
  6594. // Convert float to string with +123.45 format
  6595. char *ftostr52(const float &x)
  6596. {
  6597. long xx = x * 100;
  6598. conv[0] = (xx >= 0) ? '+' : '-';
  6599. xx = abs(xx);
  6600. conv[1] = (xx / 10000) % 10 + '0';
  6601. conv[2] = (xx / 1000) % 10 + '0';
  6602. conv[3] = (xx / 100) % 10 + '0';
  6603. conv[4] = '.';
  6604. conv[5] = (xx / 10) % 10 + '0';
  6605. conv[6] = (xx) % 10 + '0';
  6606. conv[7] = 0;
  6607. return conv;
  6608. }
  6609. /*
  6610. // Callback for after editing PID i value
  6611. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  6612. void copy_and_scalePID_i()
  6613. {
  6614. #ifdef PIDTEMP
  6615. Ki = scalePID_i(raw_Ki);
  6616. updatePID();
  6617. #endif
  6618. }
  6619. // Callback for after editing PID d value
  6620. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  6621. void copy_and_scalePID_d()
  6622. {
  6623. #ifdef PIDTEMP
  6624. Kd = scalePID_d(raw_Kd);
  6625. updatePID();
  6626. #endif
  6627. }
  6628. */
  6629. #endif //ULTRA_LCD