ultralcd.cpp 177 KB

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