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

ultralcd.cpp 37KB

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