My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ultralcd.cpp 98KB

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