ultralcd.cpp 221 KB

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