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 99KB

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