ultralcd.cpp 224 KB

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