ultralcd.cpp 231 KB

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