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

ultralcd.cpp 118KB

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