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

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