My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ultralcd.cpp 116KB

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