ultralcd.cpp 224 KB

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