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 56KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #ifdef ULTRA_LCD
  4. #include "Marlin.h"
  5. #include "language.h"
  6. #include "cardreader.h"
  7. #include "temperature.h"
  8. #include "stepper.h"
  9. #include "ConfigurationStore.h"
  10. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  11. /* Configuration settings */
  12. int plaPreheatHotendTemp;
  13. int plaPreheatHPBTemp;
  14. int plaPreheatFanSpeed;
  15. int absPreheatHotendTemp;
  16. int absPreheatHPBTemp;
  17. int absPreheatFanSpeed;
  18. #ifdef FILAMENT_LCD_DISPLAY
  19. unsigned long message_millis = 0;
  20. #endif
  21. #ifdef ULTIPANEL
  22. static float manual_feedrate[] = MANUAL_FEEDRATE;
  23. #endif // ULTIPANEL
  24. /* !Configuration settings */
  25. //Function pointer to menu functions.
  26. typedef void (*menuFunc_t)();
  27. uint8_t lcd_status_message_level;
  28. char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
  29. #ifdef DOGLCD
  30. #include "dogm_lcd_implementation.h"
  31. #else
  32. #include "ultralcd_implementation_hitachi_HD44780.h"
  33. #endif
  34. /* Different menus */
  35. static void lcd_status_screen();
  36. #ifdef ULTIPANEL
  37. extern bool powersupply;
  38. static void lcd_main_menu();
  39. static void lcd_tune_menu();
  40. static void lcd_prepare_menu();
  41. static void lcd_move_menu();
  42. static void lcd_control_menu();
  43. static void lcd_control_temperature_menu();
  44. static void lcd_control_temperature_preheat_pla_settings_menu();
  45. static void lcd_control_temperature_preheat_abs_settings_menu();
  46. static void lcd_control_motion_menu();
  47. static void lcd_control_volumetric_menu();
  48. #ifdef DOGLCD
  49. static void lcd_set_contrast();
  50. #endif
  51. static void lcd_control_retract_menu();
  52. static void lcd_sdcard_menu();
  53. #ifdef DELTA_CALIBRATION_MENU
  54. static void lcd_delta_calibrate_menu();
  55. #endif // DELTA_CALIBRATION_MENU
  56. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  57. /* Different types of actions that can be used in menu items. */
  58. static void menu_action_back(menuFunc_t data);
  59. static void menu_action_submenu(menuFunc_t data);
  60. static void menu_action_gcode(const char* pgcode);
  61. static void menu_action_function(menuFunc_t data);
  62. static void menu_action_sdfile(const char* filename, char* longFilename);
  63. static void menu_action_sddirectory(const char* filename, char* longFilename);
  64. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  65. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  66. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  67. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  68. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  69. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  70. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  71. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  72. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  73. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  74. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  75. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  76. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  77. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  78. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  79. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  80. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  81. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  82. #define ENCODER_FEEDRATE_DEADZONE 10
  83. #if !defined(LCD_I2C_VIKI)
  84. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  85. #define ENCODER_STEPS_PER_MENU_ITEM 5
  86. #endif
  87. #ifndef ENCODER_PULSES_PER_STEP
  88. #define ENCODER_PULSES_PER_STEP 1
  89. #endif
  90. #else
  91. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  92. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  93. #endif
  94. #ifndef ENCODER_PULSES_PER_STEP
  95. #define ENCODER_PULSES_PER_STEP 1
  96. #endif
  97. #endif
  98. /* Helper macros for menus */
  99. #define START_MENU() do { \
  100. if (encoderPosition > 0x8000) encoderPosition = 0; \
  101. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  102. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  103. bool wasClicked = LCD_CLICKED;\
  104. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  105. _menuItemNr = 0;
  106. #define MENU_ITEM(type, label, args...) do { \
  107. if (_menuItemNr == _lineNr) { \
  108. if (lcdDrawUpdate) { \
  109. const char* _label_pstr = PSTR(label); \
  110. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  111. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  112. }else{\
  113. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  114. }\
  115. }\
  116. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  117. lcd_quick_feedback(); \
  118. menu_action_ ## type ( args ); \
  119. return;\
  120. }\
  121. }\
  122. _menuItemNr++;\
  123. } while(0)
  124. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  125. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  126. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
  127. #define END_MENU() \
  128. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  129. 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; } \
  130. } } while(0)
  131. /** Used variables to keep track of the menu */
  132. #ifndef REPRAPWORLD_KEYPAD
  133. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  134. #else
  135. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  136. #endif
  137. #ifdef LCD_HAS_SLOW_BUTTONS
  138. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  139. #endif
  140. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  141. uint32_t blocking_enc;
  142. uint8_t lastEncoderBits;
  143. uint32_t encoderPosition;
  144. #if (SDCARDDETECT > 0)
  145. bool lcd_oldcardstatus;
  146. #endif
  147. #endif //ULTIPANEL
  148. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  149. uint32_t lcd_next_update_millis;
  150. uint8_t lcd_status_update_delay;
  151. bool ignore_click = false;
  152. bool wait_for_unclick;
  153. 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 at least 1 full redraw (first redraw is partial) */
  154. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  155. menuFunc_t prevMenu = NULL;
  156. uint16_t prevEncoderPosition;
  157. //Variables used when editing values.
  158. const char* editLabel;
  159. void* editValue;
  160. int32_t minEditValue, maxEditValue;
  161. menuFunc_t callbackFunc;
  162. // place-holders for Ki and Kd edits
  163. float raw_Ki, raw_Kd;
  164. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
  165. if (currentMenu != menu) {
  166. currentMenu = menu;
  167. encoderPosition = encoder;
  168. if (feedback) lcd_quick_feedback();
  169. // For LCD_PROGRESS_BAR re-initialize the custom characters
  170. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  171. lcd_set_custom_characters(menu == lcd_status_screen);
  172. #endif
  173. }
  174. }
  175. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  176. static void lcd_status_screen()
  177. {
  178. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  179. uint16_t mil = millis();
  180. #ifndef PROGRESS_MSG_ONCE
  181. if (mil > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
  182. progressBarTick = mil;
  183. }
  184. #endif
  185. #if PROGRESS_MSG_EXPIRE > 0
  186. // keep the message alive if paused, count down otherwise
  187. if (messageTick > 0) {
  188. if (card.isFileOpen()) {
  189. if (IS_SD_PRINTING) {
  190. if ((mil-messageTick) >= PROGRESS_MSG_EXPIRE) {
  191. lcd_status_message[0] = '\0';
  192. messageTick = 0;
  193. }
  194. }
  195. else {
  196. messageTick += LCD_UPDATE_INTERVAL;
  197. }
  198. }
  199. else {
  200. messageTick = 0;
  201. }
  202. }
  203. #endif
  204. #endif //LCD_PROGRESS_BAR
  205. if (lcd_status_update_delay)
  206. lcd_status_update_delay--;
  207. else
  208. lcdDrawUpdate = 1;
  209. if (lcdDrawUpdate) {
  210. lcd_implementation_status_screen();
  211. 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 */
  212. }
  213. #ifdef ULTIPANEL
  214. bool current_click = LCD_CLICKED;
  215. if (ignore_click) {
  216. if (wait_for_unclick) {
  217. if (!current_click) {
  218. ignore_click = wait_for_unclick = false;
  219. }
  220. else {
  221. current_click = false;
  222. }
  223. }
  224. else if (current_click) {
  225. lcd_quick_feedback();
  226. wait_for_unclick = true;
  227. current_click = false;
  228. }
  229. }
  230. if (current_click)
  231. {
  232. lcd_goto_menu(lcd_main_menu);
  233. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  234. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  235. currentMenu == lcd_status_screen
  236. #endif
  237. );
  238. #ifdef FILAMENT_LCD_DISPLAY
  239. message_millis = millis(); // get status message to show up for a while
  240. #endif
  241. }
  242. #ifdef ULTIPANEL_FEEDMULTIPLY
  243. // Dead zone at 100% feedrate
  244. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  245. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  246. {
  247. encoderPosition = 0;
  248. feedmultiply = 100;
  249. }
  250. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  251. {
  252. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  253. encoderPosition = 0;
  254. }
  255. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  256. {
  257. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  258. encoderPosition = 0;
  259. }
  260. else if (feedmultiply != 100)
  261. {
  262. feedmultiply += int(encoderPosition);
  263. encoderPosition = 0;
  264. }
  265. #endif //ULTIPANEL_FEEDMULTIPLY
  266. if (feedmultiply < 10)
  267. feedmultiply = 10;
  268. else if (feedmultiply > 999)
  269. feedmultiply = 999;
  270. #endif //ULTIPANEL
  271. }
  272. #ifdef ULTIPANEL
  273. static void lcd_return_to_status() { lcd_goto_menu(lcd_status_screen, 0, false); }
  274. static void lcd_sdcard_pause() { card.pauseSDPrint(); }
  275. static void lcd_sdcard_resume() { card.startFileprint(); }
  276. static void lcd_sdcard_stop() {
  277. card.sdprinting = false;
  278. card.closefile();
  279. quickStop();
  280. if (SD_FINISHED_STEPPERRELEASE) {
  281. enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
  282. }
  283. autotempShutdown();
  284. cancel_heatup = true;
  285. lcd_setstatus(MSG_PRINT_ABORTED);
  286. }
  287. /* Menu implementation */
  288. static void lcd_main_menu() {
  289. START_MENU();
  290. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  291. if (movesplanned() || IS_SD_PRINTING) {
  292. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  293. }
  294. else {
  295. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  296. #ifdef DELTA_CALIBRATION_MENU
  297. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  298. #endif
  299. }
  300. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  301. #ifdef SDSUPPORT
  302. if (card.cardOK) {
  303. if (card.isFileOpen()) {
  304. if (card.sdprinting)
  305. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  306. else
  307. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  308. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  309. }
  310. else {
  311. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  312. #if SDCARDDETECT < 1
  313. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  314. #endif
  315. }
  316. }
  317. else {
  318. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  319. #if SDCARDDETECT < 1
  320. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  321. #endif
  322. }
  323. #endif //SDSUPPORT
  324. END_MENU();
  325. }
  326. #ifdef SDSUPPORT
  327. static void lcd_autostart_sd() {
  328. card.autostart_index = 0;
  329. card.setroot();
  330. card.checkautostart(true);
  331. }
  332. #endif
  333. void lcd_set_home_offsets() {
  334. for(int8_t i=0; i < NUM_AXIS; i++) {
  335. if (i != E_AXIS) {
  336. add_homing[i] -= current_position[i];
  337. current_position[i] = 0.0;
  338. }
  339. }
  340. plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
  341. // Audio feedback
  342. enquecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
  343. lcd_return_to_status();
  344. }
  345. #ifdef BABYSTEPPING
  346. static void _lcd_babystep(int axis, const char *msg) {
  347. if (encoderPosition != 0) {
  348. babystepsTodo[axis] += (int)encoderPosition;
  349. encoderPosition = 0;
  350. lcdDrawUpdate = 1;
  351. }
  352. if (lcdDrawUpdate) lcd_implementation_drawedit(msg, "");
  353. if (LCD_CLICKED) lcd_goto_menu(lcd_tune_menu);
  354. }
  355. static void lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  356. static void lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  357. static void lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  358. #endif //BABYSTEPPING
  359. static void lcd_tune_menu() {
  360. START_MENU();
  361. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  362. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);
  363. #if TEMP_SENSOR_0 != 0
  364. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  365. #endif
  366. #if TEMP_SENSOR_1 != 0
  367. MENU_ITEM_EDIT(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  368. #endif
  369. #if TEMP_SENSOR_2 != 0
  370. MENU_ITEM_EDIT(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  371. #endif
  372. #if TEMP_SENSOR_3 != 0
  373. MENU_ITEM_EDIT(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
  374. #endif
  375. #if TEMP_SENSOR_BED != 0
  376. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  377. #endif
  378. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  379. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);
  380. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_F0, &extruder_multiply[0], 10, 999);
  381. #if TEMP_SENSOR_1 != 0
  382. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_F1, &extruder_multiply[1], 10, 999);
  383. #endif
  384. #if TEMP_SENSOR_2 != 0
  385. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_F2, &extruder_multiply[2], 10, 999);
  386. #endif
  387. #if TEMP_SENSOR_3 != 0
  388. MENU_ITEM_EDIT(int3, MSG_FLOW MSG_F3, &extruder_multiply[3], 10, 999);
  389. #endif
  390. #ifdef BABYSTEPPING
  391. #ifdef BABYSTEP_XY
  392. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  393. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  394. #endif //BABYSTEP_XY
  395. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  396. #endif
  397. #ifdef FILAMENTCHANGEENABLE
  398. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  399. #endif
  400. END_MENU();
  401. }
  402. void _lcd_preheat(int endnum, const float temph, const float tempb, const int fan) {
  403. if (temph > 0) setTargetHotend(temph, endnum);
  404. setTargetBed(tempb);
  405. fanSpeed = fan;
  406. lcd_return_to_status();
  407. setWatch(); // heater sanity check timer
  408. }
  409. void lcd_preheat_pla0() { _lcd_preheat(0, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  410. void lcd_preheat_abs0() { _lcd_preheat(0, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  411. #if TEMP_SENSOR_1 != 0 //2nd extruder preheat
  412. void lcd_preheat_pla1() { _lcd_preheat(1, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  413. void lcd_preheat_abs1() { _lcd_preheat(1, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  414. #endif //2nd extruder preheat
  415. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  416. void lcd_preheat_pla2() { _lcd_preheat(2, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  417. void lcd_preheat_abs2() { _lcd_preheat(2, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  418. #endif //3 extruder preheat
  419. #if TEMP_SENSOR_3 != 0 //4 extruder preheat
  420. void lcd_preheat_pla3() { _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  421. void lcd_preheat_abs3() { _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed); }
  422. #endif //4 extruder preheat
  423. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 //more than one extruder present
  424. void lcd_preheat_pla0123() {
  425. setTargetHotend0(plaPreheatHotendTemp);
  426. setTargetHotend1(plaPreheatHotendTemp);
  427. setTargetHotend2(plaPreheatHotendTemp);
  428. _lcd_preheat(3, plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed);
  429. }
  430. void lcd_preheat_abs0123() {
  431. setTargetHotend0(absPreheatHotendTemp);
  432. setTargetHotend1(absPreheatHotendTemp);
  433. setTargetHotend2(absPreheatHotendTemp);
  434. _lcd_preheat(3, absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed);
  435. }
  436. #endif //more than one extruder present
  437. void lcd_preheat_pla_bedonly() { _lcd_preheat(0, 0, plaPreheatHPBTemp, plaPreheatFanSpeed); }
  438. void lcd_preheat_abs_bedonly() { _lcd_preheat(0, 0, absPreheatHPBTemp, absPreheatFanSpeed); }
  439. static void lcd_preheat_pla_menu() {
  440. START_MENU();
  441. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  442. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H1, lcd_preheat_pla0);
  443. #if TEMP_SENSOR_1 != 0 //2 extruder preheat
  444. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H2, lcd_preheat_pla1);
  445. #endif //2 extruder preheat
  446. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  447. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H3, lcd_preheat_pla2);
  448. #endif //3 extruder preheat
  449. #if TEMP_SENSOR_3 != 0 //4 extruder preheat
  450. MENU_ITEM(function, MSG_PREHEAT_PLA_N MSG_H4, lcd_preheat_pla3);
  451. #endif //4 extruder preheat
  452. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 //all extruder preheat
  453. MENU_ITEM(function, MSG_PREHEAT_PLA_ALL, lcd_preheat_pla0123);
  454. #endif //all extruder preheat
  455. #if TEMP_SENSOR_BED != 0
  456. MENU_ITEM(function, MSG_PREHEAT_PLA_BEDONLY, lcd_preheat_pla_bedonly);
  457. #endif
  458. END_MENU();
  459. }
  460. static void lcd_preheat_abs_menu() {
  461. START_MENU();
  462. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  463. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H1, lcd_preheat_abs0);
  464. #if TEMP_SENSOR_1 != 0 //2 extruder preheat
  465. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H2, lcd_preheat_abs1);
  466. #endif //2 extruder preheat
  467. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  468. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H3, lcd_preheat_abs2);
  469. #endif //3 extruder preheat
  470. #if TEMP_SENSOR_3 != 0 //4 extruder preheat
  471. MENU_ITEM(function, MSG_PREHEAT_ABS_N MSG_H4, lcd_preheat_abs3);
  472. #endif //4 extruder preheat
  473. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 //all extruder preheat
  474. MENU_ITEM(function, MSG_PREHEAT_ABS_ALL, lcd_preheat_abs0123);
  475. #endif //all extruder preheat
  476. #if TEMP_SENSOR_BED != 0
  477. MENU_ITEM(function, MSG_PREHEAT_ABS_BEDONLY, lcd_preheat_abs_bedonly);
  478. #endif
  479. END_MENU();
  480. }
  481. void lcd_cooldown() {
  482. setTargetHotend0(0);
  483. setTargetHotend1(0);
  484. setTargetHotend2(0);
  485. setTargetHotend3(0);
  486. setTargetBed(0);
  487. fanSpeed = 0;
  488. lcd_return_to_status();
  489. }
  490. static void lcd_prepare_menu() {
  491. START_MENU();
  492. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  493. #ifdef SDSUPPORT
  494. #ifdef MENU_ADDAUTOSTART
  495. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  496. #endif
  497. #endif
  498. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  499. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  500. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  501. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  502. #if TEMP_SENSOR_0 != 0
  503. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_BED != 0
  504. MENU_ITEM(submenu, MSG_PREHEAT_PLA, lcd_preheat_pla_menu);
  505. MENU_ITEM(submenu, MSG_PREHEAT_ABS, lcd_preheat_abs_menu);
  506. #else
  507. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  508. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  509. #endif
  510. #endif
  511. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  512. #if defined(POWER_SUPPLY) && POWER_SUPPLY > 0 && defined(PS_ON_PIN) && PS_ON_PIN > -1
  513. if (powersupply) {
  514. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  515. }
  516. else {
  517. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  518. }
  519. #endif
  520. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  521. // JFR for RMud delta printer
  522. MENU_ITEM(gcode, "Calibrate bed", PSTR("M702\nG28\nG1 X-77.94 Y-45 Z36 F8000\nG4 S3\nM701 P0\nG1 X77.94 Y-45 Z36\nG4 S3\nM701 P1\nG1 X0 Y90 Z36\nG4 S3\nM701 P2\nM700\nG1 X0 Y0 Z100 F8000"));
  523. MENU_ITEM(gcode, "Check level", PSTR("G28\nG1 X0 Y0 Z1 F4000\nG1 X-77.94 Y-45 Z1\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG4 S2\nG1 X-77.94 Y-45 Z0.3 F2000\nG1 X-77.94 Y-45\nG1 X77.94 Y-45\nG1 X0 Y90\nG1 X-77.94 Y-45\nG1 X0 Y0 Z0"));
  524. MENU_ITEM(gcode, "Retract filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E-800"));
  525. MENU_ITEM(gcode, "Insert filament", PSTR("M302\nM82\nG92 E0\nG1 F4000 E60"));
  526. MENU_ITEM(gcode, "Finalize filament", PSTR("G1 F4000 E790"));
  527. END_MENU();
  528. }
  529. #ifdef DELTA_CALIBRATION_MENU
  530. static void lcd_delta_calibrate_menu()
  531. {
  532. START_MENU();
  533. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  534. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  535. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_X, PSTR("G0 F8000 X-77.94 Y-45 Z0"));
  536. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Y, PSTR("G0 F8000 X77.94 Y-45 Z0"));
  537. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Z, PSTR("G0 F8000 X0 Y90 Z0"));
  538. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_CENTER, PSTR("G0 F8000 X0 Y0 Z0"));
  539. END_MENU();
  540. }
  541. #endif // DELTA_CALIBRATION_MENU
  542. float move_menu_scale;
  543. static void lcd_move_menu_axis();
  544. static void _lcd_move(const char *name, int axis, int min, int max) {
  545. if (encoderPosition != 0) {
  546. refresh_cmd_timeout();
  547. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  548. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  549. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  550. encoderPosition = 0;
  551. #ifdef DELTA
  552. calculate_delta(current_position);
  553. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  554. #else
  555. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  556. #endif
  557. lcdDrawUpdate = 1;
  558. }
  559. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  560. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  561. }
  562. static void lcd_move_x() { _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS); }
  563. static void lcd_move_y() { _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
  564. static void lcd_move_z() { _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
  565. static void lcd_move_e() {
  566. if (encoderPosition != 0) {
  567. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  568. encoderPosition = 0;
  569. #ifdef DELTA
  570. calculate_delta(current_position);
  571. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS]/60, active_extruder);
  572. #else
  573. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS]/60, active_extruder);
  574. #endif
  575. lcdDrawUpdate = 1;
  576. }
  577. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  578. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  579. }
  580. static void lcd_move_menu_axis() {
  581. START_MENU();
  582. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  583. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  584. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  585. if (move_menu_scale < 10.0) {
  586. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  587. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  588. }
  589. END_MENU();
  590. }
  591. static void lcd_move_menu_10mm() {
  592. move_menu_scale = 10.0;
  593. lcd_move_menu_axis();
  594. }
  595. static void lcd_move_menu_1mm() {
  596. move_menu_scale = 1.0;
  597. lcd_move_menu_axis();
  598. }
  599. static void lcd_move_menu_01mm() {
  600. move_menu_scale = 0.1;
  601. lcd_move_menu_axis();
  602. }
  603. static void lcd_move_menu() {
  604. START_MENU();
  605. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  606. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  607. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  608. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  609. //TODO:X,Y,Z,E
  610. END_MENU();
  611. }
  612. static void lcd_control_menu() {
  613. START_MENU();
  614. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  615. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  616. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  617. MENU_ITEM(submenu, MSG_VOLUMETRIC, lcd_control_volumetric_menu);
  618. #ifdef DOGLCD
  619. //MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  620. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  621. #endif
  622. #ifdef FWRETRACT
  623. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  624. #endif
  625. #ifdef EEPROM_SETTINGS
  626. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  627. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  628. #endif
  629. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  630. END_MENU();
  631. }
  632. #ifdef PIDTEMP
  633. // Helpers for editing PID Ki & Kd values
  634. // grab the PID value out of the temp variable; scale it; then update the PID driver
  635. void copy_and_scalePID_i(int e) {
  636. PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
  637. updatePID();
  638. }
  639. void copy_and_scalePID_d(int e) {
  640. PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
  641. updatePID();
  642. }
  643. void copy_and_scalePID_i_E1() { copy_and_scalePID_i(0); }
  644. void copy_and_scalePID_d_E1() { copy_and_scalePID_d(0); }
  645. #ifdef PID_PARAMS_PER_EXTRUDER
  646. #if EXTRUDERS > 1
  647. void copy_and_scalePID_i_E2() { copy_and_scalePID_i(1); }
  648. void copy_and_scalePID_d_E2() { copy_and_scalePID_d(1); }
  649. #if EXTRUDERS > 2
  650. void copy_and_scalePID_i_E3() { copy_and_scalePID_i(2); }
  651. void copy_and_scalePID_d_E3() { copy_and_scalePID_d(2); }
  652. #if EXTRUDERS > 3
  653. void copy_and_scalePID_i_E4() { copy_and_scalePID_i(3); }
  654. void copy_and_scalePID_d_E5() { copy_and_scalePID_d(3); }
  655. #endif //EXTRUDERS > 3
  656. #endif //EXTRUDERS > 2
  657. #endif //EXTRUDERS > 1
  658. #endif //PID_PARAMS_PER_EXTRUDER
  659. #endif //PIDTEMP
  660. static void lcd_control_temperature_menu() {
  661. START_MENU();
  662. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  663. #if TEMP_SENSOR_0 != 0
  664. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  665. #endif
  666. #if EXTRUDERS > 1
  667. #if TEMP_SENSOR_1 != 0
  668. MENU_ITEM_EDIT(int3, MSG_NOZZLE MSG_N2, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  669. #endif
  670. #if EXTRUDERS > 2
  671. #if TEMP_SENSOR_2 != 0
  672. MENU_ITEM_EDIT(int3, MSG_NOZZLE MSG_N3, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  673. #endif
  674. #if EXTRUDERS > 3
  675. #if TEMP_SENSOR_3 != 0
  676. MENU_ITEM_EDIT(int3, MSG_NOZZLE MSG_N4, &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
  677. #endif
  678. #endif
  679. #endif
  680. #endif
  681. #if TEMP_SENSOR_BED != 0
  682. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  683. #endif
  684. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  685. #if defined(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
  686. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  687. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  688. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  689. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  690. #endif
  691. #ifdef PIDTEMP
  692. // set up temp variables - undo the default scaling
  693. raw_Ki = unscalePID_i(PID_PARAM(Ki,0));
  694. raw_Kd = unscalePID_d(PID_PARAM(Kd,0));
  695. MENU_ITEM_EDIT(float52, MSG_PID_P, &PID_PARAM(Kp,0), 1, 9990);
  696. // i is typically a small value so allows values below 1
  697. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E1);
  698. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d_E1);
  699. #ifdef PID_ADD_EXTRUSION_RATE
  700. MENU_ITEM_EDIT(float3, MSG_PID_C, &PID_PARAM(Kc,0), 1, 9990);
  701. #endif//PID_ADD_EXTRUSION_RATE
  702. #ifdef PID_PARAMS_PER_EXTRUDER
  703. #if EXTRUDERS > 1
  704. // set up temp variables - undo the default scaling
  705. raw_Ki = unscalePID_i(PID_PARAM(Ki,1));
  706. raw_Kd = unscalePID_d(PID_PARAM(Kd,1));
  707. MENU_ITEM_EDIT(float52, MSG_PID_P MSG_E2, &PID_PARAM(Kp,1), 1, 9990);
  708. // i is typically a small value so allows values below 1
  709. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I MSG_E2, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E2);
  710. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D MSG_E2, &raw_Kd, 1, 9990, copy_and_scalePID_d_E2);
  711. #ifdef PID_ADD_EXTRUSION_RATE
  712. MENU_ITEM_EDIT(float3, MSG_PID_C MSG_E2, &PID_PARAM(Kc,1), 1, 9990);
  713. #endif//PID_ADD_EXTRUSION_RATE
  714. #if EXTRUDERS > 2
  715. // set up temp variables - undo the default scaling
  716. raw_Ki = unscalePID_i(PID_PARAM(Ki,2));
  717. raw_Kd = unscalePID_d(PID_PARAM(Kd,2));
  718. MENU_ITEM_EDIT(float52, MSG_PID_P MSG_E3, &PID_PARAM(Kp,2), 1, 9990);
  719. // i is typically a small value so allows values below 1
  720. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I MSG_E3, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E3);
  721. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D MSG_E3, &raw_Kd, 1, 9990, copy_and_scalePID_d_E3);
  722. #ifdef PID_ADD_EXTRUSION_RATE
  723. MENU_ITEM_EDIT(float3, MSG_PID_C MSG_E3, &PID_PARAM(Kc,2), 1, 9990);
  724. #endif//PID_ADD_EXTRUSION_RATE
  725. #if EXTRUDERS > 3
  726. // set up temp variables - undo the default scaling
  727. raw_Ki = unscalePID_i(PID_PARAM(Ki,3));
  728. raw_Kd = unscalePID_d(PID_PARAM(Kd,3));
  729. MENU_ITEM_EDIT(float52, MSG_PID_P MSG_E4, &PID_PARAM(Kp,3), 1, 9990);
  730. // i is typically a small value so allows values below 1
  731. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I MSG_E4, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E4);
  732. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D MSG_E4, &raw_Kd, 1, 9990, copy_and_scalePID_d_E4);
  733. #ifdef PID_ADD_EXTRUSION_RATE
  734. MENU_ITEM_EDIT(float3, MSG_PID_C MSG_E4, &PID_PARAM(Kc,3), 1, 9990);
  735. #endif//PID_ADD_EXTRUSION_RATE
  736. #endif//EXTRUDERS > 3
  737. #endif//EXTRUDERS > 2
  738. #endif//EXTRUDERS > 1
  739. #endif //PID_PARAMS_PER_EXTRUDER
  740. #endif//PIDTEMP
  741. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  742. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  743. END_MENU();
  744. }
  745. static void lcd_control_temperature_preheat_pla_settings_menu() {
  746. START_MENU();
  747. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  748. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  749. #if TEMP_SENSOR_0 != 0
  750. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  751. #endif
  752. #if TEMP_SENSOR_BED != 0
  753. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  754. #endif
  755. #ifdef EEPROM_SETTINGS
  756. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  757. #endif
  758. END_MENU();
  759. }
  760. static void lcd_control_temperature_preheat_abs_settings_menu() {
  761. START_MENU();
  762. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  763. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  764. #if TEMP_SENSOR_0 != 0
  765. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  766. #endif
  767. #if TEMP_SENSOR_BED != 0
  768. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  769. #endif
  770. #ifdef EEPROM_SETTINGS
  771. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  772. #endif
  773. END_MENU();
  774. }
  775. static void lcd_control_motion_menu() {
  776. START_MENU();
  777. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  778. #ifdef ENABLE_AUTO_BED_LEVELING
  779. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, 0.5, 50);
  780. #endif
  781. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
  782. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  783. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  784. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  785. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  786. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  787. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  788. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  789. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  790. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  791. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  792. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  793. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000, reset_acceleration_rates);
  794. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  795. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  796. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  797. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  798. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  799. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  800. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  801. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
  802. #endif
  803. #ifdef SCARA
  804. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS],0.5,2);
  805. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS],0.5,2);
  806. #endif
  807. END_MENU();
  808. }
  809. static void lcd_control_volumetric_menu()
  810. {
  811. START_MENU();
  812. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  813. MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
  814. if (volumetric_enabled) {
  815. MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_0, &filament_size[0], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
  816. #if EXTRUDERS > 1
  817. MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_1, &filament_size[1], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
  818. #if EXTRUDERS > 2
  819. MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_2, &filament_size[2], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
  820. #if EXTRUDERS > 3
  821. MENU_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_SIZE_EXTRUDER_3, &filament_size[3], DEFAULT_NOMINAL_FILAMENT_DIA - .5, DEFAULT_NOMINAL_FILAMENT_DIA + .5, calculate_volumetric_multipliers);
  822. #endif //EXTRUDERS > 3
  823. #endif //EXTRUDERS > 2
  824. #endif //EXTRUDERS > 1
  825. }
  826. END_MENU();
  827. }
  828. #ifdef DOGLCD
  829. static void lcd_set_contrast() {
  830. if (encoderPosition != 0) {
  831. lcd_contrast -= encoderPosition;
  832. if (lcd_contrast < 0) lcd_contrast = 0;
  833. else if (lcd_contrast > 63) lcd_contrast = 63;
  834. encoderPosition = 0;
  835. lcdDrawUpdate = 1;
  836. u8g.setContrast(lcd_contrast);
  837. }
  838. if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
  839. if (LCD_CLICKED) lcd_goto_menu(lcd_control_menu);
  840. }
  841. #endif //DOGLCD
  842. #ifdef FWRETRACT
  843. static void lcd_control_retract_menu() {
  844. START_MENU();
  845. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  846. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  847. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  848. #if EXTRUDERS > 1
  849. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  850. #endif
  851. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  852. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  853. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  854. #if EXTRUDERS > 1
  855. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  856. #endif
  857. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  858. END_MENU();
  859. }
  860. #endif //FWRETRACT
  861. #if SDCARDDETECT == -1
  862. static void lcd_sd_refresh() {
  863. card.initsd();
  864. currentMenuViewOffset = 0;
  865. }
  866. #endif
  867. static void lcd_sd_updir() {
  868. card.updir();
  869. currentMenuViewOffset = 0;
  870. }
  871. void lcd_sdcard_menu() {
  872. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0) return; // nothing to do (so don't thrash the SD card)
  873. uint16_t fileCnt = card.getnrfilenames();
  874. START_MENU();
  875. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  876. card.getWorkDirName();
  877. if (card.filename[0] == '/') {
  878. #if SDCARDDETECT == -1
  879. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  880. #endif
  881. }
  882. else {
  883. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  884. }
  885. for(uint16_t i = 0; i < fileCnt; i++) {
  886. if (_menuItemNr == _lineNr) {
  887. #ifndef SDCARD_RATHERRECENTFIRST
  888. card.getfilename(i);
  889. #else
  890. card.getfilename(fileCnt-1-i);
  891. #endif
  892. if (card.filenameIsDir)
  893. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  894. else
  895. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  896. }
  897. else {
  898. MENU_ITEM_DUMMY();
  899. }
  900. }
  901. END_MENU();
  902. }
  903. #define menu_edit_type(_type, _name, _strFunc, scale) \
  904. void menu_edit_ ## _name () { \
  905. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  906. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  907. if (lcdDrawUpdate) \
  908. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  909. if (LCD_CLICKED) { \
  910. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  911. lcd_goto_menu(prevMenu, prevEncoderPosition); \
  912. } \
  913. } \
  914. void menu_edit_callback_ ## _name () { \
  915. menu_edit_ ## _name (); \
  916. if (LCD_CLICKED) (*callbackFunc)(); \
  917. } \
  918. static void _menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  919. prevMenu = currentMenu; \
  920. prevEncoderPosition = encoderPosition; \
  921. \
  922. lcdDrawUpdate = 2; \
  923. currentMenu = menu_edit_ ## _name; \
  924. \
  925. editLabel = pstr; \
  926. editValue = ptr; \
  927. minEditValue = minValue * scale; \
  928. maxEditValue = maxValue * scale - minEditValue; \
  929. encoderPosition = (*ptr) * scale - minEditValue; \
  930. } \
  931. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) { \
  932. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  933. currentMenu = menu_edit_ ## _name; \
  934. }\
  935. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) { \
  936. _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
  937. currentMenu = menu_edit_callback_ ## _name; \
  938. callbackFunc = callback; \
  939. }
  940. menu_edit_type(int, int3, itostr3, 1)
  941. menu_edit_type(float, float3, ftostr3, 1)
  942. menu_edit_type(float, float32, ftostr32, 100)
  943. menu_edit_type(float, float43, ftostr43, 1000)
  944. menu_edit_type(float, float5, ftostr5, 0.01)
  945. menu_edit_type(float, float51, ftostr51, 10)
  946. menu_edit_type(float, float52, ftostr52, 100)
  947. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  948. #ifdef REPRAPWORLD_KEYPAD
  949. static void reprapworld_keypad_move_z_up() {
  950. encoderPosition = 1;
  951. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  952. lcd_move_z();
  953. }
  954. static void reprapworld_keypad_move_z_down() {
  955. encoderPosition = -1;
  956. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  957. lcd_move_z();
  958. }
  959. static void reprapworld_keypad_move_x_left() {
  960. encoderPosition = -1;
  961. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  962. lcd_move_x();
  963. }
  964. static void reprapworld_keypad_move_x_right() {
  965. encoderPosition = 1;
  966. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  967. lcd_move_x();
  968. }
  969. static void reprapworld_keypad_move_y_down() {
  970. encoderPosition = 1;
  971. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  972. lcd_move_y();
  973. }
  974. static void reprapworld_keypad_move_y_up() {
  975. encoderPosition = -1;
  976. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  977. lcd_move_y();
  978. }
  979. static void reprapworld_keypad_move_home() {
  980. enquecommands_P((PSTR("G28"))); // move all axis home
  981. }
  982. #endif //REPRAPWORLD_KEYPAD
  983. /** End of menus **/
  984. static void lcd_quick_feedback() {
  985. lcdDrawUpdate = 2;
  986. blocking_enc = millis() + 500;
  987. lcd_implementation_quick_feedback();
  988. }
  989. /** Menu action functions **/
  990. static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
  991. static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
  992. static void menu_action_gcode(const char* pgcode) { enquecommands_P(pgcode); }
  993. static void menu_action_function(menuFunc_t data) { (*data)(); }
  994. static void menu_action_sdfile(const char* filename, char* longFilename) {
  995. char cmd[30];
  996. char* c;
  997. sprintf_P(cmd, PSTR("M23 %s"), filename);
  998. for(c = &cmd[4]; *c; c++) *c = tolower(*c);
  999. enquecommand(cmd);
  1000. enquecommands_P(PSTR("M24"));
  1001. lcd_return_to_status();
  1002. }
  1003. static void menu_action_sddirectory(const char* filename, char* longFilename) {
  1004. card.chdir(filename);
  1005. encoderPosition = 0;
  1006. }
  1007. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr) { *ptr = !(*ptr); }
  1008. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback) {
  1009. menu_action_setting_edit_bool(pstr, ptr);
  1010. (*callback)();
  1011. }
  1012. #endif //ULTIPANEL
  1013. /** LCD API **/
  1014. void lcd_init() {
  1015. lcd_implementation_init();
  1016. #ifdef NEWPANEL
  1017. SET_INPUT(BTN_EN1);
  1018. SET_INPUT(BTN_EN2);
  1019. WRITE(BTN_EN1,HIGH);
  1020. WRITE(BTN_EN2,HIGH);
  1021. #if BTN_ENC > 0
  1022. SET_INPUT(BTN_ENC);
  1023. WRITE(BTN_ENC,HIGH);
  1024. #endif
  1025. #ifdef REPRAPWORLD_KEYPAD
  1026. pinMode(SHIFT_CLK,OUTPUT);
  1027. pinMode(SHIFT_LD,OUTPUT);
  1028. pinMode(SHIFT_OUT,INPUT);
  1029. WRITE(SHIFT_OUT,HIGH);
  1030. WRITE(SHIFT_LD,HIGH);
  1031. #endif
  1032. #else // Not NEWPANEL
  1033. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  1034. pinMode (SR_DATA_PIN, OUTPUT);
  1035. pinMode (SR_CLK_PIN, OUTPUT);
  1036. #elif defined(SHIFT_CLK)
  1037. pinMode(SHIFT_CLK,OUTPUT);
  1038. pinMode(SHIFT_LD,OUTPUT);
  1039. pinMode(SHIFT_EN,OUTPUT);
  1040. pinMode(SHIFT_OUT,INPUT);
  1041. WRITE(SHIFT_OUT,HIGH);
  1042. WRITE(SHIFT_LD,HIGH);
  1043. WRITE(SHIFT_EN,LOW);
  1044. #else
  1045. #ifdef ULTIPANEL
  1046. #error ULTIPANEL requires an encoder
  1047. #endif
  1048. #endif // SR_LCD_2W_NL
  1049. #endif//!NEWPANEL
  1050. #if defined(SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  1051. pinMode(SDCARDDETECT, INPUT);
  1052. WRITE(SDCARDDETECT, HIGH);
  1053. lcd_oldcardstatus = IS_SD_INSERTED;
  1054. #endif //(SDCARDDETECT > 0)
  1055. #ifdef LCD_HAS_SLOW_BUTTONS
  1056. slow_buttons = 0;
  1057. #endif
  1058. lcd_buttons_update();
  1059. #ifdef ULTIPANEL
  1060. encoderDiff = 0;
  1061. #endif
  1062. }
  1063. int lcd_strlen(char *s) {
  1064. int i = 0, j = 0;
  1065. while (s[i]) {
  1066. if ((s[i] & 0xc0) != 0x80) j++;
  1067. i++;
  1068. }
  1069. return j;
  1070. }
  1071. int lcd_strlen_P(const char *s) {
  1072. int j = 0;
  1073. while (pgm_read_byte(s)) {
  1074. if ((pgm_read_byte(s) & 0xc0) != 0x80) j++;
  1075. s++;
  1076. }
  1077. return j;
  1078. }
  1079. void lcd_update() {
  1080. static unsigned long timeoutToStatus = 0;
  1081. #ifdef LCD_HAS_SLOW_BUTTONS
  1082. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1083. #endif
  1084. lcd_buttons_update();
  1085. #if (SDCARDDETECT > 0)
  1086. if (IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()) {
  1087. lcdDrawUpdate = 2;
  1088. lcd_oldcardstatus = IS_SD_INSERTED;
  1089. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1090. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  1091. currentMenu == lcd_status_screen
  1092. #endif
  1093. );
  1094. if (lcd_oldcardstatus) {
  1095. card.initsd();
  1096. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1097. }
  1098. else {
  1099. card.release();
  1100. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1101. }
  1102. }
  1103. #endif//CARDINSERTED
  1104. if (millis() > lcd_next_update_millis) {
  1105. #ifdef ULTIPANEL
  1106. #ifdef REPRAPWORLD_KEYPAD
  1107. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
  1108. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) reprapworld_keypad_move_z_down();
  1109. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) reprapworld_keypad_move_x_left();
  1110. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) reprapworld_keypad_move_x_right();
  1111. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) reprapworld_keypad_move_y_down();
  1112. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) reprapworld_keypad_move_y_up();
  1113. if (REPRAPWORLD_KEYPAD_MOVE_HOME) reprapworld_keypad_move_home();
  1114. #endif
  1115. bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
  1116. if (encoderPastThreshold || LCD_CLICKED) {
  1117. if (encoderPastThreshold) {
  1118. lcdDrawUpdate = 1;
  1119. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  1120. encoderDiff = 0;
  1121. }
  1122. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1123. }
  1124. #endif //ULTIPANEL
  1125. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  1126. blink++; // Variable for fan animation and alive dot
  1127. u8g.firstPage();
  1128. do {
  1129. u8g.setFont(FONT_MENU);
  1130. u8g.setPrintPos(125, 0);
  1131. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1132. u8g.drawPixel(127, 63); // draw alive dot
  1133. u8g.setColorIndex(1); // black on white
  1134. (*currentMenu)();
  1135. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  1136. } while( u8g.nextPage() );
  1137. #else
  1138. (*currentMenu)();
  1139. #endif
  1140. #ifdef LCD_HAS_STATUS_INDICATORS
  1141. lcd_implementation_update_indicators();
  1142. #endif
  1143. #ifdef ULTIPANEL
  1144. if (currentMenu != lcd_status_screen && millis() > timeoutToStatus) {
  1145. lcd_return_to_status();
  1146. lcdDrawUpdate = 2;
  1147. }
  1148. #endif //ULTIPANEL
  1149. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1150. if (lcdDrawUpdate) lcdDrawUpdate--;
  1151. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  1152. }
  1153. }
  1154. void lcd_ignore_click(bool b) {
  1155. ignore_click = b;
  1156. wait_for_unclick = false;
  1157. }
  1158. void lcd_finishstatus() {
  1159. int len = lcd_strlen(lcd_status_message);
  1160. if (len > 0) {
  1161. while (len < LCD_WIDTH) {
  1162. lcd_status_message[len++] = ' ';
  1163. }
  1164. }
  1165. lcd_status_message[LCD_WIDTH] = '\0';
  1166. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT) && !defined(DOGLCD)
  1167. #if PROGRESS_MSG_EXPIRE > 0
  1168. messageTick =
  1169. #endif
  1170. progressBarTick = millis();
  1171. #endif
  1172. lcdDrawUpdate = 2;
  1173. #ifdef FILAMENT_LCD_DISPLAY
  1174. message_millis = millis(); //get status message to show up for a while
  1175. #endif
  1176. }
  1177. void lcd_setstatus(const char* message) {
  1178. if (lcd_status_message_level > 0) return;
  1179. strncpy(lcd_status_message, message, LCD_WIDTH);
  1180. lcd_finishstatus();
  1181. }
  1182. void lcd_setstatuspgm(const char* message) {
  1183. if (lcd_status_message_level > 0) return;
  1184. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  1185. lcd_finishstatus();
  1186. }
  1187. void lcd_setalertstatuspgm(const char* message) {
  1188. lcd_setstatuspgm(message);
  1189. lcd_status_message_level = 1;
  1190. #ifdef ULTIPANEL
  1191. lcd_return_to_status();
  1192. #endif
  1193. }
  1194. void lcd_reset_alert_level() { lcd_status_message_level = 0; }
  1195. #ifdef DOGLCD
  1196. void lcd_setcontrast(uint8_t value) {
  1197. lcd_contrast = value & 63;
  1198. u8g.setContrast(lcd_contrast);
  1199. }
  1200. #endif
  1201. #ifdef ULTIPANEL
  1202. /* Warning: This function is called from interrupt context */
  1203. void lcd_buttons_update() {
  1204. #ifdef NEWPANEL
  1205. uint8_t newbutton = 0;
  1206. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  1207. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  1208. #if BTN_ENC > 0
  1209. if (millis() > blocking_enc && READ(BTN_ENC) == 0) newbutton |= EN_C;
  1210. #endif
  1211. buttons = newbutton;
  1212. #ifdef LCD_HAS_SLOW_BUTTONS
  1213. buttons |= slow_buttons;
  1214. #endif
  1215. #ifdef REPRAPWORLD_KEYPAD
  1216. // for the reprapworld_keypad
  1217. uint8_t newbutton_reprapworld_keypad=0;
  1218. WRITE(SHIFT_LD, LOW);
  1219. WRITE(SHIFT_LD, HIGH);
  1220. for(int8_t i = 0; i < 8; i++) {
  1221. newbutton_reprapworld_keypad >>= 1;
  1222. if (READ(SHIFT_OUT)) newbutton_reprapworld_keypad |= (1 << 7);
  1223. WRITE(SHIFT_CLK, HIGH);
  1224. WRITE(SHIFT_CLK, LOW);
  1225. }
  1226. buttons_reprapworld_keypad=~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1227. #endif
  1228. #else //read it from the shift register
  1229. uint8_t newbutton = 0;
  1230. WRITE(SHIFT_LD, LOW);
  1231. WRITE(SHIFT_LD, HIGH);
  1232. unsigned char tmp_buttons = 0;
  1233. for(int8_t i=0; i<8; i++) {
  1234. newbutton >>= 1;
  1235. if (READ(SHIFT_OUT)) newbutton |= (1 << 7);
  1236. WRITE(SHIFT_CLK, HIGH);
  1237. WRITE(SHIFT_CLK, LOW);
  1238. }
  1239. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  1240. #endif //!NEWPANEL
  1241. //manage encoder rotation
  1242. uint8_t enc=0;
  1243. if (buttons & EN_A) enc |= B01;
  1244. if (buttons & EN_B) enc |= B10;
  1245. if (enc != lastEncoderBits) {
  1246. switch(enc) {
  1247. case encrot0:
  1248. if (lastEncoderBits==encrot3) encoderDiff++;
  1249. else if (lastEncoderBits==encrot1) encoderDiff--;
  1250. break;
  1251. case encrot1:
  1252. if (lastEncoderBits==encrot0) encoderDiff++;
  1253. else if (lastEncoderBits==encrot2) encoderDiff--;
  1254. break;
  1255. case encrot2:
  1256. if (lastEncoderBits==encrot1) encoderDiff++;
  1257. else if (lastEncoderBits==encrot3) encoderDiff--;
  1258. break;
  1259. case encrot3:
  1260. if (lastEncoderBits==encrot2) encoderDiff++;
  1261. else if (lastEncoderBits==encrot0) encoderDiff--;
  1262. break;
  1263. }
  1264. }
  1265. lastEncoderBits = enc;
  1266. }
  1267. bool lcd_detected(void) {
  1268. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  1269. return lcd.LcdDetected() == 1;
  1270. #else
  1271. return true;
  1272. #endif
  1273. }
  1274. void lcd_buzz(long duration, uint16_t freq) {
  1275. #ifdef LCD_USE_I2C_BUZZER
  1276. lcd.buzz(duration,freq);
  1277. #endif
  1278. }
  1279. bool lcd_clicked() { return LCD_CLICKED; }
  1280. #endif //ULTIPANEL
  1281. /********************************/
  1282. /** Float conversion utilities **/
  1283. /********************************/
  1284. // convert float to string with +123.4 format
  1285. char conv[8];
  1286. char *ftostr3(const float &x)
  1287. {
  1288. return itostr3((int)x);
  1289. }
  1290. char *itostr2(const uint8_t &x)
  1291. {
  1292. //sprintf(conv,"%5.1f",x);
  1293. int xx=x;
  1294. conv[0]=(xx/10)%10+'0';
  1295. conv[1]=(xx)%10+'0';
  1296. conv[2]=0;
  1297. return conv;
  1298. }
  1299. // Convert float to string with 123.4 format, dropping sign
  1300. char *ftostr31(const float &x)
  1301. {
  1302. int xx=x*10;
  1303. conv[0]=(xx>=0)?'+':'-';
  1304. xx=abs(xx);
  1305. conv[1]=(xx/1000)%10+'0';
  1306. conv[2]=(xx/100)%10+'0';
  1307. conv[3]=(xx/10)%10+'0';
  1308. conv[4]='.';
  1309. conv[5]=(xx)%10+'0';
  1310. conv[6]=0;
  1311. return conv;
  1312. }
  1313. // Convert float to string with 123.4 format
  1314. char *ftostr31ns(const float &x)
  1315. {
  1316. int xx=x*10;
  1317. //conv[0]=(xx>=0)?'+':'-';
  1318. xx=abs(xx);
  1319. conv[0]=(xx/1000)%10+'0';
  1320. conv[1]=(xx/100)%10+'0';
  1321. conv[2]=(xx/10)%10+'0';
  1322. conv[3]='.';
  1323. conv[4]=(xx)%10+'0';
  1324. conv[5]=0;
  1325. return conv;
  1326. }
  1327. char *ftostr32(const float &x)
  1328. {
  1329. long xx=x*100;
  1330. if (xx >= 0)
  1331. conv[0]=(xx/10000)%10+'0';
  1332. else
  1333. conv[0]='-';
  1334. xx=abs(xx);
  1335. conv[1]=(xx/1000)%10+'0';
  1336. conv[2]=(xx/100)%10+'0';
  1337. conv[3]='.';
  1338. conv[4]=(xx/10)%10+'0';
  1339. conv[5]=(xx)%10+'0';
  1340. conv[6]=0;
  1341. return conv;
  1342. }
  1343. // Convert float to string with 1.234 format
  1344. char *ftostr43(const float &x)
  1345. {
  1346. long xx = x * 1000;
  1347. if (xx >= 0)
  1348. conv[0] = (xx / 1000) % 10 + '0';
  1349. else
  1350. conv[0] = '-';
  1351. xx = abs(xx);
  1352. conv[1] = '.';
  1353. conv[2] = (xx / 100) % 10 + '0';
  1354. conv[3] = (xx / 10) % 10 + '0';
  1355. conv[4] = (xx) % 10 + '0';
  1356. conv[5] = 0;
  1357. return conv;
  1358. }
  1359. //Float to string with 1.23 format
  1360. char *ftostr12ns(const float &x)
  1361. {
  1362. long xx=x*100;
  1363. xx=abs(xx);
  1364. conv[0]=(xx/100)%10+'0';
  1365. conv[1]='.';
  1366. conv[2]=(xx/10)%10+'0';
  1367. conv[3]=(xx)%10+'0';
  1368. conv[4]=0;
  1369. return conv;
  1370. }
  1371. // convert float to space-padded string with -_23.4_ format
  1372. char *ftostr32sp(const float &x) {
  1373. long xx = abs(x * 100);
  1374. uint8_t dig;
  1375. if (x < 0) { // negative val = -_0
  1376. conv[0] = '-';
  1377. dig = (xx / 1000) % 10;
  1378. conv[1] = dig ? '0' + dig : ' ';
  1379. }
  1380. else { // positive val = __0
  1381. dig = (xx / 10000) % 10;
  1382. if (dig) {
  1383. conv[0] = '0' + dig;
  1384. conv[1] = '0' + (xx / 1000) % 10;
  1385. }
  1386. else {
  1387. conv[0] = ' ';
  1388. dig = (xx / 1000) % 10;
  1389. conv[1] = dig ? '0' + dig : ' ';
  1390. }
  1391. }
  1392. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1393. dig = xx % 10;
  1394. if (dig) { // 2 decimal places
  1395. conv[5] = '0' + dig;
  1396. conv[4] = '0' + (xx / 10) % 10;
  1397. conv[3] = '.';
  1398. }
  1399. else { // 1 or 0 decimal place
  1400. dig = (xx / 10) % 10;
  1401. if (dig) {
  1402. conv[4] = '0' + dig;
  1403. conv[3] = '.';
  1404. }
  1405. else {
  1406. conv[3] = conv[4] = ' ';
  1407. }
  1408. conv[5] = ' ';
  1409. }
  1410. conv[6] = '\0';
  1411. return conv;
  1412. }
  1413. char *itostr31(const int &xx)
  1414. {
  1415. conv[0]=(xx>=0)?'+':'-';
  1416. conv[1]=(xx/1000)%10+'0';
  1417. conv[2]=(xx/100)%10+'0';
  1418. conv[3]=(xx/10)%10+'0';
  1419. conv[4]='.';
  1420. conv[5]=(xx)%10+'0';
  1421. conv[6]=0;
  1422. return conv;
  1423. }
  1424. // Convert int to rj string with 123 or -12 format
  1425. char *itostr3(const int &x)
  1426. {
  1427. int xx = x;
  1428. if (xx < 0) {
  1429. conv[0]='-';
  1430. xx = -xx;
  1431. } else if (xx >= 100)
  1432. conv[0]=(xx/100)%10+'0';
  1433. else
  1434. conv[0]=' ';
  1435. if (xx >= 10)
  1436. conv[1]=(xx/10)%10+'0';
  1437. else
  1438. conv[1]=' ';
  1439. conv[2]=(xx)%10+'0';
  1440. conv[3]=0;
  1441. return conv;
  1442. }
  1443. // Convert int to lj string with 123 format
  1444. char *itostr3left(const int &xx)
  1445. {
  1446. if (xx >= 100)
  1447. {
  1448. conv[0]=(xx/100)%10+'0';
  1449. conv[1]=(xx/10)%10+'0';
  1450. conv[2]=(xx)%10+'0';
  1451. conv[3]=0;
  1452. }
  1453. else if (xx >= 10)
  1454. {
  1455. conv[0]=(xx/10)%10+'0';
  1456. conv[1]=(xx)%10+'0';
  1457. conv[2]=0;
  1458. }
  1459. else
  1460. {
  1461. conv[0]=(xx)%10+'0';
  1462. conv[1]=0;
  1463. }
  1464. return conv;
  1465. }
  1466. // Convert int to rj string with 1234 format
  1467. char *itostr4(const int &xx) {
  1468. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1469. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1470. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1471. conv[3] = xx % 10 + '0';
  1472. conv[4] = 0;
  1473. return conv;
  1474. }
  1475. // Convert float to rj string with 12345 format
  1476. char *ftostr5(const float &x) {
  1477. long xx = abs(x);
  1478. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  1479. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1480. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1481. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1482. conv[4] = xx % 10 + '0';
  1483. conv[5] = 0;
  1484. return conv;
  1485. }
  1486. // Convert float to string with +1234.5 format
  1487. char *ftostr51(const float &x)
  1488. {
  1489. long xx=x*10;
  1490. conv[0]=(xx>=0)?'+':'-';
  1491. xx=abs(xx);
  1492. conv[1]=(xx/10000)%10+'0';
  1493. conv[2]=(xx/1000)%10+'0';
  1494. conv[3]=(xx/100)%10+'0';
  1495. conv[4]=(xx/10)%10+'0';
  1496. conv[5]='.';
  1497. conv[6]=(xx)%10+'0';
  1498. conv[7]=0;
  1499. return conv;
  1500. }
  1501. // Convert float to string with +123.45 format
  1502. char *ftostr52(const float &x)
  1503. {
  1504. long xx=x*100;
  1505. conv[0]=(xx>=0)?'+':'-';
  1506. xx=abs(xx);
  1507. conv[1]=(xx/10000)%10+'0';
  1508. conv[2]=(xx/1000)%10+'0';
  1509. conv[3]=(xx/100)%10+'0';
  1510. conv[4]='.';
  1511. conv[5]=(xx/10)%10+'0';
  1512. conv[6]=(xx)%10+'0';
  1513. conv[7]=0;
  1514. return conv;
  1515. }
  1516. #endif //ULTRA_LCD