My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ultralcd.cpp 132KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913
  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 "stepper.h"
  29. #include "configuration_store.h"
  30. #include "utility.h"
  31. #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
  32. #include "buzzer.h"
  33. #endif
  34. #if ENABLED(BLTOUCH)
  35. #include "endstops.h"
  36. #endif
  37. #if ENABLED(PRINTCOUNTER)
  38. #include "printcounter.h"
  39. #include "duration_t.h"
  40. #endif
  41. int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
  42. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  43. millis_t previous_lcd_status_ms = 0;
  44. #endif
  45. #if ENABLED(BABYSTEPPING)
  46. long babysteps_done = 0;
  47. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  48. static void lcd_babystep_zoffset();
  49. #else
  50. static void lcd_babystep_z();
  51. #endif
  52. #endif
  53. uint8_t lcd_status_message_level;
  54. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  55. #if ENABLED(DOGLCD)
  56. #include "ultralcd_impl_DOGM.h"
  57. #include <U8glib.h>
  58. #else
  59. #include "ultralcd_impl_HD44780.h"
  60. #endif
  61. // The main status screen
  62. void lcd_status_screen();
  63. millis_t next_lcd_update_ms;
  64. 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)
  65. uint16_t max_display_update_time = 0;
  66. #if ENABLED(DOGLCD)
  67. bool drawing_screen = false;
  68. #define LCDVIEW_KEEP_REDRAWING LCDVIEW_CALL_REDRAW_NEXT
  69. #else
  70. #define LCDVIEW_KEEP_REDRAWING LCDVIEW_REDRAW_NOW
  71. #endif
  72. #if ENABLED(DAC_STEPPER_CURRENT)
  73. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  74. int16_t driverPercent[XYZE];
  75. #endif
  76. #if ENABLED(ULTIPANEL)
  77. #ifndef TALL_FONT_CORRECTION
  78. #define TALL_FONT_CORRECTION 0
  79. #endif
  80. // Function pointer to menu functions.
  81. typedef void (*screenFunc_t)();
  82. #if HAS_POWER_SWITCH
  83. extern bool powersupply;
  84. #endif
  85. #if ENABLED(AUTO_BED_LEVELING_UBL)
  86. #include "ubl.h"
  87. #endif
  88. ////////////////////////////////////////////
  89. ///////////////// Menu Tree ////////////////
  90. ////////////////////////////////////////////
  91. void lcd_main_menu();
  92. void lcd_tune_menu();
  93. void lcd_prepare_menu();
  94. void lcd_move_menu();
  95. void lcd_control_menu();
  96. void lcd_control_temperature_menu();
  97. void lcd_control_temperature_preheat_material1_settings_menu();
  98. void lcd_control_temperature_preheat_material2_settings_menu();
  99. void lcd_control_motion_menu();
  100. void lcd_control_filament_menu();
  101. #if ENABLED(LCD_INFO_MENU)
  102. #if ENABLED(PRINTCOUNTER)
  103. void lcd_info_stats_menu();
  104. #endif
  105. void lcd_info_thermistors_menu();
  106. void lcd_info_board_menu();
  107. void lcd_info_menu();
  108. #endif // LCD_INFO_MENU
  109. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  110. void lcd_filament_change_toocold_menu();
  111. void lcd_filament_change_option_menu();
  112. void lcd_filament_change_init_message();
  113. void lcd_filament_change_unload_message();
  114. void lcd_filament_change_insert_message();
  115. void lcd_filament_change_load_message();
  116. void lcd_filament_change_heat_nozzle();
  117. void lcd_filament_change_extrude_message();
  118. void lcd_filament_change_resume_message();
  119. #endif
  120. #if ENABLED(DAC_STEPPER_CURRENT)
  121. void dac_driver_commit();
  122. void dac_driver_getValues();
  123. void lcd_dac_menu();
  124. void lcd_dac_write_eeprom();
  125. #endif
  126. #if HAS_LCD_CONTRAST
  127. void lcd_set_contrast();
  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. #endif
  138. ////////////////////////////////////////////
  139. //////////// Menu System Actions ///////////
  140. ////////////////////////////////////////////
  141. #define menu_action_back(dummy) _menu_action_back()
  142. void _menu_action_back();
  143. void menu_action_submenu(screenFunc_t data);
  144. void menu_action_gcode(const char* pgcode);
  145. void menu_action_function(screenFunc_t data);
  146. #define DECLARE_MENU_EDIT_TYPE(_type, _name) \
  147. bool _menu_edit_ ## _name(); \
  148. void menu_edit_ ## _name(); \
  149. void menu_edit_callback_ ## _name(); \
  150. void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
  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_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback); \
  153. void _menu_action_setting_edit_accessor_ ## _name(const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue); \
  154. void menu_action_setting_edit_accessor_ ## _name(const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue); \
  155. typedef void _name##_void
  156. DECLARE_MENU_EDIT_TYPE(int, int3);
  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(unsigned long, 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. void menu_action_setting_edit_accessor_bool(const char* pstr, bool (*pget)(), void (*pset)(bool));
  168. #if ENABLED(SDSUPPORT)
  169. void lcd_sdcard_menu();
  170. void menu_action_sdfile(const char* filename, char* longFilename);
  171. void menu_action_sddirectory(const char* filename, char* longFilename);
  172. #endif
  173. ////////////////////////////////////////////
  174. //////////// Menu System Macros ////////////
  175. ////////////////////////////////////////////
  176. #ifndef ENCODER_FEEDRATE_DEADZONE
  177. #define ENCODER_FEEDRATE_DEADZONE 10
  178. #endif
  179. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  180. #define ENCODER_STEPS_PER_MENU_ITEM 5
  181. #endif
  182. #ifndef ENCODER_PULSES_PER_STEP
  183. #define ENCODER_PULSES_PER_STEP 1
  184. #endif
  185. /**
  186. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  187. *
  188. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  189. * menu_action_[type](arg3...)
  190. *
  191. * Examples:
  192. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  193. * or
  194. * MENU_BACK(MSG_WATCH)
  195. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  196. * menu_action_back()
  197. *
  198. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  199. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  200. * menu_action_function(lcd_sdcard_pause)
  201. *
  202. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  203. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  204. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  205. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  206. *
  207. */
  208. #define _MENU_ITEM_PART_1(TYPE, LABEL, ...) \
  209. if (_menuLineNr == _thisItemNr) { \
  210. if (lcdDrawUpdate) \
  211. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  212. if (lcd_clicked && encoderLine == _thisItemNr) {
  213. #define _MENU_ITEM_PART_2(TYPE, ...) \
  214. menu_action_ ## TYPE(__VA_ARGS__); \
  215. if (screen_changed) return; \
  216. } \
  217. } \
  218. ++_thisItemNr
  219. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  220. _skipStatic = false; \
  221. _MENU_ITEM_PART_1(TYPE, LABEL, ## __VA_ARGS__); \
  222. _MENU_ITEM_PART_2(TYPE, ## __VA_ARGS__); \
  223. } while(0)
  224. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  225. // Used to print static text with no visible cursor.
  226. // Parameters: label [, bool center [, bool invert [, char *value] ] ]
  227. #define STATIC_ITEM(LABEL, ...) \
  228. if (_menuLineNr == _thisItemNr) { \
  229. if (_skipStatic && encoderLine <= _thisItemNr) { \
  230. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  231. ++encoderLine; \
  232. } \
  233. if (lcdDrawUpdate) \
  234. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  235. } \
  236. ++_thisItemNr
  237. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  238. bool encoderRateMultiplierEnabled;
  239. #define ENCODER_RATE_MULTIPLY(F) (encoderRateMultiplierEnabled = F)
  240. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  241. /**
  242. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  243. */
  244. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  245. _MENU_ITEM_PART_1(type, label, ## __VA_ARGS__); \
  246. encoderRateMultiplierEnabled = true; \
  247. lastEncoderMovementMillis = 0; \
  248. _MENU_ITEM_PART_2(type, ## __VA_ARGS__); \
  249. } while(0)
  250. #else // !ENCODER_RATE_MULTIPLIER
  251. #define ENCODER_RATE_MULTIPLY(F) NOOP
  252. #endif // !ENCODER_RATE_MULTIPLIER
  253. #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
  254. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  255. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  256. #define MENU_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
  257. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  258. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  259. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  260. #define MENU_MULTIPLIER_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
  261. #else //!ENCODER_RATE_MULTIPLIER
  262. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  263. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  264. #define MENU_MULTIPLIER_ITEM_EDIT_ACCESSOR(type, label, ...) MENU_ITEM(setting_edit_accessor_ ## type, label, PSTR(label), ## __VA_ARGS__)
  265. #endif //!ENCODER_RATE_MULTIPLIER
  266. /**
  267. * START_SCREEN_OR_MENU generates init code for a screen or menu
  268. *
  269. * encoderLine is the position based on the encoder
  270. * encoderTopLine is the top menu line to display
  271. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  272. * _menuLineNr is the menu item to draw and process
  273. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  274. * _countedItems is the total number of items in the menu (after one call)
  275. */
  276. #define START_SCREEN_OR_MENU(LIMIT) \
  277. ENCODER_DIRECTION_MENUS(); \
  278. ENCODER_RATE_MULTIPLY(false); \
  279. if (encoderPosition > 0x8000) encoderPosition = 0; \
  280. static int8_t _countedItems = 0; \
  281. int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
  282. if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
  283. encoderLine = max(0, _countedItems - (LIMIT)); \
  284. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  285. }
  286. #define SCREEN_OR_MENU_LOOP() \
  287. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  288. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
  289. _thisItemNr = 0
  290. /**
  291. * START_SCREEN Opening code for a screen having only static items.
  292. * Do simplified scrolling of the entire screen.
  293. *
  294. * START_MENU Opening code for a screen with menu items.
  295. * Scroll as-needed to keep the selected line in view.
  296. */
  297. #define START_SCREEN() \
  298. START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
  299. encoderTopLine = encoderLine; \
  300. bool _skipStatic = false; \
  301. SCREEN_OR_MENU_LOOP()
  302. #define START_MENU() \
  303. START_SCREEN_OR_MENU(1); \
  304. screen_changed = false; \
  305. NOMORE(encoderTopLine, encoderLine); \
  306. if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
  307. encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
  308. } \
  309. bool _skipStatic = true; \
  310. SCREEN_OR_MENU_LOOP()
  311. #define END_SCREEN() \
  312. } \
  313. _countedItems = _thisItemNr
  314. #define END_MENU() \
  315. } \
  316. _countedItems = _thisItemNr; \
  317. UNUSED(_skipStatic)
  318. ////////////////////////////////////////////
  319. ///////////// Global Variables /////////////
  320. ////////////////////////////////////////////
  321. /**
  322. * REVERSE_MENU_DIRECTION
  323. *
  324. * To reverse the menu direction we need a general way to reverse
  325. * the direction of the encoder everywhere. So encoderDirection is
  326. * added to allow the encoder to go the other way.
  327. *
  328. * This behavior is limited to scrolling Menus and SD card listings,
  329. * and is disabled in other contexts.
  330. */
  331. #if ENABLED(REVERSE_MENU_DIRECTION)
  332. int8_t encoderDirection = 1;
  333. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  334. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  335. #else
  336. #define ENCODER_DIRECTION_NORMAL() ;
  337. #define ENCODER_DIRECTION_MENUS() ;
  338. #endif
  339. // Encoder Movement
  340. volatile int8_t encoderDiff; // Updated in lcd_buttons_update, added to encoderPosition every LCD update
  341. uint32_t encoderPosition;
  342. millis_t lastEncoderMovementMillis = 0;
  343. // Button States
  344. bool lcd_clicked, wait_for_unclick;
  345. volatile uint8_t buttons;
  346. millis_t next_button_update_ms;
  347. #if ENABLED(REPRAPWORLD_KEYPAD)
  348. volatile uint8_t buttons_reprapworld_keypad;
  349. #endif
  350. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  351. volatile uint8_t slow_buttons;
  352. #endif
  353. // Menu System Navigation
  354. screenFunc_t currentScreen = lcd_status_screen;
  355. int8_t encoderTopLine;
  356. typedef struct {
  357. screenFunc_t menu_function;
  358. uint32_t encoder_position;
  359. } menuPosition;
  360. menuPosition screen_history[6];
  361. uint8_t screen_history_depth = 0;
  362. bool screen_changed, defer_return_to_status;
  363. // Value Editing
  364. const char *editLabel;
  365. void *editValue, *editSetter;
  366. int32_t minEditValue, maxEditValue;
  367. screenFunc_t callbackFunc;
  368. // Manual Moves
  369. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  370. millis_t manual_move_start_time = 0;
  371. int8_t manual_move_axis = (int8_t)NO_AXIS;
  372. #if EXTRUDERS > 1
  373. int8_t manual_move_e_index = 0;
  374. #else
  375. #define manual_move_e_index 0
  376. #endif
  377. #if PIN_EXISTS(SD_DETECT)
  378. uint8_t lcd_sd_status;
  379. #endif
  380. #if ENABLED(PIDTEMP)
  381. float raw_Ki, raw_Kd; // place-holders for Ki and Kd edits
  382. #endif
  383. /**
  384. * General function to go directly to a screen
  385. */
  386. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0) {
  387. if (currentScreen != screen) {
  388. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  389. static millis_t doubleclick_expire_ms = 0;
  390. // Going to lcd_main_menu from status screen? Remember first click time.
  391. // Going back to status screen within a very short time? Go to Z babystepping.
  392. if (screen == lcd_main_menu) {
  393. if (currentScreen == lcd_status_screen)
  394. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  395. }
  396. else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
  397. screen =
  398. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  399. lcd_babystep_zoffset
  400. #else
  401. lcd_babystep_z
  402. #endif
  403. ;
  404. #endif
  405. currentScreen = screen;
  406. encoderPosition = encoder;
  407. if (screen == lcd_status_screen) {
  408. defer_return_to_status = false;
  409. screen_history_depth = 0;
  410. }
  411. lcd_implementation_clear();
  412. #if ENABLED(LCD_PROGRESS_BAR)
  413. // For LCD_PROGRESS_BAR re-initialize custom characters
  414. lcd_set_custom_characters(screen == lcd_status_screen);
  415. #endif
  416. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  417. screen_changed = true;
  418. #if ENABLED(DOGLCD)
  419. drawing_screen = false;
  420. #endif
  421. }
  422. }
  423. /**
  424. * Synchronize safely while holding the current screen
  425. * This blocks all further screen or stripe updates once called
  426. */
  427. extern uint8_t commands_in_queue;
  428. inline void lcd_synchronize() {
  429. static bool no_reentry = false;
  430. lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_MOVING));
  431. if (no_reentry) return;
  432. no_reentry = true;
  433. screenFunc_t old_screen = currentScreen;
  434. lcd_goto_screen(lcd_synchronize);
  435. while (commands_in_queue) {
  436. idle();
  437. stepper.synchronize();
  438. }
  439. no_reentry = false;
  440. lcd_goto_screen(old_screen);
  441. }
  442. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  443. void lcd_save_previous_screen() {
  444. if (screen_history_depth < COUNT(screen_history)) {
  445. screen_history[screen_history_depth].menu_function = currentScreen;
  446. screen_history[screen_history_depth].encoder_position = encoderPosition;
  447. ++screen_history_depth;
  448. }
  449. }
  450. void lcd_goto_previous_menu() {
  451. if (screen_history_depth > 0) {
  452. --screen_history_depth;
  453. lcd_goto_screen(
  454. screen_history[screen_history_depth].menu_function,
  455. screen_history[screen_history_depth].encoder_position
  456. );
  457. }
  458. else
  459. lcd_return_to_status();
  460. }
  461. #endif // ULTIPANEL
  462. /**
  463. *
  464. * "Info Screen"
  465. *
  466. * This is very display-dependent, so the lcd implementation draws this.
  467. */
  468. void lcd_status_screen() {
  469. #if ENABLED(ULTIPANEL)
  470. ENCODER_DIRECTION_NORMAL();
  471. ENCODER_RATE_MULTIPLY(false);
  472. #endif
  473. #if ENABLED(LCD_PROGRESS_BAR)
  474. millis_t ms = millis();
  475. #if DISABLED(PROGRESS_MSG_ONCE)
  476. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  477. progress_bar_ms = ms;
  478. }
  479. #endif
  480. #if PROGRESS_MSG_EXPIRE > 0
  481. // Handle message expire
  482. if (expire_status_ms > 0) {
  483. #if ENABLED(SDSUPPORT)
  484. if (card.isFileOpen()) {
  485. // Expire the message when printing is active
  486. if (IS_SD_PRINTING) {
  487. if (ELAPSED(ms, expire_status_ms)) {
  488. lcd_status_message[0] = '\0';
  489. expire_status_ms = 0;
  490. }
  491. }
  492. else {
  493. expire_status_ms += LCD_UPDATE_INTERVAL;
  494. }
  495. }
  496. else {
  497. expire_status_ms = 0;
  498. }
  499. #else
  500. expire_status_ms = 0;
  501. #endif //SDSUPPORT
  502. }
  503. #endif
  504. #endif //LCD_PROGRESS_BAR
  505. lcd_implementation_status_screen();
  506. #if ENABLED(ULTIPANEL)
  507. if (lcd_clicked) {
  508. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  509. previous_lcd_status_ms = millis(); // get status message to show up for a while
  510. #endif
  511. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  512. #if ENABLED(LCD_PROGRESS_BAR)
  513. false
  514. #endif
  515. );
  516. lcd_goto_screen(lcd_main_menu);
  517. }
  518. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  519. int new_frm = feedrate_percentage + (int32_t)encoderPosition;
  520. // Dead zone at 100% feedrate
  521. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  522. feedrate_percentage = 100;
  523. encoderPosition = 0;
  524. }
  525. else if (feedrate_percentage == 100) {
  526. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  527. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  528. encoderPosition = 0;
  529. }
  530. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  531. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  532. encoderPosition = 0;
  533. }
  534. }
  535. else {
  536. feedrate_percentage = new_frm;
  537. encoderPosition = 0;
  538. }
  539. #endif // ULTIPANEL_FEEDMULTIPLY
  540. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  541. #endif //ULTIPANEL
  542. }
  543. /**
  544. *
  545. * draw the kill screen
  546. *
  547. */
  548. void kill_screen(const char* lcd_msg) {
  549. lcd_init();
  550. lcd_setalertstatuspgm(lcd_msg);
  551. #if ENABLED(DOGLCD)
  552. u8g.firstPage();
  553. do {
  554. lcd_kill_screen();
  555. } while (u8g.nextPage());
  556. #else
  557. lcd_kill_screen();
  558. #endif
  559. }
  560. #if ENABLED(ULTIPANEL)
  561. /**
  562. *
  563. * Audio feedback for controller clicks
  564. *
  565. */
  566. void lcd_buzz(long duration, uint16_t freq) {
  567. #if ENABLED(LCD_USE_I2C_BUZZER)
  568. lcd.buzz(duration, freq);
  569. #elif PIN_EXISTS(BEEPER)
  570. buzzer.tone(duration, freq);
  571. #else
  572. UNUSED(duration); UNUSED(freq);
  573. #endif
  574. }
  575. void lcd_quick_feedback() {
  576. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  577. buttons = 0;
  578. next_button_update_ms = millis() + 500;
  579. // Buzz and wait. The delay is needed for buttons to settle!
  580. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  581. #if ENABLED(LCD_USE_I2C_BUZZER)
  582. delay(10);
  583. #elif PIN_EXISTS(BEEPER)
  584. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  585. #endif
  586. }
  587. void lcd_completion_feedback(const bool good/*=true*/) {
  588. if (good) {
  589. lcd_buzz(100, 659);
  590. lcd_buzz(100, 698);
  591. }
  592. else lcd_buzz(20, 440);
  593. }
  594. inline void line_to_current(AxisEnum axis) {
  595. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
  596. }
  597. #if ENABLED(SDSUPPORT)
  598. void lcd_sdcard_pause() {
  599. card.pauseSDPrint();
  600. print_job_timer.pause();
  601. #if ENABLED(PARK_HEAD_ON_PAUSE)
  602. enqueue_and_echo_commands_P(PSTR("M125"));
  603. #endif
  604. }
  605. void lcd_sdcard_resume() {
  606. #if ENABLED(PARK_HEAD_ON_PAUSE)
  607. enqueue_and_echo_commands_P(PSTR("M24"));
  608. #else
  609. card.startFileprint();
  610. print_job_timer.start();
  611. #endif
  612. }
  613. void lcd_sdcard_stop() {
  614. card.stopSDPrint();
  615. clear_command_queue();
  616. quickstop_stepper();
  617. print_job_timer.stop();
  618. #if ENABLED(AUTOTEMP)
  619. thermalManager.autotempShutdown();
  620. #endif
  621. wait_for_heatup = false;
  622. lcd_setstatuspgm(PSTR(MSG_PRINT_ABORTED), true);
  623. }
  624. #endif // SDSUPPORT
  625. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  626. extern bool case_light_on;
  627. extern void update_case_light();
  628. void toggle_case_light() {
  629. case_light_on ^= true;
  630. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  631. update_case_light();
  632. }
  633. #endif // MENU_ITEM_CASE_LIGHT
  634. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  635. static void progress_bar_test() {
  636. static int8_t bar_percent = 0;
  637. if (lcd_clicked) {
  638. lcd_goto_previous_menu();
  639. lcd_set_custom_characters(false);
  640. return;
  641. }
  642. bar_percent += (int8_t)encoderPosition;
  643. bar_percent = constrain(bar_percent, 0, 100);
  644. encoderPosition = 0;
  645. lcd_implementation_drawmenu_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true);
  646. lcd.setCursor((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2);
  647. lcd.print(itostr3(bar_percent)); lcd.print('%');
  648. lcd.setCursor(0, LCD_HEIGHT - 1); lcd_draw_progress_bar(bar_percent);
  649. }
  650. void _progress_bar_test() {
  651. lcd_goto_screen(progress_bar_test);
  652. lcd_set_custom_characters();
  653. }
  654. #endif // LCD_PROGRESS_BAR_TEST
  655. #if HAS_DEBUG_MENU
  656. void lcd_debug_menu() {
  657. START_MENU();
  658. MENU_BACK(MSG_MAIN); // ^ Main
  659. #if ENABLED(LCD_PROGRESS_BAR_TEST)
  660. MENU_ITEM(submenu, MSG_PROGRESS_BAR_TEST, _progress_bar_test);
  661. #endif
  662. END_MENU();
  663. }
  664. #endif // HAS_DEBUG_MENU
  665. /**
  666. *
  667. * "Main" menu
  668. *
  669. */
  670. void lcd_main_menu() {
  671. START_MENU();
  672. MENU_BACK(MSG_WATCH);
  673. //
  674. // Debug Menu when certain options are enabled
  675. //
  676. #if HAS_DEBUG_MENU
  677. MENU_ITEM(submenu, MSG_DEBUG_MENU, lcd_debug_menu);
  678. #endif
  679. //
  680. // Switch case light on/off
  681. //
  682. #if ENABLED(MENU_ITEM_CASE_LIGHT)
  683. if (case_light_on)
  684. MENU_ITEM(function, MSG_LIGHTS_OFF, toggle_case_light);
  685. else
  686. MENU_ITEM(function, MSG_LIGHTS_ON, toggle_case_light);
  687. #endif
  688. #if ENABLED(BLTOUCH)
  689. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  690. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  691. #endif
  692. if (planner.movesplanned() || IS_SD_PRINTING) {
  693. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  694. }
  695. else {
  696. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  697. #if ENABLED(DELTA_CALIBRATION_MENU)
  698. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  699. #endif
  700. }
  701. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  702. #if ENABLED(SDSUPPORT)
  703. if (card.cardOK) {
  704. if (card.isFileOpen()) {
  705. if (card.sdprinting)
  706. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  707. else
  708. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  709. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  710. }
  711. else {
  712. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  713. #if !PIN_EXISTS(SD_DETECT)
  714. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  715. #endif
  716. }
  717. }
  718. else {
  719. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  720. #if !PIN_EXISTS(SD_DETECT)
  721. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  722. #endif
  723. }
  724. #endif //SDSUPPORT
  725. #if ENABLED(LCD_INFO_MENU)
  726. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  727. #endif
  728. END_MENU();
  729. }
  730. /**
  731. *
  732. * "Tune" submenu items
  733. *
  734. */
  735. #if HAS_M206_COMMAND
  736. /**
  737. * Set the home offset based on the current_position
  738. */
  739. void lcd_set_home_offsets() {
  740. // M428 Command
  741. enqueue_and_echo_commands_P(PSTR("M428"));
  742. lcd_return_to_status();
  743. }
  744. #endif
  745. #if ENABLED(BABYSTEPPING)
  746. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  747. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  748. ENCODER_DIRECTION_NORMAL();
  749. if (encoderPosition) {
  750. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  751. encoderPosition = 0;
  752. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  753. thermalManager.babystep_axis(axis, babystep_increment);
  754. babysteps_done += babystep_increment;
  755. }
  756. if (lcdDrawUpdate)
  757. lcd_implementation_drawedit(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
  758. }
  759. #if ENABLED(BABYSTEP_XY)
  760. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  761. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  762. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  763. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  764. #endif
  765. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  766. void lcd_babystep_zoffset() {
  767. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  768. defer_return_to_status = true;
  769. ENCODER_DIRECTION_NORMAL();
  770. if (encoderPosition) {
  771. const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  772. encoderPosition = 0;
  773. const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
  774. if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  775. if (planner.abl_enabled)
  776. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  777. zprobe_zoffset = new_zoffset;
  778. refresh_zprobe_zoffset(true);
  779. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  780. }
  781. }
  782. if (lcdDrawUpdate)
  783. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  784. }
  785. #else // !BABYSTEP_ZPROBE_OFFSET
  786. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  787. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  788. #endif // !BABYSTEP_ZPROBE_OFFSET
  789. #endif // BABYSTEPPING
  790. #if ENABLED(AUTO_BED_LEVELING_UBL)
  791. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  792. // seperate value that doesn't lose precision.
  793. static int ubl_encoderPosition = 0;
  794. static void _lcd_mesh_fine_tune(const char* msg) {
  795. defer_return_to_status = true;
  796. if (ubl.encoder_diff) {
  797. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  798. ubl.encoder_diff = 0;
  799. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
  800. mesh_edit_value = mesh_edit_accumulator;
  801. encoderPosition = 0;
  802. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  803. const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
  804. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
  805. }
  806. if (lcdDrawUpdate)
  807. lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
  808. }
  809. void _lcd_mesh_edit_NOP() {
  810. defer_return_to_status = true;
  811. }
  812. void _lcd_mesh_edit() {
  813. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  814. }
  815. float lcd_mesh_edit() {
  816. lcd_goto_screen(_lcd_mesh_edit_NOP);
  817. _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
  818. return mesh_edit_value;
  819. }
  820. void lcd_mesh_edit_setup(float initial) {
  821. mesh_edit_value = mesh_edit_accumulator = initial;
  822. lcd_goto_screen(_lcd_mesh_edit_NOP);
  823. }
  824. void _lcd_z_offset_edit() {
  825. _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
  826. }
  827. float lcd_z_offset_edit() {
  828. lcd_goto_screen(_lcd_z_offset_edit);
  829. return mesh_edit_value;
  830. }
  831. void lcd_z_offset_edit_setup(float initial) {
  832. mesh_edit_value = mesh_edit_accumulator = initial;
  833. lcd_goto_screen(_lcd_z_offset_edit);
  834. }
  835. #endif // AUTO_BED_LEVELING_UBL
  836. /**
  837. * Watch temperature callbacks
  838. */
  839. #if HAS_TEMP_HOTEND
  840. #if WATCH_HOTENDS
  841. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  842. #else
  843. #define _WATCH_FUNC(N) NOOP
  844. #endif
  845. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  846. #if HOTENDS > 1
  847. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  848. #if HOTENDS > 2
  849. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  850. #if HOTENDS > 3
  851. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  852. #if HOTENDS > 4
  853. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  854. #endif // HOTENDS > 4
  855. #endif // HOTENDS > 3
  856. #endif // HOTENDS > 2
  857. #endif // HOTENDS > 1
  858. #endif // HAS_TEMP_HOTEND
  859. #if WATCH_THE_BED
  860. void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
  861. #endif
  862. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  863. void lcd_enqueue_filament_change() {
  864. if (!DEBUGGING(DRYRUN) && thermalManager.tooColdToExtrude(active_extruder)) {
  865. lcd_save_previous_screen();
  866. lcd_goto_screen(lcd_filament_change_toocold_menu);
  867. return;
  868. }
  869. lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_INIT);
  870. enqueue_and_echo_commands_P(PSTR("M600"));
  871. }
  872. #endif
  873. /**
  874. *
  875. * "Tune" submenu
  876. *
  877. */
  878. void lcd_tune_menu() {
  879. START_MENU();
  880. //
  881. // ^ Main
  882. //
  883. MENU_BACK(MSG_MAIN);
  884. //
  885. // Speed:
  886. //
  887. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  888. // Manual bed leveling, Bed Z:
  889. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  890. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  891. #endif
  892. //
  893. // Nozzle:
  894. // Nozzle [1-4]:
  895. //
  896. #if HOTENDS == 1
  897. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  898. #else //HOTENDS > 1
  899. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  900. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  901. #if HOTENDS > 2
  902. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  903. #if HOTENDS > 3
  904. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  905. #if HOTENDS > 4
  906. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  907. #endif // HOTENDS > 4
  908. #endif // HOTENDS > 3
  909. #endif // HOTENDS > 2
  910. #endif // HOTENDS > 1
  911. //
  912. // Bed:
  913. //
  914. #if WATCH_THE_BED
  915. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  916. #endif
  917. //
  918. // Fan Speed:
  919. //
  920. #if FAN_COUNT > 0
  921. #if HAS_FAN0
  922. #if FAN_COUNT > 1
  923. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  924. #else
  925. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  926. #endif
  927. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  928. #endif
  929. #if HAS_FAN1
  930. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  931. #endif
  932. #if HAS_FAN2
  933. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  934. #endif
  935. #endif // FAN_COUNT > 0
  936. //
  937. // Flow:
  938. // Flow [1-5]:
  939. //
  940. #if EXTRUDERS == 1
  941. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  942. #else // EXTRUDERS > 1
  943. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  944. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  945. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  946. #if EXTRUDERS > 2
  947. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  948. #if EXTRUDERS > 3
  949. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  950. #if EXTRUDERS > 4
  951. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &flow_percentage[4], 10, 999);
  952. #endif // EXTRUDERS > 4
  953. #endif // EXTRUDERS > 3
  954. #endif // EXTRUDERS > 2
  955. #endif // EXTRUDERS > 1
  956. //
  957. // Babystep X:
  958. // Babystep Y:
  959. // Babystep Z:
  960. //
  961. #if ENABLED(BABYSTEPPING)
  962. #if ENABLED(BABYSTEP_XY)
  963. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  964. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  965. #endif
  966. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  967. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  968. #else
  969. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  970. #endif
  971. #endif
  972. //
  973. // Change filament
  974. //
  975. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  976. if (!thermalManager.tooColdToExtrude(active_extruder))
  977. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  978. #endif
  979. END_MENU();
  980. }
  981. /**
  982. *
  983. * "Driver current control" submenu items
  984. *
  985. */
  986. #if ENABLED(DAC_STEPPER_CURRENT)
  987. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  988. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  989. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  990. void lcd_dac_menu() {
  991. dac_driver_getValues();
  992. START_MENU();
  993. MENU_BACK(MSG_CONTROL);
  994. MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  995. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  996. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  997. MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  998. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  999. END_MENU();
  1000. }
  1001. #endif
  1002. constexpr int heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP);
  1003. /**
  1004. *
  1005. * "Prepare" submenu items
  1006. *
  1007. */
  1008. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  1009. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  1010. #if TEMP_SENSOR_BED != 0
  1011. if (tempb >= 0) thermalManager.setTargetBed(tempb);
  1012. #else
  1013. UNUSED(tempb);
  1014. #endif
  1015. #if FAN_COUNT > 0
  1016. #if FAN_COUNT > 1
  1017. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  1018. #else
  1019. fanSpeeds[0] = fan;
  1020. #endif
  1021. #else
  1022. UNUSED(fan);
  1023. #endif
  1024. lcd_return_to_status();
  1025. }
  1026. #if TEMP_SENSOR_0 != 0
  1027. void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1028. void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1029. #if TEMP_SENSOR_BED != 0
  1030. void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1031. void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1032. #endif
  1033. #endif
  1034. #if HOTENDS > 1
  1035. void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1036. void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1037. #if TEMP_SENSOR_BED != 0
  1038. void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1039. void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1040. #endif
  1041. #if HOTENDS > 2
  1042. void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1043. void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1044. #if TEMP_SENSOR_BED != 0
  1045. void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1046. void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1047. #endif
  1048. #if HOTENDS > 3
  1049. void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1050. void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1051. #if TEMP_SENSOR_BED != 0
  1052. void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1053. void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1054. #endif
  1055. #if HOTENDS > 4
  1056. void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
  1057. void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
  1058. #if TEMP_SENSOR_BED != 0
  1059. void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1060. void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1061. #endif
  1062. #endif // HOTENDS > 4
  1063. #endif // HOTENDS > 3
  1064. #endif // HOTENDS > 2
  1065. void lcd_preheat_m1_all() {
  1066. #if HOTENDS > 1
  1067. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  1068. #if HOTENDS > 2
  1069. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  1070. #if HOTENDS > 3
  1071. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  1072. #if HOTENDS > 4
  1073. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 4);
  1074. #endif // HOTENDS > 4
  1075. #endif // HOTENDS > 3
  1076. #endif // HOTENDS > 2
  1077. #endif // HOTENDS > 1
  1078. #if TEMP_SENSOR_BED != 0
  1079. lcd_preheat_m1_e0();
  1080. #else
  1081. lcd_preheat_m1_e0_only();
  1082. #endif
  1083. }
  1084. void lcd_preheat_m2_all() {
  1085. #if HOTENDS > 1
  1086. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  1087. #if HOTENDS > 2
  1088. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  1089. #if HOTENDS > 3
  1090. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  1091. #if HOTENDS > 4
  1092. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 4);
  1093. #endif // HOTENDS > 4
  1094. #endif // HOTENDS > 3
  1095. #endif // HOTENDS > 2
  1096. #endif // HOTENDS > 1
  1097. #if TEMP_SENSOR_BED != 0
  1098. lcd_preheat_m2_e0();
  1099. #else
  1100. lcd_preheat_m2_e0_only();
  1101. #endif
  1102. }
  1103. #endif // HOTENDS > 1
  1104. #if TEMP_SENSOR_BED != 0
  1105. void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  1106. void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  1107. #endif
  1108. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  1109. void lcd_preheat_m1_menu() {
  1110. START_MENU();
  1111. MENU_BACK(MSG_PREPARE);
  1112. #if HOTENDS == 1
  1113. #if TEMP_SENSOR_BED != 0
  1114. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
  1115. MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
  1116. #else
  1117. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1118. #endif
  1119. #else
  1120. #if TEMP_SENSOR_BED != 0
  1121. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
  1122. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
  1123. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
  1124. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E2, lcd_preheat_m1_e1_only);
  1125. #else
  1126. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0_only);
  1127. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
  1128. #endif
  1129. #if HOTENDS > 2
  1130. #if TEMP_SENSOR_BED != 0
  1131. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
  1132. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
  1133. #else
  1134. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
  1135. #endif
  1136. #if HOTENDS > 3
  1137. #if TEMP_SENSOR_BED != 0
  1138. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
  1139. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
  1140. #else
  1141. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
  1142. #endif
  1143. #if HOTENDS > 4
  1144. #if TEMP_SENSOR_BED != 0
  1145. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
  1146. MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
  1147. #else
  1148. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4_only);
  1149. #endif
  1150. #endif // HOTENDS > 4
  1151. #endif // HOTENDS > 3
  1152. #endif // HOTENDS > 2
  1153. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
  1154. #endif // HOTENDS > 1
  1155. #if TEMP_SENSOR_BED != 0
  1156. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
  1157. #endif
  1158. END_MENU();
  1159. }
  1160. void lcd_preheat_m2_menu() {
  1161. START_MENU();
  1162. MENU_BACK(MSG_PREPARE);
  1163. #if HOTENDS == 1
  1164. #if TEMP_SENSOR_BED != 0
  1165. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
  1166. MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
  1167. #else
  1168. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1169. #endif
  1170. #else
  1171. #if TEMP_SENSOR_BED != 0
  1172. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
  1173. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
  1174. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
  1175. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E2, lcd_preheat_m2_e1_only);
  1176. #else
  1177. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0_only);
  1178. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
  1179. #endif
  1180. #if HOTENDS > 2
  1181. #if TEMP_SENSOR_BED != 0
  1182. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
  1183. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
  1184. #else
  1185. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
  1186. #endif
  1187. #if HOTENDS > 3
  1188. #if TEMP_SENSOR_BED != 0
  1189. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
  1190. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
  1191. #else
  1192. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
  1193. #endif
  1194. #if HOTENDS > 4
  1195. #if TEMP_SENSOR_BED != 0
  1196. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
  1197. MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
  1198. #else
  1199. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4_only);
  1200. #endif
  1201. #endif // HOTENDS > 4
  1202. #endif // HOTENDS > 3
  1203. #endif // HOTENDS > 2
  1204. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
  1205. #endif // HOTENDS > 1
  1206. #if TEMP_SENSOR_BED != 0
  1207. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
  1208. #endif
  1209. END_MENU();
  1210. }
  1211. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  1212. void lcd_cooldown() {
  1213. #if FAN_COUNT > 0
  1214. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  1215. #endif
  1216. thermalManager.disable_all_heaters();
  1217. lcd_return_to_status();
  1218. }
  1219. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1220. void lcd_autostart_sd() {
  1221. card.autostart_index = 0;
  1222. card.setroot();
  1223. card.checkautostart(true);
  1224. }
  1225. #endif
  1226. #if ENABLED(LCD_BED_LEVELING)
  1227. /**
  1228. *
  1229. * "Prepare" > "Level Bed" handlers
  1230. *
  1231. */
  1232. static uint8_t manual_probe_index;
  1233. #if ENABLED(PROBE_MANUALLY)
  1234. extern bool g29_in_progress;
  1235. #endif
  1236. // LCD probed points are from defaults
  1237. constexpr uint8_t total_probe_points =
  1238. #if ABL_GRID
  1239. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1240. #elif ENABLED(AUTO_BED_LEVELING_3POINT)
  1241. int(3)
  1242. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1243. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1244. #elif ENABLED(MESH_BED_LEVELING)
  1245. (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
  1246. #endif
  1247. ;
  1248. #if ENABLED(MESH_BED_LEVELING)
  1249. // Utility to go to the next mesh point
  1250. inline void _manual_probe_goto_xy(float x, float y) {
  1251. #if MANUAL_PROBE_HEIGHT > 0
  1252. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1253. line_to_current(Z_AXIS);
  1254. #endif
  1255. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  1256. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  1257. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  1258. #if MANUAL_PROBE_HEIGHT > 0
  1259. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + 0.2;
  1260. line_to_current(Z_AXIS);
  1261. #endif
  1262. lcd_synchronize();
  1263. }
  1264. #endif // MESH_BED_LEVELING
  1265. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1266. void _lcd_level_goto_next_point();
  1267. #endif
  1268. void _lcd_level_bed_done() {
  1269. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  1270. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1271. }
  1272. /**
  1273. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  1274. */
  1275. void _lcd_level_bed_moving() {
  1276. if (lcdDrawUpdate) {
  1277. char msg[10];
  1278. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  1279. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  1280. }
  1281. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1282. }
  1283. /**
  1284. * Step 7: Get the Z coordinate, click goes to the next point or exits
  1285. */
  1286. void _lcd_level_bed_get_z() {
  1287. ENCODER_DIRECTION_NORMAL();
  1288. // Encoder wheel adjusts the Z position
  1289. if (encoderPosition) {
  1290. refresh_cmd_timeout();
  1291. current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
  1292. NOLESS(current_position[Z_AXIS], -(LCD_PROBE_Z_RANGE) * 0.5);
  1293. NOMORE(current_position[Z_AXIS], (LCD_PROBE_Z_RANGE) * 0.5);
  1294. line_to_current(Z_AXIS);
  1295. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1296. encoderPosition = 0;
  1297. }
  1298. if (lcd_clicked) {
  1299. // Use a hook to set the probe point z
  1300. // (zigzag arranges in XY order)
  1301. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1302. // UBL set-z handling goes here
  1303. #elif ENABLED(PROBE_MANUALLY)
  1304. // G29 helpfully records Z and goes to the next
  1305. // point (or beeps if done)
  1306. enqueue_and_echo_commands_P(PSTR("G29"));
  1307. manual_probe_index++;
  1308. #elif ENABLED(MESH_BED_LEVELING)
  1309. mbl.set_zigzag_z(manual_probe_index++, current_position[Z_AXIS]);
  1310. #endif
  1311. // If done...
  1312. if (manual_probe_index == total_probe_points) {
  1313. // Say "Done!"
  1314. lcd_goto_screen(_lcd_level_bed_done);
  1315. // Raise Z to the "manual probe height"
  1316. #if MANUAL_PROBE_HEIGHT > 0
  1317. current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
  1318. line_to_current(Z_AXIS);
  1319. lcd_synchronize();
  1320. #endif
  1321. // Enable leveling, if needed
  1322. #if ENABLED(MESH_BED_LEVELING)
  1323. mbl.set_has_mesh(true);
  1324. mbl.set_reactivate(true);
  1325. enqueue_and_echo_commands_P(PSTR("G28"));
  1326. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1327. // UBL enable goes here
  1328. #elif ENABLED(PROBE_MANUALLY)
  1329. // ABL will be enabled due to "G29".
  1330. #endif
  1331. lcd_return_to_status();
  1332. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  1333. lcd_completion_feedback();
  1334. }
  1335. else {
  1336. // Move to the next probe point, if needed
  1337. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1338. _lcd_level_goto_next_point();
  1339. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1340. // UBL goto-next-point goes here
  1341. #endif
  1342. }
  1343. }
  1344. // Update on first display, then only on updates to Z position
  1345. // Show message above on clicks instead
  1346. if (lcdDrawUpdate) {
  1347. const float v = current_position[Z_AXIS];
  1348. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  1349. }
  1350. }
  1351. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  1352. /**
  1353. * Step 5: Initiate a move to the next point
  1354. */
  1355. void _lcd_level_goto_next_point() {
  1356. // Set the menu to display ahead of blocking call
  1357. lcd_goto_screen(_lcd_level_bed_moving);
  1358. #if ENABLED(MESH_BED_LEVELING)
  1359. int8_t px, py;
  1360. mbl.zigzag(manual_probe_index, px, py);
  1361. // Controls the loop until the move is done
  1362. _manual_probe_goto_xy(
  1363. LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
  1364. LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
  1365. );
  1366. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1367. // UBL may have its own methodology
  1368. #elif ENABLED(PROBE_MANUALLY)
  1369. // Just wait for the G29 move to complete
  1370. lcd_synchronize();
  1371. #endif
  1372. // After the blocking function returns, change menus
  1373. lcd_goto_screen(_lcd_level_bed_get_z);
  1374. }
  1375. #endif // MESH_BED_LEVELING
  1376. /**
  1377. * Step 4: Display "Click to Begin", wait for click
  1378. * Move to the first probe position
  1379. */
  1380. void _lcd_level_bed_homing_done() {
  1381. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1382. if (lcd_clicked) {
  1383. manual_probe_index = 0;
  1384. #if ENABLED(MESH_BED_LEVELING)
  1385. _lcd_level_goto_next_point();
  1386. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  1387. // UBL click handling should go here
  1388. #elif ENABLED(PROBE_MANUALLY)
  1389. enqueue_and_echo_commands_P(PSTR("G29"));
  1390. _lcd_level_goto_next_point();
  1391. #endif
  1392. }
  1393. }
  1394. /**
  1395. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1396. */
  1397. void _lcd_level_bed_homing() {
  1398. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1399. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1400. lcd_goto_screen(_lcd_level_bed_homing_done);
  1401. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1402. }
  1403. #endif // LCD_BED_LEVELING
  1404. #if ENABLED(LCD_BED_LEVELING) || HAS_ABL
  1405. /**
  1406. * Step 2: Continue Bed Leveling...
  1407. */
  1408. void _lcd_level_bed_continue() {
  1409. #if ENABLED(LCD_BED_LEVELING)
  1410. defer_return_to_status = true;
  1411. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1412. lcd_goto_screen(_lcd_level_bed_homing);
  1413. enqueue_and_echo_commands_P(PSTR("G28"));
  1414. #else
  1415. lcd_return_to_status();
  1416. enqueue_and_echo_commands_P(axis_homed[X_AXIS] && axis_homed[Y_AXIS] ? PSTR("G29") : PSTR("G28\nG29"));
  1417. #endif
  1418. }
  1419. /**
  1420. * Step 1: Bed Level entry-point: "Cancel" or "Level Bed"
  1421. */
  1422. void lcd_level_bed() {
  1423. START_MENU();
  1424. MENU_BACK(MSG_LEVEL_BED_CANCEL);
  1425. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1426. END_MENU();
  1427. }
  1428. #endif // LCD_BED_LEVELING || HAS_ABL
  1429. /**
  1430. *
  1431. * "Prepare" submenu
  1432. *
  1433. */
  1434. void lcd_prepare_menu() {
  1435. START_MENU();
  1436. //
  1437. // ^ Main
  1438. //
  1439. MENU_BACK(MSG_MAIN);
  1440. //
  1441. // Move Axis
  1442. //
  1443. #if ENABLED(DELTA)
  1444. if (axis_homed[Z_AXIS])
  1445. #endif
  1446. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  1447. //
  1448. // Auto Home
  1449. //
  1450. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1451. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  1452. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  1453. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  1454. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  1455. #endif
  1456. //
  1457. // Level Bed
  1458. //
  1459. #if ENABLED(LCD_BED_LEVELING) || HAS_ABL
  1460. #if ENABLED(PROBE_MANUALLY)
  1461. if (!g29_in_progress)
  1462. #endif
  1463. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  1464. #endif
  1465. #if HAS_M206_COMMAND
  1466. //
  1467. // Set Home Offsets
  1468. //
  1469. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  1470. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  1471. #endif
  1472. //
  1473. // Disable Steppers
  1474. //
  1475. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1476. //
  1477. // Preheat PLA
  1478. // Preheat ABS
  1479. //
  1480. #if TEMP_SENSOR_0 != 0
  1481. //
  1482. // Change filament
  1483. //
  1484. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  1485. if (!thermalManager.tooColdToExtrude(active_extruder))
  1486. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  1487. #endif
  1488. //
  1489. // Cooldown
  1490. //
  1491. bool has_heat = false;
  1492. HOTEND_LOOP() if (thermalManager.target_temperature[HOTEND_INDEX]) { has_heat = true; break; }
  1493. #if HAS_TEMP_BED
  1494. if (thermalManager.target_temperature_bed) has_heat = true;
  1495. #endif
  1496. if (has_heat) MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1497. //
  1498. // Preheat for Material 1 and 2
  1499. //
  1500. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  1501. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
  1502. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
  1503. #else
  1504. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
  1505. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
  1506. #endif
  1507. #endif // TEMP_SENSOR_0 != 0
  1508. //
  1509. // BLTouch Self-Test and Reset
  1510. //
  1511. #if ENABLED(BLTOUCH)
  1512. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  1513. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  1514. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  1515. #endif
  1516. //
  1517. // Switch power on/off
  1518. //
  1519. #if HAS_POWER_SWITCH
  1520. if (powersupply)
  1521. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  1522. else
  1523. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  1524. #endif
  1525. //
  1526. // Autostart
  1527. //
  1528. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1529. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  1530. #endif
  1531. END_MENU();
  1532. }
  1533. float move_menu_scale;
  1534. #if ENABLED(DELTA_CALIBRATION_MENU)
  1535. void lcd_move_z();
  1536. void lcd_delta_calibrate_menu();
  1537. void _lcd_calibrate_homing() {
  1538. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
  1539. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  1540. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1541. lcd_goto_previous_menu();
  1542. }
  1543. void _lcd_delta_calibrate_home() {
  1544. enqueue_and_echo_commands_P(PSTR("G28"));
  1545. lcd_goto_screen(_lcd_calibrate_homing);
  1546. }
  1547. #if ENABLED(DELTA_AUTO_CALIBRATION)
  1548. #define _DELTA_TOWER_MOVE_RADIUS DELTA_CALIBRATION_RADIUS
  1549. #else
  1550. #define _DELTA_TOWER_MOVE_RADIUS DELTA_PRINTABLE_RADIUS
  1551. #endif
  1552. // Move directly to the tower position with uninterpolated moves
  1553. // If we used interpolated moves it would cause this to become re-entrant
  1554. void _goto_tower_pos(const float &a) {
  1555. current_position[Z_AXIS] = max(Z_HOMING_HEIGHT, Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5;
  1556. line_to_current(Z_AXIS);
  1557. current_position[X_AXIS] = a < 0 ? LOGICAL_X_POSITION(X_HOME_POS) : sin(a) * -(_DELTA_TOWER_MOVE_RADIUS);
  1558. current_position[Y_AXIS] = a < 0 ? LOGICAL_Y_POSITION(Y_HOME_POS) : cos(a) * (_DELTA_TOWER_MOVE_RADIUS);
  1559. line_to_current(Z_AXIS);
  1560. current_position[Z_AXIS] = 4.0;
  1561. line_to_current(Z_AXIS);
  1562. lcd_synchronize();
  1563. move_menu_scale = 0.1;
  1564. lcd_goto_screen(lcd_move_z);
  1565. }
  1566. void _goto_tower_x() { _goto_tower_pos(RADIANS(120)); }
  1567. void _goto_tower_y() { _goto_tower_pos(RADIANS(240)); }
  1568. void _goto_tower_z() { _goto_tower_pos(0); }
  1569. void _goto_center() { _goto_tower_pos(-1); }
  1570. void lcd_delta_calibrate_menu() {
  1571. START_MENU();
  1572. MENU_BACK(MSG_MAIN);
  1573. #if ENABLED(DELTA_AUTO_CALIBRATION)
  1574. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33 C"));
  1575. MENU_ITEM(gcode, MSG_DELTA_HEIGHT_CALIBRATE, PSTR("G33 C1"));
  1576. #endif
  1577. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  1578. if (axis_homed[Z_AXIS]) {
  1579. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  1580. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  1581. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  1582. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  1583. }
  1584. END_MENU();
  1585. }
  1586. #endif // DELTA_CALIBRATION_MENU
  1587. /**
  1588. * If the most recent manual move hasn't been fed to the planner yet,
  1589. * and the planner can accept one, send immediately
  1590. */
  1591. inline void manage_manual_move() {
  1592. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  1593. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  1594. manual_move_axis = (int8_t)NO_AXIS;
  1595. }
  1596. }
  1597. /**
  1598. * Set a flag that lcd_update() should start a move
  1599. * to "current_position" after a short delay.
  1600. */
  1601. inline void manual_move_to_current(AxisEnum axis
  1602. #if E_MANUAL > 1
  1603. , int8_t eindex=-1
  1604. #endif
  1605. ) {
  1606. #if E_MANUAL > 1
  1607. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  1608. #endif
  1609. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  1610. manual_move_axis = (int8_t)axis;
  1611. }
  1612. /**
  1613. *
  1614. * "Prepare" > "Move Axis" submenu
  1615. *
  1616. */
  1617. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  1618. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1619. ENCODER_DIRECTION_NORMAL();
  1620. if (encoderPosition) {
  1621. refresh_cmd_timeout();
  1622. float min = current_position[axis] - 1000,
  1623. max = current_position[axis] + 1000;
  1624. #if HAS_SOFTWARE_ENDSTOPS
  1625. // Limit to software endstops, if enabled
  1626. if (soft_endstops_enabled) {
  1627. #if ENABLED(MIN_SOFTWARE_ENDSTOPS)
  1628. min = soft_endstop_min[axis];
  1629. #endif
  1630. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  1631. max = soft_endstop_max[axis];
  1632. #endif
  1633. }
  1634. #endif
  1635. // Get the new position
  1636. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  1637. // Delta limits XY based on the current offset from center
  1638. // This assumes the center is 0,0
  1639. #if ENABLED(DELTA)
  1640. if (axis != Z_AXIS) {
  1641. max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
  1642. min = -max;
  1643. }
  1644. #endif
  1645. // Limit only when trying to move towards the limit
  1646. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  1647. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  1648. manual_move_to_current(axis);
  1649. encoderPosition = 0;
  1650. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1651. }
  1652. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  1653. }
  1654. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  1655. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  1656. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  1657. void _lcd_move_e(
  1658. #if E_MANUAL > 1
  1659. int8_t eindex=-1
  1660. #endif
  1661. ) {
  1662. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1663. ENCODER_DIRECTION_NORMAL();
  1664. if (encoderPosition) {
  1665. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  1666. encoderPosition = 0;
  1667. manual_move_to_current(E_AXIS
  1668. #if E_MANUAL > 1
  1669. , eindex
  1670. #endif
  1671. );
  1672. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1673. }
  1674. if (lcdDrawUpdate) {
  1675. PGM_P pos_label;
  1676. #if E_MANUAL == 1
  1677. pos_label = PSTR(MSG_MOVE_E);
  1678. #else
  1679. switch (eindex) {
  1680. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  1681. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  1682. #if E_MANUAL > 2
  1683. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  1684. #if E_MANUAL > 3
  1685. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  1686. #if E_MANUAL > 4
  1687. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  1688. #endif // E_MANUAL > 4
  1689. #endif // E_MANUAL > 3
  1690. #endif // E_MANUAL > 2
  1691. }
  1692. #endif // E_MANUAL > 1
  1693. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  1694. }
  1695. }
  1696. void lcd_move_e() { _lcd_move_e(); }
  1697. #if E_MANUAL > 1
  1698. void lcd_move_e0() { _lcd_move_e(0); }
  1699. void lcd_move_e1() { _lcd_move_e(1); }
  1700. #if E_MANUAL > 2
  1701. void lcd_move_e2() { _lcd_move_e(2); }
  1702. #if E_MANUAL > 3
  1703. void lcd_move_e3() { _lcd_move_e(3); }
  1704. #if E_MANUAL > 4
  1705. void lcd_move_e4() { _lcd_move_e(4); }
  1706. #endif // E_MANUAL > 4
  1707. #endif // E_MANUAL > 3
  1708. #endif // E_MANUAL > 2
  1709. #endif // E_MANUAL > 1
  1710. /**
  1711. *
  1712. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  1713. *
  1714. */
  1715. screenFunc_t _manual_move_func_ptr;
  1716. void lcd_move_menu_10mm() { move_menu_scale = 10.0; lcd_goto_screen(_manual_move_func_ptr); }
  1717. void lcd_move_menu_1mm() { move_menu_scale = 1.0; lcd_goto_screen(_manual_move_func_ptr); }
  1718. void lcd_move_menu_01mm() { move_menu_scale = 0.1; lcd_goto_screen(_manual_move_func_ptr); }
  1719. void _lcd_move_distance_menu(AxisEnum axis, screenFunc_t func) {
  1720. _manual_move_func_ptr = func;
  1721. START_MENU();
  1722. if (LCD_HEIGHT >= 4) {
  1723. switch(axis) {
  1724. case X_AXIS:
  1725. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  1726. case Y_AXIS:
  1727. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  1728. case Z_AXIS:
  1729. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  1730. default:
  1731. STATIC_ITEM(MSG_MOVE_E, true, true); break;
  1732. }
  1733. }
  1734. MENU_BACK(MSG_MOVE_AXIS);
  1735. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  1736. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  1737. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  1738. END_MENU();
  1739. }
  1740. void lcd_move_get_x_amount() { _lcd_move_distance_menu(X_AXIS, lcd_move_x); }
  1741. void lcd_move_get_y_amount() { _lcd_move_distance_menu(Y_AXIS, lcd_move_y); }
  1742. void lcd_move_get_z_amount() { _lcd_move_distance_menu(Z_AXIS, lcd_move_z); }
  1743. void lcd_move_get_e_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e); }
  1744. #if E_MANUAL > 1
  1745. void lcd_move_get_e0_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e0); }
  1746. void lcd_move_get_e1_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e1); }
  1747. #if E_MANUAL > 2
  1748. void lcd_move_get_e2_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e2); }
  1749. #if E_MANUAL > 3
  1750. void lcd_move_get_e3_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e3); }
  1751. #if E_MANUAL > 4
  1752. void lcd_move_get_e4_amount() { _lcd_move_distance_menu(E_AXIS, lcd_move_e4); }
  1753. #endif // E_MANUAL > 4
  1754. #endif // E_MANUAL > 3
  1755. #endif // E_MANUAL > 2
  1756. #endif // E_MANUAL > 1
  1757. /**
  1758. *
  1759. * "Prepare" > "Move Axis" submenu
  1760. *
  1761. */
  1762. #if IS_KINEMATIC
  1763. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1764. #if ENABLED(DELTA)
  1765. #define _MOVE_XY_ALLOWED (current_position[Z_AXIS] <= delta_clip_start_height)
  1766. void lcd_lower_z_to_clip_height() {
  1767. current_position[Z_AXIS] = delta_clip_start_height;
  1768. line_to_current(Z_AXIS);
  1769. lcd_synchronize();
  1770. }
  1771. #else
  1772. #define _MOVE_XY_ALLOWED true
  1773. #endif
  1774. #else
  1775. #define _MOVE_XYZ_ALLOWED true
  1776. #define _MOVE_XY_ALLOWED true
  1777. #endif
  1778. void lcd_move_menu() {
  1779. START_MENU();
  1780. MENU_BACK(MSG_PREPARE);
  1781. if (_MOVE_XYZ_ALLOWED) {
  1782. if (_MOVE_XY_ALLOWED) {
  1783. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  1784. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  1785. }
  1786. #if ENABLED(DELTA)
  1787. else
  1788. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  1789. #endif
  1790. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  1791. }
  1792. else
  1793. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1794. #if ENABLED(SWITCHING_EXTRUDER)
  1795. if (active_extruder)
  1796. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  1797. else
  1798. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  1799. #endif
  1800. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  1801. #if E_MANUAL > 1
  1802. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  1803. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  1804. #if E_MANUAL > 2
  1805. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  1806. #if E_MANUAL > 3
  1807. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  1808. #if E_MANUAL > 4
  1809. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  1810. #endif // E_MANUAL > 4
  1811. #endif // E_MANUAL > 3
  1812. #endif // E_MANUAL > 2
  1813. #endif // E_MANUAL > 1
  1814. END_MENU();
  1815. }
  1816. /**
  1817. *
  1818. * "Control" submenu
  1819. *
  1820. */
  1821. #if ENABLED(EEPROM_SETTINGS)
  1822. static void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  1823. static void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  1824. #endif
  1825. static void lcd_factory_settings() {
  1826. settings.reset();
  1827. lcd_completion_feedback();
  1828. }
  1829. void lcd_control_menu() {
  1830. START_MENU();
  1831. MENU_BACK(MSG_MAIN);
  1832. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1833. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  1834. MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
  1835. #if HAS_LCD_CONTRAST
  1836. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  1837. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  1838. #endif
  1839. #if ENABLED(FWRETRACT)
  1840. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  1841. #endif
  1842. #if ENABLED(DAC_STEPPER_CURRENT)
  1843. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  1844. #endif
  1845. #if ENABLED(EEPROM_SETTINGS)
  1846. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  1847. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  1848. #endif
  1849. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, lcd_factory_settings);
  1850. END_MENU();
  1851. }
  1852. /**
  1853. *
  1854. * "Temperature" submenu
  1855. *
  1856. */
  1857. #if ENABLED(PID_AUTOTUNE_MENU)
  1858. #if ENABLED(PIDTEMP)
  1859. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  1860. #endif
  1861. #if ENABLED(PIDTEMPBED)
  1862. int autotune_temp_bed = 70;
  1863. #endif
  1864. void _lcd_autotune(int e) {
  1865. char cmd[30];
  1866. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  1867. #if HAS_PID_FOR_BOTH
  1868. e < 0 ? autotune_temp_bed : autotune_temp[e]
  1869. #elif ENABLED(PIDTEMPBED)
  1870. autotune_temp_bed
  1871. #else
  1872. autotune_temp[e]
  1873. #endif
  1874. );
  1875. enqueue_and_echo_command(cmd);
  1876. }
  1877. #endif //PID_AUTOTUNE_MENU
  1878. #if ENABLED(PIDTEMP)
  1879. // Helpers for editing PID Ki & Kd values
  1880. // grab the PID value out of the temp variable; scale it; then update the PID driver
  1881. void copy_and_scalePID_i(int e) {
  1882. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1883. UNUSED(e);
  1884. #endif
  1885. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  1886. thermalManager.updatePID();
  1887. }
  1888. void copy_and_scalePID_d(int e) {
  1889. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1890. UNUSED(e);
  1891. #endif
  1892. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  1893. thermalManager.updatePID();
  1894. }
  1895. #define _DEFINE_PIDTEMP_BASE_FUNCS(N) \
  1896. void copy_and_scalePID_i_E ## N() { copy_and_scalePID_i(N); } \
  1897. void copy_and_scalePID_d_E ## N() { copy_and_scalePID_d(N); }
  1898. #if ENABLED(PID_AUTOTUNE_MENU)
  1899. #define DEFINE_PIDTEMP_FUNCS(N) \
  1900. _DEFINE_PIDTEMP_BASE_FUNCS(N); \
  1901. void lcd_autotune_callback_E ## N() { _lcd_autotune(N); } typedef void _pid_##N##_void
  1902. #else
  1903. #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N) typedef void _pid_##N##_void
  1904. #endif
  1905. DEFINE_PIDTEMP_FUNCS(0);
  1906. #if ENABLED(PID_PARAMS_PER_HOTEND)
  1907. #if HOTENDS > 1
  1908. DEFINE_PIDTEMP_FUNCS(1);
  1909. #if HOTENDS > 2
  1910. DEFINE_PIDTEMP_FUNCS(2);
  1911. #if HOTENDS > 3
  1912. DEFINE_PIDTEMP_FUNCS(3);
  1913. #if HOTENDS > 4
  1914. DEFINE_PIDTEMP_FUNCS(4);
  1915. #endif // HOTENDS > 4
  1916. #endif // HOTENDS > 3
  1917. #endif // HOTENDS > 2
  1918. #endif // HOTENDS > 1
  1919. #endif // PID_PARAMS_PER_HOTEND
  1920. #endif // PIDTEMP
  1921. /**
  1922. *
  1923. * "Control" > "Temperature" submenu
  1924. *
  1925. */
  1926. void lcd_control_temperature_menu() {
  1927. START_MENU();
  1928. //
  1929. // ^ Control
  1930. //
  1931. MENU_BACK(MSG_CONTROL);
  1932. //
  1933. // Nozzle:
  1934. // Nozzle [1-5]:
  1935. //
  1936. #if HOTENDS == 1
  1937. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1938. #else // HOTENDS > 1
  1939. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1940. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1941. #if HOTENDS > 2
  1942. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1943. #if HOTENDS > 3
  1944. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1945. #if HOTENDS > 4
  1946. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N5, &thermalManager.target_temperature[4], 0, HEATER_4_MAXTEMP - 15, watch_temp_callback_E4);
  1947. #endif // HOTENDS > 4
  1948. #endif // HOTENDS > 3
  1949. #endif // HOTENDS > 2
  1950. #endif // HOTENDS > 1
  1951. //
  1952. // Bed:
  1953. //
  1954. #if WATCH_THE_BED
  1955. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1956. #endif
  1957. //
  1958. // Fan Speed:
  1959. //
  1960. #if FAN_COUNT > 0
  1961. #if HAS_FAN0
  1962. #if FAN_COUNT > 1
  1963. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1964. #else
  1965. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1966. #endif
  1967. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1968. #endif
  1969. #if HAS_FAN1
  1970. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1971. #endif
  1972. #if HAS_FAN2
  1973. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1974. #endif
  1975. #endif // FAN_COUNT > 0
  1976. //
  1977. // Autotemp, Min, Max, Fact
  1978. //
  1979. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1980. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  1981. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1982. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1983. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  1984. #endif
  1985. //
  1986. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  1987. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  1988. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  1989. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  1990. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  1991. // PID-P E5, PID-I E5, PID-D E5, PID-C E5, PID Autotune E5
  1992. //
  1993. #if ENABLED(PIDTEMP)
  1994. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  1995. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1996. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1997. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1998. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1999. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  2000. #if ENABLED(PID_EXTRUSION_SCALING)
  2001. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  2002. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  2003. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  2004. #else
  2005. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  2006. #endif
  2007. #if ENABLED(PID_AUTOTUNE_MENU)
  2008. #define PID_MENU_ITEMS(ELABEL, eindex) \
  2009. _PID_MENU_ITEMS(ELABEL, eindex); \
  2010. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  2011. #else
  2012. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  2013. #endif
  2014. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  2015. PID_MENU_ITEMS(" " MSG_E1, 0);
  2016. PID_MENU_ITEMS(" " MSG_E2, 1);
  2017. #if HOTENDS > 2
  2018. PID_MENU_ITEMS(" " MSG_E3, 2);
  2019. #if HOTENDS > 3
  2020. PID_MENU_ITEMS(" " MSG_E4, 3);
  2021. #if HOTENDS > 4
  2022. PID_MENU_ITEMS(" " MSG_E5, 4);
  2023. #endif // HOTENDS > 4
  2024. #endif // HOTENDS > 3
  2025. #endif // HOTENDS > 2
  2026. #else // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2027. PID_MENU_ITEMS("", 0);
  2028. #endif // !PID_PARAMS_PER_HOTEND || HOTENDS == 1
  2029. #endif //PIDTEMP
  2030. //
  2031. // Preheat Material 1 conf
  2032. //
  2033. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  2034. //
  2035. // Preheat Material 2 conf
  2036. //
  2037. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  2038. END_MENU();
  2039. }
  2040. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  2041. #if HOTENDS > 4
  2042. #define MINTEMP_ALL MIN5(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP, HEATER_4_MINTEMP)
  2043. #define MAXTEMP_ALL MAX5(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP)
  2044. #elif HOTENDS > 3
  2045. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  2046. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  2047. #elif HOTENDS > 2
  2048. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  2049. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  2050. #elif HOTENDS > 1
  2051. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  2052. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  2053. #else
  2054. #define MINTEMP_ALL HEATER_0_MINTEMP
  2055. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  2056. #endif
  2057. START_MENU();
  2058. MENU_BACK(MSG_TEMPERATURE);
  2059. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  2060. #if TEMP_SENSOR_0 != 0
  2061. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  2062. #endif
  2063. #if TEMP_SENSOR_BED != 0
  2064. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  2065. #endif
  2066. #if ENABLED(EEPROM_SETTINGS)
  2067. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  2068. #endif
  2069. END_MENU();
  2070. }
  2071. /**
  2072. *
  2073. * "Temperature" > "Preheat Material 1 conf" submenu
  2074. *
  2075. */
  2076. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  2077. /**
  2078. *
  2079. * "Temperature" > "Preheat Material 2 conf" submenu
  2080. *
  2081. */
  2082. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  2083. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  2084. #if ENABLED(DISTINCT_E_FACTORS)
  2085. void _reset_e_acceleration_rate(const uint8_t e) { if (e == active_extruder) _reset_acceleration_rates(); }
  2086. void _reset_e0_acceleration_rate() { _reset_e_acceleration_rate(0); }
  2087. void _reset_e1_acceleration_rate() { _reset_e_acceleration_rate(1); }
  2088. #if E_STEPPERS > 2
  2089. void _reset_e2_acceleration_rate() { _reset_e_acceleration_rate(2); }
  2090. #if E_STEPPERS > 3
  2091. void _reset_e3_acceleration_rate() { _reset_e_acceleration_rate(3); }
  2092. #if E_STEPPERS > 4
  2093. void _reset_e4_acceleration_rate() { _reset_e_acceleration_rate(4); }
  2094. #endif // E_STEPPERS > 4
  2095. #endif // E_STEPPERS > 3
  2096. #endif // E_STEPPERS > 2
  2097. #endif
  2098. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  2099. #if ENABLED(DISTINCT_E_FACTORS)
  2100. void _planner_refresh_e_positioning(const uint8_t e) {
  2101. if (e == active_extruder)
  2102. _planner_refresh_positioning();
  2103. else
  2104. planner.steps_to_mm[e] = 1.0 / planner.axis_steps_per_mm[e];
  2105. }
  2106. void _planner_refresh_e0_positioning() { _reset_e_acceleration_rate(0); }
  2107. void _planner_refresh_e1_positioning() { _reset_e_acceleration_rate(1); }
  2108. #if E_STEPPERS > 2
  2109. void _planner_refresh_e2_positioning() { _reset_e_acceleration_rate(2); }
  2110. #if E_STEPPERS > 3
  2111. void _planner_refresh_e3_positioning() { _reset_e_acceleration_rate(3); }
  2112. #if E_STEPPERS > 4
  2113. void _planner_refresh_e4_positioning() { _reset_e_acceleration_rate(4); }
  2114. #endif // E_STEPPERS > 4
  2115. #endif // E_STEPPERS > 3
  2116. #endif // E_STEPPERS > 2
  2117. #endif
  2118. /**
  2119. *
  2120. * "Control" > "Motion" submenu
  2121. *
  2122. */
  2123. #if HAS_BED_PROBE && DISABLED(BABYSTEP_ZPROBE_OFFSET)
  2124. static void lcd_refresh_zprobe_zoffset() { refresh_zprobe_zoffset(); }
  2125. #endif
  2126. void lcd_control_motion_menu() {
  2127. START_MENU();
  2128. MENU_BACK(MSG_CONTROL);
  2129. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  2130. MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  2131. #elif HAS_BED_PROBE
  2132. MENU_ITEM_EDIT_CALLBACK(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX, lcd_refresh_zprobe_zoffset);
  2133. #endif
  2134. // Manual bed leveling, Bed Z:
  2135. #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
  2136. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  2137. #endif
  2138. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  2139. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  2140. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  2141. #if ENABLED(DELTA)
  2142. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  2143. #else
  2144. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  2145. #endif
  2146. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  2147. //
  2148. // M203 Settings
  2149. //
  2150. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  2151. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  2152. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  2153. #if ENABLED(DISTINCT_E_FACTORS)
  2154. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
  2155. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2156. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
  2157. #if E_STEPPERS > 2
  2158. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
  2159. #if E_STEPPERS > 3
  2160. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
  2161. #if E_STEPPERS > 4
  2162. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
  2163. #endif // E_STEPPERS > 4
  2164. #endif // E_STEPPERS > 3
  2165. #endif // E_STEPPERS > 2
  2166. #else
  2167. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  2168. #endif
  2169. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  2170. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  2171. //
  2172. // M201 Settings
  2173. //
  2174. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  2175. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  2176. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  2177. #if ENABLED(DISTINCT_E_FACTORS)
  2178. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
  2179. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
  2180. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
  2181. #if E_STEPPERS > 2
  2182. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
  2183. #if E_STEPPERS > 3
  2184. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
  2185. #if E_STEPPERS > 4
  2186. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
  2187. #endif // E_STEPPERS > 4
  2188. #endif // E_STEPPERS > 3
  2189. #endif // E_STEPPERS > 2
  2190. #else
  2191. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  2192. #endif
  2193. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  2194. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  2195. //
  2196. // M92 Settings
  2197. //
  2198. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  2199. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  2200. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  2201. #if ENABLED(DISTINCT_E_FACTORS)
  2202. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS + active_extruder], 5, 9999, _planner_refresh_positioning);
  2203. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E1STEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_e0_positioning);
  2204. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E2STEPS, &planner.axis_steps_per_mm[E_AXIS + 1], 5, 9999, _planner_refresh_e1_positioning);
  2205. #if E_STEPPERS > 2
  2206. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E3STEPS, &planner.axis_steps_per_mm[E_AXIS + 2], 5, 9999, _planner_refresh_e2_positioning);
  2207. #if E_STEPPERS > 3
  2208. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E4STEPS, &planner.axis_steps_per_mm[E_AXIS + 3], 5, 9999, _planner_refresh_e3_positioning);
  2209. #if E_STEPPERS > 4
  2210. MENU_ITEM_EDIT_CALLBACK(float62, MSG_E5STEPS, &planner.axis_steps_per_mm[E_AXIS + 4], 5, 9999, _planner_refresh_e4_positioning);
  2211. #endif // E_STEPPERS > 4
  2212. #endif // E_STEPPERS > 3
  2213. #endif // E_STEPPERS > 2
  2214. #else
  2215. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  2216. #endif
  2217. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  2218. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  2219. #endif
  2220. END_MENU();
  2221. }
  2222. /**
  2223. *
  2224. * "Control" > "Filament" submenu
  2225. *
  2226. */
  2227. void lcd_control_filament_menu() {
  2228. START_MENU();
  2229. MENU_BACK(MSG_CONTROL);
  2230. #if ENABLED(LIN_ADVANCE)
  2231. MENU_ITEM_EDIT_ACCESSOR(float3, MSG_ADVANCE_K, planner.get_extruder_advance_k, planner.set_extruder_advance_k, 0, 999);
  2232. #endif
  2233. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  2234. if (volumetric_enabled) {
  2235. #if EXTRUDERS == 1
  2236. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2237. #else // EXTRUDERS > 1
  2238. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  2239. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  2240. #if EXTRUDERS > 2
  2241. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  2242. #if EXTRUDERS > 3
  2243. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  2244. #if EXTRUDERS > 4
  2245. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
  2246. #endif // EXTRUDERS > 4
  2247. #endif // EXTRUDERS > 3
  2248. #endif // EXTRUDERS > 2
  2249. #endif // EXTRUDERS > 1
  2250. }
  2251. END_MENU();
  2252. }
  2253. /**
  2254. *
  2255. * "Control" > "Contrast" submenu
  2256. *
  2257. */
  2258. #if HAS_LCD_CONTRAST
  2259. void lcd_set_contrast() {
  2260. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2261. ENCODER_DIRECTION_NORMAL();
  2262. if (encoderPosition) {
  2263. set_lcd_contrast(lcd_contrast + encoderPosition);
  2264. encoderPosition = 0;
  2265. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2266. }
  2267. if (lcdDrawUpdate) {
  2268. lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
  2269. #if LCD_CONTRAST_MAX >= 100
  2270. itostr3(lcd_contrast)
  2271. #else
  2272. itostr2(lcd_contrast)
  2273. #endif
  2274. );
  2275. }
  2276. }
  2277. #endif // HAS_LCD_CONTRAST
  2278. /**
  2279. *
  2280. * "Control" > "Retract" submenu
  2281. *
  2282. */
  2283. #if ENABLED(FWRETRACT)
  2284. void lcd_control_retract_menu() {
  2285. START_MENU();
  2286. MENU_BACK(MSG_CONTROL);
  2287. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  2288. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  2289. #if EXTRUDERS > 1
  2290. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  2291. #endif
  2292. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  2293. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  2294. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, -100, 100);
  2295. #if EXTRUDERS > 1
  2296. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, -100, 100);
  2297. #endif
  2298. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  2299. END_MENU();
  2300. }
  2301. #endif // FWRETRACT
  2302. #if ENABLED(SDSUPPORT)
  2303. #if !PIN_EXISTS(SD_DETECT)
  2304. void lcd_sd_refresh() {
  2305. card.initsd();
  2306. encoderTopLine = 0;
  2307. }
  2308. #endif
  2309. void lcd_sd_updir() {
  2310. card.updir();
  2311. encoderTopLine = 0;
  2312. screen_changed = true;
  2313. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2314. }
  2315. /**
  2316. *
  2317. * "Print from SD" submenu
  2318. *
  2319. */
  2320. void lcd_sdcard_menu() {
  2321. ENCODER_DIRECTION_MENUS();
  2322. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  2323. const uint16_t fileCnt = card.getnrfilenames();
  2324. START_MENU();
  2325. MENU_BACK(MSG_MAIN);
  2326. card.getWorkDirName();
  2327. if (card.filename[0] == '/') {
  2328. #if !PIN_EXISTS(SD_DETECT)
  2329. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  2330. #endif
  2331. }
  2332. else {
  2333. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  2334. }
  2335. for (uint16_t i = 0; i < fileCnt; i++) {
  2336. if (_menuLineNr == _thisItemNr) {
  2337. const uint16_t nr =
  2338. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  2339. fileCnt - 1 -
  2340. #endif
  2341. i;
  2342. #if ENABLED(SDCARD_SORT_ALPHA)
  2343. card.getfilename_sorted(nr);
  2344. #else
  2345. card.getfilename(nr);
  2346. #endif
  2347. if (card.filenameIsDir)
  2348. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2349. else
  2350. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2351. }
  2352. else {
  2353. MENU_ITEM_DUMMY();
  2354. }
  2355. }
  2356. END_MENU();
  2357. }
  2358. #endif //SDSUPPORT
  2359. #if ENABLED(LCD_INFO_MENU)
  2360. #if ENABLED(PRINTCOUNTER)
  2361. /**
  2362. *
  2363. * About Printer > Statistics submenu
  2364. *
  2365. */
  2366. void lcd_info_stats_menu() {
  2367. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2368. char buffer[21];
  2369. printStatistics stats = print_job_timer.getStats();
  2370. START_SCREEN(); // 12345678901234567890
  2371. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  2372. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  2373. duration_t elapsed = stats.printTime;
  2374. elapsed.toString(buffer);
  2375. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  2376. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2377. elapsed = stats.longestPrint;
  2378. elapsed.toString(buffer);
  2379. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  2380. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  2381. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  2382. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  2383. STATIC_ITEM("", false, false, buffer); // 125m
  2384. END_SCREEN();
  2385. }
  2386. #endif // PRINTCOUNTER
  2387. /**
  2388. *
  2389. * About Printer > Thermistors
  2390. *
  2391. */
  2392. void lcd_info_thermistors_menu() {
  2393. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2394. START_SCREEN();
  2395. #define THERMISTOR_ID TEMP_SENSOR_0
  2396. #include "thermistornames.h"
  2397. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  2398. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  2399. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  2400. #if TEMP_SENSOR_1 != 0
  2401. #undef THERMISTOR_ID
  2402. #define THERMISTOR_ID TEMP_SENSOR_1
  2403. #include "thermistornames.h"
  2404. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  2405. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  2406. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  2407. #endif
  2408. #if TEMP_SENSOR_2 != 0
  2409. #undef THERMISTOR_ID
  2410. #define THERMISTOR_ID TEMP_SENSOR_2
  2411. #include "thermistornames.h"
  2412. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  2413. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  2414. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  2415. #endif
  2416. #if TEMP_SENSOR_3 != 0
  2417. #undef THERMISTOR_ID
  2418. #define THERMISTOR_ID TEMP_SENSOR_3
  2419. #include "thermistornames.h"
  2420. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  2421. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  2422. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  2423. #endif
  2424. #if TEMP_SENSOR_BED != 0
  2425. #undef THERMISTOR_ID
  2426. #define THERMISTOR_ID TEMP_SENSOR_BED
  2427. #include "thermistornames.h"
  2428. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  2429. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  2430. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  2431. #endif
  2432. END_SCREEN();
  2433. }
  2434. /**
  2435. *
  2436. * About Printer > Board Info
  2437. *
  2438. */
  2439. void lcd_info_board_menu() {
  2440. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2441. START_SCREEN();
  2442. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  2443. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  2444. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  2445. #if POWER_SUPPLY == 0
  2446. STATIC_ITEM(MSG_INFO_PSU ": Generic", true);
  2447. #elif POWER_SUPPLY == 1
  2448. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  2449. #elif POWER_SUPPLY == 2
  2450. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  2451. #endif
  2452. END_SCREEN();
  2453. }
  2454. /**
  2455. *
  2456. * About Printer > Printer Info
  2457. *
  2458. */
  2459. void lcd_info_printer_menu() {
  2460. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  2461. START_SCREEN();
  2462. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  2463. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  2464. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  2465. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  2466. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  2467. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  2468. END_SCREEN();
  2469. }
  2470. /**
  2471. *
  2472. * "About Printer" submenu
  2473. *
  2474. */
  2475. void lcd_info_menu() {
  2476. START_MENU();
  2477. MENU_BACK(MSG_MAIN);
  2478. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  2479. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  2480. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  2481. #if ENABLED(PRINTCOUNTER)
  2482. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  2483. #endif
  2484. END_MENU();
  2485. }
  2486. #endif // LCD_INFO_MENU
  2487. /**
  2488. *
  2489. * Filament Change Feature Screens
  2490. *
  2491. */
  2492. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  2493. // Portions from STATIC_ITEM...
  2494. #define HOTEND_STATUS_ITEM() do { \
  2495. if (_menuLineNr == _thisItemNr) { \
  2496. if (lcdDrawUpdate) \
  2497. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(MSG_FILAMENT_CHANGE_NOZZLE), false, true); \
  2498. lcd_implementation_hotend_status(_lcdLineNr); \
  2499. if (_skipStatic && encoderLine <= _thisItemNr) { \
  2500. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  2501. ++encoderLine; \
  2502. } \
  2503. else \
  2504. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING; \
  2505. } \
  2506. ++_thisItemNr; \
  2507. } while(0)
  2508. void lcd_filament_change_toocold_menu() {
  2509. START_MENU();
  2510. STATIC_ITEM(MSG_HEATING_FAILED_LCD, true, true);
  2511. STATIC_ITEM(MSG_FILAMENT_CHANGE_MINTEMP STRINGIFY(EXTRUDE_MINTEMP) ".", false, false);
  2512. MENU_BACK(MSG_BACK);
  2513. #if LCD_HEIGHT > 4
  2514. STATIC_ITEM(" ");
  2515. #endif
  2516. HOTEND_STATUS_ITEM();
  2517. END_MENU();
  2518. }
  2519. void lcd_filament_change_resume_print() {
  2520. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_RESUME_PRINT;
  2521. }
  2522. void lcd_filament_change_extrude_more() {
  2523. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_EXTRUDE_MORE;
  2524. }
  2525. void lcd_filament_change_option_menu() {
  2526. START_MENU();
  2527. #if LCD_HEIGHT > 2
  2528. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  2529. #endif
  2530. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_filament_change_resume_print);
  2531. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_filament_change_extrude_more);
  2532. END_MENU();
  2533. }
  2534. void lcd_filament_change_init_message() {
  2535. START_SCREEN();
  2536. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2537. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  2538. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  2539. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  2540. #define __FC_LINES_A 3
  2541. #else
  2542. #define __FC_LINES_A 2
  2543. #endif
  2544. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  2545. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  2546. #define _FC_LINES_A (__FC_LINES_A + 1)
  2547. #else
  2548. #define _FC_LINES_A __FC_LINES_A
  2549. #endif
  2550. #if LCD_HEIGHT > _FC_LINES_A + 1
  2551. STATIC_ITEM(" ");
  2552. #endif
  2553. HOTEND_STATUS_ITEM();
  2554. END_SCREEN();
  2555. }
  2556. void lcd_filament_change_unload_message() {
  2557. START_SCREEN();
  2558. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2559. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  2560. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  2561. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  2562. #define __FC_LINES_B 3
  2563. #else
  2564. #define __FC_LINES_B 2
  2565. #endif
  2566. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  2567. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  2568. #define _FC_LINES_B (__FC_LINES_B + 1)
  2569. #else
  2570. #define _FC_LINES_B __FC_LINES_B
  2571. #endif
  2572. #if LCD_HEIGHT > _FC_LINES_B + 1
  2573. STATIC_ITEM(" ");
  2574. #endif
  2575. HOTEND_STATUS_ITEM();
  2576. END_SCREEN();
  2577. }
  2578. void lcd_filament_change_wait_for_nozzles_to_heat() {
  2579. START_SCREEN();
  2580. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2581. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_1);
  2582. #ifdef MSG_FILAMENT_CHANGE_HEATING_2
  2583. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEATING_2);
  2584. #define _FC_LINES_C 3
  2585. #else
  2586. #define _FC_LINES_C 2
  2587. #endif
  2588. #if LCD_HEIGHT > _FC_LINES_C + 1
  2589. STATIC_ITEM(" ");
  2590. #endif
  2591. HOTEND_STATUS_ITEM();
  2592. END_SCREEN();
  2593. }
  2594. void lcd_filament_change_heat_nozzle() {
  2595. START_SCREEN();
  2596. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2597. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_1);
  2598. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2599. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEAT_2);
  2600. #define _FC_LINES_D 3
  2601. #else
  2602. #define _FC_LINES_D 2
  2603. #endif
  2604. #if LCD_HEIGHT > _FC_LINES_D + 1
  2605. STATIC_ITEM(" ");
  2606. #endif
  2607. HOTEND_STATUS_ITEM();
  2608. END_SCREEN();
  2609. }
  2610. void lcd_filament_change_insert_message() {
  2611. START_SCREEN();
  2612. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2613. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  2614. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  2615. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  2616. #define __FC_LINES_E 3
  2617. #else
  2618. #define __FC_LINES_E 2
  2619. #endif
  2620. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  2621. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  2622. #define _FC_LINES_E (__FC_LINES_E + 1)
  2623. #else
  2624. #define _FC_LINES_E __FC_LINES_E
  2625. #endif
  2626. #if LCD_HEIGHT > _FC_LINES_E + 1
  2627. STATIC_ITEM(" ");
  2628. #endif
  2629. HOTEND_STATUS_ITEM();
  2630. END_SCREEN();
  2631. }
  2632. void lcd_filament_change_load_message() {
  2633. START_SCREEN();
  2634. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2635. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  2636. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  2637. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  2638. #define __FC_LINES_F 3
  2639. #else
  2640. #define __FC_LINES_F 2
  2641. #endif
  2642. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  2643. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  2644. #define _FC_LINES_F (__FC_LINES_F + 1)
  2645. #else
  2646. #define _FC_LINES_F __FC_LINES_F
  2647. #endif
  2648. #if LCD_HEIGHT > _FC_LINES_F + 1
  2649. STATIC_ITEM(" ");
  2650. #endif
  2651. HOTEND_STATUS_ITEM();
  2652. END_SCREEN();
  2653. }
  2654. void lcd_filament_change_extrude_message() {
  2655. START_SCREEN();
  2656. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2657. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  2658. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  2659. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  2660. #define __FC_LINES_G 3
  2661. #else
  2662. #define __FC_LINES_G 2
  2663. #endif
  2664. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  2665. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  2666. #define _FC_LINES_G (__FC_LINES_G + 1)
  2667. #else
  2668. #define _FC_LINES_G __FC_LINES_G
  2669. #endif
  2670. #if LCD_HEIGHT > _FC_LINES_G + 1
  2671. STATIC_ITEM(" ");
  2672. #endif
  2673. HOTEND_STATUS_ITEM();
  2674. END_SCREEN();
  2675. }
  2676. void lcd_filament_change_resume_message() {
  2677. START_SCREEN();
  2678. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  2679. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  2680. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  2681. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  2682. #endif
  2683. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  2684. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  2685. #endif
  2686. END_SCREEN();
  2687. }
  2688. void lcd_filament_change_show_message(const FilamentChangeMessage message) {
  2689. switch (message) {
  2690. case FILAMENT_CHANGE_MESSAGE_INIT:
  2691. defer_return_to_status = true;
  2692. lcd_goto_screen(lcd_filament_change_init_message);
  2693. break;
  2694. case FILAMENT_CHANGE_MESSAGE_UNLOAD:
  2695. lcd_goto_screen(lcd_filament_change_unload_message);
  2696. break;
  2697. case FILAMENT_CHANGE_MESSAGE_INSERT:
  2698. lcd_goto_screen(lcd_filament_change_insert_message);
  2699. break;
  2700. case FILAMENT_CHANGE_MESSAGE_LOAD:
  2701. lcd_goto_screen(lcd_filament_change_load_message);
  2702. break;
  2703. case FILAMENT_CHANGE_MESSAGE_EXTRUDE:
  2704. lcd_goto_screen(lcd_filament_change_extrude_message);
  2705. break;
  2706. case FILAMENT_CHANGE_MESSAGE_CLICK_TO_HEAT_NOZZLE:
  2707. lcd_goto_screen(lcd_filament_change_heat_nozzle);
  2708. break;
  2709. case FILAMENT_CHANGE_MESSAGE_WAIT_FOR_NOZZLES_TO_HEAT:
  2710. lcd_goto_screen(lcd_filament_change_wait_for_nozzles_to_heat);
  2711. break;
  2712. case FILAMENT_CHANGE_MESSAGE_OPTION:
  2713. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_WAIT_FOR;
  2714. lcd_goto_screen(lcd_filament_change_option_menu);
  2715. break;
  2716. case FILAMENT_CHANGE_MESSAGE_RESUME:
  2717. lcd_goto_screen(lcd_filament_change_resume_message);
  2718. break;
  2719. case FILAMENT_CHANGE_MESSAGE_STATUS:
  2720. lcd_return_to_status();
  2721. break;
  2722. }
  2723. }
  2724. #endif // FILAMENT_CHANGE_FEATURE
  2725. /**
  2726. *
  2727. * Functions for editing single values
  2728. *
  2729. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  2730. *
  2731. * For example, DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1) expands into these functions:
  2732. *
  2733. * bool _menu_edit_int3();
  2734. * void menu_edit_int3(); // edit int (interactively)
  2735. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  2736. * void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2737. * void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue);
  2738. * void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback); // edit int with callback
  2739. * void _menu_action_setting_edit_accessor_int3(const char * const pstr, int (*pget)(), void (*pset)(int), const int minValue, const int maxValue);
  2740. * void menu_action_setting_edit_accessor_int3(const char * const pstr, int (*pget)(), void (*pset)(int), const int minValue, const int maxValue); // edit int via pget and pset accessor functions
  2741. *
  2742. * You can then use one of the menu macros to present the edit interface:
  2743. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  2744. *
  2745. * This expands into a more primitive menu item:
  2746. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2747. *
  2748. *
  2749. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  2750. *
  2751. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2752. *
  2753. * Values that are get/set via functions (As opposed to global variables) can use the accessor form:
  2754. * MENU_ITEM_EDIT_ACCESSOR(int3, MSG_SPEED, get_feedrate_percentage, set_feedrate_percentage, 10, 999)
  2755. */
  2756. #define DEFINE_MENU_EDIT_TYPE(_type, _name, _strFunc, _scale) \
  2757. bool _menu_edit_ ## _name () { \
  2758. ENCODER_DIRECTION_NORMAL(); \
  2759. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2760. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  2761. if (lcdDrawUpdate) \
  2762. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
  2763. if (lcd_clicked) { \
  2764. _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
  2765. if (editValue != NULL) \
  2766. *((_type*)editValue) = value; \
  2767. else if (editSetter != NULL) \
  2768. ((void (*)(_type))editSetter)(value); \
  2769. lcd_goto_previous_menu(); \
  2770. } \
  2771. return lcd_clicked; \
  2772. } \
  2773. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  2774. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  2775. void _menu_action_setting_edit_ ## _name (const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
  2776. lcd_save_previous_screen(); \
  2777. \
  2778. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  2779. \
  2780. editLabel = pstr; \
  2781. editValue = ptr; \
  2782. editSetter = NULL; \
  2783. minEditValue = minValue * _scale; \
  2784. maxEditValue = maxValue * _scale - minEditValue; \
  2785. encoderPosition = (*ptr) * _scale - minEditValue; \
  2786. } \
  2787. void menu_action_setting_edit_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
  2788. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2789. currentScreen = menu_edit_ ## _name; \
  2790. } \
  2791. void menu_action_setting_edit_callback_ ## _name (const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback) { \
  2792. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2793. currentScreen = menu_edit_callback_ ## _name; \
  2794. callbackFunc = callback; \
  2795. } \
  2796. void _menu_action_setting_edit_accessor_ ## _name (const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue) { \
  2797. lcd_save_previous_screen(); \
  2798. \
  2799. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  2800. \
  2801. editLabel = pstr; \
  2802. editValue = NULL; \
  2803. editSetter = pset; \
  2804. minEditValue = minValue * _scale; \
  2805. maxEditValue = maxValue * _scale - minEditValue; \
  2806. encoderPosition = pget() * _scale - minEditValue; \
  2807. } \
  2808. void menu_action_setting_edit_accessor_ ## _name (const char * const pstr, _type (*pget)(), void (*pset)(_type), const _type minValue, const _type maxValue) { \
  2809. _menu_action_setting_edit_accessor_ ## _name(pstr, pget, pset, minValue, maxValue); \
  2810. currentScreen = menu_edit_ ## _name; \
  2811. } \
  2812. typedef void _name
  2813. DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1);
  2814. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
  2815. DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
  2816. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
  2817. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01);
  2818. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
  2819. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
  2820. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
  2821. DEFINE_MENU_EDIT_TYPE(unsigned long, long5, ftostr5rj, 0.01);
  2822. /**
  2823. *
  2824. * Handlers for RepRap World Keypad input
  2825. *
  2826. */
  2827. #if ENABLED(REPRAPWORLD_KEYPAD)
  2828. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  2829. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2830. encoderPosition = dir;
  2831. switch (axis) {
  2832. case X_AXIS: lcd_move_x(); break;
  2833. case Y_AXIS: lcd_move_y(); break;
  2834. case Z_AXIS: lcd_move_z();
  2835. default: break;
  2836. }
  2837. }
  2838. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  2839. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  2840. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  2841. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  2842. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  2843. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  2844. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  2845. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  2846. inline void handle_reprapworld_keypad() {
  2847. static uint8_t keypad_debounce = 0;
  2848. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  2849. if (keypad_debounce > 0) keypad_debounce--;
  2850. }
  2851. else if (!keypad_debounce) {
  2852. keypad_debounce = 2;
  2853. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  2854. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  2855. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2856. #endif
  2857. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  2858. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  2859. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2860. #endif
  2861. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  2862. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  2863. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  2864. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  2865. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  2866. }
  2867. else {
  2868. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  2869. }
  2870. }
  2871. }
  2872. #endif // REPRAPWORLD_KEYPAD
  2873. /**
  2874. *
  2875. * Menu actions
  2876. *
  2877. */
  2878. void _menu_action_back() { lcd_goto_previous_menu(); }
  2879. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  2880. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  2881. void menu_action_function(screenFunc_t func) { (*func)(); }
  2882. #if ENABLED(SDSUPPORT)
  2883. void menu_action_sdfile(const char* filename, char* longFilename) {
  2884. UNUSED(longFilename);
  2885. card.openAndPrintFile(filename);
  2886. lcd_return_to_status();
  2887. }
  2888. void menu_action_sddirectory(const char* filename, char* longFilename) {
  2889. UNUSED(longFilename);
  2890. card.chdir(filename);
  2891. encoderPosition = 0;
  2892. screen_changed = true;
  2893. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2894. }
  2895. #endif //SDSUPPORT
  2896. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr ^= true; lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; }
  2897. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  2898. menu_action_setting_edit_bool(pstr, ptr);
  2899. (*callback)();
  2900. }
  2901. void menu_action_setting_edit_accessor_bool(const char* pstr, bool (*pget)(), void (*pset)(bool)) {
  2902. UNUSED(pstr);
  2903. pset(!pget());
  2904. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2905. }
  2906. #endif // ULTIPANEL
  2907. void lcd_init() {
  2908. lcd_implementation_init(
  2909. #if ENABLED(LCD_PROGRESS_BAR)
  2910. true
  2911. #endif
  2912. );
  2913. #if ENABLED(NEWPANEL)
  2914. #if BUTTON_EXISTS(EN1)
  2915. SET_INPUT_PULLUP(BTN_EN1);
  2916. #endif
  2917. #if BUTTON_EXISTS(EN2)
  2918. SET_INPUT_PULLUP(BTN_EN2);
  2919. #endif
  2920. #if BUTTON_EXISTS(ENC)
  2921. SET_INPUT_PULLUP(BTN_ENC);
  2922. #endif
  2923. #if ENABLED(REPRAPWORLD_KEYPAD)
  2924. SET_OUTPUT(SHIFT_CLK);
  2925. OUT_WRITE(SHIFT_LD, HIGH);
  2926. SET_INPUT_PULLUP(SHIFT_OUT);
  2927. #endif
  2928. #if BUTTON_EXISTS(UP)
  2929. SET_INPUT(BTN_UP);
  2930. #endif
  2931. #if BUTTON_EXISTS(DWN)
  2932. SET_INPUT(BTN_DWN);
  2933. #endif
  2934. #if BUTTON_EXISTS(LFT)
  2935. SET_INPUT(BTN_LFT);
  2936. #endif
  2937. #if BUTTON_EXISTS(RT)
  2938. SET_INPUT(BTN_RT);
  2939. #endif
  2940. #else // !NEWPANEL
  2941. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  2942. SET_OUTPUT(SR_DATA_PIN);
  2943. SET_OUTPUT(SR_CLK_PIN);
  2944. #elif defined(SHIFT_CLK)
  2945. SET_OUTPUT(SHIFT_CLK);
  2946. OUT_WRITE(SHIFT_LD, HIGH);
  2947. OUT_WRITE(SHIFT_EN, LOW);
  2948. SET_INPUT_PULLUP(SHIFT_OUT);
  2949. #endif // SR_LCD_2W_NL
  2950. #endif // !NEWPANEL
  2951. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2952. SET_INPUT_PULLUP(SD_DETECT_PIN);
  2953. lcd_sd_status = 2; // UNKNOWN
  2954. #endif
  2955. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2956. slow_buttons = 0;
  2957. #endif
  2958. lcd_buttons_update();
  2959. #if ENABLED(ULTIPANEL)
  2960. encoderDiff = 0;
  2961. #endif
  2962. }
  2963. int lcd_strlen(const char* s) {
  2964. int i = 0, j = 0;
  2965. while (s[i]) {
  2966. #if ENABLED(MAPPER_NON)
  2967. j++;
  2968. #else
  2969. if ((s[i] & 0xC0u) != 0x80u) j++;
  2970. #endif
  2971. i++;
  2972. }
  2973. return j;
  2974. }
  2975. int lcd_strlen_P(const char* s) {
  2976. int j = 0;
  2977. while (pgm_read_byte(s)) {
  2978. #if ENABLED(MAPPER_NON)
  2979. j++;
  2980. #else
  2981. if ((pgm_read_byte(s) & 0xC0u) != 0x80u) j++;
  2982. #endif
  2983. s++;
  2984. }
  2985. return j;
  2986. }
  2987. bool lcd_blink() {
  2988. static uint8_t blink = 0;
  2989. static millis_t next_blink_ms = 0;
  2990. millis_t ms = millis();
  2991. if (ELAPSED(ms, next_blink_ms)) {
  2992. blink ^= 0xFF;
  2993. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  2994. }
  2995. return blink != 0;
  2996. }
  2997. /**
  2998. * Update the LCD, read encoder buttons, etc.
  2999. * - Read button states
  3000. * - Check the SD Card slot state
  3001. * - Act on RepRap World keypad input
  3002. * - Update the encoder position
  3003. * - Apply acceleration to the encoder position
  3004. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  3005. * - Reset the Info Screen timeout if there's any input
  3006. * - Update status indicators, if any
  3007. *
  3008. * Run the current LCD menu handler callback function:
  3009. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  3010. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  3011. * - Call the menu handler. Menu handlers should do the following:
  3012. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  3013. * (Encoder events automatically set lcdDrawUpdate for you.)
  3014. * - if (lcdDrawUpdate) { redraw }
  3015. * - Before exiting the handler set lcdDrawUpdate to:
  3016. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  3017. * - LCDVIEW_REDRAW_NOW or LCDVIEW_NONE to keep drawing, but only in this loop.
  3018. * - LCDVIEW_CALL_REDRAW_NEXT to keep drawing and draw on the next loop also.
  3019. * - LCDVIEW_CALL_NO_REDRAW to keep drawing (or start drawing) with no redraw on the next loop.
  3020. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  3021. * so don't change lcdDrawUpdate without considering this.
  3022. *
  3023. * After the menu handler callback runs (or not):
  3024. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  3025. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  3026. *
  3027. * No worries. This function is only called from the main thread.
  3028. */
  3029. void lcd_update() {
  3030. #if ENABLED(ULTIPANEL)
  3031. static millis_t return_to_status_ms = 0;
  3032. manage_manual_move();
  3033. lcd_buttons_update();
  3034. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3035. const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
  3036. #else
  3037. constexpr bool UBL_CONDITION = true;
  3038. #endif
  3039. // If the action button is pressed...
  3040. if (UBL_CONDITION && LCD_CLICKED) {
  3041. if (!wait_for_unclick) { // If not waiting for a debounce release:
  3042. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  3043. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  3044. wait_for_user = false; // Any click clears wait for user
  3045. lcd_quick_feedback(); // Always make a click sound
  3046. }
  3047. }
  3048. else wait_for_unclick = false;
  3049. #endif
  3050. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  3051. const bool sd_status = IS_SD_INSERTED;
  3052. if (sd_status != lcd_sd_status && lcd_detected()) {
  3053. if (sd_status) {
  3054. card.initsd();
  3055. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  3056. }
  3057. else {
  3058. card.release();
  3059. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  3060. }
  3061. lcd_sd_status = sd_status;
  3062. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3063. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3064. #if ENABLED(LCD_PROGRESS_BAR)
  3065. currentScreen == lcd_status_screen
  3066. #endif
  3067. );
  3068. }
  3069. #endif //SDSUPPORT && SD_DETECT_PIN
  3070. const millis_t ms = millis();
  3071. if (ELAPSED(ms, next_lcd_update_ms)
  3072. #if ENABLED(DOGLCD)
  3073. || drawing_screen
  3074. #endif
  3075. ) {
  3076. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  3077. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  3078. lcd_implementation_update_indicators();
  3079. #endif
  3080. #if ENABLED(ULTIPANEL)
  3081. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3082. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3083. #endif
  3084. #if ENABLED(REPRAPWORLD_KEYPAD)
  3085. handle_reprapworld_keypad();
  3086. #endif
  3087. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  3088. if (encoderPastThreshold || lcd_clicked) {
  3089. if (encoderPastThreshold) {
  3090. int32_t encoderMultiplier = 1;
  3091. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  3092. if (encoderRateMultiplierEnabled) {
  3093. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  3094. if (lastEncoderMovementMillis != 0) {
  3095. // Note that the rate is always calculated between to passes through the
  3096. // loop and that the abs of the encoderDiff value is tracked.
  3097. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  3098. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  3099. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  3100. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  3101. SERIAL_ECHO_START;
  3102. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  3103. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  3104. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  3105. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  3106. SERIAL_EOL;
  3107. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  3108. }
  3109. lastEncoderMovementMillis = ms;
  3110. } // encoderRateMultiplierEnabled
  3111. #endif //ENCODER_RATE_MULTIPLIER
  3112. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  3113. encoderDiff = 0;
  3114. }
  3115. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3116. lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
  3117. }
  3118. #endif // ULTIPANEL
  3119. // We arrive here every ~100ms when idling often enough.
  3120. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  3121. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  3122. if (
  3123. #if ENABLED(ULTIPANEL)
  3124. currentScreen == lcd_status_screen &&
  3125. #endif
  3126. !lcd_status_update_delay--
  3127. ) {
  3128. lcd_status_update_delay = 9
  3129. #if ENABLED(DOGLCD)
  3130. + 3
  3131. #endif
  3132. ;
  3133. max_display_update_time--;
  3134. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3135. }
  3136. // then we want to use 1/2 of the time only.
  3137. uint16_t bbr2 = planner.block_buffer_runtime() >> 1;
  3138. #if ENABLED(DOGLCD)
  3139. if ((lcdDrawUpdate || drawing_screen) && (!bbr2 || (bbr2 > max_display_update_time)))
  3140. #else
  3141. if (lcdDrawUpdate && (!bbr2 || (bbr2 > max_display_update_time)))
  3142. #endif
  3143. {
  3144. #if ENABLED(DOGLCD)
  3145. if (!drawing_screen)
  3146. #endif
  3147. {
  3148. switch (lcdDrawUpdate) {
  3149. case LCDVIEW_CALL_NO_REDRAW:
  3150. lcdDrawUpdate = LCDVIEW_NONE;
  3151. break;
  3152. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  3153. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  3154. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3155. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  3156. case LCDVIEW_NONE:
  3157. break;
  3158. } // switch
  3159. }
  3160. #if ENABLED(ULTIPANEL)
  3161. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  3162. #else
  3163. #define CURRENTSCREEN() lcd_status_screen()
  3164. #endif
  3165. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  3166. if (!drawing_screen) {
  3167. u8g.firstPage();
  3168. drawing_screen = 1;
  3169. }
  3170. lcd_setFont(FONT_MENU);
  3171. u8g.setColorIndex(1);
  3172. CURRENTSCREEN();
  3173. if (drawing_screen && (drawing_screen = u8g.nextPage())) {
  3174. NOLESS(max_display_update_time, millis() - ms);
  3175. return;
  3176. }
  3177. #else
  3178. CURRENTSCREEN();
  3179. #endif
  3180. NOLESS(max_display_update_time, millis() - ms);
  3181. }
  3182. #if ENABLED(ULTIPANEL)
  3183. // Return to Status Screen after a timeout
  3184. if (currentScreen == lcd_status_screen || defer_return_to_status)
  3185. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  3186. else if (ELAPSED(ms, return_to_status_ms))
  3187. lcd_return_to_status();
  3188. #endif // ULTIPANEL
  3189. #if ENABLED(DOGLCD)
  3190. if (!drawing_screen)
  3191. #endif
  3192. {
  3193. switch (lcdDrawUpdate) {
  3194. case LCDVIEW_CLEAR_CALL_REDRAW:
  3195. lcd_implementation_clear();
  3196. case LCDVIEW_CALL_REDRAW_NEXT:
  3197. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  3198. break;
  3199. case LCDVIEW_REDRAW_NOW:
  3200. lcdDrawUpdate = LCDVIEW_NONE;
  3201. break;
  3202. case LCDVIEW_NONE:
  3203. break;
  3204. } // switch
  3205. }
  3206. } // ELAPSED(ms, next_lcd_update_ms)
  3207. }
  3208. void set_utf_strlen(char* s, uint8_t n) {
  3209. uint8_t i = 0, j = 0;
  3210. while (s[i] && (j < n)) {
  3211. #if ENABLED(MAPPER_NON)
  3212. j++;
  3213. #else
  3214. if ((s[i] & 0xC0u) != 0x80u) j++;
  3215. #endif
  3216. i++;
  3217. }
  3218. while (j++ < n) s[i++] = ' ';
  3219. s[i] = '\0';
  3220. }
  3221. void lcd_finishstatus(bool persist=false) {
  3222. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  3223. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  3224. UNUSED(persist);
  3225. #endif
  3226. #if ENABLED(LCD_PROGRESS_BAR)
  3227. progress_bar_ms = millis();
  3228. #if PROGRESS_MSG_EXPIRE > 0
  3229. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  3230. #endif
  3231. #endif
  3232. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  3233. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  3234. previous_lcd_status_ms = millis(); //get status message to show up for a while
  3235. #endif
  3236. }
  3237. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  3238. void dontExpireStatus() { expire_status_ms = 0; }
  3239. #endif
  3240. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  3241. void lcd_setstatus(const char * const message, const bool persist) {
  3242. if (lcd_status_message_level > 0) return;
  3243. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  3244. lcd_finishstatus(persist);
  3245. }
  3246. void lcd_setstatuspgm(const char * const message, const uint8_t level) {
  3247. if (level < lcd_status_message_level) return;
  3248. lcd_status_message_level = level;
  3249. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  3250. lcd_finishstatus(level > 0);
  3251. }
  3252. void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
  3253. if (level < lcd_status_message_level) return;
  3254. lcd_status_message_level = level;
  3255. va_list args;
  3256. va_start(args, fmt);
  3257. vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args);
  3258. va_end(args);
  3259. lcd_finishstatus(level > 0);
  3260. }
  3261. void lcd_setalertstatuspgm(const char * const message) {
  3262. lcd_setstatuspgm(message, 1);
  3263. #if ENABLED(ULTIPANEL)
  3264. lcd_return_to_status();
  3265. #endif
  3266. }
  3267. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  3268. #if HAS_LCD_CONTRAST
  3269. void set_lcd_contrast(const int value) {
  3270. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  3271. u8g.setContrast(lcd_contrast);
  3272. }
  3273. #endif
  3274. #if ENABLED(ULTIPANEL)
  3275. /**
  3276. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  3277. * These values are independent of which pins are used for EN_A and EN_B indications
  3278. * The rotary encoder part is also independent to the chipset used for the LCD
  3279. */
  3280. #if defined(EN_A) && defined(EN_B)
  3281. #define encrot0 0
  3282. #define encrot1 2
  3283. #define encrot2 3
  3284. #define encrot3 1
  3285. #endif
  3286. #define GET_BUTTON_STATES(DST) \
  3287. uint8_t new_##DST = 0; \
  3288. WRITE(SHIFT_LD, LOW); \
  3289. WRITE(SHIFT_LD, HIGH); \
  3290. for (int8_t i = 0; i < 8; i++) { \
  3291. new_##DST >>= 1; \
  3292. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  3293. WRITE(SHIFT_CLK, HIGH); \
  3294. WRITE(SHIFT_CLK, LOW); \
  3295. } \
  3296. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  3297. /**
  3298. * Read encoder buttons from the hardware registers
  3299. * Warning: This function is called from interrupt context!
  3300. */
  3301. void lcd_buttons_update() {
  3302. static uint8_t lastEncoderBits;
  3303. millis_t now = millis();
  3304. if (ELAPSED(now, next_button_update_ms)) {
  3305. #if ENABLED(NEWPANEL)
  3306. uint8_t newbutton = 0;
  3307. #if BUTTON_EXISTS(EN1)
  3308. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  3309. #endif
  3310. #if BUTTON_EXISTS(EN2)
  3311. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  3312. #endif
  3313. #if BUTTON_EXISTS(ENC)
  3314. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  3315. #endif
  3316. #if LCD_HAS_DIRECTIONAL_BUTTONS
  3317. // Manage directional buttons
  3318. #if ENABLED(REVERSE_MENU_DIRECTION)
  3319. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  3320. #else
  3321. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  3322. #endif
  3323. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  3324. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  3325. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  3326. #else
  3327. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  3328. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  3329. #endif
  3330. if (false) {
  3331. // for the else-ifs below
  3332. }
  3333. #if BUTTON_EXISTS(UP)
  3334. else if (BUTTON_PRESSED(UP)) {
  3335. encoderDiff = -(ENCODER_UD_STEPS);
  3336. next_button_update_ms = now + 300;
  3337. }
  3338. #endif
  3339. #if BUTTON_EXISTS(DWN)
  3340. else if (BUTTON_PRESSED(DWN)) {
  3341. encoderDiff = ENCODER_UD_STEPS;
  3342. next_button_update_ms = now + 300;
  3343. }
  3344. #endif
  3345. #if BUTTON_EXISTS(LFT)
  3346. else if (BUTTON_PRESSED(LFT)) {
  3347. encoderDiff = -(ENCODER_LR_PULSES);
  3348. next_button_update_ms = now + 300;
  3349. }
  3350. #endif
  3351. #if BUTTON_EXISTS(RT)
  3352. else if (BUTTON_PRESSED(RT)) {
  3353. encoderDiff = ENCODER_LR_PULSES;
  3354. next_button_update_ms = now + 300;
  3355. }
  3356. #endif
  3357. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  3358. buttons = newbutton;
  3359. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  3360. buttons |= slow_buttons;
  3361. #endif
  3362. #if ENABLED(REPRAPWORLD_KEYPAD)
  3363. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  3364. #endif
  3365. #else
  3366. GET_BUTTON_STATES(buttons);
  3367. #endif //!NEWPANEL
  3368. } // next_button_update_ms
  3369. // Manage encoder rotation
  3370. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  3371. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  3372. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  3373. #elif ENABLED(REVERSE_MENU_DIRECTION)
  3374. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  3375. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  3376. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  3377. #define ENCODER_DIFF_CW (encoderDiff--)
  3378. #define ENCODER_DIFF_CCW (encoderDiff++)
  3379. #else
  3380. #define ENCODER_DIFF_CW (encoderDiff++)
  3381. #define ENCODER_DIFF_CCW (encoderDiff--)
  3382. #endif
  3383. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  3384. uint8_t enc = 0;
  3385. if (buttons & EN_A) enc |= B01;
  3386. if (buttons & EN_B) enc |= B10;
  3387. if (enc != lastEncoderBits) {
  3388. switch (enc) {
  3389. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  3390. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  3391. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  3392. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  3393. }
  3394. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3395. if (ubl.has_control_of_lcd_panel) {
  3396. ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
  3397. encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
  3398. // wheel has not turned.
  3399. }
  3400. #endif
  3401. lastEncoderBits = enc;
  3402. }
  3403. }
  3404. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  3405. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  3406. #else
  3407. bool lcd_detected() { return true; }
  3408. #endif
  3409. #if ENABLED(AUTO_BED_LEVELING_UBL)
  3410. void chirp_at_user() {
  3411. #if ENABLED(LCD_USE_I2C_BUZZER)
  3412. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3413. #elif PIN_EXISTS(BEEPER)
  3414. buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  3415. #endif
  3416. }
  3417. bool ubl_lcd_clicked() { return LCD_CLICKED; }
  3418. #endif
  3419. #endif // ULTIPANEL
  3420. #endif // ULTRA_LCD