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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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 "ConfigurationStore.h"
  9. /* Configuration settings */
  10. int plaPreheatHotendTemp;
  11. int plaPreheatHPBTemp;
  12. int plaPreheatFanSpeed;
  13. int absPreheatHotendTemp;
  14. int absPreheatHPBTemp;
  15. int absPreheatFanSpeed;
  16. /* !Configuration settings */
  17. //Function pointer to menu functions.
  18. typedef void (*menuFunc_t)();
  19. uint8_t lcd_status_message_level;
  20. char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
  21. #include "ultralcd_implementation_hitachi_HD44780.h"
  22. /** forward declerations **/
  23. /* Different menus */
  24. static void lcd_status_screen();
  25. #ifdef ULTIPANEL
  26. static void lcd_main_menu();
  27. static void lcd_tune_menu();
  28. static void lcd_prepare_menu();
  29. static void lcd_move_menu();
  30. static void lcd_control_menu();
  31. static void lcd_control_temperature_menu();
  32. static void lcd_control_temperature_preheat_pla_settings_menu();
  33. static void lcd_control_temperature_preheat_abs_settings_menu();
  34. static void lcd_control_motion_menu();
  35. static void lcd_control_retract_menu();
  36. static void lcd_sdcard_menu();
  37. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audiable feedback that something has happend
  38. /* Different types of actions that can be used in menuitems. */
  39. static void menu_action_back(menuFunc_t data);
  40. static void menu_action_submenu(menuFunc_t data);
  41. static void menu_action_gcode(const char* pgcode);
  42. static void menu_action_function(menuFunc_t data);
  43. static void menu_action_sdfile(const char* filename, char* longFilename);
  44. static void menu_action_sddirectory(const char* filename, char* longFilename);
  45. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  46. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  47. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  48. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  49. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  50. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  51. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  52. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  53. #define ENCODER_STEPS_PER_MENU_ITEM 5
  54. /* Helper macros for menus */
  55. #define START_MENU() do { \
  56. if (encoderPosition > 0x8000) encoderPosition = 0; \
  57. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  58. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  59. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  60. _menuItemNr = 0;
  61. #define MENU_ITEM(type, label, args...) do { \
  62. if (_menuItemNr == _lineNr) { \
  63. if (lcdDrawUpdate) { \
  64. const char* _label_pstr = PSTR(label); \
  65. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  66. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  67. }else{\
  68. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  69. }\
  70. }\
  71. if (LCD_CLICKED && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  72. lcd_quick_feedback(); \
  73. menu_action_ ## type ( args ); \
  74. return;\
  75. }\
  76. }\
  77. _menuItemNr++;\
  78. } while(0)
  79. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  80. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  81. #define END_MENU() \
  82. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  83. 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; } \
  84. } } while(0)
  85. /** Used variables to keep track of the menu */
  86. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  87. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  88. uint32_t blocking_enc;
  89. uint8_t lastEncoderBits;
  90. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  91. uint32_t encoderPosition;
  92. #if (SDCARDDETECT > -1)
  93. bool lcd_oldcardstatus;
  94. #endif
  95. #endif//ULTIPANEL
  96. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  97. uint32_t lcd_next_update_millis;
  98. uint8_t lcd_status_update_delay;
  99. 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) */
  100. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  101. menuFunc_t prevMenu = NULL;
  102. uint16_t prevEncoderPosition;
  103. //Variables used when editing values.
  104. const char* editLabel;
  105. void* editValue;
  106. int32_t minEditValue, maxEditValue;
  107. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependend */
  108. static void lcd_status_screen()
  109. {
  110. if (lcd_status_update_delay)
  111. lcd_status_update_delay--;
  112. else
  113. lcdDrawUpdate = 1;
  114. if (lcdDrawUpdate)
  115. {
  116. lcd_implementation_status_screen();
  117. 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 */
  118. }
  119. #ifdef ULTIPANEL
  120. if (LCD_CLICKED)
  121. {
  122. currentMenu = lcd_main_menu;
  123. lcd_quick_feedback();
  124. }
  125. if (abs(encoderPosition / 2) > 1)
  126. feedmultiply += encoderPosition / 2;
  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. #if FAN_PIN > -1
  205. fanSpeed = plaPreheatFanSpeed;
  206. analogWrite(FAN_PIN, fanSpeed);
  207. #endif
  208. lcd_return_to_status();
  209. }
  210. void lcd_preheat_abs()
  211. {
  212. setTargetHotend0(absPreheatHotendTemp);
  213. setTargetHotend1(absPreheatHotendTemp);
  214. setTargetHotend2(absPreheatHotendTemp);
  215. setTargetBed(absPreheatHPBTemp);
  216. #if FAN_PIN > -1
  217. fanSpeed = absPreheatFanSpeed;
  218. analogWrite(FAN_PIN, fanSpeed);
  219. #endif
  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. END_MENU();
  240. }
  241. static void lcd_prepare_menu()
  242. {
  243. START_MENU();
  244. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  245. #ifdef SDSUPPORT
  246. //MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  247. #endif
  248. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  249. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  250. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  251. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla);
  252. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs);
  253. MENU_ITEM(gcode, MSG_COOLDOWN, PSTR("M104 S0\nM140 S0"));
  254. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  255. END_MENU();
  256. }
  257. float move_menu_scale;
  258. static void lcd_move_menu_axis();
  259. static void lcd_move_x()
  260. {
  261. if (encoderPosition != 0)
  262. {
  263. current_position[X_AXIS] += float((int)encoderPosition) * move_menu_scale;
  264. if (current_position[X_AXIS] < X_MIN_POS)
  265. current_position[X_AXIS] = X_MIN_POS;
  266. if (current_position[X_AXIS] > X_MAX_POS)
  267. current_position[X_AXIS] = X_MAX_POS;
  268. encoderPosition = 0;
  269. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  270. lcdDrawUpdate = 1;
  271. }
  272. if (lcdDrawUpdate)
  273. {
  274. lcd_implementation_drawedit(PSTR("X"), ftostr31(current_position[X_AXIS]));
  275. }
  276. if (LCD_CLICKED)
  277. {
  278. lcd_quick_feedback();
  279. currentMenu = lcd_move_menu_axis;
  280. encoderPosition = 0;
  281. }
  282. }
  283. static void lcd_move_y()
  284. {
  285. if (encoderPosition != 0)
  286. {
  287. current_position[Y_AXIS] += float((int)encoderPosition) * move_menu_scale;
  288. if (current_position[Y_AXIS] < Y_MIN_POS)
  289. current_position[Y_AXIS] = Y_MIN_POS;
  290. if (current_position[Y_AXIS] > Y_MAX_POS)
  291. current_position[Y_AXIS] = Y_MAX_POS;
  292. encoderPosition = 0;
  293. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  294. lcdDrawUpdate = 1;
  295. }
  296. if (lcdDrawUpdate)
  297. {
  298. lcd_implementation_drawedit(PSTR("Y"), ftostr31(current_position[Y_AXIS]));
  299. }
  300. if (LCD_CLICKED)
  301. {
  302. lcd_quick_feedback();
  303. currentMenu = lcd_move_menu_axis;
  304. encoderPosition = 0;
  305. }
  306. }
  307. static void lcd_move_z()
  308. {
  309. if (encoderPosition != 0)
  310. {
  311. current_position[Z_AXIS] += float((int)encoderPosition) * move_menu_scale;
  312. if (current_position[Z_AXIS] < Z_MIN_POS)
  313. current_position[Z_AXIS] = Z_MIN_POS;
  314. if (current_position[Z_AXIS] > Z_MAX_POS)
  315. current_position[Z_AXIS] = Z_MAX_POS;
  316. encoderPosition = 0;
  317. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 60, active_extruder);
  318. lcdDrawUpdate = 1;
  319. }
  320. if (lcdDrawUpdate)
  321. {
  322. lcd_implementation_drawedit(PSTR("Z"), ftostr31(current_position[Z_AXIS]));
  323. }
  324. if (LCD_CLICKED)
  325. {
  326. lcd_quick_feedback();
  327. currentMenu = lcd_move_menu_axis;
  328. encoderPosition = 0;
  329. }
  330. }
  331. static void lcd_move_e()
  332. {
  333. if (encoderPosition != 0)
  334. {
  335. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  336. encoderPosition = 0;
  337. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 20, active_extruder);
  338. lcdDrawUpdate = 1;
  339. }
  340. if (lcdDrawUpdate)
  341. {
  342. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  343. }
  344. if (LCD_CLICKED)
  345. {
  346. lcd_quick_feedback();
  347. currentMenu = lcd_move_menu_axis;
  348. encoderPosition = 0;
  349. }
  350. }
  351. static void lcd_move_menu_axis()
  352. {
  353. START_MENU();
  354. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  355. MENU_ITEM(submenu, "Move X", lcd_move_x);
  356. MENU_ITEM(submenu, "Move Y", lcd_move_y);
  357. MENU_ITEM(submenu, "Move Z", lcd_move_z);
  358. if (move_menu_scale < 10.0)
  359. {
  360. MENU_ITEM(submenu, "Extruder", lcd_move_e);
  361. }
  362. END_MENU();
  363. }
  364. static void lcd_move_menu_10mm()
  365. {
  366. move_menu_scale = 10.0;
  367. lcd_move_menu_axis();
  368. }
  369. static void lcd_move_menu_1mm()
  370. {
  371. move_menu_scale = 1.0;
  372. lcd_move_menu_axis();
  373. }
  374. static void lcd_move_menu_01mm()
  375. {
  376. move_menu_scale = 0.1;
  377. lcd_move_menu_axis();
  378. }
  379. static void lcd_move_menu()
  380. {
  381. START_MENU();
  382. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  383. MENU_ITEM(submenu, "Move 10mm", lcd_move_menu_10mm);
  384. MENU_ITEM(submenu, "Move 1mm", lcd_move_menu_1mm);
  385. MENU_ITEM(submenu, "Move 0.1mm", lcd_move_menu_01mm);
  386. //TODO:X,Y,Z,E
  387. END_MENU();
  388. }
  389. static void lcd_control_menu()
  390. {
  391. START_MENU();
  392. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  393. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  394. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  395. #ifdef FWRETRACT
  396. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  397. #endif
  398. #ifdef EEPROM_SETTINGS
  399. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  400. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  401. #endif
  402. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  403. END_MENU();
  404. }
  405. static void lcd_control_temperature_menu()
  406. {
  407. START_MENU();
  408. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  409. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  410. #if TEMP_SENSOR_1 != 0
  411. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  412. #endif
  413. #if TEMP_SENSOR_2 != 0
  414. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  415. #endif
  416. #if TEMP_SENSOR_BED != 0
  417. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  418. #endif
  419. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  420. #ifdef AUTOTEMP
  421. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  422. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  423. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  424. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  425. #endif
  426. #ifdef PIDTEMP
  427. MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
  428. //TODO, I and D should have a PID_dT multiplier (Ki = PID_I * PID_dT, Kd = PID_D / PID_dT)
  429. MENU_ITEM_EDIT(float52, MSG_PID_I, &Ki, 1, 9990);
  430. MENU_ITEM_EDIT(float52, MSG_PID_D, &Kd, 1, 9990);
  431. # ifdef PID_ADD_EXTRUSION_RATE
  432. MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
  433. # endif//PID_ADD_EXTRUSION_RATE
  434. #endif//PIDTEMP
  435. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  436. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  437. END_MENU();
  438. }
  439. static void lcd_control_temperature_preheat_pla_settings_menu()
  440. {
  441. START_MENU();
  442. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  443. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  444. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  445. #if TEMP_SENSOR_BED != 0
  446. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  447. #endif
  448. #ifdef EEPROM_SETTINGS
  449. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  450. #endif
  451. END_MENU();
  452. }
  453. static void lcd_control_temperature_preheat_abs_settings_menu()
  454. {
  455. START_MENU();
  456. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  457. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  458. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  459. #if TEMP_SENSOR_BED != 0
  460. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  461. #endif
  462. #ifdef EEPROM_SETTINGS
  463. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  464. #endif
  465. END_MENU();
  466. }
  467. static void lcd_control_motion_menu()
  468. {
  469. START_MENU();
  470. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  471. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
  472. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  473. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  474. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  475. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  476. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  477. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  478. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  479. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000);
  480. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000);
  481. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000);
  482. MENU_ITEM_EDIT(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000);
  483. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  484. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  485. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  486. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  487. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  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. }
  658. void lcd_update()
  659. {
  660. static unsigned long timeoutToStatus = 0;
  661. lcd_buttons_update();
  662. #if (SDCARDDETECT > -1)
  663. if((IS_SD_INSERTED != lcd_oldcardstatus))
  664. {
  665. lcdDrawUpdate = 2;
  666. lcd_oldcardstatus = IS_SD_INSERTED;
  667. lcd_implementation_init(); // to maybe revive the lcd if static electricty killed it.
  668. if(lcd_oldcardstatus)
  669. {
  670. card.initsd();
  671. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  672. }
  673. else
  674. {
  675. card.release();
  676. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  677. }
  678. }
  679. #endif//CARDINSERTED
  680. if (lcd_next_update_millis < millis())
  681. {
  682. #ifdef ULTIPANEL
  683. if (encoderDiff)
  684. {
  685. lcdDrawUpdate = 1;
  686. encoderPosition += encoderDiff;
  687. encoderDiff = 0;
  688. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  689. }
  690. if (LCD_CLICKED)
  691. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  692. #endif//ULTIPANEL
  693. (*currentMenu)();
  694. #ifdef ULTIPANEL
  695. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  696. {
  697. lcd_return_to_status();
  698. lcdDrawUpdate = 2;
  699. }
  700. #endif//ULTIPANEL
  701. if (lcdDrawUpdate == 2)
  702. lcd_implementation_clear();
  703. if (lcdDrawUpdate)
  704. lcdDrawUpdate--;
  705. lcd_next_update_millis = millis() + 100;
  706. }
  707. }
  708. void lcd_setstatus(const char* message)
  709. {
  710. if (lcd_status_message_level > 0)
  711. return;
  712. strncpy(lcd_status_message, message, LCD_WIDTH);
  713. lcdDrawUpdate = 2;
  714. }
  715. void lcd_setstatuspgm(const char* message)
  716. {
  717. if (lcd_status_message_level > 0)
  718. return;
  719. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  720. lcdDrawUpdate = 2;
  721. }
  722. void lcd_setalertstatuspgm(const char* message)
  723. {
  724. lcd_setstatuspgm(message);
  725. lcd_status_message_level = 1;
  726. #ifdef ULTIPANEL
  727. lcd_return_to_status();
  728. #endif//ULTIPANEL
  729. }
  730. void lcd_reset_alert_level()
  731. {
  732. lcd_status_message_level = 0;
  733. }
  734. #ifdef ULTIPANEL
  735. /* Warning: This function is called from interrupt context */
  736. void lcd_buttons_update()
  737. {
  738. #ifdef NEWPANEL
  739. uint8_t newbutton=0;
  740. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  741. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  742. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  743. newbutton |= EN_C;
  744. buttons = newbutton;
  745. #else //read it from the shift register
  746. uint8_t newbutton=0;
  747. WRITE(SHIFT_LD,LOW);
  748. WRITE(SHIFT_LD,HIGH);
  749. unsigned char tmp_buttons=0;
  750. for(int8_t i=0;i<8;i++)
  751. {
  752. newbutton = newbutton>>1;
  753. if(READ(SHIFT_OUT))
  754. newbutton|=(1<<7);
  755. WRITE(SHIFT_CLK,HIGH);
  756. WRITE(SHIFT_CLK,LOW);
  757. }
  758. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  759. #endif//!NEWPANEL
  760. //manage encoder rotation
  761. uint8_t enc=0;
  762. if(buttons&EN_A)
  763. enc|=(1<<0);
  764. if(buttons&EN_B)
  765. enc|=(1<<1);
  766. if(enc != lastEncoderBits)
  767. {
  768. switch(enc)
  769. {
  770. case encrot0:
  771. if(lastEncoderBits==encrot3)
  772. encoderDiff++;
  773. else if(lastEncoderBits==encrot1)
  774. encoderDiff--;
  775. break;
  776. case encrot1:
  777. if(lastEncoderBits==encrot0)
  778. encoderDiff++;
  779. else if(lastEncoderBits==encrot2)
  780. encoderDiff--;
  781. break;
  782. case encrot2:
  783. if(lastEncoderBits==encrot1)
  784. encoderDiff++;
  785. else if(lastEncoderBits==encrot3)
  786. encoderDiff--;
  787. break;
  788. case encrot3:
  789. if(lastEncoderBits==encrot2)
  790. encoderDiff++;
  791. else if(lastEncoderBits==encrot0)
  792. encoderDiff--;
  793. break;
  794. }
  795. }
  796. lastEncoderBits = enc;
  797. }
  798. #endif//ULTIPANEL
  799. /********************************/
  800. /** Float conversion utilities **/
  801. /********************************/
  802. // convert float to string with +123.4 format
  803. char conv[8];
  804. char *ftostr3(const float &x)
  805. {
  806. return itostr3((int)x);
  807. }
  808. char *itostr2(const uint8_t &x)
  809. {
  810. //sprintf(conv,"%5.1f",x);
  811. int xx=x;
  812. conv[0]=(xx/10)%10+'0';
  813. conv[1]=(xx)%10+'0';
  814. conv[2]=0;
  815. return conv;
  816. }
  817. // convert float to string with +123.4 format
  818. char *ftostr31(const float &x)
  819. {
  820. int xx=x*10;
  821. conv[0]=(xx>=0)?'+':'-';
  822. xx=abs(xx);
  823. conv[1]=(xx/1000)%10+'0';
  824. conv[2]=(xx/100)%10+'0';
  825. conv[3]=(xx/10)%10+'0';
  826. conv[4]='.';
  827. conv[5]=(xx)%10+'0';
  828. conv[6]=0;
  829. return conv;
  830. }
  831. char *ftostr32(const float &x)
  832. {
  833. long xx=x*100;
  834. conv[0]=(xx>=0)?'+':'-';
  835. xx=abs(xx);
  836. conv[1]=(xx/100)%10+'0';
  837. conv[2]='.';
  838. conv[3]=(xx/10)%10+'0';
  839. conv[4]=(xx)%10+'0';
  840. conv[5]=0;
  841. return conv;
  842. }
  843. char *itostr31(const int &xx)
  844. {
  845. conv[0]=(xx>=0)?'+':'-';
  846. conv[1]=(xx/1000)%10+'0';
  847. conv[2]=(xx/100)%10+'0';
  848. conv[3]=(xx/10)%10+'0';
  849. conv[4]='.';
  850. conv[5]=(xx)%10+'0';
  851. conv[6]=0;
  852. return conv;
  853. }
  854. char *itostr3(const int &xx)
  855. {
  856. if (xx >= 100)
  857. conv[0]=(xx/100)%10+'0';
  858. else
  859. conv[0]=' ';
  860. if (xx >= 10)
  861. conv[1]=(xx/10)%10+'0';
  862. else
  863. conv[1]=' ';
  864. conv[2]=(xx)%10+'0';
  865. conv[3]=0;
  866. return conv;
  867. }
  868. char *itostr3left(const int &xx)
  869. {
  870. if (xx >= 100)
  871. {
  872. conv[0]=(xx/100)%10+'0';
  873. conv[1]=(xx/10)%10+'0';
  874. conv[2]=(xx)%10+'0';
  875. conv[3]=0;
  876. }
  877. else if (xx >= 10)
  878. {
  879. conv[0]=(xx/10)%10+'0';
  880. conv[1]=(xx)%10+'0';
  881. conv[2]=0;
  882. }
  883. else
  884. {
  885. conv[0]=(xx)%10+'0';
  886. conv[1]=0;
  887. }
  888. return conv;
  889. }
  890. char *itostr4(const int &xx)
  891. {
  892. if (xx >= 1000)
  893. conv[0]=(xx/1000)%10+'0';
  894. else
  895. conv[0]=' ';
  896. if (xx >= 100)
  897. conv[1]=(xx/100)%10+'0';
  898. else
  899. conv[1]=' ';
  900. if (xx >= 10)
  901. conv[2]=(xx/10)%10+'0';
  902. else
  903. conv[2]=' ';
  904. conv[3]=(xx)%10+'0';
  905. conv[4]=0;
  906. return conv;
  907. }
  908. // convert float to string with 12345 format
  909. char *ftostr5(const float &x)
  910. {
  911. long xx=abs(x);
  912. if (xx >= 10000)
  913. conv[0]=(xx/10000)%10+'0';
  914. else
  915. conv[0]=' ';
  916. if (xx >= 1000)
  917. conv[1]=(xx/1000)%10+'0';
  918. else
  919. conv[1]=' ';
  920. if (xx >= 100)
  921. conv[2]=(xx/100)%10+'0';
  922. else
  923. conv[2]=' ';
  924. if (xx >= 10)
  925. conv[3]=(xx/10)%10+'0';
  926. else
  927. conv[3]=' ';
  928. conv[4]=(xx)%10+'0';
  929. conv[5]=0;
  930. return conv;
  931. }
  932. // convert float to string with +1234.5 format
  933. char *ftostr51(const float &x)
  934. {
  935. long xx=x*10;
  936. conv[0]=(xx>=0)?'+':'-';
  937. xx=abs(xx);
  938. conv[1]=(xx/10000)%10+'0';
  939. conv[2]=(xx/1000)%10+'0';
  940. conv[3]=(xx/100)%10+'0';
  941. conv[4]=(xx/10)%10+'0';
  942. conv[5]='.';
  943. conv[6]=(xx)%10+'0';
  944. conv[7]=0;
  945. return conv;
  946. }
  947. // convert float to string with +123.45 format
  948. char *ftostr52(const float &x)
  949. {
  950. long xx=x*100;
  951. conv[0]=(xx>=0)?'+':'-';
  952. xx=abs(xx);
  953. conv[1]=(xx/10000)%10+'0';
  954. conv[2]=(xx/1000)%10+'0';
  955. conv[3]=(xx/100)%10+'0';
  956. conv[4]='.';
  957. conv[5]=(xx/10)%10+'0';
  958. conv[6]=(xx)%10+'0';
  959. conv[7]=0;
  960. return conv;
  961. }
  962. #endif //ULTRA_LCD