ultralcd.cpp 188 KB

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