ultralcd.cpp 183 KB

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