ultralcd.cpp 206 KB

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