My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ultralcd.cpp 30KB

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