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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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(SDCARDDETECT,INPUT);
  701. WRITE(BTN_EN1,HIGH);
  702. WRITE(BTN_EN2,HIGH);
  703. #if defined(BTN_ENC) && BTN_ENC > -1
  704. pinMode(BTN_ENC,INPUT);
  705. WRITE(BTN_ENC,HIGH);
  706. #endif
  707. #else
  708. pinMode(SHIFT_CLK,OUTPUT);
  709. pinMode(SHIFT_LD,OUTPUT);
  710. pinMode(SHIFT_EN,OUTPUT);
  711. pinMode(SHIFT_OUT,INPUT);
  712. WRITE(SHIFT_OUT,HIGH);
  713. WRITE(SHIFT_LD,HIGH);
  714. WRITE(SHIFT_EN,LOW);
  715. #endif//!NEWPANEL
  716. #if (SDCARDDETECT > -1)
  717. WRITE(SDCARDDETECT, HIGH);
  718. lcd_oldcardstatus = IS_SD_INSERTED;
  719. #endif//(SDCARDDETECT > -1)
  720. lcd_buttons_update();
  721. #ifdef ULTIPANEL
  722. encoderDiff = 0;
  723. #endif
  724. }
  725. void lcd_update()
  726. {
  727. static unsigned long timeoutToStatus = 0;
  728. lcd_buttons_update();
  729. #ifdef LCD_HAS_SLOW_BUTTONS
  730. buttons |= lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  731. #endif
  732. #if (SDCARDDETECT > -1)
  733. if((IS_SD_INSERTED != lcd_oldcardstatus))
  734. {
  735. lcdDrawUpdate = 2;
  736. lcd_oldcardstatus = IS_SD_INSERTED;
  737. lcd_implementation_init(); // to maybe revive the lcd if static electricty killed it.
  738. if(lcd_oldcardstatus)
  739. {
  740. card.initsd();
  741. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  742. }
  743. else
  744. {
  745. card.release();
  746. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  747. }
  748. }
  749. #endif//CARDINSERTED
  750. if (lcd_next_update_millis < millis())
  751. {
  752. #ifdef ULTIPANEL
  753. if (encoderDiff)
  754. {
  755. lcdDrawUpdate = 1;
  756. encoderPosition += encoderDiff;
  757. encoderDiff = 0;
  758. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  759. }
  760. if (LCD_CLICKED)
  761. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  762. #endif//ULTIPANEL
  763. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  764. blink++; // Variable for fan animation and alive dot
  765. u8g.firstPage();
  766. do
  767. {
  768. u8g.setFont(u8g_font_6x10_marlin);
  769. u8g.setPrintPos(125,0);
  770. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  771. u8g.drawPixel(127,63); // draw alive dot
  772. u8g.setColorIndex(1); // black on white
  773. (*currentMenu)();
  774. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  775. } while( u8g.nextPage() );
  776. #else
  777. (*currentMenu)();
  778. #endif
  779. #ifdef LCD_HAS_STATUS_INDICATORS
  780. lcd_implementation_update_indicators();
  781. #endif
  782. #ifdef ULTIPANEL
  783. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  784. {
  785. lcd_return_to_status();
  786. lcdDrawUpdate = 2;
  787. }
  788. #endif//ULTIPANEL
  789. if (lcdDrawUpdate == 2)
  790. lcd_implementation_clear();
  791. if (lcdDrawUpdate)
  792. lcdDrawUpdate--;
  793. lcd_next_update_millis = millis() + 100;
  794. }
  795. }
  796. void lcd_setstatus(const char* message)
  797. {
  798. if (lcd_status_message_level > 0)
  799. return;
  800. strncpy(lcd_status_message, message, LCD_WIDTH);
  801. lcdDrawUpdate = 2;
  802. }
  803. void lcd_setstatuspgm(const char* message)
  804. {
  805. if (lcd_status_message_level > 0)
  806. return;
  807. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  808. lcdDrawUpdate = 2;
  809. }
  810. void lcd_setalertstatuspgm(const char* message)
  811. {
  812. lcd_setstatuspgm(message);
  813. lcd_status_message_level = 1;
  814. #ifdef ULTIPANEL
  815. lcd_return_to_status();
  816. #endif//ULTIPANEL
  817. }
  818. void lcd_reset_alert_level()
  819. {
  820. lcd_status_message_level = 0;
  821. }
  822. #ifdef ULTIPANEL
  823. /* Warning: This function is called from interrupt context */
  824. void lcd_buttons_update()
  825. {
  826. #ifdef NEWPANEL
  827. uint8_t newbutton=0;
  828. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  829. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  830. #if defined(BTN_ENC) && BTN_ENC > -1
  831. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  832. newbutton |= EN_C;
  833. #endif
  834. buttons = newbutton;
  835. #else //read it from the shift register
  836. uint8_t newbutton=0;
  837. WRITE(SHIFT_LD,LOW);
  838. WRITE(SHIFT_LD,HIGH);
  839. unsigned char tmp_buttons=0;
  840. for(int8_t i=0;i<8;i++)
  841. {
  842. newbutton = newbutton>>1;
  843. if(READ(SHIFT_OUT))
  844. newbutton|=(1<<7);
  845. WRITE(SHIFT_CLK,HIGH);
  846. WRITE(SHIFT_CLK,LOW);
  847. }
  848. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  849. #endif//!NEWPANEL
  850. //manage encoder rotation
  851. uint8_t enc=0;
  852. if(buttons&EN_A)
  853. enc|=(1<<0);
  854. if(buttons&EN_B)
  855. enc|=(1<<1);
  856. if(enc != lastEncoderBits)
  857. {
  858. switch(enc)
  859. {
  860. case encrot0:
  861. if(lastEncoderBits==encrot3)
  862. encoderDiff++;
  863. else if(lastEncoderBits==encrot1)
  864. encoderDiff--;
  865. break;
  866. case encrot1:
  867. if(lastEncoderBits==encrot0)
  868. encoderDiff++;
  869. else if(lastEncoderBits==encrot2)
  870. encoderDiff--;
  871. break;
  872. case encrot2:
  873. if(lastEncoderBits==encrot1)
  874. encoderDiff++;
  875. else if(lastEncoderBits==encrot3)
  876. encoderDiff--;
  877. break;
  878. case encrot3:
  879. if(lastEncoderBits==encrot2)
  880. encoderDiff++;
  881. else if(lastEncoderBits==encrot0)
  882. encoderDiff--;
  883. break;
  884. }
  885. }
  886. lastEncoderBits = enc;
  887. }
  888. bool lcd_clicked()
  889. {
  890. return LCD_CLICKED;
  891. }
  892. #endif//ULTIPANEL
  893. /********************************/
  894. /** Float conversion utilities **/
  895. /********************************/
  896. // convert float to string with +123.4 format
  897. char conv[8];
  898. char *ftostr3(const float &x)
  899. {
  900. return itostr3((int)x);
  901. }
  902. char *itostr2(const uint8_t &x)
  903. {
  904. //sprintf(conv,"%5.1f",x);
  905. int xx=x;
  906. conv[0]=(xx/10)%10+'0';
  907. conv[1]=(xx)%10+'0';
  908. conv[2]=0;
  909. return conv;
  910. }
  911. // convert float to string with +123.4 format
  912. char *ftostr31(const float &x)
  913. {
  914. int xx=x*10;
  915. conv[0]=(xx>=0)?'+':'-';
  916. xx=abs(xx);
  917. conv[1]=(xx/1000)%10+'0';
  918. conv[2]=(xx/100)%10+'0';
  919. conv[3]=(xx/10)%10+'0';
  920. conv[4]='.';
  921. conv[5]=(xx)%10+'0';
  922. conv[6]=0;
  923. return conv;
  924. }
  925. // convert float to string with 123.4 format
  926. char *ftostr31ns(const float &x)
  927. {
  928. int xx=x*10;
  929. //conv[0]=(xx>=0)?'+':'-';
  930. xx=abs(xx);
  931. conv[0]=(xx/1000)%10+'0';
  932. conv[1]=(xx/100)%10+'0';
  933. conv[2]=(xx/10)%10+'0';
  934. conv[3]='.';
  935. conv[4]=(xx)%10+'0';
  936. conv[5]=0;
  937. return conv;
  938. }
  939. char *ftostr32(const float &x)
  940. {
  941. long xx=x*100;
  942. if (xx >= 0)
  943. conv[0]=(xx/10000)%10+'0';
  944. else
  945. conv[0]='-';
  946. xx=abs(xx);
  947. conv[1]=(xx/1000)%10+'0';
  948. conv[2]=(xx/100)%10+'0';
  949. conv[3]='.';
  950. conv[4]=(xx/10)%10+'0';
  951. conv[5]=(xx)%10+'0';
  952. conv[6]=0;
  953. return conv;
  954. }
  955. char *itostr31(const int &xx)
  956. {
  957. conv[0]=(xx>=0)?'+':'-';
  958. conv[1]=(xx/1000)%10+'0';
  959. conv[2]=(xx/100)%10+'0';
  960. conv[3]=(xx/10)%10+'0';
  961. conv[4]='.';
  962. conv[5]=(xx)%10+'0';
  963. conv[6]=0;
  964. return conv;
  965. }
  966. char *itostr3(const int &xx)
  967. {
  968. if (xx >= 100)
  969. conv[0]=(xx/100)%10+'0';
  970. else
  971. conv[0]=' ';
  972. if (xx >= 10)
  973. conv[1]=(xx/10)%10+'0';
  974. else
  975. conv[1]=' ';
  976. conv[2]=(xx)%10+'0';
  977. conv[3]=0;
  978. return conv;
  979. }
  980. char *itostr3left(const int &xx)
  981. {
  982. if (xx >= 100)
  983. {
  984. conv[0]=(xx/100)%10+'0';
  985. conv[1]=(xx/10)%10+'0';
  986. conv[2]=(xx)%10+'0';
  987. conv[3]=0;
  988. }
  989. else if (xx >= 10)
  990. {
  991. conv[0]=(xx/10)%10+'0';
  992. conv[1]=(xx)%10+'0';
  993. conv[2]=0;
  994. }
  995. else
  996. {
  997. conv[0]=(xx)%10+'0';
  998. conv[1]=0;
  999. }
  1000. return conv;
  1001. }
  1002. char *itostr4(const int &xx)
  1003. {
  1004. if (xx >= 1000)
  1005. conv[0]=(xx/1000)%10+'0';
  1006. else
  1007. conv[0]=' ';
  1008. if (xx >= 100)
  1009. conv[1]=(xx/100)%10+'0';
  1010. else
  1011. conv[1]=' ';
  1012. if (xx >= 10)
  1013. conv[2]=(xx/10)%10+'0';
  1014. else
  1015. conv[2]=' ';
  1016. conv[3]=(xx)%10+'0';
  1017. conv[4]=0;
  1018. return conv;
  1019. }
  1020. // convert float to string with 12345 format
  1021. char *ftostr5(const float &x)
  1022. {
  1023. long xx=abs(x);
  1024. if (xx >= 10000)
  1025. conv[0]=(xx/10000)%10+'0';
  1026. else
  1027. conv[0]=' ';
  1028. if (xx >= 1000)
  1029. conv[1]=(xx/1000)%10+'0';
  1030. else
  1031. conv[1]=' ';
  1032. if (xx >= 100)
  1033. conv[2]=(xx/100)%10+'0';
  1034. else
  1035. conv[2]=' ';
  1036. if (xx >= 10)
  1037. conv[3]=(xx/10)%10+'0';
  1038. else
  1039. conv[3]=' ';
  1040. conv[4]=(xx)%10+'0';
  1041. conv[5]=0;
  1042. return conv;
  1043. }
  1044. // convert float to string with +1234.5 format
  1045. char *ftostr51(const float &x)
  1046. {
  1047. long xx=x*10;
  1048. conv[0]=(xx>=0)?'+':'-';
  1049. xx=abs(xx);
  1050. conv[1]=(xx/10000)%10+'0';
  1051. conv[2]=(xx/1000)%10+'0';
  1052. conv[3]=(xx/100)%10+'0';
  1053. conv[4]=(xx/10)%10+'0';
  1054. conv[5]='.';
  1055. conv[6]=(xx)%10+'0';
  1056. conv[7]=0;
  1057. return conv;
  1058. }
  1059. // convert float to string with +123.45 format
  1060. char *ftostr52(const float &x)
  1061. {
  1062. long xx=x*100;
  1063. conv[0]=(xx>=0)?'+':'-';
  1064. xx=abs(xx);
  1065. conv[1]=(xx/10000)%10+'0';
  1066. conv[2]=(xx/1000)%10+'0';
  1067. conv[3]=(xx/100)%10+'0';
  1068. conv[4]='.';
  1069. conv[5]=(xx/10)%10+'0';
  1070. conv[6]=(xx)%10+'0';
  1071. conv[7]=0;
  1072. return conv;
  1073. }
  1074. // Callback for after editing PID i value
  1075. // grab the pid i value out of the temp variable; scale it; then update the PID driver
  1076. void copy_and_scalePID_i()
  1077. {
  1078. Ki = scalePID_i(raw_Ki);
  1079. updatePID();
  1080. }
  1081. // Callback for after editing PID d value
  1082. // grab the pid d value out of the temp variable; scale it; then update the PID driver
  1083. void copy_and_scalePID_d()
  1084. {
  1085. Kd = scalePID_d(raw_Kd);
  1086. updatePID();
  1087. }
  1088. #endif //ULTRA_LCD