ultralcd.cpp 230 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999
  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. uint8_t cnt = lang_get_count();
  3200. #ifdef W25X20CL
  3201. if (cnt == 2) //display secondary language in case of clear xflash
  3202. MENU_ITEM(setlang, lang_get_name_by_code(lang_get_code(1)), 1);
  3203. else
  3204. for (int i = 2; i < cnt; i++) //skip seconday language - solved in lang_select
  3205. #else //W25X20CL
  3206. for (int i = 1; i < cnt; i++) //all seconday languages
  3207. #endif //W25X20CL
  3208. MENU_ITEM(setlang, lang_get_name_by_code(lang_get_code(i)), i);
  3209. END_MENU();
  3210. }
  3211. #endif //(LANG_MODE != 0)
  3212. void lcd_mesh_bedleveling()
  3213. {
  3214. mesh_bed_run_from_menu = true;
  3215. enquecommand_P(PSTR("G80"));
  3216. lcd_return_to_status();
  3217. }
  3218. void lcd_mesh_calibration()
  3219. {
  3220. enquecommand_P(PSTR("M45"));
  3221. lcd_return_to_status();
  3222. }
  3223. void lcd_mesh_calibration_z()
  3224. {
  3225. enquecommand_P(PSTR("M45 Z"));
  3226. lcd_return_to_status();
  3227. }
  3228. void lcd_pinda_calibration_menu()
  3229. {
  3230. START_MENU();
  3231. MENU_ITEM(back, _T(MSG_MENU_CALIBRATION), 0);
  3232. MENU_ITEM(submenu, _i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3233. END_MENU();
  3234. }
  3235. void lcd_temp_calibration_set() {
  3236. temp_cal_active = !temp_cal_active;
  3237. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3238. st_current_init();
  3239. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  3240. }
  3241. #ifdef HAS_SECOND_SERIAL_PORT
  3242. void lcd_second_serial_set() {
  3243. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3244. else selectedSerialPort = 1;
  3245. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3246. MYSERIAL.begin(BAUDRATE);
  3247. lcd_goto_menu(lcd_settings_menu);//doesn't break menuStack
  3248. }
  3249. #endif //HAS_SECOND_SERIAL_PORT
  3250. void lcd_calibrate_pinda() {
  3251. enquecommand_P(PSTR("G76"));
  3252. lcd_return_to_status();
  3253. }
  3254. #ifndef SNMM
  3255. /*void lcd_calibrate_extruder() {
  3256. if (degHotend0() > EXTRUDE_MINTEMP)
  3257. {
  3258. current_position[E_AXIS] = 0; //set initial position to zero
  3259. plan_set_e_position(current_position[E_AXIS]);
  3260. //long steps_start = st_get_position(E_AXIS);
  3261. long steps_final;
  3262. float e_steps_per_unit;
  3263. 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)
  3264. 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
  3265. 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
  3266. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3267. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3268. unsigned long msg_millis;
  3269. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3270. lcd_implementation_clear();
  3271. lcd.setCursor(0, 1); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  3272. current_position[E_AXIS] += e_shift_calibration;
  3273. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3274. st_synchronize();
  3275. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3276. msg_millis = millis();
  3277. while (!LCD_CLICKED) {
  3278. if (multi_screen && millis() - msg_millis > 5000) {
  3279. if (msg_next_e_cal_knob == NULL)
  3280. msg_next_e_cal_knob = msg_e_cal_knob;
  3281. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3282. msg_millis = millis();
  3283. }
  3284. //manage_inactivity(true);
  3285. manage_heater();
  3286. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3287. delay_keep_alive(50);
  3288. //previous_millis_cmd = millis();
  3289. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  3290. encoderDiff = 0;
  3291. if (!planner_queue_full()) {
  3292. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  3293. encoderPosition = 0;
  3294. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3295. }
  3296. }
  3297. }
  3298. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3299. //steps_final = st_get_position(E_AXIS);
  3300. lcdDrawUpdate = 1;
  3301. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3302. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3303. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3304. lcd_implementation_clear();
  3305. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3306. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3307. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3308. //delay_keep_alive(2000);
  3309. delay_keep_alive(500);
  3310. 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
  3311. lcd_update_enable(true);
  3312. lcdDrawUpdate = 2;
  3313. }
  3314. else
  3315. {
  3316. lcd_implementation_clear();
  3317. lcd.setCursor(0, 0);
  3318. lcd_printPGM(_T(MSG_ERROR));
  3319. lcd.setCursor(0, 2);
  3320. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  3321. delay(2000);
  3322. lcd_implementation_clear();
  3323. }
  3324. lcd_return_to_status();
  3325. }
  3326. void lcd_extr_cal_reset() {
  3327. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3328. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3329. //extrudemultiply = 100;
  3330. enquecommand_P(PSTR("M500"));
  3331. }*/
  3332. #endif
  3333. void lcd_toshiba_flash_air_compatibility_toggle()
  3334. {
  3335. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3336. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3337. }
  3338. void lcd_v2_calibration() {
  3339. 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
  3340. if (loaded) {
  3341. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3342. }
  3343. else {
  3344. lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3345. for (int i = 0; i < 20; i++) { //wait max. 2s
  3346. delay_keep_alive(100);
  3347. if (lcd_clicked()) {
  3348. while (lcd_clicked());
  3349. delay(10);
  3350. while (lcd_clicked());
  3351. break;
  3352. }
  3353. }
  3354. }
  3355. lcd_return_to_status();
  3356. lcd_update_enable(true);
  3357. }
  3358. void lcd_wizard() {
  3359. bool result = true;
  3360. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3361. 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
  3362. }
  3363. if (result) {
  3364. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3365. lcd_wizard(0);
  3366. }
  3367. else {
  3368. lcd_return_to_status();
  3369. lcd_update_enable(true);
  3370. lcd_update(2);
  3371. }
  3372. }
  3373. void lcd_language()
  3374. {
  3375. lcd_update_enable(true);
  3376. lcd_implementation_clear();
  3377. lcd_goto_menu(lcd_language_menu);
  3378. lcd_timeoutToStatus = -1; //infinite timeout
  3379. lcdDrawUpdate = 2;
  3380. while ((currentMenu != lcd_status_screen) && (!lang_is_selected()))
  3381. {
  3382. delay(50);
  3383. lcd_update();
  3384. manage_heater();
  3385. manage_inactivity(true);
  3386. }
  3387. if (lang_is_selected())
  3388. lcd_return_to_status();
  3389. else
  3390. lang_select(LANG_ID_PRI);
  3391. }
  3392. void lcd_wizard(int state) {
  3393. bool end = false;
  3394. int wizard_event;
  3395. const char *msg = NULL;
  3396. while (!end) {
  3397. switch (state) {
  3398. case 0: // run wizard?
  3399. 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
  3400. if (wizard_event) {
  3401. state = 1;
  3402. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3403. }
  3404. else {
  3405. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3406. end = true;
  3407. }
  3408. break;
  3409. case 1: // restore calibration status
  3410. switch (calibration_status()) {
  3411. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3412. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3413. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3414. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3415. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3416. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3417. }
  3418. break;
  3419. case 2: //selftest
  3420. 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
  3421. wizard_event = lcd_selftest();
  3422. if (wizard_event) {
  3423. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3424. state = 3;
  3425. }
  3426. else end = true;
  3427. break;
  3428. case 3: //xyz cal.
  3429. 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
  3430. wizard_event = gcode_M45(false, 0);
  3431. if (wizard_event) state = 5;
  3432. else end = true;
  3433. break;
  3434. case 4: //z cal.
  3435. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3436. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  3437. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3438. wizard_event = gcode_M45(true, 0);
  3439. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3440. else end = true;
  3441. break;
  3442. case 5: //is filament loaded?
  3443. //start to preheat nozzle and bed to save some time later
  3444. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3445. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3446. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament loaded?"), false);////MSG_WIZARD_FILAMENT_LOADED c=20 r=2
  3447. if (wizard_event) state = 8;
  3448. else state = 6;
  3449. break;
  3450. case 6: //waiting for preheat nozzle for PLA;
  3451. #ifndef SNMM
  3452. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3453. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3454. 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);
  3455. delay_keep_alive(2000);
  3456. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3457. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3458. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3459. lcd.setCursor(0, 4);
  3460. lcd.print(LCD_STR_THERMOMETER[0]);
  3461. lcd.print(ftostr3(degHotend(0)));
  3462. lcd.print("/");
  3463. lcd.print(PLA_PREHEAT_HOTEND_TEMP);
  3464. lcd.print(LCD_STR_DEGREE);
  3465. lcd_set_custom_characters();
  3466. delay_keep_alive(1000);
  3467. }
  3468. #endif //not SNMM
  3469. state = 7;
  3470. break;
  3471. case 7: //load filament
  3472. #ifdef PAT9125
  3473. fsensor_block();
  3474. #endif //PAT9125
  3475. 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
  3476. lcd_update_enable(false);
  3477. lcd_implementation_clear();
  3478. lcd_print_at_PGM(0, 2, _T(MSG_LOADING_FILAMENT));
  3479. #ifdef SNMM
  3480. change_extr(0);
  3481. #endif
  3482. gcode_M701();
  3483. #ifdef PAT9125
  3484. fsensor_unblock();
  3485. #endif //PAT9125
  3486. state = 9;
  3487. break;
  3488. case 8:
  3489. 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
  3490. if (wizard_event) state = 9;
  3491. else end = true;
  3492. break;
  3493. case 9:
  3494. 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
  3495. 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
  3496. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3497. end = true;
  3498. break;
  3499. case 10: //repeat first layer cal.?
  3500. 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
  3501. if (wizard_event) {
  3502. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3503. state = 9;
  3504. }
  3505. else {
  3506. state = 11;
  3507. }
  3508. break;
  3509. case 11: //we are finished
  3510. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3511. end = true;
  3512. break;
  3513. default: break;
  3514. }
  3515. }
  3516. printf_P(_N("State: %d\n"), state);
  3517. switch (state) { //final message
  3518. case 0: //user dont want to use wizard
  3519. msg = _T(MSG_WIZARD_QUIT);
  3520. break;
  3521. case 1: //printer was already calibrated
  3522. msg = _T(MSG_WIZARD_DONE);
  3523. break;
  3524. case 2: //selftest
  3525. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3526. break;
  3527. case 3: //xyz cal.
  3528. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3529. break;
  3530. case 4: //z cal.
  3531. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3532. break;
  3533. case 8:
  3534. msg = _i("Please load PLA filament and then resume Wizard by rebooting the printer.");////MSG_WIZARD_INSERT_CORRECT_FILAMENT c=20 r=8
  3535. break;
  3536. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3537. case 11: //we are finished
  3538. msg = _T(MSG_WIZARD_DONE);
  3539. lcd_reset_alert_level();
  3540. lcd_setstatuspgm(_T(WELCOME_MSG));
  3541. break;
  3542. default:
  3543. msg = _T(MSG_WIZARD_QUIT);
  3544. break;
  3545. }
  3546. if (state != 9) lcd_show_fullscreen_message_and_wait_P(msg);
  3547. lcd_update_enable(true);
  3548. lcd_return_to_status();
  3549. lcd_update(2);
  3550. }
  3551. static void lcd_settings_menu()
  3552. {
  3553. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3554. START_MENU();
  3555. MENU_ITEM(back, _T(MSG_MAIN), lcd_settings_menu_back);
  3556. MENU_ITEM(submenu, _i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0
  3557. if (!homing_flag)
  3558. {
  3559. MENU_ITEM(submenu, _i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0
  3560. }
  3561. if (!isPrintPaused)
  3562. {
  3563. MENU_ITEM(gcode, _i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0
  3564. }
  3565. #ifndef TMC2130
  3566. if (!farm_mode) { //dont show in menu if we are in farm mode
  3567. switch (SilentModeMenu) {
  3568. case SILENT_MODE_POWER: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  3569. case SILENT_MODE_SILENT: MENU_ITEM(function, _T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  3570. case SILENT_MODE_AUTO: MENU_ITEM(function, _T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  3571. default: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  3572. }
  3573. }
  3574. #endif //TMC2130
  3575. #ifdef PAT9125
  3576. #ifndef DEBUG_DISABLE_FSENSORCHECK
  3577. if (FSensorStateMenu == 0) {
  3578. if (fsensor_not_responding){
  3579. // Filament sensor not working
  3580. MENU_ITEM(function, _i("Fil. sensor [N/A]"), lcd_fsensor_state_set);////MSG_FSENSOR_NA c=0 r=0
  3581. MENU_ITEM(submenu, _T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail);
  3582. }
  3583. else{
  3584. // Filament sensor turned off, working, no problems
  3585. MENU_ITEM(function, _T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  3586. MENU_ITEM(submenu,_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info);
  3587. }
  3588. } else {
  3589. // Filament sensor turned on, working, no problems
  3590. MENU_ITEM(function, _T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  3591. if (filament_autoload_enabled) {
  3592. MENU_ITEM(function, _i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1
  3593. }
  3594. else {
  3595. MENU_ITEM(function, _i("F. autoload [off]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_OFF c=17 r=1
  3596. }
  3597. }
  3598. #endif //DEBUG_DISABLE_FSENSORCHECK
  3599. #endif //PAT9125
  3600. if (fans_check_enabled == true) {
  3601. MENU_ITEM(function, _i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
  3602. }
  3603. else {
  3604. MENU_ITEM(function, _i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1
  3605. }
  3606. #ifdef TMC2130
  3607. if(!farm_mode)
  3608. {
  3609. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM(function, _T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  3610. else MENU_ITEM(function, _T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  3611. if (SilentModeMenu == SILENT_MODE_NORMAL)
  3612. {
  3613. if (CrashDetectMenu == 0) MENU_ITEM(function, _T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  3614. else MENU_ITEM(function, _T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  3615. }
  3616. else MENU_ITEM(submenu, _T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  3617. }
  3618. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3619. 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
  3620. 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
  3621. 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
  3622. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3623. 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
  3624. #endif //TMC2130
  3625. if (temp_cal_active == false) {
  3626. MENU_ITEM(function, _i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1
  3627. }
  3628. else {
  3629. MENU_ITEM(function, _i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1
  3630. }
  3631. #ifdef HAS_SECOND_SERIAL_PORT
  3632. if (selectedSerialPort == 0) {
  3633. MENU_ITEM(function, _i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1
  3634. }
  3635. else {
  3636. MENU_ITEM(function, _i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1
  3637. }
  3638. #endif //HAS_SECOND_SERIAL
  3639. if (!isPrintPaused && !homing_flag)
  3640. {
  3641. MENU_ITEM(submenu, _T(MSG_BABYSTEP_Z), lcd_babystep_z);
  3642. }
  3643. #if (LANG_MODE != 0)
  3644. MENU_ITEM(submenu, _i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0
  3645. #endif //(LANG_MODE != 0)
  3646. if (card.ToshibaFlashAir_isEnabled()) {
  3647. MENU_ITEM(function, _i("SD card [FlshAir]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1
  3648. } else {
  3649. MENU_ITEM(function, _i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1
  3650. }
  3651. #ifdef SDCARD_SORT_ALPHA
  3652. if (!farm_mode) {
  3653. uint8_t sdSort;
  3654. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3655. switch (sdSort) {
  3656. case SD_SORT_TIME: MENU_ITEM(function, _i("Sort: [Time]"), lcd_sort_type_set); break;////MSG_SORT_TIME c=17 r=1
  3657. case SD_SORT_ALPHA: MENU_ITEM(function, _i("Sort: [Alphabet]"), lcd_sort_type_set); break;////MSG_SORT_ALPHA c=17 r=1
  3658. default: MENU_ITEM(function, _i("Sort: [None]"), lcd_sort_type_set);////MSG_SORT_NONE c=17 r=1
  3659. }
  3660. }
  3661. #endif // SDCARD_SORT_ALPHA
  3662. if (farm_mode)
  3663. {
  3664. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  3665. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  3666. }
  3667. END_MENU();
  3668. }
  3669. static void lcd_selftest_()
  3670. {
  3671. lcd_selftest();
  3672. }
  3673. #ifdef TMC2130
  3674. static void lcd_ustep_linearity_menu_save()
  3675. {
  3676. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  3677. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  3678. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  3679. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  3680. }
  3681. #endif //TMC2130
  3682. static void lcd_settings_menu_back()
  3683. {
  3684. #ifdef TMC2130
  3685. bool changed = false;
  3686. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  3687. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  3688. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  3689. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  3690. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  3691. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  3692. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  3693. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  3694. lcd_ustep_linearity_menu_save();
  3695. if (changed) tmc2130_init();
  3696. #endif //TMC2130
  3697. currentMenu = lcd_main_menu;
  3698. lcd_main_menu();
  3699. }
  3700. #ifdef EXPERIMENTAL_FEATURES
  3701. static void lcd_experimantal_menu();
  3702. static void lcd_homing_accuracy_menu();
  3703. static void lcd_accurate_home_set()
  3704. {
  3705. tmc2130_home_enabled = tmc2130_home_enabled?0:1;
  3706. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  3707. }
  3708. static void lcd_homing_accuracy_menu_advanced_reset()
  3709. {
  3710. tmc2130_home_bsteps[X_AXIS] = 48;
  3711. tmc2130_home_fsteps[X_AXIS] = 48;
  3712. tmc2130_home_bsteps[Y_AXIS] = 48;
  3713. tmc2130_home_fsteps[Y_AXIS] = 48;
  3714. }
  3715. static void lcd_homing_accuracy_menu_advanced_save()
  3716. {
  3717. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_ORIGIN, tmc2130_home_origin[X_AXIS]);
  3718. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_BSTEPS, tmc2130_home_bsteps[X_AXIS]);
  3719. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_X_FSTEPS, tmc2130_home_fsteps[X_AXIS]);
  3720. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_ORIGIN, tmc2130_home_origin[Y_AXIS]);
  3721. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_BSTEPS, tmc2130_home_bsteps[Y_AXIS]);
  3722. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_Y_FSTEPS, tmc2130_home_fsteps[Y_AXIS]);
  3723. }
  3724. static void lcd_homing_accuracy_menu_advanced_back()
  3725. {
  3726. lcd_homing_accuracy_menu_advanced_save();
  3727. currentMenu = lcd_homing_accuracy_menu;
  3728. lcd_homing_accuracy_menu();
  3729. }
  3730. static void lcd_homing_accuracy_menu_advanced()
  3731. {
  3732. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3733. START_MENU();
  3734. MENU_ITEM(back, PSTR("Homing accuracy"), lcd_homing_accuracy_menu_advanced_back);
  3735. MENU_ITEM(function, PSTR("Reset def. steps"), lcd_homing_accuracy_menu_advanced_reset);
  3736. MENU_ITEM_EDIT(byte3, PSTR("X-origin"), &tmc2130_home_origin[X_AXIS], 0, 63);
  3737. MENU_ITEM_EDIT(byte3, PSTR("Y-origin"), &tmc2130_home_origin[Y_AXIS], 0, 63);
  3738. MENU_ITEM_EDIT(byte3, PSTR("X-bsteps"), &tmc2130_home_bsteps[X_AXIS], 0, 128);
  3739. MENU_ITEM_EDIT(byte3, PSTR("Y-bsteps"), &tmc2130_home_bsteps[Y_AXIS], 0, 128);
  3740. MENU_ITEM_EDIT(byte3, PSTR("X-fsteps"), &tmc2130_home_fsteps[X_AXIS], 0, 128);
  3741. MENU_ITEM_EDIT(byte3, PSTR("Y-fsteps"), &tmc2130_home_fsteps[Y_AXIS], 0, 128);
  3742. END_MENU();
  3743. }
  3744. static void lcd_homing_accuracy_menu()
  3745. {
  3746. START_MENU();
  3747. MENU_ITEM(back, PSTR("Experimental"), 0);
  3748. MENU_ITEM(function, tmc2130_home_enabled?PSTR("Accur. homing On"):PSTR("Accur. homing Off"), lcd_accurate_home_set);
  3749. MENU_ITEM(gcode, PSTR("Calibrate X"), PSTR("G28XC"));
  3750. MENU_ITEM(gcode, PSTR("Calibrate Y"), PSTR("G28YC"));
  3751. MENU_ITEM(submenu, PSTR("Advanced"), lcd_homing_accuracy_menu_advanced);
  3752. END_MENU();
  3753. }
  3754. static void lcd_ustep_resolution_menu_save()
  3755. {
  3756. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_X_MRES, tmc2130_mres[X_AXIS]);
  3757. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Y_MRES, tmc2130_mres[Y_AXIS]);
  3758. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_Z_MRES, tmc2130_mres[Z_AXIS]);
  3759. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_E_MRES, tmc2130_mres[E_AXIS]);
  3760. }
  3761. static void lcd_ustep_resolution_menu_back()
  3762. {
  3763. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  3764. bool changed = false;
  3765. if (tmc2130_mres[X_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_X_MRES))
  3766. {
  3767. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS] * tmc2130_mres2usteps(tmc2130_mres[X_AXIS]) / TMC2130_USTEPS_XY;
  3768. changed = true;
  3769. }
  3770. if (tmc2130_mres[Y_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Y_MRES))
  3771. {
  3772. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Y_AXIS]) / TMC2130_USTEPS_XY;
  3773. changed = true;
  3774. }
  3775. if (tmc2130_mres[Z_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_Z_MRES))
  3776. {
  3777. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS] * tmc2130_mres2usteps(tmc2130_mres[Z_AXIS]) / TMC2130_USTEPS_Z;
  3778. changed = true;
  3779. }
  3780. if (tmc2130_mres[E_AXIS] != eeprom_read_byte((uint8_t*)EEPROM_TMC2130_E_MRES))
  3781. {
  3782. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS] * tmc2130_mres2usteps(tmc2130_mres[E_AXIS]) / TMC2130_USTEPS_E;
  3783. changed = true;
  3784. }
  3785. if (changed)
  3786. {
  3787. lcd_ustep_resolution_menu_save();
  3788. Config_StoreSettings(EEPROM_OFFSET);
  3789. tmc2130_init();
  3790. }
  3791. currentMenu = lcd_experimantal_menu;
  3792. lcd_experimantal_menu();
  3793. }
  3794. static void lcd_ustep_resolution_reset_def_xyze()
  3795. {
  3796. tmc2130_mres[X_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  3797. tmc2130_mres[Y_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_XY);
  3798. tmc2130_mres[Z_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_Z);
  3799. tmc2130_mres[E_AXIS] = tmc2130_usteps2mres(TMC2130_USTEPS_E);
  3800. float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
  3801. axis_steps_per_unit[X_AXIS] = tmp1[X_AXIS];
  3802. axis_steps_per_unit[Y_AXIS] = tmp1[Y_AXIS];
  3803. axis_steps_per_unit[Z_AXIS] = tmp1[Z_AXIS];
  3804. axis_steps_per_unit[E_AXIS] = tmp1[E_AXIS];
  3805. }
  3806. static void lcd_ustep_resolution_menu()
  3807. {
  3808. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3809. START_MENU();
  3810. MENU_ITEM(back, PSTR("Experimental"), lcd_ustep_resolution_menu_back);
  3811. MENU_ITEM(function, PSTR("Reset defaults"), lcd_ustep_resolution_reset_def_xyze);
  3812. MENU_ITEM_EDIT(mres, PSTR("X-resolution"), &tmc2130_mres[X_AXIS], 4, 4);
  3813. MENU_ITEM_EDIT(mres, PSTR("Y-resolution"), &tmc2130_mres[Y_AXIS], 4, 4);
  3814. MENU_ITEM_EDIT(mres, PSTR("Z-resolution"), &tmc2130_mres[Z_AXIS], 4, 4);
  3815. MENU_ITEM_EDIT(mres, PSTR("E-resolution"), &tmc2130_mres[E_AXIS], 2, 5);
  3816. END_MENU();
  3817. }
  3818. static void lcd_ustep_linearity_menu_back()
  3819. {
  3820. bool changed = false;
  3821. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  3822. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  3823. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  3824. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  3825. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  3826. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  3827. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  3828. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  3829. lcd_ustep_linearity_menu_save();
  3830. if (changed) tmc2130_init();
  3831. currentMenu = lcd_experimantal_menu;
  3832. lcd_experimantal_menu();
  3833. }
  3834. static void lcd_ustep_linearity_menu_recomended()
  3835. {
  3836. tmc2130_wave_fac[X_AXIS] = 220;
  3837. tmc2130_wave_fac[Y_AXIS] = 220;
  3838. tmc2130_wave_fac[Z_AXIS] = 220;
  3839. tmc2130_wave_fac[E_AXIS] = 220;
  3840. }
  3841. static void lcd_ustep_linearity_menu_reset()
  3842. {
  3843. tmc2130_wave_fac[X_AXIS] = 0;
  3844. tmc2130_wave_fac[Y_AXIS] = 0;
  3845. tmc2130_wave_fac[Z_AXIS] = 0;
  3846. tmc2130_wave_fac[E_AXIS] = 0;
  3847. }
  3848. static void lcd_ustep_linearity_menu()
  3849. {
  3850. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3851. START_MENU();
  3852. MENU_ITEM(back, PSTR("Experimental"), lcd_ustep_linearity_menu_back);
  3853. MENU_ITEM(function, PSTR("Reset correction"), lcd_ustep_linearity_menu_reset);
  3854. MENU_ITEM(function, PSTR("Recomended config"), lcd_ustep_linearity_menu_recomended);
  3855. MENU_ITEM_EDIT(wfac, PSTR("X-correction"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3856. MENU_ITEM_EDIT(wfac, PSTR("Y-correction"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3857. MENU_ITEM_EDIT(wfac, PSTR("Z-correction"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3858. MENU_ITEM_EDIT(wfac, PSTR("E-correction"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);
  3859. END_MENU();
  3860. }
  3861. static void lcd_experimantal_menu_save_all()
  3862. {
  3863. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, tmc2130_home_enabled);
  3864. lcd_ustep_resolution_menu_save();
  3865. lcd_ustep_linearity_menu_save();
  3866. Config_StoreSettings(EEPROM_OFFSET);
  3867. }
  3868. static void lcd_experimantal_menu_disable_all()
  3869. {
  3870. tmc2130_home_enabled = 0;
  3871. lcd_ustep_resolution_reset_def_xyze();
  3872. lcd_ustep_linearity_menu_reset();
  3873. lcd_experimantal_menu_save_all();
  3874. tmc2130_init();
  3875. }
  3876. static void lcd_experimantal_menu()
  3877. {
  3878. START_MENU();
  3879. MENU_ITEM(back, _T(MSG_MAIN), 0);
  3880. MENU_ITEM(function, PSTR("All Xfeatures off"), lcd_experimantal_menu_disable_all);
  3881. MENU_ITEM(submenu, PSTR("Homing accuracy"), lcd_homing_accuracy_menu);
  3882. MENU_ITEM(submenu, PSTR("uStep resolution"), lcd_ustep_resolution_menu);
  3883. MENU_ITEM(submenu, PSTR("uStep linearity"), lcd_ustep_linearity_menu);
  3884. END_MENU();
  3885. }
  3886. #endif //EXPERIMENTAL_FEATURES
  3887. static void lcd_calibration_menu()
  3888. {
  3889. START_MENU();
  3890. MENU_ITEM(back, _T(MSG_MAIN), 0);
  3891. if (!isPrintPaused)
  3892. {
  3893. MENU_ITEM(function, _i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  3894. MENU_ITEM(submenu, _i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1
  3895. MENU_ITEM(gcode, _T(MSG_AUTO_HOME), PSTR("G28 W"));
  3896. MENU_ITEM(function, _i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=0 r=0
  3897. #ifdef MK1BP
  3898. // MK1
  3899. // "Calibrate Z"
  3900. MENU_ITEM(gcode, _T(MSG_HOMEYZ), PSTR("G28 Z"));
  3901. #else //MK1BP
  3902. // MK2
  3903. MENU_ITEM(function, _i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=0 r=0
  3904. // "Calibrate Z" with storing the reference values to EEPROM.
  3905. MENU_ITEM(submenu, _T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  3906. #ifndef SNMM
  3907. //MENU_ITEM(function, _i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  3908. #endif
  3909. // "Mesh Bed Leveling"
  3910. MENU_ITEM(submenu, _i("Mesh Bed Leveling"), lcd_mesh_bedleveling);////MSG_MESH_BED_LEVELING c=0 r=0
  3911. #endif //MK1BP
  3912. MENU_ITEM(submenu, _i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=0 r=0
  3913. MENU_ITEM(submenu, _i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  3914. #ifndef TMC2130
  3915. MENU_ITEM(submenu, _i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=17 r=1
  3916. #endif
  3917. #ifndef MK1BP
  3918. MENU_ITEM(gcode, _i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=0 r=0
  3919. #endif //MK1BP
  3920. #ifndef SNMM
  3921. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  3922. #endif
  3923. #ifndef MK1BP
  3924. MENU_ITEM(submenu, _i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  3925. #endif //MK1BP
  3926. }
  3927. END_MENU();
  3928. }
  3929. void bowden_menu() {
  3930. int enc_dif = encoderDiff;
  3931. int cursor_pos = 0;
  3932. lcd_implementation_clear();
  3933. lcd.setCursor(0, 0);
  3934. lcd.print(">");
  3935. for (int i = 0; i < 4; i++) {
  3936. lcd.setCursor(1, i);
  3937. lcd.print("Extruder ");
  3938. lcd.print(i);
  3939. lcd.print(": ");
  3940. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3941. lcd.print(bowden_length[i] - 48);
  3942. }
  3943. enc_dif = encoderDiff;
  3944. while (1) {
  3945. manage_heater();
  3946. manage_inactivity(true);
  3947. if (abs((enc_dif - encoderDiff)) > 2) {
  3948. if (enc_dif > encoderDiff) {
  3949. cursor_pos--;
  3950. }
  3951. if (enc_dif < encoderDiff) {
  3952. cursor_pos++;
  3953. }
  3954. if (cursor_pos > 3) {
  3955. cursor_pos = 3;
  3956. }
  3957. if (cursor_pos < 0) {
  3958. cursor_pos = 0;
  3959. }
  3960. lcd.setCursor(0, 0);
  3961. lcd.print(" ");
  3962. lcd.setCursor(0, 1);
  3963. lcd.print(" ");
  3964. lcd.setCursor(0, 2);
  3965. lcd.print(" ");
  3966. lcd.setCursor(0, 3);
  3967. lcd.print(" ");
  3968. lcd.setCursor(0, cursor_pos);
  3969. lcd.print(">");
  3970. enc_dif = encoderDiff;
  3971. delay(100);
  3972. }
  3973. if (lcd_clicked()) {
  3974. while (lcd_clicked());
  3975. delay(10);
  3976. while (lcd_clicked());
  3977. lcd_implementation_clear();
  3978. while (1) {
  3979. manage_heater();
  3980. manage_inactivity(true);
  3981. lcd.setCursor(1, 1);
  3982. lcd.print("Extruder ");
  3983. lcd.print(cursor_pos);
  3984. lcd.print(": ");
  3985. lcd.setCursor(13, 1);
  3986. lcd.print(bowden_length[cursor_pos] - 48);
  3987. if (abs((enc_dif - encoderDiff)) > 2) {
  3988. if (enc_dif > encoderDiff) {
  3989. bowden_length[cursor_pos]--;
  3990. lcd.setCursor(13, 1);
  3991. lcd.print(bowden_length[cursor_pos] - 48);
  3992. enc_dif = encoderDiff;
  3993. }
  3994. if (enc_dif < encoderDiff) {
  3995. bowden_length[cursor_pos]++;
  3996. lcd.setCursor(13, 1);
  3997. lcd.print(bowden_length[cursor_pos] - 48);
  3998. enc_dif = encoderDiff;
  3999. }
  4000. }
  4001. delay(100);
  4002. if (lcd_clicked()) {
  4003. while (lcd_clicked());
  4004. delay(10);
  4005. while (lcd_clicked());
  4006. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  4007. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  4008. lcd_update_enable(true);
  4009. lcd_implementation_clear();
  4010. enc_dif = encoderDiff;
  4011. lcd.setCursor(0, cursor_pos);
  4012. lcd.print(">");
  4013. for (int i = 0; i < 4; i++) {
  4014. lcd.setCursor(1, i);
  4015. lcd.print("Extruder ");
  4016. lcd.print(i);
  4017. lcd.print(": ");
  4018. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4019. lcd.print(bowden_length[i] - 48);
  4020. }
  4021. break;
  4022. }
  4023. else return;
  4024. }
  4025. }
  4026. }
  4027. }
  4028. }
  4029. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  4030. lcd_implementation_clear();
  4031. lcd_print_at_PGM(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd.print(":");
  4032. lcd.setCursor(0, 1); lcd.print(">");
  4033. lcd_print_at_PGM(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  4034. lcd_print_at_PGM(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  4035. char cursor_pos = 1;
  4036. int enc_dif = 0;
  4037. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4038. while (1) {
  4039. manage_heater();
  4040. manage_inactivity(true);
  4041. if (abs((enc_dif - encoderDiff)) > 4) {
  4042. if ((abs(enc_dif - encoderDiff)) > 1) {
  4043. if (enc_dif > encoderDiff) cursor_pos--;
  4044. if (enc_dif < encoderDiff) cursor_pos++;
  4045. if (cursor_pos > 3) cursor_pos = 3;
  4046. if (cursor_pos < 1) cursor_pos = 1;
  4047. lcd.setCursor(0, 1);
  4048. lcd.print(" ");
  4049. lcd.setCursor(0, 2);
  4050. lcd.print(" ");
  4051. lcd.setCursor(0, 3);
  4052. lcd.print(" ");
  4053. lcd.setCursor(0, cursor_pos);
  4054. lcd.print(">");
  4055. enc_dif = encoderDiff;
  4056. delay(100);
  4057. }
  4058. }
  4059. if (lcd_clicked()) {
  4060. while (lcd_clicked());
  4061. delay(10);
  4062. while (lcd_clicked());
  4063. KEEPALIVE_STATE(IN_HANDLER);
  4064. return(cursor_pos - 1);
  4065. }
  4066. }
  4067. }
  4068. char choose_extruder_menu() {
  4069. int items_no = 4;
  4070. int first = 0;
  4071. int enc_dif = 0;
  4072. char cursor_pos = 1;
  4073. enc_dif = encoderDiff;
  4074. lcd_implementation_clear();
  4075. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4076. lcd.setCursor(0, 1);
  4077. lcd.print(">");
  4078. for (int i = 0; i < 3; i++) {
  4079. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4080. }
  4081. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4082. while (1) {
  4083. for (int i = 0; i < 3; i++) {
  4084. lcd.setCursor(2 + strlen_P(_T(MSG_EXTRUDER)), i+1);
  4085. lcd.print(first + i + 1);
  4086. }
  4087. manage_heater();
  4088. manage_inactivity(true);
  4089. if (abs((enc_dif - encoderDiff)) > 4) {
  4090. if ((abs(enc_dif - encoderDiff)) > 1) {
  4091. if (enc_dif > encoderDiff) {
  4092. cursor_pos--;
  4093. }
  4094. if (enc_dif < encoderDiff) {
  4095. cursor_pos++;
  4096. }
  4097. if (cursor_pos > 3) {
  4098. cursor_pos = 3;
  4099. if (first < items_no - 3) {
  4100. first++;
  4101. lcd_implementation_clear();
  4102. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4103. for (int i = 0; i < 3; i++) {
  4104. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4105. }
  4106. }
  4107. }
  4108. if (cursor_pos < 1) {
  4109. cursor_pos = 1;
  4110. if (first > 0) {
  4111. first--;
  4112. lcd_implementation_clear();
  4113. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4114. for (int i = 0; i < 3; i++) {
  4115. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4116. }
  4117. }
  4118. }
  4119. lcd.setCursor(0, 1);
  4120. lcd.print(" ");
  4121. lcd.setCursor(0, 2);
  4122. lcd.print(" ");
  4123. lcd.setCursor(0, 3);
  4124. lcd.print(" ");
  4125. lcd.setCursor(0, cursor_pos);
  4126. lcd.print(">");
  4127. enc_dif = encoderDiff;
  4128. delay(100);
  4129. }
  4130. }
  4131. if (lcd_clicked()) {
  4132. lcd_update(2);
  4133. while (lcd_clicked());
  4134. delay(10);
  4135. while (lcd_clicked());
  4136. KEEPALIVE_STATE(IN_HANDLER);
  4137. return(cursor_pos + first - 1);
  4138. }
  4139. }
  4140. }
  4141. char reset_menu() {
  4142. #ifdef SNMM
  4143. int items_no = 5;
  4144. #else
  4145. int items_no = 4;
  4146. #endif
  4147. static int first = 0;
  4148. int enc_dif = 0;
  4149. char cursor_pos = 0;
  4150. const char *item [items_no];
  4151. item[0] = "Language";
  4152. item[1] = "Statistics";
  4153. item[2] = "Shipping prep";
  4154. item[3] = "All Data";
  4155. #ifdef SNMM
  4156. item[4] = "Bowden length";
  4157. #endif // SNMM
  4158. enc_dif = encoderDiff;
  4159. lcd_implementation_clear();
  4160. lcd.setCursor(0, 0);
  4161. lcd.print(">");
  4162. while (1) {
  4163. for (int i = 0; i < 4; i++) {
  4164. lcd.setCursor(1, i);
  4165. lcd.print(item[first + i]);
  4166. }
  4167. manage_heater();
  4168. manage_inactivity(true);
  4169. if (abs((enc_dif - encoderDiff)) > 4) {
  4170. if ((abs(enc_dif - encoderDiff)) > 1) {
  4171. if (enc_dif > encoderDiff) {
  4172. cursor_pos--;
  4173. }
  4174. if (enc_dif < encoderDiff) {
  4175. cursor_pos++;
  4176. }
  4177. if (cursor_pos > 3) {
  4178. cursor_pos = 3;
  4179. if (first < items_no - 4) {
  4180. first++;
  4181. lcd_implementation_clear();
  4182. }
  4183. }
  4184. if (cursor_pos < 0) {
  4185. cursor_pos = 0;
  4186. if (first > 0) {
  4187. first--;
  4188. lcd_implementation_clear();
  4189. }
  4190. }
  4191. lcd.setCursor(0, 0);
  4192. lcd.print(" ");
  4193. lcd.setCursor(0, 1);
  4194. lcd.print(" ");
  4195. lcd.setCursor(0, 2);
  4196. lcd.print(" ");
  4197. lcd.setCursor(0, 3);
  4198. lcd.print(" ");
  4199. lcd.setCursor(0, cursor_pos);
  4200. lcd.print(">");
  4201. enc_dif = encoderDiff;
  4202. delay(100);
  4203. }
  4204. }
  4205. if (lcd_clicked()) {
  4206. while (lcd_clicked());
  4207. delay(10);
  4208. while (lcd_clicked());
  4209. return(cursor_pos + first);
  4210. }
  4211. }
  4212. }
  4213. static void lcd_disable_farm_mode() {
  4214. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4215. if (disable) {
  4216. enquecommand_P(PSTR("G99"));
  4217. lcd_return_to_status();
  4218. }
  4219. else {
  4220. lcd_goto_menu(lcd_settings_menu); //doesn't break menuStack
  4221. }
  4222. lcd_update_enable(true);
  4223. lcdDrawUpdate = 2;
  4224. }
  4225. #ifdef SNMM
  4226. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  4227. set_extrude_min_temp(.0);
  4228. current_position[E_AXIS] += shift;
  4229. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  4230. set_extrude_min_temp(EXTRUDE_MINTEMP);
  4231. }
  4232. void change_extr(int extr) { //switches multiplexer for extruders
  4233. st_synchronize();
  4234. delay(100);
  4235. disable_e0();
  4236. disable_e1();
  4237. disable_e2();
  4238. snmm_extruder = extr;
  4239. pinMode(E_MUX0_PIN, OUTPUT);
  4240. pinMode(E_MUX1_PIN, OUTPUT);
  4241. switch (extr) {
  4242. case 1:
  4243. WRITE(E_MUX0_PIN, HIGH);
  4244. WRITE(E_MUX1_PIN, LOW);
  4245. break;
  4246. case 2:
  4247. WRITE(E_MUX0_PIN, LOW);
  4248. WRITE(E_MUX1_PIN, HIGH);
  4249. break;
  4250. case 3:
  4251. WRITE(E_MUX0_PIN, HIGH);
  4252. WRITE(E_MUX1_PIN, HIGH);
  4253. break;
  4254. default:
  4255. WRITE(E_MUX0_PIN, LOW);
  4256. WRITE(E_MUX1_PIN, LOW);
  4257. break;
  4258. }
  4259. delay(100);
  4260. }
  4261. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  4262. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  4263. }
  4264. void display_loading() {
  4265. switch (snmm_extruder) {
  4266. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4267. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4268. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4269. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4270. }
  4271. }
  4272. void extr_adj(int extruder) //loading filament for SNMM
  4273. {
  4274. bool correct;
  4275. max_feedrate[E_AXIS] =80;
  4276. //max_feedrate[E_AXIS] = 50;
  4277. START:
  4278. lcd_implementation_clear();
  4279. lcd.setCursor(0, 0);
  4280. switch (extruder) {
  4281. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4282. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4283. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4284. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4285. }
  4286. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4287. do{
  4288. extr_mov(0.001,1000);
  4289. delay_keep_alive(2);
  4290. } while (!lcd_clicked());
  4291. //delay_keep_alive(500);
  4292. KEEPALIVE_STATE(IN_HANDLER);
  4293. st_synchronize();
  4294. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  4295. //if (!correct) goto START;
  4296. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  4297. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  4298. extr_mov(bowden_length[extruder], 500);
  4299. lcd_implementation_clear();
  4300. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_LOADING_FILAMENT));
  4301. if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd.setCursor(0, 1);
  4302. else lcd.print(" ");
  4303. lcd.print(snmm_extruder + 1);
  4304. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4305. st_synchronize();
  4306. max_feedrate[E_AXIS] = 50;
  4307. lcd_update_enable(true);
  4308. lcd_return_to_status();
  4309. lcdDrawUpdate = 2;
  4310. }
  4311. void extr_unload() { //unloads filament
  4312. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  4313. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  4314. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  4315. if (degHotend0() > EXTRUDE_MINTEMP) {
  4316. lcd_implementation_clear();
  4317. lcd_display_message_fullscreen_P(PSTR(""));
  4318. max_feedrate[E_AXIS] = 50;
  4319. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_UNLOADING_FILAMENT));
  4320. lcd.print(" ");
  4321. lcd.print(snmm_extruder + 1);
  4322. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4323. if (current_position[Z_AXIS] < 15) {
  4324. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  4325. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  4326. }
  4327. current_position[E_AXIS] += 10; //extrusion
  4328. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  4329. st_current_set(2, E_MOTOR_HIGH_CURRENT);
  4330. if (current_temperature[0] < 230) { //PLA & all other filaments
  4331. current_position[E_AXIS] += 5.4;
  4332. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  4333. current_position[E_AXIS] += 3.2;
  4334. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4335. current_position[E_AXIS] += 3;
  4336. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  4337. }
  4338. else { //ABS
  4339. current_position[E_AXIS] += 3.1;
  4340. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  4341. current_position[E_AXIS] += 3.1;
  4342. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  4343. current_position[E_AXIS] += 4;
  4344. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4345. /*current_position[X_AXIS] += 23; //delay
  4346. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  4347. current_position[X_AXIS] -= 23; //delay
  4348. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  4349. delay_keep_alive(4700);
  4350. }
  4351. max_feedrate[E_AXIS] = 80;
  4352. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4353. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4354. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4355. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4356. st_synchronize();
  4357. //st_current_init();
  4358. if (SilentMode != SILENT_MODE_OFF) st_current_set(2, tmp_motor[2]); //set back to normal operation currents
  4359. else st_current_set(2, tmp_motor_loud[2]);
  4360. lcd_update_enable(true);
  4361. lcd_return_to_status();
  4362. max_feedrate[E_AXIS] = 50;
  4363. }
  4364. else {
  4365. lcd_implementation_clear();
  4366. lcd.setCursor(0, 0);
  4367. lcd_printPGM(_T(MSG_ERROR));
  4368. lcd.setCursor(0, 2);
  4369. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4370. delay(2000);
  4371. lcd_implementation_clear();
  4372. }
  4373. lcd_return_to_status();
  4374. }
  4375. //wrapper functions for loading filament
  4376. static void extr_adj_0(){
  4377. change_extr(0);
  4378. extr_adj(0);
  4379. }
  4380. static void extr_adj_1() {
  4381. change_extr(1);
  4382. extr_adj(1);
  4383. }
  4384. static void extr_adj_2() {
  4385. change_extr(2);
  4386. extr_adj(2);
  4387. }
  4388. static void extr_adj_3() {
  4389. change_extr(3);
  4390. extr_adj(3);
  4391. }
  4392. static void load_all() {
  4393. for (int i = 0; i < 4; i++) {
  4394. change_extr(i);
  4395. extr_adj(i);
  4396. }
  4397. }
  4398. //wrapper functions for changing extruders
  4399. static void extr_change_0() {
  4400. change_extr(0);
  4401. lcd_return_to_status();
  4402. }
  4403. static void extr_change_1() {
  4404. change_extr(1);
  4405. lcd_return_to_status();
  4406. }
  4407. static void extr_change_2() {
  4408. change_extr(2);
  4409. lcd_return_to_status();
  4410. }
  4411. static void extr_change_3() {
  4412. change_extr(3);
  4413. lcd_return_to_status();
  4414. }
  4415. //wrapper functions for unloading filament
  4416. void extr_unload_all() {
  4417. if (degHotend0() > EXTRUDE_MINTEMP) {
  4418. for (int i = 0; i < 4; i++) {
  4419. change_extr(i);
  4420. extr_unload();
  4421. }
  4422. }
  4423. else {
  4424. lcd_implementation_clear();
  4425. lcd.setCursor(0, 0);
  4426. lcd_printPGM(_T(MSG_ERROR));
  4427. lcd.setCursor(0, 2);
  4428. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4429. delay(2000);
  4430. lcd_implementation_clear();
  4431. lcd_return_to_status();
  4432. }
  4433. }
  4434. //unloading just used filament (for snmm)
  4435. void extr_unload_used() {
  4436. if (degHotend0() > EXTRUDE_MINTEMP) {
  4437. for (int i = 0; i < 4; i++) {
  4438. if (snmm_filaments_used & (1 << i)) {
  4439. change_extr(i);
  4440. extr_unload();
  4441. }
  4442. }
  4443. snmm_filaments_used = 0;
  4444. }
  4445. else {
  4446. lcd_implementation_clear();
  4447. lcd.setCursor(0, 0);
  4448. lcd_printPGM(_T(MSG_ERROR));
  4449. lcd.setCursor(0, 2);
  4450. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4451. delay(2000);
  4452. lcd_implementation_clear();
  4453. lcd_return_to_status();
  4454. }
  4455. }
  4456. static void extr_unload_0() {
  4457. change_extr(0);
  4458. extr_unload();
  4459. }
  4460. static void extr_unload_1() {
  4461. change_extr(1);
  4462. extr_unload();
  4463. }
  4464. static void extr_unload_2() {
  4465. change_extr(2);
  4466. extr_unload();
  4467. }
  4468. static void extr_unload_3() {
  4469. change_extr(3);
  4470. extr_unload();
  4471. }
  4472. static void fil_load_menu()
  4473. {
  4474. START_MENU();
  4475. MENU_ITEM(back, _T(MSG_MAIN), 0);
  4476. MENU_ITEM(function, _i("Load all"), load_all);////MSG_LOAD_ALL c=0 r=0
  4477. MENU_ITEM(function, _i("Load filament 1"), extr_adj_0);////MSG_LOAD_FILAMENT_1 c=17 r=0
  4478. MENU_ITEM(function, _i("Load filament 2"), extr_adj_1);////MSG_LOAD_FILAMENT_2 c=17 r=0
  4479. MENU_ITEM(function, _i("Load filament 3"), extr_adj_2);////MSG_LOAD_FILAMENT_3 c=17 r=0
  4480. MENU_ITEM(function, _i("Load filament 4"), extr_adj_3);////MSG_LOAD_FILAMENT_4 c=17 r=0
  4481. END_MENU();
  4482. }
  4483. static void fil_unload_menu()
  4484. {
  4485. START_MENU();
  4486. MENU_ITEM(back, _T(MSG_MAIN), 0);
  4487. MENU_ITEM(function, _i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=0 r=0
  4488. MENU_ITEM(function, _i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17 r=0
  4489. MENU_ITEM(function, _i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17 r=0
  4490. MENU_ITEM(function, _i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17 r=0
  4491. MENU_ITEM(function, _i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4492. END_MENU();
  4493. }
  4494. static void change_extr_menu(){
  4495. START_MENU();
  4496. MENU_ITEM(back, _T(MSG_MAIN), 0);
  4497. MENU_ITEM(function, _i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  4498. MENU_ITEM(function, _i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  4499. MENU_ITEM(function, _i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  4500. MENU_ITEM(function, _i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  4501. END_MENU();
  4502. }
  4503. #endif
  4504. static void lcd_farm_no()
  4505. {
  4506. char step = 0;
  4507. int enc_dif = 0;
  4508. int _farmno = farm_no;
  4509. int _ret = 0;
  4510. lcd_implementation_clear();
  4511. lcd.setCursor(0, 0);
  4512. lcd.print("Farm no");
  4513. do
  4514. {
  4515. if (abs((enc_dif - encoderDiff)) > 2) {
  4516. if (enc_dif > encoderDiff) {
  4517. switch (step) {
  4518. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4519. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4520. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4521. default: break;
  4522. }
  4523. }
  4524. if (enc_dif < encoderDiff) {
  4525. switch (step) {
  4526. case(0): if (_farmno < 900) _farmno += 100; break;
  4527. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4528. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4529. default: break;
  4530. }
  4531. }
  4532. enc_dif = 0;
  4533. encoderDiff = 0;
  4534. }
  4535. lcd.setCursor(0, 2);
  4536. if (_farmno < 100) lcd.print("0");
  4537. if (_farmno < 10) lcd.print("0");
  4538. lcd.print(_farmno);
  4539. lcd.print(" ");
  4540. lcd.setCursor(0, 3);
  4541. lcd.print(" ");
  4542. lcd.setCursor(step, 3);
  4543. lcd.print("^");
  4544. delay(100);
  4545. if (lcd_clicked())
  4546. {
  4547. delay(200);
  4548. step++;
  4549. if(step == 3) {
  4550. _ret = 1;
  4551. farm_no = _farmno;
  4552. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4553. prusa_statistics(20);
  4554. lcd_return_to_status();
  4555. }
  4556. }
  4557. manage_heater();
  4558. } while (_ret == 0);
  4559. }
  4560. unsigned char lcd_choose_color() {
  4561. //function returns index of currently chosen item
  4562. //following part can be modified from 2 to 255 items:
  4563. //-----------------------------------------------------
  4564. unsigned char items_no = 2;
  4565. const char *item[items_no];
  4566. item[0] = "Orange";
  4567. item[1] = "Black";
  4568. //-----------------------------------------------------
  4569. unsigned char active_rows;
  4570. static int first = 0;
  4571. int enc_dif = 0;
  4572. unsigned char cursor_pos = 1;
  4573. enc_dif = encoderDiff;
  4574. lcd_implementation_clear();
  4575. lcd.setCursor(0, 1);
  4576. lcd.print(">");
  4577. active_rows = items_no < 3 ? items_no : 3;
  4578. while (1) {
  4579. lcd_print_at_PGM(0, 0, PSTR("Choose color:"));
  4580. for (int i = 0; i < active_rows; i++) {
  4581. lcd.setCursor(1, i+1);
  4582. lcd.print(item[first + i]);
  4583. }
  4584. manage_heater();
  4585. manage_inactivity(true);
  4586. proc_commands();
  4587. if (abs((enc_dif - encoderDiff)) > 12) {
  4588. if (enc_dif > encoderDiff) {
  4589. cursor_pos--;
  4590. }
  4591. if (enc_dif < encoderDiff) {
  4592. cursor_pos++;
  4593. }
  4594. if (cursor_pos > active_rows) {
  4595. cursor_pos = active_rows;
  4596. if (first < items_no - active_rows) {
  4597. first++;
  4598. lcd_implementation_clear();
  4599. }
  4600. }
  4601. if (cursor_pos < 1) {
  4602. cursor_pos = 1;
  4603. if (first > 0) {
  4604. first--;
  4605. lcd_implementation_clear();
  4606. }
  4607. }
  4608. lcd.setCursor(0, 1);
  4609. lcd.print(" ");
  4610. lcd.setCursor(0, 2);
  4611. lcd.print(" ");
  4612. lcd.setCursor(0, 3);
  4613. lcd.print(" ");
  4614. lcd.setCursor(0, cursor_pos);
  4615. lcd.print(">");
  4616. enc_dif = encoderDiff;
  4617. delay(100);
  4618. }
  4619. if (lcd_clicked()) {
  4620. while (lcd_clicked());
  4621. delay(10);
  4622. while (lcd_clicked());
  4623. switch(cursor_pos + first - 1) {
  4624. case 0: return 1; break;
  4625. case 1: return 0; break;
  4626. default: return 99; break;
  4627. }
  4628. }
  4629. }
  4630. }
  4631. void lcd_confirm_print()
  4632. {
  4633. uint8_t filament_type;
  4634. int enc_dif = 0;
  4635. int cursor_pos = 1;
  4636. int _ret = 0;
  4637. int _t = 0;
  4638. enc_dif = encoderDiff;
  4639. lcd_implementation_clear();
  4640. lcd.setCursor(0, 0);
  4641. lcd.print("Print ok ?");
  4642. do
  4643. {
  4644. if (abs(enc_dif - encoderDiff) > 12) {
  4645. if (enc_dif > encoderDiff) {
  4646. cursor_pos--;
  4647. }
  4648. if (enc_dif < encoderDiff) {
  4649. cursor_pos++;
  4650. }
  4651. enc_dif = encoderDiff;
  4652. }
  4653. if (cursor_pos > 2) { cursor_pos = 2; }
  4654. if (cursor_pos < 1) { cursor_pos = 1; }
  4655. lcd.setCursor(0, 2); lcd.print(" ");
  4656. lcd.setCursor(0, 3); lcd.print(" ");
  4657. lcd.setCursor(2, 2);
  4658. lcd_printPGM(_T(MSG_YES));
  4659. lcd.setCursor(2, 3);
  4660. lcd_printPGM(_T(MSG_NO));
  4661. lcd.setCursor(0, 1 + cursor_pos);
  4662. lcd.print(">");
  4663. delay(100);
  4664. _t = _t + 1;
  4665. if (_t>100)
  4666. {
  4667. prusa_statistics(99);
  4668. _t = 0;
  4669. }
  4670. if (lcd_clicked())
  4671. {
  4672. if (cursor_pos == 1)
  4673. {
  4674. _ret = 1;
  4675. filament_type = lcd_choose_color();
  4676. prusa_statistics(4, filament_type);
  4677. no_response = true; //we need confirmation by recieving PRUSA thx
  4678. important_status = 4;
  4679. saved_filament_type = filament_type;
  4680. NcTime = millis();
  4681. }
  4682. if (cursor_pos == 2)
  4683. {
  4684. _ret = 2;
  4685. filament_type = lcd_choose_color();
  4686. prusa_statistics(5, filament_type);
  4687. no_response = true; //we need confirmation by recieving PRUSA thx
  4688. important_status = 5;
  4689. saved_filament_type = filament_type;
  4690. NcTime = millis();
  4691. }
  4692. }
  4693. manage_heater();
  4694. manage_inactivity();
  4695. proc_commands();
  4696. } while (_ret == 0);
  4697. }
  4698. #include "w25x20cl.h"
  4699. static void lcd_test_menu()
  4700. {
  4701. W25X20CL_SPI_ENTER();
  4702. w25x20cl_enable_wr();
  4703. w25x20cl_chip_erase();
  4704. w25x20cl_disable_wr();
  4705. }
  4706. static void lcd_main_menu()
  4707. {
  4708. SDscrool = 0;
  4709. START_MENU();
  4710. // Majkl superawesome menu
  4711. MENU_ITEM(back, _T(MSG_WATCH), 0);
  4712. #ifdef RESUME_DEBUG
  4713. if (!saved_printing)
  4714. MENU_ITEM(function, PSTR("tst - Save"), lcd_menu_test_save);
  4715. else
  4716. MENU_ITEM(function, PSTR("tst - Restore"), lcd_menu_test_restore);
  4717. #endif //RESUME_DEBUG
  4718. #ifdef TMC2130_DEBUG
  4719. MENU_ITEM(function, PSTR("recover print"), recover_print);
  4720. MENU_ITEM(function, PSTR("power panic"), uvlo_);
  4721. #endif //TMC2130_DEBUG
  4722. /* if (farm_mode && !IS_SD_PRINTING )
  4723. {
  4724. int tempScrool = 0;
  4725. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4726. //delay(100);
  4727. return; // nothing to do (so don't thrash the SD card)
  4728. uint16_t fileCnt = card.getnrfilenames();
  4729. card.getWorkDirName();
  4730. if (card.filename[0] == '/')
  4731. {
  4732. #if SDCARDDETECT == -1
  4733. MENU_ITEM(function, _T(MSG_REFRESH), lcd_sd_refresh);
  4734. #endif
  4735. } else {
  4736. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4737. }
  4738. for (uint16_t i = 0; i < fileCnt; i++)
  4739. {
  4740. if (_menuItemNr == _lineNr)
  4741. {
  4742. #ifndef SDCARD_RATHERRECENTFIRST
  4743. card.getfilename(i);
  4744. #else
  4745. card.getfilename(fileCnt - 1 - i);
  4746. #endif
  4747. if (card.filenameIsDir)
  4748. {
  4749. MENU_ITEM(sddirectory, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  4750. } else {
  4751. MENU_ITEM(sdfile, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  4752. }
  4753. } else {
  4754. MENU_ITEM_DUMMY();
  4755. }
  4756. }
  4757. MENU_ITEM(back, PSTR("- - - - - - - - -"), 0);
  4758. }*/
  4759. 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)
  4760. {
  4761. MENU_ITEM(submenu, _T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4762. }
  4763. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4764. {
  4765. MENU_ITEM(submenu, _i("Tune"), lcd_tune_menu);////MSG_TUNE c=0 r=0
  4766. } else
  4767. {
  4768. MENU_ITEM(submenu, _i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=0 r=0
  4769. }
  4770. #ifdef SDSUPPORT
  4771. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4772. {
  4773. if (card.isFileOpen())
  4774. {
  4775. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4776. if (card.sdprinting)
  4777. {
  4778. MENU_ITEM(function, _i("Pause print"), lcd_sdcard_pause);////MSG_PAUSE_PRINT c=0 r=0
  4779. }
  4780. else
  4781. {
  4782. MENU_ITEM(function, _i("Resume print"), lcd_sdcard_resume);////MSG_RESUME_PRINT c=0 r=0
  4783. }
  4784. MENU_ITEM(submenu, _T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4785. }
  4786. }
  4787. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4788. //MENU_ITEM(submenu, _T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4789. }
  4790. else
  4791. {
  4792. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4793. {
  4794. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4795. /*else*/ MENU_ITEM(submenu, _T(MSG_CARD_MENU), lcd_sdcard_menu);
  4796. }
  4797. #if SDCARDDETECT < 1
  4798. MENU_ITEM(gcode, _i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD c=0 r=0
  4799. #endif
  4800. }
  4801. } else
  4802. {
  4803. MENU_ITEM(submenu, _i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=0 r=0
  4804. #if SDCARDDETECT < 1
  4805. MENU_ITEM(gcode, _i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD c=0 r=0
  4806. #endif
  4807. }
  4808. #endif
  4809. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4810. {
  4811. if (farm_mode)
  4812. {
  4813. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  4814. }
  4815. }
  4816. else
  4817. {
  4818. #ifndef SNMM
  4819. #ifdef PAT9125
  4820. if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
  4821. MENU_ITEM(submenu, _i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
  4822. else
  4823. #endif //PAT9125
  4824. MENU_ITEM(function, _T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4825. MENU_ITEM(submenu, _T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4826. #endif
  4827. #ifdef SNMM
  4828. MENU_ITEM(submenu, _T(MSG_LOAD_FILAMENT), fil_load_menu);
  4829. MENU_ITEM(submenu, _T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  4830. MENU_ITEM(submenu, _i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  4831. #endif
  4832. MENU_ITEM(submenu, _T(MSG_SETTINGS), lcd_settings_menu);
  4833. if(!isPrintPaused) MENU_ITEM(submenu, _T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  4834. #ifdef EXPERIMENTAL_FEATURES
  4835. MENU_ITEM(submenu, PSTR("Experimantal"), lcd_experimantal_menu);
  4836. #endif //EXPERIMENTAL_FEATURES
  4837. }
  4838. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4839. {
  4840. MENU_ITEM(submenu, _i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0
  4841. }
  4842. #if defined(TMC2130) || defined(PAT9125)
  4843. MENU_ITEM(submenu, PSTR("Fail stats"), lcd_menu_fails_stats);
  4844. #endif
  4845. MENU_ITEM(submenu, _i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
  4846. MENU_ITEM(submenu, _i("W25x20XL init"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
  4847. END_MENU();
  4848. }
  4849. void stack_error() {
  4850. SET_OUTPUT(BEEPER);
  4851. WRITE(BEEPER, HIGH);
  4852. delay(1000);
  4853. WRITE(BEEPER, LOW);
  4854. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  4855. //err_triggered = 1;
  4856. while (1) delay_keep_alive(1000);
  4857. }
  4858. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4859. bool stepper_timer_overflow_state = false;
  4860. uint16_t stepper_timer_overflow_max = 0;
  4861. uint16_t stepper_timer_overflow_last = 0;
  4862. uint16_t stepper_timer_overflow_cnt = 0;
  4863. void stepper_timer_overflow() {
  4864. char msg[28];
  4865. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  4866. lcd_setstatus(msg);
  4867. stepper_timer_overflow_state = false;
  4868. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  4869. stepper_timer_overflow_max = stepper_timer_overflow_last;
  4870. SERIAL_ECHOPGM("Stepper timer overflow: ");
  4871. MYSERIAL.print(msg);
  4872. SERIAL_ECHOLNPGM("");
  4873. WRITE(BEEPER, LOW);
  4874. }
  4875. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4876. #ifdef SDSUPPORT
  4877. static void lcd_autostart_sd()
  4878. {
  4879. card.lastnr = 0;
  4880. card.setroot();
  4881. card.checkautostart(true);
  4882. }
  4883. #endif
  4884. static void lcd_silent_mode_set_tune() {
  4885. switch (SilentModeMenu) {
  4886. #ifdef TMC2130
  4887. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  4888. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  4889. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  4890. #else
  4891. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  4892. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  4893. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  4894. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  4895. #endif //TMC2130
  4896. }
  4897. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  4898. st_current_init();
  4899. menu_action_back();
  4900. }
  4901. static void lcd_colorprint_change() {
  4902. enquecommand_P(PSTR("M600"));
  4903. custom_message = true;
  4904. custom_message_type = 2; //just print status message
  4905. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4906. lcd_return_to_status();
  4907. lcdDrawUpdate = 3;
  4908. }
  4909. static void lcd_tune_menu()
  4910. {
  4911. if (menuData.tuneMenu.status == 0) {
  4912. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  4913. menuData.tuneMenu.status = 1;
  4914. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4915. } else if (menuData.tuneMenu.extrudemultiply != extrudemultiply) {
  4916. // extrudemultiply has been changed from the child menu. Apply the new value.
  4917. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4918. calculate_extruder_multipliers();
  4919. }
  4920. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4921. START_MENU();
  4922. MENU_ITEM(back, _T(MSG_MAIN), 0); //1
  4923. MENU_ITEM_EDIT(int3, _i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=0 r=0
  4924. MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  4925. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  4926. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  4927. MENU_ITEM_EDIT(int3, _i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=0 r=0
  4928. #ifdef FILAMENTCHANGEENABLE
  4929. MENU_ITEM(function, _T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7
  4930. #endif
  4931. #ifndef DEBUG_DISABLE_FSENSORCHECK
  4932. #ifdef PAT9125
  4933. if (FSensorStateMenu == 0) {
  4934. MENU_ITEM(function, _T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  4935. }
  4936. else {
  4937. MENU_ITEM(function, _T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  4938. }
  4939. #endif //PAT9125
  4940. #endif //DEBUG_DISABLE_FSENSORCHECK
  4941. #ifdef TMC2130
  4942. if(!farm_mode)
  4943. {
  4944. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM(function, _T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  4945. else MENU_ITEM(function, _T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  4946. if (SilentModeMenu == SILENT_MODE_NORMAL)
  4947. {
  4948. if (CrashDetectMenu == 0) MENU_ITEM(function, _T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  4949. else MENU_ITEM(function, _T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  4950. }
  4951. else MENU_ITEM(submenu, _T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  4952. }
  4953. #else //TMC2130
  4954. if (!farm_mode) { //dont show in menu if we are in farm mode
  4955. switch (SilentModeMenu) {
  4956. case SILENT_MODE_POWER: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  4957. case SILENT_MODE_SILENT: MENU_ITEM(function, _T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  4958. case SILENT_MODE_AUTO: MENU_ITEM(function, _T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  4959. default: MENU_ITEM(function, _T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  4960. }
  4961. }
  4962. #endif //TMC2130
  4963. END_MENU();
  4964. }
  4965. static void lcd_move_menu_01mm()
  4966. {
  4967. move_menu_scale = 0.1;
  4968. lcd_move_menu_axis();
  4969. }
  4970. static void lcd_control_temperature_menu()
  4971. {
  4972. #ifdef PIDTEMP
  4973. // set up temp variables - undo the default scaling
  4974. // raw_Ki = unscalePID_i(Ki);
  4975. // raw_Kd = unscalePID_d(Kd);
  4976. #endif
  4977. START_MENU();
  4978. MENU_ITEM(back, _T(MSG_SETTINGS), 0);
  4979. #if TEMP_SENSOR_0 != 0
  4980. MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  4981. #endif
  4982. #if TEMP_SENSOR_1 != 0
  4983. MENU_ITEM_EDIT(int3, _i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1 c=0 r=0
  4984. #endif
  4985. #if TEMP_SENSOR_2 != 0
  4986. MENU_ITEM_EDIT(int3, _i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2 c=0 r=0
  4987. #endif
  4988. #if TEMP_SENSOR_BED != 0
  4989. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  4990. #endif
  4991. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  4992. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  4993. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  4994. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN c=0 r=0
  4995. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX c=0 r=0
  4996. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR c=0 r=0
  4997. #endif
  4998. END_MENU();
  4999. }
  5000. #if SDCARDDETECT == -1
  5001. static void lcd_sd_refresh()
  5002. {
  5003. card.initsd();
  5004. currentMenuViewOffset = 0;
  5005. }
  5006. #endif
  5007. static void lcd_sd_updir()
  5008. {
  5009. SDscrool = 0;
  5010. card.updir();
  5011. currentMenuViewOffset = 0;
  5012. }
  5013. void lcd_print_stop() {
  5014. cancel_heatup = true;
  5015. #ifdef MESH_BED_LEVELING
  5016. mbl.active = false;
  5017. #endif
  5018. // Stop the stoppers, update the position from the stoppers.
  5019. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  5020. planner_abort_hard();
  5021. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  5022. // Z baystep is no more applied. Reset it.
  5023. babystep_reset();
  5024. }
  5025. // Clean the input command queue.
  5026. cmdqueue_reset();
  5027. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  5028. lcd_update(2);
  5029. card.sdprinting = false;
  5030. card.closefile();
  5031. stoptime = millis();
  5032. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5033. pause_time = 0;
  5034. save_statistics(total_filament_used, t);
  5035. lcd_return_to_status();
  5036. lcd_ignore_click(true);
  5037. lcd_commands_step = 0;
  5038. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  5039. // Turn off the print fan
  5040. SET_OUTPUT(FAN_PIN);
  5041. WRITE(FAN_PIN, 0);
  5042. fanSpeed = 0;
  5043. }
  5044. void lcd_sdcard_stop()
  5045. {
  5046. lcd.setCursor(0, 0);
  5047. lcd_printPGM(_T(MSG_STOP_PRINT));
  5048. lcd.setCursor(2, 2);
  5049. lcd_printPGM(_T(MSG_NO));
  5050. lcd.setCursor(2, 3);
  5051. lcd_printPGM(_T(MSG_YES));
  5052. lcd.setCursor(0, 2); lcd.print(" ");
  5053. lcd.setCursor(0, 3); lcd.print(" ");
  5054. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  5055. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  5056. lcd.setCursor(0, 1 + encoderPosition);
  5057. lcd.print(">");
  5058. if (lcd_clicked())
  5059. {
  5060. if ((int32_t)encoderPosition == 1)
  5061. {
  5062. lcd_return_to_status();
  5063. }
  5064. if ((int32_t)encoderPosition == 2)
  5065. {
  5066. lcd_print_stop();
  5067. }
  5068. }
  5069. }
  5070. /*
  5071. void getFileDescription(char *name, char *description) {
  5072. // get file description, ie the REAL filenam, ie the second line
  5073. card.openFile(name, true);
  5074. int i = 0;
  5075. // skip the first line (which is the version line)
  5076. while (true) {
  5077. uint16_t readByte = card.get();
  5078. if (readByte == '\n') {
  5079. break;
  5080. }
  5081. }
  5082. // read the second line (which is the description line)
  5083. while (true) {
  5084. uint16_t readByte = card.get();
  5085. if (i == 0) {
  5086. // skip the first '^'
  5087. readByte = card.get();
  5088. }
  5089. description[i] = readByte;
  5090. i++;
  5091. if (readByte == '\n') {
  5092. break;
  5093. }
  5094. }
  5095. card.closefile();
  5096. description[i-1] = 0;
  5097. }
  5098. */
  5099. void lcd_sdcard_menu()
  5100. {
  5101. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5102. int tempScrool = 0;
  5103. if (presort_flag == true) {
  5104. presort_flag = false;
  5105. card.presort();
  5106. }
  5107. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  5108. //delay(100);
  5109. return; // nothing to do (so don't thrash the SD card)
  5110. uint16_t fileCnt = card.getnrfilenames();
  5111. START_MENU();
  5112. MENU_ITEM(back, _T(MSG_MAIN), 0);
  5113. card.getWorkDirName();
  5114. if (card.filename[0] == '/')
  5115. {
  5116. #if SDCARDDETECT == -1
  5117. MENU_ITEM(function, _T(MSG_REFRESH), lcd_sd_refresh);
  5118. #endif
  5119. } else {
  5120. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5121. }
  5122. for (uint16_t i = 0; i < fileCnt; i++)
  5123. {
  5124. if (_menuItemNr == _lineNr)
  5125. {
  5126. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  5127. /*#ifdef SDCARD_RATHERRECENTFIRST
  5128. #ifndef SDCARD_SORT_ALPHA
  5129. fileCnt - 1 -
  5130. #endif
  5131. #endif
  5132. i;*/
  5133. #ifdef SDCARD_SORT_ALPHA
  5134. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  5135. else card.getfilename_sorted(nr);
  5136. #else
  5137. card.getfilename(nr);
  5138. #endif
  5139. if (card.filenameIsDir)
  5140. MENU_ITEM(sddirectory, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  5141. else
  5142. MENU_ITEM(sdfile, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  5143. } else {
  5144. MENU_ITEM_DUMMY();
  5145. }
  5146. }
  5147. END_MENU();
  5148. }
  5149. //char description [10] [31];
  5150. /*void get_description() {
  5151. uint16_t fileCnt = card.getnrfilenames();
  5152. for (uint16_t i = 0; i < fileCnt; i++)
  5153. {
  5154. card.getfilename(fileCnt - 1 - i);
  5155. getFileDescription(card.filename, description[i]);
  5156. }
  5157. }*/
  5158. /*void lcd_farm_sdcard_menu()
  5159. {
  5160. static int i = 0;
  5161. if (i == 0) {
  5162. get_description();
  5163. i++;
  5164. }
  5165. //int j;
  5166. //char description[31];
  5167. int tempScrool = 0;
  5168. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  5169. //delay(100);
  5170. return; // nothing to do (so don't thrash the SD card)
  5171. uint16_t fileCnt = card.getnrfilenames();
  5172. START_MENU();
  5173. MENU_ITEM(back, _T(MSG_MAIN), 0);
  5174. card.getWorkDirName();
  5175. if (card.filename[0] == '/')
  5176. {
  5177. #if SDCARDDETECT == -1
  5178. MENU_ITEM(function, _T(MSG_REFRESH), lcd_sd_refresh);
  5179. #endif
  5180. }
  5181. else {
  5182. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5183. }
  5184. for (uint16_t i = 0; i < fileCnt; i++)
  5185. {
  5186. if (_menuItemNr == _lineNr)
  5187. {
  5188. #ifndef SDCARD_RATHERRECENTFIRST
  5189. card.getfilename(i);
  5190. #else
  5191. card.getfilename(fileCnt - 1 - i);
  5192. #endif
  5193. if (card.filenameIsDir)
  5194. {
  5195. MENU_ITEM(sddirectory, _T(MSG_CARD_MENU), card.filename, card.longFilename);
  5196. }
  5197. else {
  5198. MENU_ITEM(sdfile, _T(MSG_CARD_MENU), card.filename, description[i]);
  5199. }
  5200. }
  5201. else {
  5202. MENU_ITEM_DUMMY();
  5203. }
  5204. }
  5205. END_MENU();
  5206. }*/
  5207. #define menu_edit_type(_type, _name, _strFunc, scale) \
  5208. void menu_edit_ ## _name () \
  5209. { \
  5210. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  5211. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  5212. if (lcdDrawUpdate) \
  5213. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  5214. if (LCD_CLICKED) \
  5215. { \
  5216. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  5217. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  5218. } \
  5219. } \
  5220. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  5221. { \
  5222. asm("cli"); \
  5223. menuData.editMenuParentState.prevMenu = currentMenu; \
  5224. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  5225. asm("sei"); \
  5226. \
  5227. lcdDrawUpdate = 2; \
  5228. menuData.editMenuParentState.editLabel = pstr; \
  5229. menuData.editMenuParentState.editValue = ptr; \
  5230. menuData.editMenuParentState.minEditValue = minValue * scale; \
  5231. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  5232. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  5233. \
  5234. }\
  5235. /*
  5236. void menu_edit_callback_ ## _name () { \
  5237. menu_edit_ ## _name (); \
  5238. if (LCD_CLICKED) (*callbackFunc)(); \
  5239. } \
  5240. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  5241. { \
  5242. menuData.editMenuParentState.prevMenu = currentMenu; \
  5243. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  5244. \
  5245. lcdDrawUpdate = 2; \
  5246. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  5247. \
  5248. menuData.editMenuParentState.editLabel = pstr; \
  5249. menuData.editMenuParentState.editValue = ptr; \
  5250. menuData.editMenuParentState.minEditValue = minValue * scale; \
  5251. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  5252. callbackFunc = callback;\
  5253. }
  5254. */
  5255. #ifdef TMC2130
  5256. extern char conv[8];
  5257. // Convert tmc2130 mres to string
  5258. char *mres_to_str3(const uint8_t &x)
  5259. {
  5260. return itostr3(256 >> x);
  5261. }
  5262. menu_edit_type(uint8_t, mres, mres_to_str3, 1)
  5263. // Convert tmc2130 wfac to string
  5264. char *wfac_to_str5(const uint8_t &x)
  5265. {
  5266. if (x >= TMC2130_WAVE_FAC1000_MIN)
  5267. {
  5268. conv[0] = '[';
  5269. ftostr43(((float)((uint16_t)x + 1000) / 1000), 1);
  5270. }
  5271. else strncpy_P(conv, _i(" [off"), 6);////MSG_EXTRUDER_CORRECTION_OFF c=6 r=0
  5272. conv[6] = ']';
  5273. conv[7] = ' ';
  5274. conv[8] = 0;
  5275. return conv;
  5276. }
  5277. menu_edit_type(uint8_t, wfac, wfac_to_str5, 1)
  5278. #endif //TMC2130
  5279. menu_edit_type(uint8_t, byte3, itostr3, 1)
  5280. menu_edit_type(int, int3, itostr3, 1)
  5281. menu_edit_type(float, float3, ftostr3, 1)
  5282. menu_edit_type(float, float32, ftostr32, 100)
  5283. menu_edit_type(float, float43, ftostr43, 1000)
  5284. menu_edit_type(float, float5, ftostr5, 0.01)
  5285. menu_edit_type(float, float51, ftostr51, 10)
  5286. menu_edit_type(float, float52, ftostr52, 100)
  5287. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  5288. static void lcd_selftest_v()
  5289. {
  5290. (void)lcd_selftest();
  5291. }
  5292. bool lcd_selftest()
  5293. {
  5294. int _progress = 0;
  5295. bool _result = true;
  5296. lcd_wait_for_cool_down();
  5297. lcd_implementation_clear();
  5298. lcd.setCursor(0, 0); lcd_printPGM(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0
  5299. #ifdef TMC2130
  5300. FORCE_HIGH_POWER_START;
  5301. #endif // TMC2130
  5302. delay(2000);
  5303. KEEPALIVE_STATE(IN_HANDLER);
  5304. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  5305. #if (defined(FANCHECK) && defined(TACH_0))
  5306. _result = lcd_selftest_fan_dialog(0);
  5307. #else //defined(TACH_0)
  5308. _result = lcd_selftest_manual_fan_check(0, false);
  5309. if (!_result)
  5310. {
  5311. const char *_err;
  5312. lcd_selftest_error(7, _err, _err); //extruder fan not spinning
  5313. }
  5314. #endif //defined(TACH_0)
  5315. if (_result)
  5316. {
  5317. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  5318. #if (defined(FANCHECK) && defined(TACH_1))
  5319. _result = lcd_selftest_fan_dialog(1);
  5320. #else //defined(TACH_1)
  5321. _result = lcd_selftest_manual_fan_check(1, false);
  5322. if (!_result)
  5323. {
  5324. const char *_err;
  5325. lcd_selftest_error(6, _err, _err); //print fan not spinning
  5326. }
  5327. #endif //defined(TACH_1)
  5328. }
  5329. if (_result)
  5330. {
  5331. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  5332. #ifndef TMC2130
  5333. _result = lcd_selfcheck_endstops();
  5334. #else
  5335. _result = true;
  5336. #endif
  5337. }
  5338. if (_result)
  5339. {
  5340. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  5341. _result = lcd_selfcheck_check_heater(false);
  5342. }
  5343. if (_result)
  5344. {
  5345. //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
  5346. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  5347. #ifdef TMC2130
  5348. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5349. #else
  5350. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5351. #endif //TMC2130
  5352. }
  5353. if (_result)
  5354. {
  5355. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  5356. #ifndef TMC2130
  5357. _result = lcd_selfcheck_pulleys(X_AXIS);
  5358. #endif
  5359. }
  5360. if (_result)
  5361. {
  5362. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  5363. #ifdef TMC2130
  5364. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5365. #else
  5366. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5367. #endif // TMC2130
  5368. }
  5369. if (_result)
  5370. {
  5371. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  5372. #ifndef TMC2130
  5373. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5374. #endif // TMC2130
  5375. }
  5376. if (_result)
  5377. {
  5378. #ifdef TMC2130
  5379. tmc2130_home_exit();
  5380. enable_endstops(false);
  5381. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  5382. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  5383. #endif
  5384. //homeaxis(X_AXIS);
  5385. //homeaxis(Y_AXIS);
  5386. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5387. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5388. st_synchronize();
  5389. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  5390. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  5391. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  5392. enquecommand_P(PSTR("G28 W"));
  5393. enquecommand_P(PSTR("G1 Z15 F1000"));
  5394. }
  5395. }
  5396. #ifdef TMC2130
  5397. if (_result)
  5398. {
  5399. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5400. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5401. st_synchronize();
  5402. _progress = lcd_selftest_screen(13, 0, 2, true, 0);
  5403. bool bres = tmc2130_home_calibrate(X_AXIS);
  5404. _progress = lcd_selftest_screen(13, 1, 2, true, 0);
  5405. bres &= tmc2130_home_calibrate(Y_AXIS);
  5406. _progress = lcd_selftest_screen(13, 2, 2, true, 0);
  5407. if (bres)
  5408. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5409. _result = bres;
  5410. }
  5411. #endif //TMC2130
  5412. if (_result)
  5413. {
  5414. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  5415. _result = lcd_selfcheck_check_heater(true);
  5416. }
  5417. if (_result)
  5418. {
  5419. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5420. #ifdef PAT9125
  5421. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5422. _result = lcd_selftest_fsensor();
  5423. #endif // PAT9125
  5424. }
  5425. if (_result)
  5426. {
  5427. #ifdef PAT9125
  5428. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5429. #endif // PAT9125
  5430. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5431. }
  5432. else
  5433. {
  5434. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5435. }
  5436. lcd_reset_alert_level();
  5437. enquecommand_P(PSTR("M84"));
  5438. lcd_implementation_clear();
  5439. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5440. if (_result)
  5441. {
  5442. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=0 r=0
  5443. }
  5444. else
  5445. {
  5446. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5447. }
  5448. #ifdef TMC2130
  5449. FORCE_HIGH_POWER_END;
  5450. #endif // TMC2130
  5451. KEEPALIVE_STATE(NOT_BUSY);
  5452. return(_result);
  5453. }
  5454. #ifdef TMC2130
  5455. static void reset_crash_det(char axis) {
  5456. current_position[axis] += 10;
  5457. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5458. st_synchronize();
  5459. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5460. }
  5461. static bool lcd_selfcheck_axis_sg(char axis) {
  5462. // each axis length is measured twice
  5463. float axis_length, current_position_init, current_position_final;
  5464. float measured_axis_length[2];
  5465. float margin = 60;
  5466. float max_error_mm = 5;
  5467. switch (axis) {
  5468. case 0: axis_length = X_MAX_POS; break;
  5469. case 1: axis_length = Y_MAX_POS + 8; break;
  5470. default: axis_length = 210; break;
  5471. }
  5472. tmc2130_sg_stop_on_crash = false;
  5473. tmc2130_home_exit();
  5474. enable_endstops(true);
  5475. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5476. current_position[Z_AXIS] += 17;
  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. tmc2130_home_enter(Z_AXIS_MASK);
  5479. st_synchronize();
  5480. tmc2130_home_exit();
  5481. }
  5482. // first axis length measurement begin
  5483. current_position[axis] -= (axis_length + margin);
  5484. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5485. st_synchronize();
  5486. tmc2130_sg_meassure_start(axis);
  5487. current_position_init = st_get_position_mm(axis);
  5488. current_position[axis] += 2 * 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;
  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. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5495. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5496. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5497. current_position_final = st_get_position_mm(axis);
  5498. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5499. // first measurement end and second measurement begin
  5500. current_position[axis] -= margin;
  5501. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5502. st_synchronize();
  5503. current_position[axis] -= (axis_length + margin);
  5504. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5505. st_synchronize();
  5506. current_position_init = st_get_position_mm(axis);
  5507. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5508. //end of second measurement, now check for possible errors:
  5509. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5510. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5511. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5512. enable_endstops(false);
  5513. const char *_error_1;
  5514. const char *_error_2;
  5515. if (axis == X_AXIS) _error_1 = "X";
  5516. if (axis == Y_AXIS) _error_1 = "Y";
  5517. if (axis == Z_AXIS) _error_1 = "Z";
  5518. lcd_selftest_error(9, _error_1, _error_2);
  5519. current_position[axis] = 0;
  5520. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5521. reset_crash_det(axis);
  5522. return false;
  5523. }
  5524. }
  5525. printf_P(_N("Axis length difference:%.3f\n"), abs(measured_axis_length[0] - measured_axis_length[1]));
  5526. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5527. //loose pulleys
  5528. const char *_error_1;
  5529. const char *_error_2;
  5530. if (axis == X_AXIS) _error_1 = "X";
  5531. if (axis == Y_AXIS) _error_1 = "Y";
  5532. if (axis == Z_AXIS) _error_1 = "Z";
  5533. lcd_selftest_error(8, _error_1, _error_2);
  5534. current_position[axis] = 0;
  5535. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5536. reset_crash_det(axis);
  5537. return false;
  5538. }
  5539. current_position[axis] = 0;
  5540. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5541. reset_crash_det(axis);
  5542. return true;
  5543. }
  5544. #endif //TMC2130
  5545. //#ifndef TMC2130
  5546. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5547. {
  5548. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5549. bool _stepdone = false;
  5550. bool _stepresult = false;
  5551. int _progress = 0;
  5552. int _travel_done = 0;
  5553. int _err_endstop = 0;
  5554. int _lcd_refresh = 0;
  5555. _travel = _travel + (_travel / 10);
  5556. if (_axis == X_AXIS) {
  5557. current_position[Z_AXIS] += 17;
  5558. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5559. }
  5560. do {
  5561. current_position[_axis] = current_position[_axis] - 1;
  5562. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5563. st_synchronize();
  5564. #ifdef TMC2130
  5565. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1))
  5566. #else //TMC2130
  5567. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5568. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5569. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5570. #endif //TMC2130
  5571. {
  5572. if (_axis == 0)
  5573. {
  5574. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5575. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5576. }
  5577. if (_axis == 1)
  5578. {
  5579. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5580. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5581. }
  5582. if (_axis == 2)
  5583. {
  5584. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5585. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5586. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5587. /*disable_x();
  5588. disable_y();
  5589. disable_z();*/
  5590. }
  5591. _stepdone = true;
  5592. }
  5593. if (_lcd_refresh < 6)
  5594. {
  5595. _lcd_refresh++;
  5596. }
  5597. else
  5598. {
  5599. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  5600. _lcd_refresh = 0;
  5601. }
  5602. manage_heater();
  5603. manage_inactivity(true);
  5604. //delay(100);
  5605. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5606. } while (!_stepdone);
  5607. //current_position[_axis] = current_position[_axis] + 15;
  5608. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5609. if (!_stepresult)
  5610. {
  5611. const char *_error_1;
  5612. const char *_error_2;
  5613. if (_axis == X_AXIS) _error_1 = "X";
  5614. if (_axis == Y_AXIS) _error_1 = "Y";
  5615. if (_axis == Z_AXIS) _error_1 = "Z";
  5616. if (_err_endstop == 0) _error_2 = "X";
  5617. if (_err_endstop == 1) _error_2 = "Y";
  5618. if (_err_endstop == 2) _error_2 = "Z";
  5619. if (_travel_done >= _travel)
  5620. {
  5621. lcd_selftest_error(5, _error_1, _error_2);
  5622. }
  5623. else
  5624. {
  5625. lcd_selftest_error(4, _error_1, _error_2);
  5626. }
  5627. }
  5628. return _stepresult;
  5629. }
  5630. #ifndef TMC2130
  5631. static bool lcd_selfcheck_pulleys(int axis)
  5632. {
  5633. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5634. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5635. float current_position_init;
  5636. float move;
  5637. bool endstop_triggered = false;
  5638. int i;
  5639. unsigned long timeout_counter;
  5640. refresh_cmd_timeout();
  5641. manage_inactivity(true);
  5642. if (axis == 0) move = 50; //X_AXIS
  5643. else move = 50; //Y_AXIS
  5644. current_position_init = current_position[axis];
  5645. current_position[axis] += 2;
  5646. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5647. for (i = 0; i < 5; i++) {
  5648. refresh_cmd_timeout();
  5649. current_position[axis] = current_position[axis] + move;
  5650. st_current_set(0, 850); //set motor current higher
  5651. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5652. st_synchronize();
  5653. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5654. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5655. current_position[axis] = current_position[axis] - move;
  5656. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5657. st_synchronize();
  5658. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5659. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5660. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5661. return(false);
  5662. }
  5663. }
  5664. timeout_counter = millis() + 2500;
  5665. endstop_triggered = false;
  5666. manage_inactivity(true);
  5667. while (!endstop_triggered) {
  5668. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5669. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5670. endstop_triggered = true;
  5671. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5672. current_position[axis] += (axis == X_AXIS) ? 13 : 9;
  5673. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5674. st_synchronize();
  5675. return(true);
  5676. }
  5677. else {
  5678. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5679. return(false);
  5680. }
  5681. }
  5682. else {
  5683. current_position[axis] -= 1;
  5684. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5685. st_synchronize();
  5686. if (millis() > timeout_counter) {
  5687. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5688. return(false);
  5689. }
  5690. }
  5691. }
  5692. return(true);
  5693. }
  5694. #endif //TMC2130
  5695. static bool lcd_selfcheck_endstops()
  5696. {
  5697. bool _result = true;
  5698. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5699. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5700. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5701. {
  5702. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5703. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5704. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5705. }
  5706. 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);
  5707. delay(500);
  5708. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5709. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5710. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5711. {
  5712. _result = false;
  5713. char _error[4] = "";
  5714. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5715. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5716. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5717. lcd_selftest_error(3, _error, "");
  5718. }
  5719. manage_heater();
  5720. manage_inactivity(true);
  5721. return _result;
  5722. }
  5723. //#endif //not defined TMC2130
  5724. static bool lcd_selfcheck_check_heater(bool _isbed)
  5725. {
  5726. int _counter = 0;
  5727. int _progress = 0;
  5728. bool _stepresult = false;
  5729. bool _docycle = true;
  5730. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5731. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5732. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5733. target_temperature[0] = (_isbed) ? 0 : 200;
  5734. target_temperature_bed = (_isbed) ? 100 : 0;
  5735. manage_heater();
  5736. manage_inactivity(true);
  5737. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5738. do {
  5739. _counter++;
  5740. _docycle = (_counter < _cycles) ? true : false;
  5741. manage_heater();
  5742. manage_inactivity(true);
  5743. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5744. /*if (_isbed) {
  5745. MYSERIAL.print("Bed temp:");
  5746. MYSERIAL.println(degBed());
  5747. }
  5748. else {
  5749. MYSERIAL.print("Hotend temp:");
  5750. MYSERIAL.println(degHotend(0));
  5751. }*/
  5752. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5753. } while (_docycle);
  5754. target_temperature[0] = 0;
  5755. target_temperature_bed = 0;
  5756. manage_heater();
  5757. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5758. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5759. /*
  5760. MYSERIAL.println("");
  5761. MYSERIAL.print("Checked result:");
  5762. MYSERIAL.println(_checked_result);
  5763. MYSERIAL.print("Opposite result:");
  5764. MYSERIAL.println(_opposite_result);
  5765. */
  5766. if (_opposite_result < ((_isbed) ? 10 : 3))
  5767. {
  5768. if (_checked_result >= ((_isbed) ? 3 : 10))
  5769. {
  5770. _stepresult = true;
  5771. }
  5772. else
  5773. {
  5774. lcd_selftest_error(1, "", "");
  5775. }
  5776. }
  5777. else
  5778. {
  5779. lcd_selftest_error(2, "", "");
  5780. }
  5781. manage_heater();
  5782. manage_inactivity(true);
  5783. KEEPALIVE_STATE(IN_HANDLER);
  5784. return _stepresult;
  5785. }
  5786. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5787. {
  5788. lcd_implementation_quick_feedback();
  5789. target_temperature[0] = 0;
  5790. target_temperature_bed = 0;
  5791. manage_heater();
  5792. manage_inactivity();
  5793. lcd_implementation_clear();
  5794. lcd.setCursor(0, 0);
  5795. lcd_printPGM(_i("Selftest error !"));////MSG_SELFTEST_ERROR c=0 r=0
  5796. lcd.setCursor(0, 1);
  5797. lcd_printPGM(_i("Please check :"));////MSG_SELFTEST_PLEASECHECK c=0 r=0
  5798. switch (_error_no)
  5799. {
  5800. case 1:
  5801. lcd.setCursor(0, 2);
  5802. lcd_printPGM(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=0 r=0
  5803. lcd.setCursor(0, 3);
  5804. lcd_printPGM(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=0 r=0
  5805. break;
  5806. case 2:
  5807. lcd.setCursor(0, 2);
  5808. lcd_printPGM(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER c=0 r=0
  5809. lcd.setCursor(0, 3);
  5810. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5811. break;
  5812. case 3:
  5813. lcd.setCursor(0, 2);
  5814. lcd_printPGM(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=0 r=0
  5815. lcd.setCursor(0, 3);
  5816. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5817. lcd.setCursor(17, 3);
  5818. lcd.print(_error_1);
  5819. break;
  5820. case 4:
  5821. lcd.setCursor(0, 2);
  5822. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  5823. lcd.setCursor(18, 2);
  5824. lcd.print(_error_1);
  5825. lcd.setCursor(0, 3);
  5826. lcd_printPGM(_i("Endstop"));////MSG_SELFTEST_ENDSTOP c=0 r=0
  5827. lcd.setCursor(18, 3);
  5828. lcd.print(_error_2);
  5829. break;
  5830. case 5:
  5831. lcd.setCursor(0, 2);
  5832. lcd_printPGM(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1
  5833. lcd.setCursor(0, 3);
  5834. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  5835. lcd.setCursor(18, 3);
  5836. lcd.print(_error_1);
  5837. break;
  5838. case 6:
  5839. lcd.setCursor(0, 2);
  5840. lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  5841. lcd.setCursor(0, 3);
  5842. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5843. lcd.setCursor(18, 3);
  5844. lcd.print(_error_1);
  5845. break;
  5846. case 7:
  5847. lcd.setCursor(0, 2);
  5848. lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5849. lcd.setCursor(0, 3);
  5850. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5851. lcd.setCursor(18, 3);
  5852. lcd.print(_error_1);
  5853. break;
  5854. case 8:
  5855. lcd.setCursor(0, 2);
  5856. lcd_printPGM(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1
  5857. lcd.setCursor(0, 3);
  5858. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  5859. lcd.setCursor(18, 3);
  5860. lcd.print(_error_1);
  5861. break;
  5862. case 9:
  5863. lcd.setCursor(0, 2);
  5864. lcd_printPGM(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=0 r=0
  5865. lcd.setCursor(0, 3);
  5866. lcd_printPGM(_i("Axis"));////MSG_SELFTEST_AXIS c=0 r=0
  5867. lcd.setCursor(18, 3);
  5868. lcd.print(_error_1);
  5869. break;
  5870. case 10:
  5871. lcd.setCursor(0, 2);
  5872. lcd_printPGM(_i("Front/left fans"));////MSG_SELFTEST_FANS c=0 r=0
  5873. lcd.setCursor(0, 3);
  5874. lcd_printPGM(_i("Swapped"));////MSG_SELFTEST_SWAPPED c=0 r=0
  5875. lcd.setCursor(18, 3);
  5876. lcd.print(_error_1);
  5877. break;
  5878. case 11:
  5879. lcd.setCursor(0, 2);
  5880. lcd_printPGM(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0
  5881. lcd.setCursor(0, 3);
  5882. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5883. break;
  5884. }
  5885. delay(1000);
  5886. lcd_implementation_quick_feedback();
  5887. do {
  5888. delay(100);
  5889. manage_heater();
  5890. manage_inactivity();
  5891. } while (!lcd_clicked());
  5892. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5893. lcd_return_to_status();
  5894. }
  5895. #ifdef PAT9125
  5896. static bool lcd_selftest_fsensor() {
  5897. fsensor_init();
  5898. if (fsensor_not_responding)
  5899. {
  5900. const char *_err;
  5901. lcd_selftest_error(11, _err, _err);
  5902. }
  5903. return(!fsensor_not_responding);
  5904. }
  5905. #endif //PAT9125
  5906. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5907. {
  5908. bool _result = check_opposite;
  5909. lcd_implementation_clear();
  5910. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_SELFTEST_FAN));
  5911. switch (_fan)
  5912. {
  5913. case 0:
  5914. // extruder cooling fan
  5915. lcd.setCursor(0, 1);
  5916. if(check_opposite == true) lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  5917. else lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5918. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5919. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5920. break;
  5921. case 1:
  5922. // object cooling fan
  5923. lcd.setCursor(0, 1);
  5924. if (check_opposite == true) lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5925. else lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  5926. SET_OUTPUT(FAN_PIN);
  5927. analogWrite(FAN_PIN, 255);
  5928. break;
  5929. }
  5930. delay(500);
  5931. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  5932. lcd.setCursor(0, 3); lcd.print(">");
  5933. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  5934. int8_t enc_dif = 0;
  5935. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5936. button_pressed = false;
  5937. do
  5938. {
  5939. switch (_fan)
  5940. {
  5941. case 0:
  5942. // extruder cooling fan
  5943. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5944. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5945. break;
  5946. case 1:
  5947. // object cooling fan
  5948. SET_OUTPUT(FAN_PIN);
  5949. analogWrite(FAN_PIN, 255);
  5950. break;
  5951. }
  5952. if (abs((enc_dif - encoderDiff)) > 2) {
  5953. if (enc_dif > encoderDiff) {
  5954. _result = !check_opposite;
  5955. lcd.setCursor(0, 2); lcd.print(">");
  5956. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  5957. lcd.setCursor(0, 3); lcd.print(" ");
  5958. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  5959. }
  5960. if (enc_dif < encoderDiff) {
  5961. _result = check_opposite;
  5962. lcd.setCursor(0, 2); lcd.print(" ");
  5963. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  5964. lcd.setCursor(0, 3); lcd.print(">");
  5965. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  5966. }
  5967. enc_dif = 0;
  5968. encoderDiff = 0;
  5969. }
  5970. manage_heater();
  5971. delay(100);
  5972. } while (!lcd_clicked());
  5973. KEEPALIVE_STATE(IN_HANDLER);
  5974. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5975. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5976. SET_OUTPUT(FAN_PIN);
  5977. analogWrite(FAN_PIN, 0);
  5978. fanSpeed = 0;
  5979. manage_heater();
  5980. return _result;
  5981. }
  5982. static bool lcd_selftest_fan_dialog(int _fan)
  5983. {
  5984. bool _result = true;
  5985. int _errno = 7;
  5986. switch (_fan) {
  5987. case 0:
  5988. fanSpeed = 0;
  5989. manage_heater(); //turn off fan
  5990. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5991. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5992. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5993. if (!fan_speed[0]) _result = false;
  5994. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5995. //MYSERIAL.println(fan_speed[0]);
  5996. //SERIAL_ECHOPGM("Print fan speed: ");
  5997. //MYSERIAL.print(fan_speed[1]);
  5998. break;
  5999. case 1:
  6000. //will it work with Thotend > 50 C ?
  6001. fanSpeed = 150; //print fan
  6002. for (uint8_t i = 0; i < 5; i++) {
  6003. delay_keep_alive(1000);
  6004. lcd.setCursor(18, 3);
  6005. lcd.print("-");
  6006. delay_keep_alive(1000);
  6007. lcd.setCursor(18, 3);
  6008. lcd.print("|");
  6009. }
  6010. fanSpeed = 0;
  6011. manage_heater(); //turn off fan
  6012. manage_inactivity(true); //to turn off print fan
  6013. if (!fan_speed[1]) {
  6014. _result = false; _errno = 6; //print fan not spinning
  6015. }
  6016. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  6017. //check fans manually
  6018. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  6019. if (_result) {
  6020. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  6021. if (!_result) _errno = 6; //print fan not spinning
  6022. }
  6023. else {
  6024. _errno = 10; //swapped fans
  6025. }
  6026. }
  6027. //SERIAL_ECHOPGM("Extruder fan speed: ");
  6028. //MYSERIAL.println(fan_speed[0]);
  6029. //SERIAL_ECHOPGM("Print fan speed: ");
  6030. //MYSERIAL.println(fan_speed[1]);
  6031. break;
  6032. }
  6033. if (!_result)
  6034. {
  6035. const char *_err;
  6036. lcd_selftest_error(_errno, _err, _err);
  6037. }
  6038. return _result;
  6039. }
  6040. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  6041. {
  6042. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  6043. int _step_block = 0;
  6044. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  6045. if (_clear) lcd_implementation_clear();
  6046. lcd.setCursor(0, 0);
  6047. if (_step == -1) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6048. if (_step == 0) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6049. if (_step == 1) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6050. if (_step == 2) lcd_printPGM(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0
  6051. if (_step == 3) lcd_printPGM(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0
  6052. if (_step == 4) lcd_printPGM(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0
  6053. if (_step == 5) lcd_printPGM(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0
  6054. if (_step == 6) lcd_printPGM(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0
  6055. if (_step == 7) lcd_printPGM(_T(MSG_SELFTEST_CHECK_BED));
  6056. if (_step == 8) lcd_printPGM(_T(MSG_SELFTEST_CHECK_BED));
  6057. if (_step == 9) lcd_printPGM(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6058. if (_step == 10) lcd_printPGM(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6059. if (_step == 11) lcd_printPGM(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0
  6060. if (_step == 12) lcd_printPGM(_T(MSG_SELFTEST_FAILED));
  6061. if (_step == 13) lcd_printPGM(PSTR("Calibrating home"));
  6062. lcd.setCursor(0, 1);
  6063. lcd_printPGM(separator);
  6064. if ((_step >= -1) && (_step <= 1))
  6065. {
  6066. //SERIAL_ECHOLNPGM("Fan test");
  6067. lcd_print_at_PGM(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 r=0
  6068. lcd.setCursor(18, 2);
  6069. (_step < 0) ? lcd.print(_indicator) : lcd.print("OK");
  6070. lcd_print_at_PGM(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 r=0
  6071. lcd.setCursor(18, 3);
  6072. (_step < 1) ? lcd.print(_indicator) : lcd.print("OK");
  6073. }
  6074. else if (_step >= 9 && _step <= 10)
  6075. {
  6076. lcd_print_at_PGM(0, 2, _i("Filament sensor:"));////MSG_SELFTEST_FILAMENT_SENSOR c=18 r=0
  6077. lcd.setCursor(18, 2);
  6078. (_step == 9) ? lcd.print(_indicator) : lcd.print("OK");
  6079. }
  6080. else if (_step < 9)
  6081. {
  6082. //SERIAL_ECHOLNPGM("Other tests");
  6083. _step_block = 3;
  6084. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  6085. _step_block = 4;
  6086. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  6087. _step_block = 5;
  6088. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  6089. _step_block = 6;
  6090. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  6091. _step_block = 7;
  6092. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  6093. }
  6094. if (_delay > 0) delay_keep_alive(_delay);
  6095. _progress++;
  6096. return (_progress > _progress_scale * 2) ? 0 : _progress;
  6097. }
  6098. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  6099. {
  6100. lcd.setCursor(_col, _row);
  6101. switch (_state)
  6102. {
  6103. case 1:
  6104. lcd.print(_name);
  6105. lcd.setCursor(_col + strlen(_name), _row);
  6106. lcd.print(":");
  6107. lcd.setCursor(_col + strlen(_name) + 1, _row);
  6108. lcd.print(_indicator);
  6109. break;
  6110. case 2:
  6111. lcd.print(_name);
  6112. lcd.setCursor(_col + strlen(_name), _row);
  6113. lcd.print(":");
  6114. lcd.setCursor(_col + strlen(_name) + 1, _row);
  6115. lcd.print("OK");
  6116. break;
  6117. default:
  6118. lcd.print(_name);
  6119. }
  6120. }
  6121. /** End of menus **/
  6122. static void lcd_quick_feedback()
  6123. {
  6124. lcdDrawUpdate = 2;
  6125. button_pressed = false;
  6126. lcd_implementation_quick_feedback();
  6127. }
  6128. /** Menu action functions **/
  6129. /**
  6130. * @brief Go up in menu structure
  6131. * @param data one time action to be done before leaving menu e.g. saving data or 0
  6132. */
  6133. static void menu_action_back(menuFunc_t data)
  6134. {
  6135. if (data) data();
  6136. MenuStack::Record record = menuStack.pop();
  6137. lcd_goto_menu(record.menu);
  6138. encoderPosition = record.position;
  6139. }
  6140. /**
  6141. * @brief Go deeper into menu structure
  6142. * @param data nested menu
  6143. */
  6144. static void menu_action_submenu(menuFunc_t data) {
  6145. menuStack.push(currentMenu, encoderPosition);
  6146. lcd_goto_menu(data);
  6147. }
  6148. static void menu_action_gcode(const char* pgcode) {
  6149. enquecommand_P(pgcode);
  6150. }
  6151. static void menu_action_setlang(unsigned char lang)
  6152. {
  6153. if (!lang_select(lang))
  6154. {
  6155. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language from XFLASH?"), false, true))
  6156. lang_boot_update_start(lang);
  6157. lcd_update_enable(true);
  6158. lcd_implementation_clear();
  6159. lcd_goto_menu(lcd_language_menu);
  6160. lcd_timeoutToStatus = -1; //infinite timeout
  6161. lcdDrawUpdate = 2;
  6162. }
  6163. }
  6164. static void menu_action_function(menuFunc_t data) {
  6165. (*data)();
  6166. }
  6167. static bool check_file(const char* filename) {
  6168. if (farm_mode) return true;
  6169. bool result = false;
  6170. uint32_t filesize;
  6171. card.openFile((char*)filename, true);
  6172. filesize = card.getFileSize();
  6173. if (filesize > END_FILE_SECTION) {
  6174. card.setIndex(filesize - END_FILE_SECTION);
  6175. }
  6176. while (!card.eof() && !result) {
  6177. card.sdprinting = true;
  6178. get_command();
  6179. result = check_commands();
  6180. }
  6181. card.printingHasFinished();
  6182. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  6183. lcd_finishstatus();
  6184. return result;
  6185. }
  6186. static void menu_action_sdfile(const char* filename, char* longFilename)
  6187. {
  6188. loading_flag = false;
  6189. char cmd[30];
  6190. char* c;
  6191. bool result = true;
  6192. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6193. for (c = &cmd[4]; *c; c++)
  6194. *c = tolower(*c);
  6195. const char end[5] = ".gco";
  6196. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6197. for (int i = 0; i < 8; i++) {
  6198. if (strcmp((cmd + i + 4), end) == 0) {
  6199. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6200. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6201. break;
  6202. }
  6203. else {
  6204. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6205. }
  6206. }
  6207. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6208. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6209. for (uint8_t i = 0; i < depth; i++) {
  6210. for (int j = 0; j < 8; j++) {
  6211. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  6212. }
  6213. }
  6214. if (!check_file(filename)) {
  6215. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=2
  6216. lcd_update_enable(true);
  6217. }
  6218. if (result) {
  6219. enquecommand(cmd);
  6220. enquecommand_P(PSTR("M24"));
  6221. }
  6222. lcd_return_to_status();
  6223. }
  6224. static void menu_action_sddirectory(const char* filename, char* longFilename)
  6225. {
  6226. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6227. strcpy(dir_names[depth], filename);
  6228. MYSERIAL.println(dir_names[depth]);
  6229. card.chdir(filename);
  6230. encoderPosition = 0;
  6231. }
  6232. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  6233. {
  6234. *ptr = !(*ptr);
  6235. }
  6236. /*
  6237. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  6238. {
  6239. menu_action_setting_edit_bool(pstr, ptr);
  6240. (*callback)();
  6241. }
  6242. */
  6243. #endif//ULTIPANEL
  6244. /** LCD API **/
  6245. void lcd_init()
  6246. {
  6247. lcd_implementation_init();
  6248. #ifdef NEWPANEL
  6249. SET_INPUT(BTN_EN1);
  6250. SET_INPUT(BTN_EN2);
  6251. WRITE(BTN_EN1, HIGH);
  6252. WRITE(BTN_EN2, HIGH);
  6253. #if BTN_ENC > 0
  6254. SET_INPUT(BTN_ENC);
  6255. WRITE(BTN_ENC, HIGH);
  6256. #endif
  6257. #ifdef REPRAPWORLD_KEYPAD
  6258. pinMode(SHIFT_CLK, OUTPUT);
  6259. pinMode(SHIFT_LD, OUTPUT);
  6260. pinMode(SHIFT_OUT, INPUT);
  6261. WRITE(SHIFT_OUT, HIGH);
  6262. WRITE(SHIFT_LD, HIGH);
  6263. #endif
  6264. #else // Not NEWPANEL
  6265. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  6266. pinMode (SR_DATA_PIN, OUTPUT);
  6267. pinMode (SR_CLK_PIN, OUTPUT);
  6268. #elif defined(SHIFT_CLK)
  6269. pinMode(SHIFT_CLK, OUTPUT);
  6270. pinMode(SHIFT_LD, OUTPUT);
  6271. pinMode(SHIFT_EN, OUTPUT);
  6272. pinMode(SHIFT_OUT, INPUT);
  6273. WRITE(SHIFT_OUT, HIGH);
  6274. WRITE(SHIFT_LD, HIGH);
  6275. WRITE(SHIFT_EN, LOW);
  6276. #else
  6277. #ifdef ULTIPANEL
  6278. #error ULTIPANEL requires an encoder
  6279. #endif
  6280. #endif // SR_LCD_2W_NL
  6281. #endif//!NEWPANEL
  6282. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6283. pinMode(SDCARDDETECT, INPUT);
  6284. WRITE(SDCARDDETECT, HIGH);
  6285. lcd_oldcardstatus = IS_SD_INSERTED;
  6286. #endif//(SDCARDDETECT > 0)
  6287. #ifdef LCD_HAS_SLOW_BUTTONS
  6288. slow_buttons = 0;
  6289. #endif
  6290. lcd_buttons_update();
  6291. #ifdef ULTIPANEL
  6292. encoderDiff = 0;
  6293. #endif
  6294. }
  6295. //#include <avr/pgmspace.h>
  6296. static volatile bool lcd_update_enabled = true;
  6297. unsigned long lcd_timeoutToStatus = 0;
  6298. void lcd_update_enable(bool enabled)
  6299. {
  6300. if (lcd_update_enabled != enabled) {
  6301. lcd_update_enabled = enabled;
  6302. if (enabled) {
  6303. // Reset encoder position. This is equivalent to re-entering a menu.
  6304. encoderPosition = 0;
  6305. encoderDiff = 0;
  6306. // Enabling the normal LCD update procedure.
  6307. // Reset the timeout interval.
  6308. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6309. // Force the keypad update now.
  6310. lcd_next_update_millis = millis() - 1;
  6311. // Full update.
  6312. lcd_implementation_clear();
  6313. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6314. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  6315. #else
  6316. if (currentMenu == lcd_status_screen)
  6317. lcd_set_custom_characters_degree();
  6318. else
  6319. lcd_set_custom_characters_arrows();
  6320. #endif
  6321. lcd_update(2);
  6322. } else {
  6323. // Clear the LCD always, or let it to the caller?
  6324. }
  6325. }
  6326. }
  6327. void lcd_update(uint8_t lcdDrawUpdateOverride)
  6328. {
  6329. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  6330. lcdDrawUpdate = lcdDrawUpdateOverride;
  6331. if (!lcd_update_enabled)
  6332. return;
  6333. #ifdef LCD_HAS_SLOW_BUTTONS
  6334. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  6335. #endif
  6336. lcd_buttons_update();
  6337. #if (SDCARDDETECT > 0)
  6338. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  6339. {
  6340. lcdDrawUpdate = 2;
  6341. lcd_oldcardstatus = IS_SD_INSERTED;
  6342. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  6343. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6344. currentMenu == lcd_status_screen
  6345. #endif
  6346. );
  6347. if (lcd_oldcardstatus)
  6348. {
  6349. card.initsd();
  6350. LCD_MESSAGERPGM(_i("Card inserted"));////MSG_SD_INSERTED c=0 r=0
  6351. //get_description();
  6352. }
  6353. else
  6354. {
  6355. card.release();
  6356. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=0 r=0
  6357. }
  6358. }
  6359. #endif//CARDINSERTED
  6360. if (lcd_next_update_millis < millis())
  6361. {
  6362. #ifdef DEBUG_BLINK_ACTIVE
  6363. static bool active_led = false;
  6364. active_led = !active_led;
  6365. pinMode(LED_PIN, OUTPUT);
  6366. digitalWrite(LED_PIN, active_led?HIGH:LOW);
  6367. #endif //DEBUG_BLINK_ACTIVE
  6368. #ifdef ULTIPANEL
  6369. #ifdef REPRAPWORLD_KEYPAD
  6370. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  6371. reprapworld_keypad_move_z_up();
  6372. }
  6373. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  6374. reprapworld_keypad_move_z_down();
  6375. }
  6376. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  6377. reprapworld_keypad_move_x_left();
  6378. }
  6379. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  6380. reprapworld_keypad_move_x_right();
  6381. }
  6382. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  6383. reprapworld_keypad_move_y_down();
  6384. }
  6385. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  6386. reprapworld_keypad_move_y_up();
  6387. }
  6388. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  6389. reprapworld_keypad_move_home();
  6390. }
  6391. #endif
  6392. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  6393. {
  6394. if (lcdDrawUpdate == 0)
  6395. lcdDrawUpdate = 1;
  6396. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  6397. encoderDiff = 0;
  6398. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6399. }
  6400. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6401. #endif//ULTIPANEL
  6402. (*currentMenu)();
  6403. #ifdef LCD_HAS_STATUS_INDICATORS
  6404. lcd_implementation_update_indicators();
  6405. #endif
  6406. #ifdef ULTIPANEL
  6407. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  6408. {
  6409. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  6410. // to give it a chance to save its state.
  6411. // This is useful for example, when the babystep value has to be written into EEPROM.
  6412. if (currentMenu != NULL) {
  6413. menuExiting = true;
  6414. (*currentMenu)();
  6415. menuExiting = false;
  6416. }
  6417. lcd_implementation_clear();
  6418. lcd_return_to_status();
  6419. lcdDrawUpdate = 2;
  6420. }
  6421. #endif//ULTIPANEL
  6422. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  6423. if (lcdDrawUpdate) lcdDrawUpdate--;
  6424. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  6425. }
  6426. if (!SdFatUtil::test_stack_integrity()) stack_error();
  6427. #ifdef DEBUG_STEPPER_TIMER_MISSED
  6428. if (stepper_timer_overflow_state) stepper_timer_overflow();
  6429. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  6430. lcd_ping(); //check that we have received ping command if we are in farm mode
  6431. lcd_send_status();
  6432. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6433. }
  6434. void lcd_printer_connected() {
  6435. printer_connected = true;
  6436. }
  6437. static void lcd_send_status() {
  6438. if (farm_mode && no_response && ((millis() - NcTime) > (NC_TIME * 1000))) {
  6439. //send important status messages periodicaly
  6440. prusa_statistics(important_status, saved_filament_type);
  6441. NcTime = millis();
  6442. lcd_connect_printer();
  6443. }
  6444. }
  6445. static void lcd_connect_printer() {
  6446. lcd_update_enable(false);
  6447. lcd_implementation_clear();
  6448. bool pressed = false;
  6449. int i = 0;
  6450. int t = 0;
  6451. lcd_set_custom_characters_progress();
  6452. lcd_implementation_print_at(0, 0, "Connect printer to");
  6453. lcd_implementation_print_at(0, 1, "monitoring or hold");
  6454. lcd_implementation_print_at(0, 2, "the knob to continue");
  6455. while (no_response) {
  6456. i++;
  6457. t++;
  6458. delay_keep_alive(100);
  6459. proc_commands();
  6460. if (t == 10) {
  6461. prusa_statistics(important_status, saved_filament_type);
  6462. t = 0;
  6463. }
  6464. if (READ(BTN_ENC)) { //if button is not pressed
  6465. i = 0;
  6466. lcd_implementation_print_at(0, 3, " ");
  6467. }
  6468. if (i!=0) lcd_implementation_print_at((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
  6469. if (i == NC_BUTTON_LONG_PRESS * 10) {
  6470. no_response = false;
  6471. }
  6472. }
  6473. lcd_set_custom_characters_degree();
  6474. lcd_update_enable(true);
  6475. lcd_update(2);
  6476. }
  6477. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6478. if (farm_mode) {
  6479. bool empty = is_buffer_empty();
  6480. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6481. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6482. //therefore longer period is used
  6483. printer_connected = false;
  6484. }
  6485. else {
  6486. lcd_printer_connected();
  6487. }
  6488. }
  6489. }
  6490. void lcd_ignore_click(bool b)
  6491. {
  6492. ignore_click = b;
  6493. wait_for_unclick = false;
  6494. }
  6495. void lcd_finishstatus() {
  6496. int len = strlen(lcd_status_message);
  6497. if (len > 0) {
  6498. while (len < LCD_WIDTH) {
  6499. lcd_status_message[len++] = ' ';
  6500. }
  6501. }
  6502. lcd_status_message[LCD_WIDTH] = '\0';
  6503. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  6504. #if PROGRESS_MSG_EXPIRE > 0
  6505. messageTick =
  6506. #endif
  6507. progressBarTick = millis();
  6508. #endif
  6509. lcdDrawUpdate = 2;
  6510. #ifdef FILAMENT_LCD_DISPLAY
  6511. message_millis = millis(); //get status message to show up for a while
  6512. #endif
  6513. }
  6514. void lcd_setstatus(const char* message)
  6515. {
  6516. if (lcd_status_message_level > 0)
  6517. return;
  6518. strncpy(lcd_status_message, message, LCD_WIDTH);
  6519. lcd_finishstatus();
  6520. }
  6521. void lcd_setstatuspgm(const char* message)
  6522. {
  6523. if (lcd_status_message_level > 0)
  6524. return;
  6525. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6526. lcd_status_message[LCD_WIDTH] = 0;
  6527. lcd_finishstatus();
  6528. }
  6529. void lcd_setalertstatuspgm(const char* message)
  6530. {
  6531. lcd_setstatuspgm(message);
  6532. lcd_status_message_level = 1;
  6533. #ifdef ULTIPANEL
  6534. lcd_return_to_status();
  6535. #endif//ULTIPANEL
  6536. }
  6537. void lcd_reset_alert_level()
  6538. {
  6539. lcd_status_message_level = 0;
  6540. }
  6541. uint8_t get_message_level()
  6542. {
  6543. return lcd_status_message_level;
  6544. }
  6545. #ifdef DOGLCD
  6546. void lcd_setcontrast(uint8_t value)
  6547. {
  6548. lcd_contrast = value & 63;
  6549. u8g.setContrast(lcd_contrast);
  6550. }
  6551. #endif
  6552. #ifdef ULTIPANEL
  6553. /* Warning: This function is called from interrupt context */
  6554. void lcd_buttons_update()
  6555. {
  6556. static bool _lock = false;
  6557. if (_lock) return;
  6558. _lock = true;
  6559. #ifdef NEWPANEL
  6560. uint8_t newbutton = 0;
  6561. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  6562. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  6563. #if BTN_ENC > 0
  6564. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  6565. if (READ(BTN_ENC) == 0) { //button is pressed
  6566. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6567. if (millis() > button_blanking_time) {
  6568. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6569. if (button_pressed == false && long_press_active == false) {
  6570. longPressTimer.start();
  6571. button_pressed = true;
  6572. }
  6573. else {
  6574. if (longPressTimer.expired(LONG_PRESS_TIME)) {
  6575. long_press_active = true;
  6576. move_menu_scale = 1.0;
  6577. menu_action_submenu(lcd_move_z);
  6578. }
  6579. }
  6580. }
  6581. }
  6582. else { //button not pressed
  6583. if (button_pressed) { //button was released
  6584. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6585. if (long_press_active == false) { //button released before long press gets activated
  6586. newbutton |= EN_C;
  6587. }
  6588. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  6589. //button_pressed is set back to false via lcd_quick_feedback function
  6590. }
  6591. else {
  6592. long_press_active = false;
  6593. }
  6594. }
  6595. }
  6596. else { //we are in modal mode
  6597. if (READ(BTN_ENC) == 0)
  6598. newbutton |= EN_C;
  6599. }
  6600. #endif
  6601. buttons = newbutton;
  6602. #ifdef LCD_HAS_SLOW_BUTTONS
  6603. buttons |= slow_buttons;
  6604. #endif
  6605. #ifdef REPRAPWORLD_KEYPAD
  6606. // for the reprapworld_keypad
  6607. uint8_t newbutton_reprapworld_keypad = 0;
  6608. WRITE(SHIFT_LD, LOW);
  6609. WRITE(SHIFT_LD, HIGH);
  6610. for (int8_t i = 0; i < 8; i++) {
  6611. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  6612. if (READ(SHIFT_OUT))
  6613. newbutton_reprapworld_keypad |= (1 << 7);
  6614. WRITE(SHIFT_CLK, HIGH);
  6615. WRITE(SHIFT_CLK, LOW);
  6616. }
  6617. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  6618. #endif
  6619. #else //read it from the shift register
  6620. uint8_t newbutton = 0;
  6621. WRITE(SHIFT_LD, LOW);
  6622. WRITE(SHIFT_LD, HIGH);
  6623. unsigned char tmp_buttons = 0;
  6624. for (int8_t i = 0; i < 8; i++)
  6625. {
  6626. newbutton = newbutton >> 1;
  6627. if (READ(SHIFT_OUT))
  6628. newbutton |= (1 << 7);
  6629. WRITE(SHIFT_CLK, HIGH);
  6630. WRITE(SHIFT_CLK, LOW);
  6631. }
  6632. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  6633. #endif//!NEWPANEL
  6634. //manage encoder rotation
  6635. uint8_t enc = 0;
  6636. if (buttons & EN_A) enc |= B01;
  6637. if (buttons & EN_B) enc |= B10;
  6638. if (enc != lastEncoderBits)
  6639. {
  6640. switch (enc)
  6641. {
  6642. case encrot0:
  6643. if (lastEncoderBits == encrot3)
  6644. encoderDiff++;
  6645. else if (lastEncoderBits == encrot1)
  6646. encoderDiff--;
  6647. break;
  6648. case encrot1:
  6649. if (lastEncoderBits == encrot0)
  6650. encoderDiff++;
  6651. else if (lastEncoderBits == encrot2)
  6652. encoderDiff--;
  6653. break;
  6654. case encrot2:
  6655. if (lastEncoderBits == encrot1)
  6656. encoderDiff++;
  6657. else if (lastEncoderBits == encrot3)
  6658. encoderDiff--;
  6659. break;
  6660. case encrot3:
  6661. if (lastEncoderBits == encrot2)
  6662. encoderDiff++;
  6663. else if (lastEncoderBits == encrot0)
  6664. encoderDiff--;
  6665. break;
  6666. }
  6667. }
  6668. lastEncoderBits = enc;
  6669. _lock = false;
  6670. }
  6671. bool lcd_detected(void)
  6672. {
  6673. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  6674. return lcd.LcdDetected() == 1;
  6675. #else
  6676. return true;
  6677. #endif
  6678. }
  6679. void lcd_buzz(long duration, uint16_t freq)
  6680. {
  6681. #ifdef LCD_USE_I2C_BUZZER
  6682. lcd.buzz(duration, freq);
  6683. #endif
  6684. }
  6685. bool lcd_clicked()
  6686. {
  6687. bool clicked = LCD_CLICKED;
  6688. if(clicked) button_pressed = false;
  6689. return clicked;
  6690. }
  6691. #endif//ULTIPANEL
  6692. /********************************/
  6693. /** Float conversion utilities **/
  6694. /********************************/
  6695. // convert float to string with +123.4 format
  6696. char conv[8];
  6697. char *ftostr3(const float &x)
  6698. {
  6699. return itostr3((int)x);
  6700. }
  6701. char *itostr2(const uint8_t &x)
  6702. {
  6703. //sprintf(conv,"%5.1f",x);
  6704. int xx = x;
  6705. conv[0] = (xx / 10) % 10 + '0';
  6706. conv[1] = (xx) % 10 + '0';
  6707. conv[2] = 0;
  6708. return conv;
  6709. }
  6710. // Convert float to string with 123.4 format, dropping sign
  6711. char *ftostr31(const float &x)
  6712. {
  6713. int xx = x * 10;
  6714. conv[0] = (xx >= 0) ? '+' : '-';
  6715. xx = abs(xx);
  6716. conv[1] = (xx / 1000) % 10 + '0';
  6717. conv[2] = (xx / 100) % 10 + '0';
  6718. conv[3] = (xx / 10) % 10 + '0';
  6719. conv[4] = '.';
  6720. conv[5] = (xx) % 10 + '0';
  6721. conv[6] = 0;
  6722. return conv;
  6723. }
  6724. // Convert float to string with 123.4 format
  6725. char *ftostr31ns(const float &x)
  6726. {
  6727. int xx = x * 10;
  6728. //conv[0]=(xx>=0)?'+':'-';
  6729. xx = abs(xx);
  6730. conv[0] = (xx / 1000) % 10 + '0';
  6731. conv[1] = (xx / 100) % 10 + '0';
  6732. conv[2] = (xx / 10) % 10 + '0';
  6733. conv[3] = '.';
  6734. conv[4] = (xx) % 10 + '0';
  6735. conv[5] = 0;
  6736. return conv;
  6737. }
  6738. char *ftostr32(const float &x)
  6739. {
  6740. long xx = x * 100;
  6741. if (xx >= 0)
  6742. conv[0] = (xx / 10000) % 10 + '0';
  6743. else
  6744. conv[0] = '-';
  6745. xx = abs(xx);
  6746. conv[1] = (xx / 1000) % 10 + '0';
  6747. conv[2] = (xx / 100) % 10 + '0';
  6748. conv[3] = '.';
  6749. conv[4] = (xx / 10) % 10 + '0';
  6750. conv[5] = (xx) % 10 + '0';
  6751. conv[6] = 0;
  6752. return conv;
  6753. }
  6754. //// Convert float to rj string with 123.45 format
  6755. char *ftostr32ns(const float &x) {
  6756. long xx = abs(x);
  6757. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6758. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6759. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  6760. conv[3] = '.';
  6761. conv[4] = (xx / 10) % 10 + '0';
  6762. conv[5] = xx % 10 + '0';
  6763. return conv;
  6764. }
  6765. // Convert float to string with 1.234 format
  6766. char *ftostr43(const float &x, uint8_t offset)
  6767. {
  6768. const size_t maxOffset = sizeof(conv)/sizeof(conv[0]) - 6;
  6769. if (offset>maxOffset) offset = maxOffset;
  6770. long xx = x * 1000;
  6771. if (xx >= 0)
  6772. conv[offset] = (xx / 1000) % 10 + '0';
  6773. else
  6774. conv[offset] = '-';
  6775. xx = abs(xx);
  6776. conv[offset + 1] = '.';
  6777. conv[offset + 2] = (xx / 100) % 10 + '0';
  6778. conv[offset + 3] = (xx / 10) % 10 + '0';
  6779. conv[offset + 4] = (xx) % 10 + '0';
  6780. conv[offset + 5] = 0;
  6781. return conv;
  6782. }
  6783. //Float to string with 1.23 format
  6784. char *ftostr12ns(const float &x)
  6785. {
  6786. long xx = x * 100;
  6787. xx = abs(xx);
  6788. conv[0] = (xx / 100) % 10 + '0';
  6789. conv[1] = '.';
  6790. conv[2] = (xx / 10) % 10 + '0';
  6791. conv[3] = (xx) % 10 + '0';
  6792. conv[4] = 0;
  6793. return conv;
  6794. }
  6795. //Float to string with 1.234 format
  6796. char *ftostr13ns(const float &x)
  6797. {
  6798. long xx = x * 1000;
  6799. if (xx >= 0)
  6800. conv[0] = ' ';
  6801. else
  6802. conv[0] = '-';
  6803. xx = abs(xx);
  6804. conv[1] = (xx / 1000) % 10 + '0';
  6805. conv[2] = '.';
  6806. conv[3] = (xx / 100) % 10 + '0';
  6807. conv[4] = (xx / 10) % 10 + '0';
  6808. conv[5] = (xx) % 10 + '0';
  6809. conv[6] = 0;
  6810. return conv;
  6811. }
  6812. // convert float to space-padded string with -_23.4_ format
  6813. char *ftostr32sp(const float &x) {
  6814. long xx = abs(x * 100);
  6815. uint8_t dig;
  6816. if (x < 0) { // negative val = -_0
  6817. conv[0] = '-';
  6818. dig = (xx / 1000) % 10;
  6819. conv[1] = dig ? '0' + dig : ' ';
  6820. }
  6821. else { // positive val = __0
  6822. dig = (xx / 10000) % 10;
  6823. if (dig) {
  6824. conv[0] = '0' + dig;
  6825. conv[1] = '0' + (xx / 1000) % 10;
  6826. }
  6827. else {
  6828. conv[0] = ' ';
  6829. dig = (xx / 1000) % 10;
  6830. conv[1] = dig ? '0' + dig : ' ';
  6831. }
  6832. }
  6833. conv[2] = '0' + (xx / 100) % 10; // lsd always
  6834. dig = xx % 10;
  6835. if (dig) { // 2 decimal places
  6836. conv[5] = '0' + dig;
  6837. conv[4] = '0' + (xx / 10) % 10;
  6838. conv[3] = '.';
  6839. }
  6840. else { // 1 or 0 decimal place
  6841. dig = (xx / 10) % 10;
  6842. if (dig) {
  6843. conv[4] = '0' + dig;
  6844. conv[3] = '.';
  6845. }
  6846. else {
  6847. conv[3] = conv[4] = ' ';
  6848. }
  6849. conv[5] = ' ';
  6850. }
  6851. conv[6] = '\0';
  6852. return conv;
  6853. }
  6854. char *itostr31(const int &xx)
  6855. {
  6856. conv[0] = (xx >= 0) ? '+' : '-';
  6857. conv[1] = (xx / 1000) % 10 + '0';
  6858. conv[2] = (xx / 100) % 10 + '0';
  6859. conv[3] = (xx / 10) % 10 + '0';
  6860. conv[4] = '.';
  6861. conv[5] = (xx) % 10 + '0';
  6862. conv[6] = 0;
  6863. return conv;
  6864. }
  6865. // Convert int to rj string with 123 or -12 format
  6866. char *itostr3(const int &x)
  6867. {
  6868. int xx = x;
  6869. if (xx < 0) {
  6870. conv[0] = '-';
  6871. xx = -xx;
  6872. } else if (xx >= 100)
  6873. conv[0] = (xx / 100) % 10 + '0';
  6874. else
  6875. conv[0] = ' ';
  6876. if (xx >= 10)
  6877. conv[1] = (xx / 10) % 10 + '0';
  6878. else
  6879. conv[1] = ' ';
  6880. conv[2] = (xx) % 10 + '0';
  6881. conv[3] = 0;
  6882. return conv;
  6883. }
  6884. // Convert int to lj string with 123 format
  6885. char *itostr3left(const int &xx)
  6886. {
  6887. if (xx >= 100)
  6888. {
  6889. conv[0] = (xx / 100) % 10 + '0';
  6890. conv[1] = (xx / 10) % 10 + '0';
  6891. conv[2] = (xx) % 10 + '0';
  6892. conv[3] = 0;
  6893. }
  6894. else if (xx >= 10)
  6895. {
  6896. conv[0] = (xx / 10) % 10 + '0';
  6897. conv[1] = (xx) % 10 + '0';
  6898. conv[2] = 0;
  6899. }
  6900. else
  6901. {
  6902. conv[0] = (xx) % 10 + '0';
  6903. conv[1] = 0;
  6904. }
  6905. return conv;
  6906. }
  6907. // Convert int to rj string with 1234 format
  6908. char *itostr4(const int &xx) {
  6909. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6910. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6911. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6912. conv[3] = xx % 10 + '0';
  6913. conv[4] = 0;
  6914. return conv;
  6915. }
  6916. // Convert float to rj string with 12345 format
  6917. char *ftostr5(const float &x) {
  6918. long xx = abs(x);
  6919. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6920. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6921. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6922. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6923. conv[4] = xx % 10 + '0';
  6924. conv[5] = 0;
  6925. return conv;
  6926. }
  6927. // Convert float to string with +1234.5 format
  6928. char *ftostr51(const float &x)
  6929. {
  6930. long xx = x * 10;
  6931. conv[0] = (xx >= 0) ? '+' : '-';
  6932. xx = abs(xx);
  6933. conv[1] = (xx / 10000) % 10 + '0';
  6934. conv[2] = (xx / 1000) % 10 + '0';
  6935. conv[3] = (xx / 100) % 10 + '0';
  6936. conv[4] = (xx / 10) % 10 + '0';
  6937. conv[5] = '.';
  6938. conv[6] = (xx) % 10 + '0';
  6939. conv[7] = 0;
  6940. return conv;
  6941. }
  6942. // Convert float to string with +123.45 format
  6943. char *ftostr52(const float &x)
  6944. {
  6945. long xx = x * 100;
  6946. conv[0] = (xx >= 0) ? '+' : '-';
  6947. xx = abs(xx);
  6948. conv[1] = (xx / 10000) % 10 + '0';
  6949. conv[2] = (xx / 1000) % 10 + '0';
  6950. conv[3] = (xx / 100) % 10 + '0';
  6951. conv[4] = '.';
  6952. conv[5] = (xx / 10) % 10 + '0';
  6953. conv[6] = (xx) % 10 + '0';
  6954. conv[7] = 0;
  6955. return conv;
  6956. }
  6957. /*
  6958. // Callback for after editing PID i value
  6959. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  6960. void copy_and_scalePID_i()
  6961. {
  6962. #ifdef PIDTEMP
  6963. Ki = scalePID_i(raw_Ki);
  6964. updatePID();
  6965. #endif
  6966. }
  6967. // Callback for after editing PID d value
  6968. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  6969. void copy_and_scalePID_d()
  6970. {
  6971. #ifdef PIDTEMP
  6972. Kd = scalePID_d(raw_Kd);
  6973. updatePID();
  6974. #endif
  6975. }
  6976. */
  6977. #endif //ULTRA_LCD