ultralcd.cpp 193 KB

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