My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ultralcd.cpp 59KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #ifdef ULTRA_LCD
  4. #include "Marlin.h"
  5. #include "language.h"
  6. #include "cardreader.h"
  7. #include "temperature.h"
  8. #include "stepper.h"
  9. #include "ConfigurationStore.h"
  10. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  11. bool encoderRateMultiplierEnabled;
  12. int32_t lastEncoderMovementMillis;
  13. /* Configuration settings */
  14. int plaPreheatHotendTemp;
  15. int plaPreheatHPBTemp;
  16. int plaPreheatFanSpeed;
  17. int absPreheatHotendTemp;
  18. int absPreheatHPBTemp;
  19. int absPreheatFanSpeed;
  20. #ifdef FILAMENT_LCD_DISPLAY
  21. unsigned long message_millis = 0;
  22. #endif
  23. #ifdef ULTIPANEL
  24. static float manual_feedrate[] = MANUAL_FEEDRATE;
  25. #endif // ULTIPANEL
  26. /* !Configuration settings */
  27. //Function pointer to menu functions.
  28. typedef void (*menuFunc_t)();
  29. uint8_t lcd_status_message_level;
  30. char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
  31. #ifdef DOGLCD
  32. #include "dogm_lcd_implementation.h"
  33. #else
  34. #include "ultralcd_implementation_hitachi_HD44780.h"
  35. #endif
  36. /** forward declarations **/
  37. void copy_and_scalePID_i();
  38. void copy_and_scalePID_d();
  39. /* Different menus */
  40. static void lcd_status_screen();
  41. #ifdef ULTIPANEL
  42. extern bool powersupply;
  43. static void lcd_main_menu();
  44. static void lcd_tune_menu();
  45. static void lcd_prepare_menu();
  46. static void lcd_move_menu();
  47. static void lcd_control_menu();
  48. static void lcd_control_temperature_menu();
  49. static void lcd_control_temperature_preheat_pla_settings_menu();
  50. static void lcd_control_temperature_preheat_abs_settings_menu();
  51. static void lcd_control_motion_menu();
  52. static void lcd_control_volumetric_menu();
  53. #ifdef DOGLCD
  54. static void lcd_set_contrast();
  55. #endif
  56. static void lcd_control_retract_menu();
  57. static void lcd_sdcard_menu();
  58. #ifdef DELTA_CALIBRATION_MENU
  59. static void lcd_delta_calibrate_menu();
  60. #endif // DELTA_CALIBRATION_MENU
  61. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  62. /* Different types of actions that can be used in menu items. */
  63. static void menu_action_back(menuFunc_t data);
  64. static void menu_action_submenu(menuFunc_t data);
  65. static void menu_action_gcode(const char* pgcode);
  66. static void menu_action_function(menuFunc_t data);
  67. static void menu_action_sdfile(const char* filename, char* longFilename);
  68. static void menu_action_sddirectory(const char* filename, char* longFilename);
  69. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  70. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  71. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  72. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  73. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  74. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  75. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  76. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  77. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  78. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  79. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  80. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  81. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  82. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  83. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  84. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  85. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  86. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  87. #define ENCODER_FEEDRATE_DEADZONE 10
  88. #if !defined(LCD_I2C_VIKI)
  89. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  90. #define ENCODER_STEPS_PER_MENU_ITEM 5
  91. #endif
  92. #ifndef ENCODER_PULSES_PER_STEP
  93. #define ENCODER_PULSES_PER_STEP 1
  94. #endif
  95. #else
  96. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  97. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  98. #endif
  99. #ifndef ENCODER_PULSES_PER_STEP
  100. #define ENCODER_PULSES_PER_STEP 1
  101. #endif
  102. #endif
  103. /* Helper macros for menus */
  104. #define START_MENU() do { \
  105. encoderRateMultiplierEnabled = false; \
  106. if (encoderPosition > 0x8000) encoderPosition = 0; \
  107. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  108. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  109. bool wasClicked = LCD_CLICKED;\
  110. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  111. _menuItemNr = 0;
  112. #define MENU_ITEM(type, label, args...) do { \
  113. if (_menuItemNr == _lineNr) { \
  114. if (lcdDrawUpdate) { \
  115. const char* _label_pstr = PSTR(label); \
  116. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  117. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  118. }else{\
  119. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  120. }\
  121. }\
  122. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  123. lcd_quick_feedback(); \
  124. menu_action_ ## type ( args ); \
  125. return;\
  126. }\
  127. }\
  128. _menuItemNr++;\
  129. } while(0)
  130. #ifdef ENCODER_RATE_MULTIPLIER
  131. #define MENU_MULTIPLIER_ITEM(type, label, args...) do { \
  132. if (_menuItemNr == _lineNr) { \
  133. if (lcdDrawUpdate) { \
  134. const char* _label_pstr = PSTR(label); \
  135. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  136. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  137. }else{\
  138. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  139. }\
  140. }\
  141. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  142. lcd_quick_feedback(); \
  143. encoderRateMultiplierEnabled = true; \
  144. lastEncoderMovementMillis = 0; \
  145. menu_action_ ## type ( args ); \
  146. return;\
  147. }\
  148. }\
  149. _menuItemNr++;\
  150. } while(0)
  151. #endif
  152. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  153. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  154. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
  155. #ifdef ENCODER_RATE_MULTIPLIER
  156. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  157. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_MULTIPLIER_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
  158. #else
  159. #define MENU_MULTIPLIER_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  160. #define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
  161. #endif
  162. #define END_MENU() \
  163. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  164. if ((uint8_t)(encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) - LCD_HEIGHT + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
  165. } } while(0)
  166. /** Used variables to keep track of the menu */
  167. #ifndef REPRAPWORLD_KEYPAD
  168. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  169. #else
  170. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  171. #endif
  172. #ifdef LCD_HAS_SLOW_BUTTONS
  173. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  174. #endif
  175. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  176. uint32_t blocking_enc;
  177. uint8_t lastEncoderBits;
  178. uint32_t encoderPosition;
  179. #if (SDCARDDETECT > 0)
  180. bool lcd_oldcardstatus;
  181. #endif
  182. #endif //ULTIPANEL
  183. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  184. uint32_t lcd_next_update_millis;
  185. uint8_t lcd_status_update_delay;
  186. bool ignore_click = false;
  187. bool wait_for_unclick;
  188. 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) */
  189. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  190. menuFunc_t prevMenu = NULL;
  191. uint16_t prevEncoderPosition;
  192. //Variables used when editing values.
  193. const char* editLabel;
  194. void* editValue;
  195. int32_t minEditValue, maxEditValue;
  196. menuFunc_t callbackFunc;
  197. // place-holders for Ki and Kd edits, and the extruder # being edited
  198. float raw_Ki, raw_Kd;
  199. int pid_current_extruder;
  200. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
  201. if (currentMenu != menu) {
  202. currentMenu = menu;
  203. encoderPosition = encoder;
  204. if (feedback) lcd_quick_feedback();
  205. // For LCD_PROGRESS_BAR re-initialize the custom characters
  206. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  207. lcd_set_custom_characters(menu == lcd_status_screen);
  208. #endif
  209. }
  210. }
  211. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  212. static void lcd_status_screen()
  213. {
  214. encoderRateMultiplierEnabled = false;
  215. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  216. uint16_t mil = millis();
  217. #ifndef PROGRESS_MSG_ONCE
  218. if (mil > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
  219. progressBarTick = mil;
  220. }
  221. #endif
  222. #if PROGRESS_MSG_EXPIRE > 0
  223. // keep the message alive if paused, count down otherwise
  224. if (messageTick > 0) {
  225. if (card.isFileOpen()) {
  226. if (IS_SD_PRINTING) {
  227. if ((mil-messageTick) >= PROGRESS_MSG_EXPIRE) {
  228. lcd_status_message[0] = '\0';
  229. messageTick = 0;
  230. }
  231. }
  232. else {
  233. messageTick += LCD_UPDATE_INTERVAL;
  234. }
  235. }
  236. else {
  237. messageTick = 0;
  238. }
  239. }
  240. #endif
  241. #endif //LCD_PROGRESS_BAR
  242. if (lcd_status_update_delay)
  243. lcd_status_update_delay--;
  244. else
  245. lcdDrawUpdate = 1;
  246. if (lcdDrawUpdate) {
  247. lcd_implementation_status_screen();
  248. 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 */
  249. }
  250. #ifdef ULTIPANEL
  251. bool current_click = LCD_CLICKED;
  252. if (ignore_click) {
  253. if (wait_for_unclick) {
  254. if (!current_click) {
  255. ignore_click = wait_for_unclick = false;
  256. }
  257. else {
  258. current_click = false;
  259. }
  260. }
  261. else if (current_click) {
  262. lcd_quick_feedback();
  263. wait_for_unclick = true;
  264. current_click = false;
  265. }
  266. }
  267. if (current_click)
  268. {
  269. lcd_goto_menu(lcd_main_menu);
  270. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  271. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  272. currentMenu == lcd_status_screen
  273. #endif
  274. );
  275. #ifdef FILAMENT_LCD_DISPLAY
  276. message_millis = millis(); // get status message to show up for a while
  277. #endif
  278. }
  279. #ifdef ULTIPANEL_FEEDMULTIPLY
  280. // Dead zone at 100% feedrate
  281. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  282. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  283. {
  284. encoderPosition = 0;
  285. feedmultiply = 100;
  286. }
  287. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  288. {
  289. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  290. encoderPosition = 0;
  291. }
  292. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  293. {
  294. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  295. encoderPosition = 0;
  296. }
  297. else if (feedmultiply != 100)
  298. {
  299. feedmultiply += int(encoderPosition);
  300. encoderPosition = 0;
  301. }
  302. #endif //ULTIPANEL_FEEDMULTIPLY
  303. if (feedmultiply < 10)
  304. feedmultiply = 10;
  305. else if (feedmultiply > 999)
  306. feedmultiply = 999;
  307. #endif //ULTIPANEL
  308. }
  309. #ifdef ULTIPANEL
  310. static void lcd_return_to_status() { lcd_goto_menu(lcd_status_screen, 0, false); }
  311. static void lcd_sdcard_pause() { card.pauseSDPrint(); }
  312. static void lcd_sdcard_resume() { card.startFileprint(); }
  313. static void lcd_sdcard_stop()
  314. {
  315. card.sdprinting = false;
  316. card.closefile();
  317. quickStop();
  318. if(SD_FINISHED_STEPPERRELEASE)
  319. {
  320. enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
  321. }
  322. autotempShutdown();
  323. cancel_heatup = true;
  324. lcd_setstatus(MSG_PRINT_ABORTED);
  325. }
  326. /* Menu implementation */
  327. static void lcd_main_menu()
  328. {
  329. START_MENU();
  330. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  331. if (movesplanned() || IS_SD_PRINTING)
  332. {
  333. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  334. }else{
  335. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  336. #ifdef DELTA_CALIBRATION_MENU
  337. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  338. #endif // DELTA_CALIBRATION_MENU
  339. }
  340. /*JFR TEST*/ MENU_ITEM(gcode, "test multiline", PSTR("G4 S3\nM104 S50\nG4 S1\nM104 S200\nG4 S2\nM104 S0")); // SD-card changed by user
  341. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  342. #ifdef SDSUPPORT
  343. if (card.cardOK)
  344. {
  345. if (card.isFileOpen())
  346. {
  347. if (card.sdprinting)
  348. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  349. else
  350. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  351. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  352. }else{
  353. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  354. #if SDCARDDETECT < 1
  355. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  356. #endif
  357. }
  358. }else{
  359. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  360. #if SDCARDDETECT < 1
  361. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  362. #endif
  363. }
  364. #endif
  365. END_MENU();
  366. }
  367. #ifdef SDSUPPORT
  368. static void lcd_autostart_sd()
  369. {
  370. card.autostart_index=0;
  371. card.setroot();
  372. card.checkautostart(true);
  373. }
  374. #endif
  375. void lcd_set_home_offsets()
  376. {
  377. for(int8_t i=0; i < NUM_AXIS; i++) {
  378. if (i != E_AXIS) {
  379. add_homing[i] -= current_position[i];
  380. current_position[i] = 0.0;
  381. }
  382. }
  383. plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
  384. // Audio feedback
  385. enquecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
  386. lcd_return_to_status();
  387. }
  388. #ifdef BABYSTEPPING
  389. static void _lcd_babystep(int axis, const char *msg) {
  390. if (encoderPosition != 0) {
  391. babystepsTodo[axis] += (int)encoderPosition;
  392. encoderPosition = 0;
  393. lcdDrawUpdate = 1;
  394. }
  395. if (lcdDrawUpdate) lcd_implementation_drawedit(msg, "");
  396. if (LCD_CLICKED) lcd_goto_menu(lcd_tune_menu);
  397. }
  398. static void lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  399. static void lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  400. static void lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  401. #endif //BABYSTEPPING
  402. static void lcd_tune_menu()
  403. {
  404. START_MENU();
  405. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  406. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);
  407. #if TEMP_SENSOR_0 != 0
  408. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  409. #endif
  410. #if TEMP_SENSOR_1 != 0
  411. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  412. #endif
  413. #if TEMP_SENSOR_2 != 0
  414. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  415. #endif
  416. #if TEMP_SENSOR_3 != 0
  417. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
  418. #endif
  419. #if TEMP_SENSOR_BED != 0
  420. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  421. #endif
  422. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  423. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);
  424. MENU_ITEM_EDIT(int3, MSG_FLOW " 0", &extruder_multiply[0], 10, 999);
  425. #if TEMP_SENSOR_1 != 0
  426. MENU_ITEM_EDIT(int3, MSG_FLOW " 1", &extruder_multiply[1], 10, 999);
  427. #endif
  428. #if TEMP_SENSOR_2 != 0
  429. MENU_ITEM_EDIT(int3, MSG_FLOW " 2", &extruder_multiply[2], 10, 999);
  430. #endif
  431. #if TEMP_SENSOR_3 != 0
  432. MENU_ITEM_EDIT(int3, MSG_FLOW " 3", &extruder_multiply[3], 10, 999);
  433. #endif
  434. #ifdef BABYSTEPPING
  435. #ifdef BABYSTEP_XY
  436. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  437. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  438. #endif //BABYSTEP_XY
  439. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  440. #endif
  441. #ifdef FILAMENTCHANGEENABLE
  442. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  443. #endif
  444. END_MENU();
  445. }
  446. void lcd_preheat_pla0()
  447. {
  448. setTargetHotend0(plaPreheatHotendTemp);
  449. setTargetBed(plaPreheatHPBTemp);
  450. fanSpeed = plaPreheatFanSpeed;
  451. lcd_return_to_status();
  452. setWatch(); // heater sanity check timer
  453. }
  454. void lcd_preheat_abs0()
  455. {
  456. setTargetHotend0(absPreheatHotendTemp);
  457. setTargetBed(absPreheatHPBTemp);
  458. fanSpeed = absPreheatFanSpeed;
  459. lcd_return_to_status();
  460. setWatch(); // heater sanity check timer
  461. }
  462. #if TEMP_SENSOR_1 != 0 //2nd extruder preheat
  463. void lcd_preheat_pla1()
  464. {
  465. setTargetHotend1(plaPreheatHotendTemp);
  466. setTargetBed(plaPreheatHPBTemp);
  467. fanSpeed = plaPreheatFanSpeed;
  468. lcd_return_to_status();
  469. setWatch(); // heater sanity check timer
  470. }
  471. void lcd_preheat_abs1()
  472. {
  473. setTargetHotend1(absPreheatHotendTemp);
  474. setTargetBed(absPreheatHPBTemp);
  475. fanSpeed = absPreheatFanSpeed;
  476. lcd_return_to_status();
  477. setWatch(); // heater sanity check timer
  478. }
  479. #endif //2nd extruder preheat
  480. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  481. void lcd_preheat_pla2()
  482. {
  483. setTargetHotend2(plaPreheatHotendTemp);
  484. setTargetBed(plaPreheatHPBTemp);
  485. fanSpeed = plaPreheatFanSpeed;
  486. lcd_return_to_status();
  487. setWatch(); // heater sanity check timer
  488. }
  489. void lcd_preheat_abs2()
  490. {
  491. setTargetHotend2(absPreheatHotendTemp);
  492. setTargetBed(absPreheatHPBTemp);
  493. fanSpeed = absPreheatFanSpeed;
  494. lcd_return_to_status();
  495. setWatch(); // heater sanity check timer
  496. }
  497. #endif //3 extruder preheat
  498. #if TEMP_SENSOR_3 != 0 //4 extruder preheat
  499. void lcd_preheat_pla3()
  500. {
  501. setTargetHotend3(plaPreheatHotendTemp);
  502. setTargetBed(plaPreheatHPBTemp);
  503. fanSpeed = plaPreheatFanSpeed;
  504. lcd_return_to_status();
  505. setWatch(); // heater sanity check timer
  506. }
  507. void lcd_preheat_abs3()
  508. {
  509. setTargetHotend3(absPreheatHotendTemp);
  510. setTargetBed(absPreheatHPBTemp);
  511. fanSpeed = absPreheatFanSpeed;
  512. lcd_return_to_status();
  513. setWatch(); // heater sanity check timer
  514. }
  515. #endif //4 extruder preheat
  516. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 //more than one extruder present
  517. void lcd_preheat_pla0123()
  518. {
  519. setTargetHotend0(plaPreheatHotendTemp);
  520. setTargetHotend1(plaPreheatHotendTemp);
  521. setTargetHotend2(plaPreheatHotendTemp);
  522. setTargetHotend3(plaPreheatHotendTemp);
  523. setTargetBed(plaPreheatHPBTemp);
  524. fanSpeed = plaPreheatFanSpeed;
  525. lcd_return_to_status();
  526. setWatch(); // heater sanity check timer
  527. }
  528. void lcd_preheat_abs0123()
  529. {
  530. setTargetHotend0(absPreheatHotendTemp);
  531. setTargetHotend1(absPreheatHotendTemp);
  532. setTargetHotend2(absPreheatHotendTemp);
  533. setTargetHotend3(absPreheatHotendTemp);
  534. setTargetBed(absPreheatHPBTemp);
  535. fanSpeed = absPreheatFanSpeed;
  536. lcd_return_to_status();
  537. setWatch(); // heater sanity check timer
  538. }
  539. #endif //more than one extruder present
  540. void lcd_preheat_pla_bedonly()
  541. {
  542. setTargetBed(plaPreheatHPBTemp);
  543. fanSpeed = plaPreheatFanSpeed;
  544. lcd_return_to_status();
  545. setWatch(); // heater sanity check timer
  546. }
  547. void lcd_preheat_abs_bedonly()
  548. {
  549. setTargetBed(absPreheatHPBTemp);
  550. fanSpeed = absPreheatFanSpeed;
  551. lcd_return_to_status();
  552. setWatch(); // heater sanity check timer
  553. }
  554. static void lcd_preheat_pla_menu()
  555. {
  556. START_MENU();
  557. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  558. MENU_ITEM(function, MSG_PREHEAT_PLA_N "1", lcd_preheat_pla0);
  559. #if TEMP_SENSOR_1 != 0 //2 extruder preheat
  560. MENU_ITEM(function, MSG_PREHEAT_PLA_N "2", lcd_preheat_pla1);
  561. #endif //2 extruder preheat
  562. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  563. MENU_ITEM(function, MSG_PREHEAT_PLA_N "3", lcd_preheat_pla2);
  564. #endif //3 extruder preheat
  565. #if TEMP_SENSOR_3 != 0 //4 extruder preheat
  566. MENU_ITEM(function, MSG_PREHEAT_PLA_N "4", lcd_preheat_pla3);
  567. #endif //4 extruder preheat
  568. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 //all extruder preheat
  569. MENU_ITEM(function, MSG_PREHEAT_PLA_ALL, lcd_preheat_pla0123);
  570. #endif //all extruder preheat
  571. #if TEMP_SENSOR_BED != 0
  572. MENU_ITEM(function, MSG_PREHEAT_PLA_BEDONLY, lcd_preheat_pla_bedonly);
  573. #endif
  574. END_MENU();
  575. }
  576. static void lcd_preheat_abs_menu()
  577. {
  578. START_MENU();
  579. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  580. MENU_ITEM(function, MSG_PREHEAT_ABS_N "1", lcd_preheat_abs0);
  581. #if TEMP_SENSOR_1 != 0 //2 extruder preheat
  582. MENU_ITEM(function, MSG_PREHEAT_ABS_N "2", lcd_preheat_abs1);
  583. #endif //2 extruder preheat
  584. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  585. MENU_ITEM(function, MSG_PREHEAT_ABS_N "3", lcd_preheat_abs2);
  586. #endif //3 extruder preheat
  587. #if TEMP_SENSOR_3 != 0 //4 extruder preheat
  588. MENU_ITEM(function, MSG_PREHEAT_ABS_N "4", lcd_preheat_abs3);
  589. #endif //4 extruder preheat
  590. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 //all extruder preheat
  591. MENU_ITEM(function, MSG_PREHEAT_ABS_ALL, lcd_preheat_abs0123);
  592. #endif //all extruder preheat
  593. #if TEMP_SENSOR_BED != 0
  594. MENU_ITEM(function, MSG_PREHEAT_ABS_BEDONLY, lcd_preheat_abs_bedonly);
  595. #endif
  596. END_MENU();
  597. }
  598. void lcd_cooldown()
  599. {
  600. setTargetHotend0(0);
  601. setTargetHotend1(0);
  602. setTargetHotend2(0);
  603. setTargetHotend3(0);
  604. setTargetBed(0);
  605. fanSpeed = 0;
  606. lcd_return_to_status();
  607. }
  608. static void lcd_prepare_menu()
  609. {
  610. START_MENU();
  611. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  612. #ifdef SDSUPPORT
  613. #ifdef MENU_ADDAUTOSTART
  614. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  615. #endif
  616. #endif
  617. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  618. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  619. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  620. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  621. #if TEMP_SENSOR_0 != 0
  622. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_BED != 0
  623. MENU_ITEM(submenu, MSG_PREHEAT_PLA, lcd_preheat_pla_menu);
  624. MENU_ITEM(submenu, MSG_PREHEAT_ABS, lcd_preheat_abs_menu);
  625. #else
  626. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  627. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  628. #endif
  629. #endif
  630. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  631. #if PS_ON_PIN > -1
  632. if (powersupply)
  633. {
  634. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  635. }else{
  636. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  637. }
  638. #endif
  639. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  640. // JFR for RMud delta printer
  641. MENU_ITEM(gcode, "Calibrate bed", PSTR("M702\nG28\nG1 X-77.94 Y-45 Z36 F8000\nG4 S3\nM701 P0\nG1 X77.94 Y-45 Z36\nG4 S3\nM701 P1\nG1 X0 Y90 Z36\nG4 S3\nM701 P2\nM700\nG1 X0 Y0 Z100 F8000"));
  642. MENU_ITEM(gcode, "Check level", PSTR("G28\nG1 X0 Y0 Z1 F4000\nG1 X-77.94 Y-45 Z1\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG4 S2\nG1 X-77.94 Y-45 Z0.3 F2000\nG1 X-77.94 Y-45\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG1 X0 Y0 Z0"));
  643. MENU_ITEM(gcode, "Retract filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E-800"));
  644. MENU_ITEM(gcode, "Insert filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E60"));
  645. MENU_ITEM(gcode, "Finalize filament", PSTR("G1 F4000 E790"));
  646. END_MENU();
  647. }
  648. #ifdef DELTA_CALIBRATION_MENU
  649. static void lcd_delta_calibrate_menu()
  650. {
  651. START_MENU();
  652. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  653. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  654. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_X, PSTR("G0 F8000 X-77.94 Y-45 Z0"));
  655. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Y, PSTR("G0 F8000 X77.94 Y-45 Z0"));
  656. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Z, PSTR("G0 F8000 X0 Y90 Z0"));
  657. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_CENTER, PSTR("G0 F8000 X0 Y0 Z0"));
  658. END_MENU();
  659. }
  660. #endif // DELTA_CALIBRATION_MENU
  661. float move_menu_scale;
  662. static void lcd_move_menu_axis();
  663. static void _lcd_move(const char *name, int axis, int min, int max) {
  664. if (encoderPosition != 0) {
  665. refresh_cmd_timeout();
  666. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  667. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  668. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  669. encoderPosition = 0;
  670. #ifdef DELTA
  671. calculate_delta(current_position);
  672. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  673. #else
  674. 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);
  675. #endif
  676. lcdDrawUpdate = 1;
  677. }
  678. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  679. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  680. }
  681. static void lcd_move_x() { _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS); }
  682. static void lcd_move_y() { _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
  683. static void lcd_move_z() { _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
  684. static void lcd_move_e()
  685. {
  686. if (encoderPosition != 0)
  687. {
  688. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  689. encoderPosition = 0;
  690. #ifdef DELTA
  691. calculate_delta(current_position);
  692. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS]/60, active_extruder);
  693. #else
  694. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS]/60, active_extruder);
  695. #endif
  696. lcdDrawUpdate = 1;
  697. }
  698. if (lcdDrawUpdate)
  699. {
  700. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  701. }
  702. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  703. }
  704. static void lcd_move_menu_axis()
  705. {
  706. START_MENU();
  707. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  708. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  709. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  710. if (move_menu_scale < 10.0)
  711. {
  712. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  713. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  714. }
  715. END_MENU();
  716. }
  717. static void lcd_move_menu_10mm()
  718. {
  719. move_menu_scale = 10.0;
  720. lcd_move_menu_axis();
  721. }
  722. static void lcd_move_menu_1mm()
  723. {
  724. move_menu_scale = 1.0;
  725. lcd_move_menu_axis();
  726. }
  727. static void lcd_move_menu_01mm()
  728. {
  729. move_menu_scale = 0.1;
  730. lcd_move_menu_axis();
  731. }
  732. static void lcd_move_menu()
  733. {
  734. START_MENU();
  735. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  736. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  737. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  738. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  739. //TODO:X,Y,Z,E
  740. END_MENU();
  741. }
  742. static void lcd_control_menu()
  743. {
  744. START_MENU();
  745. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  746. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  747. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  748. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  749. #ifdef DOGLCD
  750. // MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  751. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  752. #endif
  753. #ifdef FWRETRACT
  754. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  755. #endif
  756. #ifdef EEPROM_SETTINGS
  757. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  758. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  759. #endif
  760. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  761. END_MENU();
  762. }
  763. static void lcd_control_temperature_menu()
  764. {
  765. START_MENU();
  766. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  767. #if TEMP_SENSOR_0 != 0
  768. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  769. #endif
  770. #if TEMP_SENSOR_1 != 0 && EXTRUDERS > 1
  771. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  772. #endif
  773. #if TEMP_SENSOR_2 != 0 && EXTRUDERS > 2
  774. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  775. #endif
  776. #if TEMP_SENSOR_3 != 0 && EXTRUDERS > 3
  777. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
  778. #endif
  779. #if TEMP_SENSOR_BED != 0
  780. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  781. #endif
  782. MENU_MULTIPLIER_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  783. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  784. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  785. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  786. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  787. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  788. #endif
  789. #ifdef PIDTEMP
  790. // set up temp variables - undo the default scaling
  791. pid_current_extruder = 0;
  792. raw_Ki = unscalePID_i(PID_PARAM(Ki,0));
  793. raw_Kd = unscalePID_d(PID_PARAM(Kd,0));
  794. MENU_ITEM_EDIT(float52, MSG_PID_P, &PID_PARAM(Kp,0), 1, 9990);
  795. // i is typically a small value so allows values below 1
  796. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
  797. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
  798. #ifdef PID_ADD_EXTRUSION_RATE
  799. MENU_ITEM_EDIT(float3, MSG_PID_C, &PID_PARAM(Kc,0), 1, 9990);
  800. #endif//PID_ADD_EXTRUSION_RATE
  801. #ifdef PID_PARAMS_PER_EXTRUDER
  802. #if EXTRUDERS > 1
  803. // set up temp variables - undo the default scaling
  804. pid_current_extruder = 0;
  805. raw_Ki = unscalePID_i(PID_PARAM(Ki,1));
  806. raw_Kd = unscalePID_d(PID_PARAM(Kd,1));
  807. MENU_ITEM_EDIT(float52, MSG_PID_P " E2", &PID_PARAM(Kp,1), 1, 9990);
  808. // i is typically a small value so allows values below 1
  809. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E2", &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
  810. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E2", &raw_Kd, 1, 9990, copy_and_scalePID_d);
  811. #ifdef PID_ADD_EXTRUSION_RATE
  812. MENU_ITEM_EDIT(float3, MSG_PID_C " E2", &PID_PARAM(Kc,1), 1, 9990);
  813. #endif//PID_ADD_EXTRUSION_RATE
  814. #endif//EXTRUDERS > 1
  815. #if EXTRUDERS > 2
  816. // set up temp variables - undo the default scaling
  817. pid_current_extruder = 0;
  818. raw_Ki = unscalePID_i(PID_PARAM(Ki,2));
  819. raw_Kd = unscalePID_d(PID_PARAM(Kd,2));
  820. MENU_ITEM_EDIT(float52, MSG_PID_P " E3", &PID_PARAM(Kp,2), 1, 9990);
  821. // i is typically a small value so allows values below 1
  822. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E3", &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
  823. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E3", &raw_Kd, 1, 9990, copy_and_scalePID_d);
  824. #ifdef PID_ADD_EXTRUSION_RATE
  825. MENU_ITEM_EDIT(float3, MSG_PID_C " E3", &PID_PARAM(Kc,2), 1, 9990);
  826. #endif//PID_ADD_EXTRUSION_RATE
  827. #endif//EXTRUDERS > 2
  828. #endif // PID_PARAMS_PER_EXTRUDER
  829. #endif//PIDTEMP
  830. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  831. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  832. END_MENU();
  833. }
  834. static void lcd_control_temperature_preheat_pla_settings_menu()
  835. {
  836. START_MENU();
  837. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  838. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  839. #if TEMP_SENSOR_0 != 0
  840. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  841. #endif
  842. #if TEMP_SENSOR_BED != 0
  843. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  844. #endif
  845. #ifdef EEPROM_SETTINGS
  846. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  847. #endif
  848. END_MENU();
  849. }
  850. static void lcd_control_temperature_preheat_abs_settings_menu()
  851. {
  852. START_MENU();
  853. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  854. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  855. #if TEMP_SENSOR_0 != 0
  856. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  857. #endif
  858. #if TEMP_SENSOR_BED != 0
  859. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  860. #endif
  861. #ifdef EEPROM_SETTINGS
  862. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  863. #endif
  864. END_MENU();
  865. }
  866. static void lcd_control_motion_menu()
  867. {
  868. START_MENU();
  869. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  870. #ifdef ENABLE_AUTO_BED_LEVELING
  871. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, 0.5, 50);
  872. #endif
  873. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
  874. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  875. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  876. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  877. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  878. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  879. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  880. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  881. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  882. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  883. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  884. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  885. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000, reset_acceleration_rates);
  886. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  887. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  888. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  889. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  890. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  891. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  892. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  893. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
  894. #endif
  895. #ifdef SCARA
  896. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS],0.5,2);
  897. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS],0.5,2);
  898. #endif
  899. END_MENU();
  900. }
  901. static void lcd_control_volumetric_menu()
  902. {
  903. START_MENU();
  904. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  905. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  906. if (volumetric_enabled) {
  907. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_0, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
  908. #if EXTRUDERS > 1
  909. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_1, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
  910. #if EXTRUDERS > 2
  911. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_2, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
  912. #if EXTRUDERS > 3
  913. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_3, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
  914. #endif //EXTRUDERS > 3
  915. #endif //EXTRUDERS > 2
  916. #endif //EXTRUDERS > 1
  917. }
  918. END_MENU();
  919. }
  920. #ifdef DOGLCD
  921. static void lcd_set_contrast()
  922. {
  923. if (encoderPosition != 0)
  924. {
  925. lcd_contrast -= encoderPosition;
  926. if (lcd_contrast < 0) lcd_contrast = 0;
  927. else if (lcd_contrast > 63) lcd_contrast = 63;
  928. encoderPosition = 0;
  929. lcdDrawUpdate = 1;
  930. u8g.setContrast(lcd_contrast);
  931. }
  932. if (lcdDrawUpdate)
  933. {
  934. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
  935. }
  936. if (LCD_CLICKED) lcd_goto_menu(lcd_control_menu);
  937. }
  938. #endif
  939. #ifdef FWRETRACT
  940. static void lcd_control_retract_menu()
  941. {
  942. START_MENU();
  943. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  944. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  945. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  946. #if EXTRUDERS > 1
  947. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  948. #endif
  949. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  950. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  951. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  952. #if EXTRUDERS > 1
  953. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  954. #endif
  955. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  956. END_MENU();
  957. }
  958. #endif //FWRETRACT
  959. #if SDCARDDETECT == -1
  960. static void lcd_sd_refresh()
  961. {
  962. card.initsd();
  963. currentMenuViewOffset = 0;
  964. }
  965. #endif
  966. static void lcd_sd_updir()
  967. {
  968. card.updir();
  969. currentMenuViewOffset = 0;
  970. }
  971. void lcd_sdcard_menu()
  972. {
  973. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  974. return; // nothing to do (so don't thrash the SD card)
  975. uint16_t fileCnt = card.getnrfilenames();
  976. START_MENU();
  977. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  978. card.getWorkDirName();
  979. if(card.filename[0]=='/')
  980. {
  981. #if SDCARDDETECT == -1
  982. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  983. #endif
  984. }else{
  985. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  986. }
  987. for(uint16_t i=0;i<fileCnt;i++)
  988. {
  989. if (_menuItemNr == _lineNr)
  990. {
  991. #ifndef SDCARD_RATHERRECENTFIRST
  992. card.getfilename(i);
  993. #else
  994. card.getfilename(fileCnt-1-i);
  995. #endif
  996. if (card.filenameIsDir)
  997. {
  998. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  999. }else{
  1000. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1001. }
  1002. }else{
  1003. MENU_ITEM_DUMMY();
  1004. }
  1005. }
  1006. END_MENU();
  1007. }
  1008. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1009. void menu_edit_ ## _name () \
  1010. { \
  1011. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1012. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1013. if (lcdDrawUpdate) \
  1014. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1015. if (LCD_CLICKED) \
  1016. { \
  1017. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1018. lcd_goto_menu(prevMenu, prevEncoderPosition); \
  1019. } \
  1020. } \
  1021. void menu_edit_callback_ ## _name () { \
  1022. menu_edit_ ## _name (); \
  1023. if (LCD_CLICKED) (*callbackFunc)(); \
  1024. } \
  1025. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  1026. { \
  1027. prevMenu = currentMenu; \
  1028. prevEncoderPosition = encoderPosition; \
  1029. \
  1030. lcdDrawUpdate = 2; \
  1031. currentMenu = menu_edit_ ## _name; \
  1032. \
  1033. editLabel = pstr; \
  1034. editValue = ptr; \
  1035. minEditValue = minValue * scale; \
  1036. maxEditValue = maxValue * scale - minEditValue; \
  1037. encoderPosition = (*ptr) * scale - minEditValue; \
  1038. }\
  1039. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  1040. { \
  1041. prevMenu = currentMenu; \
  1042. prevEncoderPosition = encoderPosition; \
  1043. \
  1044. lcdDrawUpdate = 2; \
  1045. currentMenu = menu_edit_callback_ ## _name; \
  1046. \
  1047. editLabel = pstr; \
  1048. editValue = ptr; \
  1049. minEditValue = minValue * scale; \
  1050. maxEditValue = maxValue * scale - minEditValue; \
  1051. encoderPosition = (*ptr) * scale - minEditValue; \
  1052. callbackFunc = callback;\
  1053. }
  1054. menu_edit_type(int, int3, itostr3, 1)
  1055. menu_edit_type(float, float3, ftostr3, 1)
  1056. menu_edit_type(float, float32, ftostr32, 100)
  1057. menu_edit_type(float, float43, ftostr43, 1000)
  1058. menu_edit_type(float, float5, ftostr5, 0.01)
  1059. menu_edit_type(float, float51, ftostr51, 10)
  1060. menu_edit_type(float, float52, ftostr52, 100)
  1061. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1062. #ifdef REPRAPWORLD_KEYPAD
  1063. static void reprapworld_keypad_move_z_up() {
  1064. encoderPosition = 1;
  1065. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1066. lcd_move_z();
  1067. }
  1068. static void reprapworld_keypad_move_z_down() {
  1069. encoderPosition = -1;
  1070. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1071. lcd_move_z();
  1072. }
  1073. static void reprapworld_keypad_move_x_left() {
  1074. encoderPosition = -1;
  1075. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1076. lcd_move_x();
  1077. }
  1078. static void reprapworld_keypad_move_x_right() {
  1079. encoderPosition = 1;
  1080. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1081. lcd_move_x();
  1082. }
  1083. static void reprapworld_keypad_move_y_down() {
  1084. encoderPosition = 1;
  1085. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1086. lcd_move_y();
  1087. }
  1088. static void reprapworld_keypad_move_y_up() {
  1089. encoderPosition = -1;
  1090. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  1091. lcd_move_y();
  1092. }
  1093. static void reprapworld_keypad_move_home() {
  1094. enquecommands_P((PSTR("G28"))); // move all axis home
  1095. }
  1096. #endif
  1097. /** End of menus **/
  1098. static void lcd_quick_feedback()
  1099. {
  1100. lcdDrawUpdate = 2;
  1101. blocking_enc = millis() + 500;
  1102. lcd_implementation_quick_feedback();
  1103. }
  1104. /** Menu action functions **/
  1105. static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
  1106. static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
  1107. static void menu_action_gcode(const char* pgcode)
  1108. {
  1109. enquecommands_P(pgcode);
  1110. }
  1111. static void menu_action_function(menuFunc_t data) { (*data)(); }
  1112. static void menu_action_sdfile(const char* filename, char* longFilename)
  1113. {
  1114. char cmd[30];
  1115. char* c;
  1116. sprintf_P(cmd, PSTR("M23 %s"), filename);
  1117. for(c = &cmd[4]; *c; c++)
  1118. *c = tolower(*c);
  1119. enquecommand(cmd);
  1120. enquecommands_P(PSTR("M24"));
  1121. lcd_return_to_status();
  1122. }
  1123. static void menu_action_sddirectory(const char* filename, char* longFilename)
  1124. {
  1125. card.chdir(filename);
  1126. encoderPosition = 0;
  1127. }
  1128. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  1129. {
  1130. *ptr = !(*ptr);
  1131. }
  1132. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  1133. {
  1134. menu_action_setting_edit_bool(pstr, ptr);
  1135. (*callback)();
  1136. }
  1137. #endif//ULTIPANEL
  1138. /** LCD API **/
  1139. void lcd_init()
  1140. {
  1141. lcd_implementation_init();
  1142. #ifdef NEWPANEL
  1143. SET_INPUT(BTN_EN1);
  1144. SET_INPUT(BTN_EN2);
  1145. WRITE(BTN_EN1,HIGH);
  1146. WRITE(BTN_EN2,HIGH);
  1147. #if BTN_ENC > 0
  1148. SET_INPUT(BTN_ENC);
  1149. WRITE(BTN_ENC,HIGH);
  1150. #endif
  1151. #ifdef REPRAPWORLD_KEYPAD
  1152. pinMode(SHIFT_CLK,OUTPUT);
  1153. pinMode(SHIFT_LD,OUTPUT);
  1154. pinMode(SHIFT_OUT,INPUT);
  1155. WRITE(SHIFT_OUT,HIGH);
  1156. WRITE(SHIFT_LD,HIGH);
  1157. #endif
  1158. #else // Not NEWPANEL
  1159. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  1160. pinMode (SR_DATA_PIN, OUTPUT);
  1161. pinMode (SR_CLK_PIN, OUTPUT);
  1162. #elif defined(SHIFT_CLK)
  1163. pinMode(SHIFT_CLK,OUTPUT);
  1164. pinMode(SHIFT_LD,OUTPUT);
  1165. pinMode(SHIFT_EN,OUTPUT);
  1166. pinMode(SHIFT_OUT,INPUT);
  1167. WRITE(SHIFT_OUT,HIGH);
  1168. WRITE(SHIFT_LD,HIGH);
  1169. WRITE(SHIFT_EN,LOW);
  1170. #else
  1171. #ifdef ULTIPANEL
  1172. #error ULTIPANEL requires an encoder
  1173. #endif
  1174. #endif // SR_LCD_2W_NL
  1175. #endif//!NEWPANEL
  1176. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  1177. pinMode(SDCARDDETECT,INPUT);
  1178. WRITE(SDCARDDETECT, HIGH);
  1179. lcd_oldcardstatus = IS_SD_INSERTED;
  1180. #endif//(SDCARDDETECT > 0)
  1181. #ifdef LCD_HAS_SLOW_BUTTONS
  1182. slow_buttons = 0;
  1183. #endif
  1184. lcd_buttons_update();
  1185. #ifdef ULTIPANEL
  1186. encoderDiff = 0;
  1187. #endif
  1188. }
  1189. void lcd_update()
  1190. {
  1191. static unsigned long timeoutToStatus = 0;
  1192. #ifdef LCD_HAS_SLOW_BUTTONS
  1193. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1194. #endif
  1195. lcd_buttons_update();
  1196. #if (SDCARDDETECT > 0)
  1197. if((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  1198. {
  1199. lcdDrawUpdate = 2;
  1200. lcd_oldcardstatus = IS_SD_INSERTED;
  1201. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1202. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  1203. currentMenu == lcd_status_screen
  1204. #endif
  1205. );
  1206. if(lcd_oldcardstatus)
  1207. {
  1208. card.initsd();
  1209. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1210. }
  1211. else
  1212. {
  1213. card.release();
  1214. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1215. }
  1216. }
  1217. #endif//CARDINSERTED
  1218. if (lcd_next_update_millis < millis())
  1219. {
  1220. #ifdef ULTIPANEL
  1221. #ifdef REPRAPWORLD_KEYPAD
  1222. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  1223. reprapworld_keypad_move_z_up();
  1224. }
  1225. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  1226. reprapworld_keypad_move_z_down();
  1227. }
  1228. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  1229. reprapworld_keypad_move_x_left();
  1230. }
  1231. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  1232. reprapworld_keypad_move_x_right();
  1233. }
  1234. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  1235. reprapworld_keypad_move_y_down();
  1236. }
  1237. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  1238. reprapworld_keypad_move_y_up();
  1239. }
  1240. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  1241. reprapworld_keypad_move_home();
  1242. }
  1243. #endif
  1244. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  1245. {
  1246. int32_t encoderMultiplier = 1;
  1247. #ifdef ENCODER_RATE_MULTIPLIER
  1248. if (encoderRateMultiplierEnabled)
  1249. {
  1250. int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
  1251. if (lastEncoderMovementMillis != 0)
  1252. {
  1253. // Note that the rate is always calculated between to passes through the
  1254. // loop and that the abs of the encoderDiff value is tracked.
  1255. float encoderStepRate =
  1256. (float)(encoderMovementSteps) / ((float)(millis() - lastEncoderMovementMillis)) * 1000.0;
  1257. if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC)
  1258. {
  1259. encoderMultiplier = 100;
  1260. }
  1261. else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC)
  1262. {
  1263. encoderMultiplier = 10;
  1264. }
  1265. #ifdef ENCODER_RATE_MULTIPLIER_DEBUG
  1266. SERIAL_ECHO_START;
  1267. SERIAL_ECHO("Enc Step Rate: ");
  1268. SERIAL_ECHO(encoderStepRate);
  1269. SERIAL_ECHO(" Multiplier: ");
  1270. SERIAL_ECHO(encoderMultiplier);
  1271. SERIAL_ECHO(" ENCODER_10X_STEPS_PER_SEC: ");
  1272. SERIAL_ECHO(ENCODER_10X_STEPS_PER_SEC);
  1273. SERIAL_ECHO(" ENCODER_100X_STEPS_PER_SEC: ");
  1274. SERIAL_ECHOLN(ENCODER_100X_STEPS_PER_SEC);
  1275. #endif
  1276. }
  1277. lastEncoderMovementMillis = millis();
  1278. }
  1279. #endif
  1280. lcdDrawUpdate = 1;
  1281. encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
  1282. encoderDiff = 0;
  1283. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1284. }
  1285. if (LCD_CLICKED)
  1286. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1287. #endif//ULTIPANEL
  1288. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  1289. blink++; // Variable for fan animation and alive dot
  1290. u8g.firstPage();
  1291. do
  1292. {
  1293. u8g.setFont(FONT_MENU);
  1294. u8g.setPrintPos(125,0);
  1295. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1296. u8g.drawPixel(127,63); // draw alive dot
  1297. u8g.setColorIndex(1); // black on white
  1298. (*currentMenu)();
  1299. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  1300. } while( u8g.nextPage() );
  1301. #else
  1302. (*currentMenu)();
  1303. #endif
  1304. #ifdef LCD_HAS_STATUS_INDICATORS
  1305. lcd_implementation_update_indicators();
  1306. #endif
  1307. #ifdef ULTIPANEL
  1308. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  1309. {
  1310. lcd_return_to_status();
  1311. lcdDrawUpdate = 2;
  1312. }
  1313. #endif//ULTIPANEL
  1314. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1315. if (lcdDrawUpdate) lcdDrawUpdate--;
  1316. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  1317. }
  1318. }
  1319. void lcd_ignore_click(bool b)
  1320. {
  1321. ignore_click = b;
  1322. wait_for_unclick = false;
  1323. }
  1324. void lcd_finishstatus() {
  1325. int len = strlen(lcd_status_message);
  1326. if (len > 0) {
  1327. while (len < LCD_WIDTH) {
  1328. lcd_status_message[len++] = ' ';
  1329. }
  1330. }
  1331. lcd_status_message[LCD_WIDTH] = '\0';
  1332. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  1333. #if PROGRESS_MSG_EXPIRE > 0
  1334. messageTick =
  1335. #endif
  1336. progressBarTick = millis();
  1337. #endif
  1338. lcdDrawUpdate = 2;
  1339. #ifdef FILAMENT_LCD_DISPLAY
  1340. message_millis = millis(); //get status message to show up for a while
  1341. #endif
  1342. }
  1343. void lcd_setstatus(const char* message)
  1344. {
  1345. if (lcd_status_message_level > 0)
  1346. return;
  1347. strncpy(lcd_status_message, message, LCD_WIDTH);
  1348. lcd_finishstatus();
  1349. }
  1350. void lcd_setstatuspgm(const char* message)
  1351. {
  1352. if (lcd_status_message_level > 0)
  1353. return;
  1354. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  1355. lcd_finishstatus();
  1356. }
  1357. void lcd_setalertstatuspgm(const char* message)
  1358. {
  1359. lcd_setstatuspgm(message);
  1360. lcd_status_message_level = 1;
  1361. #ifdef ULTIPANEL
  1362. lcd_return_to_status();
  1363. #endif//ULTIPANEL
  1364. }
  1365. void lcd_reset_alert_level()
  1366. {
  1367. lcd_status_message_level = 0;
  1368. }
  1369. #ifdef DOGLCD
  1370. void lcd_setcontrast(uint8_t value)
  1371. {
  1372. lcd_contrast = value & 63;
  1373. u8g.setContrast(lcd_contrast);
  1374. }
  1375. #endif
  1376. #ifdef ULTIPANEL
  1377. /* Warning: This function is called from interrupt context */
  1378. void lcd_buttons_update()
  1379. {
  1380. #ifdef NEWPANEL
  1381. uint8_t newbutton=0;
  1382. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  1383. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  1384. #if BTN_ENC > 0
  1385. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  1386. newbutton |= EN_C;
  1387. #endif
  1388. buttons = newbutton;
  1389. #ifdef LCD_HAS_SLOW_BUTTONS
  1390. buttons |= slow_buttons;
  1391. #endif
  1392. #ifdef REPRAPWORLD_KEYPAD
  1393. // for the reprapworld_keypad
  1394. uint8_t newbutton_reprapworld_keypad=0;
  1395. WRITE(SHIFT_LD,LOW);
  1396. WRITE(SHIFT_LD,HIGH);
  1397. for(int8_t i=0;i<8;i++) {
  1398. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad>>1;
  1399. if(READ(SHIFT_OUT))
  1400. newbutton_reprapworld_keypad|=(1<<7);
  1401. WRITE(SHIFT_CLK,HIGH);
  1402. WRITE(SHIFT_CLK,LOW);
  1403. }
  1404. buttons_reprapworld_keypad=~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1405. #endif
  1406. #else //read it from the shift register
  1407. uint8_t newbutton=0;
  1408. WRITE(SHIFT_LD,LOW);
  1409. WRITE(SHIFT_LD,HIGH);
  1410. unsigned char tmp_buttons=0;
  1411. for(int8_t i=0;i<8;i++)
  1412. {
  1413. newbutton = newbutton>>1;
  1414. if(READ(SHIFT_OUT))
  1415. newbutton|=(1<<7);
  1416. WRITE(SHIFT_CLK,HIGH);
  1417. WRITE(SHIFT_CLK,LOW);
  1418. }
  1419. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  1420. #endif//!NEWPANEL
  1421. //manage encoder rotation
  1422. uint8_t enc=0;
  1423. if (buttons & EN_A) enc |= B01;
  1424. if (buttons & EN_B) enc |= B10;
  1425. if(enc != lastEncoderBits)
  1426. {
  1427. switch(enc)
  1428. {
  1429. case encrot0:
  1430. if(lastEncoderBits==encrot3)
  1431. encoderDiff++;
  1432. else if(lastEncoderBits==encrot1)
  1433. encoderDiff--;
  1434. break;
  1435. case encrot1:
  1436. if(lastEncoderBits==encrot0)
  1437. encoderDiff++;
  1438. else if(lastEncoderBits==encrot2)
  1439. encoderDiff--;
  1440. break;
  1441. case encrot2:
  1442. if(lastEncoderBits==encrot1)
  1443. encoderDiff++;
  1444. else if(lastEncoderBits==encrot3)
  1445. encoderDiff--;
  1446. break;
  1447. case encrot3:
  1448. if(lastEncoderBits==encrot2)
  1449. encoderDiff++;
  1450. else if(lastEncoderBits==encrot0)
  1451. encoderDiff--;
  1452. break;
  1453. }
  1454. }
  1455. lastEncoderBits = enc;
  1456. }
  1457. bool lcd_detected(void)
  1458. {
  1459. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  1460. return lcd.LcdDetected() == 1;
  1461. #else
  1462. return true;
  1463. #endif
  1464. }
  1465. void lcd_buzz(long duration, uint16_t freq)
  1466. {
  1467. #ifdef LCD_USE_I2C_BUZZER
  1468. lcd.buzz(duration,freq);
  1469. #endif
  1470. }
  1471. bool lcd_clicked()
  1472. {
  1473. return LCD_CLICKED;
  1474. }
  1475. #endif//ULTIPANEL
  1476. /********************************/
  1477. /** Float conversion utilities **/
  1478. /********************************/
  1479. // convert float to string with +123.4 format
  1480. char conv[8];
  1481. char *ftostr3(const float &x)
  1482. {
  1483. return itostr3((int)x);
  1484. }
  1485. char *itostr2(const uint8_t &x)
  1486. {
  1487. //sprintf(conv,"%5.1f",x);
  1488. int xx=x;
  1489. conv[0]=(xx/10)%10+'0';
  1490. conv[1]=(xx)%10+'0';
  1491. conv[2]=0;
  1492. return conv;
  1493. }
  1494. // Convert float to string with 123.4 format, dropping sign
  1495. char *ftostr31(const float &x)
  1496. {
  1497. int xx=x*10;
  1498. conv[0]=(xx>=0)?'+':'-';
  1499. xx=abs(xx);
  1500. conv[1]=(xx/1000)%10+'0';
  1501. conv[2]=(xx/100)%10+'0';
  1502. conv[3]=(xx/10)%10+'0';
  1503. conv[4]='.';
  1504. conv[5]=(xx)%10+'0';
  1505. conv[6]=0;
  1506. return conv;
  1507. }
  1508. // Convert float to string with 123.4 format
  1509. char *ftostr31ns(const float &x)
  1510. {
  1511. int xx=x*10;
  1512. //conv[0]=(xx>=0)?'+':'-';
  1513. xx=abs(xx);
  1514. conv[0]=(xx/1000)%10+'0';
  1515. conv[1]=(xx/100)%10+'0';
  1516. conv[2]=(xx/10)%10+'0';
  1517. conv[3]='.';
  1518. conv[4]=(xx)%10+'0';
  1519. conv[5]=0;
  1520. return conv;
  1521. }
  1522. char *ftostr32(const float &x)
  1523. {
  1524. long xx=x*100;
  1525. if (xx >= 0)
  1526. conv[0]=(xx/10000)%10+'0';
  1527. else
  1528. conv[0]='-';
  1529. xx=abs(xx);
  1530. conv[1]=(xx/1000)%10+'0';
  1531. conv[2]=(xx/100)%10+'0';
  1532. conv[3]='.';
  1533. conv[4]=(xx/10)%10+'0';
  1534. conv[5]=(xx)%10+'0';
  1535. conv[6]=0;
  1536. return conv;
  1537. }
  1538. // Convert float to string with 1.234 format
  1539. char *ftostr43(const float &x)
  1540. {
  1541. long xx = x * 1000;
  1542. if (xx >= 0)
  1543. conv[0] = (xx / 1000) % 10 + '0';
  1544. else
  1545. conv[0] = '-';
  1546. xx = abs(xx);
  1547. conv[1] = '.';
  1548. conv[2] = (xx / 100) % 10 + '0';
  1549. conv[3] = (xx / 10) % 10 + '0';
  1550. conv[4] = (xx) % 10 + '0';
  1551. conv[5] = 0;
  1552. return conv;
  1553. }
  1554. //Float to string with 1.23 format
  1555. char *ftostr12ns(const float &x)
  1556. {
  1557. long xx=x*100;
  1558. xx=abs(xx);
  1559. conv[0]=(xx/100)%10+'0';
  1560. conv[1]='.';
  1561. conv[2]=(xx/10)%10+'0';
  1562. conv[3]=(xx)%10+'0';
  1563. conv[4]=0;
  1564. return conv;
  1565. }
  1566. // convert float to space-padded string with -_23.4_ format
  1567. char *ftostr32sp(const float &x) {
  1568. long xx = abs(x * 100);
  1569. uint8_t dig;
  1570. if (x < 0) { // negative val = -_0
  1571. conv[0] = '-';
  1572. dig = (xx / 1000) % 10;
  1573. conv[1] = dig ? '0' + dig : ' ';
  1574. }
  1575. else { // positive val = __0
  1576. dig = (xx / 10000) % 10;
  1577. if (dig) {
  1578. conv[0] = '0' + dig;
  1579. conv[1] = '0' + (xx / 1000) % 10;
  1580. }
  1581. else {
  1582. conv[0] = ' ';
  1583. dig = (xx / 1000) % 10;
  1584. conv[1] = dig ? '0' + dig : ' ';
  1585. }
  1586. }
  1587. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1588. dig = xx % 10;
  1589. if (dig) { // 2 decimal places
  1590. conv[5] = '0' + dig;
  1591. conv[4] = '0' + (xx / 10) % 10;
  1592. conv[3] = '.';
  1593. }
  1594. else { // 1 or 0 decimal place
  1595. dig = (xx / 10) % 10;
  1596. if (dig) {
  1597. conv[4] = '0' + dig;
  1598. conv[3] = '.';
  1599. }
  1600. else {
  1601. conv[3] = conv[4] = ' ';
  1602. }
  1603. conv[5] = ' ';
  1604. }
  1605. conv[6] = '\0';
  1606. return conv;
  1607. }
  1608. char *itostr31(const int &xx)
  1609. {
  1610. conv[0]=(xx>=0)?'+':'-';
  1611. conv[1]=(xx/1000)%10+'0';
  1612. conv[2]=(xx/100)%10+'0';
  1613. conv[3]=(xx/10)%10+'0';
  1614. conv[4]='.';
  1615. conv[5]=(xx)%10+'0';
  1616. conv[6]=0;
  1617. return conv;
  1618. }
  1619. // Convert int to rj string with 123 or -12 format
  1620. char *itostr3(const int &x)
  1621. {
  1622. int xx = x;
  1623. if (xx < 0) {
  1624. conv[0]='-';
  1625. xx = -xx;
  1626. } else if (xx >= 100)
  1627. conv[0]=(xx/100)%10+'0';
  1628. else
  1629. conv[0]=' ';
  1630. if (xx >= 10)
  1631. conv[1]=(xx/10)%10+'0';
  1632. else
  1633. conv[1]=' ';
  1634. conv[2]=(xx)%10+'0';
  1635. conv[3]=0;
  1636. return conv;
  1637. }
  1638. // Convert int to lj string with 123 format
  1639. char *itostr3left(const int &xx)
  1640. {
  1641. if (xx >= 100)
  1642. {
  1643. conv[0]=(xx/100)%10+'0';
  1644. conv[1]=(xx/10)%10+'0';
  1645. conv[2]=(xx)%10+'0';
  1646. conv[3]=0;
  1647. }
  1648. else if (xx >= 10)
  1649. {
  1650. conv[0]=(xx/10)%10+'0';
  1651. conv[1]=(xx)%10+'0';
  1652. conv[2]=0;
  1653. }
  1654. else
  1655. {
  1656. conv[0]=(xx)%10+'0';
  1657. conv[1]=0;
  1658. }
  1659. return conv;
  1660. }
  1661. // Convert int to rj string with 1234 format
  1662. char *itostr4(const int &xx) {
  1663. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1664. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1665. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1666. conv[3] = xx % 10 + '0';
  1667. conv[4] = 0;
  1668. return conv;
  1669. }
  1670. // Convert float to rj string with 12345 format
  1671. char *ftostr5(const float &x) {
  1672. long xx = abs(x);
  1673. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  1674. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1675. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1676. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1677. conv[4] = xx % 10 + '0';
  1678. conv[5] = 0;
  1679. return conv;
  1680. }
  1681. // Convert float to string with +1234.5 format
  1682. char *ftostr51(const float &x)
  1683. {
  1684. long xx=x*10;
  1685. conv[0]=(xx>=0)?'+':'-';
  1686. xx=abs(xx);
  1687. conv[1]=(xx/10000)%10+'0';
  1688. conv[2]=(xx/1000)%10+'0';
  1689. conv[3]=(xx/100)%10+'0';
  1690. conv[4]=(xx/10)%10+'0';
  1691. conv[5]='.';
  1692. conv[6]=(xx)%10+'0';
  1693. conv[7]=0;
  1694. return conv;
  1695. }
  1696. // Convert float to string with +123.45 format
  1697. char *ftostr52(const float &x)
  1698. {
  1699. long xx=x*100;
  1700. conv[0]=(xx>=0)?'+':'-';
  1701. xx=abs(xx);
  1702. conv[1]=(xx/10000)%10+'0';
  1703. conv[2]=(xx/1000)%10+'0';
  1704. conv[3]=(xx/100)%10+'0';
  1705. conv[4]='.';
  1706. conv[5]=(xx/10)%10+'0';
  1707. conv[6]=(xx)%10+'0';
  1708. conv[7]=0;
  1709. return conv;
  1710. }
  1711. // Callback for after editing PID i value
  1712. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  1713. void copy_and_scalePID_i()
  1714. {
  1715. #ifdef PIDTEMP
  1716. PID_PARAM(Ki, pid_current_extruder) = scalePID_i(raw_Ki);
  1717. updatePID();
  1718. #endif
  1719. }
  1720. // Callback for after editing PID d value
  1721. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  1722. void copy_and_scalePID_d()
  1723. {
  1724. #ifdef PIDTEMP
  1725. PID_PARAM(Kd, pid_current_extruder) = scalePID_d(raw_Kd);
  1726. updatePID();
  1727. #endif
  1728. }
  1729. #endif //ULTRA_LCD