ultralcd.cpp 186 KB

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