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 99KB

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