My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 102KB

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