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

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