ultralcd.cpp 191 KB

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