My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ultralcd.cpp 102KB

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