ultralcd.cpp 215 KB

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