ultralcd.cpp 198 KB

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