My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.cpp 38KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #ifdef ULTRA_LCD
  4. #include "Marlin.h"
  5. #include "language.h"
  6. #include "cardreader.h"
  7. #include "temperature.h"
  8. #include "stepper.h"
  9. #include "ConfigurationStore.h"
  10. /* Configuration settings */
  11. int plaPreheatHotendTemp;
  12. int plaPreheatHPBTemp;
  13. int plaPreheatFanSpeed;
  14. int absPreheatHotendTemp;
  15. int absPreheatHPBTemp;
  16. int absPreheatFanSpeed;
  17. /* !Configuration settings */
  18. //Function pointer to menu functions.
  19. typedef void (*menuFunc_t)();
  20. uint8_t lcd_status_message_level;
  21. char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
  22. #ifdef DOGLCD
  23. #include "dogm_lcd_implementation.h"
  24. #else
  25. #include "ultralcd_implementation_hitachi_HD44780.h"
  26. #endif
  27. /** forward declerations **/
  28. void copy_and_scalePID_i();
  29. void copy_and_scalePID_d();
  30. /* Different menus */
  31. static void lcd_status_screen();
  32. #ifdef ULTIPANEL
  33. static void lcd_main_menu();
  34. static void lcd_tune_menu();
  35. static void lcd_prepare_menu();
  36. static void lcd_move_menu();
  37. static void lcd_control_menu();
  38. static void lcd_control_temperature_menu();
  39. static void lcd_control_temperature_preheat_pla_settings_menu();
  40. static void lcd_control_temperature_preheat_abs_settings_menu();
  41. static void lcd_control_motion_menu();
  42. static void lcd_control_retract_menu();
  43. static void lcd_sdcard_menu();
  44. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audiable feedback that something has happend
  45. /* Different types of actions that can be used in menuitems. */
  46. static void menu_action_back(menuFunc_t data);
  47. static void menu_action_submenu(menuFunc_t data);
  48. static void menu_action_gcode(const char* pgcode);
  49. static void menu_action_function(menuFunc_t data);
  50. static void menu_action_sdfile(const char* filename, char* longFilename);
  51. static void menu_action_sddirectory(const char* filename, char* longFilename);
  52. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  53. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  54. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  55. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  56. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  57. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  58. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  59. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  60. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  61. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  62. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  63. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  64. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  65. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  66. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  67. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  68. #define ENCODER_FEEDRATE_DEADZONE 10
  69. #if !defined(LCD_I2C_VIKI)
  70. #define ENCODER_STEPS_PER_MENU_ITEM 5
  71. #else
  72. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  73. #endif
  74. /* Helper macros for menus */
  75. #define START_MENU() do { \
  76. if (encoderPosition > 0x8000) encoderPosition = 0; \
  77. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  78. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  79. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  80. _menuItemNr = 0;
  81. #define MENU_ITEM(type, label, args...) do { \
  82. if (_menuItemNr == _lineNr) { \
  83. if (lcdDrawUpdate) { \
  84. const char* _label_pstr = PSTR(label); \
  85. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  86. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  87. }else{\
  88. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  89. }\
  90. }\
  91. if (LCD_CLICKED && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  92. lcd_quick_feedback(); \
  93. menu_action_ ## type ( args ); \
  94. return;\
  95. }\
  96. }\
  97. _menuItemNr++;\
  98. } while(0)
  99. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  100. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  101. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
  102. #define END_MENU() \
  103. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  104. 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; } \
  105. } } while(0)
  106. /** Used variables to keep track of the menu */
  107. #ifndef REPRAPWORLD_KEYPAD
  108. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  109. #else
  110. volatile uint16_t buttons;//Contains the bits of the currently pressed buttons (extended).
  111. #endif
  112. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  113. uint32_t blocking_enc;
  114. uint8_t lastEncoderBits;
  115. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  116. uint32_t encoderPosition;
  117. #if (SDCARDDETECT > 0)
  118. bool lcd_oldcardstatus;
  119. #endif
  120. #endif//ULTIPANEL
  121. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  122. uint32_t lcd_next_update_millis;
  123. uint8_t lcd_status_update_delay;
  124. 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) */
  125. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  126. menuFunc_t prevMenu = NULL;
  127. uint16_t prevEncoderPosition;
  128. //Variables used when editing values.
  129. const char* editLabel;
  130. void* editValue;
  131. int32_t minEditValue, maxEditValue;
  132. menuFunc_t callbackFunc;
  133. // placeholders for Ki and Kd edits
  134. float raw_Ki, raw_Kd;
  135. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependend */
  136. static void lcd_status_screen()
  137. {
  138. if (lcd_status_update_delay)
  139. lcd_status_update_delay--;
  140. else
  141. lcdDrawUpdate = 1;
  142. if (lcdDrawUpdate)
  143. {
  144. lcd_implementation_status_screen();
  145. 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 */
  146. }
  147. #ifdef ULTIPANEL
  148. if (LCD_CLICKED)
  149. {
  150. currentMenu = lcd_main_menu;
  151. encoderPosition = 0;
  152. lcd_quick_feedback();
  153. }
  154. // Dead zone at 100% feedrate
  155. if (feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100 ||
  156. feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100)
  157. {
  158. encoderPosition = 0;
  159. feedmultiply = 100;
  160. }
  161. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  162. {
  163. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  164. encoderPosition = 0;
  165. }
  166. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  167. {
  168. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  169. encoderPosition = 0;
  170. }
  171. else if (feedmultiply != 100)
  172. {
  173. feedmultiply += int(encoderPosition);
  174. encoderPosition = 0;
  175. }
  176. if (feedmultiply < 10)
  177. feedmultiply = 10;
  178. if (feedmultiply > 999)
  179. feedmultiply = 999;
  180. #endif//ULTIPANEL
  181. }
  182. #ifdef ULTIPANEL
  183. static void lcd_return_to_status()
  184. {
  185. encoderPosition = 0;
  186. currentMenu = lcd_status_screen;
  187. }
  188. static void lcd_sdcard_pause()
  189. {
  190. card.pauseSDPrint();
  191. }
  192. static void lcd_sdcard_resume()
  193. {
  194. card.startFileprint();
  195. }
  196. static void lcd_sdcard_stop()
  197. {
  198. card.sdprinting = false;
  199. card.closefile();
  200. quickStop();
  201. if(SD_FINISHED_STEPPERRELEASE)
  202. {
  203. enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
  204. }
  205. autotempShutdown();
  206. }
  207. /* Menu implementation */
  208. static void lcd_main_menu()
  209. {
  210. START_MENU();
  211. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  212. if (movesplanned() || IS_SD_PRINTING)
  213. {
  214. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  215. }else{
  216. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  217. }
  218. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  219. #ifdef SDSUPPORT
  220. if (card.cardOK)
  221. {
  222. if (card.isFileOpen())
  223. {
  224. if (card.sdprinting)
  225. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  226. else
  227. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  228. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  229. }else{
  230. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  231. #if SDCARDDETECT < 1
  232. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  233. #endif
  234. }
  235. }else{
  236. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  237. #if SDCARDDETECT < 1
  238. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  239. #endif
  240. }
  241. #endif
  242. END_MENU();
  243. }
  244. #ifdef SDSUPPORT
  245. static void lcd_autostart_sd()
  246. {
  247. card.lastnr=0;
  248. card.setroot();
  249. card.checkautostart(true);
  250. }
  251. #endif
  252. void lcd_preheat_pla()
  253. {
  254. setTargetHotend0(plaPreheatHotendTemp);
  255. setTargetHotend1(plaPreheatHotendTemp);
  256. setTargetHotend2(plaPreheatHotendTemp);
  257. setTargetBed(plaPreheatHPBTemp);
  258. fanSpeed = plaPreheatFanSpeed;
  259. lcd_return_to_status();
  260. setWatch(); // heater sanity check timer
  261. }
  262. void lcd_preheat_abs()
  263. {
  264. setTargetHotend0(absPreheatHotendTemp);
  265. setTargetHotend1(absPreheatHotendTemp);
  266. setTargetHotend2(absPreheatHotendTemp);
  267. setTargetBed(absPreheatHPBTemp);
  268. fanSpeed = absPreheatFanSpeed;
  269. lcd_return_to_status();
  270. setWatch(); // heater sanity check timer
  271. }
  272. static void lcd_cooldown()
  273. {
  274. setTargetHotend0(0);
  275. setTargetHotend1(0);
  276. setTargetHotend2(0);
  277. setTargetBed(0);
  278. lcd_return_to_status();
  279. }
  280. static void lcd_tune_menu()
  281. {
  282. START_MENU();
  283. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  284. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);
  285. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  286. #if TEMP_SENSOR_1 != 0
  287. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  288. #endif
  289. #if TEMP_SENSOR_2 != 0
  290. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  291. #endif
  292. #if TEMP_SENSOR_BED != 0
  293. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  294. #endif
  295. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  296. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);
  297. #ifdef FILAMENTCHANGEENABLE
  298. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  299. #endif
  300. END_MENU();
  301. }
  302. static void lcd_prepare_menu()
  303. {
  304. START_MENU();
  305. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  306. #ifdef SDSUPPORT
  307. //MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  308. #endif
  309. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  310. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  311. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  312. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla);
  313. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs);
  314. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  315. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  316. END_MENU();
  317. }
  318. float move_menu_scale;
  319. static void lcd_move_menu_axis();
  320. static void lcd_move_x()
  321. {
  322. if (encoderPosition != 0)
  323. {
  324. current_position[X_AXIS] += float((int)encoderPosition) * move_menu_scale;
  325. if (min_software_endstops && current_position[X_AXIS] < X_MIN_POS)
  326. current_position[X_AXIS] = X_MIN_POS;
  327. if (max_software_endstops && current_position[X_AXIS] > X_MAX_POS)
  328. current_position[X_AXIS] = X_MAX_POS;
  329. encoderPosition = 0;
  330. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  331. lcdDrawUpdate = 1;
  332. }
  333. if (lcdDrawUpdate)
  334. {
  335. lcd_implementation_drawedit(PSTR("X"), ftostr31(current_position[X_AXIS]));
  336. }
  337. if (LCD_CLICKED)
  338. {
  339. lcd_quick_feedback();
  340. currentMenu = lcd_move_menu_axis;
  341. encoderPosition = 0;
  342. }
  343. }
  344. static void lcd_move_y()
  345. {
  346. if (encoderPosition != 0)
  347. {
  348. current_position[Y_AXIS] += float((int)encoderPosition) * move_menu_scale;
  349. if (min_software_endstops && current_position[Y_AXIS] < Y_MIN_POS)
  350. current_position[Y_AXIS] = Y_MIN_POS;
  351. if (max_software_endstops && current_position[Y_AXIS] > Y_MAX_POS)
  352. current_position[Y_AXIS] = Y_MAX_POS;
  353. encoderPosition = 0;
  354. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600, active_extruder);
  355. lcdDrawUpdate = 1;
  356. }
  357. if (lcdDrawUpdate)
  358. {
  359. lcd_implementation_drawedit(PSTR("Y"), ftostr31(current_position[Y_AXIS]));
  360. }
  361. if (LCD_CLICKED)
  362. {
  363. lcd_quick_feedback();
  364. currentMenu = lcd_move_menu_axis;
  365. encoderPosition = 0;
  366. }
  367. }
  368. static void lcd_move_z()
  369. {
  370. if (encoderPosition != 0)
  371. {
  372. current_position[Z_AXIS] += float((int)encoderPosition) * move_menu_scale;
  373. if (min_software_endstops && current_position[Z_AXIS] < Z_MIN_POS)
  374. current_position[Z_AXIS] = Z_MIN_POS;
  375. if (max_software_endstops && current_position[Z_AXIS] > Z_MAX_POS)
  376. current_position[Z_AXIS] = Z_MAX_POS;
  377. encoderPosition = 0;
  378. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 60, active_extruder);
  379. lcdDrawUpdate = 1;
  380. }
  381. if (lcdDrawUpdate)
  382. {
  383. lcd_implementation_drawedit(PSTR("Z"), ftostr31(current_position[Z_AXIS]));
  384. }
  385. if (LCD_CLICKED)
  386. {
  387. lcd_quick_feedback();
  388. currentMenu = lcd_move_menu_axis;
  389. encoderPosition = 0;
  390. }
  391. }
  392. static void lcd_move_e()
  393. {
  394. if (encoderPosition != 0)
  395. {
  396. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  397. encoderPosition = 0;
  398. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 20, active_extruder);
  399. lcdDrawUpdate = 1;
  400. }
  401. if (lcdDrawUpdate)
  402. {
  403. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  404. }
  405. if (LCD_CLICKED)
  406. {
  407. lcd_quick_feedback();
  408. currentMenu = lcd_move_menu_axis;
  409. encoderPosition = 0;
  410. }
  411. }
  412. static void lcd_move_menu_axis()
  413. {
  414. START_MENU();
  415. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  416. MENU_ITEM(submenu, "Move X", lcd_move_x);
  417. MENU_ITEM(submenu, "Move Y", lcd_move_y);
  418. if (move_menu_scale < 10.0)
  419. {
  420. MENU_ITEM(submenu, "Move Z", lcd_move_z);
  421. MENU_ITEM(submenu, "Extruder", lcd_move_e);
  422. }
  423. END_MENU();
  424. }
  425. static void lcd_move_menu_10mm()
  426. {
  427. move_menu_scale = 10.0;
  428. lcd_move_menu_axis();
  429. }
  430. static void lcd_move_menu_1mm()
  431. {
  432. move_menu_scale = 1.0;
  433. lcd_move_menu_axis();
  434. }
  435. static void lcd_move_menu_01mm()
  436. {
  437. move_menu_scale = 0.1;
  438. lcd_move_menu_axis();
  439. }
  440. static void lcd_move_menu()
  441. {
  442. START_MENU();
  443. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  444. MENU_ITEM(submenu, "Move 10mm", lcd_move_menu_10mm);
  445. MENU_ITEM(submenu, "Move 1mm", lcd_move_menu_1mm);
  446. MENU_ITEM(submenu, "Move 0.1mm", lcd_move_menu_01mm);
  447. //TODO:X,Y,Z,E
  448. END_MENU();
  449. }
  450. static void lcd_control_menu()
  451. {
  452. START_MENU();
  453. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  454. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  455. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  456. #ifdef FWRETRACT
  457. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  458. #endif
  459. #ifdef EEPROM_SETTINGS
  460. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  461. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  462. #endif
  463. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  464. END_MENU();
  465. }
  466. static void lcd_control_temperature_menu()
  467. {
  468. #ifdef PIDTEMP
  469. // set up temp variables - undo the default scaling
  470. raw_Ki = unscalePID_i(Ki);
  471. raw_Kd = unscalePID_d(Kd);
  472. #endif
  473. START_MENU();
  474. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  475. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  476. #if TEMP_SENSOR_1 != 0
  477. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  478. #endif
  479. #if TEMP_SENSOR_2 != 0
  480. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  481. #endif
  482. #if TEMP_SENSOR_BED != 0
  483. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  484. #endif
  485. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  486. #ifdef AUTOTEMP
  487. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  488. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  489. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  490. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  491. #endif
  492. #ifdef PIDTEMP
  493. MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
  494. // i is typically a small value so allows values below 1
  495. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
  496. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
  497. # ifdef PID_ADD_EXTRUSION_RATE
  498. MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
  499. # endif//PID_ADD_EXTRUSION_RATE
  500. #endif//PIDTEMP
  501. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  502. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  503. END_MENU();
  504. }
  505. static void lcd_control_temperature_preheat_pla_settings_menu()
  506. {
  507. START_MENU();
  508. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  509. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  510. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  511. #if TEMP_SENSOR_BED != 0
  512. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  513. #endif
  514. #ifdef EEPROM_SETTINGS
  515. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  516. #endif
  517. END_MENU();
  518. }
  519. static void lcd_control_temperature_preheat_abs_settings_menu()
  520. {
  521. START_MENU();
  522. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  523. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  524. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  525. #if TEMP_SENSOR_BED != 0
  526. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  527. #endif
  528. #ifdef EEPROM_SETTINGS
  529. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  530. #endif
  531. END_MENU();
  532. }
  533. static void lcd_control_motion_menu()
  534. {
  535. START_MENU();
  536. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  537. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
  538. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  539. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  540. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  541. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  542. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  543. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  544. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  545. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  546. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  547. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  548. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  549. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000, reset_acceleration_rates);
  550. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  551. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  552. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  553. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  554. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  555. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  556. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  557. MENU_ITEM_EDIT(bool, "Endstop abort", &abort_on_endstop_hit);
  558. #endif
  559. END_MENU();
  560. }
  561. #ifdef FWRETRACT
  562. static void lcd_control_retract_menu()
  563. {
  564. START_MENU();
  565. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  566. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  567. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  568. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  569. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  570. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  571. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  572. END_MENU();
  573. }
  574. #endif
  575. #if SDCARDDETECT == -1
  576. static void lcd_sd_refresh()
  577. {
  578. card.initsd();
  579. currentMenuViewOffset = 0;
  580. }
  581. #endif
  582. static void lcd_sd_updir()
  583. {
  584. card.updir();
  585. currentMenuViewOffset = 0;
  586. }
  587. void lcd_sdcard_menu()
  588. {
  589. uint16_t fileCnt = card.getnrfilenames();
  590. START_MENU();
  591. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  592. card.getWorkDirName();
  593. if(card.filename[0]=='/')
  594. {
  595. #if SDCARDDETECT == -1
  596. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  597. #endif
  598. }else{
  599. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  600. }
  601. for(uint16_t i=0;i<fileCnt;i++)
  602. {
  603. if (_menuItemNr == _lineNr)
  604. {
  605. card.getfilename(i);
  606. if (card.filenameIsDir)
  607. {
  608. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  609. }else{
  610. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  611. }
  612. }else{
  613. MENU_ITEM_DUMMY();
  614. }
  615. }
  616. END_MENU();
  617. }
  618. #define menu_edit_type(_type, _name, _strFunc, scale) \
  619. void menu_edit_ ## _name () \
  620. { \
  621. if ((int32_t)encoderPosition < minEditValue) \
  622. encoderPosition = minEditValue; \
  623. if ((int32_t)encoderPosition > maxEditValue) \
  624. encoderPosition = maxEditValue; \
  625. if (lcdDrawUpdate) \
  626. lcd_implementation_drawedit(editLabel, _strFunc(((_type)encoderPosition) / scale)); \
  627. if (LCD_CLICKED) \
  628. { \
  629. *((_type*)editValue) = ((_type)encoderPosition) / scale; \
  630. lcd_quick_feedback(); \
  631. currentMenu = prevMenu; \
  632. encoderPosition = prevEncoderPosition; \
  633. } \
  634. } \
  635. void menu_edit_callback_ ## _name () \
  636. { \
  637. if ((int32_t)encoderPosition < minEditValue) \
  638. encoderPosition = minEditValue; \
  639. if ((int32_t)encoderPosition > maxEditValue) \
  640. encoderPosition = maxEditValue; \
  641. if (lcdDrawUpdate) \
  642. lcd_implementation_drawedit(editLabel, _strFunc(((_type)encoderPosition) / scale)); \
  643. if (LCD_CLICKED) \
  644. { \
  645. *((_type*)editValue) = ((_type)encoderPosition) / scale; \
  646. lcd_quick_feedback(); \
  647. currentMenu = prevMenu; \
  648. encoderPosition = prevEncoderPosition; \
  649. (*callbackFunc)();\
  650. } \
  651. } \
  652. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  653. { \
  654. prevMenu = currentMenu; \
  655. prevEncoderPosition = encoderPosition; \
  656. \
  657. lcdDrawUpdate = 2; \
  658. currentMenu = menu_edit_ ## _name; \
  659. \
  660. editLabel = pstr; \
  661. editValue = ptr; \
  662. minEditValue = minValue * scale; \
  663. maxEditValue = maxValue * scale; \
  664. encoderPosition = (*ptr) * scale; \
  665. }\
  666. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  667. { \
  668. prevMenu = currentMenu; \
  669. prevEncoderPosition = encoderPosition; \
  670. \
  671. lcdDrawUpdate = 2; \
  672. currentMenu = menu_edit_callback_ ## _name; \
  673. \
  674. editLabel = pstr; \
  675. editValue = ptr; \
  676. minEditValue = minValue * scale; \
  677. maxEditValue = maxValue * scale; \
  678. encoderPosition = (*ptr) * scale; \
  679. callbackFunc = callback;\
  680. }
  681. menu_edit_type(int, int3, itostr3, 1)
  682. menu_edit_type(float, float3, ftostr3, 1)
  683. menu_edit_type(float, float32, ftostr32, 100)
  684. menu_edit_type(float, float5, ftostr5, 0.01)
  685. menu_edit_type(float, float51, ftostr51, 10)
  686. menu_edit_type(float, float52, ftostr52, 100)
  687. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  688. #ifdef REPRAPWORLD_KEYPAD
  689. static void reprapworld_keypad_move_y_down() {
  690. encoderPosition = 1;
  691. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  692. lcd_move_y();
  693. }
  694. static void reprapworld_keypad_move_y_up() {
  695. encoderPosition = -1;
  696. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  697. lcd_move_y();
  698. }
  699. static void reprapworld_keypad_move_home() {
  700. //enquecommand_P((PSTR("G28"))); // move all axis home
  701. // TODO gregor: move all axis home, i have currently only one axis on my prusa i3
  702. enquecommand_P((PSTR("G28 Y")));
  703. }
  704. #endif
  705. /** End of menus **/
  706. static void lcd_quick_feedback()
  707. {
  708. lcdDrawUpdate = 2;
  709. blocking_enc = millis() + 500;
  710. lcd_implementation_quick_feedback();
  711. }
  712. /** Menu action functions **/
  713. static void menu_action_back(menuFunc_t data)
  714. {
  715. currentMenu = data;
  716. encoderPosition = 0;
  717. }
  718. static void menu_action_submenu(menuFunc_t data)
  719. {
  720. currentMenu = data;
  721. encoderPosition = 0;
  722. }
  723. static void menu_action_gcode(const char* pgcode)
  724. {
  725. enquecommand_P(pgcode);
  726. }
  727. static void menu_action_function(menuFunc_t data)
  728. {
  729. (*data)();
  730. }
  731. static void menu_action_sdfile(const char* filename, char* longFilename)
  732. {
  733. char cmd[30];
  734. char* c;
  735. sprintf_P(cmd, PSTR("M23 %s"), filename);
  736. for(c = &cmd[4]; *c; c++)
  737. *c = tolower(*c);
  738. enquecommand(cmd);
  739. enquecommand_P(PSTR("M24"));
  740. lcd_return_to_status();
  741. }
  742. static void menu_action_sddirectory(const char* filename, char* longFilename)
  743. {
  744. card.chdir(filename);
  745. encoderPosition = 0;
  746. }
  747. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  748. {
  749. *ptr = !(*ptr);
  750. }
  751. #endif//ULTIPANEL
  752. /** LCD API **/
  753. void lcd_init()
  754. {
  755. lcd_implementation_init();
  756. #ifdef NEWPANEL
  757. pinMode(BTN_EN1,INPUT);
  758. pinMode(BTN_EN2,INPUT);
  759. pinMode(SDCARDDETECT,INPUT);
  760. WRITE(BTN_EN1,HIGH);
  761. WRITE(BTN_EN2,HIGH);
  762. #if BTN_ENC > 0
  763. pinMode(BTN_ENC,INPUT);
  764. WRITE(BTN_ENC,HIGH);
  765. #endif
  766. #ifdef REPRAPWORLD_KEYPAD
  767. pinMode(SHIFT_CLK,OUTPUT);
  768. pinMode(SHIFT_LD,OUTPUT);
  769. pinMode(SHIFT_OUT,INPUT);
  770. WRITE(SHIFT_OUT,HIGH);
  771. WRITE(SHIFT_LD,HIGH);
  772. #endif
  773. #else
  774. pinMode(SHIFT_CLK,OUTPUT);
  775. pinMode(SHIFT_LD,OUTPUT);
  776. pinMode(SHIFT_EN,OUTPUT);
  777. pinMode(SHIFT_OUT,INPUT);
  778. WRITE(SHIFT_OUT,HIGH);
  779. WRITE(SHIFT_LD,HIGH);
  780. WRITE(SHIFT_EN,LOW);
  781. #endif//!NEWPANEL
  782. #if (SDCARDDETECT > 0)
  783. WRITE(SDCARDDETECT, HIGH);
  784. lcd_oldcardstatus = IS_SD_INSERTED;
  785. #endif//(SDCARDDETECT > 0)
  786. lcd_buttons_update();
  787. #ifdef ULTIPANEL
  788. encoderDiff = 0;
  789. #endif
  790. }
  791. void lcd_update()
  792. {
  793. static unsigned long timeoutToStatus = 0;
  794. lcd_buttons_update();
  795. #ifdef LCD_HAS_SLOW_BUTTONS
  796. buttons |= lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  797. #endif
  798. #if (SDCARDDETECT > 0)
  799. if((IS_SD_INSERTED != lcd_oldcardstatus))
  800. {
  801. lcdDrawUpdate = 2;
  802. lcd_oldcardstatus = IS_SD_INSERTED;
  803. lcd_implementation_init(); // to maybe revive the lcd if static electricty killed it.
  804. if(lcd_oldcardstatus)
  805. {
  806. card.initsd();
  807. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  808. }
  809. else
  810. {
  811. card.release();
  812. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  813. }
  814. }
  815. #endif//CARDINSERTED
  816. if (lcd_next_update_millis < millis())
  817. {
  818. #ifdef ULTIPANEL
  819. #ifdef REPRAPWORLD_KEYPAD
  820. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  821. reprapworld_keypad_move_y_down();
  822. }
  823. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  824. reprapworld_keypad_move_y_up();
  825. }
  826. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  827. reprapworld_keypad_move_home();
  828. }
  829. #endif
  830. if (encoderDiff)
  831. {
  832. lcdDrawUpdate = 1;
  833. encoderPosition += encoderDiff;
  834. encoderDiff = 0;
  835. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  836. }
  837. if (LCD_CLICKED)
  838. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  839. #endif//ULTIPANEL
  840. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  841. blink++; // Variable for fan animation and alive dot
  842. u8g.firstPage();
  843. do
  844. {
  845. u8g.setFont(u8g_font_6x10_marlin);
  846. u8g.setPrintPos(125,0);
  847. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  848. u8g.drawPixel(127,63); // draw alive dot
  849. u8g.setColorIndex(1); // black on white
  850. (*currentMenu)();
  851. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  852. } while( u8g.nextPage() );
  853. #else
  854. (*currentMenu)();
  855. #endif
  856. #ifdef LCD_HAS_STATUS_INDICATORS
  857. lcd_implementation_update_indicators();
  858. #endif
  859. #ifdef ULTIPANEL
  860. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  861. {
  862. lcd_return_to_status();
  863. lcdDrawUpdate = 2;
  864. }
  865. #endif//ULTIPANEL
  866. if (lcdDrawUpdate == 2)
  867. lcd_implementation_clear();
  868. if (lcdDrawUpdate)
  869. lcdDrawUpdate--;
  870. lcd_next_update_millis = millis() + 100;
  871. }
  872. }
  873. void lcd_setstatus(const char* message)
  874. {
  875. if (lcd_status_message_level > 0)
  876. return;
  877. strncpy(lcd_status_message, message, LCD_WIDTH);
  878. lcdDrawUpdate = 2;
  879. }
  880. void lcd_setstatuspgm(const char* message)
  881. {
  882. if (lcd_status_message_level > 0)
  883. return;
  884. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  885. lcdDrawUpdate = 2;
  886. }
  887. void lcd_setalertstatuspgm(const char* message)
  888. {
  889. lcd_setstatuspgm(message);
  890. lcd_status_message_level = 1;
  891. #ifdef ULTIPANEL
  892. lcd_return_to_status();
  893. #endif//ULTIPANEL
  894. }
  895. void lcd_reset_alert_level()
  896. {
  897. lcd_status_message_level = 0;
  898. }
  899. #ifdef ULTIPANEL
  900. /* Warning: This function is called from interrupt context */
  901. void lcd_buttons_update()
  902. {
  903. #ifdef NEWPANEL
  904. uint8_t newbutton=0;
  905. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  906. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  907. #if BTN_ENC > 0
  908. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  909. newbutton |= EN_C;
  910. #endif
  911. #ifdef REPRAPWORLD_KEYPAD
  912. // for the reprapworld_keypad
  913. uint8_t newbutton_reprapworld_keypad=0;
  914. WRITE(SHIFT_LD,LOW);
  915. WRITE(SHIFT_LD,HIGH);
  916. for(int8_t i=0;i<8;i++) {
  917. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad>>1;
  918. if(READ(SHIFT_OUT))
  919. newbutton_reprapworld_keypad|=(1<<7);
  920. WRITE(SHIFT_CLK,HIGH);
  921. WRITE(SHIFT_CLK,LOW);
  922. }
  923. newbutton |= ((~newbutton_reprapworld_keypad) << REPRAPWORLD_BTN_OFFSET); //invert it, because a pressed switch produces a logical 0
  924. #endif
  925. buttons = newbutton;
  926. #else //read it from the shift register
  927. uint8_t newbutton=0;
  928. WRITE(SHIFT_LD,LOW);
  929. WRITE(SHIFT_LD,HIGH);
  930. unsigned char tmp_buttons=0;
  931. for(int8_t i=0;i<8;i++)
  932. {
  933. newbutton = newbutton>>1;
  934. if(READ(SHIFT_OUT))
  935. newbutton|=(1<<7);
  936. WRITE(SHIFT_CLK,HIGH);
  937. WRITE(SHIFT_CLK,LOW);
  938. }
  939. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  940. #endif//!NEWPANEL
  941. //manage encoder rotation
  942. uint8_t enc=0;
  943. if(buttons&EN_A)
  944. enc|=(1<<0);
  945. if(buttons&EN_B)
  946. enc|=(1<<1);
  947. if(enc != lastEncoderBits)
  948. {
  949. switch(enc)
  950. {
  951. case encrot0:
  952. if(lastEncoderBits==encrot3)
  953. encoderDiff++;
  954. else if(lastEncoderBits==encrot1)
  955. encoderDiff--;
  956. break;
  957. case encrot1:
  958. if(lastEncoderBits==encrot0)
  959. encoderDiff++;
  960. else if(lastEncoderBits==encrot2)
  961. encoderDiff--;
  962. break;
  963. case encrot2:
  964. if(lastEncoderBits==encrot1)
  965. encoderDiff++;
  966. else if(lastEncoderBits==encrot3)
  967. encoderDiff--;
  968. break;
  969. case encrot3:
  970. if(lastEncoderBits==encrot2)
  971. encoderDiff++;
  972. else if(lastEncoderBits==encrot0)
  973. encoderDiff--;
  974. break;
  975. }
  976. }
  977. lastEncoderBits = enc;
  978. }
  979. void lcd_buzz(long duration, uint16_t freq)
  980. {
  981. #ifdef LCD_USE_I2C_BUZZER
  982. lcd.buzz(duration,freq);
  983. #endif
  984. }
  985. bool lcd_clicked()
  986. {
  987. return LCD_CLICKED;
  988. }
  989. #endif//ULTIPANEL
  990. /********************************/
  991. /** Float conversion utilities **/
  992. /********************************/
  993. // convert float to string with +123.4 format
  994. char conv[8];
  995. char *ftostr3(const float &x)
  996. {
  997. return itostr3((int)x);
  998. }
  999. char *itostr2(const uint8_t &x)
  1000. {
  1001. //sprintf(conv,"%5.1f",x);
  1002. int xx=x;
  1003. conv[0]=(xx/10)%10+'0';
  1004. conv[1]=(xx)%10+'0';
  1005. conv[2]=0;
  1006. return conv;
  1007. }
  1008. // convert float to string with +123.4 format
  1009. char *ftostr31(const float &x)
  1010. {
  1011. int xx=x*10;
  1012. conv[0]=(xx>=0)?'+':'-';
  1013. xx=abs(xx);
  1014. conv[1]=(xx/1000)%10+'0';
  1015. conv[2]=(xx/100)%10+'0';
  1016. conv[3]=(xx/10)%10+'0';
  1017. conv[4]='.';
  1018. conv[5]=(xx)%10+'0';
  1019. conv[6]=0;
  1020. return conv;
  1021. }
  1022. // convert float to string with 123.4 format
  1023. char *ftostr31ns(const float &x)
  1024. {
  1025. int xx=x*10;
  1026. //conv[0]=(xx>=0)?'+':'-';
  1027. xx=abs(xx);
  1028. conv[0]=(xx/1000)%10+'0';
  1029. conv[1]=(xx/100)%10+'0';
  1030. conv[2]=(xx/10)%10+'0';
  1031. conv[3]='.';
  1032. conv[4]=(xx)%10+'0';
  1033. conv[5]=0;
  1034. return conv;
  1035. }
  1036. char *ftostr32(const float &x)
  1037. {
  1038. long xx=x*100;
  1039. if (xx >= 0)
  1040. conv[0]=(xx/10000)%10+'0';
  1041. else
  1042. conv[0]='-';
  1043. xx=abs(xx);
  1044. conv[1]=(xx/1000)%10+'0';
  1045. conv[2]=(xx/100)%10+'0';
  1046. conv[3]='.';
  1047. conv[4]=(xx/10)%10+'0';
  1048. conv[5]=(xx)%10+'0';
  1049. conv[6]=0;
  1050. return conv;
  1051. }
  1052. char *itostr31(const int &xx)
  1053. {
  1054. conv[0]=(xx>=0)?'+':'-';
  1055. conv[1]=(xx/1000)%10+'0';
  1056. conv[2]=(xx/100)%10+'0';
  1057. conv[3]=(xx/10)%10+'0';
  1058. conv[4]='.';
  1059. conv[5]=(xx)%10+'0';
  1060. conv[6]=0;
  1061. return conv;
  1062. }
  1063. char *itostr3(const int &xx)
  1064. {
  1065. if (xx >= 100)
  1066. conv[0]=(xx/100)%10+'0';
  1067. else
  1068. conv[0]=' ';
  1069. if (xx >= 10)
  1070. conv[1]=(xx/10)%10+'0';
  1071. else
  1072. conv[1]=' ';
  1073. conv[2]=(xx)%10+'0';
  1074. conv[3]=0;
  1075. return conv;
  1076. }
  1077. char *itostr3left(const int &xx)
  1078. {
  1079. if (xx >= 100)
  1080. {
  1081. conv[0]=(xx/100)%10+'0';
  1082. conv[1]=(xx/10)%10+'0';
  1083. conv[2]=(xx)%10+'0';
  1084. conv[3]=0;
  1085. }
  1086. else if (xx >= 10)
  1087. {
  1088. conv[0]=(xx/10)%10+'0';
  1089. conv[1]=(xx)%10+'0';
  1090. conv[2]=0;
  1091. }
  1092. else
  1093. {
  1094. conv[0]=(xx)%10+'0';
  1095. conv[1]=0;
  1096. }
  1097. return conv;
  1098. }
  1099. char *itostr4(const int &xx)
  1100. {
  1101. if (xx >= 1000)
  1102. conv[0]=(xx/1000)%10+'0';
  1103. else
  1104. conv[0]=' ';
  1105. if (xx >= 100)
  1106. conv[1]=(xx/100)%10+'0';
  1107. else
  1108. conv[1]=' ';
  1109. if (xx >= 10)
  1110. conv[2]=(xx/10)%10+'0';
  1111. else
  1112. conv[2]=' ';
  1113. conv[3]=(xx)%10+'0';
  1114. conv[4]=0;
  1115. return conv;
  1116. }
  1117. // convert float to string with 12345 format
  1118. char *ftostr5(const float &x)
  1119. {
  1120. long xx=abs(x);
  1121. if (xx >= 10000)
  1122. conv[0]=(xx/10000)%10+'0';
  1123. else
  1124. conv[0]=' ';
  1125. if (xx >= 1000)
  1126. conv[1]=(xx/1000)%10+'0';
  1127. else
  1128. conv[1]=' ';
  1129. if (xx >= 100)
  1130. conv[2]=(xx/100)%10+'0';
  1131. else
  1132. conv[2]=' ';
  1133. if (xx >= 10)
  1134. conv[3]=(xx/10)%10+'0';
  1135. else
  1136. conv[3]=' ';
  1137. conv[4]=(xx)%10+'0';
  1138. conv[5]=0;
  1139. return conv;
  1140. }
  1141. // convert float to string with +1234.5 format
  1142. char *ftostr51(const float &x)
  1143. {
  1144. long xx=x*10;
  1145. conv[0]=(xx>=0)?'+':'-';
  1146. xx=abs(xx);
  1147. conv[1]=(xx/10000)%10+'0';
  1148. conv[2]=(xx/1000)%10+'0';
  1149. conv[3]=(xx/100)%10+'0';
  1150. conv[4]=(xx/10)%10+'0';
  1151. conv[5]='.';
  1152. conv[6]=(xx)%10+'0';
  1153. conv[7]=0;
  1154. return conv;
  1155. }
  1156. // convert float to string with +123.45 format
  1157. char *ftostr52(const float &x)
  1158. {
  1159. long xx=x*100;
  1160. conv[0]=(xx>=0)?'+':'-';
  1161. xx=abs(xx);
  1162. conv[1]=(xx/10000)%10+'0';
  1163. conv[2]=(xx/1000)%10+'0';
  1164. conv[3]=(xx/100)%10+'0';
  1165. conv[4]='.';
  1166. conv[5]=(xx/10)%10+'0';
  1167. conv[6]=(xx)%10+'0';
  1168. conv[7]=0;
  1169. return conv;
  1170. }
  1171. // Callback for after editing PID i value
  1172. // grab the pid i value out of the temp variable; scale it; then update the PID driver
  1173. void copy_and_scalePID_i()
  1174. {
  1175. #ifdef PIDTEMP
  1176. Ki = scalePID_i(raw_Ki);
  1177. updatePID();
  1178. #endif
  1179. }
  1180. // Callback for after editing PID d value
  1181. // grab the pid d value out of the temp variable; scale it; then update the PID driver
  1182. void copy_and_scalePID_d()
  1183. {
  1184. #ifdef PIDTEMP
  1185. Kd = scalePID_d(raw_Kd);
  1186. updatePID();
  1187. #endif
  1188. }
  1189. #endif //ULTRA_LCD