My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ultralcd.cpp 100KB

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