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

ultralcd.cpp 37KB

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