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

ultralcd.cpp 100KB

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