ultralcd.cpp 230 KB

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