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

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