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

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