ultralcd.cpp 147 KB

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