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