My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ultralcd.cpp 86KB

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