My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ultralcd.cpp 122KB

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