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

ultralcd.cpp 100KB

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