ultralcd.cpp 224 KB

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