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

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