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

ultralcd.cpp 100KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040
  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)
  43. millis_t previous_lcd_status_ms = 0;
  44. #endif
  45. uint8_t lcd_status_message_level;
  46. char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
  47. #if ENABLED(DOGLCD)
  48. #include "ultralcd_impl_DOGM.h"
  49. #else
  50. #include "ultralcd_impl_HD44780.h"
  51. #endif
  52. // The main status screen
  53. void lcd_status_screen();
  54. millis_t next_lcd_update_ms;
  55. 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)
  56. #if ENABLED(DAC_STEPPER_CURRENT)
  57. #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
  58. uint16_t driverPercent[XYZE];
  59. #endif
  60. #if ENABLED(ULTIPANEL)
  61. // place-holders for Ki and Kd edits
  62. float raw_Ki, raw_Kd;
  63. /**
  64. * REVERSE_MENU_DIRECTION
  65. *
  66. * To reverse the menu direction we need a general way to reverse
  67. * the direction of the encoder everywhere. So encoderDirection is
  68. * added to allow the encoder to go the other way.
  69. *
  70. * This behavior is limited to scrolling Menus and SD card listings,
  71. * and is disabled in other contexts.
  72. */
  73. #if ENABLED(REVERSE_MENU_DIRECTION)
  74. int8_t encoderDirection = 1;
  75. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  76. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  77. #else
  78. #define ENCODER_DIRECTION_NORMAL() ;
  79. #define ENCODER_DIRECTION_MENUS() ;
  80. #endif
  81. int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
  82. millis_t manual_move_start_time = 0;
  83. int8_t manual_move_axis = (int8_t)NO_AXIS;
  84. #if EXTRUDERS > 1
  85. int8_t manual_move_e_index = 0;
  86. #else
  87. #define manual_move_e_index 0
  88. #endif
  89. bool encoderRateMultiplierEnabled;
  90. int32_t lastEncoderMovementMillis;
  91. #if HAS_POWER_SWITCH
  92. extern bool powersupply;
  93. #endif
  94. #if HAS_CASE_LIGHT
  95. extern bool case_light_on;
  96. #endif
  97. const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
  98. void lcd_main_menu();
  99. void lcd_tune_menu();
  100. void lcd_prepare_menu();
  101. void lcd_move_menu();
  102. void lcd_control_menu();
  103. void lcd_control_temperature_menu();
  104. void lcd_control_temperature_preheat_material1_settings_menu();
  105. void lcd_control_temperature_preheat_material2_settings_menu();
  106. void lcd_control_motion_menu();
  107. void lcd_control_volumetric_menu();
  108. #if ENABLED(DAC_STEPPER_CURRENT)
  109. void dac_driver_commit();
  110. void dac_driver_getValues();
  111. void lcd_dac_menu();
  112. void lcd_dac_write_eeprom();
  113. #endif
  114. #if ENABLED(LCD_INFO_MENU)
  115. #if ENABLED(PRINTCOUNTER)
  116. void lcd_info_stats_menu();
  117. #endif
  118. void lcd_info_thermistors_menu();
  119. void lcd_info_board_menu();
  120. void lcd_info_menu();
  121. #endif // LCD_INFO_MENU
  122. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  123. void lcd_filament_change_option_menu();
  124. void lcd_filament_change_init_message();
  125. void lcd_filament_change_unload_message();
  126. void lcd_filament_change_insert_message();
  127. void lcd_filament_change_load_message();
  128. void lcd_filament_change_extrude_message();
  129. void lcd_filament_change_resume_message();
  130. #endif
  131. #if HAS_LCD_CONTRAST
  132. void lcd_set_contrast();
  133. #endif
  134. #if ENABLED(FWRETRACT)
  135. void lcd_control_retract_menu();
  136. #endif
  137. #if ENABLED(DELTA_CALIBRATION_MENU)
  138. void lcd_delta_calibrate_menu();
  139. #endif
  140. #if ENABLED(MANUAL_BED_LEVELING)
  141. #include "mesh_bed_leveling.h"
  142. #endif
  143. // Function pointer to menu functions.
  144. typedef void (*screenFunc_t)();
  145. // Different types of actions that can be used in menu items.
  146. #define menu_action_back(dummy) _menu_action_back()
  147. void _menu_action_back();
  148. void menu_action_submenu(screenFunc_t data);
  149. void menu_action_gcode(const char* pgcode);
  150. void menu_action_function(screenFunc_t data);
  151. void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  152. void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  153. void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  154. void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  155. void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  156. void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  157. void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  158. void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  159. void menu_action_setting_edit_float62(const char* pstr, float* ptr, float minValue, float maxValue);
  160. void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  161. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
  162. void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, screenFunc_t callbackFunc);
  163. void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  164. void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  165. void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  166. void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  167. void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  168. void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  169. void menu_action_setting_edit_callback_float62(const char* pstr, float* ptr, float minValue, float maxValue, screenFunc_t callbackFunc);
  170. void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, screenFunc_t callbackFunc);
  171. #if ENABLED(SDSUPPORT)
  172. void lcd_sdcard_menu();
  173. void menu_action_sdfile(const char* filename, char* longFilename);
  174. void menu_action_sddirectory(const char* filename, char* longFilename);
  175. #endif
  176. /* Helper macros for menus */
  177. #ifndef ENCODER_FEEDRATE_DEADZONE
  178. #define ENCODER_FEEDRATE_DEADZONE 10
  179. #endif
  180. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  181. #define ENCODER_STEPS_PER_MENU_ITEM 5
  182. #endif
  183. #ifndef ENCODER_PULSES_PER_STEP
  184. #define ENCODER_PULSES_PER_STEP 1
  185. #endif
  186. /**
  187. * START_SCREEN_OR_MENU generates init code for a screen or menu
  188. *
  189. * encoderLine is the position based on the encoder
  190. * encoderTopLine is the top menu line to display
  191. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  192. * _menuLineNr is the menu item to draw and process
  193. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  194. * _countedItems is the total number of items in the menu (after one call)
  195. */
  196. #define START_SCREEN_OR_MENU(LIMIT) \
  197. ENCODER_DIRECTION_MENUS(); \
  198. encoderRateMultiplierEnabled = false; \
  199. if (encoderPosition > 0x8000) encoderPosition = 0; \
  200. static int8_t _countedItems = 0; \
  201. int8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
  202. if (_countedItems > 0 && encoderLine >= _countedItems - LIMIT) { \
  203. encoderLine = max(0, _countedItems - LIMIT); \
  204. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
  205. }
  206. #define SCREEN_OR_MENU_LOOP() \
  207. int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
  208. for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT; _lcdLineNr++, _menuLineNr++) { \
  209. _thisItemNr = 0
  210. /**
  211. * START_SCREEN Opening code for a screen having only static items.
  212. * Do simplified scrolling of the entire screen.
  213. *
  214. * START_MENU Opening code for a screen with menu items.
  215. * Scroll as-needed to keep the selected line in view.
  216. */
  217. #define START_SCREEN() \
  218. START_SCREEN_OR_MENU(LCD_HEIGHT); \
  219. encoderTopLine = encoderLine; \
  220. bool _skipStatic = false; \
  221. SCREEN_OR_MENU_LOOP()
  222. #define START_MENU() \
  223. START_SCREEN_OR_MENU(1); \
  224. NOMORE(encoderTopLine, encoderLine); \
  225. if (encoderLine >= encoderTopLine + LCD_HEIGHT) { \
  226. encoderTopLine = encoderLine - (LCD_HEIGHT - 1); \
  227. } \
  228. bool _skipStatic = true; \
  229. SCREEN_OR_MENU_LOOP()
  230. /**
  231. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  232. *
  233. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  234. * menu_action_[type](arg3...)
  235. *
  236. * Examples:
  237. * MENU_ITEM(back, MSG_WATCH, 0 [dummy parameter] )
  238. * or
  239. * MENU_BACK(MSG_WATCH)
  240. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH))
  241. * menu_action_back()
  242. *
  243. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  244. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  245. * menu_action_function(lcd_sdcard_pause)
  246. *
  247. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  248. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  249. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  250. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  251. *
  252. */
  253. #define _MENU_ITEM_PART_1(TYPE, LABEL, ...) \
  254. if (_menuLineNr == _thisItemNr) { \
  255. if (lcdDrawUpdate) \
  256. lcd_implementation_drawmenu_ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  257. if (lcd_clicked && encoderLine == _thisItemNr) {
  258. #define _MENU_ITEM_PART_2(TYPE, ...) \
  259. menu_action_ ## TYPE(__VA_ARGS__); \
  260. return; \
  261. } \
  262. } \
  263. ++_thisItemNr
  264. #define MENU_ITEM(TYPE, LABEL, ...) do { \
  265. _skipStatic = false; \
  266. _MENU_ITEM_PART_1(TYPE, LABEL, ## __VA_ARGS__); \
  267. _MENU_ITEM_PART_2(TYPE, ## __VA_ARGS__); \
  268. } while(0)
  269. #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL, 0)
  270. // Used to print static text with no visible cursor.
  271. #define STATIC_ITEM(LABEL, ...) \
  272. if (_menuLineNr == _thisItemNr) { \
  273. if (_skipStatic && encoderLine <= _thisItemNr) { \
  274. encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
  275. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT; \
  276. } \
  277. if (lcdDrawUpdate) \
  278. lcd_implementation_drawmenu_static(_lcdLineNr, PSTR(LABEL), ## __VA_ARGS__); \
  279. } \
  280. ++_thisItemNr
  281. #define END_SCREEN() \
  282. } \
  283. _countedItems = _thisItemNr
  284. #define END_MENU() \
  285. } \
  286. _countedItems = _thisItemNr; \
  287. UNUSED(_skipStatic)
  288. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  289. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  290. /**
  291. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  292. */
  293. #define MENU_MULTIPLIER_ITEM(type, label, ...) do { \
  294. _MENU_ITEM_PART_1(type, label, ## __VA_ARGS__); \
  295. encoderRateMultiplierEnabled = true; \
  296. lastEncoderMovementMillis = 0; \
  297. _MENU_ITEM_PART_2(type, ## __VA_ARGS__); \
  298. } while(0)
  299. #endif //ENCODER_RATE_MULTIPLIER
  300. #define MENU_ITEM_DUMMY() do { _thisItemNr++; } while(0)
  301. #define MENU_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  302. #define MENU_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  303. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  304. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  305. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  306. #else //!ENCODER_RATE_MULTIPLIER
  307. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, ...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## __VA_ARGS__)
  308. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, ...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## __VA_ARGS__)
  309. #endif //!ENCODER_RATE_MULTIPLIER
  310. /** Used variables to keep track of the menu */
  311. volatile uint8_t buttons; //the last checked buttons in a bit array.
  312. #if ENABLED(REPRAPWORLD_KEYPAD)
  313. volatile uint8_t buttons_reprapworld_keypad; // to store the keypad shift register values
  314. #endif
  315. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  316. volatile uint8_t slow_buttons; // Bits of the pressed buttons.
  317. #endif
  318. int8_t encoderTopLine; /* scroll offset in the current menu */
  319. millis_t next_button_update_ms;
  320. uint8_t lastEncoderBits;
  321. uint32_t encoderPosition;
  322. #if PIN_EXISTS(SD_DETECT)
  323. uint8_t lcd_sd_status;
  324. #endif
  325. typedef struct {
  326. screenFunc_t menu_function;
  327. uint32_t encoder_position;
  328. } menuPosition;
  329. screenFunc_t currentScreen = lcd_status_screen; // pointer to the currently active menu handler
  330. menuPosition screen_history[10];
  331. uint8_t screen_history_depth = 0;
  332. // LCD and menu clicks
  333. bool lcd_clicked, wait_for_unclick, defer_return_to_status;
  334. // Variables used when editing values.
  335. const char* editLabel;
  336. void* editValue;
  337. int32_t minEditValue, maxEditValue;
  338. screenFunc_t callbackFunc; // call this after editing
  339. /**
  340. * General function to go directly to a screen
  341. */
  342. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder = 0) {
  343. if (currentScreen != screen) {
  344. currentScreen = screen;
  345. encoderPosition = encoder;
  346. if (screen == lcd_status_screen) {
  347. defer_return_to_status = false;
  348. screen_history_depth = 0;
  349. }
  350. lcd_implementation_clear();
  351. #if ENABLED(LCD_PROGRESS_BAR)
  352. // For LCD_PROGRESS_BAR re-initialize custom characters
  353. lcd_set_custom_characters(screen == lcd_status_screen);
  354. #endif
  355. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  356. }
  357. }
  358. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  359. inline void lcd_save_previous_menu() {
  360. if (screen_history_depth < COUNT(screen_history)) {
  361. screen_history[screen_history_depth].menu_function = currentScreen;
  362. screen_history[screen_history_depth].encoder_position = encoderPosition;
  363. ++screen_history_depth;
  364. }
  365. }
  366. void lcd_goto_previous_menu() {
  367. if (screen_history_depth > 0) {
  368. --screen_history_depth;
  369. lcd_goto_screen(
  370. screen_history[screen_history_depth].menu_function,
  371. screen_history[screen_history_depth].encoder_position
  372. );
  373. }
  374. else
  375. lcd_return_to_status();
  376. }
  377. #endif // ULTIPANEL
  378. /**
  379. *
  380. * "Info Screen"
  381. *
  382. * This is very display-dependent, so the lcd implementation draws this.
  383. */
  384. void lcd_status_screen() {
  385. #if ENABLED(ULTIPANEL)
  386. ENCODER_DIRECTION_NORMAL();
  387. encoderRateMultiplierEnabled = false;
  388. #endif
  389. #if ENABLED(LCD_PROGRESS_BAR)
  390. millis_t ms = millis();
  391. #if DISABLED(PROGRESS_MSG_ONCE)
  392. if (ELAPSED(ms, progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME)) {
  393. progress_bar_ms = ms;
  394. }
  395. #endif
  396. #if PROGRESS_MSG_EXPIRE > 0
  397. // Handle message expire
  398. if (expire_status_ms > 0) {
  399. #if ENABLED(SDSUPPORT)
  400. if (card.isFileOpen()) {
  401. // Expire the message when printing is active
  402. if (IS_SD_PRINTING) {
  403. if (ELAPSED(ms, expire_status_ms)) {
  404. lcd_status_message[0] = '\0';
  405. expire_status_ms = 0;
  406. }
  407. }
  408. else {
  409. expire_status_ms += LCD_UPDATE_INTERVAL;
  410. }
  411. }
  412. else {
  413. expire_status_ms = 0;
  414. }
  415. #else
  416. expire_status_ms = 0;
  417. #endif //SDSUPPORT
  418. }
  419. #endif
  420. #endif //LCD_PROGRESS_BAR
  421. lcd_implementation_status_screen();
  422. #if ENABLED(ULTIPANEL)
  423. if (lcd_clicked) {
  424. #if ENABLED(FILAMENT_LCD_DISPLAY)
  425. previous_lcd_status_ms = millis(); // get status message to show up for a while
  426. #endif
  427. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  428. #if ENABLED(LCD_PROGRESS_BAR)
  429. false
  430. #endif
  431. );
  432. lcd_goto_screen(lcd_main_menu);
  433. }
  434. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  435. int new_frm = feedrate_percentage + (int32_t)encoderPosition;
  436. // Dead zone at 100% feedrate
  437. if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
  438. feedrate_percentage = 100;
  439. encoderPosition = 0;
  440. }
  441. else if (feedrate_percentage == 100) {
  442. if ((int32_t)encoderPosition > ENCODER_FEEDRATE_DEADZONE) {
  443. feedrate_percentage += (int32_t)encoderPosition - (ENCODER_FEEDRATE_DEADZONE);
  444. encoderPosition = 0;
  445. }
  446. else if ((int32_t)encoderPosition < -(ENCODER_FEEDRATE_DEADZONE)) {
  447. feedrate_percentage += (int32_t)encoderPosition + ENCODER_FEEDRATE_DEADZONE;
  448. encoderPosition = 0;
  449. }
  450. }
  451. else {
  452. feedrate_percentage = new_frm;
  453. encoderPosition = 0;
  454. }
  455. #endif // ULTIPANEL_FEEDMULTIPLY
  456. feedrate_percentage = constrain(feedrate_percentage, 10, 999);
  457. #endif //ULTIPANEL
  458. }
  459. /**
  460. *
  461. * draw the kill screen
  462. *
  463. */
  464. void kill_screen(const char* lcd_msg) {
  465. lcd_init();
  466. lcd_setalertstatuspgm(lcd_msg);
  467. #if ENABLED(DOGLCD)
  468. u8g.firstPage();
  469. do {
  470. lcd_kill_screen();
  471. } while (u8g.nextPage());
  472. #else
  473. lcd_kill_screen();
  474. #endif
  475. }
  476. #if ENABLED(ULTIPANEL)
  477. inline void line_to_current(AxisEnum axis) {
  478. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
  479. }
  480. #if ENABLED(SDSUPPORT)
  481. void lcd_sdcard_pause() {
  482. card.pauseSDPrint();
  483. print_job_timer.pause();
  484. }
  485. void lcd_sdcard_resume() {
  486. card.startFileprint();
  487. print_job_timer.start();
  488. }
  489. void lcd_sdcard_stop() {
  490. card.stopSDPrint();
  491. clear_command_queue();
  492. quickstop_stepper();
  493. print_job_timer.stop();
  494. #if ENABLED(AUTOTEMP)
  495. thermalManager.autotempShutdown();
  496. #endif
  497. wait_for_heatup = false;
  498. lcd_setstatus(MSG_PRINT_ABORTED, true);
  499. }
  500. #endif //SDSUPPORT
  501. /**
  502. *
  503. * "Main" menu
  504. *
  505. */
  506. void lcd_main_menu() {
  507. START_MENU();
  508. MENU_BACK(MSG_WATCH);
  509. //
  510. // Switch case light on/off
  511. //
  512. #if HAS_CASE_LIGHT && ENABLED(MENU_ITEM_CASE_LIGHT)
  513. if (case_light_on == 0)
  514. MENU_ITEM(gcode, MSG_LIGHTS_ON, PSTR("M355 S1"));
  515. else
  516. MENU_ITEM(gcode, MSG_LIGHTS_OFF, PSTR("M355 S0"));
  517. #endif
  518. #if ENABLED(BLTOUCH)
  519. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  520. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  521. #endif
  522. if (planner.movesplanned() || IS_SD_PRINTING) {
  523. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  524. }
  525. else {
  526. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  527. #if ENABLED(DELTA_CALIBRATION_MENU)
  528. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  529. #endif
  530. }
  531. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  532. #if ENABLED(SDSUPPORT)
  533. if (card.cardOK) {
  534. if (card.isFileOpen()) {
  535. if (card.sdprinting)
  536. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  537. else
  538. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  539. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  540. }
  541. else {
  542. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  543. #if !PIN_EXISTS(SD_DETECT)
  544. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  545. #endif
  546. }
  547. }
  548. else {
  549. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  550. #if !PIN_EXISTS(SD_DETECT)
  551. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  552. #endif
  553. }
  554. #endif //SDSUPPORT
  555. #if ENABLED(LCD_INFO_MENU)
  556. MENU_ITEM(submenu, MSG_INFO_MENU, lcd_info_menu);
  557. #endif
  558. END_MENU();
  559. }
  560. /**
  561. *
  562. * "Tune" submenu items
  563. *
  564. */
  565. /**
  566. * Set the home offset based on the current_position
  567. */
  568. void lcd_set_home_offsets() {
  569. // M428 Command
  570. enqueue_and_echo_commands_P(PSTR("M428"));
  571. lcd_return_to_status();
  572. }
  573. #if ENABLED(BABYSTEPPING)
  574. long babysteps_done = 0;
  575. void _lcd_babystep(const AxisEnum axis, const char* msg) {
  576. if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
  577. ENCODER_DIRECTION_NORMAL();
  578. if (encoderPosition) {
  579. int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  580. encoderPosition = 0;
  581. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  582. thermalManager.babystep_axis(axis, babystep_increment);
  583. babysteps_done += babystep_increment;
  584. }
  585. if (lcdDrawUpdate)
  586. lcd_implementation_drawedit(msg, ftostr43sign(
  587. ((1000 * babysteps_done) * planner.steps_to_mm[axis]) * 0.001f
  588. ));
  589. }
  590. #if ENABLED(BABYSTEP_XY)
  591. void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  592. void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  593. void lcd_babystep_x() { lcd_goto_screen(_lcd_babystep_x); babysteps_done = 0; defer_return_to_status = true; }
  594. void lcd_babystep_y() { lcd_goto_screen(_lcd_babystep_y); babysteps_done = 0; defer_return_to_status = true; }
  595. #endif
  596. void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  597. void lcd_babystep_z() { lcd_goto_screen(_lcd_babystep_z); babysteps_done = 0; defer_return_to_status = true; }
  598. #endif //BABYSTEPPING
  599. /**
  600. * Watch temperature callbacks
  601. */
  602. #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
  603. #if TEMP_SENSOR_0 != 0
  604. void watch_temp_callback_E0() { thermalManager.start_watching_heater(0); }
  605. #endif
  606. #if HOTENDS > 1 && TEMP_SENSOR_1 != 0
  607. void watch_temp_callback_E1() { thermalManager.start_watching_heater(1); }
  608. #endif // HOTENDS > 1
  609. #if HOTENDS > 2 && TEMP_SENSOR_2 != 0
  610. void watch_temp_callback_E2() { thermalManager.start_watching_heater(2); }
  611. #endif // HOTENDS > 2
  612. #if HOTENDS > 3 && TEMP_SENSOR_3 != 0
  613. void watch_temp_callback_E3() { thermalManager.start_watching_heater(3); }
  614. #endif // HOTENDS > 3
  615. #else
  616. #if TEMP_SENSOR_0 != 0
  617. void watch_temp_callback_E0() {}
  618. #endif
  619. #if HOTENDS > 1 && TEMP_SENSOR_1 != 0
  620. void watch_temp_callback_E1() {}
  621. #endif // HOTENDS > 1
  622. #if HOTENDS > 2 && TEMP_SENSOR_2 != 0
  623. void watch_temp_callback_E2() {}
  624. #endif // HOTENDS > 2
  625. #if HOTENDS > 3 && TEMP_SENSOR_3 != 0
  626. void watch_temp_callback_E3() {}
  627. #endif // HOTENDS > 3
  628. #endif
  629. #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
  630. #if TEMP_SENSOR_BED != 0
  631. void watch_temp_callback_bed() { thermalManager.start_watching_bed(); }
  632. #endif
  633. #else
  634. #if TEMP_SENSOR_BED != 0
  635. void watch_temp_callback_bed() {}
  636. #endif
  637. #endif
  638. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  639. void lcd_enqueue_filament_change() {
  640. lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_INIT);
  641. enqueue_and_echo_commands_P(PSTR("M600"));
  642. }
  643. #endif
  644. /**
  645. *
  646. * "Tune" submenu
  647. *
  648. */
  649. void lcd_tune_menu() {
  650. START_MENU();
  651. //
  652. // ^ Main
  653. //
  654. MENU_BACK(MSG_MAIN);
  655. //
  656. // Speed:
  657. //
  658. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
  659. // Manual bed leveling, Bed Z:
  660. #if ENABLED(MANUAL_BED_LEVELING)
  661. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  662. #endif
  663. //
  664. // Nozzle:
  665. // Nozzle [1-4]:
  666. //
  667. #if HOTENDS == 1
  668. #if TEMP_SENSOR_0 != 0
  669. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  670. #endif
  671. #else //HOTENDS > 1
  672. #if TEMP_SENSOR_0 != 0
  673. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  674. #endif
  675. #if TEMP_SENSOR_1 != 0
  676. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  677. #endif
  678. #if HOTENDS > 2
  679. #if TEMP_SENSOR_2 != 0
  680. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  681. #endif
  682. #if HOTENDS > 3
  683. #if TEMP_SENSOR_3 != 0
  684. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  685. #endif
  686. #endif // HOTENDS > 3
  687. #endif // HOTENDS > 2
  688. #endif // HOTENDS > 1
  689. //
  690. // Bed:
  691. //
  692. #if TEMP_SENSOR_BED != 0
  693. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  694. #endif
  695. //
  696. // Fan Speed:
  697. //
  698. #if FAN_COUNT > 0
  699. #if HAS_FAN0
  700. #if FAN_COUNT > 1
  701. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  702. #else
  703. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  704. #endif
  705. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  706. #endif
  707. #if HAS_FAN1
  708. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  709. #endif
  710. #if HAS_FAN2
  711. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  712. #endif
  713. #endif // FAN_COUNT > 0
  714. //
  715. // Flow:
  716. // Flow 1:
  717. // Flow 2:
  718. // Flow 3:
  719. // Flow 4:
  720. //
  721. #if EXTRUDERS == 1
  722. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
  723. #else // EXTRUDERS > 1
  724. MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
  725. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
  726. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &flow_percentage[1], 10, 999);
  727. #if EXTRUDERS > 2
  728. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &flow_percentage[2], 10, 999);
  729. #if EXTRUDERS > 3
  730. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &flow_percentage[3], 10, 999);
  731. #endif //EXTRUDERS > 3
  732. #endif //EXTRUDERS > 2
  733. #endif //EXTRUDERS > 1
  734. //
  735. // Babystep X:
  736. // Babystep Y:
  737. // Babystep Z:
  738. //
  739. #if ENABLED(BABYSTEPPING)
  740. #if ENABLED(BABYSTEP_XY)
  741. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  742. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  743. #endif //BABYSTEP_XY
  744. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  745. #endif
  746. //
  747. // Change filament
  748. //
  749. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  750. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_enqueue_filament_change);
  751. #endif
  752. END_MENU();
  753. }
  754. /**
  755. *
  756. * "Driver current control" submenu items
  757. *
  758. */
  759. #if ENABLED(DAC_STEPPER_CURRENT)
  760. void dac_driver_getValues() { LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); }
  761. void dac_driver_commit() { dac_current_set_percents(driverPercent); }
  762. void dac_driver_eeprom_write() { dac_commit_eeprom(); }
  763. void lcd_dac_menu() {
  764. dac_driver_getValues();
  765. START_MENU();
  766. MENU_BACK(MSG_CONTROL);
  767. MENU_ITEM_EDIT_CALLBACK(int3, MSG_X " " MSG_DAC_PERCENT, &driverPercent[X_AXIS], 0, 100, dac_driver_commit);
  768. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Y " " MSG_DAC_PERCENT, &driverPercent[Y_AXIS], 0, 100, dac_driver_commit);
  769. MENU_ITEM_EDIT_CALLBACK(int3, MSG_Z " " MSG_DAC_PERCENT, &driverPercent[Z_AXIS], 0, 100, dac_driver_commit);
  770. MENU_ITEM_EDIT_CALLBACK(int3, MSG_E " " MSG_DAC_PERCENT, &driverPercent[E_AXIS], 0, 100, dac_driver_commit);
  771. MENU_ITEM(function, MSG_DAC_EEPROM_WRITE, dac_driver_eeprom_write);
  772. END_MENU();
  773. }
  774. #endif
  775. constexpr int heater_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP);
  776. /**
  777. *
  778. * "Prepare" submenu items
  779. *
  780. */
  781. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  782. if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
  783. #if TEMP_SENSOR_BED != 0
  784. thermalManager.setTargetBed(tempb);
  785. #else
  786. UNUSED(tempb);
  787. #endif
  788. #if FAN_COUNT > 0
  789. #if FAN_COUNT > 1
  790. fanSpeeds[active_extruder < FAN_COUNT ? active_extruder : 0] = fan;
  791. #else
  792. fanSpeeds[0] = fan;
  793. #endif
  794. #else
  795. UNUSED(fan);
  796. #endif
  797. lcd_return_to_status();
  798. }
  799. #if TEMP_SENSOR_0 != 0
  800. void lcd_preheat_material1_hotend0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  801. void lcd_preheat_material2_hotend0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  802. #endif
  803. #if HOTENDS > 1
  804. void lcd_preheat_material1_hotend1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  805. void lcd_preheat_material2_hotend1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  806. #if HOTENDS > 2
  807. void lcd_preheat_material1_hotend2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  808. void lcd_preheat_material2_hotend2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  809. #if HOTENDS > 3
  810. void lcd_preheat_material1_hotend3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  811. void lcd_preheat_material2_hotend3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  812. #endif
  813. #endif
  814. void lcd_preheat_material1_hotend0123() {
  815. #if HOTENDS > 1
  816. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
  817. #if HOTENDS > 2
  818. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
  819. #if HOTENDS > 3
  820. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
  821. #endif
  822. #endif
  823. #endif
  824. lcd_preheat_material1_hotend0();
  825. }
  826. void lcd_preheat_material2_hotend0123() {
  827. #if HOTENDS > 1
  828. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
  829. #if HOTENDS > 2
  830. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
  831. #if HOTENDS > 3
  832. thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
  833. #endif
  834. #endif
  835. #endif
  836. lcd_preheat_material2_hotend0();
  837. }
  838. #endif // HOTENDS > 1
  839. #if TEMP_SENSOR_BED != 0
  840. void lcd_preheat_material1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
  841. void lcd_preheat_material2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
  842. #endif
  843. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  844. void lcd_preheat_material1_menu() {
  845. START_MENU();
  846. MENU_BACK(MSG_PREPARE);
  847. #if HOTENDS == 1
  848. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_material1_hotend0);
  849. #else
  850. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_material1_hotend0);
  851. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_material1_hotend1);
  852. #if HOTENDS > 2
  853. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_material1_hotend2);
  854. #if HOTENDS > 3
  855. MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_material1_hotend3);
  856. #endif
  857. #endif
  858. MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_material1_hotend0123);
  859. #endif
  860. #if TEMP_SENSOR_BED != 0
  861. MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_material1_bedonly);
  862. #endif
  863. END_MENU();
  864. }
  865. void lcd_preheat_material2_menu() {
  866. START_MENU();
  867. MENU_BACK(MSG_PREPARE);
  868. #if HOTENDS == 1
  869. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_material2_hotend0);
  870. #else
  871. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_material2_hotend0);
  872. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_material2_hotend1);
  873. #if HOTENDS > 2
  874. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_material2_hotend2);
  875. #if HOTENDS > 3
  876. MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_material2_hotend3);
  877. #endif
  878. #endif
  879. MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_material2_hotend0123);
  880. #endif
  881. #if TEMP_SENSOR_BED != 0
  882. MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_material2_bedonly);
  883. #endif
  884. END_MENU();
  885. }
  886. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  887. void lcd_cooldown() {
  888. #if FAN_COUNT > 0
  889. for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
  890. #endif
  891. thermalManager.disable_all_heaters();
  892. lcd_return_to_status();
  893. }
  894. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  895. void lcd_autostart_sd() {
  896. card.autostart_index = 0;
  897. card.setroot();
  898. card.checkautostart(true);
  899. }
  900. #endif
  901. #if ENABLED(MANUAL_BED_LEVELING)
  902. /**
  903. *
  904. * "Prepare" > "Bed Leveling" handlers
  905. *
  906. */
  907. static uint8_t _lcd_level_bed_position;
  908. // Utility to go to the next mesh point
  909. // A raise is added between points if Z_HOMING_HEIGHT is in use
  910. // Note: During Manual Bed Leveling the homed Z position is MESH_HOME_SEARCH_Z
  911. // Z position will be restored with the final action, a G28
  912. inline void _mbl_goto_xy(float x, float y) {
  913. current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT);
  914. line_to_current(Z_AXIS);
  915. current_position[X_AXIS] = LOGICAL_X_POSITION(x);
  916. current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
  917. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
  918. #if Z_HOMING_HEIGHT > 0
  919. current_position[Z_AXIS] = LOGICAL_Z_POSITION(MESH_HOME_SEARCH_Z);
  920. line_to_current(Z_AXIS);
  921. #endif
  922. stepper.synchronize();
  923. }
  924. void _lcd_level_goto_next_point();
  925. void _lcd_level_bed_done() {
  926. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
  927. lcdDrawUpdate =
  928. #if ENABLED(DOGLCD)
  929. LCDVIEW_CALL_REDRAW_NEXT
  930. #else
  931. LCDVIEW_CALL_NO_REDRAW
  932. #endif
  933. ;
  934. }
  935. /**
  936. * Step 7: Get the Z coordinate, then goto next point or exit
  937. */
  938. void _lcd_level_bed_get_z() {
  939. ENCODER_DIRECTION_NORMAL();
  940. // Encoder wheel adjusts the Z position
  941. if (encoderPosition) {
  942. refresh_cmd_timeout();
  943. current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
  944. NOLESS(current_position[Z_AXIS], 0);
  945. NOMORE(current_position[Z_AXIS], MESH_HOME_SEARCH_Z * 2);
  946. line_to_current(Z_AXIS);
  947. lcdDrawUpdate =
  948. #if ENABLED(DOGLCD)
  949. LCDVIEW_CALL_REDRAW_NEXT
  950. #else
  951. LCDVIEW_REDRAW_NOW
  952. #endif
  953. ;
  954. encoderPosition = 0;
  955. }
  956. static bool debounce_click = false;
  957. if (lcd_clicked) {
  958. if (!debounce_click) {
  959. debounce_click = true; // ignore multiple "clicks" in a row
  960. mbl.set_zigzag_z(_lcd_level_bed_position++, current_position[Z_AXIS]);
  961. if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
  962. lcd_goto_screen(_lcd_level_bed_done);
  963. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z + Z_HOMING_HEIGHT;
  964. line_to_current(Z_AXIS);
  965. stepper.synchronize();
  966. mbl.set_has_mesh(true);
  967. enqueue_and_echo_commands_P(PSTR("G28"));
  968. lcd_return_to_status();
  969. //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
  970. #if HAS_BUZZER
  971. lcd_buzz(200, 659);
  972. lcd_buzz(200, 698);
  973. #endif
  974. }
  975. else {
  976. lcd_goto_screen(_lcd_level_goto_next_point);
  977. }
  978. }
  979. }
  980. else {
  981. debounce_click = false;
  982. }
  983. // Update on first display, then only on updates to Z position
  984. // Show message above on clicks instead
  985. if (lcdDrawUpdate) {
  986. float v = current_position[Z_AXIS] - MESH_HOME_SEARCH_Z;
  987. lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
  988. }
  989. }
  990. /**
  991. * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  992. */
  993. void _lcd_level_bed_moving() {
  994. if (lcdDrawUpdate) {
  995. char msg[10];
  996. sprintf_P(msg, PSTR("%i / %u"), (int)(_lcd_level_bed_position + 1), (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS));
  997. lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
  998. }
  999. lcdDrawUpdate =
  1000. #if ENABLED(DOGLCD)
  1001. LCDVIEW_CALL_REDRAW_NEXT
  1002. #else
  1003. LCDVIEW_CALL_NO_REDRAW
  1004. #endif
  1005. ;
  1006. }
  1007. /**
  1008. * Step 5: Initiate a move to the next point
  1009. */
  1010. void _lcd_level_goto_next_point() {
  1011. // Set the menu to display ahead of blocking call
  1012. lcd_goto_screen(_lcd_level_bed_moving);
  1013. // _mbl_goto_xy runs the menu loop until the move is done
  1014. int8_t px, py;
  1015. mbl.zigzag(_lcd_level_bed_position, px, py);
  1016. _mbl_goto_xy(mbl.get_probe_x(px), mbl.get_probe_y(py));
  1017. // After the blocking function returns, change menus
  1018. lcd_goto_screen(_lcd_level_bed_get_z);
  1019. }
  1020. /**
  1021. * Step 4: Display "Click to Begin", wait for click
  1022. * Move to the first probe position
  1023. */
  1024. void _lcd_level_bed_homing_done() {
  1025. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
  1026. if (lcd_clicked) {
  1027. _lcd_level_bed_position = 0;
  1028. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z
  1029. #if Z_HOME_DIR > 0
  1030. + Z_MAX_POS
  1031. #endif
  1032. ;
  1033. planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1034. lcd_goto_screen(_lcd_level_goto_next_point);
  1035. }
  1036. }
  1037. /**
  1038. * Step 3: Display "Homing XYZ" - Wait for homing to finish
  1039. */
  1040. void _lcd_level_bed_homing() {
  1041. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
  1042. lcdDrawUpdate =
  1043. #if ENABLED(DOGLCD)
  1044. LCDVIEW_CALL_REDRAW_NEXT
  1045. #else
  1046. LCDVIEW_CALL_NO_REDRAW
  1047. #endif
  1048. ;
  1049. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1050. lcd_goto_screen(_lcd_level_bed_homing_done);
  1051. }
  1052. /**
  1053. * Step 2: Continue Bed Leveling...
  1054. */
  1055. void _lcd_level_bed_continue() {
  1056. defer_return_to_status = true;
  1057. axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
  1058. mbl.reset();
  1059. enqueue_and_echo_commands_P(PSTR("G28"));
  1060. lcd_goto_screen(_lcd_level_bed_homing);
  1061. }
  1062. /**
  1063. * Step 1: MBL entry-point: "Cancel" or "Level Bed"
  1064. */
  1065. void lcd_level_bed() {
  1066. START_MENU();
  1067. MENU_BACK(MSG_LEVEL_BED_CANCEL);
  1068. MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
  1069. END_MENU();
  1070. }
  1071. #endif // MANUAL_BED_LEVELING
  1072. /**
  1073. *
  1074. * "Prepare" submenu
  1075. *
  1076. */
  1077. void lcd_prepare_menu() {
  1078. START_MENU();
  1079. //
  1080. // ^ Main
  1081. //
  1082. MENU_BACK(MSG_MAIN);
  1083. //
  1084. // Auto Home
  1085. //
  1086. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1087. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  1088. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  1089. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  1090. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  1091. #endif
  1092. //
  1093. // Set Home Offsets
  1094. //
  1095. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  1096. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  1097. //
  1098. // Level Bed
  1099. //
  1100. #if HAS_ABL
  1101. MENU_ITEM(gcode, MSG_LEVEL_BED,
  1102. axis_homed[X_AXIS] && axis_homed[Y_AXIS] ? PSTR("G29") : PSTR("G28\nG29")
  1103. );
  1104. #elif ENABLED(MANUAL_BED_LEVELING)
  1105. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  1106. #endif
  1107. //
  1108. // Move Axis
  1109. //
  1110. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  1111. //
  1112. // Disable Steppers
  1113. //
  1114. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1115. //
  1116. // Preheat PLA
  1117. // Preheat ABS
  1118. //
  1119. #if TEMP_SENSOR_0 != 0
  1120. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  1121. MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_material1_menu);
  1122. MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_material2_menu);
  1123. #else
  1124. MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_material1_hotend0);
  1125. MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_material2_hotend0);
  1126. #endif
  1127. #endif
  1128. //
  1129. // Cooldown
  1130. //
  1131. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  1132. //
  1133. // BLTouch Self-Test and Reset
  1134. //
  1135. #if ENABLED(BLTOUCH)
  1136. MENU_ITEM(gcode, MSG_BLTOUCH_SELFTEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST)));
  1137. if (!endstops.z_probe_enabled && TEST_BLTOUCH())
  1138. MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET)));
  1139. #endif
  1140. //
  1141. // Switch power on/off
  1142. //
  1143. #if HAS_POWER_SWITCH
  1144. if (powersupply)
  1145. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  1146. else
  1147. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  1148. #endif
  1149. //
  1150. // Autostart
  1151. //
  1152. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  1153. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  1154. #endif
  1155. END_MENU();
  1156. }
  1157. #if ENABLED(DELTA_CALIBRATION_MENU)
  1158. void _goto_tower_pos(const float &a) {
  1159. do_blocking_move_to(
  1160. a < 0 ? X_HOME_POS : sin(a) * -(DELTA_PRINTABLE_RADIUS),
  1161. a < 0 ? Y_HOME_POS : cos(a) * (DELTA_PRINTABLE_RADIUS),
  1162. 4
  1163. );
  1164. }
  1165. void _goto_tower_x() { _goto_tower_pos(RADIANS(120)); }
  1166. void _goto_tower_y() { _goto_tower_pos(RADIANS(240)); }
  1167. void _goto_tower_z() { _goto_tower_pos(0); }
  1168. void _goto_center() { _goto_tower_pos(-1); }
  1169. void lcd_delta_calibrate_menu() {
  1170. START_MENU();
  1171. MENU_BACK(MSG_MAIN);
  1172. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1173. MENU_ITEM(function, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  1174. MENU_ITEM(function, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  1175. MENU_ITEM(function, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  1176. MENU_ITEM(function, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  1177. END_MENU();
  1178. }
  1179. #endif // DELTA_CALIBRATION_MENU
  1180. float move_menu_scale;
  1181. /**
  1182. * If the most recent manual move hasn't been fed to the planner yet,
  1183. * and the planner can accept one, send immediately
  1184. */
  1185. inline void manage_manual_move() {
  1186. if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
  1187. planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
  1188. manual_move_axis = (int8_t)NO_AXIS;
  1189. }
  1190. }
  1191. /**
  1192. * Set a flag that lcd_update() should start a move
  1193. * to "current_position" after a short delay.
  1194. */
  1195. inline void manual_move_to_current(AxisEnum axis
  1196. #if E_MANUAL > 1
  1197. , int8_t eindex=-1
  1198. #endif
  1199. ) {
  1200. #if E_MANUAL > 1
  1201. if (axis == E_AXIS) manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  1202. #endif
  1203. manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
  1204. manual_move_axis = (int8_t)axis;
  1205. }
  1206. /**
  1207. *
  1208. * "Prepare" > "Move Axis" submenu
  1209. *
  1210. */
  1211. void _lcd_move_xyz(const char* name, AxisEnum axis) {
  1212. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1213. ENCODER_DIRECTION_NORMAL();
  1214. if (encoderPosition) {
  1215. refresh_cmd_timeout();
  1216. // Limit to software endstops, if enabled
  1217. float min = (soft_endstops_enabled && min_software_endstops) ? soft_endstop_min[axis] : current_position[axis] - 1000,
  1218. max = (soft_endstops_enabled && max_software_endstops) ? soft_endstop_max[axis] : current_position[axis] + 1000;
  1219. // Get the new position
  1220. current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
  1221. // Delta limits XY based on the current offset from center
  1222. // This assumes the center is 0,0
  1223. #if ENABLED(DELTA)
  1224. if (axis != Z_AXIS) {
  1225. max = sqrt(sq(DELTA_PRINTABLE_RADIUS) - sq(current_position[Y_AXIS - axis]));
  1226. min = -max;
  1227. }
  1228. #endif
  1229. // Limit only when trying to move towards the limit
  1230. if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
  1231. if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
  1232. manual_move_to_current(axis);
  1233. encoderPosition = 0;
  1234. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1235. }
  1236. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr41sign(current_position[axis]));
  1237. }
  1238. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  1239. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  1240. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  1241. void _lcd_move_e(
  1242. #if E_MANUAL > 1
  1243. int8_t eindex=-1
  1244. #endif
  1245. ) {
  1246. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1247. ENCODER_DIRECTION_NORMAL();
  1248. if (encoderPosition) {
  1249. current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
  1250. encoderPosition = 0;
  1251. manual_move_to_current(E_AXIS
  1252. #if E_MANUAL > 1
  1253. , eindex
  1254. #endif
  1255. );
  1256. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1257. }
  1258. if (lcdDrawUpdate) {
  1259. PGM_P pos_label;
  1260. #if E_MANUAL == 1
  1261. pos_label = PSTR(MSG_MOVE_E);
  1262. #else
  1263. switch (eindex) {
  1264. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  1265. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  1266. #if E_MANUAL > 2
  1267. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  1268. #if E_MANUAL > 3
  1269. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  1270. #endif
  1271. #endif
  1272. }
  1273. #endif
  1274. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
  1275. }
  1276. }
  1277. void lcd_move_e() { _lcd_move_e(); }
  1278. #if E_MANUAL > 1
  1279. void lcd_move_e0() { _lcd_move_e(0); }
  1280. void lcd_move_e1() { _lcd_move_e(1); }
  1281. #if E_MANUAL > 2
  1282. void lcd_move_e2() { _lcd_move_e(2); }
  1283. #if E_MANUAL > 3
  1284. void lcd_move_e3() { _lcd_move_e(3); }
  1285. #endif
  1286. #endif
  1287. #endif
  1288. /**
  1289. *
  1290. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  1291. *
  1292. */
  1293. #if IS_KINEMATIC
  1294. #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
  1295. #else
  1296. #define _MOVE_XYZ_ALLOWED true
  1297. #endif
  1298. void _lcd_move_menu_axis() {
  1299. START_MENU();
  1300. MENU_BACK(MSG_MOVE_AXIS);
  1301. if (_MOVE_XYZ_ALLOWED) {
  1302. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  1303. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  1304. }
  1305. if (move_menu_scale < 10.0) {
  1306. if (_MOVE_XYZ_ALLOWED) MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1307. #if ENABLED(SWITCHING_EXTRUDER)
  1308. if (active_extruder)
  1309. MENU_ITEM(gcode, MSG_SELECT MSG_E1, PSTR("T0"));
  1310. else
  1311. MENU_ITEM(gcode, MSG_SELECT MSG_E2, PSTR("T1"));
  1312. #endif
  1313. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1314. #if E_MANUAL > 1
  1315. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_e0);
  1316. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_e1);
  1317. #if E_MANUAL > 2
  1318. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_e2);
  1319. #if E_MANUAL > 3
  1320. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_e3);
  1321. #endif
  1322. #endif
  1323. #endif
  1324. }
  1325. END_MENU();
  1326. }
  1327. void lcd_move_menu_10mm() {
  1328. move_menu_scale = 10.0;
  1329. _lcd_move_menu_axis();
  1330. }
  1331. void lcd_move_menu_1mm() {
  1332. move_menu_scale = 1.0;
  1333. _lcd_move_menu_axis();
  1334. }
  1335. void lcd_move_menu_01mm() {
  1336. move_menu_scale = 0.1;
  1337. _lcd_move_menu_axis();
  1338. }
  1339. /**
  1340. *
  1341. * "Prepare" > "Move Axis" submenu
  1342. *
  1343. */
  1344. void lcd_move_menu() {
  1345. START_MENU();
  1346. MENU_BACK(MSG_PREPARE);
  1347. if (_MOVE_XYZ_ALLOWED)
  1348. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  1349. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  1350. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  1351. //TODO:X,Y,Z,E
  1352. END_MENU();
  1353. }
  1354. /**
  1355. *
  1356. * "Control" submenu
  1357. *
  1358. */
  1359. void lcd_control_menu() {
  1360. START_MENU();
  1361. MENU_BACK(MSG_MAIN);
  1362. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1363. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  1364. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  1365. #if HAS_LCD_CONTRAST
  1366. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  1367. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  1368. #endif
  1369. #if ENABLED(FWRETRACT)
  1370. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  1371. #endif
  1372. #if ENABLED(DAC_STEPPER_CURRENT)
  1373. MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, lcd_dac_menu);
  1374. #endif
  1375. #if ENABLED(EEPROM_SETTINGS)
  1376. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1377. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  1378. #endif
  1379. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  1380. END_MENU();
  1381. }
  1382. /**
  1383. *
  1384. * "Temperature" submenu
  1385. *
  1386. */
  1387. #if ENABLED(PID_AUTOTUNE_MENU)
  1388. #if ENABLED(PIDTEMP)
  1389. int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
  1390. #endif
  1391. #if ENABLED(PIDTEMPBED)
  1392. int autotune_temp_bed = 70;
  1393. #endif
  1394. void _lcd_autotune(int e) {
  1395. char cmd[30];
  1396. sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
  1397. #if HAS_PID_FOR_BOTH
  1398. e < 0 ? autotune_temp_bed : autotune_temp[e]
  1399. #elif ENABLED(PIDTEMPBED)
  1400. autotune_temp_bed
  1401. #else
  1402. autotune_temp[e]
  1403. #endif
  1404. );
  1405. enqueue_and_echo_command(cmd);
  1406. }
  1407. #endif //PID_AUTOTUNE_MENU
  1408. #if ENABLED(PIDTEMP)
  1409. // Helpers for editing PID Ki & Kd values
  1410. // grab the PID value out of the temp variable; scale it; then update the PID driver
  1411. void copy_and_scalePID_i(int e) {
  1412. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1413. UNUSED(e);
  1414. #endif
  1415. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  1416. thermalManager.updatePID();
  1417. }
  1418. void copy_and_scalePID_d(int e) {
  1419. #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
  1420. UNUSED(e);
  1421. #endif
  1422. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  1423. thermalManager.updatePID();
  1424. }
  1425. #define _PIDTEMP_BASE_FUNCTIONS(eindex) \
  1426. void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
  1427. void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); }
  1428. #if ENABLED(PID_AUTOTUNE_MENU)
  1429. #define _PIDTEMP_FUNCTIONS(eindex) \
  1430. _PIDTEMP_BASE_FUNCTIONS(eindex); \
  1431. void lcd_autotune_callback_E ## eindex() { _lcd_autotune(eindex); }
  1432. #else
  1433. #define _PIDTEMP_FUNCTIONS(eindex) _PIDTEMP_BASE_FUNCTIONS(eindex)
  1434. #endif
  1435. _PIDTEMP_FUNCTIONS(0)
  1436. #if ENABLED(PID_PARAMS_PER_HOTEND)
  1437. #if HOTENDS > 1
  1438. _PIDTEMP_FUNCTIONS(1)
  1439. #if HOTENDS > 2
  1440. _PIDTEMP_FUNCTIONS(2)
  1441. #if HOTENDS > 3
  1442. _PIDTEMP_FUNCTIONS(3)
  1443. #endif //HOTENDS > 3
  1444. #endif //HOTENDS > 2
  1445. #endif //HOTENDS > 1
  1446. #endif //PID_PARAMS_PER_HOTEND
  1447. #endif //PIDTEMP
  1448. /**
  1449. *
  1450. * "Control" > "Temperature" submenu
  1451. *
  1452. */
  1453. void lcd_control_temperature_menu() {
  1454. START_MENU();
  1455. //
  1456. // ^ Control
  1457. //
  1458. MENU_BACK(MSG_CONTROL);
  1459. //
  1460. // Nozzle:
  1461. // Nozzle [1-4]:
  1462. //
  1463. #if HOTENDS == 1
  1464. #if TEMP_SENSOR_0 != 0
  1465. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1466. #endif
  1467. #else //HOTENDS > 1
  1468. #if TEMP_SENSOR_0 != 0
  1469. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &thermalManager.target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  1470. #endif
  1471. #if TEMP_SENSOR_1 != 0
  1472. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &thermalManager.target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  1473. #endif
  1474. #if HOTENDS > 2
  1475. #if TEMP_SENSOR_2 != 0
  1476. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &thermalManager.target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  1477. #endif
  1478. #if HOTENDS > 3
  1479. #if TEMP_SENSOR_3 != 0
  1480. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &thermalManager.target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  1481. #endif
  1482. #endif // HOTENDS > 3
  1483. #endif // HOTENDS > 2
  1484. #endif // HOTENDS > 1
  1485. //
  1486. // Bed:
  1487. //
  1488. #if TEMP_SENSOR_BED != 0
  1489. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_BED, &thermalManager.target_temperature_bed, 0, BED_MAXTEMP - 15, watch_temp_callback_bed);
  1490. #endif
  1491. //
  1492. // Fan Speed:
  1493. //
  1494. #if FAN_COUNT > 0
  1495. #if HAS_FAN0
  1496. #if FAN_COUNT > 1
  1497. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED " 1"
  1498. #else
  1499. #define MSG_1ST_FAN_SPEED MSG_FAN_SPEED
  1500. #endif
  1501. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_1ST_FAN_SPEED, &fanSpeeds[0], 0, 255);
  1502. #endif
  1503. #if HAS_FAN1
  1504. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 2", &fanSpeeds[1], 0, 255);
  1505. #endif
  1506. #if HAS_FAN2
  1507. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED " 3", &fanSpeeds[2], 0, 255);
  1508. #endif
  1509. #endif // FAN_COUNT > 0
  1510. //
  1511. // Autotemp, Min, Max, Fact
  1512. //
  1513. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  1514. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
  1515. MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  1516. MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  1517. MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
  1518. #endif
  1519. //
  1520. // PID-P, PID-I, PID-D, PID-C, PID Autotune
  1521. // PID-P E1, PID-I E1, PID-D E1, PID-C E1, PID Autotune E1
  1522. // PID-P E2, PID-I E2, PID-D E2, PID-C E2, PID Autotune E2
  1523. // PID-P E3, PID-I E3, PID-D E3, PID-C E3, PID Autotune E3
  1524. // PID-P E4, PID-I E4, PID-D E4, PID-C E4, PID Autotune E4
  1525. //
  1526. #if ENABLED(PIDTEMP)
  1527. #define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
  1528. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  1529. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  1530. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  1531. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  1532. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  1533. #if ENABLED(PID_EXTRUSION_SCALING)
  1534. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  1535. _PID_BASE_MENU_ITEMS(ELABEL, eindex); \
  1536. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1537. #else
  1538. #define _PID_MENU_ITEMS(ELABEL, eindex) _PID_BASE_MENU_ITEMS(ELABEL, eindex)
  1539. #endif
  1540. #if ENABLED(PID_AUTOTUNE_MENU)
  1541. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1542. _PID_MENU_ITEMS(ELABEL, eindex); \
  1543. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_PID_AUTOTUNE ELABEL, &autotune_temp[eindex], 150, heater_maxtemp[eindex] - 15, lcd_autotune_callback_E ## eindex)
  1544. #else
  1545. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1546. #endif
  1547. #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
  1548. PID_MENU_ITEMS(MSG_E1, 0);
  1549. PID_MENU_ITEMS(MSG_E2, 1);
  1550. #if HOTENDS > 2
  1551. PID_MENU_ITEMS(MSG_E3, 2);
  1552. #if HOTENDS > 3
  1553. PID_MENU_ITEMS(MSG_E4, 3);
  1554. #endif //HOTENDS > 3
  1555. #endif //HOTENDS > 2
  1556. #else //!PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1557. PID_MENU_ITEMS("", 0);
  1558. #endif //!PID_PARAMS_PER_HOTEND || HOTENDS == 1
  1559. #endif //PIDTEMP
  1560. //
  1561. // Preheat Material 1 conf
  1562. //
  1563. MENU_ITEM(submenu, MSG_PREHEAT_1_SETTINGS, lcd_control_temperature_preheat_material1_settings_menu);
  1564. //
  1565. // Preheat Material 2 conf
  1566. //
  1567. MENU_ITEM(submenu, MSG_PREHEAT_2_SETTINGS, lcd_control_temperature_preheat_material2_settings_menu);
  1568. END_MENU();
  1569. }
  1570. void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
  1571. #if HOTENDS > 3
  1572. #define MINTEMP_ALL MIN4(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP, HEATER_3_MINTEMP)
  1573. #define MAXTEMP_ALL MAX4(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP)
  1574. #elif HOTENDS > 2
  1575. #define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
  1576. #define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
  1577. #elif HOTENDS > 1
  1578. #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
  1579. #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
  1580. #else
  1581. #define MINTEMP_ALL HEATER_0_MINTEMP
  1582. #define MAXTEMP_ALL HEATER_0_MAXTEMP
  1583. #endif
  1584. START_MENU();
  1585. MENU_BACK(MSG_TEMPERATURE);
  1586. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
  1587. #if TEMP_SENSOR_0 != 0
  1588. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
  1589. #endif
  1590. #if TEMP_SENSOR_BED != 0
  1591. MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
  1592. #endif
  1593. #if ENABLED(EEPROM_SETTINGS)
  1594. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1595. #endif
  1596. END_MENU();
  1597. }
  1598. /**
  1599. *
  1600. * "Temperature" > "Preheat Material 1 conf" submenu
  1601. *
  1602. */
  1603. void lcd_control_temperature_preheat_material1_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
  1604. /**
  1605. *
  1606. * "Temperature" > "Preheat Material 2 conf" submenu
  1607. *
  1608. */
  1609. void lcd_control_temperature_preheat_material2_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
  1610. void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
  1611. void _planner_refresh_positioning() { planner.refresh_positioning(); }
  1612. /**
  1613. *
  1614. * "Control" > "Motion" submenu
  1615. *
  1616. */
  1617. void lcd_control_motion_menu() {
  1618. START_MENU();
  1619. MENU_BACK(MSG_CONTROL);
  1620. #if HAS_BED_PROBE
  1621. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  1622. #endif
  1623. // Manual bed leveling, Bed Z:
  1624. #if ENABLED(MANUAL_BED_LEVELING)
  1625. MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  1626. #endif
  1627. MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
  1628. MENU_ITEM_EDIT(float3, MSG_VX_JERK, &planner.max_jerk[X_AXIS], 1, 990);
  1629. MENU_ITEM_EDIT(float3, MSG_VY_JERK, &planner.max_jerk[Y_AXIS], 1, 990);
  1630. #if ENABLED(DELTA)
  1631. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 1, 990);
  1632. #else
  1633. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_jerk[Z_AXIS], 0.1, 990);
  1634. #endif
  1635. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
  1636. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate_mm_s[X_AXIS], 1, 999);
  1637. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate_mm_s[Y_AXIS], 1, 999);
  1638. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate_mm_s[Z_AXIS], 1, 999);
  1639. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
  1640. MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
  1641. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
  1642. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_mm_per_s2[X_AXIS], 100, 99000, _reset_acceleration_rates);
  1643. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_mm_per_s2[Y_AXIS], 100, 99000, _reset_acceleration_rates);
  1644. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_mm_per_s2[Z_AXIS], 10, 99000, _reset_acceleration_rates);
  1645. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
  1646. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
  1647. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
  1648. MENU_ITEM_EDIT_CALLBACK(float62, MSG_XSTEPS, &planner.axis_steps_per_mm[X_AXIS], 5, 9999, _planner_refresh_positioning);
  1649. MENU_ITEM_EDIT_CALLBACK(float62, MSG_YSTEPS, &planner.axis_steps_per_mm[Y_AXIS], 5, 9999, _planner_refresh_positioning);
  1650. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ZSTEPS, &planner.axis_steps_per_mm[Z_AXIS], 5, 9999, _planner_refresh_positioning);
  1651. MENU_ITEM_EDIT_CALLBACK(float62, MSG_ESTEPS, &planner.axis_steps_per_mm[E_AXIS], 5, 9999, _planner_refresh_positioning);
  1652. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  1653. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
  1654. #endif
  1655. END_MENU();
  1656. }
  1657. /**
  1658. *
  1659. * "Control" > "Filament" submenu
  1660. *
  1661. */
  1662. void lcd_control_volumetric_menu() {
  1663. START_MENU();
  1664. MENU_BACK(MSG_CONTROL);
  1665. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  1666. if (volumetric_enabled) {
  1667. #if EXTRUDERS == 1
  1668. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1669. #else //EXTRUDERS > 1
  1670. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1671. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  1672. #if EXTRUDERS > 2
  1673. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  1674. #if EXTRUDERS > 3
  1675. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  1676. #endif //EXTRUDERS > 3
  1677. #endif //EXTRUDERS > 2
  1678. #endif //EXTRUDERS > 1
  1679. }
  1680. END_MENU();
  1681. }
  1682. /**
  1683. *
  1684. * "Control" > "Contrast" submenu
  1685. *
  1686. */
  1687. #if HAS_LCD_CONTRAST
  1688. void lcd_set_contrast() {
  1689. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1690. ENCODER_DIRECTION_NORMAL();
  1691. if (encoderPosition) {
  1692. set_lcd_contrast(lcd_contrast + encoderPosition);
  1693. encoderPosition = 0;
  1694. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  1695. }
  1696. if (lcdDrawUpdate) {
  1697. lcd_implementation_drawedit(PSTR(MSG_CONTRAST),
  1698. #if LCD_CONTRAST_MAX >= 100
  1699. itostr3(lcd_contrast)
  1700. #else
  1701. itostr2(lcd_contrast)
  1702. #endif
  1703. );
  1704. }
  1705. }
  1706. #endif // HAS_LCD_CONTRAST
  1707. /**
  1708. *
  1709. * "Control" > "Retract" submenu
  1710. *
  1711. */
  1712. #if ENABLED(FWRETRACT)
  1713. void lcd_control_retract_menu() {
  1714. START_MENU();
  1715. MENU_BACK(MSG_CONTROL);
  1716. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  1717. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  1718. #if EXTRUDERS > 1
  1719. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  1720. #endif
  1721. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate_mm_s, 1, 999);
  1722. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  1723. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  1724. #if EXTRUDERS > 1
  1725. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  1726. #endif
  1727. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate_mm_s, 1, 999);
  1728. END_MENU();
  1729. }
  1730. #endif // FWRETRACT
  1731. #if ENABLED(SDSUPPORT)
  1732. #if !PIN_EXISTS(SD_DETECT)
  1733. void lcd_sd_refresh() {
  1734. card.initsd();
  1735. encoderTopLine = 0;
  1736. }
  1737. #endif
  1738. void lcd_sd_updir() {
  1739. card.updir();
  1740. encoderTopLine = 0;
  1741. }
  1742. /**
  1743. *
  1744. * "Print from SD" submenu
  1745. *
  1746. */
  1747. void lcd_sdcard_menu() {
  1748. ENCODER_DIRECTION_MENUS();
  1749. if (!lcdDrawUpdate && !lcd_clicked) return; // nothing to do (so don't thrash the SD card)
  1750. uint16_t fileCnt = card.getnrfilenames();
  1751. START_MENU();
  1752. MENU_BACK(MSG_MAIN);
  1753. card.getWorkDirName();
  1754. if (card.filename[0] == '/') {
  1755. #if !PIN_EXISTS(SD_DETECT)
  1756. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1757. #endif
  1758. }
  1759. else {
  1760. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1761. }
  1762. for (uint16_t i = 0; i < fileCnt; i++) {
  1763. if (_menuLineNr == _thisItemNr) {
  1764. card.getfilename(
  1765. #if ENABLED(SDCARD_RATHERRECENTFIRST)
  1766. fileCnt-1 -
  1767. #endif
  1768. i
  1769. );
  1770. if (card.filenameIsDir)
  1771. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1772. else
  1773. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1774. }
  1775. else {
  1776. MENU_ITEM_DUMMY();
  1777. }
  1778. }
  1779. END_MENU();
  1780. }
  1781. #endif //SDSUPPORT
  1782. #if ENABLED(LCD_INFO_MENU)
  1783. #if ENABLED(PRINTCOUNTER)
  1784. /**
  1785. *
  1786. * About Printer > Statistics submenu
  1787. *
  1788. */
  1789. void lcd_info_stats_menu() {
  1790. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1791. char buffer[21];
  1792. printStatistics stats = print_job_timer.getStats();
  1793. START_SCREEN(); // 12345678901234567890
  1794. STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count: 999
  1795. STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed : 666
  1796. duration_t elapsed = stats.printTime;
  1797. elapsed.toString(buffer);
  1798. STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false); // Total print Time:
  1799. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  1800. elapsed = stats.longestPrint;
  1801. elapsed.toString(buffer);
  1802. STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
  1803. STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
  1804. sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10);
  1805. STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
  1806. STATIC_ITEM("", false, false, buffer); // 125m
  1807. END_SCREEN();
  1808. }
  1809. #endif // PRINTCOUNTER
  1810. /**
  1811. *
  1812. * About Printer > Thermistors
  1813. *
  1814. */
  1815. void lcd_info_thermistors_menu() {
  1816. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1817. START_SCREEN();
  1818. #define THERMISTOR_ID TEMP_SENSOR_0
  1819. #include "thermistornames.h"
  1820. STATIC_ITEM("T0: " THERMISTOR_NAME, false, true);
  1821. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_0_MINTEMP), false);
  1822. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_0_MAXTEMP), false);
  1823. #if TEMP_SENSOR_1 != 0
  1824. #undef THERMISTOR_ID
  1825. #define THERMISTOR_ID TEMP_SENSOR_1
  1826. #include "thermistornames.h"
  1827. STATIC_ITEM("T1: " THERMISTOR_NAME, false, true);
  1828. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_1_MINTEMP), false);
  1829. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_1_MAXTEMP), false);
  1830. #endif
  1831. #if TEMP_SENSOR_2 != 0
  1832. #undef THERMISTOR_ID
  1833. #define THERMISTOR_ID TEMP_SENSOR_2
  1834. #include "thermistornames.h"
  1835. STATIC_ITEM("T2: " THERMISTOR_NAME, false, true);
  1836. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_2_MINTEMP), false);
  1837. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_2_MAXTEMP), false);
  1838. #endif
  1839. #if TEMP_SENSOR_3 != 0
  1840. #undef THERMISTOR_ID
  1841. #define THERMISTOR_ID TEMP_SENSOR_3
  1842. #include "thermistornames.h"
  1843. STATIC_ITEM("T3: " THERMISTOR_NAME, false, true);
  1844. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(HEATER_3_MINTEMP), false);
  1845. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_3_MAXTEMP), false);
  1846. #endif
  1847. #if TEMP_SENSOR_BED != 0
  1848. #undef THERMISTOR_ID
  1849. #define THERMISTOR_ID TEMP_SENSOR_BED
  1850. #include "thermistornames.h"
  1851. STATIC_ITEM("TBed:" THERMISTOR_NAME, false, true);
  1852. STATIC_ITEM(MSG_INFO_MIN_TEMP ": " STRINGIFY(BED_MINTEMP), false);
  1853. STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(BED_MAXTEMP), false);
  1854. #endif
  1855. END_SCREEN();
  1856. }
  1857. /**
  1858. *
  1859. * About Printer > Board Info
  1860. *
  1861. */
  1862. void lcd_info_board_menu() {
  1863. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1864. START_SCREEN();
  1865. STATIC_ITEM(BOARD_NAME, true, true); // MyPrinterController
  1866. STATIC_ITEM(MSG_INFO_BAUDRATE ": " STRINGIFY(BAUDRATE), true); // Baud: 250000
  1867. STATIC_ITEM(MSG_INFO_PROTOCOL ": " PROTOCOL_VERSION, true); // Protocol: 1.0
  1868. #ifdef POWER_SUPPLY
  1869. #if (POWER_SUPPLY == 1)
  1870. STATIC_ITEM(MSG_INFO_PSU ": ATX", true); // Power Supply: ATX
  1871. #elif (POWER_SUPPLY == 2)
  1872. STATIC_ITEM(MSG_INFO_PSU ": XBox", true); // Power Supply: XBox
  1873. #endif
  1874. #endif // POWER_SUPPLY
  1875. END_SCREEN();
  1876. }
  1877. /**
  1878. *
  1879. * About Printer > Printer Info
  1880. *
  1881. */
  1882. void lcd_info_printer_menu() {
  1883. if (lcd_clicked) { return lcd_goto_previous_menu(); }
  1884. START_SCREEN();
  1885. STATIC_ITEM(MSG_MARLIN, true, true); // Marlin
  1886. STATIC_ITEM(SHORT_BUILD_VERSION, true); // x.x.x-Branch
  1887. STATIC_ITEM(STRING_DISTRIBUTION_DATE, true); // YYYY-MM-DD HH:MM
  1888. STATIC_ITEM(MACHINE_NAME, true); // My3DPrinter
  1889. STATIC_ITEM(WEBSITE_URL, true); // www.my3dprinter.com
  1890. STATIC_ITEM(MSG_INFO_EXTRUDERS ": " STRINGIFY(EXTRUDERS), true); // Extruders: 2
  1891. END_SCREEN();
  1892. }
  1893. /**
  1894. *
  1895. * "About Printer" submenu
  1896. *
  1897. */
  1898. void lcd_info_menu() {
  1899. START_MENU();
  1900. MENU_BACK(MSG_MAIN);
  1901. MENU_ITEM(submenu, MSG_INFO_PRINTER_MENU, lcd_info_printer_menu); // Printer Info >
  1902. MENU_ITEM(submenu, MSG_INFO_BOARD_MENU, lcd_info_board_menu); // Board Info >
  1903. MENU_ITEM(submenu, MSG_INFO_THERMISTOR_MENU, lcd_info_thermistors_menu); // Thermistors >
  1904. #if ENABLED(PRINTCOUNTER)
  1905. MENU_ITEM(submenu, MSG_INFO_STATS_MENU, lcd_info_stats_menu); // Printer Statistics >
  1906. #endif
  1907. END_MENU();
  1908. }
  1909. #endif // LCD_INFO_MENU
  1910. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  1911. void lcd_filament_change_resume_print() {
  1912. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_RESUME_PRINT;
  1913. lcd_goto_screen(lcd_status_screen);
  1914. }
  1915. void lcd_filament_change_extrude_more() {
  1916. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_EXTRUDE_MORE;
  1917. }
  1918. void lcd_filament_change_option_menu() {
  1919. START_MENU();
  1920. #if LCD_HEIGHT > 2
  1921. STATIC_ITEM(MSG_FILAMENT_CHANGE_OPTION_HEADER, true, false);
  1922. #endif
  1923. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_RESUME, lcd_filament_change_resume_print);
  1924. MENU_ITEM(function, MSG_FILAMENT_CHANGE_OPTION_EXTRUDE, lcd_filament_change_extrude_more);
  1925. END_MENU();
  1926. }
  1927. void lcd_filament_change_init_message() {
  1928. START_SCREEN();
  1929. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1930. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_1);
  1931. #ifdef MSG_FILAMENT_CHANGE_INIT_2
  1932. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_2);
  1933. #endif
  1934. #ifdef MSG_FILAMENT_CHANGE_INIT_3
  1935. STATIC_ITEM(MSG_FILAMENT_CHANGE_INIT_3);
  1936. #endif
  1937. END_SCREEN();
  1938. }
  1939. void lcd_filament_change_unload_message() {
  1940. START_SCREEN();
  1941. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1942. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_1);
  1943. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_2
  1944. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_2);
  1945. #endif
  1946. #ifdef MSG_FILAMENT_CHANGE_UNLOAD_3
  1947. STATIC_ITEM(MSG_FILAMENT_CHANGE_UNLOAD_3);
  1948. #endif
  1949. END_SCREEN();
  1950. }
  1951. void lcd_filament_change_insert_message() {
  1952. START_SCREEN();
  1953. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1954. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_1);
  1955. #ifdef MSG_FILAMENT_CHANGE_INSERT_2
  1956. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_2);
  1957. #endif
  1958. #ifdef MSG_FILAMENT_CHANGE_INSERT_3
  1959. STATIC_ITEM(MSG_FILAMENT_CHANGE_INSERT_3);
  1960. #endif
  1961. END_SCREEN();
  1962. }
  1963. void lcd_filament_change_load_message() {
  1964. START_SCREEN();
  1965. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1966. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_1);
  1967. #ifdef MSG_FILAMENT_CHANGE_LOAD_2
  1968. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_2);
  1969. #endif
  1970. #ifdef MSG_FILAMENT_CHANGE_LOAD_3
  1971. STATIC_ITEM(MSG_FILAMENT_CHANGE_LOAD_3);
  1972. #endif
  1973. END_SCREEN();
  1974. }
  1975. void lcd_filament_change_extrude_message() {
  1976. START_SCREEN();
  1977. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1978. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_1);
  1979. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_2
  1980. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_2);
  1981. #endif
  1982. #ifdef MSG_FILAMENT_CHANGE_EXTRUDE_3
  1983. STATIC_ITEM(MSG_FILAMENT_CHANGE_EXTRUDE_3);
  1984. #endif
  1985. END_SCREEN();
  1986. }
  1987. void lcd_filament_change_resume_message() {
  1988. START_SCREEN();
  1989. STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, true, true);
  1990. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_1);
  1991. #ifdef MSG_FILAMENT_CHANGE_RESUME_2
  1992. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_2);
  1993. #endif
  1994. #ifdef MSG_FILAMENT_CHANGE_RESUME_3
  1995. STATIC_ITEM(MSG_FILAMENT_CHANGE_RESUME_3);
  1996. #endif
  1997. END_SCREEN();
  1998. }
  1999. void lcd_filament_change_show_message(const FilamentChangeMessage message) {
  2000. switch (message) {
  2001. case FILAMENT_CHANGE_MESSAGE_INIT:
  2002. defer_return_to_status = true;
  2003. lcd_goto_screen(lcd_filament_change_init_message);
  2004. break;
  2005. case FILAMENT_CHANGE_MESSAGE_UNLOAD:
  2006. lcd_goto_screen(lcd_filament_change_unload_message);
  2007. break;
  2008. case FILAMENT_CHANGE_MESSAGE_INSERT:
  2009. lcd_goto_screen(lcd_filament_change_insert_message);
  2010. break;
  2011. case FILAMENT_CHANGE_MESSAGE_LOAD:
  2012. lcd_goto_screen(lcd_filament_change_load_message);
  2013. break;
  2014. case FILAMENT_CHANGE_MESSAGE_EXTRUDE:
  2015. lcd_goto_screen(lcd_filament_change_extrude_message);
  2016. break;
  2017. case FILAMENT_CHANGE_MESSAGE_OPTION:
  2018. filament_change_menu_response = FILAMENT_CHANGE_RESPONSE_WAIT_FOR;
  2019. lcd_goto_screen(lcd_filament_change_option_menu);
  2020. break;
  2021. case FILAMENT_CHANGE_MESSAGE_RESUME:
  2022. lcd_goto_screen(lcd_filament_change_resume_message);
  2023. break;
  2024. case FILAMENT_CHANGE_MESSAGE_STATUS:
  2025. lcd_return_to_status();
  2026. break;
  2027. }
  2028. }
  2029. #endif // FILAMENT_CHANGE_FEATURE
  2030. /**
  2031. *
  2032. * Functions for editing single values
  2033. *
  2034. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  2035. *
  2036. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  2037. *
  2038. * bool _menu_edit_int3();
  2039. * void menu_edit_int3(); // edit int (interactively)
  2040. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  2041. * void _menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  2042. * void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  2043. * void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, screenFunc_t callback); // edit int with callback
  2044. *
  2045. * You can then use one of the menu macros to present the edit interface:
  2046. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  2047. *
  2048. * This expands into a more primitive menu item:
  2049. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2050. *
  2051. *
  2052. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  2053. *
  2054. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  2055. */
  2056. #define menu_edit_type(_type, _name, _strFunc, scale) \
  2057. bool _menu_edit_ ## _name () { \
  2058. ENCODER_DIRECTION_NORMAL(); \
  2059. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2060. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  2061. if (lcdDrawUpdate) \
  2062. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  2063. if (lcd_clicked) { \
  2064. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  2065. lcd_goto_previous_menu(); \
  2066. } \
  2067. return lcd_clicked; \
  2068. } \
  2069. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  2070. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  2071. void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  2072. lcd_save_previous_menu(); \
  2073. \
  2074. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; \
  2075. \
  2076. editLabel = pstr; \
  2077. editValue = ptr; \
  2078. minEditValue = minValue * scale; \
  2079. maxEditValue = maxValue * scale - minEditValue; \
  2080. encoderPosition = (*ptr) * scale - minEditValue; \
  2081. } \
  2082. void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  2083. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2084. currentScreen = menu_edit_ ## _name; \
  2085. }\
  2086. void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, screenFunc_t callback) { \
  2087. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  2088. currentScreen = menu_edit_callback_ ## _name; \
  2089. callbackFunc = callback; \
  2090. }
  2091. menu_edit_type(int, int3, itostr3, 1)
  2092. menu_edit_type(float, float3, ftostr3, 1)
  2093. menu_edit_type(float, float32, ftostr32, 100)
  2094. menu_edit_type(float, float43, ftostr43sign, 1000)
  2095. menu_edit_type(float, float5, ftostr5rj, 0.01)
  2096. menu_edit_type(float, float51, ftostr51sign, 10)
  2097. menu_edit_type(float, float52, ftostr52sign, 100)
  2098. menu_edit_type(float, float62, ftostr62sign, 100)
  2099. menu_edit_type(unsigned long, long5, ftostr5rj, 0.01)
  2100. /**
  2101. *
  2102. * Handlers for RepRap World Keypad input
  2103. *
  2104. */
  2105. #if ENABLED(REPRAPWORLD_KEYPAD)
  2106. void _reprapworld_keypad_move(AxisEnum axis, int dir) {
  2107. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  2108. encoderPosition = dir;
  2109. switch (axis) {
  2110. case X_AXIS: lcd_move_x(); break;
  2111. case Y_AXIS: lcd_move_y(); break;
  2112. case Z_AXIS: lcd_move_z();
  2113. default: break;
  2114. }
  2115. }
  2116. void reprapworld_keypad_move_z_up() { _reprapworld_keypad_move(Z_AXIS, 1); }
  2117. void reprapworld_keypad_move_z_down() { _reprapworld_keypad_move(Z_AXIS, -1); }
  2118. void reprapworld_keypad_move_x_left() { _reprapworld_keypad_move(X_AXIS, -1); }
  2119. void reprapworld_keypad_move_x_right() { _reprapworld_keypad_move(X_AXIS, 1); }
  2120. void reprapworld_keypad_move_y_up() { _reprapworld_keypad_move(Y_AXIS, -1); }
  2121. void reprapworld_keypad_move_y_down() { _reprapworld_keypad_move(Y_AXIS, 1); }
  2122. void reprapworld_keypad_move_home() { enqueue_and_echo_commands_P(PSTR("G28")); } // move all axes home and wait
  2123. void reprapworld_keypad_move_menu() { lcd_goto_screen(lcd_move_menu); }
  2124. #endif // REPRAPWORLD_KEYPAD
  2125. /**
  2126. *
  2127. * Audio feedback for controller clicks
  2128. *
  2129. */
  2130. void lcd_buzz(long duration, uint16_t freq) {
  2131. #if ENABLED(LCD_USE_I2C_BUZZER)
  2132. lcd.buzz(duration, freq);
  2133. #elif PIN_EXISTS(BEEPER)
  2134. buzzer.tone(duration, freq);
  2135. #else
  2136. UNUSED(duration); UNUSED(freq);
  2137. #endif
  2138. }
  2139. void lcd_quick_feedback() {
  2140. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2141. buttons = 0;
  2142. next_button_update_ms = millis() + 500;
  2143. // Buzz and wait. The delay is needed for buttons to settle!
  2144. lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  2145. #if ENABLED(LCD_USE_I2C_BUZZER)
  2146. delay(10);
  2147. #elif PIN_EXISTS(BEEPER)
  2148. for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
  2149. #endif
  2150. }
  2151. /**
  2152. *
  2153. * Menu actions
  2154. *
  2155. */
  2156. void _menu_action_back() { lcd_goto_previous_menu(); }
  2157. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_menu(); lcd_goto_screen(func); }
  2158. void menu_action_gcode(const char* pgcode) { enqueue_and_echo_commands_P(pgcode); }
  2159. void menu_action_function(screenFunc_t func) { (*func)(); }
  2160. #if ENABLED(SDSUPPORT)
  2161. void menu_action_sdfile(const char* filename, char* longFilename) {
  2162. UNUSED(longFilename);
  2163. card.openAndPrintFile(filename);
  2164. lcd_return_to_status();
  2165. }
  2166. void menu_action_sddirectory(const char* filename, char* longFilename) {
  2167. UNUSED(longFilename);
  2168. card.chdir(filename);
  2169. encoderPosition = 0;
  2170. }
  2171. #endif //SDSUPPORT
  2172. void menu_action_setting_edit_bool(const char* pstr, bool* ptr) {UNUSED(pstr); *ptr = !(*ptr); }
  2173. void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callback) {
  2174. menu_action_setting_edit_bool(pstr, ptr);
  2175. (*callback)();
  2176. }
  2177. #endif // ULTIPANEL
  2178. void lcd_init() {
  2179. lcd_implementation_init(
  2180. #if ENABLED(LCD_PROGRESS_BAR)
  2181. true
  2182. #endif
  2183. );
  2184. #if ENABLED(NEWPANEL)
  2185. #if BUTTON_EXISTS(EN1)
  2186. SET_INPUT(BTN_EN1);
  2187. WRITE(BTN_EN1, HIGH);
  2188. #endif
  2189. #if BUTTON_EXISTS(EN2)
  2190. SET_INPUT(BTN_EN2);
  2191. WRITE(BTN_EN2, HIGH);
  2192. #endif
  2193. #if BUTTON_EXISTS(ENC)
  2194. SET_INPUT(BTN_ENC);
  2195. WRITE(BTN_ENC, HIGH);
  2196. #endif
  2197. #if ENABLED(REPRAPWORLD_KEYPAD)
  2198. SET_OUTPUT(SHIFT_CLK);
  2199. OUT_WRITE(SHIFT_LD, HIGH);
  2200. SET_INPUT_PULLUP(SHIFT_OUT);
  2201. #endif
  2202. #if BUTTON_EXISTS(UP)
  2203. SET_INPUT(BTN_UP);
  2204. #endif
  2205. #if BUTTON_EXISTS(DWN)
  2206. SET_INPUT(BTN_DWN);
  2207. #endif
  2208. #if BUTTON_EXISTS(LFT)
  2209. SET_INPUT(BTN_LFT);
  2210. #endif
  2211. #if BUTTON_EXISTS(RT)
  2212. SET_INPUT(BTN_RT);
  2213. #endif
  2214. #else // !NEWPANEL
  2215. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  2216. SET_OUTPUT(SR_DATA_PIN);
  2217. SET_OUTPUT(SR_CLK_PIN);
  2218. #elif defined(SHIFT_CLK)
  2219. SET_OUTPUT(SHIFT_CLK);
  2220. OUT_WRITE(SHIFT_LD, HIGH);
  2221. OUT_WRITE(SHIFT_EN, LOW);
  2222. SET_INPUT_PULLUP(SHIFT_OUT);
  2223. #endif // SR_LCD_2W_NL
  2224. #endif // !NEWPANEL
  2225. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2226. SET_INPUT(SD_DETECT_PIN);
  2227. WRITE(SD_DETECT_PIN, HIGH);
  2228. lcd_sd_status = 2; // UNKNOWN
  2229. #endif
  2230. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2231. slow_buttons = 0;
  2232. #endif
  2233. lcd_buttons_update();
  2234. #if ENABLED(ULTIPANEL)
  2235. encoderDiff = 0;
  2236. #endif
  2237. }
  2238. int lcd_strlen(const char* s) {
  2239. int i = 0, j = 0;
  2240. while (s[i]) {
  2241. #if ENABLED(MAPPER_NON)
  2242. j++;
  2243. #else
  2244. if ((s[i] & 0xC0u) != 0x80u) j++;
  2245. #endif
  2246. i++;
  2247. }
  2248. return j;
  2249. }
  2250. int lcd_strlen_P(const char* s) {
  2251. int j = 0;
  2252. while (pgm_read_byte(s)) {
  2253. #if ENABLED(MAPPER_NON)
  2254. j++;
  2255. #else
  2256. if ((pgm_read_byte(s) & 0xC0u) != 0x80u) j++;
  2257. #endif
  2258. s++;
  2259. }
  2260. return j;
  2261. }
  2262. bool lcd_blink() {
  2263. static uint8_t blink = 0;
  2264. static millis_t next_blink_ms = 0;
  2265. millis_t ms = millis();
  2266. if (ELAPSED(ms, next_blink_ms)) {
  2267. blink ^= 0xFF;
  2268. next_blink_ms = ms + 1000 - LCD_UPDATE_INTERVAL / 2;
  2269. }
  2270. return blink != 0;
  2271. }
  2272. /**
  2273. * Update the LCD, read encoder buttons, etc.
  2274. * - Read button states
  2275. * - Check the SD Card slot state
  2276. * - Act on RepRap World keypad input
  2277. * - Update the encoder position
  2278. * - Apply acceleration to the encoder position
  2279. * - Set lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NOW on controller events
  2280. * - Reset the Info Screen timeout if there's any input
  2281. * - Update status indicators, if any
  2282. *
  2283. * Run the current LCD menu handler callback function:
  2284. * - Call the handler only if lcdDrawUpdate != LCDVIEW_NONE
  2285. * - Before calling the handler, LCDVIEW_CALL_NO_REDRAW => LCDVIEW_NONE
  2286. * - Call the menu handler. Menu handlers should do the following:
  2287. * - If a value changes, set lcdDrawUpdate to LCDVIEW_REDRAW_NOW and draw the value
  2288. * (Encoder events automatically set lcdDrawUpdate for you.)
  2289. * - if (lcdDrawUpdate) { redraw }
  2290. * - Before exiting the handler set lcdDrawUpdate to:
  2291. * - LCDVIEW_CLEAR_CALL_REDRAW to clear screen and set LCDVIEW_CALL_REDRAW_NEXT.
  2292. * - LCDVIEW_REDRAW_NOW or LCDVIEW_NONE to keep drawingm but only in this loop.
  2293. * - LCDVIEW_REDRAW_NEXT to keep drawing and draw on the next loop also.
  2294. * - LCDVIEW_CALL_NO_REDRAW to keep drawing (or start drawing) with no redraw on the next loop.
  2295. * - NOTE: For graphical displays menu handlers may be called 2 or more times per loop,
  2296. * so don't change lcdDrawUpdate without considering this.
  2297. *
  2298. * After the menu handler callback runs (or not):
  2299. * - Clear the LCD if lcdDrawUpdate == LCDVIEW_CLEAR_CALL_REDRAW
  2300. * - Update lcdDrawUpdate for the next loop (i.e., move one state down, usually)
  2301. *
  2302. * No worries. This function is only called from the main thread.
  2303. */
  2304. void lcd_update() {
  2305. #if ENABLED(ULTIPANEL)
  2306. static millis_t return_to_status_ms = 0;
  2307. manage_manual_move();
  2308. lcd_buttons_update();
  2309. // If the action button is pressed...
  2310. if (LCD_CLICKED) {
  2311. if (!wait_for_unclick) { // If not waiting for a debounce release:
  2312. wait_for_unclick = true; // Set debounce flag to ignore continous clicks
  2313. lcd_clicked = !wait_for_user; // Keep the click if not waiting for a user-click
  2314. wait_for_user = false; // Any click clears wait for user
  2315. lcd_quick_feedback(); // Always make a click sound
  2316. }
  2317. }
  2318. else wait_for_unclick = false;
  2319. #endif
  2320. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  2321. bool sd_status = IS_SD_INSERTED;
  2322. if (sd_status != lcd_sd_status && lcd_detected()) {
  2323. if (sd_status) {
  2324. card.initsd();
  2325. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2326. }
  2327. else {
  2328. card.release();
  2329. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2330. }
  2331. lcd_sd_status = sd_status;
  2332. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2333. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  2334. #if ENABLED(LCD_PROGRESS_BAR)
  2335. currentScreen == lcd_status_screen
  2336. #endif
  2337. );
  2338. }
  2339. #endif //SDSUPPORT && SD_DETECT_PIN
  2340. millis_t ms = millis();
  2341. if (ELAPSED(ms, next_lcd_update_ms)) {
  2342. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  2343. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  2344. lcd_implementation_update_indicators();
  2345. #endif
  2346. #if ENABLED(ULTIPANEL)
  2347. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2348. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  2349. #endif
  2350. #if ENABLED(REPRAPWORLD_KEYPAD)
  2351. static uint8_t keypad_debounce = 0;
  2352. if (!REPRAPWORLD_KEYPAD_PRESSED) {
  2353. if (keypad_debounce > 0) keypad_debounce--;
  2354. }
  2355. else if (!keypad_debounce) {
  2356. keypad_debounce = 2;
  2357. if (REPRAPWORLD_KEYPAD_MOVE_MENU) reprapworld_keypad_move_menu();
  2358. #if DISABLED(DELTA) && Z_HOME_DIR == -1
  2359. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2360. #endif
  2361. if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
  2362. #if ENABLED(DELTA) || Z_HOME_DIR != -1
  2363. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  2364. #endif
  2365. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  2366. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  2367. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  2368. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  2369. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  2370. }
  2371. else {
  2372. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  2373. }
  2374. }
  2375. #endif // REPRAPWORLD_KEYPAD
  2376. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  2377. if (encoderPastThreshold || lcd_clicked) {
  2378. if (encoderPastThreshold) {
  2379. int32_t encoderMultiplier = 1;
  2380. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  2381. if (encoderRateMultiplierEnabled) {
  2382. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  2383. if (lastEncoderMovementMillis != 0) {
  2384. // Note that the rate is always calculated between to passes through the
  2385. // loop and that the abs of the encoderDiff value is tracked.
  2386. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  2387. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  2388. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  2389. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  2390. SERIAL_ECHO_START;
  2391. SERIAL_ECHOPAIR("Enc Step Rate: ", encoderStepRate);
  2392. SERIAL_ECHOPAIR(" Multiplier: ", encoderMultiplier);
  2393. SERIAL_ECHOPAIR(" ENCODER_10X_STEPS_PER_SEC: ", ENCODER_10X_STEPS_PER_SEC);
  2394. SERIAL_ECHOPAIR(" ENCODER_100X_STEPS_PER_SEC: ", ENCODER_100X_STEPS_PER_SEC);
  2395. SERIAL_EOL;
  2396. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  2397. }
  2398. lastEncoderMovementMillis = ms;
  2399. } // encoderRateMultiplierEnabled
  2400. #endif //ENCODER_RATE_MULTIPLIER
  2401. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  2402. encoderDiff = 0;
  2403. }
  2404. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  2405. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2406. }
  2407. #endif // ULTIPANEL
  2408. #if ENABLED(ENSURE_SMOOTH_MOVES) && ENABLED(ALWAYS_ALLOW_MENU)
  2409. #define STATUS_UPDATE_CONDITION planner.long_move()
  2410. #else
  2411. #define STATUS_UPDATE_CONDITION true
  2412. #endif
  2413. #if ENABLED(ENSURE_SMOOTH_MOVES) && DISABLED(ALWAYS_ALLOW_MENU)
  2414. #define LCD_HANDLER_CONDITION planner.long_move()
  2415. #else
  2416. #define LCD_HANDLER_CONDITION true
  2417. #endif
  2418. // We arrive here every ~100ms when idling often enough.
  2419. // Instead of tracking the changes simply redraw the Info Screen ~1 time a second.
  2420. static int8_t lcd_status_update_delay = 1; // first update one loop delayed
  2421. if (STATUS_UPDATE_CONDITION &&
  2422. #if ENABLED(ULTIPANEL)
  2423. currentScreen == lcd_status_screen &&
  2424. #endif
  2425. !lcd_status_update_delay--
  2426. ) {
  2427. lcd_status_update_delay = 9;
  2428. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2429. }
  2430. if (LCD_HANDLER_CONDITION) {
  2431. if (lcdDrawUpdate) {
  2432. switch (lcdDrawUpdate) {
  2433. case LCDVIEW_CALL_NO_REDRAW:
  2434. lcdDrawUpdate = LCDVIEW_NONE;
  2435. break;
  2436. case LCDVIEW_CLEAR_CALL_REDRAW: // set by handlers, then altered after (rarely occurs here)
  2437. case LCDVIEW_CALL_REDRAW_NEXT: // set by handlers, then altered after (never occurs here?)
  2438. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2439. case LCDVIEW_REDRAW_NOW: // set above, or by a handler through LCDVIEW_CALL_REDRAW_NEXT
  2440. case LCDVIEW_NONE:
  2441. break;
  2442. } // switch
  2443. #if ENABLED(ULTIPANEL)
  2444. #define CURRENTSCREEN() (*currentScreen)(), lcd_clicked = false
  2445. #else
  2446. #define CURRENTSCREEN() lcd_status_screen()
  2447. #endif
  2448. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  2449. static int8_t dot_color = 0;
  2450. dot_color = 1 - dot_color;
  2451. u8g.firstPage();
  2452. do {
  2453. lcd_setFont(FONT_MENU);
  2454. u8g.setPrintPos(125, 0);
  2455. u8g.setColorIndex(dot_color); // Set color for the alive dot
  2456. u8g.drawPixel(127, 63); // draw alive dot
  2457. u8g.setColorIndex(1); // black on white
  2458. CURRENTSCREEN();
  2459. } while (u8g.nextPage());
  2460. #else
  2461. CURRENTSCREEN();
  2462. #endif
  2463. }
  2464. #if ENABLED(ULTIPANEL)
  2465. // Return to Status Screen after a timeout
  2466. if (currentScreen == lcd_status_screen || defer_return_to_status)
  2467. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  2468. else if (ELAPSED(ms, return_to_status_ms))
  2469. lcd_return_to_status();
  2470. #endif // ULTIPANEL
  2471. switch (lcdDrawUpdate) {
  2472. case LCDVIEW_CLEAR_CALL_REDRAW:
  2473. lcd_implementation_clear();
  2474. case LCDVIEW_CALL_REDRAW_NEXT:
  2475. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  2476. break;
  2477. case LCDVIEW_REDRAW_NOW:
  2478. lcdDrawUpdate = LCDVIEW_NONE;
  2479. break;
  2480. case LCDVIEW_NONE:
  2481. break;
  2482. } // switch
  2483. } // LCD_HANDLER_CONDITION
  2484. }
  2485. }
  2486. void set_utf_strlen(char* s, uint8_t n) {
  2487. uint8_t i = 0, j = 0;
  2488. while (s[i] && (j < n)) {
  2489. #if ENABLED(MAPPER_NON)
  2490. j++;
  2491. #else
  2492. if ((s[i] & 0xC0u) != 0x80u) j++;
  2493. #endif
  2494. i++;
  2495. }
  2496. while (j++ < n) s[i++] = ' ';
  2497. s[i] = '\0';
  2498. }
  2499. void lcd_finishstatus(bool persist=false) {
  2500. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  2501. #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
  2502. UNUSED(persist);
  2503. #endif
  2504. #if ENABLED(LCD_PROGRESS_BAR)
  2505. progress_bar_ms = millis();
  2506. #if PROGRESS_MSG_EXPIRE > 0
  2507. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  2508. #endif
  2509. #endif
  2510. lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
  2511. #if ENABLED(FILAMENT_LCD_DISPLAY)
  2512. previous_lcd_status_ms = millis(); //get status message to show up for a while
  2513. #endif
  2514. }
  2515. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  2516. void dontExpireStatus() { expire_status_ms = 0; }
  2517. #endif
  2518. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  2519. void lcd_setstatus(const char* const message, bool persist) {
  2520. if (lcd_status_message_level > 0) return;
  2521. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  2522. lcd_finishstatus(persist);
  2523. }
  2524. void lcd_setstatuspgm(const char* const message, uint8_t level) {
  2525. if (level < lcd_status_message_level) return;
  2526. lcd_status_message_level = level;
  2527. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  2528. lcd_finishstatus(level > 0);
  2529. }
  2530. void lcd_setalertstatuspgm(const char* const message) {
  2531. lcd_setstatuspgm(message, 1);
  2532. #if ENABLED(ULTIPANEL)
  2533. lcd_return_to_status();
  2534. #endif
  2535. }
  2536. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  2537. #if HAS_LCD_CONTRAST
  2538. void set_lcd_contrast(const int value) {
  2539. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  2540. u8g.setContrast(lcd_contrast);
  2541. }
  2542. #endif
  2543. #if ENABLED(ULTIPANEL)
  2544. /**
  2545. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  2546. * These values are independent of which pins are used for EN_A and EN_B indications
  2547. * The rotary encoder part is also independent to the chipset used for the LCD
  2548. */
  2549. #if defined(EN_A) && defined(EN_B)
  2550. #define encrot0 0
  2551. #define encrot1 2
  2552. #define encrot2 3
  2553. #define encrot3 1
  2554. #endif
  2555. #define GET_BUTTON_STATES(DST) \
  2556. uint8_t new_##DST = 0; \
  2557. WRITE(SHIFT_LD, LOW); \
  2558. WRITE(SHIFT_LD, HIGH); \
  2559. for (int8_t i = 0; i < 8; i++) { \
  2560. new_##DST >>= 1; \
  2561. if (READ(SHIFT_OUT)) SBI(new_##DST, 7); \
  2562. WRITE(SHIFT_CLK, HIGH); \
  2563. WRITE(SHIFT_CLK, LOW); \
  2564. } \
  2565. DST = ~new_##DST; //invert it, because a pressed switch produces a logical 0
  2566. /**
  2567. * Read encoder buttons from the hardware registers
  2568. * Warning: This function is called from interrupt context!
  2569. */
  2570. void lcd_buttons_update() {
  2571. millis_t now = millis();
  2572. if (ELAPSED(now, next_button_update_ms)) {
  2573. #if ENABLED(NEWPANEL)
  2574. uint8_t newbutton = 0;
  2575. #if BUTTON_EXISTS(EN1)
  2576. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  2577. #endif
  2578. #if BUTTON_EXISTS(EN2)
  2579. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  2580. #endif
  2581. #if BUTTON_EXISTS(ENC)
  2582. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  2583. #endif
  2584. #if LCD_HAS_DIRECTIONAL_BUTTONS
  2585. // Manage directional buttons
  2586. #if ENABLED(REVERSE_MENU_DIRECTION)
  2587. #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
  2588. #else
  2589. #define _ENCODER_UD_STEPS ENCODER_STEPS_PER_MENU_ITEM
  2590. #endif
  2591. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  2592. #define ENCODER_UD_STEPS _ENCODER_UD_STEPS
  2593. #define ENCODER_LR_PULSES ENCODER_PULSES_PER_STEP
  2594. #else
  2595. #define ENCODER_UD_STEPS -(_ENCODER_UD_STEPS)
  2596. #define ENCODER_LR_PULSES -(ENCODER_PULSES_PER_STEP)
  2597. #endif
  2598. if (false) {
  2599. // for the else-ifs below
  2600. }
  2601. #if BUTTON_EXISTS(UP)
  2602. else if (BUTTON_PRESSED(UP)) {
  2603. encoderDiff = -(ENCODER_UD_STEPS);
  2604. next_button_update_ms = now + 300;
  2605. }
  2606. #endif
  2607. #if BUTTON_EXISTS(DWN)
  2608. else if (BUTTON_PRESSED(DWN)) {
  2609. encoderDiff = ENCODER_UD_STEPS;
  2610. next_button_update_ms = now + 300;
  2611. }
  2612. #endif
  2613. #if BUTTON_EXISTS(LFT)
  2614. else if (BUTTON_PRESSED(LFT)) {
  2615. encoderDiff = -(ENCODER_LR_PULSES);
  2616. next_button_update_ms = now + 300;
  2617. }
  2618. #endif
  2619. #if BUTTON_EXISTS(RT)
  2620. else if (BUTTON_PRESSED(RT)) {
  2621. encoderDiff = ENCODER_LR_PULSES;
  2622. next_button_update_ms = now + 300;
  2623. }
  2624. #endif
  2625. #endif // LCD_HAS_DIRECTIONAL_BUTTONS
  2626. buttons = newbutton;
  2627. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  2628. buttons |= slow_buttons;
  2629. #endif
  2630. #if ENABLED(REPRAPWORLD_KEYPAD)
  2631. GET_BUTTON_STATES(buttons_reprapworld_keypad);
  2632. #endif
  2633. #else
  2634. GET_BUTTON_STATES(buttons);
  2635. #endif //!NEWPANEL
  2636. } // next_button_update_ms
  2637. // Manage encoder rotation
  2638. #if ENABLED(REVERSE_MENU_DIRECTION) && ENABLED(REVERSE_ENCODER_DIRECTION)
  2639. #define ENCODER_DIFF_CW (encoderDiff -= encoderDirection)
  2640. #define ENCODER_DIFF_CCW (encoderDiff += encoderDirection)
  2641. #elif ENABLED(REVERSE_MENU_DIRECTION)
  2642. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  2643. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  2644. #elif ENABLED(REVERSE_ENCODER_DIRECTION)
  2645. #define ENCODER_DIFF_CW (encoderDiff--)
  2646. #define ENCODER_DIFF_CCW (encoderDiff++)
  2647. #else
  2648. #define ENCODER_DIFF_CW (encoderDiff++)
  2649. #define ENCODER_DIFF_CCW (encoderDiff--)
  2650. #endif
  2651. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  2652. uint8_t enc = 0;
  2653. if (buttons & EN_A) enc |= B01;
  2654. if (buttons & EN_B) enc |= B10;
  2655. if (enc != lastEncoderBits) {
  2656. switch (enc) {
  2657. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  2658. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  2659. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  2660. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  2661. }
  2662. }
  2663. lastEncoderBits = enc;
  2664. }
  2665. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  2666. bool lcd_detected() { return lcd.LcdDetected() == 1; }
  2667. #endif
  2668. #endif // ULTIPANEL
  2669. #endif // ULTRA_LCD