ultralcd.cpp 231 KB

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