ultralcd.cpp 176 KB

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