ultralcd.cpp 183 KB

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