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

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