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

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