My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 36KB

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