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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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 (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. }
  184. }else{
  185. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  186. }
  187. #endif
  188. END_MENU();
  189. }
  190. #ifdef SDSUPPORT
  191. static void lcd_autostart_sd()
  192. {
  193. card.lastnr=0;
  194. card.setroot();
  195. card.checkautostart(true);
  196. }
  197. #endif
  198. void lcd_preheat_pla()
  199. {
  200. setTargetHotend0(plaPreheatHotendTemp);
  201. setTargetHotend1(plaPreheatHotendTemp);
  202. setTargetHotend2(plaPreheatHotendTemp);
  203. setTargetBed(plaPreheatHPBTemp);
  204. fanSpeed = plaPreheatFanSpeed;
  205. lcd_return_to_status();
  206. }
  207. void lcd_preheat_abs()
  208. {
  209. setTargetHotend0(absPreheatHotendTemp);
  210. setTargetHotend1(absPreheatHotendTemp);
  211. setTargetHotend2(absPreheatHotendTemp);
  212. setTargetBed(absPreheatHPBTemp);
  213. fanSpeed = absPreheatFanSpeed;
  214. lcd_return_to_status();
  215. }
  216. static void lcd_tune_menu()
  217. {
  218. START_MENU();
  219. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  220. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);
  221. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  222. #if TEMP_SENSOR_1 != 0
  223. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  224. #endif
  225. #if TEMP_SENSOR_2 != 0
  226. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  227. #endif
  228. #if TEMP_SENSOR_BED != 0
  229. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  230. #endif
  231. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  232. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);
  233. #ifdef FILAMENTCHANGEENABLE
  234. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  235. #endif
  236. END_MENU();
  237. }
  238. static void lcd_prepare_menu()
  239. {
  240. START_MENU();
  241. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  242. #ifdef SDSUPPORT
  243. //MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  244. #endif
  245. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  246. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  247. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  248. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla);
  249. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs);
  250. MENU_ITEM(gcode, MSG_COOLDOWN, PSTR("M104 S0\nM140 S0"));
  251. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  252. END_MENU();
  253. }
  254. float move_menu_scale;
  255. static void lcd_move_menu_axis();
  256. static void lcd_move_x()
  257. {
  258. if (encoderPosition != 0)
  259. {
  260. current_position[X_AXIS] += float((int)encoderPosition) * move_menu_scale;
  261. if (current_position[X_AXIS] < X_MIN_POS)
  262. current_position[X_AXIS] = X_MIN_POS;
  263. if (current_position[X_AXIS] > X_MAX_POS)
  264. current_position[X_AXIS] = X_MAX_POS;
  265. encoderPosition = 0;
  266. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  267. lcdDrawUpdate = 1;
  268. }
  269. if (lcdDrawUpdate)
  270. {
  271. lcd_implementation_drawedit(PSTR("X"), ftostr31(current_position[X_AXIS]));
  272. }
  273. if (LCD_CLICKED)
  274. {
  275. lcd_quick_feedback();
  276. currentMenu = lcd_move_menu_axis;
  277. encoderPosition = 0;
  278. }
  279. }
  280. static void lcd_move_y()
  281. {
  282. if (encoderPosition != 0)
  283. {
  284. current_position[Y_AXIS] += float((int)encoderPosition) * move_menu_scale;
  285. if (current_position[Y_AXIS] < Y_MIN_POS)
  286. current_position[Y_AXIS] = Y_MIN_POS;
  287. if (current_position[Y_AXIS] > Y_MAX_POS)
  288. current_position[Y_AXIS] = Y_MAX_POS;
  289. encoderPosition = 0;
  290. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  291. lcdDrawUpdate = 1;
  292. }
  293. if (lcdDrawUpdate)
  294. {
  295. lcd_implementation_drawedit(PSTR("Y"), ftostr31(current_position[Y_AXIS]));
  296. }
  297. if (LCD_CLICKED)
  298. {
  299. lcd_quick_feedback();
  300. currentMenu = lcd_move_menu_axis;
  301. encoderPosition = 0;
  302. }
  303. }
  304. static void lcd_move_z()
  305. {
  306. if (encoderPosition != 0)
  307. {
  308. current_position[Z_AXIS] += float((int)encoderPosition) * move_menu_scale;
  309. if (current_position[Z_AXIS] < Z_MIN_POS)
  310. current_position[Z_AXIS] = Z_MIN_POS;
  311. if (current_position[Z_AXIS] > Z_MAX_POS)
  312. current_position[Z_AXIS] = Z_MAX_POS;
  313. encoderPosition = 0;
  314. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 60, active_extruder);
  315. lcdDrawUpdate = 1;
  316. }
  317. if (lcdDrawUpdate)
  318. {
  319. lcd_implementation_drawedit(PSTR("Z"), ftostr31(current_position[Z_AXIS]));
  320. }
  321. if (LCD_CLICKED)
  322. {
  323. lcd_quick_feedback();
  324. currentMenu = lcd_move_menu_axis;
  325. encoderPosition = 0;
  326. }
  327. }
  328. static void lcd_move_e()
  329. {
  330. if (encoderPosition != 0)
  331. {
  332. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  333. encoderPosition = 0;
  334. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 20, active_extruder);
  335. lcdDrawUpdate = 1;
  336. }
  337. if (lcdDrawUpdate)
  338. {
  339. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  340. }
  341. if (LCD_CLICKED)
  342. {
  343. lcd_quick_feedback();
  344. currentMenu = lcd_move_menu_axis;
  345. encoderPosition = 0;
  346. }
  347. }
  348. static void lcd_move_menu_axis()
  349. {
  350. START_MENU();
  351. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  352. MENU_ITEM(submenu, "Move X", lcd_move_x);
  353. MENU_ITEM(submenu, "Move Y", lcd_move_y);
  354. if (move_menu_scale < 10.0)
  355. {
  356. MENU_ITEM(submenu, "Move Z", lcd_move_z);
  357. MENU_ITEM(submenu, "Extruder", lcd_move_e);
  358. }
  359. END_MENU();
  360. }
  361. static void lcd_move_menu_10mm()
  362. {
  363. move_menu_scale = 10.0;
  364. lcd_move_menu_axis();
  365. }
  366. static void lcd_move_menu_1mm()
  367. {
  368. move_menu_scale = 1.0;
  369. lcd_move_menu_axis();
  370. }
  371. static void lcd_move_menu_01mm()
  372. {
  373. move_menu_scale = 0.1;
  374. lcd_move_menu_axis();
  375. }
  376. static void lcd_move_menu()
  377. {
  378. START_MENU();
  379. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  380. MENU_ITEM(submenu, "Move 10mm", lcd_move_menu_10mm);
  381. MENU_ITEM(submenu, "Move 1mm", lcd_move_menu_1mm);
  382. MENU_ITEM(submenu, "Move 0.1mm", lcd_move_menu_01mm);
  383. //TODO:X,Y,Z,E
  384. END_MENU();
  385. }
  386. static void lcd_control_menu()
  387. {
  388. START_MENU();
  389. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  390. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  391. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  392. #ifdef FWRETRACT
  393. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  394. #endif
  395. #ifdef EEPROM_SETTINGS
  396. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  397. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  398. #endif
  399. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  400. END_MENU();
  401. }
  402. static void lcd_control_temperature_menu()
  403. {
  404. START_MENU();
  405. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  406. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  407. #if TEMP_SENSOR_1 != 0
  408. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  409. #endif
  410. #if TEMP_SENSOR_2 != 0
  411. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  412. #endif
  413. #if TEMP_SENSOR_BED != 0
  414. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  415. #endif
  416. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  417. #ifdef AUTOTEMP
  418. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  419. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  420. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  421. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  422. #endif
  423. #ifdef PIDTEMP
  424. MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
  425. //TODO, I and D should have a PID_dT multiplier (Ki = PID_I * PID_dT, Kd = PID_D / PID_dT)
  426. MENU_ITEM_EDIT(float52, MSG_PID_I, &Ki, 1, 9990);
  427. MENU_ITEM_EDIT(float52, MSG_PID_D, &Kd, 1, 9990);
  428. # ifdef PID_ADD_EXTRUSION_RATE
  429. MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
  430. # endif//PID_ADD_EXTRUSION_RATE
  431. #endif//PIDTEMP
  432. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  433. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  434. END_MENU();
  435. }
  436. static void lcd_control_temperature_preheat_pla_settings_menu()
  437. {
  438. START_MENU();
  439. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  440. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  441. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  442. #if TEMP_SENSOR_BED != 0
  443. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  444. #endif
  445. #ifdef EEPROM_SETTINGS
  446. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  447. #endif
  448. END_MENU();
  449. }
  450. static void lcd_control_temperature_preheat_abs_settings_menu()
  451. {
  452. START_MENU();
  453. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  454. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  455. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  456. #if TEMP_SENSOR_BED != 0
  457. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  458. #endif
  459. #ifdef EEPROM_SETTINGS
  460. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  461. #endif
  462. END_MENU();
  463. }
  464. static void lcd_control_motion_menu()
  465. {
  466. START_MENU();
  467. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  468. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
  469. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  470. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  471. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  472. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  473. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  474. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  475. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  476. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000);
  477. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000);
  478. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000);
  479. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000);
  480. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  481. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  482. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  483. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  484. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  485. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  486. MENU_ITEM_EDIT(bool, "Endstop abort", &abort_on_endstop_hit);
  487. #endif
  488. END_MENU();
  489. }
  490. #ifdef FWRETRACT
  491. static void lcd_control_retract_menu()
  492. {
  493. START_MENU();
  494. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  495. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  496. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  497. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  498. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  499. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  500. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  501. END_MENU();
  502. }
  503. #endif
  504. #if SDCARDDETECT == -1
  505. static void lcd_sd_refresh()
  506. {
  507. card.initsd();
  508. currentMenuViewOffset = 0;
  509. }
  510. #endif
  511. static void lcd_sd_updir()
  512. {
  513. card.updir();
  514. currentMenuViewOffset = 0;
  515. }
  516. void lcd_sdcard_menu()
  517. {
  518. uint16_t fileCnt = card.getnrfilenames();
  519. START_MENU();
  520. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  521. card.getWorkDirName();
  522. if(card.filename[0]=='/')
  523. {
  524. #if SDCARDDETECT == -1
  525. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  526. #endif
  527. }else{
  528. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  529. }
  530. for(uint16_t i=0;i<fileCnt;i++)
  531. {
  532. if (_menuItemNr == _lineNr)
  533. {
  534. card.getfilename(i);
  535. if (card.filenameIsDir)
  536. {
  537. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  538. }else{
  539. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  540. }
  541. }else{
  542. MENU_ITEM_DUMMY();
  543. }
  544. }
  545. END_MENU();
  546. }
  547. #define menu_edit_type(_type, _name, _strFunc, scale) \
  548. void menu_edit_ ## _name () \
  549. { \
  550. if ((int32_t)encoderPosition < minEditValue) \
  551. encoderPosition = minEditValue; \
  552. if ((int32_t)encoderPosition > maxEditValue) \
  553. encoderPosition = maxEditValue; \
  554. if (lcdDrawUpdate) \
  555. lcd_implementation_drawedit(editLabel, _strFunc(((_type)encoderPosition) / scale)); \
  556. if (LCD_CLICKED) \
  557. { \
  558. *((_type*)editValue) = ((_type)encoderPosition) / scale; \
  559. lcd_quick_feedback(); \
  560. currentMenu = prevMenu; \
  561. encoderPosition = prevEncoderPosition; \
  562. } \
  563. } \
  564. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  565. { \
  566. prevMenu = currentMenu; \
  567. prevEncoderPosition = encoderPosition; \
  568. \
  569. lcdDrawUpdate = 2; \
  570. currentMenu = menu_edit_ ## _name; \
  571. \
  572. editLabel = pstr; \
  573. editValue = ptr; \
  574. minEditValue = minValue * scale; \
  575. maxEditValue = maxValue * scale; \
  576. encoderPosition = (*ptr) * scale; \
  577. }
  578. menu_edit_type(int, int3, itostr3, 1)
  579. menu_edit_type(float, float3, ftostr3, 1)
  580. menu_edit_type(float, float32, ftostr32, 100)
  581. menu_edit_type(float, float5, ftostr5, 0.01)
  582. menu_edit_type(float, float51, ftostr51, 10)
  583. menu_edit_type(float, float52, ftostr52, 100)
  584. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  585. /** End of menus **/
  586. static void lcd_quick_feedback()
  587. {
  588. lcdDrawUpdate = 2;
  589. blocking_enc = millis() + 500;
  590. lcd_implementation_quick_feedback();
  591. }
  592. /** Menu action functions **/
  593. static void menu_action_back(menuFunc_t data)
  594. {
  595. currentMenu = data;
  596. encoderPosition = 0;
  597. }
  598. static void menu_action_submenu(menuFunc_t data)
  599. {
  600. currentMenu = data;
  601. encoderPosition = 0;
  602. }
  603. static void menu_action_gcode(const char* pgcode)
  604. {
  605. enquecommand_P(pgcode);
  606. }
  607. static void menu_action_function(menuFunc_t data)
  608. {
  609. (*data)();
  610. }
  611. static void menu_action_sdfile(const char* filename, char* longFilename)
  612. {
  613. char cmd[30];
  614. char* c;
  615. sprintf_P(cmd, PSTR("M23 %s"), filename);
  616. for(c = &cmd[4]; *c; c++)
  617. *c = tolower(*c);
  618. enquecommand(cmd);
  619. enquecommand_P(PSTR("M24"));
  620. lcd_return_to_status();
  621. }
  622. static void menu_action_sddirectory(const char* filename, char* longFilename)
  623. {
  624. card.chdir(filename);
  625. encoderPosition = 0;
  626. }
  627. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  628. {
  629. *ptr = !(*ptr);
  630. }
  631. #endif//ULTIPANEL
  632. /** LCD API **/
  633. void lcd_init()
  634. {
  635. lcd_implementation_init();
  636. #ifdef NEWPANEL
  637. pinMode(BTN_EN1,INPUT);
  638. pinMode(BTN_EN2,INPUT);
  639. pinMode(BTN_ENC,INPUT);
  640. pinMode(SDCARDDETECT,INPUT);
  641. WRITE(BTN_EN1,HIGH);
  642. WRITE(BTN_EN2,HIGH);
  643. WRITE(BTN_ENC,HIGH);
  644. #else
  645. pinMode(SHIFT_CLK,OUTPUT);
  646. pinMode(SHIFT_LD,OUTPUT);
  647. pinMode(SHIFT_EN,OUTPUT);
  648. pinMode(SHIFT_OUT,INPUT);
  649. WRITE(SHIFT_OUT,HIGH);
  650. WRITE(SHIFT_LD,HIGH);
  651. WRITE(SHIFT_EN,LOW);
  652. #endif//!NEWPANEL
  653. #if (SDCARDDETECT > -1)
  654. WRITE(SDCARDDETECT, HIGH);
  655. lcd_oldcardstatus = IS_SD_INSERTED;
  656. #endif//(SDCARDDETECT > -1)
  657. lcd_buttons_update();
  658. encoderDiff = 0;
  659. }
  660. void lcd_update()
  661. {
  662. static unsigned long timeoutToStatus = 0;
  663. lcd_buttons_update();
  664. #if (SDCARDDETECT > -1)
  665. if((IS_SD_INSERTED != lcd_oldcardstatus))
  666. {
  667. lcdDrawUpdate = 2;
  668. lcd_oldcardstatus = IS_SD_INSERTED;
  669. lcd_implementation_init(); // to maybe revive the lcd if static electricty killed it.
  670. if(lcd_oldcardstatus)
  671. {
  672. card.initsd();
  673. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  674. }
  675. else
  676. {
  677. card.release();
  678. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  679. }
  680. }
  681. #endif//CARDINSERTED
  682. if (lcd_next_update_millis < millis())
  683. {
  684. #ifdef ULTIPANEL
  685. if (encoderDiff)
  686. {
  687. lcdDrawUpdate = 1;
  688. encoderPosition += encoderDiff;
  689. encoderDiff = 0;
  690. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  691. }
  692. if (LCD_CLICKED)
  693. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  694. #endif//ULTIPANEL
  695. (*currentMenu)();
  696. #ifdef ULTIPANEL
  697. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  698. {
  699. lcd_return_to_status();
  700. lcdDrawUpdate = 2;
  701. }
  702. #endif//ULTIPANEL
  703. if (lcdDrawUpdate == 2)
  704. lcd_implementation_clear();
  705. if (lcdDrawUpdate)
  706. lcdDrawUpdate--;
  707. lcd_next_update_millis = millis() + 100;
  708. }
  709. }
  710. void lcd_setstatus(const char* message)
  711. {
  712. if (lcd_status_message_level > 0)
  713. return;
  714. strncpy(lcd_status_message, message, LCD_WIDTH);
  715. lcdDrawUpdate = 2;
  716. }
  717. void lcd_setstatuspgm(const char* message)
  718. {
  719. if (lcd_status_message_level > 0)
  720. return;
  721. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  722. lcdDrawUpdate = 2;
  723. }
  724. void lcd_setalertstatuspgm(const char* message)
  725. {
  726. lcd_setstatuspgm(message);
  727. lcd_status_message_level = 1;
  728. #ifdef ULTIPANEL
  729. lcd_return_to_status();
  730. #endif//ULTIPANEL
  731. }
  732. void lcd_reset_alert_level()
  733. {
  734. lcd_status_message_level = 0;
  735. }
  736. #ifdef ULTIPANEL
  737. /* Warning: This function is called from interrupt context */
  738. void lcd_buttons_update()
  739. {
  740. #ifdef NEWPANEL
  741. uint8_t newbutton=0;
  742. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  743. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  744. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  745. newbutton |= EN_C;
  746. buttons = newbutton;
  747. #else //read it from the shift register
  748. uint8_t newbutton=0;
  749. WRITE(SHIFT_LD,LOW);
  750. WRITE(SHIFT_LD,HIGH);
  751. unsigned char tmp_buttons=0;
  752. for(int8_t i=0;i<8;i++)
  753. {
  754. newbutton = newbutton>>1;
  755. if(READ(SHIFT_OUT))
  756. newbutton|=(1<<7);
  757. WRITE(SHIFT_CLK,HIGH);
  758. WRITE(SHIFT_CLK,LOW);
  759. }
  760. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  761. #endif//!NEWPANEL
  762. //manage encoder rotation
  763. uint8_t enc=0;
  764. if(buttons&EN_A)
  765. enc|=(1<<0);
  766. if(buttons&EN_B)
  767. enc|=(1<<1);
  768. if(enc != lastEncoderBits)
  769. {
  770. switch(enc)
  771. {
  772. case encrot0:
  773. if(lastEncoderBits==encrot3)
  774. encoderDiff++;
  775. else if(lastEncoderBits==encrot1)
  776. encoderDiff--;
  777. break;
  778. case encrot1:
  779. if(lastEncoderBits==encrot0)
  780. encoderDiff++;
  781. else if(lastEncoderBits==encrot2)
  782. encoderDiff--;
  783. break;
  784. case encrot2:
  785. if(lastEncoderBits==encrot1)
  786. encoderDiff++;
  787. else if(lastEncoderBits==encrot3)
  788. encoderDiff--;
  789. break;
  790. case encrot3:
  791. if(lastEncoderBits==encrot2)
  792. encoderDiff++;
  793. else if(lastEncoderBits==encrot0)
  794. encoderDiff--;
  795. break;
  796. }
  797. }
  798. lastEncoderBits = enc;
  799. }
  800. #endif//ULTIPANEL
  801. /********************************/
  802. /** Float conversion utilities **/
  803. /********************************/
  804. // convert float to string with +123.4 format
  805. char conv[8];
  806. char *ftostr3(const float &x)
  807. {
  808. return itostr3((int)x);
  809. }
  810. char *itostr2(const uint8_t &x)
  811. {
  812. //sprintf(conv,"%5.1f",x);
  813. int xx=x;
  814. conv[0]=(xx/10)%10+'0';
  815. conv[1]=(xx)%10+'0';
  816. conv[2]=0;
  817. return conv;
  818. }
  819. // convert float to string with +123.4 format
  820. char *ftostr31(const float &x)
  821. {
  822. int xx=x*10;
  823. conv[0]=(xx>=0)?'+':'-';
  824. xx=abs(xx);
  825. conv[1]=(xx/1000)%10+'0';
  826. conv[2]=(xx/100)%10+'0';
  827. conv[3]=(xx/10)%10+'0';
  828. conv[4]='.';
  829. conv[5]=(xx)%10+'0';
  830. conv[6]=0;
  831. return conv;
  832. }
  833. char *ftostr32(const float &x)
  834. {
  835. long xx=x*100;
  836. if (xx >= 0)
  837. conv[0]=(xx/10000)%10+'0';
  838. else
  839. conv[0]='-';
  840. xx=abs(xx);
  841. conv[1]=(xx/1000)%10+'0';
  842. conv[2]=(xx/100)%10+'0';
  843. conv[3]='.';
  844. conv[4]=(xx/10)%10+'0';
  845. conv[5]=(xx)%10+'0';
  846. conv[6]=0;
  847. return conv;
  848. }
  849. char *itostr31(const int &xx)
  850. {
  851. conv[0]=(xx>=0)?'+':'-';
  852. conv[1]=(xx/1000)%10+'0';
  853. conv[2]=(xx/100)%10+'0';
  854. conv[3]=(xx/10)%10+'0';
  855. conv[4]='.';
  856. conv[5]=(xx)%10+'0';
  857. conv[6]=0;
  858. return conv;
  859. }
  860. char *itostr3(const int &xx)
  861. {
  862. if (xx >= 100)
  863. conv[0]=(xx/100)%10+'0';
  864. else
  865. conv[0]=' ';
  866. if (xx >= 10)
  867. conv[1]=(xx/10)%10+'0';
  868. else
  869. conv[1]=' ';
  870. conv[2]=(xx)%10+'0';
  871. conv[3]=0;
  872. return conv;
  873. }
  874. char *itostr3left(const int &xx)
  875. {
  876. if (xx >= 100)
  877. {
  878. conv[0]=(xx/100)%10+'0';
  879. conv[1]=(xx/10)%10+'0';
  880. conv[2]=(xx)%10+'0';
  881. conv[3]=0;
  882. }
  883. else if (xx >= 10)
  884. {
  885. conv[0]=(xx/10)%10+'0';
  886. conv[1]=(xx)%10+'0';
  887. conv[2]=0;
  888. }
  889. else
  890. {
  891. conv[0]=(xx)%10+'0';
  892. conv[1]=0;
  893. }
  894. return conv;
  895. }
  896. char *itostr4(const int &xx)
  897. {
  898. if (xx >= 1000)
  899. conv[0]=(xx/1000)%10+'0';
  900. else
  901. conv[0]=' ';
  902. if (xx >= 100)
  903. conv[1]=(xx/100)%10+'0';
  904. else
  905. conv[1]=' ';
  906. if (xx >= 10)
  907. conv[2]=(xx/10)%10+'0';
  908. else
  909. conv[2]=' ';
  910. conv[3]=(xx)%10+'0';
  911. conv[4]=0;
  912. return conv;
  913. }
  914. // convert float to string with 12345 format
  915. char *ftostr5(const float &x)
  916. {
  917. long xx=abs(x);
  918. if (xx >= 10000)
  919. conv[0]=(xx/10000)%10+'0';
  920. else
  921. conv[0]=' ';
  922. if (xx >= 1000)
  923. conv[1]=(xx/1000)%10+'0';
  924. else
  925. conv[1]=' ';
  926. if (xx >= 100)
  927. conv[2]=(xx/100)%10+'0';
  928. else
  929. conv[2]=' ';
  930. if (xx >= 10)
  931. conv[3]=(xx/10)%10+'0';
  932. else
  933. conv[3]=' ';
  934. conv[4]=(xx)%10+'0';
  935. conv[5]=0;
  936. return conv;
  937. }
  938. // convert float to string with +1234.5 format
  939. char *ftostr51(const float &x)
  940. {
  941. long xx=x*10;
  942. conv[0]=(xx>=0)?'+':'-';
  943. xx=abs(xx);
  944. conv[1]=(xx/10000)%10+'0';
  945. conv[2]=(xx/1000)%10+'0';
  946. conv[3]=(xx/100)%10+'0';
  947. conv[4]=(xx/10)%10+'0';
  948. conv[5]='.';
  949. conv[6]=(xx)%10+'0';
  950. conv[7]=0;
  951. return conv;
  952. }
  953. // convert float to string with +123.45 format
  954. char *ftostr52(const float &x)
  955. {
  956. long xx=x*100;
  957. conv[0]=(xx>=0)?'+':'-';
  958. xx=abs(xx);
  959. conv[1]=(xx/10000)%10+'0';
  960. conv[2]=(xx/1000)%10+'0';
  961. conv[3]=(xx/100)%10+'0';
  962. conv[4]='.';
  963. conv[5]=(xx/10)%10+'0';
  964. conv[6]=(xx)%10+'0';
  965. conv[7]=0;
  966. return conv;
  967. }
  968. #endif //ULTRA_LCD