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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367
  1. #include "ultralcd.h"
  2. #if ENABLED(ULTRA_LCD)
  3. #include "Marlin.h"
  4. #include "language.h"
  5. #include "cardreader.h"
  6. #include "temperature.h"
  7. #include "stepper.h"
  8. #include "configuration_store.h"
  9. /**
  10. * REVERSE_MENU_DIRECTION
  11. *
  12. * To reverse the menu direction we need a general way to reverse
  13. * the direction of the encoder everywhere. So encoderDirection is
  14. * added to allow the encoder to go the other way.
  15. *
  16. * This behavior is limited to scrolling Menus and SD card listings,
  17. * and is disabled in other contexts.
  18. */
  19. #if ENABLED(REVERSE_MENU_DIRECTION)
  20. int8_t encoderDirection = 1;
  21. #define ENCODER_DIRECTION_NORMAL() (encoderDirection = 1)
  22. #define ENCODER_DIRECTION_MENUS() (encoderDirection = -1)
  23. #else
  24. #define ENCODER_DIRECTION_NORMAL() ;
  25. #define ENCODER_DIRECTION_MENUS() ;
  26. #endif
  27. uint8_t blink = 0; // Variable for animation
  28. int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update
  29. bool encoderRateMultiplierEnabled;
  30. int32_t lastEncoderMovementMillis;
  31. int plaPreheatHotendTemp;
  32. int plaPreheatHPBTemp;
  33. int plaPreheatFanSpeed;
  34. int absPreheatHotendTemp;
  35. int absPreheatHPBTemp;
  36. int absPreheatFanSpeed;
  37. #if ENABLED(FILAMENT_LCD_DISPLAY)
  38. millis_t previous_lcd_status_ms = 0;
  39. #endif
  40. // Function pointer to menu functions.
  41. typedef void (*menuFunc_t)();
  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. #if ENABLED(ULTIPANEL)
  52. #if HAS_POWER_SWITCH
  53. extern bool powersupply;
  54. #endif
  55. const float manual_feedrate[] = MANUAL_FEEDRATE;
  56. static void lcd_main_menu();
  57. static void lcd_tune_menu();
  58. static void lcd_prepare_menu();
  59. static void lcd_move_menu();
  60. static void lcd_control_menu();
  61. static void lcd_control_temperature_menu();
  62. static void lcd_control_temperature_preheat_pla_settings_menu();
  63. static void lcd_control_temperature_preheat_abs_settings_menu();
  64. static void lcd_control_motion_menu();
  65. static void lcd_control_volumetric_menu();
  66. #if ENABLED(HAS_LCD_CONTRAST)
  67. static void lcd_set_contrast();
  68. #endif
  69. #if ENABLED(FWRETRACT)
  70. static void lcd_control_retract_menu();
  71. #endif
  72. #if ENABLED(DELTA_CALIBRATION_MENU)
  73. static void lcd_delta_calibrate_menu();
  74. #endif
  75. #if ENABLED(MANUAL_BED_LEVELING)
  76. #include "mesh_bed_leveling.h"
  77. static void _lcd_level_bed();
  78. static void _lcd_level_bed_homing();
  79. static void lcd_level_bed();
  80. #endif
  81. /* Different types of actions that can be used in menu items. */
  82. static void menu_action_back(menuFunc_t data);
  83. static void menu_action_submenu(menuFunc_t data);
  84. static void menu_action_gcode(const char* pgcode);
  85. static void menu_action_function(menuFunc_t data);
  86. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  87. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  88. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  89. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  90. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  91. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  92. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  93. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  94. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  95. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  96. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  97. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  98. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  99. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  100. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  101. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  102. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  103. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  104. #if ENABLED(SDSUPPORT)
  105. static void lcd_sdcard_menu();
  106. static void menu_action_sdfile(const char* filename, char* longFilename);
  107. static void menu_action_sddirectory(const char* filename, char* longFilename);
  108. #endif
  109. #define ENCODER_FEEDRATE_DEADZONE 10
  110. #if DISABLED(LCD_I2C_VIKI)
  111. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  112. #define ENCODER_STEPS_PER_MENU_ITEM 5
  113. #endif
  114. #ifndef ENCODER_PULSES_PER_STEP
  115. #define ENCODER_PULSES_PER_STEP 1
  116. #endif
  117. #else
  118. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  119. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  120. #endif
  121. #ifndef ENCODER_PULSES_PER_STEP
  122. #define ENCODER_PULSES_PER_STEP 1
  123. #endif
  124. #endif
  125. /* Helper macros for menus */
  126. /**
  127. * START_MENU generates the init code for a menu function
  128. */
  129. #define START_MENU() do { \
  130. ENCODER_DIRECTION_MENUS(); \
  131. encoderRateMultiplierEnabled = false; \
  132. if (encoderPosition > 0x8000) encoderPosition = 0; \
  133. uint8_t encoderLine = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM; \
  134. NOMORE(currentMenuViewOffset, encoderLine); \
  135. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  136. bool wasClicked = LCD_CLICKED, itemSelected; \
  137. for (uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  138. _menuItemNr = 0;
  139. /**
  140. * MENU_ITEM generates draw & handler code for a menu item, potentially calling:
  141. *
  142. * lcd_implementation_drawmenu_[type](sel, row, label, arg3...)
  143. * menu_action_[type](arg3...)
  144. *
  145. * Examples:
  146. * MENU_ITEM(back, MSG_WATCH, lcd_status_screen)
  147. * lcd_implementation_drawmenu_back(sel, row, PSTR(MSG_WATCH), lcd_status_screen)
  148. * menu_action_back(lcd_status_screen)
  149. *
  150. * MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause)
  151. * lcd_implementation_drawmenu_function(sel, row, PSTR(MSG_PAUSE_PRINT), lcd_sdcard_pause)
  152. * menu_action_function(lcd_sdcard_pause)
  153. *
  154. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  155. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  156. * lcd_implementation_drawmenu_setting_edit_int3(sel, row, PSTR(MSG_SPEED), PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  157. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  158. *
  159. */
  160. #define MENU_ITEM(type, label, args...) do { \
  161. if (_menuItemNr == _lineNr) { \
  162. itemSelected = encoderLine == _menuItemNr; \
  163. if (lcdDrawUpdate) \
  164. lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
  165. if (wasClicked && itemSelected) { \
  166. lcd_quick_feedback(); \
  167. menu_action_ ## type(args); \
  168. return; \
  169. } \
  170. } \
  171. _menuItemNr++; \
  172. } while(0)
  173. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  174. //#define ENCODER_RATE_MULTIPLIER_DEBUG // If defined, output the encoder steps per second value
  175. /**
  176. * MENU_MULTIPLIER_ITEM generates drawing and handling code for a multiplier menu item
  177. */
  178. #define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
  179. if (_menuItemNr == _lineNr) { \
  180. itemSelected = encoderLine == _menuItemNr; \
  181. if (lcdDrawUpdate) \
  182. lcd_implementation_drawmenu_ ## type(itemSelected, _drawLineNr, PSTR(label), ## args); \
  183. if (wasClicked && itemSelected) { \
  184. lcd_quick_feedback(); \
  185. encoderRateMultiplierEnabled = true; \
  186. lastEncoderMovementMillis = 0; \
  187. menu_action_ ## type(args); \
  188. return; \
  189. } \
  190. } \
  191. _menuItemNr++; \
  192. } while(0)
  193. #endif //ENCODER_RATE_MULTIPLIER
  194. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  195. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  196. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  197. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  198. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  199. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  200. #else //!ENCODER_RATE_MULTIPLIER
  201. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label), ## args)
  202. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label), ## args)
  203. #endif //!ENCODER_RATE_MULTIPLIER
  204. #define END_MENU() \
  205. if (encoderLine >= _menuItemNr) { encoderPosition = _menuItemNr * (ENCODER_STEPS_PER_MENU_ITEM) - 1; encoderLine = _menuItemNr - 1; }\
  206. if (encoderLine >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = encoderLine - (LCD_HEIGHT) + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
  207. } } while(0)
  208. /** Used variables to keep track of the menu */
  209. volatile uint8_t buttons; //the last checked buttons in a bit array.
  210. #if ENABLED(REPRAPWORLD_KEYPAD)
  211. volatile uint8_t buttons_reprapworld_keypad; // to store the keypad shift register values
  212. #endif
  213. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  214. volatile uint8_t slow_buttons; // Bits of the pressed buttons.
  215. #endif
  216. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  217. millis_t next_button_update_ms;
  218. uint8_t lastEncoderBits;
  219. uint32_t encoderPosition;
  220. #if PIN_EXISTS(SD_DETECT)
  221. uint8_t lcd_sd_status;
  222. #endif
  223. #endif // ULTIPANEL
  224. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  225. millis_t next_lcd_update_ms;
  226. uint8_t lcd_status_update_delay;
  227. bool ignore_click = false;
  228. bool wait_for_unclick;
  229. uint8_t lcdDrawUpdate = 2; /* Set to none-zero when the LCD needs to draw, decreased after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial) */
  230. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  231. menuFunc_t prevMenu = NULL;
  232. uint16_t prevEncoderPosition;
  233. //Variables used when editing values.
  234. const char* editLabel;
  235. void* editValue;
  236. int32_t minEditValue, maxEditValue;
  237. menuFunc_t callbackFunc;
  238. // place-holders for Ki and Kd edits
  239. float raw_Ki, raw_Kd;
  240. /**
  241. * General function to go directly to a menu
  242. */
  243. static void lcd_goto_menu(menuFunc_t menu, const bool feedback = false, const uint32_t encoder = 0) {
  244. if (currentMenu != menu) {
  245. currentMenu = menu;
  246. #if ENABLED(NEWPANEL)
  247. encoderPosition = encoder;
  248. if (feedback) lcd_quick_feedback();
  249. #endif
  250. // For LCD_PROGRESS_BAR re-initialize the custom characters
  251. #if ENABLED(LCD_PROGRESS_BAR)
  252. lcd_set_custom_characters(menu == lcd_status_screen);
  253. #endif
  254. }
  255. }
  256. inline void lcd_save_previous_menu() { prevMenu = currentMenu; prevEncoderPosition = encoderPosition; }
  257. static void lcd_goto_previous_menu() { lcd_goto_menu(prevMenu, true, prevEncoderPosition); }
  258. /**
  259. *
  260. * "Info Screen"
  261. *
  262. * This is very display-dependent, so the lcd implementation draws this.
  263. */
  264. static void lcd_status_screen() {
  265. ENCODER_DIRECTION_NORMAL();
  266. encoderRateMultiplierEnabled = false;
  267. #if ENABLED(LCD_PROGRESS_BAR)
  268. millis_t ms = millis();
  269. #if DISABLED(PROGRESS_MSG_ONCE)
  270. if (ms > progress_bar_ms + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
  271. progress_bar_ms = ms;
  272. }
  273. #endif
  274. #if PROGRESS_MSG_EXPIRE > 0
  275. // Handle message expire
  276. if (expire_status_ms > 0) {
  277. #if ENABLED(SDSUPPORT)
  278. if (card.isFileOpen()) {
  279. // Expire the message when printing is active
  280. if (IS_SD_PRINTING) {
  281. if (ms >= expire_status_ms) {
  282. lcd_status_message[0] = '\0';
  283. expire_status_ms = 0;
  284. }
  285. }
  286. else {
  287. expire_status_ms += LCD_UPDATE_INTERVAL;
  288. }
  289. }
  290. else {
  291. expire_status_ms = 0;
  292. }
  293. #else
  294. expire_status_ms = 0;
  295. #endif //SDSUPPORT
  296. }
  297. #endif
  298. #endif //LCD_PROGRESS_BAR
  299. lcd_implementation_status_screen();
  300. #if ENABLED(ULTIPANEL)
  301. bool current_click = LCD_CLICKED;
  302. if (ignore_click) {
  303. if (wait_for_unclick) {
  304. if (!current_click)
  305. ignore_click = wait_for_unclick = false;
  306. else
  307. current_click = false;
  308. }
  309. else if (current_click) {
  310. lcd_quick_feedback();
  311. wait_for_unclick = true;
  312. current_click = false;
  313. }
  314. }
  315. if (current_click) {
  316. lcd_goto_menu(lcd_main_menu, true);
  317. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  318. #if ENABLED(LCD_PROGRESS_BAR)
  319. currentMenu == lcd_status_screen
  320. #endif
  321. );
  322. #if ENABLED(FILAMENT_LCD_DISPLAY)
  323. previous_lcd_status_ms = millis(); // get status message to show up for a while
  324. #endif
  325. }
  326. #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
  327. // Dead zone at 100% feedrate
  328. if ((feedrate_multiplier < 100 && (feedrate_multiplier + int(encoderPosition)) > 100) ||
  329. (feedrate_multiplier > 100 && (feedrate_multiplier + int(encoderPosition)) < 100)) {
  330. encoderPosition = 0;
  331. feedrate_multiplier = 100;
  332. }
  333. if (feedrate_multiplier == 100) {
  334. if (int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE) {
  335. feedrate_multiplier += int(encoderPosition) - (ENCODER_FEEDRATE_DEADZONE);
  336. encoderPosition = 0;
  337. }
  338. else if (int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE) {
  339. feedrate_multiplier += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  340. encoderPosition = 0;
  341. }
  342. }
  343. else {
  344. feedrate_multiplier += int(encoderPosition);
  345. encoderPosition = 0;
  346. }
  347. #endif // ULTIPANEL_FEEDMULTIPLY
  348. feedrate_multiplier = constrain(feedrate_multiplier, 10, 999);
  349. #endif //ULTIPANEL
  350. }
  351. #if ENABLED(ULTIPANEL)
  352. static void lcd_return_to_status() { lcd_goto_menu(lcd_status_screen); }
  353. #if ENABLED(SDSUPPORT)
  354. static void lcd_sdcard_pause() { card.pauseSDPrint(); }
  355. static void lcd_sdcard_resume() { card.startFileprint(); }
  356. static void lcd_sdcard_stop() {
  357. quickStop();
  358. card.sdprinting = false;
  359. card.closefile();
  360. autotempShutdown();
  361. cancel_heatup = true;
  362. lcd_setstatus(MSG_PRINT_ABORTED, true);
  363. }
  364. #endif //SDSUPPORT
  365. /**
  366. *
  367. * "Main" menu
  368. *
  369. */
  370. static void lcd_main_menu() {
  371. START_MENU();
  372. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  373. if (movesplanned() || IS_SD_PRINTING) {
  374. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  375. }
  376. else {
  377. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  378. #if ENABLED(DELTA_CALIBRATION_MENU)
  379. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  380. #endif
  381. }
  382. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  383. #if ENABLED(SDSUPPORT)
  384. if (card.cardOK) {
  385. if (card.isFileOpen()) {
  386. if (card.sdprinting)
  387. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  388. else
  389. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  390. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  391. }
  392. else {
  393. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  394. #if !PIN_EXISTS(SD_DETECT)
  395. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  396. #endif
  397. }
  398. }
  399. else {
  400. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  401. #if !PIN_EXISTS(SD_DETECT)
  402. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  403. #endif
  404. }
  405. #endif //SDSUPPORT
  406. END_MENU();
  407. }
  408. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  409. static void lcd_autostart_sd() {
  410. card.autostart_index = 0;
  411. card.setroot();
  412. card.checkautostart(true);
  413. }
  414. #endif
  415. /**
  416. * Set the home offset based on the current_position
  417. */
  418. void lcd_set_home_offsets() {
  419. // M428 Command
  420. enqueuecommands_P(PSTR("M428"));
  421. lcd_return_to_status();
  422. }
  423. #if ENABLED(BABYSTEPPING)
  424. static void _lcd_babystep(int axis, const char* msg) {
  425. ENCODER_DIRECTION_NORMAL();
  426. if (encoderPosition != 0) {
  427. babystepsTodo[axis] += (BABYSTEP_MULTIPLICATOR) * (int)encoderPosition;
  428. encoderPosition = 0;
  429. lcdDrawUpdate = 1;
  430. }
  431. if (lcdDrawUpdate) lcd_implementation_drawedit(msg, "");
  432. if (LCD_CLICKED) lcd_goto_previous_menu();
  433. }
  434. static void lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  435. static void lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  436. static void lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  437. #endif //BABYSTEPPING
  438. /**
  439. * Watch temperature callbacks
  440. */
  441. #if ENABLED(THERMAL_PROTECTION_HOTENDS)
  442. #if TEMP_SENSOR_0 != 0
  443. void watch_temp_callback_E0() { start_watching_heater(0); }
  444. #endif
  445. #if EXTRUDERS > 1 && TEMP_SENSOR_1 != 0
  446. void watch_temp_callback_E1() { start_watching_heater(1); }
  447. #endif // EXTRUDERS > 1
  448. #if EXTRUDERS > 2 && TEMP_SENSOR_2 != 0
  449. void watch_temp_callback_E2() { start_watching_heater(2); }
  450. #endif // EXTRUDERS > 2
  451. #if EXTRUDERS > 3 && TEMP_SENSOR_3 != 0
  452. void watch_temp_callback_E3() { start_watching_heater(3); }
  453. #endif // EXTRUDERS > 3
  454. #else
  455. #if TEMP_SENSOR_0 != 0
  456. void watch_temp_callback_E0() {}
  457. #endif
  458. #if EXTRUDERS > 1 && TEMP_SENSOR_1 != 0
  459. void watch_temp_callback_E1() {}
  460. #endif // EXTRUDERS > 1
  461. #if EXTRUDERS > 2 && TEMP_SENSOR_2 != 0
  462. void watch_temp_callback_E2() {}
  463. #endif // EXTRUDERS > 2
  464. #if EXTRUDERS > 3 && TEMP_SENSOR_3 != 0
  465. void watch_temp_callback_E3() {}
  466. #endif // EXTRUDERS > 3
  467. #endif
  468. /**
  469. *
  470. * "Tune" submenu
  471. *
  472. */
  473. static void lcd_tune_menu() {
  474. START_MENU();
  475. //
  476. // ^ Main
  477. //
  478. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  479. //
  480. // Speed:
  481. //
  482. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999);
  483. //
  484. // Nozzle:
  485. // Nozzle [1-4]:
  486. //
  487. #if EXTRUDERS == 1
  488. #if TEMP_SENSOR_0 != 0
  489. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  490. #endif
  491. #else //EXTRUDERS > 1
  492. #if TEMP_SENSOR_0 != 0
  493. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  494. #endif
  495. #if TEMP_SENSOR_1 != 0
  496. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  497. #endif
  498. #if EXTRUDERS > 2
  499. #if TEMP_SENSOR_2 != 0
  500. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  501. #endif
  502. #if EXTRUDERS > 3
  503. #if TEMP_SENSOR_3 != 0
  504. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  505. #endif
  506. #endif // EXTRUDERS > 3
  507. #endif // EXTRUDERS > 2
  508. #endif // EXTRUDERS > 1
  509. //
  510. // Bed:
  511. //
  512. #if TEMP_SENSOR_BED != 0
  513. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  514. #endif
  515. //
  516. // Fan Speed:
  517. //
  518. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  519. //
  520. // Flow:
  521. // Flow 1:
  522. // Flow 2:
  523. // Flow 3:
  524. // Flow 4:
  525. //
  526. #if EXTRUDERS == 1
  527. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[0], 10, 999);
  528. #else // EXTRUDERS > 1
  529. MENU_ITEM_EDIT(int3, MSG_FLOW, &extruder_multiplier[active_extruder], 10, 999);
  530. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &extruder_multiplier[0], 10, 999);
  531. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &extruder_multiplier[1], 10, 999);
  532. #if EXTRUDERS > 2
  533. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &extruder_multiplier[2], 10, 999);
  534. #if EXTRUDERS > 3
  535. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &extruder_multiplier[3], 10, 999);
  536. #endif //EXTRUDERS > 3
  537. #endif //EXTRUDERS > 2
  538. #endif //EXTRUDERS > 1
  539. //
  540. // Babystep X:
  541. // Babystep Y:
  542. // Babystep Z:
  543. //
  544. #if ENABLED(BABYSTEPPING)
  545. #if ENABLED(BABYSTEP_XY)
  546. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  547. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  548. #endif //BABYSTEP_XY
  549. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  550. #endif
  551. //
  552. // Change filament
  553. //
  554. #if ENABLED(FILAMENTCHANGEENABLE)
  555. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  556. #endif
  557. END_MENU();
  558. }
  559. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  560. if (temph > 0) setTargetHotend(temph, endnum);
  561. #if TEMP_SENSOR_BED != 0
  562. setTargetBed(tempb);
  563. #endif
  564. fanSpeed = fan;
  565. lcd_return_to_status();
  566. }
  567. #if TEMP_SENSOR_0 != 0
  568. void lcd_preheat_pla0() { _lcd_preheat(0, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  569. void lcd_preheat_abs0() { _lcd_preheat(0, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  570. #endif
  571. #if EXTRUDERS > 1
  572. void lcd_preheat_pla1() { _lcd_preheat(1, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  573. void lcd_preheat_abs1() { _lcd_preheat(1, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  574. #if EXTRUDERS > 2
  575. void lcd_preheat_pla2() { _lcd_preheat(2, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  576. void lcd_preheat_abs2() { _lcd_preheat(2, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  577. #if EXTRUDERS > 3
  578. void lcd_preheat_pla3() { _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  579. void lcd_preheat_abs3() { _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  580. #endif
  581. #endif
  582. void lcd_preheat_pla0123() {
  583. setTargetHotend0(plaPreheatHotendTemp);
  584. setTargetHotend1(plaPreheatHotendTemp);
  585. setTargetHotend2(plaPreheatHotendTemp);
  586. _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed);
  587. }
  588. void lcd_preheat_abs0123() {
  589. setTargetHotend0(absPreheatHotendTemp);
  590. setTargetHotend1(absPreheatHotendTemp);
  591. setTargetHotend2(absPreheatHotendTemp);
  592. _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed);
  593. }
  594. #endif // EXTRUDERS > 1
  595. #if TEMP_SENSOR_BED != 0
  596. void lcd_preheat_pla_bedonly() { _lcd_preheat(0, 0, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  597. void lcd_preheat_abs_bedonly() { _lcd_preheat(0, 0, absPreheatHPBTemp, absPreheatFanSpeed); }
  598. #endif
  599. #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
  600. static void lcd_preheat_pla_menu() {
  601. START_MENU();
  602. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  603. #if EXTRUDERS == 1
  604. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  605. #else
  606. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H1, lcd_preheat_pla0);
  607. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H2, lcd_preheat_pla1);
  608. #if EXTRUDERS > 2
  609. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H3, lcd_preheat_pla2);
  610. #if EXTRUDERS > 3
  611. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H4, lcd_preheat_pla3);
  612. #endif
  613. #endif
  614. MENU_ITEM(function, MSG_PREHEAT_PLA_ALL, lcd_preheat_pla0123);
  615. #endif
  616. #if TEMP_SENSOR_BED != 0
  617. MENU_ITEM(function, MSG_PREHEAT_PLA_BEDONLY, lcd_preheat_pla_bedonly);
  618. #endif
  619. END_MENU();
  620. }
  621. static void lcd_preheat_abs_menu() {
  622. START_MENU();
  623. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  624. #if EXTRUDERS == 1
  625. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  626. #else
  627. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H1, lcd_preheat_abs0);
  628. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H2, lcd_preheat_abs1);
  629. #if EXTRUDERS > 2
  630. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H3, lcd_preheat_abs2);
  631. #if EXTRUDERS > 3
  632. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H4, lcd_preheat_abs3);
  633. #endif
  634. #endif
  635. MENU_ITEM(function, MSG_PREHEAT_ABS_ALL, lcd_preheat_abs0123);
  636. #endif
  637. #if TEMP_SENSOR_BED != 0
  638. MENU_ITEM(function, MSG_PREHEAT_ABS_BEDONLY, lcd_preheat_abs_bedonly);
  639. #endif
  640. END_MENU();
  641. }
  642. #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_BED)
  643. void lcd_cooldown() {
  644. disable_all_heaters();
  645. fanSpeed = 0;
  646. lcd_return_to_status();
  647. }
  648. /**
  649. *
  650. * "Prepare" submenu
  651. *
  652. */
  653. static void lcd_prepare_menu() {
  654. START_MENU();
  655. //
  656. // ^ Main
  657. //
  658. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  659. //
  660. // Auto Home
  661. //
  662. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  663. //
  664. // Set Home Offsets
  665. //
  666. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  667. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  668. //
  669. // Level Bed
  670. //
  671. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  672. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS])
  673. MENU_ITEM(gcode, MSG_LEVEL_BED, PSTR("G29"));
  674. #elif ENABLED(MANUAL_BED_LEVELING)
  675. MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
  676. #endif
  677. //
  678. // Move Axis
  679. //
  680. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  681. //
  682. // Disable Steppers
  683. //
  684. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  685. //
  686. // Preheat PLA
  687. // Preheat ABS
  688. //
  689. #if TEMP_SENSOR_0 != 0
  690. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0
  691. MENU_ITEM(submenu, MSG_PREHEAT_PLA, lcd_preheat_pla_menu);
  692. MENU_ITEM(submenu, MSG_PREHEAT_ABS, lcd_preheat_abs_menu);
  693. #else
  694. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  695. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  696. #endif
  697. #endif
  698. //
  699. // Cooldown
  700. //
  701. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  702. //
  703. // Switch power on/off
  704. //
  705. #if HAS_POWER_SWITCH
  706. if (powersupply)
  707. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  708. else
  709. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  710. #endif
  711. //
  712. // Autostart
  713. //
  714. #if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
  715. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  716. #endif
  717. END_MENU();
  718. }
  719. #if ENABLED(DELTA_CALIBRATION_MENU)
  720. static void lcd_delta_calibrate_menu() {
  721. START_MENU();
  722. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  723. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  724. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_X, PSTR("G0 F8000 X-77.94 Y-45 Z0"));
  725. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Y, PSTR("G0 F8000 X77.94 Y-45 Z0"));
  726. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Z, PSTR("G0 F8000 X0 Y90 Z0"));
  727. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_CENTER, PSTR("G0 F8000 X0 Y0 Z0"));
  728. END_MENU();
  729. }
  730. #endif // DELTA_CALIBRATION_MENU
  731. inline void line_to_current(AxisEnum axis) {
  732. #if ENABLED(DELTA)
  733. calculate_delta(current_position);
  734. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  735. #else
  736. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  737. #endif
  738. }
  739. /**
  740. *
  741. * "Prepare" > "Move Axis" submenu
  742. *
  743. */
  744. float move_menu_scale;
  745. static void lcd_move_menu_axis();
  746. static void _lcd_move(const char* name, AxisEnum axis, int min, int max) {
  747. ENCODER_DIRECTION_NORMAL();
  748. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  749. refresh_cmd_timeout();
  750. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  751. if (min_software_endstops) NOLESS(current_position[axis], min);
  752. if (max_software_endstops) NOMORE(current_position[axis], max);
  753. encoderPosition = 0;
  754. line_to_current(axis);
  755. lcdDrawUpdate = 1;
  756. }
  757. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  758. if (LCD_CLICKED) lcd_goto_previous_menu();
  759. }
  760. #if ENABLED(DELTA)
  761. static float delta_clip_radius_2 = (DELTA_PRINTABLE_RADIUS) * (DELTA_PRINTABLE_RADIUS);
  762. static int delta_clip( float a ) { return sqrt(delta_clip_radius_2 - a*a); }
  763. static void lcd_move_x() { int clip = delta_clip(current_position[Y_AXIS]); _lcd_move(PSTR(MSG_MOVE_X), X_AXIS, max(X_MIN_POS, -clip), min(X_MAX_POS, clip)); }
  764. static void lcd_move_y() { int clip = delta_clip(current_position[X_AXIS]); _lcd_move(PSTR(MSG_MOVE_X), X_AXIS, max(X_MIN_POS, -clip), min(X_MAX_POS, clip)); }
  765. #else
  766. static void lcd_move_x() { _lcd_move(PSTR(MSG_MOVE_X), X_AXIS, X_MIN_POS, X_MAX_POS); }
  767. static void lcd_move_y() { _lcd_move(PSTR(MSG_MOVE_Y), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
  768. #endif
  769. static void lcd_move_z() { _lcd_move(PSTR(MSG_MOVE_Z), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
  770. static void lcd_move_e(
  771. #if EXTRUDERS > 1
  772. uint8_t e
  773. #endif
  774. ) {
  775. ENCODER_DIRECTION_NORMAL();
  776. #if EXTRUDERS > 1
  777. unsigned short original_active_extruder = active_extruder;
  778. active_extruder = e;
  779. #endif
  780. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  781. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  782. encoderPosition = 0;
  783. line_to_current(E_AXIS);
  784. lcdDrawUpdate = 1;
  785. }
  786. if (lcdDrawUpdate) {
  787. PGM_P pos_label;
  788. #if EXTRUDERS == 1
  789. pos_label = PSTR(MSG_MOVE_E);
  790. #else
  791. switch (e) {
  792. case 0: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  793. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  794. #if EXTRUDERS > 2
  795. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  796. #if EXTRUDERS > 3
  797. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  798. #endif //EXTRUDERS > 3
  799. #endif //EXTRUDERS > 2
  800. }
  801. #endif //EXTRUDERS > 1
  802. lcd_implementation_drawedit(pos_label, ftostr31(current_position[E_AXIS]));
  803. }
  804. if (LCD_CLICKED) lcd_goto_previous_menu();
  805. #if EXTRUDERS > 1
  806. active_extruder = original_active_extruder;
  807. #endif
  808. }
  809. #if EXTRUDERS > 1
  810. static void lcd_move_e0() { lcd_move_e(0); }
  811. static void lcd_move_e1() { lcd_move_e(1); }
  812. #if EXTRUDERS > 2
  813. static void lcd_move_e2() { lcd_move_e(2); }
  814. #if EXTRUDERS > 3
  815. static void lcd_move_e3() { lcd_move_e(3); }
  816. #endif
  817. #endif
  818. #endif // EXTRUDERS > 1
  819. /**
  820. *
  821. * "Prepare" > "Move Xmm" > "Move XYZ" submenu
  822. *
  823. */
  824. static void lcd_move_menu_axis() {
  825. START_MENU();
  826. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  827. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  828. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  829. if (move_menu_scale < 10.0) {
  830. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  831. #if EXTRUDERS == 1
  832. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  833. #else
  834. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_e0);
  835. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_e1);
  836. #if EXTRUDERS > 2
  837. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_e2);
  838. #if EXTRUDERS > 3
  839. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_e3);
  840. #endif
  841. #endif
  842. #endif // EXTRUDERS > 1
  843. }
  844. END_MENU();
  845. }
  846. static void lcd_move_menu_10mm() {
  847. move_menu_scale = 10.0;
  848. lcd_move_menu_axis();
  849. }
  850. static void lcd_move_menu_1mm() {
  851. move_menu_scale = 1.0;
  852. lcd_move_menu_axis();
  853. }
  854. static void lcd_move_menu_01mm() {
  855. move_menu_scale = 0.1;
  856. lcd_move_menu_axis();
  857. }
  858. /**
  859. *
  860. * "Prepare" > "Move Axis" submenu
  861. *
  862. */
  863. static void lcd_move_menu() {
  864. START_MENU();
  865. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  866. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  867. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  868. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  869. //TODO:X,Y,Z,E
  870. END_MENU();
  871. }
  872. /**
  873. *
  874. * "Control" submenu
  875. *
  876. */
  877. static void lcd_control_menu() {
  878. START_MENU();
  879. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  880. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  881. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  882. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  883. #if ENABLED(HAS_LCD_CONTRAST)
  884. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  885. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  886. #endif
  887. #if ENABLED(FWRETRACT)
  888. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  889. #endif
  890. #if ENABLED(EEPROM_SETTINGS)
  891. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  892. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  893. #endif
  894. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  895. END_MENU();
  896. }
  897. /**
  898. *
  899. * "Temperature" submenu
  900. *
  901. */
  902. #if ENABLED(PIDTEMP)
  903. // Helpers for editing PID Ki & Kd values
  904. // grab the PID value out of the temp variable; scale it; then update the PID driver
  905. void copy_and_scalePID_i(int e) {
  906. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  907. updatePID();
  908. }
  909. void copy_and_scalePID_d(int e) {
  910. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  911. updatePID();
  912. }
  913. #define COPY_AND_SCALE(eindex) \
  914. void copy_and_scalePID_i_E ## eindex() { copy_and_scalePID_i(eindex); } \
  915. void copy_and_scalePID_d_E ## eindex() { copy_and_scalePID_d(eindex); }
  916. COPY_AND_SCALE(0);
  917. #if ENABLED(PID_PARAMS_PER_EXTRUDER)
  918. #if EXTRUDERS > 1
  919. COPY_AND_SCALE(1);
  920. #if EXTRUDERS > 2
  921. COPY_AND_SCALE(2);
  922. #if EXTRUDERS > 3
  923. COPY_AND_SCALE(3);
  924. #endif //EXTRUDERS > 3
  925. #endif //EXTRUDERS > 2
  926. #endif //EXTRUDERS > 1
  927. #endif //PID_PARAMS_PER_EXTRUDER
  928. #endif //PIDTEMP
  929. /**
  930. *
  931. * "Control" > "Temperature" submenu
  932. *
  933. */
  934. static void lcd_control_temperature_menu() {
  935. START_MENU();
  936. //
  937. // ^ Control
  938. //
  939. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  940. //
  941. // Nozzle:
  942. // Nozzle [1-4]:
  943. //
  944. #if EXTRUDERS == 1
  945. #if TEMP_SENSOR_0 != 0
  946. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  947. #endif
  948. #else //EXTRUDERS > 1
  949. #if TEMP_SENSOR_0 != 0
  950. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N1, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15, watch_temp_callback_E0);
  951. #endif
  952. #if TEMP_SENSOR_1 != 0
  953. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15, watch_temp_callback_E1);
  954. #endif
  955. #if EXTRUDERS > 2
  956. #if TEMP_SENSOR_2 != 0
  957. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15, watch_temp_callback_E2);
  958. #endif
  959. #if EXTRUDERS > 3
  960. #if TEMP_SENSOR_3 != 0
  961. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15, watch_temp_callback_E3);
  962. #endif
  963. #endif // EXTRUDERS > 3
  964. #endif // EXTRUDERS > 2
  965. #endif // EXTRUDERS > 1
  966. //
  967. // Bed:
  968. //
  969. #if TEMP_SENSOR_BED != 0
  970. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  971. #endif
  972. //
  973. // Fan Speed:
  974. //
  975. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  976. //
  977. // Autotemp, Min, Max, Fact
  978. //
  979. #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  980. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  981. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  982. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  983. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  984. #endif
  985. //
  986. // PID-P, PID-I, PID-D, PID-C
  987. // PID-P E1, PID-I E1, PID-D E1, PID-C E1
  988. // PID-P E2, PID-I E2, PID-D E2, PID-C E2
  989. // PID-P E3, PID-I E3, PID-D E3, PID-C E3
  990. // PID-P E4, PID-I E4, PID-D E4, PID-C E4
  991. //
  992. #if ENABLED(PIDTEMP)
  993. #define _PID_MENU_ITEMS(ELABEL, eindex) \
  994. raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
  995. raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
  996. MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
  997. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
  998. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
  999. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  1000. #define PID_MENU_ITEMS(ELABEL, eindex) \
  1001. _PID_MENU_ITEMS(ELABEL, eindex); \
  1002. MENU_ITEM_EDIT(float3, MSG_PID_C ELABEL, &PID_PARAM(Kc, eindex), 1, 9990)
  1003. #else
  1004. #define PID_MENU_ITEMS(ELABEL, eindex) _PID_MENU_ITEMS(ELABEL, eindex)
  1005. #endif
  1006. #if ENABLED(PID_PARAMS_PER_EXTRUDER) && EXTRUDERS > 1
  1007. PID_MENU_ITEMS(MSG_E1, 0);
  1008. PID_MENU_ITEMS(MSG_E2, 1);
  1009. #if EXTRUDERS > 2
  1010. PID_MENU_ITEMS(MSG_E3, 2);
  1011. #if EXTRUDERS > 3
  1012. PID_MENU_ITEMS(MSG_E4, 3);
  1013. #endif //EXTRUDERS > 3
  1014. #endif //EXTRUDERS > 2
  1015. #else //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1016. PID_MENU_ITEMS("", 0);
  1017. #endif //!PID_PARAMS_PER_EXTRUDER || EXTRUDERS == 1
  1018. #endif //PIDTEMP
  1019. //
  1020. // Preheat PLA conf
  1021. //
  1022. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  1023. //
  1024. // Preheat ABS conf
  1025. //
  1026. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  1027. END_MENU();
  1028. }
  1029. /**
  1030. *
  1031. * "Temperature" > "Preheat PLA conf" submenu
  1032. *
  1033. */
  1034. static void lcd_control_temperature_preheat_pla_settings_menu() {
  1035. START_MENU();
  1036. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1037. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  1038. #if TEMP_SENSOR_0 != 0
  1039. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1040. #endif
  1041. #if TEMP_SENSOR_BED != 0
  1042. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1043. #endif
  1044. #if ENABLED(EEPROM_SETTINGS)
  1045. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1046. #endif
  1047. END_MENU();
  1048. }
  1049. /**
  1050. *
  1051. * "Temperature" > "Preheat ABS conf" submenu
  1052. *
  1053. */
  1054. static void lcd_control_temperature_preheat_abs_settings_menu() {
  1055. START_MENU();
  1056. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1057. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  1058. #if TEMP_SENSOR_0 != 0
  1059. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
  1060. #endif
  1061. #if TEMP_SENSOR_BED != 0
  1062. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, BED_MINTEMP, BED_MAXTEMP - 15);
  1063. #endif
  1064. #if ENABLED(EEPROM_SETTINGS)
  1065. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  1066. #endif
  1067. END_MENU();
  1068. }
  1069. /**
  1070. *
  1071. * "Control" > "Motion" submenu
  1072. *
  1073. */
  1074. static void lcd_control_motion_menu() {
  1075. START_MENU();
  1076. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1077. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  1078. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  1079. #endif
  1080. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 10, 99000);
  1081. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  1082. #if ENABLED(DELTA)
  1083. MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &max_z_jerk, 1, 990);
  1084. #else
  1085. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  1086. #endif
  1087. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  1088. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  1089. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  1090. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  1091. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  1092. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  1093. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  1094. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  1095. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  1096. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 10, 99000, reset_acceleration_rates);
  1097. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  1098. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  1099. MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &travel_acceleration, 100, 99000);
  1100. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  1101. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  1102. #if ENABLED(DELTA)
  1103. MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1104. #else
  1105. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  1106. #endif
  1107. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  1108. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
  1109. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
  1110. #endif
  1111. #if ENABLED(SCARA)
  1112. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS], 0.5, 2);
  1113. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS], 0.5, 2);
  1114. #endif
  1115. END_MENU();
  1116. }
  1117. /**
  1118. *
  1119. * "Control" > "Filament" submenu
  1120. *
  1121. */
  1122. static void lcd_control_volumetric_menu() {
  1123. START_MENU();
  1124. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1125. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  1126. if (volumetric_enabled) {
  1127. #if EXTRUDERS == 1
  1128. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1129. #else //EXTRUDERS > 1
  1130. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  1131. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  1132. #if EXTRUDERS > 2
  1133. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  1134. #if EXTRUDERS > 3
  1135. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  1136. #endif //EXTRUDERS > 3
  1137. #endif //EXTRUDERS > 2
  1138. #endif //EXTRUDERS > 1
  1139. }
  1140. END_MENU();
  1141. }
  1142. /**
  1143. *
  1144. * "Control" > "Contrast" submenu
  1145. *
  1146. */
  1147. #if ENABLED(HAS_LCD_CONTRAST)
  1148. static void lcd_set_contrast() {
  1149. ENCODER_DIRECTION_NORMAL();
  1150. if (encoderPosition != 0) {
  1151. #if ENABLED(U8GLIB_LM6059_AF)
  1152. lcd_contrast += encoderPosition;
  1153. lcd_contrast &= 0xFF;
  1154. #else
  1155. lcd_contrast -= encoderPosition;
  1156. lcd_contrast &= 0x3F;
  1157. #endif
  1158. encoderPosition = 0;
  1159. lcdDrawUpdate = 1;
  1160. u8g.setContrast(lcd_contrast);
  1161. }
  1162. if (lcdDrawUpdate) {
  1163. #if ENABLED(U8GLIB_LM6059_AF)
  1164. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr3(lcd_contrast));
  1165. #else
  1166. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
  1167. #endif
  1168. }
  1169. if (LCD_CLICKED) lcd_goto_previous_menu();
  1170. }
  1171. #endif // HAS_LCD_CONTRAST
  1172. /**
  1173. *
  1174. * "Control" > "Retract" submenu
  1175. *
  1176. */
  1177. #if ENABLED(FWRETRACT)
  1178. static void lcd_control_retract_menu() {
  1179. START_MENU();
  1180. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1181. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  1182. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  1183. #if EXTRUDERS > 1
  1184. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  1185. #endif
  1186. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  1187. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  1188. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  1189. #if EXTRUDERS > 1
  1190. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  1191. #endif
  1192. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  1193. END_MENU();
  1194. }
  1195. #endif // FWRETRACT
  1196. #if ENABLED(SDSUPPORT)
  1197. #if !PIN_EXISTS(SD_DETECT)
  1198. static void lcd_sd_refresh() {
  1199. card.initsd();
  1200. currentMenuViewOffset = 0;
  1201. }
  1202. #endif
  1203. static void lcd_sd_updir() {
  1204. card.updir();
  1205. currentMenuViewOffset = 0;
  1206. }
  1207. /**
  1208. *
  1209. * "Print from SD" submenu
  1210. *
  1211. */
  1212. void lcd_sdcard_menu() {
  1213. ENCODER_DIRECTION_MENUS();
  1214. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
  1215. uint16_t fileCnt = card.getnrfilenames();
  1216. START_MENU();
  1217. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1218. card.getWorkDirName();
  1219. if (card.filename[0] == '/') {
  1220. #if !PIN_EXISTS(SD_DETECT)
  1221. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1222. #endif
  1223. }
  1224. else {
  1225. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1226. }
  1227. for (uint16_t i = 0; i < fileCnt; i++) {
  1228. if (_menuItemNr == _lineNr) {
  1229. card.getfilename(
  1230. #if ENABLED(SDCARD_RATHERRECENTFIRST)
  1231. fileCnt-1 -
  1232. #endif
  1233. i
  1234. );
  1235. if (card.filenameIsDir)
  1236. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1237. else
  1238. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1239. }
  1240. else {
  1241. MENU_ITEM_DUMMY();
  1242. }
  1243. }
  1244. END_MENU();
  1245. }
  1246. #endif //SDSUPPORT
  1247. /**
  1248. *
  1249. * Functions for editing single values
  1250. *
  1251. * The "menu_edit_type" macro generates the functions needed to edit a numerical value.
  1252. *
  1253. * For example, menu_edit_type(int, int3, itostr3, 1) expands into these functions:
  1254. *
  1255. * bool _menu_edit_int3();
  1256. * void menu_edit_int3(); // edit int (interactively)
  1257. * void menu_edit_callback_int3(); // edit int (interactively) with callback on completion
  1258. * static void _menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1259. * static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  1260. * static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callback); // edit int with callback
  1261. *
  1262. * You can then use one of the menu macros to present the edit interface:
  1263. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_multiplier, 10, 999)
  1264. *
  1265. * This expands into a more primitive menu item:
  1266. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1267. *
  1268. *
  1269. * Also: MENU_MULTIPLIER_ITEM_EDIT, MENU_ITEM_EDIT_CALLBACK, and MENU_MULTIPLIER_ITEM_EDIT_CALLBACK
  1270. *
  1271. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_multiplier, 10, 999)
  1272. */
  1273. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1274. bool _menu_edit_ ## _name () { \
  1275. ENCODER_DIRECTION_NORMAL(); \
  1276. bool isClicked = LCD_CLICKED; \
  1277. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1278. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1279. if (lcdDrawUpdate) \
  1280. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1281. if (isClicked) { \
  1282. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1283. lcd_goto_previous_menu(); \
  1284. } \
  1285. return isClicked; \
  1286. } \
  1287. void menu_edit_ ## _name () { _menu_edit_ ## _name(); } \
  1288. void menu_edit_callback_ ## _name () { if (_menu_edit_ ## _name ()) (*callbackFunc)(); } \
  1289. static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1290. lcd_save_previous_menu(); \
  1291. \
  1292. lcdDrawUpdate = 2; \
  1293. currentMenu = menu_edit_ ## _name; \
  1294. \
  1295. editLabel = pstr; \
  1296. editValue = ptr; \
  1297. minEditValue = minValue * scale; \
  1298. maxEditValue = maxValue * scale - minEditValue; \
  1299. encoderPosition = (*ptr) * scale - minEditValue; \
  1300. } \
  1301. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  1302. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1303. currentMenu = menu_edit_ ## _name; \
  1304. }\
  1305. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) { \
  1306. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  1307. currentMenu = menu_edit_callback_ ## _name; \
  1308. callbackFunc = callback; \
  1309. }
  1310. menu_edit_type(int, int3, itostr3, 1)
  1311. menu_edit_type(float, float3, ftostr3, 1)
  1312. menu_edit_type(float, float32, ftostr32, 100)
  1313. menu_edit_type(float, float43, ftostr43, 1000)
  1314. menu_edit_type(float, float5, ftostr5, 0.01)
  1315. menu_edit_type(float, float51, ftostr51, 10)
  1316. menu_edit_type(float, float52, ftostr52, 100)
  1317. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1318. /**
  1319. *
  1320. * Handlers for RepRap World Keypad input
  1321. *
  1322. */
  1323. #if ENABLED(REPRAPWORLD_KEYPAD)
  1324. static void reprapworld_keypad_move_z_up() {
  1325. encoderPosition = 1;
  1326. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1327. lcd_move_z();
  1328. }
  1329. static void reprapworld_keypad_move_z_down() {
  1330. encoderPosition = -1;
  1331. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1332. lcd_move_z();
  1333. }
  1334. static void reprapworld_keypad_move_x_left() {
  1335. encoderPosition = -1;
  1336. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1337. lcd_move_x();
  1338. }
  1339. static void reprapworld_keypad_move_x_right() {
  1340. encoderPosition = 1;
  1341. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1342. lcd_move_x();
  1343. }
  1344. static void reprapworld_keypad_move_y_down() {
  1345. encoderPosition = 1;
  1346. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1347. lcd_move_y();
  1348. }
  1349. static void reprapworld_keypad_move_y_up() {
  1350. encoderPosition = -1;
  1351. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1352. lcd_move_y();
  1353. }
  1354. static void reprapworld_keypad_move_home() {
  1355. enqueuecommands_P((PSTR("G28"))); // move all axis home
  1356. }
  1357. #endif // REPRAPWORLD_KEYPAD
  1358. /**
  1359. *
  1360. * Audio feedback for controller clicks
  1361. *
  1362. */
  1363. #if ENABLED(LCD_USE_I2C_BUZZER)
  1364. void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
  1365. lcd.buzz(duration, freq);
  1366. }
  1367. #endif
  1368. void lcd_quick_feedback() {
  1369. lcdDrawUpdate = 2;
  1370. next_button_update_ms = millis() + 500;
  1371. #if ENABLED(LCD_USE_I2C_BUZZER)
  1372. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1373. #define LCD_FEEDBACK_FREQUENCY_HZ 100
  1374. #endif
  1375. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1376. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
  1377. #endif
  1378. lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1379. #elif PIN_EXISTS(BEEPER)
  1380. #ifndef LCD_FEEDBACK_FREQUENCY_HZ
  1381. #define LCD_FEEDBACK_FREQUENCY_HZ 5000
  1382. #endif
  1383. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1384. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1385. #endif
  1386. buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  1387. #else
  1388. #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
  1389. #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
  1390. #endif
  1391. delay(LCD_FEEDBACK_FREQUENCY_DURATION_MS);
  1392. #endif
  1393. }
  1394. /**
  1395. *
  1396. * Menu actions
  1397. *
  1398. */
  1399. static void menu_action_back(menuFunc_t func) { lcd_goto_menu(func); }
  1400. static void menu_action_submenu(menuFunc_t func) { lcd_save_previous_menu(); lcd_goto_menu(func); }
  1401. static void menu_action_gcode(const char* pgcode) { enqueuecommands_P(pgcode); }
  1402. static void menu_action_function(menuFunc_t func) { (*func)(); }
  1403. #if ENABLED(SDSUPPORT)
  1404. static void menu_action_sdfile(const char* filename, char* longFilename) {
  1405. char cmd[30];
  1406. char* c;
  1407. sprintf_P(cmd, PSTR("M23 %s"), filename);
  1408. for (c = &cmd[4]; *c; c++) *c = tolower(*c);
  1409. enqueuecommand(cmd);
  1410. enqueuecommands_P(PSTR("M24"));
  1411. lcd_return_to_status();
  1412. }
  1413. static void menu_action_sddirectory(const char* filename, char* longFilename) {
  1414. card.chdir(filename);
  1415. encoderPosition = 0;
  1416. }
  1417. #endif //SDSUPPORT
  1418. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { *ptr = !(*ptr); }
  1419. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback) {
  1420. menu_action_setting_edit_bool(pstr, ptr);
  1421. (*callback)();
  1422. }
  1423. #endif //ULTIPANEL
  1424. /** LCD API **/
  1425. void lcd_init() {
  1426. lcd_implementation_init();
  1427. #if ENABLED(NEWPANEL)
  1428. #if BTN_EN1 > 0
  1429. SET_INPUT(BTN_EN1);
  1430. WRITE(BTN_EN1, HIGH);
  1431. #endif
  1432. #if BTN_EN2 > 0
  1433. SET_INPUT(BTN_EN2);
  1434. WRITE(BTN_EN2, HIGH);
  1435. #endif
  1436. #if BTN_ENC > 0
  1437. SET_INPUT(BTN_ENC);
  1438. WRITE(BTN_ENC, HIGH);
  1439. #endif
  1440. #if ENABLED(REPRAPWORLD_KEYPAD)
  1441. pinMode(SHIFT_CLK, OUTPUT);
  1442. pinMode(SHIFT_LD, OUTPUT);
  1443. pinMode(SHIFT_OUT, INPUT);
  1444. WRITE(SHIFT_OUT, HIGH);
  1445. WRITE(SHIFT_LD, HIGH);
  1446. #endif
  1447. #ifdef RIGIDBOT_PANEL
  1448. SET_INPUT(BTN_UP);
  1449. SET_INPUT(BTN_DWN);
  1450. SET_INPUT(BTN_LFT);
  1451. SET_INPUT(BTN_RT);
  1452. #endif
  1453. #else // Not NEWPANEL
  1454. #if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
  1455. pinMode(SR_DATA_PIN, OUTPUT);
  1456. pinMode(SR_CLK_PIN, OUTPUT);
  1457. #elif defined(SHIFT_CLK)
  1458. pinMode(SHIFT_CLK, OUTPUT);
  1459. pinMode(SHIFT_LD, OUTPUT);
  1460. pinMode(SHIFT_EN, OUTPUT);
  1461. pinMode(SHIFT_OUT, INPUT);
  1462. WRITE(SHIFT_OUT, HIGH);
  1463. WRITE(SHIFT_LD, HIGH);
  1464. WRITE(SHIFT_EN, LOW);
  1465. #endif // SR_LCD_2W_NL
  1466. #endif//!NEWPANEL
  1467. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1468. SET_INPUT(SD_DETECT_PIN);
  1469. WRITE(SD_DETECT_PIN, HIGH);
  1470. lcd_sd_status = 2; // UNKNOWN
  1471. #endif
  1472. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1473. slow_buttons = 0;
  1474. #endif
  1475. lcd_buttons_update();
  1476. #if ENABLED(ULTIPANEL)
  1477. encoderDiff = 0;
  1478. #endif
  1479. }
  1480. int lcd_strlen(char* s) {
  1481. int i = 0, j = 0;
  1482. while (s[i]) {
  1483. if ((s[i] & 0xc0) != 0x80) j++;
  1484. i++;
  1485. }
  1486. return j;
  1487. }
  1488. int lcd_strlen_P(const char* s) {
  1489. int j = 0;
  1490. while (pgm_read_byte(s)) {
  1491. if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
  1492. s++;
  1493. }
  1494. return j;
  1495. }
  1496. /**
  1497. * Update the LCD, read encoder buttons, etc.
  1498. * - Read button states
  1499. * - Check the SD Card slot state
  1500. * - Act on RepRap World keypad input
  1501. * - Update the encoder position
  1502. * - Apply acceleration to the encoder position
  1503. * - Reset the Info Screen timeout if there's any input
  1504. * - Update status indicators, if any
  1505. * - Clear the LCD if lcdDrawUpdate == 2
  1506. *
  1507. * Warning: This function is called from interrupt context!
  1508. */
  1509. void lcd_update() {
  1510. #if ENABLED(ULTIPANEL)
  1511. static millis_t return_to_status_ms = 0;
  1512. #endif
  1513. lcd_buttons_update();
  1514. #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
  1515. bool sd_status = IS_SD_INSERTED;
  1516. if (sd_status != lcd_sd_status && lcd_detected()) {
  1517. lcdDrawUpdate = 2;
  1518. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1519. #if ENABLED(LCD_PROGRESS_BAR)
  1520. currentMenu == lcd_status_screen
  1521. #endif
  1522. );
  1523. if (sd_status) {
  1524. card.initsd();
  1525. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1526. }
  1527. else {
  1528. card.release();
  1529. if (lcd_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1530. }
  1531. lcd_sd_status = sd_status;
  1532. }
  1533. #endif //SDSUPPORT && SD_DETECT_PIN
  1534. millis_t ms = millis();
  1535. if (ms > next_lcd_update_ms) {
  1536. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1537. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1538. #endif
  1539. #if ENABLED(ULTIPANEL)
  1540. #if ENABLED(REPRAPWORLD_KEYPAD)
  1541. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  1542. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  1543. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  1544. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  1545. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  1546. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  1547. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  1548. #endif
  1549. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  1550. if (encoderPastThreshold || LCD_CLICKED) {
  1551. if (encoderPastThreshold) {
  1552. int32_t encoderMultiplier = 1;
  1553. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  1554. if (encoderRateMultiplierEnabled) {
  1555. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  1556. if (lastEncoderMovementMillis != 0) {
  1557. // Note that the rate is always calculated between to passes through the
  1558. // loop and that the abs of the encoderDiff value is tracked.
  1559. float encoderStepRate = (float)(encoderMovementSteps) / ((float)(ms - lastEncoderMovementMillis)) * 1000.0;
  1560. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
  1561. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
  1562. #if ENABLED(ENCODER_RATE_MULTIPLIER_DEBUG)
  1563. SERIAL_ECHO_START;
  1564. SERIAL_ECHO("Enc Step Rate: ");
  1565. SERIAL_ECHO(encoderStepRate);
  1566. SERIAL_ECHO(" Multiplier: ");
  1567. SERIAL_ECHO(encoderMultiplier);
  1568. SERIAL_ECHO(" ENCODER_10X_STEPS_PER_SEC: ");
  1569. SERIAL_ECHO(ENCODER_10X_STEPS_PER_SEC);
  1570. SERIAL_ECHO(" ENCODER_100X_STEPS_PER_SEC: ");
  1571. SERIAL_ECHOLN(ENCODER_100X_STEPS_PER_SEC);
  1572. #endif //ENCODER_RATE_MULTIPLIER_DEBUG
  1573. }
  1574. lastEncoderMovementMillis = ms;
  1575. } // encoderRateMultiplierEnabled
  1576. #endif //ENCODER_RATE_MULTIPLIER
  1577. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  1578. encoderDiff = 0;
  1579. }
  1580. return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
  1581. lcdDrawUpdate = 1;
  1582. }
  1583. #endif //ULTIPANEL
  1584. if (currentMenu == lcd_status_screen) {
  1585. if (!lcd_status_update_delay) {
  1586. lcdDrawUpdate = 1;
  1587. lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
  1588. }
  1589. else {
  1590. lcd_status_update_delay--;
  1591. }
  1592. }
  1593. #if ENABLED(DOGLCD) // Changes due to different driver architecture of the DOGM display
  1594. if (lcdDrawUpdate) {
  1595. blink++; // Variable for animation and alive dot
  1596. u8g.firstPage();
  1597. do {
  1598. lcd_setFont(FONT_MENU);
  1599. u8g.setPrintPos(125, 0);
  1600. if (blink & 1) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1601. u8g.drawPixel(127, 63); // draw alive dot
  1602. u8g.setColorIndex(1); // black on white
  1603. (*currentMenu)();
  1604. } while (u8g.nextPage());
  1605. }
  1606. #else
  1607. if (lcdDrawUpdate) {
  1608. blink++; // Variable for animation
  1609. (*currentMenu)();
  1610. }
  1611. #endif
  1612. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  1613. lcd_implementation_update_indicators();
  1614. #endif
  1615. #if ENABLED(ULTIPANEL)
  1616. // Return to Status Screen after a timeout
  1617. if (currentMenu != lcd_status_screen &&
  1618. #if ENABLED(MANUAL_BED_LEVELING)
  1619. currentMenu != _lcd_level_bed &&
  1620. currentMenu != _lcd_level_bed_homing &&
  1621. #endif
  1622. millis() > return_to_status_ms
  1623. ) {
  1624. lcd_return_to_status();
  1625. lcdDrawUpdate = 2;
  1626. }
  1627. #endif // ULTIPANEL
  1628. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1629. if (lcdDrawUpdate) lcdDrawUpdate--;
  1630. next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL;
  1631. }
  1632. }
  1633. void lcd_ignore_click(bool b) {
  1634. ignore_click = b;
  1635. wait_for_unclick = false;
  1636. }
  1637. void lcd_finishstatus(bool persist=false) {
  1638. #if ENABLED(LCD_PROGRESS_BAR)
  1639. progress_bar_ms = millis();
  1640. #if PROGRESS_MSG_EXPIRE > 0
  1641. expire_status_ms = persist ? 0 : progress_bar_ms + PROGRESS_MSG_EXPIRE;
  1642. #endif
  1643. #endif
  1644. lcdDrawUpdate = 2;
  1645. #if ENABLED(FILAMENT_LCD_DISPLAY)
  1646. previous_lcd_status_ms = millis(); //get status message to show up for a while
  1647. #endif
  1648. }
  1649. #if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
  1650. void dontExpireStatus() { expire_status_ms = 0; }
  1651. #endif
  1652. void set_utf_strlen(char* s, uint8_t n) {
  1653. uint8_t i = 0, j = 0;
  1654. while (s[i] && (j < n)) {
  1655. if ((s[i] & 0xc0u) != 0x80u) j++;
  1656. i++;
  1657. }
  1658. while (j++ < n) s[i++] = ' ';
  1659. s[i] = 0;
  1660. }
  1661. bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
  1662. void lcd_setstatus(const char* message, bool persist) {
  1663. if (lcd_status_message_level > 0) return;
  1664. strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
  1665. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1666. lcd_finishstatus(persist);
  1667. }
  1668. void lcd_setstatuspgm(const char* message, uint8_t level) {
  1669. if (level >= lcd_status_message_level) {
  1670. strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
  1671. set_utf_strlen(lcd_status_message, LCD_WIDTH);
  1672. lcd_status_message_level = level;
  1673. lcd_finishstatus(level > 0);
  1674. }
  1675. }
  1676. void lcd_setalertstatuspgm(const char* message) {
  1677. lcd_setstatuspgm(message, 1);
  1678. #if ENABLED(ULTIPANEL)
  1679. lcd_return_to_status();
  1680. #endif
  1681. }
  1682. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  1683. #if ENABLED(HAS_LCD_CONTRAST)
  1684. void lcd_setcontrast(uint8_t value) {
  1685. lcd_contrast = value & 0x3F;
  1686. u8g.setContrast(lcd_contrast);
  1687. }
  1688. #endif
  1689. #if ENABLED(ULTIPANEL)
  1690. /**
  1691. * Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
  1692. * These values are independent of which pins are used for EN_A and EN_B indications
  1693. * The rotary encoder part is also independent to the chipset used for the LCD
  1694. */
  1695. #if defined(EN_A) && defined(EN_B)
  1696. #define encrot0 0
  1697. #define encrot1 2
  1698. #define encrot2 3
  1699. #define encrot3 1
  1700. #endif
  1701. /**
  1702. * Read encoder buttons from the hardware registers
  1703. * Warning: This function is called from interrupt context!
  1704. */
  1705. void lcd_buttons_update() {
  1706. #if ENABLED(NEWPANEL)
  1707. uint8_t newbutton = 0;
  1708. #if BTN_EN1 > 0
  1709. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  1710. #endif
  1711. #if BTN_EN2 > 0
  1712. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  1713. #endif
  1714. #if ENABLED(RIGIDBOT_PANEL) || BTN_ENC > 0
  1715. millis_t now = millis();
  1716. #endif
  1717. #if ENABLED(RIGIDBOT_PANEL)
  1718. if (now > next_button_update_ms) {
  1719. if (READ(BTN_UP) == 0) {
  1720. encoderDiff = -1 * (ENCODER_STEPS_PER_MENU_ITEM);
  1721. next_button_update_ms = now + 300;
  1722. }
  1723. else if (READ(BTN_DWN) == 0) {
  1724. encoderDiff = ENCODER_STEPS_PER_MENU_ITEM;
  1725. next_button_update_ms = now + 300;
  1726. }
  1727. else if (READ(BTN_LFT) == 0) {
  1728. encoderDiff = -1 * (ENCODER_PULSES_PER_STEP);
  1729. next_button_update_ms = now + 300;
  1730. }
  1731. else if (READ(BTN_RT) == 0) {
  1732. encoderDiff = ENCODER_PULSES_PER_STEP;
  1733. next_button_update_ms = now + 300;
  1734. }
  1735. }
  1736. #endif
  1737. #if BTN_ENC > 0
  1738. if (now > next_button_update_ms && READ(BTN_ENC) == 0) newbutton |= EN_C;
  1739. #endif
  1740. buttons = newbutton;
  1741. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  1742. buttons |= slow_buttons;
  1743. #endif
  1744. #if ENABLED(REPRAPWORLD_KEYPAD)
  1745. // for the reprapworld_keypad
  1746. uint8_t newbutton_reprapworld_keypad = 0;
  1747. WRITE(SHIFT_LD, LOW);
  1748. WRITE(SHIFT_LD, HIGH);
  1749. for (int8_t i = 0; i < 8; i++) {
  1750. newbutton_reprapworld_keypad >>= 1;
  1751. if (READ(SHIFT_OUT)) SBI(newbutton_reprapworld_keypad, 7);
  1752. WRITE(SHIFT_CLK, HIGH);
  1753. WRITE(SHIFT_CLK, LOW);
  1754. }
  1755. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1756. #endif
  1757. #else //read it from the shift register
  1758. uint8_t newbutton = 0;
  1759. WRITE(SHIFT_LD, LOW);
  1760. WRITE(SHIFT_LD, HIGH);
  1761. unsigned char tmp_buttons = 0;
  1762. for (int8_t i = 0; i < 8; i++) {
  1763. newbutton >>= 1;
  1764. if (READ(SHIFT_OUT)) SBI(newbutton, 7);
  1765. WRITE(SHIFT_CLK, HIGH);
  1766. WRITE(SHIFT_CLK, LOW);
  1767. }
  1768. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  1769. #endif //!NEWPANEL
  1770. #if ENABLED(REVERSE_MENU_DIRECTION)
  1771. #define ENCODER_DIFF_CW (encoderDiff += encoderDirection)
  1772. #define ENCODER_DIFF_CCW (encoderDiff -= encoderDirection)
  1773. #else
  1774. #define ENCODER_DIFF_CW (encoderDiff++)
  1775. #define ENCODER_DIFF_CCW (encoderDiff--)
  1776. #endif
  1777. #define ENCODER_SPIN(_E1, _E2) switch (lastEncoderBits) { case _E1: ENCODER_DIFF_CW; break; case _E2: ENCODER_DIFF_CCW; }
  1778. //manage encoder rotation
  1779. uint8_t enc = 0;
  1780. if (buttons & EN_A) enc |= B01;
  1781. if (buttons & EN_B) enc |= B10;
  1782. if (enc != lastEncoderBits) {
  1783. switch (enc) {
  1784. case encrot0: ENCODER_SPIN(encrot3, encrot1); break;
  1785. case encrot1: ENCODER_SPIN(encrot0, encrot2); break;
  1786. case encrot2: ENCODER_SPIN(encrot1, encrot3); break;
  1787. case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
  1788. }
  1789. }
  1790. lastEncoderBits = enc;
  1791. }
  1792. bool lcd_detected(void) {
  1793. #if (ENABLED(LCD_I2C_TYPE_MCP23017) || ENABLED(LCD_I2C_TYPE_MCP23008)) && ENABLED(DETECT_DEVICE)
  1794. return lcd.LcdDetected() == 1;
  1795. #else
  1796. return true;
  1797. #endif
  1798. }
  1799. bool lcd_clicked() { return LCD_CLICKED; }
  1800. #endif // ULTIPANEL
  1801. /*********************************/
  1802. /** Number to string conversion **/
  1803. /*********************************/
  1804. char conv[8];
  1805. // Convert float to rj string with 123 or -12 format
  1806. char *ftostr3(const float& x) { return itostr3((int)x); }
  1807. // Convert float to rj string with _123, -123, _-12, or __-1 format
  1808. char *ftostr4sign(const float& x) { return itostr4sign((int)x); }
  1809. // Convert int to string with 12 format
  1810. char* itostr2(const uint8_t& x) {
  1811. //sprintf(conv,"%5.1f",x);
  1812. int xx = x;
  1813. conv[0] = (xx / 10) % 10 + '0';
  1814. conv[1] = xx % 10 + '0';
  1815. conv[2] = 0;
  1816. return conv;
  1817. }
  1818. // Convert float to string with +123.4 format
  1819. char* ftostr31(const float& x) {
  1820. int xx = abs(x * 10);
  1821. conv[0] = (x >= 0) ? '+' : '-';
  1822. conv[1] = (xx / 1000) % 10 + '0';
  1823. conv[2] = (xx / 100) % 10 + '0';
  1824. conv[3] = (xx / 10) % 10 + '0';
  1825. conv[4] = '.';
  1826. conv[5] = xx % 10 + '0';
  1827. conv[6] = 0;
  1828. return conv;
  1829. }
  1830. // Convert float to string with 123.4 format, dropping sign
  1831. char* ftostr31ns(const float& x) {
  1832. int xx = abs(x * 10);
  1833. conv[0] = (xx / 1000) % 10 + '0';
  1834. conv[1] = (xx / 100) % 10 + '0';
  1835. conv[2] = (xx / 10) % 10 + '0';
  1836. conv[3] = '.';
  1837. conv[4] = xx % 10 + '0';
  1838. conv[5] = 0;
  1839. return conv;
  1840. }
  1841. // Convert float to string with 123.45 format
  1842. char *ftostr32(const float& x) {
  1843. long xx = abs(x * 100);
  1844. conv[0] = x >= 0 ? (xx / 10000) % 10 + '0' : '-';
  1845. conv[1] = (xx / 1000) % 10 + '0';
  1846. conv[2] = (xx / 100) % 10 + '0';
  1847. conv[3] = '.';
  1848. conv[4] = (xx / 10) % 10 + '0';
  1849. conv[5] = xx % 10 + '0';
  1850. conv[6] = 0;
  1851. return conv;
  1852. }
  1853. // Convert float to string with 1.234 format
  1854. char* ftostr43(const float& x) {
  1855. long xx = x * 1000;
  1856. if (xx >= 0)
  1857. conv[0] = (xx / 1000) % 10 + '0';
  1858. else
  1859. conv[0] = '-';
  1860. xx = abs(xx);
  1861. conv[1] = '.';
  1862. conv[2] = (xx / 100) % 10 + '0';
  1863. conv[3] = (xx / 10) % 10 + '0';
  1864. conv[4] = (xx) % 10 + '0';
  1865. conv[5] = 0;
  1866. return conv;
  1867. }
  1868. // Convert float to string with 1.23 format
  1869. char* ftostr12ns(const float& x) {
  1870. long xx = x * 100;
  1871. xx = abs(xx);
  1872. conv[0] = (xx / 100) % 10 + '0';
  1873. conv[1] = '.';
  1874. conv[2] = (xx / 10) % 10 + '0';
  1875. conv[3] = (xx) % 10 + '0';
  1876. conv[4] = 0;
  1877. return conv;
  1878. }
  1879. // Convert float to space-padded string with -_23.4_ format
  1880. char* ftostr32sp(const float& x) {
  1881. long xx = abs(x * 100);
  1882. uint8_t dig;
  1883. if (x < 0) { // negative val = -_0
  1884. conv[0] = '-';
  1885. dig = (xx / 1000) % 10;
  1886. conv[1] = dig ? '0' + dig : ' ';
  1887. }
  1888. else { // positive val = __0
  1889. dig = (xx / 10000) % 10;
  1890. if (dig) {
  1891. conv[0] = '0' + dig;
  1892. conv[1] = '0' + (xx / 1000) % 10;
  1893. }
  1894. else {
  1895. conv[0] = ' ';
  1896. dig = (xx / 1000) % 10;
  1897. conv[1] = dig ? '0' + dig : ' ';
  1898. }
  1899. }
  1900. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1901. dig = xx % 10;
  1902. if (dig) { // 2 decimal places
  1903. conv[5] = '0' + dig;
  1904. conv[4] = '0' + (xx / 10) % 10;
  1905. conv[3] = '.';
  1906. }
  1907. else { // 1 or 0 decimal place
  1908. dig = (xx / 10) % 10;
  1909. if (dig) {
  1910. conv[4] = '0' + dig;
  1911. conv[3] = '.';
  1912. }
  1913. else {
  1914. conv[3] = conv[4] = ' ';
  1915. }
  1916. conv[5] = ' ';
  1917. }
  1918. conv[6] = '\0';
  1919. return conv;
  1920. }
  1921. // Convert int to lj string with +123.0 format
  1922. char* itostr31(const int& x) {
  1923. conv[0] = x >= 0 ? '+' : '-';
  1924. int xx = abs(x);
  1925. conv[1] = (xx / 100) % 10 + '0';
  1926. conv[2] = (xx / 10) % 10 + '0';
  1927. conv[3] = xx % 10 + '0';
  1928. conv[4] = '.';
  1929. conv[5] = '0';
  1930. conv[6] = 0;
  1931. return conv;
  1932. }
  1933. // Convert int to rj string with 123 or -12 format
  1934. char* itostr3(const int& x) {
  1935. int xx = x;
  1936. if (xx < 0) {
  1937. conv[0] = '-';
  1938. xx = -xx;
  1939. }
  1940. else
  1941. conv[0] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1942. conv[1] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1943. conv[2] = xx % 10 + '0';
  1944. conv[3] = 0;
  1945. return conv;
  1946. }
  1947. // Convert int to lj string with 123 format
  1948. char* itostr3left(const int& xx) {
  1949. if (xx >= 100) {
  1950. conv[0] = (xx / 100) % 10 + '0';
  1951. conv[1] = (xx / 10) % 10 + '0';
  1952. conv[2] = xx % 10 + '0';
  1953. conv[3] = 0;
  1954. }
  1955. else if (xx >= 10) {
  1956. conv[0] = (xx / 10) % 10 + '0';
  1957. conv[1] = xx % 10 + '0';
  1958. conv[2] = 0;
  1959. }
  1960. else {
  1961. conv[0] = xx % 10 + '0';
  1962. conv[1] = 0;
  1963. }
  1964. return conv;
  1965. }
  1966. // Convert int to rj string with 1234 format
  1967. char* itostr4(const int& xx) {
  1968. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1969. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1970. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1971. conv[3] = xx % 10 + '0';
  1972. conv[4] = 0;
  1973. return conv;
  1974. }
  1975. // Convert int to rj string with _123, -123, _-12, or __-1 format
  1976. char *itostr4sign(const int& x) {
  1977. int xx = abs(x);
  1978. int sign = 0;
  1979. if (xx >= 100) {
  1980. conv[1] = (xx / 100) % 10 + '0';
  1981. conv[2] = (xx / 10) % 10 + '0';
  1982. }
  1983. else if (xx >= 10) {
  1984. conv[0] = ' ';
  1985. sign = 1;
  1986. conv[2] = (xx / 10) % 10 + '0';
  1987. }
  1988. else {
  1989. conv[0] = ' ';
  1990. conv[1] = ' ';
  1991. sign = 2;
  1992. }
  1993. conv[sign] = x < 0 ? '-' : ' ';
  1994. conv[3] = xx % 10 + '0';
  1995. conv[4] = 0;
  1996. return conv;
  1997. }
  1998. // Convert float to rj string with 12345 format
  1999. char* ftostr5(const float& x) {
  2000. long xx = abs(x);
  2001. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2002. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2003. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2004. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2005. conv[4] = xx % 10 + '0';
  2006. conv[5] = 0;
  2007. return conv;
  2008. }
  2009. // Convert float to string with +1234.5 format
  2010. char* ftostr51(const float& x) {
  2011. long xx = abs(x * 10);
  2012. conv[0] = (x >= 0) ? '+' : '-';
  2013. conv[1] = (xx / 10000) % 10 + '0';
  2014. conv[2] = (xx / 1000) % 10 + '0';
  2015. conv[3] = (xx / 100) % 10 + '0';
  2016. conv[4] = (xx / 10) % 10 + '0';
  2017. conv[5] = '.';
  2018. conv[6] = xx % 10 + '0';
  2019. conv[7] = 0;
  2020. return conv;
  2021. }
  2022. // Convert float to string with +123.45 format
  2023. char* ftostr52(const float& x) {
  2024. conv[0] = (x >= 0) ? '+' : '-';
  2025. long xx = abs(x * 100);
  2026. conv[1] = (xx / 10000) % 10 + '0';
  2027. conv[2] = (xx / 1000) % 10 + '0';
  2028. conv[3] = (xx / 100) % 10 + '0';
  2029. conv[4] = '.';
  2030. conv[5] = (xx / 10) % 10 + '0';
  2031. conv[6] = xx % 10 + '0';
  2032. conv[7] = 0;
  2033. return conv;
  2034. }
  2035. #if ENABLED(MANUAL_BED_LEVELING)
  2036. static int _lcd_level_bed_position;
  2037. /**
  2038. * MBL Wait for controller movement and clicks:
  2039. * - Movement adjusts the Z axis
  2040. * - Click saves the Z and goes to the next mesh point
  2041. */
  2042. static void _lcd_level_bed() {
  2043. ENCODER_DIRECTION_NORMAL();
  2044. if ((encoderPosition != 0) && (movesplanned() <= 3)) {
  2045. refresh_cmd_timeout();
  2046. current_position[Z_AXIS] += float((int)encoderPosition) * (MBL_Z_STEP);
  2047. if (min_software_endstops) NOLESS(current_position[Z_AXIS], Z_MIN_POS);
  2048. if (max_software_endstops) NOMORE(current_position[Z_AXIS], Z_MAX_POS);
  2049. encoderPosition = 0;
  2050. line_to_current(Z_AXIS);
  2051. lcdDrawUpdate = 2;
  2052. }
  2053. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr43(current_position[Z_AXIS]));
  2054. static bool debounce_click = false;
  2055. if (LCD_CLICKED) {
  2056. if (!debounce_click) {
  2057. debounce_click = true;
  2058. int ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS),
  2059. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2060. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2061. mbl.set_z(ix, iy, current_position[Z_AXIS]);
  2062. _lcd_level_bed_position++;
  2063. if (_lcd_level_bed_position == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
  2064. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2065. line_to_current(Z_AXIS);
  2066. mbl.active = 1;
  2067. enqueuecommands_P(PSTR("G28"));
  2068. lcd_return_to_status();
  2069. }
  2070. else {
  2071. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2072. line_to_current(Z_AXIS);
  2073. ix = _lcd_level_bed_position % (MESH_NUM_X_POINTS);
  2074. iy = _lcd_level_bed_position / (MESH_NUM_X_POINTS);
  2075. if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // Zig zag
  2076. current_position[X_AXIS] = mbl.get_x(ix);
  2077. current_position[Y_AXIS] = mbl.get_y(iy);
  2078. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2079. lcdDrawUpdate = 2;
  2080. }
  2081. }
  2082. }
  2083. else {
  2084. debounce_click = false;
  2085. }
  2086. }
  2087. /**
  2088. * MBL Move to mesh starting point
  2089. */
  2090. static void _lcd_level_bed_homing() {
  2091. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("XYZ"), "Homing");
  2092. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]) {
  2093. current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
  2094. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2095. current_position[X_AXIS] = MESH_MIN_X;
  2096. current_position[Y_AXIS] = MESH_MIN_Y;
  2097. line_to_current(manual_feedrate[X_AXIS] <= manual_feedrate[Y_AXIS] ? X_AXIS : Y_AXIS);
  2098. _lcd_level_bed_position = 0;
  2099. lcd_goto_menu(_lcd_level_bed);
  2100. }
  2101. lcdDrawUpdate = 2;
  2102. }
  2103. /**
  2104. * MBL entry-point
  2105. */
  2106. static void lcd_level_bed() {
  2107. axis_known_position[X_AXIS] = axis_known_position[Y_AXIS] = axis_known_position[Z_AXIS] = false;
  2108. mbl.reset();
  2109. enqueuecommands_P(PSTR("G28"));
  2110. lcdDrawUpdate = 2;
  2111. lcd_goto_menu(_lcd_level_bed_homing);
  2112. }
  2113. #endif // MANUAL_BED_LEVELING
  2114. #endif // ULTRA_LCD