ultralcd.cpp 181 KB

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