ultralcd.cpp 235 KB

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