ultralcd.cpp 235 KB

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