ultralcd.cpp 220 KB

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