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

ultralcd.cpp 30KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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. /* Configuration settings */
  11. int plaPreheatHotendTemp;
  12. int plaPreheatHPBTemp;
  13. int plaPreheatFanSpeed;
  14. int absPreheatHotendTemp;
  15. int absPreheatHPBTemp;
  16. int absPreheatFanSpeed;
  17. /* !Configuration settings */
  18. //Function pointer to menu functions.
  19. typedef void (*menuFunc_t)();
  20. uint8_t lcd_status_message_level;
  21. char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
  22. #include "ultralcd_implementation_hitachi_HD44780.h"
  23. /** forward declerations **/
  24. /* Different menus */
  25. static void lcd_status_screen();
  26. #ifdef ULTIPANEL
  27. static void lcd_main_menu();
  28. static void lcd_tune_menu();
  29. static void lcd_prepare_menu();
  30. static void lcd_move_menu();
  31. static void lcd_control_menu();
  32. static void lcd_control_temperature_menu();
  33. static void lcd_control_temperature_preheat_pla_settings_menu();
  34. static void lcd_control_temperature_preheat_abs_settings_menu();
  35. static void lcd_control_motion_menu();
  36. static void lcd_control_retract_menu();
  37. static void lcd_sdcard_menu();
  38. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audiable feedback that something has happend
  39. /* Different types of actions that can be used in menuitems. */
  40. static void menu_action_back(menuFunc_t data);
  41. static void menu_action_submenu(menuFunc_t data);
  42. static void menu_action_gcode(const char* pgcode);
  43. static void menu_action_function(menuFunc_t data);
  44. static void menu_action_sdfile(const char* filename, char* longFilename);
  45. static void menu_action_sddirectory(const char* filename, char* longFilename);
  46. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  47. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  48. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  49. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  50. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  51. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  52. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  53. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  54. #define ENCODER_STEPS_PER_MENU_ITEM 5
  55. /* Helper macros for menus */
  56. #define START_MENU() do { \
  57. if (encoderPosition > 0x8000) encoderPosition = 0; \
  58. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  59. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  60. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  61. _menuItemNr = 0;
  62. #define MENU_ITEM(type, label, args...) do { \
  63. if (_menuItemNr == _lineNr) { \
  64. if (lcdDrawUpdate) { \
  65. const char* _label_pstr = PSTR(label); \
  66. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  67. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  68. }else{\
  69. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  70. }\
  71. }\
  72. if (LCD_CLICKED && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  73. lcd_quick_feedback(); \
  74. menu_action_ ## type ( args ); \
  75. return;\
  76. }\
  77. }\
  78. _menuItemNr++;\
  79. } while(0)
  80. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  81. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  82. #define END_MENU() \
  83. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  84. 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; } \
  85. } } while(0)
  86. /** Used variables to keep track of the menu */
  87. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  88. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  89. uint32_t blocking_enc;
  90. uint8_t lastEncoderBits;
  91. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  92. uint32_t encoderPosition;
  93. #if (SDCARDDETECT > -1)
  94. bool lcd_oldcardstatus;
  95. #endif
  96. #endif//ULTIPANEL
  97. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  98. uint32_t lcd_next_update_millis;
  99. uint8_t lcd_status_update_delay;
  100. 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 atleast 1 full redraw (first redraw is partial) */
  101. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  102. menuFunc_t prevMenu = NULL;
  103. uint16_t prevEncoderPosition;
  104. //Variables used when editing values.
  105. const char* editLabel;
  106. void* editValue;
  107. int32_t minEditValue, maxEditValue;
  108. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependend */
  109. static void lcd_status_screen()
  110. {
  111. if (lcd_status_update_delay)
  112. lcd_status_update_delay--;
  113. else
  114. lcdDrawUpdate = 1;
  115. if (lcdDrawUpdate)
  116. {
  117. lcd_implementation_status_screen();
  118. 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 */
  119. }
  120. #ifdef ULTIPANEL
  121. if (LCD_CLICKED)
  122. {
  123. currentMenu = lcd_main_menu;
  124. lcd_quick_feedback();
  125. }
  126. feedmultiply += int(encoderPosition);
  127. encoderPosition = 0;
  128. if (feedmultiply < 10)
  129. feedmultiply = 10;
  130. if (feedmultiply > 999)
  131. feedmultiply = 999;
  132. #endif//ULTIPANEL
  133. }
  134. #ifdef ULTIPANEL
  135. static void lcd_return_to_status()
  136. {
  137. encoderPosition = 0;
  138. currentMenu = lcd_status_screen;
  139. }
  140. static void lcd_sdcard_pause()
  141. {
  142. card.pauseSDPrint();
  143. }
  144. static void lcd_sdcard_resume()
  145. {
  146. card.startFileprint();
  147. }
  148. static void lcd_sdcard_stop()
  149. {
  150. card.sdprinting = false;
  151. card.closefile();
  152. quickStop();
  153. if(SD_FINISHED_STEPPERRELEASE)
  154. {
  155. enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
  156. }
  157. autotempShutdown();
  158. }
  159. /* Menu implementation */
  160. static void lcd_main_menu()
  161. {
  162. START_MENU();
  163. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  164. if (movesplanned() || IS_SD_PRINTING)
  165. {
  166. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  167. }else{
  168. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  169. }
  170. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  171. #ifdef SDSUPPORT
  172. if (card.cardOK)
  173. {
  174. if (card.isFileOpen())
  175. {
  176. if (card.sdprinting)
  177. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  178. else
  179. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  180. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  181. }else{
  182. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  183. #if SDCARDDETECT < 1
  184. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  185. #endif
  186. }
  187. }else{
  188. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  189. #if SDCARDDETECT < 1
  190. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  191. #endif
  192. }
  193. #endif
  194. END_MENU();
  195. }
  196. #ifdef SDSUPPORT
  197. static void lcd_autostart_sd()
  198. {
  199. card.lastnr=0;
  200. card.setroot();
  201. card.checkautostart(true);
  202. }
  203. #endif
  204. void lcd_preheat_pla()
  205. {
  206. setTargetHotend0(plaPreheatHotendTemp);
  207. setTargetHotend1(plaPreheatHotendTemp);
  208. setTargetHotend2(plaPreheatHotendTemp);
  209. setTargetBed(plaPreheatHPBTemp);
  210. fanSpeed = plaPreheatFanSpeed;
  211. lcd_return_to_status();
  212. }
  213. void lcd_preheat_abs()
  214. {
  215. setTargetHotend0(absPreheatHotendTemp);
  216. setTargetHotend1(absPreheatHotendTemp);
  217. setTargetHotend2(absPreheatHotendTemp);
  218. setTargetBed(absPreheatHPBTemp);
  219. fanSpeed = absPreheatFanSpeed;
  220. lcd_return_to_status();
  221. }
  222. static void lcd_tune_menu()
  223. {
  224. START_MENU();
  225. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  226. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);
  227. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  228. #if TEMP_SENSOR_1 != 0
  229. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  230. #endif
  231. #if TEMP_SENSOR_2 != 0
  232. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  233. #endif
  234. #if TEMP_SENSOR_BED != 0
  235. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  236. #endif
  237. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  238. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);
  239. #ifdef FILAMENTCHANGEENABLE
  240. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  241. #endif
  242. END_MENU();
  243. }
  244. static void lcd_prepare_menu()
  245. {
  246. START_MENU();
  247. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  248. #ifdef SDSUPPORT
  249. //MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  250. #endif
  251. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  252. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  253. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  254. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla);
  255. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs);
  256. MENU_ITEM(gcode, MSG_COOLDOWN, PSTR("M104 S0\nM140 S0"));
  257. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  258. END_MENU();
  259. }
  260. float move_menu_scale;
  261. static void lcd_move_menu_axis();
  262. static void lcd_move_x()
  263. {
  264. if (encoderPosition != 0)
  265. {
  266. current_position[X_AXIS] += float((int)encoderPosition) * move_menu_scale;
  267. if (current_position[X_AXIS] < X_MIN_POS)
  268. current_position[X_AXIS] = X_MIN_POS;
  269. if (current_position[X_AXIS] > X_MAX_POS)
  270. current_position[X_AXIS] = X_MAX_POS;
  271. encoderPosition = 0;
  272. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  273. lcdDrawUpdate = 1;
  274. }
  275. if (lcdDrawUpdate)
  276. {
  277. lcd_implementation_drawedit(PSTR("X"), ftostr31(current_position[X_AXIS]));
  278. }
  279. if (LCD_CLICKED)
  280. {
  281. lcd_quick_feedback();
  282. currentMenu = lcd_move_menu_axis;
  283. encoderPosition = 0;
  284. }
  285. }
  286. static void lcd_move_y()
  287. {
  288. if (encoderPosition != 0)
  289. {
  290. current_position[Y_AXIS] += float((int)encoderPosition) * move_menu_scale;
  291. if (current_position[Y_AXIS] < Y_MIN_POS)
  292. current_position[Y_AXIS] = Y_MIN_POS;
  293. if (current_position[Y_AXIS] > Y_MAX_POS)
  294. current_position[Y_AXIS] = Y_MAX_POS;
  295. encoderPosition = 0;
  296. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  297. lcdDrawUpdate = 1;
  298. }
  299. if (lcdDrawUpdate)
  300. {
  301. lcd_implementation_drawedit(PSTR("Y"), ftostr31(current_position[Y_AXIS]));
  302. }
  303. if (LCD_CLICKED)
  304. {
  305. lcd_quick_feedback();
  306. currentMenu = lcd_move_menu_axis;
  307. encoderPosition = 0;
  308. }
  309. }
  310. static void lcd_move_z()
  311. {
  312. if (encoderPosition != 0)
  313. {
  314. current_position[Z_AXIS] += float((int)encoderPosition) * move_menu_scale;
  315. if (current_position[Z_AXIS] < Z_MIN_POS)
  316. current_position[Z_AXIS] = Z_MIN_POS;
  317. if (current_position[Z_AXIS] > Z_MAX_POS)
  318. current_position[Z_AXIS] = Z_MAX_POS;
  319. encoderPosition = 0;
  320. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 60, active_extruder);
  321. lcdDrawUpdate = 1;
  322. }
  323. if (lcdDrawUpdate)
  324. {
  325. lcd_implementation_drawedit(PSTR("Z"), ftostr31(current_position[Z_AXIS]));
  326. }
  327. if (LCD_CLICKED)
  328. {
  329. lcd_quick_feedback();
  330. currentMenu = lcd_move_menu_axis;
  331. encoderPosition = 0;
  332. }
  333. }
  334. static void lcd_move_e()
  335. {
  336. if (encoderPosition != 0)
  337. {
  338. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  339. encoderPosition = 0;
  340. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 20, active_extruder);
  341. lcdDrawUpdate = 1;
  342. }
  343. if (lcdDrawUpdate)
  344. {
  345. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  346. }
  347. if (LCD_CLICKED)
  348. {
  349. lcd_quick_feedback();
  350. currentMenu = lcd_move_menu_axis;
  351. encoderPosition = 0;
  352. }
  353. }
  354. static void lcd_move_menu_axis()
  355. {
  356. START_MENU();
  357. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  358. MENU_ITEM(submenu, "Move X", lcd_move_x);
  359. MENU_ITEM(submenu, "Move Y", lcd_move_y);
  360. if (move_menu_scale < 10.0)
  361. {
  362. MENU_ITEM(submenu, "Move Z", lcd_move_z);
  363. MENU_ITEM(submenu, "Extruder", lcd_move_e);
  364. }
  365. END_MENU();
  366. }
  367. static void lcd_move_menu_10mm()
  368. {
  369. move_menu_scale = 10.0;
  370. lcd_move_menu_axis();
  371. }
  372. static void lcd_move_menu_1mm()
  373. {
  374. move_menu_scale = 1.0;
  375. lcd_move_menu_axis();
  376. }
  377. static void lcd_move_menu_01mm()
  378. {
  379. move_menu_scale = 0.1;
  380. lcd_move_menu_axis();
  381. }
  382. static void lcd_move_menu()
  383. {
  384. START_MENU();
  385. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  386. MENU_ITEM(submenu, "Move 10mm", lcd_move_menu_10mm);
  387. MENU_ITEM(submenu, "Move 1mm", lcd_move_menu_1mm);
  388. MENU_ITEM(submenu, "Move 0.1mm", lcd_move_menu_01mm);
  389. //TODO:X,Y,Z,E
  390. END_MENU();
  391. }
  392. static void lcd_control_menu()
  393. {
  394. START_MENU();
  395. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  396. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  397. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  398. #ifdef FWRETRACT
  399. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  400. #endif
  401. #ifdef EEPROM_SETTINGS
  402. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  403. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  404. #endif
  405. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  406. END_MENU();
  407. }
  408. static void lcd_control_temperature_menu()
  409. {
  410. START_MENU();
  411. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  412. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  413. #if TEMP_SENSOR_1 != 0
  414. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  415. #endif
  416. #if TEMP_SENSOR_2 != 0
  417. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  418. #endif
  419. #if TEMP_SENSOR_BED != 0
  420. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  421. #endif
  422. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  423. #ifdef AUTOTEMP
  424. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  425. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  426. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  427. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  428. #endif
  429. #ifdef PIDTEMP
  430. MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
  431. //TODO, I and D should have a PID_dT multiplier (Ki = PID_I * PID_dT, Kd = PID_D / PID_dT)
  432. MENU_ITEM_EDIT(float52, MSG_PID_I, &Ki, 1, 9990);
  433. MENU_ITEM_EDIT(float52, MSG_PID_D, &Kd, 1, 9990);
  434. # ifdef PID_ADD_EXTRUSION_RATE
  435. MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
  436. # endif//PID_ADD_EXTRUSION_RATE
  437. #endif//PIDTEMP
  438. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  439. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  440. END_MENU();
  441. }
  442. static void lcd_control_temperature_preheat_pla_settings_menu()
  443. {
  444. START_MENU();
  445. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  446. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  447. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  448. #if TEMP_SENSOR_BED != 0
  449. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  450. #endif
  451. #ifdef EEPROM_SETTINGS
  452. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  453. #endif
  454. END_MENU();
  455. }
  456. static void lcd_control_temperature_preheat_abs_settings_menu()
  457. {
  458. START_MENU();
  459. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  460. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  461. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  462. #if TEMP_SENSOR_BED != 0
  463. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  464. #endif
  465. #ifdef EEPROM_SETTINGS
  466. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  467. #endif
  468. END_MENU();
  469. }
  470. static void lcd_control_motion_menu()
  471. {
  472. START_MENU();
  473. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  474. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
  475. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  476. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  477. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  478. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  479. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  480. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  481. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  482. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000);
  483. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000);
  484. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000);
  485. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000);
  486. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  487. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  488. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  489. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  490. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  491. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  492. MENU_ITEM_EDIT(bool, "Endstop abort", &abort_on_endstop_hit);
  493. #endif
  494. END_MENU();
  495. }
  496. #ifdef FWRETRACT
  497. static void lcd_control_retract_menu()
  498. {
  499. START_MENU();
  500. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  501. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  502. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  503. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  504. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  505. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  506. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  507. END_MENU();
  508. }
  509. #endif
  510. #if SDCARDDETECT == -1
  511. static void lcd_sd_refresh()
  512. {
  513. card.initsd();
  514. currentMenuViewOffset = 0;
  515. }
  516. #endif
  517. static void lcd_sd_updir()
  518. {
  519. card.updir();
  520. currentMenuViewOffset = 0;
  521. }
  522. void lcd_sdcard_menu()
  523. {
  524. uint16_t fileCnt = card.getnrfilenames();
  525. START_MENU();
  526. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  527. card.getWorkDirName();
  528. if(card.filename[0]=='/')
  529. {
  530. #if SDCARDDETECT == -1
  531. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  532. #endif
  533. }else{
  534. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  535. }
  536. for(uint16_t i=0;i<fileCnt;i++)
  537. {
  538. if (_menuItemNr == _lineNr)
  539. {
  540. card.getfilename(i);
  541. if (card.filenameIsDir)
  542. {
  543. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  544. }else{
  545. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  546. }
  547. }else{
  548. MENU_ITEM_DUMMY();
  549. }
  550. }
  551. END_MENU();
  552. }
  553. #define menu_edit_type(_type, _name, _strFunc, scale) \
  554. void menu_edit_ ## _name () \
  555. { \
  556. if ((int32_t)encoderPosition < minEditValue) \
  557. encoderPosition = minEditValue; \
  558. if ((int32_t)encoderPosition > maxEditValue) \
  559. encoderPosition = maxEditValue; \
  560. if (lcdDrawUpdate) \
  561. lcd_implementation_drawedit(editLabel, _strFunc(((_type)encoderPosition) / scale)); \
  562. if (LCD_CLICKED) \
  563. { \
  564. *((_type*)editValue) = ((_type)encoderPosition) / scale; \
  565. lcd_quick_feedback(); \
  566. currentMenu = prevMenu; \
  567. encoderPosition = prevEncoderPosition; \
  568. } \
  569. } \
  570. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  571. { \
  572. prevMenu = currentMenu; \
  573. prevEncoderPosition = encoderPosition; \
  574. \
  575. lcdDrawUpdate = 2; \
  576. currentMenu = menu_edit_ ## _name; \
  577. \
  578. editLabel = pstr; \
  579. editValue = ptr; \
  580. minEditValue = minValue * scale; \
  581. maxEditValue = maxValue * scale; \
  582. encoderPosition = (*ptr) * scale; \
  583. }
  584. menu_edit_type(int, int3, itostr3, 1)
  585. menu_edit_type(float, float3, ftostr3, 1)
  586. menu_edit_type(float, float32, ftostr32, 100)
  587. menu_edit_type(float, float5, ftostr5, 0.01)
  588. menu_edit_type(float, float51, ftostr51, 10)
  589. menu_edit_type(float, float52, ftostr52, 100)
  590. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  591. /** End of menus **/
  592. static void lcd_quick_feedback()
  593. {
  594. lcdDrawUpdate = 2;
  595. blocking_enc = millis() + 500;
  596. lcd_implementation_quick_feedback();
  597. }
  598. /** Menu action functions **/
  599. static void menu_action_back(menuFunc_t data)
  600. {
  601. currentMenu = data;
  602. encoderPosition = 0;
  603. }
  604. static void menu_action_submenu(menuFunc_t data)
  605. {
  606. currentMenu = data;
  607. encoderPosition = 0;
  608. }
  609. static void menu_action_gcode(const char* pgcode)
  610. {
  611. enquecommand_P(pgcode);
  612. }
  613. static void menu_action_function(menuFunc_t data)
  614. {
  615. (*data)();
  616. }
  617. static void menu_action_sdfile(const char* filename, char* longFilename)
  618. {
  619. char cmd[30];
  620. char* c;
  621. sprintf_P(cmd, PSTR("M23 %s"), filename);
  622. for(c = &cmd[4]; *c; c++)
  623. *c = tolower(*c);
  624. enquecommand(cmd);
  625. enquecommand_P(PSTR("M24"));
  626. lcd_return_to_status();
  627. }
  628. static void menu_action_sddirectory(const char* filename, char* longFilename)
  629. {
  630. card.chdir(filename);
  631. encoderPosition = 0;
  632. }
  633. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  634. {
  635. *ptr = !(*ptr);
  636. }
  637. #endif//ULTIPANEL
  638. /** LCD API **/
  639. void lcd_init()
  640. {
  641. lcd_implementation_init();
  642. #ifdef NEWPANEL
  643. pinMode(BTN_EN1,INPUT);
  644. pinMode(BTN_EN2,INPUT);
  645. pinMode(BTN_ENC,INPUT);
  646. pinMode(SDCARDDETECT,INPUT);
  647. WRITE(BTN_EN1,HIGH);
  648. WRITE(BTN_EN2,HIGH);
  649. WRITE(BTN_ENC,HIGH);
  650. #else
  651. pinMode(SHIFT_CLK,OUTPUT);
  652. pinMode(SHIFT_LD,OUTPUT);
  653. pinMode(SHIFT_EN,OUTPUT);
  654. pinMode(SHIFT_OUT,INPUT);
  655. WRITE(SHIFT_OUT,HIGH);
  656. WRITE(SHIFT_LD,HIGH);
  657. WRITE(SHIFT_EN,LOW);
  658. #endif//!NEWPANEL
  659. #if (SDCARDDETECT > -1)
  660. WRITE(SDCARDDETECT, HIGH);
  661. lcd_oldcardstatus = IS_SD_INSERTED;
  662. #endif//(SDCARDDETECT > -1)
  663. lcd_buttons_update();
  664. encoderDiff = 0;
  665. }
  666. void lcd_update()
  667. {
  668. static unsigned long timeoutToStatus = 0;
  669. lcd_buttons_update();
  670. #ifdef LCD_HAS_EXTRA_BUTTONS
  671. buttons |= lcd_read_extra_buttons(); // buttons which take too long to read in interrupt context
  672. #endif
  673. #if (SDCARDDETECT > -1)
  674. if((IS_SD_INSERTED != lcd_oldcardstatus))
  675. {
  676. lcdDrawUpdate = 2;
  677. lcd_oldcardstatus = IS_SD_INSERTED;
  678. lcd_implementation_init(); // to maybe revive the lcd if static electricty killed it.
  679. if(lcd_oldcardstatus)
  680. {
  681. card.initsd();
  682. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  683. }
  684. else
  685. {
  686. card.release();
  687. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  688. }
  689. }
  690. #endif//CARDINSERTED
  691. if (lcd_next_update_millis < millis())
  692. {
  693. #ifdef ULTIPANEL
  694. if (encoderDiff)
  695. {
  696. lcdDrawUpdate = 1;
  697. encoderPosition += encoderDiff;
  698. encoderDiff = 0;
  699. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  700. }
  701. if (LCD_CLICKED)
  702. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  703. #endif//ULTIPANEL
  704. (*currentMenu)();
  705. #ifdef ULTIPANEL
  706. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  707. {
  708. lcd_return_to_status();
  709. lcdDrawUpdate = 2;
  710. }
  711. #endif//ULTIPANEL
  712. if (lcdDrawUpdate == 2)
  713. lcd_implementation_clear();
  714. if (lcdDrawUpdate)
  715. lcdDrawUpdate--;
  716. lcd_next_update_millis = millis() + 100;
  717. }
  718. }
  719. void lcd_setstatus(const char* message)
  720. {
  721. if (lcd_status_message_level > 0)
  722. return;
  723. strncpy(lcd_status_message, message, LCD_WIDTH);
  724. lcdDrawUpdate = 2;
  725. }
  726. void lcd_setstatuspgm(const char* message)
  727. {
  728. if (lcd_status_message_level > 0)
  729. return;
  730. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  731. lcdDrawUpdate = 2;
  732. }
  733. void lcd_setalertstatuspgm(const char* message)
  734. {
  735. lcd_setstatuspgm(message);
  736. lcd_status_message_level = 1;
  737. #ifdef ULTIPANEL
  738. lcd_return_to_status();
  739. #endif//ULTIPANEL
  740. }
  741. void lcd_reset_alert_level()
  742. {
  743. lcd_status_message_level = 0;
  744. }
  745. #ifdef ULTIPANEL
  746. /* Warning: This function is called from interrupt context */
  747. void lcd_buttons_update()
  748. {
  749. #ifdef NEWPANEL
  750. uint8_t newbutton=0;
  751. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  752. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  753. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  754. newbutton |= EN_C;
  755. buttons = newbutton;
  756. #else //read it from the shift register
  757. uint8_t newbutton=0;
  758. WRITE(SHIFT_LD,LOW);
  759. WRITE(SHIFT_LD,HIGH);
  760. unsigned char tmp_buttons=0;
  761. for(int8_t i=0;i<8;i++)
  762. {
  763. newbutton = newbutton>>1;
  764. if(READ(SHIFT_OUT))
  765. newbutton|=(1<<7);
  766. WRITE(SHIFT_CLK,HIGH);
  767. WRITE(SHIFT_CLK,LOW);
  768. }
  769. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  770. #endif//!NEWPANEL
  771. //manage encoder rotation
  772. uint8_t enc=0;
  773. if(buttons&EN_A)
  774. enc|=(1<<0);
  775. if(buttons&EN_B)
  776. enc|=(1<<1);
  777. if(enc != lastEncoderBits)
  778. {
  779. switch(enc)
  780. {
  781. case encrot0:
  782. if(lastEncoderBits==encrot3)
  783. encoderDiff++;
  784. else if(lastEncoderBits==encrot1)
  785. encoderDiff--;
  786. break;
  787. case encrot1:
  788. if(lastEncoderBits==encrot0)
  789. encoderDiff++;
  790. else if(lastEncoderBits==encrot2)
  791. encoderDiff--;
  792. break;
  793. case encrot2:
  794. if(lastEncoderBits==encrot1)
  795. encoderDiff++;
  796. else if(lastEncoderBits==encrot3)
  797. encoderDiff--;
  798. break;
  799. case encrot3:
  800. if(lastEncoderBits==encrot2)
  801. encoderDiff++;
  802. else if(lastEncoderBits==encrot0)
  803. encoderDiff--;
  804. break;
  805. }
  806. }
  807. lastEncoderBits = enc;
  808. }
  809. #endif//ULTIPANEL
  810. bool lcd_clicked()
  811. {
  812. return LCD_CLICKED;
  813. }
  814. /********************************/
  815. /** Float conversion utilities **/
  816. /********************************/
  817. // convert float to string with +123.4 format
  818. char conv[8];
  819. char *ftostr3(const float &x)
  820. {
  821. return itostr3((int)x);
  822. }
  823. char *itostr2(const uint8_t &x)
  824. {
  825. //sprintf(conv,"%5.1f",x);
  826. int xx=x;
  827. conv[0]=(xx/10)%10+'0';
  828. conv[1]=(xx)%10+'0';
  829. conv[2]=0;
  830. return conv;
  831. }
  832. // convert float to string with +123.4 format
  833. char *ftostr31(const float &x)
  834. {
  835. int xx=x*10;
  836. conv[0]=(xx>=0)?'+':'-';
  837. xx=abs(xx);
  838. conv[1]=(xx/1000)%10+'0';
  839. conv[2]=(xx/100)%10+'0';
  840. conv[3]=(xx/10)%10+'0';
  841. conv[4]='.';
  842. conv[5]=(xx)%10+'0';
  843. conv[6]=0;
  844. return conv;
  845. }
  846. char *ftostr32(const float &x)
  847. {
  848. long xx=x*100;
  849. if (xx >= 0)
  850. conv[0]=(xx/10000)%10+'0';
  851. else
  852. conv[0]='-';
  853. xx=abs(xx);
  854. conv[1]=(xx/1000)%10+'0';
  855. conv[2]=(xx/100)%10+'0';
  856. conv[3]='.';
  857. conv[4]=(xx/10)%10+'0';
  858. conv[5]=(xx)%10+'0';
  859. conv[6]=0;
  860. return conv;
  861. }
  862. char *itostr31(const int &xx)
  863. {
  864. conv[0]=(xx>=0)?'+':'-';
  865. conv[1]=(xx/1000)%10+'0';
  866. conv[2]=(xx/100)%10+'0';
  867. conv[3]=(xx/10)%10+'0';
  868. conv[4]='.';
  869. conv[5]=(xx)%10+'0';
  870. conv[6]=0;
  871. return conv;
  872. }
  873. char *itostr3(const int &xx)
  874. {
  875. if (xx >= 100)
  876. conv[0]=(xx/100)%10+'0';
  877. else
  878. conv[0]=' ';
  879. if (xx >= 10)
  880. conv[1]=(xx/10)%10+'0';
  881. else
  882. conv[1]=' ';
  883. conv[2]=(xx)%10+'0';
  884. conv[3]=0;
  885. return conv;
  886. }
  887. char *itostr3left(const int &xx)
  888. {
  889. if (xx >= 100)
  890. {
  891. conv[0]=(xx/100)%10+'0';
  892. conv[1]=(xx/10)%10+'0';
  893. conv[2]=(xx)%10+'0';
  894. conv[3]=0;
  895. }
  896. else if (xx >= 10)
  897. {
  898. conv[0]=(xx/10)%10+'0';
  899. conv[1]=(xx)%10+'0';
  900. conv[2]=0;
  901. }
  902. else
  903. {
  904. conv[0]=(xx)%10+'0';
  905. conv[1]=0;
  906. }
  907. return conv;
  908. }
  909. char *itostr4(const int &xx)
  910. {
  911. if (xx >= 1000)
  912. conv[0]=(xx/1000)%10+'0';
  913. else
  914. conv[0]=' ';
  915. if (xx >= 100)
  916. conv[1]=(xx/100)%10+'0';
  917. else
  918. conv[1]=' ';
  919. if (xx >= 10)
  920. conv[2]=(xx/10)%10+'0';
  921. else
  922. conv[2]=' ';
  923. conv[3]=(xx)%10+'0';
  924. conv[4]=0;
  925. return conv;
  926. }
  927. // convert float to string with 12345 format
  928. char *ftostr5(const float &x)
  929. {
  930. long xx=abs(x);
  931. if (xx >= 10000)
  932. conv[0]=(xx/10000)%10+'0';
  933. else
  934. conv[0]=' ';
  935. if (xx >= 1000)
  936. conv[1]=(xx/1000)%10+'0';
  937. else
  938. conv[1]=' ';
  939. if (xx >= 100)
  940. conv[2]=(xx/100)%10+'0';
  941. else
  942. conv[2]=' ';
  943. if (xx >= 10)
  944. conv[3]=(xx/10)%10+'0';
  945. else
  946. conv[3]=' ';
  947. conv[4]=(xx)%10+'0';
  948. conv[5]=0;
  949. return conv;
  950. }
  951. // convert float to string with +1234.5 format
  952. char *ftostr51(const float &x)
  953. {
  954. long xx=x*10;
  955. conv[0]=(xx>=0)?'+':'-';
  956. xx=abs(xx);
  957. conv[1]=(xx/10000)%10+'0';
  958. conv[2]=(xx/1000)%10+'0';
  959. conv[3]=(xx/100)%10+'0';
  960. conv[4]=(xx/10)%10+'0';
  961. conv[5]='.';
  962. conv[6]=(xx)%10+'0';
  963. conv[7]=0;
  964. return conv;
  965. }
  966. // convert float to string with +123.45 format
  967. char *ftostr52(const float &x)
  968. {
  969. long xx=x*100;
  970. conv[0]=(xx>=0)?'+':'-';
  971. xx=abs(xx);
  972. conv[1]=(xx/10000)%10+'0';
  973. conv[2]=(xx/1000)%10+'0';
  974. conv[3]=(xx/100)%10+'0';
  975. conv[4]='.';
  976. conv[5]=(xx/10)%10+'0';
  977. conv[6]=(xx)%10+'0';
  978. conv[7]=0;
  979. return conv;
  980. }
  981. #endif //ULTRA_LCD