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

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