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

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