ultralcd.cpp 156 KB

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