My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.cpp 102KB

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