ultralcd.cpp 216 KB

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