My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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