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

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