ultralcd.cpp 226 KB

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