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

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