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

ultralcd.cpp 97KB

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