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

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