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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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(SDCARDDETECT,INPUT);
  646. WRITE(BTN_EN1,HIGH);
  647. WRITE(BTN_EN2,HIGH);
  648. #if defined(BTN_ENC) && BTN_ENC > -1
  649. pinMode(BTN_ENC,INPUT);
  650. WRITE(BTN_ENC,HIGH);
  651. #endif
  652. #else
  653. pinMode(SHIFT_CLK,OUTPUT);
  654. pinMode(SHIFT_LD,OUTPUT);
  655. pinMode(SHIFT_EN,OUTPUT);
  656. pinMode(SHIFT_OUT,INPUT);
  657. WRITE(SHIFT_OUT,HIGH);
  658. WRITE(SHIFT_LD,HIGH);
  659. WRITE(SHIFT_EN,LOW);
  660. #endif//!NEWPANEL
  661. #if (SDCARDDETECT > -1)
  662. WRITE(SDCARDDETECT, HIGH);
  663. lcd_oldcardstatus = IS_SD_INSERTED;
  664. #endif//(SDCARDDETECT > -1)
  665. lcd_buttons_update();
  666. #ifdef ULTIPANEL
  667. encoderDiff = 0;
  668. #endif
  669. }
  670. void lcd_update()
  671. {
  672. static unsigned long timeoutToStatus = 0;
  673. lcd_buttons_update();
  674. #ifdef LCD_HAS_SLOW_BUTTONS
  675. buttons |= lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  676. #endif
  677. #if (SDCARDDETECT > -1)
  678. if((IS_SD_INSERTED != lcd_oldcardstatus))
  679. {
  680. lcdDrawUpdate = 2;
  681. lcd_oldcardstatus = IS_SD_INSERTED;
  682. lcd_implementation_init(); // to maybe revive the lcd if static electricty killed it.
  683. if(lcd_oldcardstatus)
  684. {
  685. card.initsd();
  686. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  687. }
  688. else
  689. {
  690. card.release();
  691. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  692. }
  693. }
  694. #endif//CARDINSERTED
  695. if (lcd_next_update_millis < millis())
  696. {
  697. #ifdef ULTIPANEL
  698. if (encoderDiff)
  699. {
  700. lcdDrawUpdate = 1;
  701. encoderPosition += encoderDiff;
  702. encoderDiff = 0;
  703. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  704. }
  705. if (LCD_CLICKED)
  706. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  707. #endif//ULTIPANEL
  708. (*currentMenu)();
  709. #ifdef LCD_HAS_STATUS_INDICATORS
  710. lcd_implementation_update_indicators();
  711. #endif
  712. #ifdef ULTIPANEL
  713. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  714. {
  715. lcd_return_to_status();
  716. lcdDrawUpdate = 2;
  717. }
  718. #endif//ULTIPANEL
  719. if (lcdDrawUpdate == 2)
  720. lcd_implementation_clear();
  721. if (lcdDrawUpdate)
  722. lcdDrawUpdate--;
  723. lcd_next_update_millis = millis() + 100;
  724. }
  725. }
  726. void lcd_setstatus(const char* message)
  727. {
  728. if (lcd_status_message_level > 0)
  729. return;
  730. strncpy(lcd_status_message, message, LCD_WIDTH);
  731. lcdDrawUpdate = 2;
  732. }
  733. void lcd_setstatuspgm(const char* message)
  734. {
  735. if (lcd_status_message_level > 0)
  736. return;
  737. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  738. lcdDrawUpdate = 2;
  739. }
  740. void lcd_setalertstatuspgm(const char* message)
  741. {
  742. lcd_setstatuspgm(message);
  743. lcd_status_message_level = 1;
  744. #ifdef ULTIPANEL
  745. lcd_return_to_status();
  746. #endif//ULTIPANEL
  747. }
  748. void lcd_reset_alert_level()
  749. {
  750. lcd_status_message_level = 0;
  751. }
  752. #ifdef ULTIPANEL
  753. /* Warning: This function is called from interrupt context */
  754. void lcd_buttons_update()
  755. {
  756. #ifdef NEWPANEL
  757. uint8_t newbutton=0;
  758. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  759. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  760. #if defined(BTN_ENC) && BTN_ENC > -1
  761. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  762. newbutton |= EN_C;
  763. #endif
  764. buttons = newbutton;
  765. #else //read it from the shift register
  766. uint8_t newbutton=0;
  767. WRITE(SHIFT_LD,LOW);
  768. WRITE(SHIFT_LD,HIGH);
  769. unsigned char tmp_buttons=0;
  770. for(int8_t i=0;i<8;i++)
  771. {
  772. newbutton = newbutton>>1;
  773. if(READ(SHIFT_OUT))
  774. newbutton|=(1<<7);
  775. WRITE(SHIFT_CLK,HIGH);
  776. WRITE(SHIFT_CLK,LOW);
  777. }
  778. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  779. #endif//!NEWPANEL
  780. //manage encoder rotation
  781. uint8_t enc=0;
  782. if(buttons&EN_A)
  783. enc|=(1<<0);
  784. if(buttons&EN_B)
  785. enc|=(1<<1);
  786. if(enc != lastEncoderBits)
  787. {
  788. switch(enc)
  789. {
  790. case encrot0:
  791. if(lastEncoderBits==encrot3)
  792. encoderDiff++;
  793. else if(lastEncoderBits==encrot1)
  794. encoderDiff--;
  795. break;
  796. case encrot1:
  797. if(lastEncoderBits==encrot0)
  798. encoderDiff++;
  799. else if(lastEncoderBits==encrot2)
  800. encoderDiff--;
  801. break;
  802. case encrot2:
  803. if(lastEncoderBits==encrot1)
  804. encoderDiff++;
  805. else if(lastEncoderBits==encrot3)
  806. encoderDiff--;
  807. break;
  808. case encrot3:
  809. if(lastEncoderBits==encrot2)
  810. encoderDiff++;
  811. else if(lastEncoderBits==encrot0)
  812. encoderDiff--;
  813. break;
  814. }
  815. }
  816. lastEncoderBits = enc;
  817. }
  818. bool lcd_clicked()
  819. {
  820. return LCD_CLICKED;
  821. }
  822. #endif//ULTIPANEL
  823. /********************************/
  824. /** Float conversion utilities **/
  825. /********************************/
  826. // convert float to string with +123.4 format
  827. char conv[8];
  828. char *ftostr3(const float &x)
  829. {
  830. return itostr3((int)x);
  831. }
  832. char *itostr2(const uint8_t &x)
  833. {
  834. //sprintf(conv,"%5.1f",x);
  835. int xx=x;
  836. conv[0]=(xx/10)%10+'0';
  837. conv[1]=(xx)%10+'0';
  838. conv[2]=0;
  839. return conv;
  840. }
  841. // convert float to string with +123.4 format
  842. char *ftostr31(const float &x)
  843. {
  844. int xx=x*10;
  845. conv[0]=(xx>=0)?'+':'-';
  846. xx=abs(xx);
  847. conv[1]=(xx/1000)%10+'0';
  848. conv[2]=(xx/100)%10+'0';
  849. conv[3]=(xx/10)%10+'0';
  850. conv[4]='.';
  851. conv[5]=(xx)%10+'0';
  852. conv[6]=0;
  853. return conv;
  854. }
  855. char *ftostr32(const float &x)
  856. {
  857. long xx=x*100;
  858. if (xx >= 0)
  859. conv[0]=(xx/10000)%10+'0';
  860. else
  861. conv[0]='-';
  862. xx=abs(xx);
  863. conv[1]=(xx/1000)%10+'0';
  864. conv[2]=(xx/100)%10+'0';
  865. conv[3]='.';
  866. conv[4]=(xx/10)%10+'0';
  867. conv[5]=(xx)%10+'0';
  868. conv[6]=0;
  869. return conv;
  870. }
  871. char *itostr31(const int &xx)
  872. {
  873. conv[0]=(xx>=0)?'+':'-';
  874. conv[1]=(xx/1000)%10+'0';
  875. conv[2]=(xx/100)%10+'0';
  876. conv[3]=(xx/10)%10+'0';
  877. conv[4]='.';
  878. conv[5]=(xx)%10+'0';
  879. conv[6]=0;
  880. return conv;
  881. }
  882. char *itostr3(const int &xx)
  883. {
  884. if (xx >= 100)
  885. conv[0]=(xx/100)%10+'0';
  886. else
  887. conv[0]=' ';
  888. if (xx >= 10)
  889. conv[1]=(xx/10)%10+'0';
  890. else
  891. conv[1]=' ';
  892. conv[2]=(xx)%10+'0';
  893. conv[3]=0;
  894. return conv;
  895. }
  896. char *itostr3left(const int &xx)
  897. {
  898. if (xx >= 100)
  899. {
  900. conv[0]=(xx/100)%10+'0';
  901. conv[1]=(xx/10)%10+'0';
  902. conv[2]=(xx)%10+'0';
  903. conv[3]=0;
  904. }
  905. else if (xx >= 10)
  906. {
  907. conv[0]=(xx/10)%10+'0';
  908. conv[1]=(xx)%10+'0';
  909. conv[2]=0;
  910. }
  911. else
  912. {
  913. conv[0]=(xx)%10+'0';
  914. conv[1]=0;
  915. }
  916. return conv;
  917. }
  918. char *itostr4(const int &xx)
  919. {
  920. if (xx >= 1000)
  921. conv[0]=(xx/1000)%10+'0';
  922. else
  923. conv[0]=' ';
  924. if (xx >= 100)
  925. conv[1]=(xx/100)%10+'0';
  926. else
  927. conv[1]=' ';
  928. if (xx >= 10)
  929. conv[2]=(xx/10)%10+'0';
  930. else
  931. conv[2]=' ';
  932. conv[3]=(xx)%10+'0';
  933. conv[4]=0;
  934. return conv;
  935. }
  936. // convert float to string with 12345 format
  937. char *ftostr5(const float &x)
  938. {
  939. long xx=abs(x);
  940. if (xx >= 10000)
  941. conv[0]=(xx/10000)%10+'0';
  942. else
  943. conv[0]=' ';
  944. if (xx >= 1000)
  945. conv[1]=(xx/1000)%10+'0';
  946. else
  947. conv[1]=' ';
  948. if (xx >= 100)
  949. conv[2]=(xx/100)%10+'0';
  950. else
  951. conv[2]=' ';
  952. if (xx >= 10)
  953. conv[3]=(xx/10)%10+'0';
  954. else
  955. conv[3]=' ';
  956. conv[4]=(xx)%10+'0';
  957. conv[5]=0;
  958. return conv;
  959. }
  960. // convert float to string with +1234.5 format
  961. char *ftostr51(const float &x)
  962. {
  963. long xx=x*10;
  964. conv[0]=(xx>=0)?'+':'-';
  965. xx=abs(xx);
  966. conv[1]=(xx/10000)%10+'0';
  967. conv[2]=(xx/1000)%10+'0';
  968. conv[3]=(xx/100)%10+'0';
  969. conv[4]=(xx/10)%10+'0';
  970. conv[5]='.';
  971. conv[6]=(xx)%10+'0';
  972. conv[7]=0;
  973. return conv;
  974. }
  975. // convert float to string with +123.45 format
  976. char *ftostr52(const float &x)
  977. {
  978. long xx=x*100;
  979. conv[0]=(xx>=0)?'+':'-';
  980. xx=abs(xx);
  981. conv[1]=(xx/10000)%10+'0';
  982. conv[2]=(xx/1000)%10+'0';
  983. conv[3]=(xx/100)%10+'0';
  984. conv[4]='.';
  985. conv[5]=(xx/10)%10+'0';
  986. conv[6]=(xx)%10+'0';
  987. conv[7]=0;
  988. return conv;
  989. }
  990. #endif //ULTRA_LCD