ultralcd.cpp 211 KB

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