ultralcd.cpp 231 KB

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