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

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