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

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