My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 100KB

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