My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 160KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "ultralcd.h"
  23. #if ENABLED(ULTRA_LCD)
  24. #include "Marlin.h"
  25. #include "language.h"
  26. #include "cardreader.h"
  27. #include "temperature.h"
  28. #include "planner.h"
  29. #include "stepper.h"
  30. #include "configuration_store.h"
  31. #include "utility.h"
  32. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  33. #include "buzzer.h"
  34. #endif
  35. #if ENABLED(PRINTCOUNTER)
  36. #include "printcounter.h"
  37. #include "duration_t.h"
  38. #endif
  39. #if ENABLED(BLTOUCH)
  40. #include "endstops.h"
  41. #endif
  42. #if ENABLED(AUTO_BED_LEVELING_UBL)
  43. #include "ubl.h"
  44. bool ubl_lcd_map_control = false;
  45. #endif
  46. // Initialized by settings.load()
  47. int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  48. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  49. millis_t previous_lcd_status_ms = 0;
  50. #endif
  51. #if ENABLED(BABYSTEPPING)
  52. long babysteps_done = 0;
  53. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  54. static void lcd_babystep_zoffset();
  55. #else
  56. static void lcd_babystep_z();
  57. #endif
  58. #endif
  59. uint8_t lcd_status_message_level;
  60. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  61. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  62. uint8_t status_scroll_pos = 0;
  63. #endif
  64. #if ENABLED(DOGLCD)
  65. #include "ultralcd_impl_DOGM.h"
  66. #include <U8glib.h>
  67. #else
  68. #include "ultralcd_impl_HD44780.h"
  69. #endif
  70. // The main status screen
  71. void lcd_status_screen();
  72. millis_t next_lcd_update_ms;
  73. uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
  74. uint16_t max_display_update_time = 0;
  75. #if ENABLED(DOGLCD)
  76. bool drawing_screen = false;
  77. #endif
  78. #if ENABLED(DAC_STEPPER_CURRENT)
  79. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  80. uint8_t driverPercent[XYZE];
  81. #endif
  82. #if ENABLED(ULTIPANEL)
  83. #ifndef TALL_FONT_CORRECTION
  84. #define TALL_FONT_CORRECTION 0
  85. #endif
  86. // Function pointer to menu functions.
  87. typedef void (*screenFunc_t)();
  88. #if HAS_POWER_SWITCH
  89. extern bool powersupply_on;
  90. #endif
  91. ////////////////////////////////////////////
  92. ///////////////// Menu Tree ////////////////
  93. ////////////////////////////////////////////
  94. void lcd_main_menu();
  95. void lcd_tune_menu();
  96. void lcd_prepare_menu();
  97. void lcd_move_menu();
  98. void lcd_control_menu();
  99. void lcd_control_temperature_menu();
  100. void lcd_control_temperature_preheat_material1_settings_menu();
  101. void lcd_control_temperature_preheat_material2_settings_menu();
  102. void lcd_control_motion_menu();
  103. void lcd_control_filament_menu();
  104. #if ENABLED(LCD_INFO_MENU)
  105. #if ENABLED(PRINTCOUNTER)
  106. void lcd_info_stats_menu();
  107. #endif
  108. void lcd_info_thermistors_menu();
  109. void lcd_info_board_menu();
  110. void lcd_info_menu();
  111. #endif // LCD_INFO_MENU
  112. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  113. void lcd_advanced_pause_toocold_menu();
  114. void lcd_advanced_pause_option_menu();
  115. void lcd_advanced_pause_init_message();
  116. void lcd_advanced_pause_unload_message();
  117. void lcd_advanced_pause_insert_message();
  118. void lcd_advanced_pause_load_message();
  119. void lcd_advanced_pause_heat_nozzle();
  120. void lcd_advanced_pause_extrude_message();
  121. void lcd_advanced_pause_resume_message();
  122. #endif
  123. #if ENABLED(DAC_STEPPER_CURRENT)
  124. void dac_driver_commit();
  125. void dac_driver_getValues();
  126. void lcd_dac_menu();
  127. void lcd_dac_write_eeprom();
  128. #endif
  129. #if ENABLED(FWRETRACT)
  130. void lcd_control_retract_menu();
  131. #endif
  132. #if ENABLED(DELTA_CALIBRATION_MENU)
  133. void lcd_delta_calibrate_menu();
  134. #endif
  135. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  136. #include "mesh_bed_leveling.h"
  137. extern void mesh_probing_done();
  138. #endif
  139. ////////////////////////////////////////////
  140. //////////// Menu System Actions ///////////
  141. ////////////////////////////////////////////
  142. #define menu_action_back(dummy) _menu_action_back()
  143. void _menu_action_back();
  144. void menu_action_submenu(screenFunc_t data);
  145. void menu_action_gcode(const char* pgcode);
  146. void menu_action_function(screenFunc_t data);
  147. #define DECLARE_MENU_EDIT_TYPE(_type, _name) \
  148. bool _menu_edit_ ## _name(); \
  149. void menu_edit_ ## _name(); \
  150. void menu_edit_callback_ ## _name(); \
  151. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
  152. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
  153. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
  154. typedef void _name##_void
  155. DECLARE_MENU_EDIT_TYPE(int16_t, int3);
  156. DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
  157. DECLARE_MENU_EDIT_TYPE(float, float3);
  158. DECLARE_MENU_EDIT_TYPE(float, float32);
  159. DECLARE_MENU_EDIT_TYPE(float, float43);
  160. DECLARE_MENU_EDIT_TYPE(float, float5);
  161. DECLARE_MENU_EDIT_TYPE(float, float51);
  162. DECLARE_MENU_EDIT_TYPE(float, float52);
  163. DECLARE_MENU_EDIT_TYPE(float, float62);
  164. DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
  165. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  166. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  167. #if ENABLED(SDSUPPORT)
  168. void lcd_sdcard_menu();
  169. void menu_action_sdfile(const char* filename, char* longFilename);
  170. void menu_action_sddirectory(const char* filename, char* longFilename);
  171. #endif
  172. ////////////////////////////////////////////
  173. //////////// Menu System Macros ////////////
  174. ////////////////////////////////////////////
  175. #ifndef ENCODER_FEEDRATE_DEADZONE
  176. #define ENCODER_FEEDRATE_DEADZONE 10
  177. #endif
  178. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  179. #define ENCODER_STEPS_PER_MENU_ITEM 5
  180. #endif
  181. #ifndef ENCODER_PULSES_PER_STEP
  182. #define ENCODER_PULSES_PER_STEP 1
  183. #endif
  184. /**
  185. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  186. *
  187. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  188. * menu_action_[type](arg3...)
  189. *
  190. * Examples:
  191. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  192. * or
  193. * MENU_BACK(MSG_WATCH)
  194. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  195. * menu_action_back()
  196. *
  197. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  198. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  199. * menu_action_function(lcd_sdcard_pause)
  200. *
  201. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  202. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  203. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  204. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  205. *
  206. */
  207. #define _MENU_ITEM_PART_1(TYPE, ...) \
  208. if (_menuLineNr == _thisItemNr) { \
  209. if (lcd_clicked && encoderLine == _thisItemNr) {
  210. #define _MENU_ITEM_PART_2(TYPE, LABEL, ...) \
  211. menu_action_ ## TYPE(__VA_ARGS__); \
  212. if (screen_changed) return; \
  213. } \
  214. if (lcdDrawUpdate) \
  215. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  216. } \
  217. ++_thisItemNr
  218. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  219. _skipStatic = false; \
  220. _MENU_ITEM_PART_1(TYPE, ## __VA_ARGS__); \
  221. _MENU_ITEM_PART_2(TYPE, LABEL, ## __VA_ARGS__); \
  222. }while(0)
  223. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  224. // Used to print static text with no visible cursor.
  225. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  226. #define STATIC_ITEM(LABEL, ...) \
  227. if (_menuLineNr == _thisItemNr) { \
  228. if (_skipStatic && encoderLine <= _thisItemNr) { \
  229. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  230. ++encoderLine; \
  231. } \
  232. if (lcdDrawUpdate) \
  233. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  234. } \
  235. ++_thisItemNr
  236. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  237. bool encoderRateMultiplierEnabled;
  238. #define ENCODER_RATE_MULTIPLY(F) (encoderRateMultiplierEnabled = F)
  239. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  240. /**
  241. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  242. */
  243. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  244. _MENU_ITEM_PART_1(type, ## __VA_ARGS__); \
  245. encoderRateMultiplierEnabled = true; \
  246. lastEncoderMovementMillis = 0; \
  247. _MENU_ITEM_PART_2(type, label, ## __VA_ARGS__); \
  248. }while(0)
  249. #else // !ENCODER_RATE_MULTIPLIER
  250. #define ENCODER_RATE_MULTIPLY(F) NOOP
  251. #endif // !ENCODER_RATE_MULTIPLIER
  252. #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
  253. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  254. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  255. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  256. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  257. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  258. #else // !ENCODER_RATE_MULTIPLIER
  259. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  260. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  261. #endif // !ENCODER_RATE_MULTIPLIER
  262. /**
  263. * START_SCREEN_OR_MENU generates init code for a screen or menu
  264. *
  265. * encoderLine is the position based on the encoder
  266. * encoderTopLine is the top menu line to display
  267. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  268. * _menuLineNr is the menu item to draw and process
  269. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  270. * _countedItems is the total number of items in the menu (after one call)
  271. */
  272. #define START_SCREEN_OR_MENU(LIMIT) \
  273. ENCODER_DIRECTION_MENUS(); \
  274. ENCODER_RATE_MULTIPLY(false); \
  275. if (encoderPosition > 0x8000) encoderPosition = 0; \
  276. static int8_t _countedItems = 0; \
  277. int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
  278. if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
  279. encoderLine = max(0, _countedItems - (LIMIT)); \
  280. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  281. }
  282. #define SCREEN_OR_MENU_LOOP() \
  283. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  284. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
  285. _thisItemNr = 0
  286. /**
  287. * START_SCREEN Opening code for a screen having only static items.
  288. * Do simplified scrolling of the entire screen.
  289. *
  290. * START_MENU Opening code for a screen with menu items.
  291. * Scroll as-needed to keep the selected line in view.
  292. */
  293. #define START_SCREEN() \
  294. START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
  295. encoderTopLine = encoderLine; \
  296. bool _skipStatic = false; \
  297. SCREEN_OR_MENU_LOOP()
  298. #define START_MENU() \
  299. START_SCREEN_OR_MENU(1); \
  300. screen_changed = false; \
  301. NOMORE(encoderTopLine, encoderLine); \
  302. if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
  303. encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
  304. } \
  305. bool _skipStatic = true; \
  306. SCREEN_OR_MENU_LOOP()
  307. #define END_SCREEN() \
  308. } \
  309. _countedItems = _thisItemNr
  310. #define END_MENU() \
  311. } \
  312. _countedItems = _thisItemNr; \
  313. UNUSED(_skipStatic)
  314. ////////////////////////////////////////////
  315. ///////////// Global Variables /////////////
  316. ////////////////////////////////////////////
  317. /**
  318. * REVERSE_MENU_DIRECTION
  319. *
  320. * To reverse the menu direction we need a general way to reverse
  321. * the direction of the encoder everywhere. So encoderDirection is
  322. * added to allow the encoder to go the other way.
  323. *
  324. * This behavior is limited to scrolling Menus and SD card listings,
  325. * and is disabled in other contexts.
  326. */
  327. #if ENABLED(REVERSE_MENU_DIRECTION)
  328. int8_t encoderDirection = 1;
  329. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  330. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  331. #else
  332. #define ENCODER_DIRECTION_NORMAL() ;
  333. #define ENCODER_DIRECTION_MENUS() ;
  334. #endif
  335. // Encoder Movement
  336. volatile int8_t encoderDiff; // Updated in lcd_buttons_update, added to encoderPosition every LCD update
  337. uint32_t encoderPosition;
  338. millis_t lastEncoderMovementMillis = 0;
  339. // Button States
  340. bool lcd_clicked, wait_for_unclick;
  341. volatile uint8_t buttons;
  342. millis_t next_button_update_ms;
  343. #if ENABLED(REPRAPWORLD_KEYPAD)
  344. volatile uint8_t buttons_reprapworld_keypad;
  345. #endif
  346. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  347. volatile uint8_t slow_buttons;
  348. #endif
  349. // Menu System Navigation
  350. screenFunc_t currentScreen = lcd_status_screen;
  351. int8_t encoderTopLine;
  352. typedef struct {
  353. screenFunc_t menu_function;
  354. uint32_t encoder_position;
  355. } menuPosition;
  356. menuPosition screen_history[6];
  357. uint8_t screen_history_depth = 0;
  358. bool screen_changed, defer_return_to_status;
  359. // Value Editing
  360. const char *editLabel;
  361. void *editValue;
  362. int32_t minEditValue, maxEditValue;
  363. screenFunc_t callbackFunc;
  364. bool liveEdit;
  365. // Manual Moves
  366. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  367. millis_t manual_move_start_time = 0;
  368. int8_t manual_move_axis = (int8_t)NO_AXIS;
  369. #if EXTRUDERS > 1
  370. int8_t manual_move_e_index = 0;
  371. #else
  372. #define manual_move_e_index 0
  373. #endif
  374. #if PIN_EXISTS(SD_DETECT)
  375. uint8_t lcd_sd_status;
  376. #endif
  377. #if ENABLED(PIDTEMP)
  378. float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
  379. #endif
  380. /**
  381. * General function to go directly to a screen
  382. */
  383. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0) {
  384. if (currentScreen != screen) {
  385. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  386. static millis_t doubleclick_expire_ms = 0;
  387. // Going to lcd_main_menu from status screen? Remember first click time.
  388. // Going back to status screen within a very short time? Go to Z babystepping.
  389. if (screen == lcd_main_menu) {
  390. if (currentScreen == lcd_status_screen)
  391. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  392. }
  393. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
  394. screen =
  395. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  396. lcd_babystep_zoffset
  397. #else
  398. lcd_babystep_z
  399. #endif
  400. ;
  401. #endif
  402. currentScreen = screen;
  403. encoderPosition = encoder;
  404. if (screen == lcd_status_screen) {
  405. defer_return_to_status = false;
  406. #if ENABLED(AUTO_BED_LEVELING_UBL)
  407. ubl_lcd_map_control = false;
  408. #endif
  409. screen_history_depth = 0;
  410. }
  411. lcd_implementation_clear();
  412. // Re-initialize custom characters that may be re-used
  413. #if DISABLED(DOGLCD) && ENABLED(AUTO_BED_LEVELING_UBL)
  414. if (!ubl_lcd_map_control) lcd_set_custom_characters(
  415. #if ENABLED(LCD_PROGRESS_BAR)
  416. screen == lcd_status_screen
  417. #endif
  418. );
  419. #elif ENABLED(LCD_PROGRESS_BAR)
  420. lcd_set_custom_characters(screen == lcd_status_screen);
  421. #endif
  422. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  423. screen_changed = true;
  424. #if ENABLED(DOGLCD)
  425. drawing_screen = false;
  426. #endif
  427. }
  428. }
  429. /**
  430. * Show "Moving..." till moves are done, then revert to previous display.
  431. */
  432. static const char moving[] PROGMEM = MSG_MOVING;
  433. static const char *sync_message = moving;
  434. //
  435. // Display the synchronize screen until moves are
  436. // finished, and don't return to the caller until
  437. // done. ** This blocks the command queue! **
  438. //
  439. void _lcd_synchronize() {
  440. static bool no_reentry = false;
  441. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
  442. if (no_reentry) return;
  443. // Make this the current handler till all moves are done
  444. no_reentry = true;
  445. screenFunc_t old_screen = currentScreen;
  446. lcd_goto_screen(_lcd_synchronize);
  447. stepper.synchronize();
  448. no_reentry = false;
  449. lcd_goto_screen(old_screen);
  450. }
  451. // Display the synchronize screen with a custom message
  452. // ** This blocks the command queue! **
  453. void lcd_synchronize(const char * const msg=NULL) {
  454. sync_message = msg ? msg : moving;
  455. _lcd_synchronize();
  456. }
  457. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  458. void lcd_save_previous_screen() {
  459. if (screen_history_depth < COUNT(screen_history)) {
  460. screen_history[screen_history_depth].menu_function = currentScreen;
  461. screen_history[screen_history_depth].encoder_position = encoderPosition;
  462. ++screen_history_depth;
  463. }
  464. }
  465. void lcd_goto_previous_menu() {
  466. if (screen_history_depth > 0) {
  467. --screen_history_depth;
  468. lcd_goto_screen(
  469. screen_history[screen_history_depth].menu_function,
  470. screen_history[screen_history_depth].encoder_position
  471. );
  472. }
  473. else
  474. lcd_return_to_status();
  475. }
  476. #endif // ULTIPANEL
  477. /**
  478. *
  479. * "Info Screen"
  480. *
  481. * This is very display-dependent, so the lcd implementation draws this.
  482. */
  483. void lcd_status_screen() {
  484. #if ENABLED(ULTIPANEL)
  485. ENCODER_DIRECTION_NORMAL();
  486. ENCODER_RATE_MULTIPLY(false);
  487. #endif
  488. #if ENABLED(LCD_PROGRESS_BAR)
  489. millis_t ms = millis();
  490. #if DISABLED(PROGRESS_MSG_ONCE)
  491. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  492. progress_bar_ms = ms;
  493. }
  494. #endif
  495. #if PROGRESS_MSG_EXPIRE > 0
  496. // Handle message expire
  497. if (expire_status_ms > 0) {
  498. #if ENABLED(SDSUPPORT)
  499. if (card.isFileOpen()) {
  500. // Expire the message when printing is active
  501. if (IS_SD_PRINTING) {
  502. if (ELAPSED(ms, expire_status_ms)) {
  503. lcd_status_message[0] = '\0';
  504. expire_status_ms = 0;
  505. }
  506. }
  507. else {
  508. expire_status_ms += LCD_UPDATE_INTERVAL;
  509. }
  510. }
  511. else {
  512. expire_status_ms = 0;
  513. }
  514. #else
  515. expire_status_ms = 0;
  516. #endif // SDSUPPORT
  517. }
  518. #endif
  519. #endif // LCD_PROGRESS_BAR
  520. #if ENABLED(ULTIPANEL)
  521. if (lcd_clicked) {
  522. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  523. previous_lcd_status_ms = millis(); // get status message to show up for a while
  524. #endif
  525. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  526. #if ENABLED(LCD_PROGRESS_BAR)
  527. false
  528. #endif
  529. );
  530. lcd_goto_screen(lcd_main_menu);
  531. return;
  532. }
  533. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  534. const int16_t new_frm = feedrate_percentage + (int32_t)encoderPosition;
  535. // Dead zone at 100% feedrate
  536. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  537. feedrate_percentage = 100;
  538. encoderPosition = 0;
  539. }
  540. else if (feedrate_percentage == 100) {
  541. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  542. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  543. encoderPosition = 0;
  544. }
  545. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  546. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  547. encoderPosition = 0;
  548. }
  549. }
  550. else {
  551. feedrate_percentage = new_frm;
  552. encoderPosition = 0;
  553. }
  554. #endif // ULTIPANEL_FEEDMULTIPLY
  555. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  556. #endif // ULTIPANEL
  557. lcd_implementation_status_screen();
  558. }
  559. void lcd_reset_status() { lcd_setstatusPGM(PSTR(""), -1); }
  560. /**
  561. *
  562. * draw the kill screen
  563. *
  564. */
  565. void kill_screen(const char* lcd_msg) {
  566. lcd_init();
  567. lcd_setalertstatusPGM(lcd_msg);
  568. #if ENABLED(DOGLCD)
  569. u8g.firstPage();
  570. do {
  571. lcd_kill_screen();
  572. } while (u8g.nextPage());
  573. #else
  574. lcd_kill_screen();
  575. #endif
  576. }
  577. #if ENABLED(ULTIPANEL)
  578. /**
  579. *
  580. * Audio feedback for controller clicks
  581. *
  582. */
  583. void lcd_buzz(long duration, uint16_t freq) {
  584. #if ENABLED(LCD_USE_I2C_BUZZER)
  585. lcd.buzz(duration, freq);
  586. #elif PIN_EXISTS(BEEPER)
  587. buzzer.tone(duration, freq);
  588. #else
  589. UNUSED(duration); UNUSED(freq);
  590. #endif
  591. }
  592. void lcd_quick_feedback() {
  593. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  594. buttons = 0;
  595. next_button_update_ms = millis() + 500;
  596. // Buzz and wait. The delay is needed for buttons to settle!
  597. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  598. #if ENABLED(LCD_USE_I2C_BUZZER)
  599. delay(10);
  600. #elif PIN_EXISTS(BEEPER)
  601. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  602. #endif
  603. }
  604. void lcd_completion_feedback(const bool good/*=true*/) {
  605. if (good) {
  606. lcd_buzz(100, 659);
  607. lcd_buzz(100, 698);
  608. }
  609. else lcd_buzz(20, 440);
  610. }
  611. inline void line_to_current_z() {
  612. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[Z_AXIS]), active_extruder);
  613. }
  614. inline void line_to_z(const float &z) {
  615. current_position[Z_AXIS] = z;
  616. line_to_current_z();
  617. }
  618. #if ENABLED(SDSUPPORT)
  619. void lcd_sdcard_pause() {
  620. card.pauseSDPrint();
  621. print_job_timer.pause();
  622. #if ENABLED(PARK_HEAD_ON_PAUSE)
  623. enqueue_and_echo_commands_P(PSTR("M125"));
  624. #endif
  625. lcd_setstatusPGM(PSTR(MSG_PRINT_PAUSED), -1);
  626. }
  627. void lcd_sdcard_resume() {
  628. #if ENABLED(PARK_HEAD_ON_PAUSE)
  629. enqueue_and_echo_commands_P(PSTR("M24"));
  630. #else
  631. card.startFileprint();
  632. print_job_timer.start();
  633. #endif
  634. lcd_reset_status();
  635. }
  636. void lcd_sdcard_stop() {
  637. card.stopSDPrint();
  638. clear_command_queue();
  639. quickstop_stepper();
  640. print_job_timer.stop();
  641. thermalManager.disable_all_heaters();
  642. #if FAN_COUNT > 0
  643. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  644. #endif
  645. wait_for_heatup = false;
  646. lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
  647. lcd_return_to_status();
  648. }
  649. #endif // SDSUPPORT
  650. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  651. extern int case_light_brightness;
  652. extern bool case_light_on;
  653. extern void update_case_light();
  654. void case_light_menu() {
  655. START_MENU();
  656. //
  657. // ^ Main
  658. //
  659. MENU_BACK(MSG_MAIN);
  660. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CASE_LIGHT_BRIGHTNESS, &case_light_brightness, 0, 255, update_case_light, true);
  661. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  662. END_MENU();
  663. }
  664. #endif // MENU_ITEM_CASE_LIGHT
  665. #if ENABLED(BLTOUCH)
  666. /**
  667. *
  668. * "BLTouch" submenu
  669. *
  670. */
  671. static void bltouch_menu() {
  672. START_MENU();
  673. //
  674. // ^ Main
  675. //
  676. MENU_BACK(MSG_MAIN);
  677. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  678. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  679. MENU_ITEM(gcode, MSG_BLTOUCH_DEPLOY, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_DEPLOY)));
  680. MENU_ITEM(gcode, MSG_BLTOUCH_STOW, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_STOW)));
  681. END_MENU();
  682. }
  683. #endif // BLTOUCH
  684. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  685. static void progress_bar_test() {
  686. static int8_t bar_percent = 0;
  687. if (lcd_clicked) {
  688. lcd_goto_previous_menu();
  689. lcd_set_custom_characters(false);
  690. return;
  691. }
  692. bar_percent += (int8_t)encoderPosition;
  693. bar_percent = constrain(bar_percent, 0, 100);
  694. encoderPosition = 0;
  695. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  696. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  697. lcd.print(itostr3(bar_percent)); lcd.write('%');
  698. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  699. }
  700. void _progress_bar_test() {
  701. lcd_goto_screen(progress_bar_test);
  702. lcd_set_custom_characters();
  703. }
  704. #endif // LCD_PROGRESS_BAR_TEST
  705. #if HAS_DEBUG_MENU
  706. void lcd_debug_menu() {
  707. START_MENU();
  708. MENU_BACK(MSG_MAIN); // ^ Main
  709. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  710. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  711. #endif
  712. END_MENU();
  713. }
  714. #endif // HAS_DEBUG_MENU
  715. #if ENABLED(CUSTOM_USER_MENUS)
  716. #ifdef USER_SCRIPT_DONE
  717. #define _DONE_SCRIPT "\n" USER_SCRIPT_DONE
  718. #else
  719. #define _DONE_SCRIPT ""
  720. #endif
  721. void _lcd_user_gcode(const char * const cmd) {
  722. enqueue_and_echo_commands_P(cmd);
  723. lcd_completion_feedback();
  724. }
  725. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  726. void lcd_user_gcode_1() { _lcd_user_gcode(PSTR(USER_GCODE_1 _DONE_SCRIPT)); }
  727. #endif
  728. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  729. void lcd_user_gcode_2() { _lcd_user_gcode(PSTR(USER_GCODE_2 _DONE_SCRIPT)); }
  730. #endif
  731. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  732. void lcd_user_gcode_3() { _lcd_user_gcode(PSTR(USER_GCODE_3 _DONE_SCRIPT)); }
  733. #endif
  734. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  735. void lcd_user_gcode_4() { _lcd_user_gcode(PSTR(USER_GCODE_4 _DONE_SCRIPT)); }
  736. #endif
  737. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  738. void lcd_user_gcode_5() { _lcd_user_gcode(PSTR(USER_GCODE_5 _DONE_SCRIPT)); }
  739. #endif
  740. void _lcd_user_menu() {
  741. START_MENU();
  742. MENU_BACK(MSG_MAIN);
  743. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  744. MENU_ITEM(function, USER_DESC_1, lcd_user_gcode_1);
  745. #endif
  746. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  747. MENU_ITEM(function, USER_DESC_2, lcd_user_gcode_2);
  748. #endif
  749. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  750. MENU_ITEM(function, USER_DESC_3, lcd_user_gcode_3);
  751. #endif
  752. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  753. MENU_ITEM(function, USER_DESC_4, lcd_user_gcode_4);
  754. #endif
  755. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  756. MENU_ITEM(function, USER_DESC_5, lcd_user_gcode_5);
  757. #endif
  758. END_MENU();
  759. }
  760. #endif
  761. /**
  762. *
  763. * "Main" menu
  764. *
  765. */
  766. void lcd_main_menu() {
  767. START_MENU();
  768. MENU_BACK(MSG_WATCH);
  769. #if ENABLED(CUSTOM_USER_MENUS)
  770. MENU_ITEM(submenu, MSG_USER_MENU, _lcd_user_menu);
  771. #endif
  772. //
  773. // Debug Menu when certain options are enabled
  774. //
  775. #if HAS_DEBUG_MENU
  776. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  777. #endif
  778. //
  779. // Set Case light on/off/brightness
  780. //
  781. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  782. if (USEABLE_HARDWARE_PWM(CASE_LIGHT_PIN)) {
  783. MENU_ITEM(submenu, MSG_CASE_LIGHT, case_light_menu);
  784. }
  785. else
  786. MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
  787. #endif
  788. if (planner.movesplanned() || IS_SD_PRINTING) {
  789. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  790. }
  791. else {
  792. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  793. }
  794. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  795. #if ENABLED(SDSUPPORT)
  796. if (card.cardOK) {
  797. if (card.isFileOpen()) {
  798. if (card.sdprinting)
  799. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  800. else
  801. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  802. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  803. }
  804. else {
  805. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  806. #if !PIN_EXISTS(SD_DETECT)
  807. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  808. #endif
  809. }
  810. }
  811. else {
  812. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  813. #if !PIN_EXISTS(SD_DETECT)
  814. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  815. #endif
  816. }
  817. #endif // SDSUPPORT
  818. #if ENABLED(LCD_INFO_MENU)
  819. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  820. #endif
  821. END_MENU();
  822. }
  823. /**
  824. *
  825. * "Tune" submenu items
  826. *
  827. */
  828. #if HAS_M206_COMMAND
  829. /**
  830. * Set the home offset based on the current_position
  831. */
  832. void lcd_set_home_offsets() {
  833. // M428 Command
  834. enqueue_and_echo_commands_P(PSTR("M428"));
  835. lcd_return_to_status();
  836. }
  837. #endif
  838. #if ENABLED(BABYSTEPPING)
  839. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  840. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  841. ENCODER_DIRECTION_NORMAL();
  842. if (encoderPosition) {
  843. const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  844. encoderPosition = 0;
  845. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  846. thermalManager.babystep_axis(axis, babystep_increment);
  847. babysteps_done += babystep_increment;
  848. }
  849. if (lcdDrawUpdate)
  850. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  851. }
  852. #if ENABLED(BABYSTEP_XY)
  853. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  854. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  855. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  856. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  857. #endif
  858. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  859. void lcd_babystep_zoffset() {
  860. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  861. defer_return_to_status = true;
  862. ENCODER_DIRECTION_NORMAL();
  863. if (encoderPosition) {
  864. const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  865. encoderPosition = 0;
  866. const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
  867. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  868. if (planner.abl_enabled)
  869. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  870. zprobe_zoffset = new_zoffset;
  871. refresh_zprobe_zoffset(true);
  872. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  873. }
  874. }
  875. if (lcdDrawUpdate)
  876. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  877. }
  878. #else // !BABYSTEP_ZPROBE_OFFSET
  879. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  880. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  881. #endif // !BABYSTEP_ZPROBE_OFFSET
  882. #endif // BABYSTEPPING
  883. #if ENABLED(AUTO_BED_LEVELING_UBL)
  884. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  885. // separate value that doesn't lose precision.
  886. static int16_t ubl_encoderPosition = 0;
  887. static void _lcd_mesh_fine_tune(const char* msg) {
  888. defer_return_to_status = true;
  889. if (ubl.encoder_diff) {
  890. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  891. ubl.encoder_diff = 0;
  892. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  893. mesh_edit_value = mesh_edit_accumulator;
  894. encoderPosition = 0;
  895. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  896. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  897. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  898. }
  899. if (lcdDrawUpdate)
  900. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  901. }
  902. void _lcd_mesh_edit_NOP() {
  903. defer_return_to_status = true;
  904. }
  905. float lcd_mesh_edit() {
  906. lcd_goto_screen(_lcd_mesh_edit_NOP);
  907. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  908. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  909. return mesh_edit_value;
  910. }
  911. void lcd_mesh_edit_setup(float initial) {
  912. mesh_edit_value = mesh_edit_accumulator = initial;
  913. lcd_goto_screen(_lcd_mesh_edit_NOP);
  914. }
  915. void _lcd_z_offset_edit() {
  916. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  917. }
  918. float lcd_z_offset_edit() {
  919. lcd_goto_screen(_lcd_z_offset_edit);
  920. return mesh_edit_value;
  921. }
  922. void lcd_z_offset_edit_setup(float initial) {
  923. mesh_edit_value = mesh_edit_accumulator = initial;
  924. lcd_goto_screen(_lcd_z_offset_edit);
  925. }
  926. #endif // AUTO_BED_LEVELING_UBL
  927. /**
  928. * Watch temperature callbacks
  929. */
  930. #if HAS_TEMP_HOTEND
  931. #if WATCH_HOTENDS
  932. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  933. #else
  934. #define _WATCH_FUNC(N) NOOP
  935. #endif
  936. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  937. #if HOTENDS > 1
  938. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  939. #if HOTENDS > 2
  940. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  941. #if HOTENDS > 3
  942. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  943. #if HOTENDS > 4
  944. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  945. #endif // HOTENDS > 4
  946. #endif // HOTENDS > 3
  947. #endif // HOTENDS > 2
  948. #endif // HOTENDS > 1
  949. #endif // HAS_TEMP_HOTEND
  950. void watch_temp_callback_bed() {
  951. #if WATCH_THE_BED
  952. thermalManager.start_watching_bed();
  953. #endif
  954. }
  955. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  956. void lcd_enqueue_filament_change() {
  957. #if ENABLED(PREVENT_COLD_EXTRUSION)
  958. if (!DEBUGGING(DRYRUN) && !thermalManager.allow_cold_extrude &&
  959. thermalManager.degTargetHotend(active_extruder) < thermalManager.extrude_min_temp) {
  960. lcd_save_previous_screen();
  961. lcd_goto_screen(lcd_advanced_pause_toocold_menu);
  962. return;
  963. }
  964. #endif
  965. lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INIT);
  966. enqueue_and_echo_commands_P(PSTR("M600 B0"));
  967. }
  968. #endif // ADVANCED_PAUSE_FEATURE
  969. /**
  970. *
  971. * "Tune" submenu
  972. *
  973. */
  974. void lcd_tune_menu() {
  975. START_MENU();
  976. //
  977. // ^ Main
  978. //
  979. MENU_BACK(MSG_MAIN);
  980. //
  981. // Speed:
  982. //
  983. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  984. // Manual bed leveling, Bed Z:
  985. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  986. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  987. #endif
  988. //
  989. // Nozzle:
  990. // Nozzle [1-4]:
  991. //
  992. #if HOTENDS == 1
  993. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  994. #else // HOTENDS > 1
  995. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  996. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  997. #if HOTENDS > 2
  998. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  999. #if HOTENDS > 3
  1000. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1001. #if HOTENDS > 4
  1002. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  1003. #endif // HOTENDS > 4
  1004. #endif // HOTENDS > 3
  1005. #endif // HOTENDS > 2
  1006. #endif // HOTENDS > 1
  1007. //
  1008. // Bed:
  1009. //
  1010. #if HAS_TEMP_BED
  1011. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1012. #endif
  1013. //
  1014. // Fan Speed:
  1015. //
  1016. #if FAN_COUNT > 0
  1017. #if HAS_FAN0
  1018. #if FAN_COUNT > 1
  1019. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1020. #else
  1021. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1022. #endif
  1023. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1024. #endif
  1025. #if HAS_FAN1
  1026. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1027. #endif
  1028. #if HAS_FAN2
  1029. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1030. #endif
  1031. #endif // FAN_COUNT > 0
  1032. //
  1033. // Flow:
  1034. // Flow [1-5]:
  1035. //
  1036. #if EXTRUDERS == 1
  1037. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  1038. #else // EXTRUDERS > 1
  1039. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  1040. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  1041. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  1042. #if EXTRUDERS > 2
  1043. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  1044. #if EXTRUDERS > 3
  1045. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  1046. #if EXTRUDERS > 4
  1047. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  1048. #endif // EXTRUDERS > 4
  1049. #endif // EXTRUDERS > 3
  1050. #endif // EXTRUDERS > 2
  1051. #endif // EXTRUDERS > 1
  1052. //
  1053. // Babystep X:
  1054. // Babystep Y:
  1055. // Babystep Z:
  1056. //
  1057. #if ENABLED(BABYSTEPPING)
  1058. #if ENABLED(BABYSTEP_XY)
  1059. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  1060. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  1061. #endif
  1062. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1063. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1064. #else
  1065. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  1066. #endif
  1067. #endif
  1068. //
  1069. // Change filament
  1070. //
  1071. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  1072. if (!thermalManager.tooColdToExtrude(active_extruder))
  1073. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1074. #endif
  1075. END_MENU();
  1076. }
  1077. /**
  1078. *
  1079. * "Driver current control" submenu items
  1080. *
  1081. */
  1082. #if ENABLED(DAC_STEPPER_CURRENT)
  1083. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  1084. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  1085. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  1086. void lcd_dac_menu() {
  1087. dac_driver_getValues();
  1088. START_MENU();
  1089. MENU_BACK(MSG_CONTROL);
  1090. MENU_ITEM_EDIT_CALLBACK(int8, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  1091. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  1092. MENU_ITEM_EDIT_CALLBACK(int8, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  1093. MENU_ITEM_EDIT_CALLBACK(int8, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  1094. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  1095. END_MENU();
  1096. }
  1097. #endif // DAC_STEPPER_CURRENT
  1098. #if HAS_MOTOR_CURRENT_PWM
  1099. void lcd_pwm_menu() {
  1100. START_MENU();
  1101. MENU_BACK(MSG_CONTROL);
  1102. #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
  1103. MENU_ITEM_EDIT_CALLBACK(long5, MSG_X MSG_Y, &stepper.motor_current_setting[0], 100, 2000, Stepper::refresh_motor_power);
  1104. #endif
  1105. #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
  1106. MENU_ITEM_EDIT_CALLBACK(long5, MSG_Z, &stepper.motor_current_setting[1], 100, 2000, Stepper::refresh_motor_power);
  1107. #endif
  1108. #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
  1109. MENU_ITEM_EDIT_CALLBACK(long5, MSG_E, &stepper.motor_current_setting[2], 100, 2000, Stepper::refresh_motor_power);
  1110. #endif
  1111. END_MENU();
  1112. }
  1113. #endif // HAS_MOTOR_CURRENT_PWM
  1114. constexpr int16_t heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  1115. /**
  1116. *
  1117. * "Prepare" submenu items
  1118. *
  1119. */
  1120. void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
  1121. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  1122. #if TEMP_SENSOR_BED != 0
  1123. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  1124. #else
  1125. UNUSED(tempb);
  1126. #endif
  1127. #if FAN_COUNT > 0
  1128. #if FAN_COUNT > 1
  1129. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  1130. #else
  1131. fanSpeeds[0] = fan;
  1132. #endif
  1133. #else
  1134. UNUSED(fan);
  1135. #endif
  1136. lcd_return_to_status();
  1137. }
  1138. #if TEMP_SENSOR_0 != 0
  1139. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1140. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1141. #if TEMP_SENSOR_BED != 0
  1142. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1143. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1144. #endif
  1145. #endif
  1146. #if HOTENDS > 1
  1147. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1148. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1149. #if TEMP_SENSOR_BED != 0
  1150. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1151. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1152. #endif
  1153. #if HOTENDS > 2
  1154. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1155. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1156. #if TEMP_SENSOR_BED != 0
  1157. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1158. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1159. #endif
  1160. #if HOTENDS > 3
  1161. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1162. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1163. #if TEMP_SENSOR_BED != 0
  1164. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1165. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1166. #endif
  1167. #if HOTENDS > 4
  1168. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1169. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1170. #if TEMP_SENSOR_BED != 0
  1171. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1172. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1173. #endif
  1174. #endif // HOTENDS > 4
  1175. #endif // HOTENDS > 3
  1176. #endif // HOTENDS > 2
  1177. void lcd_preheat_m1_all() {
  1178. #if HOTENDS > 1
  1179. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1180. #if HOTENDS > 2
  1181. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1182. #if HOTENDS > 3
  1183. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1184. #if HOTENDS > 4
  1185. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1186. #endif // HOTENDS > 4
  1187. #endif // HOTENDS > 3
  1188. #endif // HOTENDS > 2
  1189. #endif // HOTENDS > 1
  1190. #if TEMP_SENSOR_BED != 0
  1191. lcd_preheat_m1_e0();
  1192. #else
  1193. lcd_preheat_m1_e0_only();
  1194. #endif
  1195. }
  1196. void lcd_preheat_m2_all() {
  1197. #if HOTENDS > 1
  1198. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1199. #if HOTENDS > 2
  1200. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1201. #if HOTENDS > 3
  1202. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1203. #if HOTENDS > 4
  1204. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1205. #endif // HOTENDS > 4
  1206. #endif // HOTENDS > 3
  1207. #endif // HOTENDS > 2
  1208. #endif // HOTENDS > 1
  1209. #if TEMP_SENSOR_BED != 0
  1210. lcd_preheat_m2_e0();
  1211. #else
  1212. lcd_preheat_m2_e0_only();
  1213. #endif
  1214. }
  1215. #endif // HOTENDS > 1
  1216. #if TEMP_SENSOR_BED != 0
  1217. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1218. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1219. #endif
  1220. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0)
  1221. void lcd_preheat_m1_menu() {
  1222. START_MENU();
  1223. MENU_BACK(MSG_PREPARE);
  1224. #if HOTENDS == 1
  1225. #if TEMP_SENSOR_BED != 0
  1226. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1227. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1228. #else
  1229. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1230. #endif
  1231. #else
  1232. #if TEMP_SENSOR_BED != 0
  1233. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1234. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1235. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1236. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1237. #else
  1238. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1239. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1240. #endif
  1241. #if HOTENDS > 2
  1242. #if TEMP_SENSOR_BED != 0
  1243. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1244. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1245. #else
  1246. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1247. #endif
  1248. #if HOTENDS > 3
  1249. #if TEMP_SENSOR_BED != 0
  1250. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1251. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1252. #else
  1253. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1254. #endif
  1255. #if HOTENDS > 4
  1256. #if TEMP_SENSOR_BED != 0
  1257. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1258. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1259. #else
  1260. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1261. #endif
  1262. #endif // HOTENDS > 4
  1263. #endif // HOTENDS > 3
  1264. #endif // HOTENDS > 2
  1265. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1266. #endif // HOTENDS > 1
  1267. #if TEMP_SENSOR_BED != 0
  1268. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1269. #endif
  1270. END_MENU();
  1271. }
  1272. void lcd_preheat_m2_menu() {
  1273. START_MENU();
  1274. MENU_BACK(MSG_PREPARE);
  1275. #if HOTENDS == 1
  1276. #if TEMP_SENSOR_BED != 0
  1277. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1278. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1279. #else
  1280. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1281. #endif
  1282. #else
  1283. #if TEMP_SENSOR_BED != 0
  1284. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1285. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1286. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1287. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1288. #else
  1289. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1290. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1291. #endif
  1292. #if HOTENDS > 2
  1293. #if TEMP_SENSOR_BED != 0
  1294. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1295. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1296. #else
  1297. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1298. #endif
  1299. #if HOTENDS > 3
  1300. #if TEMP_SENSOR_BED != 0
  1301. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1302. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1303. #else
  1304. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1305. #endif
  1306. #if HOTENDS > 4
  1307. #if TEMP_SENSOR_BED != 0
  1308. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1309. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1310. #else
  1311. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1312. #endif
  1313. #endif // HOTENDS > 4
  1314. #endif // HOTENDS > 3
  1315. #endif // HOTENDS > 2
  1316. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1317. #endif // HOTENDS > 1
  1318. #if TEMP_SENSOR_BED != 0
  1319. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1320. #endif
  1321. END_MENU();
  1322. }
  1323. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED)
  1324. void lcd_cooldown() {
  1325. #if FAN_COUNT > 0
  1326. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1327. #endif
  1328. thermalManager.disable_all_heaters();
  1329. lcd_return_to_status();
  1330. }
  1331. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1332. void lcd_autostart_sd() {
  1333. card.autostart_index = 0;
  1334. card.setroot();
  1335. card.checkautostart(true);
  1336. }
  1337. #endif
  1338. #if ENABLED(EEPROM_SETTINGS)
  1339. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1340. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1341. #endif
  1342. #if HAS_BED_PROBE && DISABLED(BABYSTEP_ZPROBE_OFFSET)
  1343. static void lcd_refresh_zprobe_zoffset() { refresh_zprobe_zoffset(); }
  1344. #endif
  1345. #if ENABLED(LCD_BED_LEVELING)
  1346. /**
  1347. *
  1348. * "Prepare" > "Level Bed" handlers
  1349. *
  1350. */
  1351. static uint8_t manual_probe_index;
  1352. // LCD probed points are from defaults
  1353. constexpr uint8_t total_probe_points = (
  1354. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  1355. 3
  1356. #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
  1357. GRID_MAX_POINTS
  1358. #endif
  1359. );
  1360. //
  1361. // Raise Z to the "manual probe height"
  1362. // Don't return until done.
  1363. // ** This blocks the command queue! **
  1364. //
  1365. void _lcd_after_probing() {
  1366. #if MANUAL_PROBE_HEIGHT > 0
  1367. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1368. #endif
  1369. // Display "Done" screen and wait for moves to complete
  1370. #if MANUAL_PROBE_HEIGHT > 0 || ENABLED(MESH_BED_LEVELING)
  1371. lcd_synchronize(PSTR(MSG_LEVEL_BED_DONE));
  1372. #endif
  1373. lcd_goto_previous_menu();
  1374. lcd_completion_feedback();
  1375. defer_return_to_status = false;
  1376. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1377. }
  1378. #if ENABLED(MESH_BED_LEVELING)
  1379. // Utility to go to the next mesh point
  1380. inline void _manual_probe_goto_xy(float x, float y) {
  1381. #if MANUAL_PROBE_HEIGHT > 0
  1382. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT);
  1383. #endif
  1384. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1385. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1386. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1387. #if MANUAL_PROBE_HEIGHT > 0
  1388. line_to_z(LOGICAL_Z_POSITION(Z_MIN_POS));
  1389. #endif
  1390. lcd_synchronize();
  1391. }
  1392. #elif ENABLED(PROBE_MANUALLY)
  1393. bool lcd_wait_for_move;
  1394. //
  1395. // Bed leveling is done. Wait for G29 to complete.
  1396. // A flag is used so that this can release control
  1397. // and allow the command queue to be processed.
  1398. //
  1399. void _lcd_level_bed_done() {
  1400. if (!lcd_wait_for_move) _lcd_after_probing();
  1401. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1402. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1403. }
  1404. #endif
  1405. void _lcd_level_goto_next_point();
  1406. /**
  1407. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1408. */
  1409. void _lcd_level_bed_get_z() {
  1410. ENCODER_DIRECTION_NORMAL();
  1411. if (lcd_clicked) {
  1412. //
  1413. // Save the current Z position
  1414. //
  1415. #if ENABLED(MESH_BED_LEVELING)
  1416. //
  1417. // MBL records the position but doesn't move to the next one
  1418. //
  1419. mbl.set_zigzag_z(manual_probe_index, current_position[Z_AXIS]);
  1420. #endif
  1421. // If done...
  1422. if (++manual_probe_index >= total_probe_points) {
  1423. #if ENABLED(PROBE_MANUALLY)
  1424. //
  1425. // The last G29 will record and enable but not move.
  1426. //
  1427. lcd_wait_for_move = true;
  1428. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1429. lcd_goto_screen(_lcd_level_bed_done);
  1430. #elif ENABLED(MESH_BED_LEVELING)
  1431. _lcd_after_probing();
  1432. mbl.set_has_mesh(true);
  1433. mesh_probing_done();
  1434. #endif
  1435. }
  1436. else {
  1437. // MESH_BED_LEVELING: Z already stored, just move
  1438. // PROBE_MANUALLY: Send G29 to record Z, then move
  1439. _lcd_level_goto_next_point();
  1440. }
  1441. return;
  1442. }
  1443. //
  1444. // Encoder knob or keypad buttons adjust the Z position
  1445. //
  1446. if (encoderPosition) {
  1447. refresh_cmd_timeout();
  1448. const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1449. line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5));
  1450. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  1451. encoderPosition = 0;
  1452. }
  1453. //
  1454. // Draw on first display, then only on Z change
  1455. //
  1456. if (lcdDrawUpdate) {
  1457. const float v = current_position[Z_AXIS];
  1458. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1459. }
  1460. }
  1461. /**
  1462. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1463. */
  1464. void _lcd_level_bed_moving() {
  1465. if (lcdDrawUpdate) {
  1466. char msg[10];
  1467. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1468. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1469. }
  1470. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1471. #if ENABLED(PROBE_MANUALLY)
  1472. if (!lcd_wait_for_move) lcd_goto_screen(_lcd_level_bed_get_z);
  1473. #endif
  1474. }
  1475. /**
  1476. * Step 5: Initiate a move to the next point
  1477. */
  1478. void _lcd_level_goto_next_point() {
  1479. // Set the menu to display ahead of blocking call
  1480. lcd_goto_screen(_lcd_level_bed_moving);
  1481. #if ENABLED(MESH_BED_LEVELING)
  1482. int8_t px, py;
  1483. mbl.zigzag(manual_probe_index, px, py);
  1484. // Controls the loop until the move is done
  1485. _manual_probe_goto_xy(
  1486. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1487. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1488. );
  1489. // After the blocking function returns, change menus
  1490. lcd_goto_screen(_lcd_level_bed_get_z);
  1491. #elif ENABLED(PROBE_MANUALLY)
  1492. // G29 Records Z, moves, and signals when it pauses
  1493. lcd_wait_for_move = true;
  1494. enqueue_and_echo_commands_P(PSTR("G29 V1"));
  1495. #endif
  1496. }
  1497. /**
  1498. * Step 4: Display "Click to Begin", wait for click
  1499. * Move to the first probe position
  1500. */
  1501. void _lcd_level_bed_homing_done() {
  1502. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1503. if (lcd_clicked) {
  1504. manual_probe_index = 0;
  1505. _lcd_level_goto_next_point();
  1506. }
  1507. }
  1508. /**
  1509. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1510. */
  1511. void _lcd_level_bed_homing() {
  1512. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1513. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1514. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1515. lcd_goto_screen(_lcd_level_bed_homing_done);
  1516. }
  1517. #if ENABLED(PROBE_MANUALLY)
  1518. extern bool g29_in_progress;
  1519. #endif
  1520. /**
  1521. * Step 2: Continue Bed Leveling...
  1522. */
  1523. void _lcd_level_bed_continue() {
  1524. defer_return_to_status = true;
  1525. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1526. lcd_goto_screen(_lcd_level_bed_homing);
  1527. enqueue_and_echo_commands_P(PSTR("G28"));
  1528. }
  1529. static bool _level_state;
  1530. void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(_level_state); }
  1531. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1532. void _lcd_set_z_fade_height() { set_z_fade_height(planner.z_fade_height); }
  1533. #endif
  1534. /**
  1535. * Step 1: Bed Level entry-point
  1536. *
  1537. * << Prepare
  1538. * Auto Home (if homing needed)
  1539. * Leveling On/Off (if data exists, and homed)
  1540. * Level Bed
  1541. * Fade Height: --- (Req: ENABLE_LEVELING_FADE_HEIGHT)
  1542. * Mesh Z Offset: --- (Req: MESH_BED_LEVELING)
  1543. * Z Probe Offset: --- (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
  1544. * Load Settings (Req: EEPROM_SETTINGS)
  1545. * Save Settings (Req: EEPROM_SETTINGS)
  1546. */
  1547. void lcd_bed_leveling() {
  1548. START_MENU();
  1549. MENU_BACK(MSG_PREPARE);
  1550. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1551. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1552. else if (leveling_is_valid()) {
  1553. _level_state = leveling_is_active();
  1554. MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
  1555. }
  1556. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  1557. set_z_fade_height(planner.z_fade_height);
  1558. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
  1559. #endif
  1560. //
  1561. // MBL Z Offset
  1562. //
  1563. #if ENABLED(MESH_BED_LEVELING)
  1564. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1565. #endif
  1566. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  1567. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  1568. #elif HAS_BED_PROBE
  1569. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  1570. #endif
  1571. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1572. #if ENABLED(EEPROM_SETTINGS)
  1573. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  1574. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  1575. #endif
  1576. END_MENU();
  1577. }
  1578. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1579. void _lcd_ubl_level_bed();
  1580. static int16_t ubl_storage_slot = 0,
  1581. custom_hotend_temp = 190,
  1582. side_points = 3,
  1583. ubl_fillin_amount = 5,
  1584. ubl_height_amount = 1,
  1585. n_edit_pts = 1,
  1586. x_plot = 0,
  1587. y_plot = 0;
  1588. #if HAS_TEMP_BED
  1589. static int16_t custom_bed_temp = 50;
  1590. #endif
  1591. /**
  1592. * UBL Build Custom Mesh Command
  1593. */
  1594. void _lcd_ubl_build_custom_mesh() {
  1595. char UBL_LCD_GCODE[20];
  1596. enqueue_and_echo_commands_P(PSTR("G28"));
  1597. #if HAS_TEMP_BED
  1598. sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
  1599. enqueue_and_echo_command(UBL_LCD_GCODE);
  1600. #endif
  1601. sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
  1602. enqueue_and_echo_command(UBL_LCD_GCODE);
  1603. enqueue_and_echo_commands_P(PSTR("G29 P1"));
  1604. }
  1605. /**
  1606. * UBL Custom Mesh submenu
  1607. *
  1608. * << Build Mesh
  1609. * Hotend Temp: ---
  1610. * Bed Temp: ---
  1611. * Build Custom Mesh
  1612. */
  1613. void _lcd_ubl_custom_mesh() {
  1614. START_MENU();
  1615. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1616. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_HOTEND_TEMP, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
  1617. #if HAS_TEMP_BED
  1618. MENU_ITEM_EDIT(int3, MSG_UBL_CUSTOM_BED_TEMP, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 5));
  1619. #endif
  1620. MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  1621. END_MENU();
  1622. }
  1623. /**
  1624. * UBL Adjust Mesh Height Command
  1625. */
  1626. void _lcd_ubl_adjust_height_cmd() {
  1627. char UBL_LCD_GCODE[16];
  1628. const int ind = ubl_height_amount < 0 ? 6 : 7;
  1629. strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6-"));
  1630. sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
  1631. enqueue_and_echo_command(UBL_LCD_GCODE);
  1632. }
  1633. /**
  1634. * UBL Adjust Mesh Height submenu
  1635. *
  1636. * << Edit Mesh
  1637. * Height Amount: ---
  1638. * Adjust Mesh Height
  1639. * << Info Screen
  1640. */
  1641. void _lcd_ubl_height_adjust_menu() {
  1642. START_MENU();
  1643. MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
  1644. MENU_ITEM_EDIT(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9);
  1645. MENU_ITEM(function, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_adjust_height_cmd);
  1646. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1647. END_MENU();
  1648. }
  1649. /**
  1650. * UBL Edit Mesh submenu
  1651. *
  1652. * << UBL Tools
  1653. * Fine Tune All
  1654. * Fine Tune Closest
  1655. * - Adjust Mesh Height >>
  1656. * << Info Screen
  1657. */
  1658. void _lcd_ubl_edit_mesh() {
  1659. START_MENU();
  1660. MENU_BACK(MSG_UBL_TOOLS);
  1661. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  1662. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  1663. MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_height_adjust_menu);
  1664. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1665. END_MENU();
  1666. }
  1667. /**
  1668. * UBL Validate Custom Mesh Command
  1669. */
  1670. void _lcd_ubl_validate_custom_mesh() {
  1671. char UBL_LCD_GCODE[24];
  1672. const int temp =
  1673. #if HAS_TEMP_BED
  1674. custom_bed_temp
  1675. #else
  1676. 0
  1677. #endif
  1678. ;
  1679. sprintf_P(UBL_LCD_GCODE, PSTR("G28\nG26 C B%i H%i P"), temp, custom_hotend_temp);
  1680. enqueue_and_echo_command(UBL_LCD_GCODE);
  1681. }
  1682. /**
  1683. * UBL Validate Mesh submenu
  1684. *
  1685. * << UBL Tools
  1686. * PLA Mesh Validation
  1687. * ABS Mesh Validation
  1688. * Validate Custom Mesh
  1689. * << Info Screen
  1690. */
  1691. void _lcd_ubl_validate_mesh() {
  1692. START_MENU();
  1693. MENU_BACK(MSG_UBL_TOOLS);
  1694. #if HAS_TEMP_BED
  1695. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1696. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1697. #else
  1698. MENU_ITEM(gcode, MSG_UBL_VALIDATE_PLA_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  1699. MENU_ITEM(gcode, MSG_UBL_VALIDATE_ABS_MESH, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  1700. #endif
  1701. MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  1702. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1703. END_MENU();
  1704. }
  1705. /**
  1706. * UBL Grid Leveling Command
  1707. */
  1708. void _lcd_ubl_grid_level_cmd() {
  1709. char UBL_LCD_GCODE[10];
  1710. sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
  1711. enqueue_and_echo_command(UBL_LCD_GCODE);
  1712. }
  1713. /**
  1714. * UBL Grid Leveling submenu
  1715. *
  1716. * << UBL Tools
  1717. * Side points: ---
  1718. * Level Mesh
  1719. */
  1720. void _lcd_ubl_grid_level() {
  1721. START_MENU();
  1722. MENU_BACK(MSG_UBL_TOOLS);
  1723. MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  1724. MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
  1725. END_MENU();
  1726. }
  1727. /**
  1728. * UBL Mesh Leveling submenu
  1729. *
  1730. * << UBL Tools
  1731. * 3-Point Mesh Leveling
  1732. * - Grid Mesh Leveling >>
  1733. * << Info Screen
  1734. */
  1735. void _lcd_ubl_mesh_leveling() {
  1736. START_MENU();
  1737. MENU_BACK(MSG_UBL_TOOLS);
  1738. MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  1739. MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  1740. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1741. END_MENU();
  1742. }
  1743. /**
  1744. * UBL Fill-in Amount Mesh Command
  1745. */
  1746. void _lcd_ubl_fillin_amount_cmd() {
  1747. char UBL_LCD_GCODE[16];
  1748. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  1749. enqueue_and_echo_command(UBL_LCD_GCODE);
  1750. }
  1751. /**
  1752. * UBL Smart Fill-in Command
  1753. */
  1754. void _lcd_ubl_smart_fillin_cmd() {
  1755. char UBL_LCD_GCODE[12];
  1756. sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 T0"));
  1757. enqueue_and_echo_command(UBL_LCD_GCODE);
  1758. }
  1759. /**
  1760. * UBL Fill-in Mesh submenu
  1761. *
  1762. * << Build Mesh
  1763. * Fill-in Amount: ---
  1764. * Fill-in Mesh
  1765. * Smart Fill-in
  1766. * Manual Fill-in
  1767. * << Info Screen
  1768. */
  1769. void _lcd_ubl_fillin_menu() {
  1770. START_MENU();
  1771. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  1772. MENU_ITEM_EDIT(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9);
  1773. MENU_ITEM(function, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_amount_cmd);
  1774. MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
  1775. MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  1776. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1777. END_MENU();
  1778. }
  1779. void _lcd_ubl_invalidate() {
  1780. ubl.invalidate();
  1781. SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
  1782. }
  1783. /**
  1784. * UBL Build Mesh submenu
  1785. *
  1786. * << UBL Tools
  1787. * Build PLA Mesh
  1788. * Build ABS Mesh
  1789. * - Build Custom Mesh >>
  1790. * Build Cold Mesh
  1791. * - Fill-in Mesh >>
  1792. * Continue Bed Mesh
  1793. * Invalidate All
  1794. * Invalidate Closest
  1795. * << Info Screen
  1796. */
  1797. void _lcd_ubl_build_mesh() {
  1798. START_MENU();
  1799. MENU_BACK(MSG_UBL_TOOLS);
  1800. #if HAS_TEMP_BED
  1801. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1802. "G28\n"
  1803. "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
  1804. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1805. "G29 P1\n"
  1806. "M104 S0\n"
  1807. "M140 S0"
  1808. ));
  1809. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1810. "G28\n"
  1811. "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
  1812. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1813. "G29 P1\n"
  1814. "M104 S0\n"
  1815. "M140 S0"
  1816. ));
  1817. #else
  1818. MENU_ITEM(gcode, MSG_UBL_BUILD_PLA_MESH, PSTR(
  1819. "G28\n"
  1820. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  1821. "G29 P1\n"
  1822. "M104 S0"
  1823. ));
  1824. MENU_ITEM(gcode, MSG_UBL_BUILD_ABS_MESH, PSTR(
  1825. "G28\n"
  1826. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  1827. "G29 P1\n"
  1828. "M104 S0"
  1829. ));
  1830. #endif
  1831. MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  1832. MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  1833. MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_menu);
  1834. MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  1835. MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  1836. MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  1837. MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
  1838. END_MENU();
  1839. }
  1840. /**
  1841. * UBL Load Mesh Command
  1842. */
  1843. void _lcd_ubl_load_mesh_cmd() {
  1844. char UBL_LCD_GCODE[8];
  1845. sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
  1846. enqueue_and_echo_command(UBL_LCD_GCODE);
  1847. }
  1848. /**
  1849. * UBL Save Mesh Command
  1850. */
  1851. void _lcd_ubl_save_mesh_cmd() {
  1852. char UBL_LCD_GCODE[8];
  1853. sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
  1854. enqueue_and_echo_command(UBL_LCD_GCODE);
  1855. }
  1856. /**
  1857. * UBL Mesh Storage submenu
  1858. *
  1859. * << Unified Bed Leveling
  1860. * Memory Slot: ---
  1861. * Load Bed Mesh
  1862. * Save Bed Mesh
  1863. */
  1864. void _lcd_ubl_storage_mesh() {
  1865. START_MENU();
  1866. MENU_BACK(MSG_UBL_LEVEL_BED);
  1867. MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, 9);
  1868. MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  1869. MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  1870. END_MENU();
  1871. }
  1872. /**
  1873. * UBL LCD "radar" map homing
  1874. */
  1875. void _lcd_ubl_output_map_lcd();
  1876. void _lcd_ubl_map_homing() {
  1877. defer_return_to_status = true;
  1878. ubl_lcd_map_control = true; // Return to the map screen
  1879. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
  1880. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  1881. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1882. lcd_goto_screen(_lcd_ubl_output_map_lcd);
  1883. }
  1884. /**
  1885. * UBL LCD "radar" map point editing
  1886. */
  1887. void _lcd_ubl_map_lcd_edit_cmd() {
  1888. char ubl_lcd_gcode [50], str[10], str2[10];
  1889. dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
  1890. dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
  1891. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
  1892. enqueue_and_echo_command(ubl_lcd_gcode);
  1893. }
  1894. /**
  1895. * UBL LCD Map Movement
  1896. */
  1897. void ubl_map_move_to_xy() {
  1898. current_position[X_AXIS] = LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]));
  1899. current_position[Y_AXIS] = LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]));
  1900. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1901. }
  1902. /**
  1903. * UBL LCD "radar" map
  1904. */
  1905. void set_current_from_steppers_for_axis(const AxisEnum axis);
  1906. void sync_plan_position();
  1907. void _lcd_ubl_output_map_lcd() {
  1908. static int16_t step_scaler = 0;
  1909. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
  1910. return lcd_goto_screen(_lcd_ubl_map_homing);
  1911. if (lcd_clicked) return _lcd_ubl_map_lcd_edit_cmd();
  1912. ENCODER_DIRECTION_NORMAL();
  1913. if (encoderPosition) {
  1914. step_scaler += (int32_t)encoderPosition;
  1915. x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
  1916. if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM)
  1917. step_scaler = 0;
  1918. refresh_cmd_timeout();
  1919. encoderPosition = 0;
  1920. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1921. }
  1922. // Encoder to the right (++)
  1923. if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
  1924. if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
  1925. // Encoder to the left (--)
  1926. if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
  1927. if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
  1928. // Prevent underrun/overrun of plot numbers
  1929. x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
  1930. y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
  1931. // Determine number of points to edit
  1932. #if IS_KINEMATIC
  1933. n_edit_pts = 9; //TODO: Delta accessible edit points
  1934. #else
  1935. const bool xc = WITHIN(x_plot, 1, GRID_MAX_POINTS_X - 2),
  1936. yc = WITHIN(y_plot, 1, GRID_MAX_POINTS_Y - 2);
  1937. n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
  1938. #endif
  1939. if (lcdDrawUpdate) {
  1940. lcd_implementation_ubl_plot(x_plot, y_plot);
  1941. ubl_map_move_to_xy(); // Move to current location
  1942. if (planner.movesplanned() > 1) { // if the nozzle is moving, cancel the move. There is a new location
  1943. stepper.quick_stop();
  1944. set_current_from_steppers_for_axis(ALL_AXES);
  1945. sync_plan_position();
  1946. ubl_map_move_to_xy(); // Move to new location
  1947. refresh_cmd_timeout();
  1948. }
  1949. }
  1950. }
  1951. /**
  1952. * UBL Homing before LCD map
  1953. */
  1954. void _lcd_ubl_output_map_lcd_cmd() {
  1955. if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) {
  1956. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1957. enqueue_and_echo_commands_P(PSTR("G28"));
  1958. }
  1959. lcd_goto_screen(_lcd_ubl_map_homing);
  1960. }
  1961. /**
  1962. * UBL Output map submenu
  1963. *
  1964. * << Unified Bed Leveling
  1965. * Output for Host
  1966. * Output for CSV
  1967. * Off Printer Backup
  1968. * Output Mesh Map
  1969. */
  1970. void _lcd_ubl_output_map() {
  1971. START_MENU();
  1972. MENU_BACK(MSG_UBL_LEVEL_BED);
  1973. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
  1974. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
  1975. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
  1976. MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
  1977. END_MENU();
  1978. }
  1979. /**
  1980. * UBL Tools submenu
  1981. *
  1982. * << Unified Bed Leveling
  1983. * - Build Mesh >>
  1984. * - Validate Mesh >>
  1985. * - Edit Mesh >>
  1986. * - Mesh Leveling >>
  1987. */
  1988. void _lcd_ubl_tools_menu() {
  1989. START_MENU();
  1990. MENU_BACK(MSG_UBL_LEVEL_BED);
  1991. MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  1992. MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
  1993. MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  1994. MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
  1995. MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  1996. END_MENU();
  1997. }
  1998. /**
  1999. * UBL Step-By-Step submenu
  2000. *
  2001. * << Unified Bed Leveling
  2002. * 1 Build Cold Mesh
  2003. * 2 Smart Fill-in
  2004. * - 3 Validate Mesh >>
  2005. * 4 Fine Tune All
  2006. * - 5 Validate Mesh >>
  2007. * 6 Fine Tune All
  2008. * 7 Save Bed Mesh
  2009. */
  2010. void _lcd_ubl_step_by_step() {
  2011. START_MENU();
  2012. MENU_BACK(MSG_UBL_LEVEL_BED);
  2013. MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  2014. MENU_ITEM(function, "2 " MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
  2015. MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2016. MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  2017. MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  2018. MENU_ITEM(gcode, "6 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  2019. MENU_ITEM(function, "7 " MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  2020. END_MENU();
  2021. }
  2022. /**
  2023. * UBL System submenu
  2024. *
  2025. * << Prepare
  2026. * - Manually Build Mesh >>
  2027. * - Activate UBL >>
  2028. * - Deactivate UBL >>
  2029. * - Step-By-Step UBL >>
  2030. * - Mesh Storage >>
  2031. * - Output Map >>
  2032. * - UBL Tools >>
  2033. * - Output UBL Info >>
  2034. */
  2035. void _lcd_ubl_level_bed() {
  2036. START_MENU();
  2037. MENU_BACK(MSG_PREPARE);
  2038. MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  2039. MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  2040. MENU_ITEM(submenu, MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
  2041. MENU_ITEM(function, MSG_UBL_MESH_EDIT, _lcd_ubl_output_map_lcd_cmd);
  2042. MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  2043. MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  2044. MENU_ITEM(submenu, MSG_UBL_TOOLS, _lcd_ubl_tools_menu);
  2045. MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
  2046. END_MENU();
  2047. }
  2048. #endif // AUTO_BED_LEVELING_UBL
  2049. /**
  2050. *
  2051. * "Prepare" submenu
  2052. *
  2053. */
  2054. void lcd_prepare_menu() {
  2055. START_MENU();
  2056. //
  2057. // ^ Main
  2058. //
  2059. MENU_BACK(MSG_MAIN);
  2060. //
  2061. // Move Axis
  2062. //
  2063. #if ENABLED(DELTA)
  2064. if (axis_homed[Z_AXIS])
  2065. #endif
  2066. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  2067. //
  2068. // Auto Home
  2069. //
  2070. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2071. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  2072. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  2073. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  2074. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  2075. #endif
  2076. //
  2077. // Level Bed
  2078. //
  2079. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2080. MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  2081. #elif ENABLED(LCD_BED_LEVELING)
  2082. #if ENABLED(PROBE_MANUALLY)
  2083. if (!g29_in_progress)
  2084. #endif
  2085. MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
  2086. #elif PLANNER_LEVELING
  2087. MENU_ITEM(gcode, MSG_BED_LEVELING, PSTR("G28\nG29"));
  2088. #endif
  2089. #if HAS_M206_COMMAND
  2090. //
  2091. // Set Home Offsets
  2092. //
  2093. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  2094. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  2095. #endif
  2096. //
  2097. // Disable Steppers
  2098. //
  2099. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2100. //
  2101. // Change filament
  2102. //
  2103. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2104. if (!thermalManager.tooColdToExtrude(active_extruder))
  2105. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  2106. #endif
  2107. #if TEMP_SENSOR_0 != 0
  2108. //
  2109. // Cooldown
  2110. //
  2111. bool has_heat = false;
  2112. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  2113. #if HAS_TEMP_BED
  2114. if (thermalManager.target_temperature_bed) has_heat = true;
  2115. #endif
  2116. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  2117. //
  2118. // Preheat for Material 1 and 2
  2119. //
  2120. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0
  2121. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  2122. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  2123. #else
  2124. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  2125. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  2126. #endif
  2127. #endif // TEMP_SENSOR_0 != 0
  2128. //
  2129. // BLTouch Self-Test and Reset
  2130. //
  2131. #if ENABLED(BLTOUCH)
  2132. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  2133. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  2134. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  2135. #endif
  2136. //
  2137. // Switch power on/off
  2138. //
  2139. #if HAS_POWER_SWITCH
  2140. if (powersupply_on)
  2141. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  2142. else
  2143. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  2144. #endif
  2145. //
  2146. // Autostart
  2147. //
  2148. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  2149. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  2150. #endif
  2151. //
  2152. // Delta Calibration
  2153. //
  2154. #if ENABLED(DELTA_CALIBRATION_MENU)
  2155. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  2156. #endif
  2157. END_MENU();
  2158. }
  2159. float move_menu_scale;
  2160. #if ENABLED(DELTA_CALIBRATION_MENU)
  2161. void lcd_move_z();
  2162. void lcd_delta_calibrate_menu();
  2163. void _lcd_calibrate_homing() {
  2164. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  2165. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  2166. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2167. lcd_goto_previous_menu();
  2168. }
  2169. void _lcd_delta_calibrate_home() {
  2170. #if HAS_LEVELING
  2171. reset_bed_level(); // After calibration bed-level data is no longer valid
  2172. #endif
  2173. enqueue_and_echo_commands_P(PSTR("G28"));
  2174. lcd_goto_screen(_lcd_calibrate_homing);
  2175. }
  2176. void _man_probe_pt(const float &lx, const float &ly) {
  2177. #if HAS_LEVELING
  2178. reset_bed_level(); // After calibration bed-level data is no longer valid
  2179. #endif
  2180. float z_dest = LOGICAL_Z_POSITION((Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5);
  2181. line_to_z(z_dest);
  2182. current_position[X_AXIS] = LOGICAL_X_POSITION(lx);
  2183. current_position[Y_AXIS] = LOGICAL_Y_POSITION(ly);
  2184. line_to_current_z();
  2185. z_dest = LOGICAL_Z_POSITION(Z_CLEARANCE_BETWEEN_PROBES);
  2186. line_to_z(z_dest);
  2187. lcd_synchronize();
  2188. move_menu_scale = PROBE_MANUALLY_STEP;
  2189. lcd_goto_screen(lcd_move_z);
  2190. }
  2191. float lcd_probe_pt(const float &lx, const float &ly) {
  2192. _man_probe_pt(lx, ly);
  2193. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2194. defer_return_to_status = true;
  2195. wait_for_user = true;
  2196. while (wait_for_user) idle();
  2197. KEEPALIVE_STATE(IN_HANDLER);
  2198. defer_return_to_status = false;
  2199. lcd_goto_previous_menu();
  2200. return current_position[Z_AXIS];
  2201. }
  2202. void _goto_tower_x() { _man_probe_pt(cos(RADIANS(210)) * delta_calibration_radius, sin(RADIANS(210)) * delta_calibration_radius); }
  2203. void _goto_tower_y() { _man_probe_pt(cos(RADIANS(330)) * delta_calibration_radius, sin(RADIANS(330)) * delta_calibration_radius); }
  2204. void _goto_tower_z() { _man_probe_pt(cos(RADIANS( 90)) * delta_calibration_radius, sin(RADIANS( 90)) * delta_calibration_radius); }
  2205. void _goto_center() { _man_probe_pt(0,0); }
  2206. void lcd_delta_G33_settings() {
  2207. START_MENU();
  2208. MENU_BACK(MSG_DELTA_CALIBRATE);
  2209. float delta_height = DELTA_HEIGHT + home_offset[Z_AXIS], Tz = 0.00;
  2210. MENU_ITEM_EDIT(float52, "Height", &delta_height, delta_height, delta_height);
  2211. MENU_ITEM_EDIT(float43, "Ex", &endstop_adj[A_AXIS], -5.0, 5.0);
  2212. MENU_ITEM_EDIT(float43, "Ey", &endstop_adj[B_AXIS], -5.0, 5.0);
  2213. MENU_ITEM_EDIT(float43, "Ez", &endstop_adj[C_AXIS], -5.0, 5.0);
  2214. MENU_ITEM_EDIT(float52, "Radius", &delta_radius, DELTA_RADIUS - 5.0, DELTA_RADIUS + 5.0);
  2215. MENU_ITEM_EDIT(float43, "Tx", &delta_tower_angle_trim[A_AXIS], -5.0, 5.0);
  2216. MENU_ITEM_EDIT(float43, "Ty", &delta_tower_angle_trim[B_AXIS], -5.0, 5.0);
  2217. MENU_ITEM_EDIT(float43, "Tz", &Tz, -5.0, 5.0);
  2218. END_MENU();
  2219. }
  2220. void lcd_delta_calibrate_menu() {
  2221. START_MENU();
  2222. MENU_BACK(MSG_MAIN);
  2223. #if ENABLED(DELTA_AUTO_CALIBRATION)
  2224. MENU_ITEM(submenu, MSG_DELTA_SETTINGS, lcd_delta_G33_settings);
  2225. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33"));
  2226. MENU_ITEM(gcode, MSG_DELTA_HEIGHT_CALIBRATE, PSTR("G33 P1"));
  2227. #if ENABLED(EEPROM_SETTINGS)
  2228. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2229. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2230. #endif
  2231. #endif
  2232. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  2233. if (axis_homed[Z_AXIS]) {
  2234. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  2235. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  2236. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  2237. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  2238. }
  2239. END_MENU();
  2240. }
  2241. #endif // DELTA_CALIBRATION_MENU
  2242. /**
  2243. * If the most recent manual move hasn't been fed to the planner yet,
  2244. * and the planner can accept one, send immediately
  2245. */
  2246. inline void manage_manual_move() {
  2247. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  2248. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  2249. manual_move_axis = (int8_t)NO_AXIS;
  2250. }
  2251. }
  2252. /**
  2253. * Set a flag that lcd_update() should start a move
  2254. * to "current_position" after a short delay.
  2255. */
  2256. inline void manual_move_to_current(AxisEnum axis
  2257. #if E_MANUAL > 1
  2258. , int8_t eindex=-1
  2259. #endif
  2260. ) {
  2261. #if E_MANUAL > 1
  2262. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  2263. #endif
  2264. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  2265. manual_move_axis = (int8_t)axis;
  2266. }
  2267. /**
  2268. *
  2269. * "Prepare" > "Move Axis" submenu
  2270. *
  2271. */
  2272. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  2273. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2274. ENCODER_DIRECTION_NORMAL();
  2275. if (encoderPosition) {
  2276. refresh_cmd_timeout();
  2277. float min = current_position[axis] - 1000,
  2278. max = current_position[axis] + 1000;
  2279. #if HAS_SOFTWARE_ENDSTOPS
  2280. // Limit to software endstops, if enabled
  2281. if (soft_endstops_enabled) {
  2282. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  2283. min = soft_endstop_min[axis];
  2284. #endif
  2285. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  2286. max = soft_endstop_max[axis];
  2287. #endif
  2288. }
  2289. #endif
  2290. // Get the new position
  2291. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  2292. // Delta limits XY based on the current offset from center
  2293. // This assumes the center is 0,0
  2294. #if ENABLED(DELTA)
  2295. if (axis != Z_AXIS) {
  2296. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  2297. min = -max;
  2298. }
  2299. #endif
  2300. // Limit only when trying to move towards the limit
  2301. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  2302. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  2303. manual_move_to_current(axis);
  2304. encoderPosition = 0;
  2305. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2306. }
  2307. if (lcdDrawUpdate)
  2308. lcd_implementation_drawedit(name, move_menu_scale >= 0.1 ? ftostr41sign(current_position[axis]) : ftostr43sign(current_position[axis]));
  2309. }
  2310. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  2311. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  2312. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  2313. void _lcd_move_e(
  2314. #if E_MANUAL > 1
  2315. int8_t eindex=-1
  2316. #endif
  2317. ) {
  2318. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2319. ENCODER_DIRECTION_NORMAL();
  2320. if (encoderPosition) {
  2321. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  2322. encoderPosition = 0;
  2323. manual_move_to_current(E_AXIS
  2324. #if E_MANUAL > 1
  2325. , eindex
  2326. #endif
  2327. );
  2328. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2329. }
  2330. if (lcdDrawUpdate) {
  2331. PGM_P pos_label;
  2332. #if E_MANUAL == 1
  2333. pos_label = PSTR(MSG_MOVE_E);
  2334. #else
  2335. switch (eindex) {
  2336. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  2337. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  2338. #if E_MANUAL > 2
  2339. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  2340. #if E_MANUAL > 3
  2341. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  2342. #if E_MANUAL > 4
  2343. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  2344. #endif // E_MANUAL > 4
  2345. #endif // E_MANUAL > 3
  2346. #endif // E_MANUAL > 2
  2347. }
  2348. #endif // E_MANUAL > 1
  2349. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  2350. }
  2351. }
  2352. void lcd_move_e() { _lcd_move_e(); }
  2353. #if E_MANUAL > 1
  2354. void lcd_move_e0() { _lcd_move_e(0); }
  2355. void lcd_move_e1() { _lcd_move_e(1); }
  2356. #if E_MANUAL > 2
  2357. void lcd_move_e2() { _lcd_move_e(2); }
  2358. #if E_MANUAL > 3
  2359. void lcd_move_e3() { _lcd_move_e(3); }
  2360. #if E_MANUAL > 4
  2361. void lcd_move_e4() { _lcd_move_e(4); }
  2362. #endif // E_MANUAL > 4
  2363. #endif // E_MANUAL > 3
  2364. #endif // E_MANUAL > 2
  2365. #endif // E_MANUAL > 1
  2366. /**
  2367. *
  2368. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  2369. *
  2370. */
  2371. screenFunc_t _manual_move_func_ptr;
  2372. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  2373. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  2374. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  2375. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  2376. _manual_move_func_ptr = func;
  2377. START_MENU();
  2378. if (LCD_HEIGHT >= 4) {
  2379. switch(axis) {
  2380. case X_AXIS:
  2381. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  2382. case Y_AXIS:
  2383. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  2384. case Z_AXIS:
  2385. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  2386. default:
  2387. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  2388. }
  2389. }
  2390. MENU_BACK(MSG_MOVE_AXIS);
  2391. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  2392. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  2393. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  2394. END_MENU();
  2395. }
  2396. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  2397. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  2398. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  2399. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  2400. #if E_MANUAL > 1
  2401. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  2402. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  2403. #if E_MANUAL > 2
  2404. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  2405. #if E_MANUAL > 3
  2406. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  2407. #if E_MANUAL > 4
  2408. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  2409. #endif // E_MANUAL > 4
  2410. #endif // E_MANUAL > 3
  2411. #endif // E_MANUAL > 2
  2412. #endif // E_MANUAL > 1
  2413. /**
  2414. *
  2415. * "Prepare" > "Move Axis" submenu
  2416. *
  2417. */
  2418. #if IS_KINEMATIC
  2419. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  2420. #if ENABLED(DELTA)
  2421. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  2422. void lcd_lower_z_to_clip_height() {
  2423. line_to_z(delta_clip_start_height);
  2424. lcd_synchronize();
  2425. }
  2426. #else
  2427. #define _MOVE_XY_ALLOWED true
  2428. #endif
  2429. #else
  2430. #define _MOVE_XYZ_ALLOWED true
  2431. #define _MOVE_XY_ALLOWED true
  2432. #endif
  2433. void lcd_move_menu() {
  2434. START_MENU();
  2435. MENU_BACK(MSG_PREPARE);
  2436. if (_MOVE_XYZ_ALLOWED) {
  2437. if (_MOVE_XY_ALLOWED) {
  2438. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  2439. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  2440. }
  2441. #if ENABLED(DELTA)
  2442. else
  2443. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  2444. #endif
  2445. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  2446. }
  2447. else
  2448. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  2449. #if ENABLED(SWITCHING_EXTRUDER)
  2450. if (active_extruder)
  2451. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  2452. else
  2453. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  2454. #endif
  2455. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  2456. #if E_MANUAL > 1
  2457. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  2458. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  2459. #if E_MANUAL > 2
  2460. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  2461. #if E_MANUAL > 3
  2462. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  2463. #if E_MANUAL > 4
  2464. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  2465. #endif // E_MANUAL > 4
  2466. #endif // E_MANUAL > 3
  2467. #endif // E_MANUAL > 2
  2468. #endif // E_MANUAL > 1
  2469. END_MENU();
  2470. }
  2471. /**
  2472. *
  2473. * "Control" submenu
  2474. *
  2475. */
  2476. #if HAS_LCD_CONTRAST
  2477. void lcd_callback_set_contrast() { set_lcd_contrast(lcd_contrast); }
  2478. #endif
  2479. static void lcd_factory_settings() {
  2480. settings.reset();
  2481. lcd_completion_feedback();
  2482. }
  2483. void lcd_control_menu() {
  2484. START_MENU();
  2485. MENU_BACK(MSG_MAIN);
  2486. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2487. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  2488. MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
  2489. #if HAS_LCD_CONTRAST
  2490. MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, (int*)&lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
  2491. #endif
  2492. #if ENABLED(FWRETRACT)
  2493. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  2494. #endif
  2495. #if ENABLED(DAC_STEPPER_CURRENT)
  2496. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  2497. #endif
  2498. #if HAS_MOTOR_CURRENT_PWM
  2499. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_pwm_menu);
  2500. #endif
  2501. #if ENABLED(BLTOUCH)
  2502. MENU_ITEM(submenu, MSG_BLTOUCH, bltouch_menu);
  2503. #endif
  2504. #if ENABLED(EEPROM_SETTINGS)
  2505. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2506. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  2507. #endif
  2508. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  2509. #if ENABLED(EEPROM_SETTINGS)
  2510. MENU_ITEM(gcode, MSG_INIT_EEPROM, PSTR("M502\nM500")); // TODO: Add "Are You Sure?" step
  2511. #endif
  2512. END_MENU();
  2513. }
  2514. /**
  2515. *
  2516. * "Temperature" submenu
  2517. *
  2518. */
  2519. #if ENABLED(PID_AUTOTUNE_MENU)
  2520. #if ENABLED(PIDTEMP)
  2521. int16_t autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  2522. #endif
  2523. #if ENABLED(PIDTEMPBED)
  2524. int16_t autotune_temp_bed = 70;
  2525. #endif
  2526. void _lcd_autotune(int16_t e) {
  2527. char cmd[30];
  2528. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  2529. #if HAS_PID_FOR_BOTH
  2530. e < 0 ? autotune_temp_bed : autotune_temp[e]
  2531. #elif ENABLED(PIDTEMPBED)
  2532. autotune_temp_bed
  2533. #else
  2534. autotune_temp[e]
  2535. #endif
  2536. );
  2537. enqueue_and_echo_command(cmd);
  2538. }
  2539. #endif // PID_AUTOTUNE_MENU
  2540. #if ENABLED(PIDTEMP)
  2541. // Helpers for editing PID Ki & Kd values
  2542. // grab the PID value out of the temp variable; scale it; then update the PID driver
  2543. void copy_and_scalePID_i(int16_t e) {
  2544. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2545. UNUSED(e);
  2546. #endif
  2547. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  2548. thermalManager.updatePID();
  2549. }
  2550. void copy_and_scalePID_d(int16_t e) {
  2551. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  2552. UNUSED(e);
  2553. #endif
  2554. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  2555. thermalManager.updatePID();
  2556. }
  2557. #define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
  2558. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  2559. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  2560. #if ENABLED(PID_AUTOTUNE_MENU)
  2561. #define DEFINE_PIDTEMP_FUNCS(N) \
  2562. _DEFINE_PIDTEMP_BASE_FUNCS(N); \
  2563. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); } typedef void _pid_##N##_void
  2564. #else
  2565. #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N) typedef void _pid_##N##_void
  2566. #endif
  2567. DEFINE_PIDTEMP_FUNCS(0);
  2568. #if ENABLED(PID_PARAMS_PER_HOTEND)
  2569. #if HOTENDS > 1
  2570. DEFINE_PIDTEMP_FUNCS(1);
  2571. #if HOTENDS > 2
  2572. DEFINE_PIDTEMP_FUNCS(2);
  2573. #if HOTENDS > 3
  2574. DEFINE_PIDTEMP_FUNCS(3);
  2575. #if HOTENDS > 4
  2576. DEFINE_PIDTEMP_FUNCS(4);
  2577. #endif // HOTENDS > 4
  2578. #endif // HOTENDS > 3
  2579. #endif // HOTENDS > 2
  2580. #endif // HOTENDS > 1
  2581. #endif // PID_PARAMS_PER_HOTEND
  2582. #endif // PIDTEMP
  2583. /**
  2584. *
  2585. * "Control" > "Temperature" submenu
  2586. *
  2587. */
  2588. void lcd_control_temperature_menu() {
  2589. START_MENU();
  2590. //
  2591. // ^ Control
  2592. //
  2593. MENU_BACK(MSG_CONTROL);
  2594. //
  2595. // Nozzle:
  2596. // Nozzle [1-5]:
  2597. //
  2598. #if HOTENDS == 1
  2599. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2600. #else // HOTENDS > 1
  2601. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  2602. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  2603. #if HOTENDS > 2
  2604. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  2605. #if HOTENDS > 3
  2606. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  2607. #if HOTENDS > 4
  2608. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  2609. #endif // HOTENDS > 4
  2610. #endif // HOTENDS > 3
  2611. #endif // HOTENDS > 2
  2612. #endif // HOTENDS > 1
  2613. //
  2614. // Bed:
  2615. //
  2616. #if HAS_TEMP_BED
  2617. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  2618. #endif
  2619. //
  2620. // Fan Speed:
  2621. //
  2622. #if FAN_COUNT > 0
  2623. #if HAS_FAN0
  2624. #if FAN_COUNT > 1
  2625. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  2626. #else
  2627. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  2628. #endif
  2629. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  2630. #endif
  2631. #if HAS_FAN1
  2632. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  2633. #endif
  2634. #if HAS_FAN2
  2635. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  2636. #endif
  2637. #endif // FAN_COUNT > 0
  2638. //
  2639. // Autotemp, Min, Max, Fact
  2640. //
  2641. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  2642. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  2643. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  2644. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  2645. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  2646. #endif
  2647. //
  2648. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  2649. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  2650. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  2651. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  2652. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  2653. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  2654. //
  2655. #if ENABLED(PIDTEMP)
  2656. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  2657. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  2658. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  2659. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  2660. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  2661. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  2662. #if ENABLED(PID_EXTRUSION_SCALING)
  2663. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  2664. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  2665. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  2666. #else
  2667. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  2668. #endif
  2669. #if ENABLED(PID_AUTOTUNE_MENU)
  2670. #define PID_MENU_ITEMS(ELABEL, eindex) \
  2671. _PID_MENU_ITEMS(ELABEL, eindex); \
  2672. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  2673. #else
  2674. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  2675. #endif
  2676. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  2677. PID_MENU_ITEMS(" " MSG_E1, 0);
  2678. PID_MENU_ITEMS(" " MSG_E2, 1);
  2679. #if HOTENDS > 2
  2680. PID_MENU_ITEMS(" " MSG_E3, 2);
  2681. #if HOTENDS > 3
  2682. PID_MENU_ITEMS(" " MSG_E4, 3);
  2683. #if HOTENDS > 4
  2684. PID_MENU_ITEMS(" " MSG_E5, 4);
  2685. #endif // HOTENDS > 4
  2686. #endif // HOTENDS > 3
  2687. #endif // HOTENDS > 2
  2688. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2689. PID_MENU_ITEMS("", 0);
  2690. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2691. #endif // PIDTEMP
  2692. //
  2693. // Preheat Material 1 conf
  2694. //
  2695. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  2696. //
  2697. // Preheat Material 2 conf
  2698. //
  2699. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  2700. END_MENU();
  2701. }
  2702. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  2703. #if HOTENDS > 4
  2704. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  2705. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  2706. #elif HOTENDS > 3
  2707. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  2708. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  2709. #elif HOTENDS > 2
  2710. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  2711. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  2712. #elif HOTENDS > 1
  2713. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  2714. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  2715. #else
  2716. #define MINTEMP_ALL HEATER_0_MINTEMP
  2717. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  2718. #endif
  2719. START_MENU();
  2720. MENU_BACK(MSG_TEMPERATURE);
  2721. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  2722. #if TEMP_SENSOR_0 != 0
  2723. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  2724. #endif
  2725. #if TEMP_SENSOR_BED != 0
  2726. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2727. #endif
  2728. #if ENABLED(EEPROM_SETTINGS)
  2729. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2730. #endif
  2731. END_MENU();
  2732. }
  2733. /**
  2734. *
  2735. * "Temperature" > "Preheat Material 1 conf" submenu
  2736. *
  2737. */
  2738. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2739. /**
  2740. *
  2741. * "Temperature" > "Preheat Material 2 conf" submenu
  2742. *
  2743. */
  2744. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2745. /**
  2746. *
  2747. * "Control" > "Motion" submenu
  2748. *
  2749. */
  2750. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2751. #if ENABLED(DISTINCT_E_FACTORS)
  2752. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2753. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2754. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2755. #if E_STEPPERS > 2
  2756. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2757. #if E_STEPPERS > 3
  2758. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2759. #if E_STEPPERS > 4
  2760. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2761. #endif // E_STEPPERS > 4
  2762. #endif // E_STEPPERS > 3
  2763. #endif // E_STEPPERS > 2
  2764. #endif
  2765. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2766. #if ENABLED(DISTINCT_E_FACTORS)
  2767. void _planner_refresh_e_positioning(const uint8_t e) {
  2768. if (e == active_extruder)
  2769. _planner_refresh_positioning();
  2770. else
  2771. planner.steps_to_mm[E_AXIS + e] = 1.0 / planner.axis_steps_per_mm[E_AXIS + e];
  2772. }
  2773. void _planner_refresh_e0_positioning() { _planner_refresh_e_positioning(0); }
  2774. void _planner_refresh_e1_positioning() { _planner_refresh_e_positioning(1); }
  2775. #if E_STEPPERS > 2
  2776. void _planner_refresh_e2_positioning() { _planner_refresh_e_positioning(2); }
  2777. #if E_STEPPERS > 3
  2778. void _planner_refresh_e3_positioning() { _planner_refresh_e_positioning(3); }
  2779. #if E_STEPPERS > 4
  2780. void _planner_refresh_e4_positioning() { _planner_refresh_e_positioning(4); }
  2781. #endif // E_STEPPERS > 4
  2782. #endif // E_STEPPERS > 3
  2783. #endif // E_STEPPERS > 2
  2784. #endif
  2785. // M203 / M205 Velocity options
  2786. void lcd_control_motion_velocity_menu() {
  2787. START_MENU();
  2788. MENU_BACK(MSG_MOTION);
  2789. // M203 Max Feedrate
  2790. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2791. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2792. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2793. #if ENABLED(DISTINCT_E_FACTORS)
  2794. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2795. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2796. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2797. #if E_STEPPERS > 2
  2798. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2799. #if E_STEPPERS > 3
  2800. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2801. #if E_STEPPERS > 4
  2802. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2803. #endif // E_STEPPERS > 4
  2804. #endif // E_STEPPERS > 3
  2805. #endif // E_STEPPERS > 2
  2806. #else
  2807. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2808. #endif
  2809. // M205 S Min Feedrate
  2810. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2811. // M205 T Min Travel Feedrate
  2812. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2813. END_MENU();
  2814. }
  2815. // M201 / M204 Accelerations
  2816. void lcd_control_motion_acceleration_menu() {
  2817. START_MENU();
  2818. MENU_BACK(MSG_MOTION);
  2819. // M204 P Acceleration
  2820. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2821. // M204 R Retract Acceleration
  2822. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2823. // M204 T Travel Acceleration
  2824. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2825. // M201 settings
  2826. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2827. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2828. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2829. #if ENABLED(DISTINCT_E_FACTORS)
  2830. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2831. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2832. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2833. #if E_STEPPERS > 2
  2834. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2835. #if E_STEPPERS > 3
  2836. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2837. #if E_STEPPERS > 4
  2838. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2839. #endif // E_STEPPERS > 4
  2840. #endif // E_STEPPERS > 3
  2841. #endif // E_STEPPERS > 2
  2842. #else
  2843. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2844. #endif
  2845. END_MENU();
  2846. }
  2847. // M205 Jerk
  2848. void lcd_control_motion_jerk_menu() {
  2849. START_MENU();
  2850. MENU_BACK(MSG_MOTION);
  2851. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2852. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2853. #if ENABLED(DELTA)
  2854. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2855. #else
  2856. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2857. #endif
  2858. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2859. END_MENU();
  2860. }
  2861. // M92 Steps-per-mm
  2862. void lcd_control_motion_steps_per_mm_menu() {
  2863. START_MENU();
  2864. MENU_BACK(MSG_MOTION);
  2865. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2866. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2867. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2868. #if ENABLED(DISTINCT_E_FACTORS)
  2869. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2870. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2871. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2872. #if E_STEPPERS > 2
  2873. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2874. #if E_STEPPERS > 3
  2875. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2876. #if E_STEPPERS > 4
  2877. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2878. #endif // E_STEPPERS > 4
  2879. #endif // E_STEPPERS > 3
  2880. #endif // E_STEPPERS > 2
  2881. #else
  2882. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2883. #endif
  2884. END_MENU();
  2885. }
  2886. void lcd_control_motion_menu() {
  2887. START_MENU();
  2888. MENU_BACK(MSG_CONTROL);
  2889. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2890. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2891. #elif HAS_BED_PROBE
  2892. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  2893. #endif
  2894. // M203 / M205 - Feedrate items
  2895. MENU_ITEM(submenu, MSG_VELOCITY, lcd_control_motion_velocity_menu);
  2896. // M201 - Acceleration items
  2897. MENU_ITEM(submenu, MSG_ACCELERATION, lcd_control_motion_acceleration_menu);
  2898. // M205 - Max Jerk
  2899. MENU_ITEM(submenu, MSG_JERK, lcd_control_motion_jerk_menu);
  2900. // M92 - Steps Per mm
  2901. MENU_ITEM(submenu, MSG_STEPS_PER_MM, lcd_control_motion_steps_per_mm_menu);
  2902. // M540 S - Abort on endstop hit when SD printing
  2903. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2904. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2905. #endif
  2906. END_MENU();
  2907. }
  2908. /**
  2909. *
  2910. * "Control" > "Filament" submenu
  2911. *
  2912. */
  2913. void lcd_control_filament_menu() {
  2914. START_MENU();
  2915. MENU_BACK(MSG_CONTROL);
  2916. #if ENABLED(LIN_ADVANCE)
  2917. MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
  2918. #endif
  2919. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  2920. if (volumetric_enabled) {
  2921. #if EXTRUDERS == 1
  2922. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2923. #else // EXTRUDERS > 1
  2924. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2925. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  2926. #if EXTRUDERS > 2
  2927. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  2928. #if EXTRUDERS > 3
  2929. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  2930. #if EXTRUDERS > 4
  2931. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  2932. #endif // EXTRUDERS > 4
  2933. #endif // EXTRUDERS > 3
  2934. #endif // EXTRUDERS > 2
  2935. #endif // EXTRUDERS > 1
  2936. }
  2937. END_MENU();
  2938. }
  2939. /**
  2940. *
  2941. * "Control" > "Retract" submenu
  2942. *
  2943. */
  2944. #if ENABLED(FWRETRACT)
  2945. void lcd_control_retract_menu() {
  2946. START_MENU();
  2947. MENU_BACK(MSG_CONTROL);
  2948. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  2949. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  2950. #if EXTRUDERS > 1
  2951. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &swap_retract_length, 0, 100);
  2952. #endif
  2953. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  2954. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  2955. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  2956. #if EXTRUDERS > 1
  2957. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &swap_retract_recover_length, -100, 100);
  2958. #endif
  2959. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  2960. END_MENU();
  2961. }
  2962. #endif // FWRETRACT
  2963. #if ENABLED(SDSUPPORT)
  2964. #if !PIN_EXISTS(SD_DETECT)
  2965. void lcd_sd_refresh() {
  2966. card.initsd();
  2967. encoderTopLine = 0;
  2968. }
  2969. #endif
  2970. void lcd_sd_updir() {
  2971. card.updir();
  2972. encoderTopLine = 0;
  2973. screen_changed = true;
  2974. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2975. }
  2976. /**
  2977. *
  2978. * "Print from SD" submenu
  2979. *
  2980. */
  2981. void lcd_sdcard_menu() {
  2982. ENCODER_DIRECTION_MENUS();
  2983. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  2984. const uint16_t fileCnt = card.getnrfilenames();
  2985. START_MENU();
  2986. MENU_BACK(MSG_MAIN);
  2987. card.getWorkDirName();
  2988. if (card.filename[0] == '/') {
  2989. #if !PIN_EXISTS(SD_DETECT)
  2990. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  2991. #endif
  2992. }
  2993. else {
  2994. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  2995. }
  2996. for (uint16_t i = 0; i < fileCnt; i++) {
  2997. if (_menuLineNr == _thisItemNr) {
  2998. const uint16_t nr =
  2999. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  3000. fileCnt - 1 -
  3001. #endif
  3002. i;
  3003. #if ENABLED(SDCARD_SORT_ALPHA)
  3004. card.getfilename_sorted(nr);
  3005. #else
  3006. card.getfilename(nr);
  3007. #endif
  3008. if (card.filenameIsDir)
  3009. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3010. else
  3011. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  3012. }
  3013. else {
  3014. MENU_ITEM_DUMMY();
  3015. }
  3016. }
  3017. END_MENU();
  3018. }
  3019. #endif // SDSUPPORT
  3020. #if ENABLED(LCD_INFO_MENU)
  3021. #if ENABLED(PRINTCOUNTER)
  3022. /**
  3023. *
  3024. * About Printer > Statistics submenu
  3025. *
  3026. */
  3027. void lcd_info_stats_menu() {
  3028. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3029. char buffer[21];
  3030. printStatistics stats = print_job_timer.getStats();
  3031. START_SCREEN(); // 12345678901234567890
  3032. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  3033. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  3034. duration_t elapsed = stats.printTime;
  3035. elapsed.toString(buffer);
  3036. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  3037. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3038. elapsed = stats.longestPrint;
  3039. elapsed.toString(buffer);
  3040. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  3041. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  3042. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
  3043. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  3044. STATIC_ITEM("", false, false, buffer); // 125m
  3045. END_SCREEN();
  3046. }
  3047. #endif // PRINTCOUNTER
  3048. /**
  3049. *
  3050. * About Printer > Thermistors
  3051. *
  3052. */
  3053. void lcd_info_thermistors_menu() {
  3054. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3055. START_SCREEN();
  3056. #define THERMISTOR_ID TEMP_SENSOR_0
  3057. #include "thermistornames.h"
  3058. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  3059. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  3060. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  3061. #if TEMP_SENSOR_1 != 0
  3062. #undef THERMISTOR_ID
  3063. #define THERMISTOR_ID TEMP_SENSOR_1
  3064. #include "thermistornames.h"
  3065. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  3066. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  3067. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  3068. #endif
  3069. #if TEMP_SENSOR_2 != 0
  3070. #undef THERMISTOR_ID
  3071. #define THERMISTOR_ID TEMP_SENSOR_2
  3072. #include "thermistornames.h"
  3073. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  3074. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  3075. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  3076. #endif
  3077. #if TEMP_SENSOR_3 != 0
  3078. #undef THERMISTOR_ID
  3079. #define THERMISTOR_ID TEMP_SENSOR_3
  3080. #include "thermistornames.h"
  3081. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  3082. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  3083. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  3084. #endif
  3085. #if TEMP_SENSOR_4 != 0
  3086. #undef THERMISTOR_ID
  3087. #define THERMISTOR_ID TEMP_SENSOR_4
  3088. #include "thermistornames.h"
  3089. STATIC_ITEM("T4: " THERMISTOR_NAME, false, true);
  3090. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_4_MINTEMP), false);
  3091. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false);
  3092. #endif
  3093. #if TEMP_SENSOR_BED != 0
  3094. #undef THERMISTOR_ID
  3095. #define THERMISTOR_ID TEMP_SENSOR_BED
  3096. #include "thermistornames.h"
  3097. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  3098. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  3099. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  3100. #endif
  3101. END_SCREEN();
  3102. }
  3103. /**
  3104. *
  3105. * About Printer > Board Info
  3106. *
  3107. */
  3108. void lcd_info_board_menu() {
  3109. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3110. START_SCREEN();
  3111. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  3112. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  3113. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  3114. #if POWER_SUPPLY == 0
  3115. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  3116. #elif POWER_SUPPLY == 1
  3117. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  3118. #elif POWER_SUPPLY == 2
  3119. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  3120. #endif
  3121. END_SCREEN();
  3122. }
  3123. /**
  3124. *
  3125. * About Printer > Printer Info
  3126. *
  3127. */
  3128. void lcd_info_printer_menu() {
  3129. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  3130. START_SCREEN();
  3131. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  3132. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  3133. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  3134. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  3135. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  3136. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  3137. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  3138. STATIC_ITEM(MSG_3POINT_LEVELING, true); // 3-Point Leveling
  3139. #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
  3140. STATIC_ITEM(MSG_LINEAR_LEVELING, true); // Linear Leveling
  3141. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  3142. STATIC_ITEM(MSG_BILINEAR_LEVELING, true); // Bi-linear Leveling
  3143. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  3144. STATIC_ITEM(MSG_UBL_LEVELING, true); // Unified Bed Leveling
  3145. #elif ENABLED(MESH_BED_LEVELING)
  3146. STATIC_ITEM(MSG_MESH_LEVELING, true); // Mesh Leveling
  3147. #endif
  3148. END_SCREEN();
  3149. }
  3150. /**
  3151. *
  3152. * "About Printer" submenu
  3153. *
  3154. */
  3155. void lcd_info_menu() {
  3156. START_MENU();
  3157. MENU_BACK(MSG_MAIN);
  3158. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  3159. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  3160. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  3161. #if ENABLED(PRINTCOUNTER)
  3162. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  3163. #endif
  3164. END_MENU();
  3165. }
  3166. #endif // LCD_INFO_MENU
  3167. /**
  3168. *
  3169. * Filament Change Feature Screens
  3170. *
  3171. */
  3172. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  3173. // Portions from STATIC_ITEM...
  3174. #define HOTEND_STATUS_ITEM() do { \
  3175. if (_menuLineNr == _thisItemNr) { \
  3176. if (lcdDrawUpdate) { \
  3177. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  3178. lcd_implementation_hotend_status(_lcdLineNr); \
  3179. } \
  3180. if (_skipStatic && encoderLine <= _thisItemNr) { \
  3181. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  3182. ++encoderLine; \
  3183. } \
  3184. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  3185. } \
  3186. ++_thisItemNr; \
  3187. }while(0)
  3188. void lcd_advanced_pause_toocold_menu() {
  3189. START_MENU();
  3190. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  3191. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  3192. MENU_BACK(MSG_BACK);
  3193. #if LCD_HEIGHT > 4
  3194. STATIC_ITEM(" ");
  3195. #endif
  3196. HOTEND_STATUS_ITEM();
  3197. END_MENU();
  3198. }
  3199. void lcd_advanced_pause_resume_print() {
  3200. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_RESUME_PRINT;
  3201. }
  3202. void lcd_advanced_pause_extrude_more() {
  3203. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_EXTRUDE_MORE;
  3204. }
  3205. void lcd_advanced_pause_option_menu() {
  3206. START_MENU();
  3207. #if LCD_HEIGHT > 2
  3208. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  3209. #endif
  3210. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_advanced_pause_resume_print);
  3211. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_advanced_pause_extrude_more);
  3212. END_MENU();
  3213. }
  3214. void lcd_advanced_pause_init_message() {
  3215. START_SCREEN();
  3216. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3217. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  3218. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  3219. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  3220. #define __FC_LINES_A 3
  3221. #else
  3222. #define __FC_LINES_A 2
  3223. #endif
  3224. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  3225. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  3226. #define _FC_LINES_A (__FC_LINES_A + 1)
  3227. #else
  3228. #define _FC_LINES_A __FC_LINES_A
  3229. #endif
  3230. #if LCD_HEIGHT > _FC_LINES_A + 1
  3231. STATIC_ITEM(" ");
  3232. #endif
  3233. HOTEND_STATUS_ITEM();
  3234. END_SCREEN();
  3235. }
  3236. void lcd_advanced_pause_unload_message() {
  3237. START_SCREEN();
  3238. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3239. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  3240. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  3241. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  3242. #define __FC_LINES_B 3
  3243. #else
  3244. #define __FC_LINES_B 2
  3245. #endif
  3246. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  3247. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  3248. #define _FC_LINES_B (__FC_LINES_B + 1)
  3249. #else
  3250. #define _FC_LINES_B __FC_LINES_B
  3251. #endif
  3252. #if LCD_HEIGHT > _FC_LINES_B + 1
  3253. STATIC_ITEM(" ");
  3254. #endif
  3255. HOTEND_STATUS_ITEM();
  3256. END_SCREEN();
  3257. }
  3258. void lcd_advanced_pause_wait_for_nozzles_to_heat() {
  3259. START_SCREEN();
  3260. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3261. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  3262. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  3263. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  3264. #define _FC_LINES_C 3
  3265. #else
  3266. #define _FC_LINES_C 2
  3267. #endif
  3268. #if LCD_HEIGHT > _FC_LINES_C + 1
  3269. STATIC_ITEM(" ");
  3270. #endif
  3271. HOTEND_STATUS_ITEM();
  3272. END_SCREEN();
  3273. }
  3274. void lcd_advanced_pause_heat_nozzle() {
  3275. START_SCREEN();
  3276. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3277. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  3278. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3279. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  3280. #define _FC_LINES_D 3
  3281. #else
  3282. #define _FC_LINES_D 2
  3283. #endif
  3284. #if LCD_HEIGHT > _FC_LINES_D + 1
  3285. STATIC_ITEM(" ");
  3286. #endif
  3287. HOTEND_STATUS_ITEM();
  3288. END_SCREEN();
  3289. }
  3290. void lcd_advanced_pause_insert_message() {
  3291. START_SCREEN();
  3292. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3293. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  3294. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  3295. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  3296. #define __FC_LINES_E 3
  3297. #else
  3298. #define __FC_LINES_E 2
  3299. #endif
  3300. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  3301. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  3302. #define _FC_LINES_E (__FC_LINES_E + 1)
  3303. #else
  3304. #define _FC_LINES_E __FC_LINES_E
  3305. #endif
  3306. #if LCD_HEIGHT > _FC_LINES_E + 1
  3307. STATIC_ITEM(" ");
  3308. #endif
  3309. HOTEND_STATUS_ITEM();
  3310. END_SCREEN();
  3311. }
  3312. void lcd_advanced_pause_load_message() {
  3313. START_SCREEN();
  3314. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3315. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  3316. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  3317. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  3318. #define __FC_LINES_F 3
  3319. #else
  3320. #define __FC_LINES_F 2
  3321. #endif
  3322. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  3323. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  3324. #define _FC_LINES_F (__FC_LINES_F + 1)
  3325. #else
  3326. #define _FC_LINES_F __FC_LINES_F
  3327. #endif
  3328. #if LCD_HEIGHT > _FC_LINES_F + 1
  3329. STATIC_ITEM(" ");
  3330. #endif
  3331. HOTEND_STATUS_ITEM();
  3332. END_SCREEN();
  3333. }
  3334. void lcd_advanced_pause_extrude_message() {
  3335. START_SCREEN();
  3336. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3337. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  3338. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  3339. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  3340. #define __FC_LINES_G 3
  3341. #else
  3342. #define __FC_LINES_G 2
  3343. #endif
  3344. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  3345. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  3346. #define _FC_LINES_G (__FC_LINES_G + 1)
  3347. #else
  3348. #define _FC_LINES_G __FC_LINES_G
  3349. #endif
  3350. #if LCD_HEIGHT > _FC_LINES_G + 1
  3351. STATIC_ITEM(" ");
  3352. #endif
  3353. HOTEND_STATUS_ITEM();
  3354. END_SCREEN();
  3355. }
  3356. void lcd_advanced_pause_resume_message() {
  3357. START_SCREEN();
  3358. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  3359. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  3360. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  3361. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  3362. #endif
  3363. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  3364. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  3365. #endif
  3366. END_SCREEN();
  3367. }
  3368. void lcd_advanced_pause_show_message(const AdvancedPauseMessage message) {
  3369. switch (message) {
  3370. case ADVANCED_PAUSE_MESSAGE_INIT:
  3371. defer_return_to_status = true;
  3372. lcd_goto_screen(lcd_advanced_pause_init_message);
  3373. break;
  3374. case ADVANCED_PAUSE_MESSAGE_UNLOAD:
  3375. defer_return_to_status = true;
  3376. lcd_goto_screen(lcd_advanced_pause_unload_message);
  3377. break;
  3378. case ADVANCED_PAUSE_MESSAGE_INSERT:
  3379. defer_return_to_status = true;
  3380. lcd_goto_screen(lcd_advanced_pause_insert_message);
  3381. break;
  3382. case ADVANCED_PAUSE_MESSAGE_LOAD:
  3383. defer_return_to_status = true;
  3384. lcd_goto_screen(lcd_advanced_pause_load_message);
  3385. break;
  3386. case ADVANCED_PAUSE_MESSAGE_EXTRUDE:
  3387. defer_return_to_status = true;
  3388. lcd_goto_screen(lcd_advanced_pause_extrude_message);
  3389. break;
  3390. case ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  3391. defer_return_to_status = true;
  3392. lcd_goto_screen(lcd_advanced_pause_heat_nozzle);
  3393. break;
  3394. case ADVANCED_PAUSE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  3395. defer_return_to_status = true;
  3396. lcd_goto_screen(lcd_advanced_pause_wait_for_nozzles_to_heat);
  3397. break;
  3398. case ADVANCED_PAUSE_MESSAGE_OPTION:
  3399. defer_return_to_status = true;
  3400. advanced_pause_menu_response = ADVANCED_PAUSE_RESPONSE_WAIT_FOR;
  3401. lcd_goto_screen(lcd_advanced_pause_option_menu);
  3402. break;
  3403. case ADVANCED_PAUSE_MESSAGE_RESUME:
  3404. defer_return_to_status = true;
  3405. lcd_goto_screen(lcd_advanced_pause_resume_message);
  3406. break;
  3407. case ADVANCED_PAUSE_MESSAGE_STATUS:
  3408. lcd_return_to_status();
  3409. break;
  3410. }
  3411. }
  3412. #endif // ADVANCED_PAUSE_FEATURE
  3413. /**
  3414. *
  3415. * Functions for editing single values
  3416. *
  3417. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  3418. *
  3419. * For example, DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1) expands into these functions:
  3420. *
  3421. * bool _menu_edit_int3();
  3422. * void menu_edit_int3(); // edit int16_t (interactively)
  3423. * void menu_edit_callback_int3(); // edit int16_t (interactively) with callback on completion
  3424. * void _menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  3425. * void menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  3426. * void menu_action_setting_edit_callback_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue, const screenFunc_t callback, const bool live); // edit int16_t with callback
  3427. *
  3428. * You can then use one of the menu macros to present the edit interface:
  3429. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  3430. *
  3431. * This expands into a more primitive menu item:
  3432. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3433. *
  3434. * ...which calls:
  3435. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  3436. */
  3437. #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
  3438. bool _menu_edit_ ## _name() { \
  3439. ENCODER_DIRECTION_NORMAL(); \
  3440. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3441. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  3442. if (lcdDrawUpdate) \
  3443. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  3444. if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
  3445. _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  3446. if (editValue != NULL) *((_type*)editValue) = value; \
  3447. if (liveEdit) (*callbackFunc)(); \
  3448. if (lcd_clicked) lcd_goto_previous_menu(); \
  3449. } \
  3450. return lcd_clicked; \
  3451. } \
  3452. void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
  3453. void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
  3454. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  3455. lcd_save_previous_screen(); \
  3456. \
  3457. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  3458. \
  3459. editLabel = pstr; \
  3460. editValue = ptr; \
  3461. minEditValue = minValue * _scale; \
  3462. maxEditValue = maxValue * _scale - minEditValue; \
  3463. encoderPosition = (*ptr) * _scale - minEditValue; \
  3464. } \
  3465. void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  3466. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3467. currentScreen = menu_edit_ ## _name; \
  3468. } \
  3469. void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
  3470. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  3471. currentScreen = menu_edit_callback_ ## _name; \
  3472. callbackFunc = callback; \
  3473. liveEdit = live; \
  3474. } \
  3475. typedef void _name
  3476. DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
  3477. DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
  3478. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
  3479. DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
  3480. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
  3481. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01);
  3482. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
  3483. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
  3484. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
  3485. DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01);
  3486. /**
  3487. *
  3488. * Handlers for Keypad input
  3489. *
  3490. */
  3491. #if ENABLED(ADC_KEYPAD)
  3492. inline bool handle_adc_keypad() {
  3493. static uint8_t adc_steps = 0;
  3494. if (buttons_reprapworld_keypad) {
  3495. if (adc_steps < 20) ++adc_steps;
  3496. lcd_quick_feedback();
  3497. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3498. if (encoderDirection == -1) { // side effect which signals we are inside a menu
  3499. if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM;
  3500. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM;
  3501. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_LEFT) menu_action_back();
  3502. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) lcd_return_to_status();
  3503. }
  3504. else {
  3505. const int8_t step = adc_steps > 19 ? 100 : adc_steps > 10 ? 10 : 1;
  3506. if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_DOWN) encoderPosition += ENCODER_PULSES_PER_STEP * step;
  3507. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_UP) encoderPosition -= ENCODER_PULSES_PER_STEP * step;
  3508. else if (buttons_reprapworld_keypad & EN_REPRAPWORLD_KEYPAD_RIGHT) encoderPosition = 0;
  3509. }
  3510. #if ENABLED(ADC_KEYPAD_DEBUG)
  3511. SERIAL_PROTOCOLLNPAIR("buttons_reprapworld_keypad = ", (uint32_t)buttons_reprapworld_keypad);
  3512. SERIAL_PROTOCOLLNPAIR("encoderPosition = ", (uint32_t)encoderPosition);
  3513. #endif
  3514. return true;
  3515. }
  3516. else if (!thermalManager.current_ADCKey_raw)
  3517. adc_steps = 0; // reset stepping acceleration
  3518. return false;
  3519. }
  3520. #elif ENABLED(REPRAPWORLD_KEYPAD)
  3521. void _reprapworld_keypad_move(const AxisEnum axis, const int16_t dir) {
  3522. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  3523. encoderPosition = dir;
  3524. switch (axis) {
  3525. case X_AXIS: lcd_move_x(); break;
  3526. case Y_AXIS: lcd_move_y(); break;
  3527. case Z_AXIS: lcd_move_z();
  3528. default: break;
  3529. }
  3530. }
  3531. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  3532. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  3533. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  3534. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  3535. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  3536. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  3537. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  3538. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  3539. inline void handle_reprapworld_keypad() {
  3540. static uint8_t keypad_debounce = 0;
  3541. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  3542. if (keypad_debounce > 0) keypad_debounce--;
  3543. }
  3544. else if (!keypad_debounce) {
  3545. keypad_debounce = 2;
  3546. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  3547. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  3548. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3549. #endif
  3550. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  3551. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  3552. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  3553. #endif
  3554. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  3555. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  3556. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  3557. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  3558. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  3559. }
  3560. else {
  3561. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  3562. }
  3563. }
  3564. }
  3565. #endif // REPRAPWORLD_KEYPAD
  3566. /**
  3567. *
  3568. * Menu actions
  3569. *
  3570. */
  3571. void _menu_action_back() { lcd_goto_previous_menu(); }
  3572. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  3573. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  3574. void menu_action_function(screenFunc_t func) { (*func)(); }
  3575. #if ENABLED(SDSUPPORT)
  3576. void menu_action_sdfile(const char* filename, char* longFilename) {
  3577. UNUSED(longFilename);
  3578. card.openAndPrintFile(filename);
  3579. lcd_return_to_status();
  3580. }
  3581. void menu_action_sddirectory(const char* filename, char* longFilename) {
  3582. UNUSED(longFilename);
  3583. card.chdir(filename);
  3584. encoderPosition = 0;
  3585. screen_changed = true;
  3586. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3587. }
  3588. #endif // SDSUPPORT
  3589. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  3590. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  3591. menu_action_setting_edit_bool(pstr, ptr);
  3592. (*callback)();
  3593. }
  3594. #endif // ULTIPANEL
  3595. void lcd_init() {
  3596. lcd_implementation_init(
  3597. #if ENABLED(LCD_PROGRESS_BAR)
  3598. true
  3599. #endif
  3600. );
  3601. #if ENABLED(NEWPANEL)
  3602. #if BUTTON_EXISTS(EN1)
  3603. SET_INPUT_PULLUP(BTN_EN1);
  3604. #endif
  3605. #if BUTTON_EXISTS(EN2)
  3606. SET_INPUT_PULLUP(BTN_EN2);
  3607. #endif
  3608. #if BUTTON_EXISTS(ENC)
  3609. SET_INPUT_PULLUP(BTN_ENC);
  3610. #endif
  3611. #if ENABLED(REPRAPWORLD_KEYPAD) && DISABLED(ADC_KEYPAD)
  3612. SET_OUTPUT(SHIFT_CLK);
  3613. OUT_WRITE(SHIFT_LD, HIGH);
  3614. SET_INPUT_PULLUP(SHIFT_OUT);
  3615. #endif
  3616. #if BUTTON_EXISTS(UP)
  3617. SET_INPUT(BTN_UP);
  3618. #endif
  3619. #if BUTTON_EXISTS(DWN)
  3620. SET_INPUT(BTN_DWN);
  3621. #endif
  3622. #if BUTTON_EXISTS(LFT)
  3623. SET_INPUT(BTN_LFT);
  3624. #endif
  3625. #if BUTTON_EXISTS(RT)
  3626. SET_INPUT(BTN_RT);
  3627. #endif
  3628. #else // !NEWPANEL
  3629. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  3630. SET_OUTPUT(SR_DATA_PIN);
  3631. SET_OUTPUT(SR_CLK_PIN);
  3632. #elif defined(SHIFT_CLK)
  3633. SET_OUTPUT(SHIFT_CLK);
  3634. OUT_WRITE(SHIFT_LD, HIGH);
  3635. OUT_WRITE(SHIFT_EN, LOW);
  3636. SET_INPUT_PULLUP(SHIFT_OUT);
  3637. #endif // SR_LCD_2W_NL
  3638. #endif // !NEWPANEL
  3639. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3640. SET_INPUT_PULLUP(SD_DETECT_PIN);
  3641. lcd_sd_status = 2; // UNKNOWN
  3642. #endif
  3643. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3644. slow_buttons = 0;
  3645. #endif
  3646. lcd_buttons_update();
  3647. #if ENABLED(ULTIPANEL)
  3648. encoderDiff = 0;
  3649. #endif
  3650. }
  3651. int16_t lcd_strlen(const char* s) {
  3652. int16_t i = 0, j = 0;
  3653. while (s[i]) {
  3654. if (PRINTABLE(s[i])) j++;
  3655. i++;
  3656. }
  3657. return j;
  3658. }
  3659. int16_t lcd_strlen_P(const char* s) {
  3660. int16_t j = 0;
  3661. while (pgm_read_byte(s)) {
  3662. if (PRINTABLE(pgm_read_byte(s))) j++;
  3663. s++;
  3664. }
  3665. return j;
  3666. }
  3667. bool lcd_blink() {
  3668. static uint8_t blink = 0;
  3669. static millis_t next_blink_ms = 0;
  3670. millis_t ms = millis();
  3671. if (ELAPSED(ms, next_blink_ms)) {
  3672. blink ^= 0xFF;
  3673. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  3674. }
  3675. return blink != 0;
  3676. }
  3677. /**
  3678. * Update the LCD, read encoder buttons, etc.
  3679. * - Read button states
  3680. * - Check the SD Card slot state
  3681. * - Act on RepRap World keypad input
  3682. * - Update the encoder position
  3683. * - Apply acceleration to the encoder position
  3684. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  3685. * - Reset the Info Screen timeout if there's any input
  3686. * - Update status indicators, if any
  3687. *
  3688. * Run the current LCD menu handler callback function:
  3689. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  3690. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  3691. * - Call the menu handler. Menu handlers should do the following:
  3692. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  3693. * (Encoder events automatically set lcdDrawUpdate for you.)
  3694. * - if (lcdDrawUpdate) { redraw }
  3695. * - Before exiting the handler set lcdDrawUpdate to:
  3696. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  3697. * - LCDVIEW_REDRAW_NOW to draw now (including remaining stripes).
  3698. * - LCDVIEW_CALL_REDRAW_NEXT to draw now and get LCDVIEW_REDRAW_NOW on the next loop.
  3699. * - LCDVIEW_CALL_NO_REDRAW to draw now and get LCDVIEW_NONE on the next loop.
  3700. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  3701. * so don't change lcdDrawUpdate without considering this.
  3702. *
  3703. * After the menu handler callback runs (or not):
  3704. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  3705. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  3706. *
  3707. * No worries. This function is only called from the main thread.
  3708. */
  3709. void lcd_update() {
  3710. #if ENABLED(ULTIPANEL)
  3711. static millis_t return_to_status_ms = 0;
  3712. manage_manual_move();
  3713. lcd_buttons_update();
  3714. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3715. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  3716. #else
  3717. constexpr bool UBL_CONDITION = true;
  3718. #endif
  3719. // If the action button is pressed...
  3720. if (UBL_CONDITION && LCD_CLICKED) {
  3721. if (!wait_for_unclick) { // If not waiting for a debounce release:
  3722. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  3723. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  3724. wait_for_user = false; // Any click clears wait for user
  3725. lcd_quick_feedback(); // Always make a click sound
  3726. }
  3727. }
  3728. else wait_for_unclick = false;
  3729. #endif
  3730. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3731. const bool sd_status = IS_SD_INSERTED;
  3732. if (sd_status != lcd_sd_status && lcd_detected()) {
  3733. if (sd_status) {
  3734. card.initsd();
  3735. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  3736. }
  3737. else {
  3738. card.release();
  3739. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  3740. }
  3741. lcd_sd_status = sd_status;
  3742. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3743. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3744. #if ENABLED(LCD_PROGRESS_BAR)
  3745. currentScreen == lcd_status_screen
  3746. #endif
  3747. );
  3748. }
  3749. #endif // SDSUPPORT && SD_DETECT_PIN
  3750. const millis_t ms = millis();
  3751. if (ELAPSED(ms, next_lcd_update_ms)
  3752. #if ENABLED(DOGLCD)
  3753. || drawing_screen
  3754. #endif
  3755. ) {
  3756. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  3757. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  3758. lcd_implementation_update_indicators();
  3759. #endif
  3760. #if ENABLED(ULTIPANEL)
  3761. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3762. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3763. #endif
  3764. #if ENABLED(ADC_KEYPAD)
  3765. if (handle_adc_keypad())
  3766. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3767. #elif ENABLED(REPRAPWORLD_KEYPAD)
  3768. handle_reprapworld_keypad();
  3769. #endif
  3770. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  3771. if (encoderPastThreshold || lcd_clicked) {
  3772. if (encoderPastThreshold) {
  3773. int32_t encoderMultiplier = 1;
  3774. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  3775. if (encoderRateMultiplierEnabled) {
  3776. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  3777. if (lastEncoderMovementMillis) {
  3778. // Note that the rate is always calculated between two passes through the
  3779. // loop and that the abs of the encoderDiff value is tracked.
  3780. float encoderStepRate = float(encoderMovementSteps) / float(ms - lastEncoderMovementMillis) * 1000.0;
  3781. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  3782. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  3783. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  3784. SERIAL_ECHO_START();
  3785. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3786. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3787. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3788. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3789. SERIAL_EOL();
  3790. #endif // ENCODER_RATE_MULTIPLIER_DEBUG
  3791. }
  3792. lastEncoderMovementMillis = ms;
  3793. } // encoderRateMultiplierEnabled
  3794. #endif // ENCODER_RATE_MULTIPLIER
  3795. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3796. encoderDiff = 0;
  3797. }
  3798. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3799. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3800. }
  3801. #endif // ULTIPANEL
  3802. // We arrive here every ~100ms when idling often enough.
  3803. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3804. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3805. if (
  3806. #if ENABLED(ULTIPANEL)
  3807. currentScreen == lcd_status_screen &&
  3808. #endif
  3809. !lcd_status_update_delay--
  3810. ) {
  3811. lcd_status_update_delay = 9
  3812. #if ENABLED(DOGLCD)
  3813. + 3
  3814. #endif
  3815. ;
  3816. max_display_update_time--;
  3817. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3818. }
  3819. // then we want to use 1/2 of the time only.
  3820. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3821. #if ENABLED(DOGLCD)
  3822. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3823. #else
  3824. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3825. #endif
  3826. {
  3827. #if ENABLED(DOGLCD)
  3828. if (!drawing_screen)
  3829. #endif
  3830. {
  3831. switch (lcdDrawUpdate) {
  3832. case LCDVIEW_CALL_NO_REDRAW:
  3833. lcdDrawUpdate = LCDVIEW_NONE;
  3834. break;
  3835. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3836. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3837. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3838. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3839. case LCDVIEW_NONE:
  3840. break;
  3841. } // switch
  3842. }
  3843. #if ENABLED(ADC_KEYPAD)
  3844. buttons_reprapworld_keypad = 0;
  3845. #endif
  3846. #if ENABLED(ULTIPANEL)
  3847. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3848. #else
  3849. #define CURRENTSCREEN() lcd_status_screen()
  3850. #endif
  3851. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3852. if (!drawing_screen) {
  3853. u8g.firstPage();
  3854. drawing_screen = 1;
  3855. }
  3856. lcd_setFont(FONT_MENU);
  3857. u8g.setColorIndex(1);
  3858. CURRENTSCREEN();
  3859. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3860. NOLESS(max_display_update_time, millis() - ms);
  3861. return;
  3862. }
  3863. #else
  3864. CURRENTSCREEN();
  3865. #endif
  3866. NOLESS(max_display_update_time, millis() - ms);
  3867. }
  3868. #if ENABLED(ULTIPANEL)
  3869. // Return to Status Screen after a timeout
  3870. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3871. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3872. else if (ELAPSED(ms, return_to_status_ms))
  3873. lcd_return_to_status();
  3874. #endif // ULTIPANEL
  3875. #if ENABLED(DOGLCD)
  3876. if (!drawing_screen)
  3877. #endif
  3878. {
  3879. switch (lcdDrawUpdate) {
  3880. case LCDVIEW_CLEAR_CALL_REDRAW:
  3881. lcd_implementation_clear();
  3882. case LCDVIEW_CALL_REDRAW_NEXT:
  3883. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3884. break;
  3885. case LCDVIEW_REDRAW_NOW:
  3886. lcdDrawUpdate = LCDVIEW_NONE;
  3887. break;
  3888. case LCDVIEW_NONE:
  3889. break;
  3890. } // switch
  3891. }
  3892. } // ELAPSED(ms, next_lcd_update_ms)
  3893. }
  3894. void pad_message_string() {
  3895. uint8_t i = 0, j = 0;
  3896. char c;
  3897. while ((c = lcd_status_message[i]) && j < LCD_WIDTH) {
  3898. if (PRINTABLE(c)) j++;
  3899. i++;
  3900. }
  3901. if (true
  3902. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  3903. && j < LCD_WIDTH
  3904. #endif
  3905. ) {
  3906. // pad with spaces to fill up the line
  3907. while (j++ < LCD_WIDTH) lcd_status_message[i++] = ' ';
  3908. // chop off at the edge
  3909. lcd_status_message[i] = '\0';
  3910. }
  3911. }
  3912. void lcd_finishstatus(const bool persist=false) {
  3913. pad_message_string();
  3914. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3915. UNUSED(persist);
  3916. #endif
  3917. #if ENABLED(LCD_PROGRESS_BAR)
  3918. progress_bar_ms = millis();
  3919. #if PROGRESS_MSG_EXPIRE > 0
  3920. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  3921. #endif
  3922. #endif
  3923. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3924. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  3925. previous_lcd_status_ms = millis(); //get status message to show up for a while
  3926. #endif
  3927. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  3928. status_scroll_pos = 0;
  3929. #endif
  3930. }
  3931. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  3932. void dontExpireStatus() { expire_status_ms = 0; }
  3933. #endif
  3934. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  3935. void lcd_setstatus(const char * const message, const bool persist) {
  3936. if (lcd_status_message_level > 0) return;
  3937. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  3938. lcd_finishstatus(persist);
  3939. }
  3940. void lcd_setstatusPGM(const char * const message, int8_t level) {
  3941. if (level < 0) level = lcd_status_message_level = 0;
  3942. if (level < lcd_status_message_level) return;
  3943. lcd_status_message_level = level;
  3944. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  3945. lcd_finishstatus(level > 0);
  3946. }
  3947. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  3948. if (level < lcd_status_message_level) return;
  3949. lcd_status_message_level = level;
  3950. va_list args;
  3951. va_start(args, fmt);
  3952. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  3953. va_end(args);
  3954. lcd_finishstatus(level > 0);
  3955. }
  3956. void lcd_setalertstatusPGM(const char * const message) {
  3957. lcd_setstatusPGM(message, 1);
  3958. #if ENABLED(ULTIPANEL)
  3959. lcd_return_to_status();
  3960. #endif
  3961. }
  3962. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  3963. #if HAS_LCD_CONTRAST
  3964. void set_lcd_contrast(const uint16_t value) {
  3965. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  3966. u8g.setContrast(lcd_contrast);
  3967. }
  3968. #endif
  3969. #if ENABLED(ULTIPANEL)
  3970. /**
  3971. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  3972. * These values are independent of which pins are used for EN_A and EN_B indications
  3973. * The rotary encoder part is also independent to the chipset used for the LCD
  3974. */
  3975. #if defined(EN_A) && defined(EN_B)
  3976. #define encrot0 0
  3977. #define encrot1 2
  3978. #define encrot2 3
  3979. #define encrot3 1
  3980. #endif
  3981. #define GET_BUTTON_STATES(DST) \
  3982. uint8_t new_##DST = 0; \
  3983. WRITE(SHIFT_LD, LOW); \
  3984. WRITE(SHIFT_LD, HIGH); \
  3985. for (int8_t i = 0; i < 8; i++) { \
  3986. new_##DST >>= 1; \
  3987. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  3988. WRITE(SHIFT_CLK, HIGH); \
  3989. WRITE(SHIFT_CLK, LOW); \
  3990. } \
  3991. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  3992. /**
  3993. * Read encoder buttons from the hardware registers
  3994. * Warning: This function is called from interrupt context!
  3995. */
  3996. void lcd_buttons_update() {
  3997. static uint8_t lastEncoderBits;
  3998. millis_t now = millis();
  3999. if (ELAPSED(now, next_button_update_ms)) {
  4000. #if ENABLED(NEWPANEL)
  4001. uint8_t newbutton = 0;
  4002. #if BUTTON_EXISTS(EN1)
  4003. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  4004. #endif
  4005. #if BUTTON_EXISTS(EN2)
  4006. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  4007. #endif
  4008. #if BUTTON_EXISTS(ENC)
  4009. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  4010. #endif
  4011. #if LCD_HAS_DIRECTIONAL_BUTTONS
  4012. // Manage directional buttons
  4013. #if ENABLED(REVERSE_MENU_DIRECTION)
  4014. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  4015. #else
  4016. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  4017. #endif
  4018. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  4019. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  4020. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  4021. #else
  4022. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  4023. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  4024. #endif
  4025. if (false) {
  4026. // for the else-ifs below
  4027. }
  4028. #if BUTTON_EXISTS(UP)
  4029. else if (BUTTON_PRESSED(UP)) {
  4030. encoderDiff = -(ENCODER_UD_STEPS);
  4031. next_button_update_ms = now + 300;
  4032. }
  4033. #endif
  4034. #if BUTTON_EXISTS(DWN)
  4035. else if (BUTTON_PRESSED(DWN)) {
  4036. encoderDiff = ENCODER_UD_STEPS;
  4037. next_button_update_ms = now + 300;
  4038. }
  4039. #endif
  4040. #if BUTTON_EXISTS(LFT)
  4041. else if (BUTTON_PRESSED(LFT)) {
  4042. encoderDiff = -(ENCODER_LR_PULSES);
  4043. next_button_update_ms = now + 300;
  4044. }
  4045. #endif
  4046. #if BUTTON_EXISTS(RT)
  4047. else if (BUTTON_PRESSED(RT)) {
  4048. encoderDiff = ENCODER_LR_PULSES;
  4049. next_button_update_ms = now + 300;
  4050. }
  4051. #endif
  4052. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  4053. buttons = newbutton;
  4054. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  4055. buttons |= slow_buttons;
  4056. #endif
  4057. #if ENABLED(ADC_KEYPAD)
  4058. uint8_t newbutton_reprapworld_keypad = 0;
  4059. buttons = 0;
  4060. if (buttons_reprapworld_keypad == 0) {
  4061. newbutton_reprapworld_keypad = get_ADC_keyValue();
  4062. if (WITHIN(newbutton_reprapworld_keypad, 1, 8))
  4063. buttons_reprapworld_keypad = _BV(newbutton_reprapworld_keypad - 1);
  4064. }
  4065. #elif ENABLED(REPRAPWORLD_KEYPAD)
  4066. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  4067. #endif
  4068. #else
  4069. GET_BUTTON_STATES(buttons);
  4070. #endif // !NEWPANEL
  4071. } // next_button_update_ms
  4072. // Manage encoder rotation
  4073. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  4074. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  4075. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  4076. #elif ENABLED(REVERSE_MENU_DIRECTION)
  4077. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  4078. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  4079. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  4080. #define ENCODER_DIFF_CW (encoderDiff--)
  4081. #define ENCODER_DIFF_CCW (encoderDiff++)
  4082. #else
  4083. #define ENCODER_DIFF_CW (encoderDiff++)
  4084. #define ENCODER_DIFF_CCW (encoderDiff--)
  4085. #endif
  4086. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  4087. uint8_t enc = 0;
  4088. if (buttons & EN_A) enc |= B01;
  4089. if (buttons & EN_B) enc |= B10;
  4090. if (enc != lastEncoderBits) {
  4091. switch (enc) {
  4092. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  4093. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  4094. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  4095. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  4096. }
  4097. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4098. if (ubl.has_control_of_lcd_panel) {
  4099. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  4100. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  4101. // knob has not turned.
  4102. }
  4103. #endif
  4104. lastEncoderBits = enc;
  4105. }
  4106. }
  4107. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  4108. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  4109. #else
  4110. bool lcd_detected() { return true; }
  4111. #endif
  4112. #if ENABLED(AUTO_BED_LEVELING_UBL)
  4113. void chirp_at_user() {
  4114. #if ENABLED(LCD_USE_I2C_BUZZER)
  4115. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4116. #elif PIN_EXISTS(BEEPER)
  4117. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  4118. #endif
  4119. }
  4120. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  4121. #endif
  4122. #endif // ULTIPANEL
  4123. #if ENABLED(ADC_KEYPAD)
  4124. typedef struct {
  4125. uint16_t ADCKeyValueMin, ADCKeyValueMax;
  4126. uint8_t ADCKeyNo;
  4127. } _stADCKeypadTable_;
  4128. static const _stADCKeypadTable_ stADCKeyTable[] PROGMEM = {
  4129. // VALUE_MIN, VALUE_MAX, KEY
  4130. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F1 + 1 }, // F1
  4131. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F2 + 1 }, // F2
  4132. { 4000, 4096, BLEN_REPRAPWORLD_KEYPAD_F3 + 1 }, // F3
  4133. { 300, 500, BLEN_REPRAPWORLD_KEYPAD_LEFT + 1 }, // LEFT
  4134. { 1900, 2200, BLEN_REPRAPWORLD_KEYPAD_RIGHT + 1 }, // RIGHT
  4135. { 570, 870, BLEN_REPRAPWORLD_KEYPAD_UP + 1 }, // UP
  4136. { 2670, 2870, BLEN_REPRAPWORLD_KEYPAD_DOWN + 1 }, // DOWN
  4137. { 1150, 1450, BLEN_REPRAPWORLD_KEYPAD_MIDDLE + 1 }, // ENTER
  4138. };
  4139. uint8_t get_ADC_keyValue(void) {
  4140. if (thermalManager.ADCKey_count >= 16) {
  4141. const uint16_t currentkpADCValue = thermalManager.current_ADCKey_raw >> 2;
  4142. #if ENABLED(ADC_KEYPAD_DEBUG)
  4143. SERIAL_PROTOCOLLN(currentkpADCValue);
  4144. #endif
  4145. thermalManager.current_ADCKey_raw = 0;
  4146. thermalManager.ADCKey_count = 0;
  4147. if (currentkpADCValue < 4000)
  4148. for (uint8_t i = 0; i < ADC_KEY_NUM; i++) {
  4149. const uint16_t lo = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMin),
  4150. hi = pgm_read_word(&stADCKeyTable[i].ADCKeyValueMax);
  4151. if (WITHIN(currentkpADCValue, lo, hi)) return pgm_read_byte(&stADCKeyTable[i].ADCKeyNo);
  4152. }
  4153. }
  4154. return 0;
  4155. }
  4156. #endif
  4157. #endif // ULTRA_LCD