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

ultralcd.cpp 100KB

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