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

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