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

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