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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  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. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  11. /* Configuration settings */
  12. int plaPreheatHotendTemp;
  13. int plaPreheatHPBTemp;
  14. int plaPreheatFanSpeed;
  15. int absPreheatHotendTemp;
  16. int absPreheatHPBTemp;
  17. int absPreheatFanSpeed;
  18. #ifdef FILAMENT_LCD_DISPLAY
  19. unsigned long message_millis = 0;
  20. #endif
  21. #ifdef ULTIPANEL
  22. static float manual_feedrate[] = MANUAL_FEEDRATE;
  23. #endif // ULTIPANEL
  24. /* !Configuration settings */
  25. //Function pointer to menu functions.
  26. typedef void (*menuFunc_t)();
  27. uint8_t lcd_status_message_level;
  28. char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
  29. #ifdef DOGLCD
  30. #include "dogm_lcd_implementation.h"
  31. #else
  32. #include "ultralcd_implementation_hitachi_HD44780.h"
  33. #endif
  34. /** forward declarations **/
  35. void copy_and_scalePID_i();
  36. void copy_and_scalePID_d();
  37. /* Different menus */
  38. static void lcd_status_screen();
  39. #ifdef ULTIPANEL
  40. extern bool powersupply;
  41. static void lcd_main_menu();
  42. static void lcd_tune_menu();
  43. static void lcd_prepare_menu();
  44. static void lcd_move_menu();
  45. static void lcd_control_menu();
  46. static void lcd_control_temperature_menu();
  47. static void lcd_control_temperature_preheat_pla_settings_menu();
  48. static void lcd_control_temperature_preheat_abs_settings_menu();
  49. static void lcd_control_motion_menu();
  50. #ifdef DOGLCD
  51. static void lcd_set_contrast();
  52. #endif
  53. static void lcd_control_retract_menu();
  54. static void lcd_sdcard_menu();
  55. #ifdef DELTA_CALIBRATION_MENU
  56. static void lcd_delta_calibrate_menu();
  57. #endif // DELTA_CALIBRATION_MENU
  58. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  59. /* Different types of actions that can be used in menu items. */
  60. static void menu_action_back(menuFunc_t data);
  61. static void menu_action_submenu(menuFunc_t data);
  62. static void menu_action_gcode(const char* pgcode);
  63. static void menu_action_function(menuFunc_t data);
  64. static void menu_action_sdfile(const char* filename, char* longFilename);
  65. static void menu_action_sddirectory(const char* filename, char* longFilename);
  66. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  67. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  68. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  69. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  70. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  71. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  72. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  73. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  74. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  75. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  76. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  77. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  78. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  79. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  80. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  81. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  82. #define ENCODER_FEEDRATE_DEADZONE 10
  83. #if !defined(LCD_I2C_VIKI)
  84. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  85. #define ENCODER_STEPS_PER_MENU_ITEM 5
  86. #endif
  87. #ifndef ENCODER_PULSES_PER_STEP
  88. #define ENCODER_PULSES_PER_STEP 1
  89. #endif
  90. #else
  91. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  92. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  93. #endif
  94. #ifndef ENCODER_PULSES_PER_STEP
  95. #define ENCODER_PULSES_PER_STEP 1
  96. #endif
  97. #endif
  98. /* Helper macros for menus */
  99. #define START_MENU() do { \
  100. if (encoderPosition > 0x8000) encoderPosition = 0; \
  101. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  102. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  103. bool wasClicked = LCD_CLICKED;\
  104. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  105. _menuItemNr = 0;
  106. #define MENU_ITEM(type, label, args...) do { \
  107. if (_menuItemNr == _lineNr) { \
  108. if (lcdDrawUpdate) { \
  109. const char* _label_pstr = PSTR(label); \
  110. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  111. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  112. }else{\
  113. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  114. }\
  115. }\
  116. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  117. lcd_quick_feedback(); \
  118. menu_action_ ## type ( args ); \
  119. return;\
  120. }\
  121. }\
  122. _menuItemNr++;\
  123. } while(0)
  124. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  125. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, PSTR(label) , ## args )
  126. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, PSTR(label) , ## args )
  127. #define END_MENU() \
  128. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  129. 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; } \
  130. } } while(0)
  131. /** Used variables to keep track of the menu */
  132. #ifndef REPRAPWORLD_KEYPAD
  133. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  134. #else
  135. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  136. #endif
  137. #ifdef LCD_HAS_SLOW_BUTTONS
  138. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  139. #endif
  140. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  141. uint32_t blocking_enc;
  142. uint8_t lastEncoderBits;
  143. uint32_t encoderPosition;
  144. #if (SDCARDDETECT > 0)
  145. bool lcd_oldcardstatus;
  146. #endif
  147. #endif //ULTIPANEL
  148. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  149. uint32_t lcd_next_update_millis;
  150. uint8_t lcd_status_update_delay;
  151. bool ignore_click = false;
  152. bool wait_for_unclick;
  153. 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 at least 1 full redraw (first redraw is partial) */
  154. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  155. menuFunc_t prevMenu = NULL;
  156. uint16_t prevEncoderPosition;
  157. //Variables used when editing values.
  158. const char* editLabel;
  159. void* editValue;
  160. int32_t minEditValue, maxEditValue;
  161. menuFunc_t callbackFunc;
  162. // place-holders for Ki and Kd edits
  163. float raw_Ki, raw_Kd;
  164. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
  165. if (currentMenu != menu) {
  166. currentMenu = menu;
  167. encoderPosition = encoder;
  168. if (feedback) lcd_quick_feedback();
  169. // For LCD_PROGRESS_BAR re-initialize the custom characters
  170. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  171. lcd_set_custom_characters(menu == lcd_status_screen);
  172. #endif
  173. }
  174. }
  175. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  176. static void lcd_status_screen()
  177. {
  178. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  179. uint16_t mil = millis();
  180. #ifndef PROGRESS_MSG_ONCE
  181. if (mil > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
  182. progressBarTick = mil;
  183. }
  184. #endif
  185. #if PROGRESS_MSG_EXPIRE > 0
  186. // keep the message alive if paused, count down otherwise
  187. if (messageTick > 0) {
  188. if (card.isFileOpen()) {
  189. if (IS_SD_PRINTING) {
  190. if ((mil-messageTick) >= PROGRESS_MSG_EXPIRE) {
  191. lcd_status_message[0] = '\0';
  192. messageTick = 0;
  193. }
  194. }
  195. else {
  196. messageTick += LCD_UPDATE_INTERVAL;
  197. }
  198. }
  199. else {
  200. messageTick = 0;
  201. }
  202. }
  203. #endif
  204. #endif //LCD_PROGRESS_BAR
  205. if (lcd_status_update_delay)
  206. lcd_status_update_delay--;
  207. else
  208. lcdDrawUpdate = 1;
  209. if (lcdDrawUpdate)
  210. {
  211. lcd_implementation_status_screen();
  212. 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 */
  213. }
  214. #ifdef ULTIPANEL
  215. bool current_click = LCD_CLICKED;
  216. if (ignore_click) {
  217. if (wait_for_unclick) {
  218. if (!current_click) {
  219. ignore_click = wait_for_unclick = false;
  220. }
  221. else {
  222. current_click = false;
  223. }
  224. }
  225. else if (current_click) {
  226. lcd_quick_feedback();
  227. wait_for_unclick = true;
  228. current_click = false;
  229. }
  230. }
  231. if (current_click)
  232. {
  233. lcd_goto_menu(lcd_main_menu);
  234. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  235. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  236. currentMenu == lcd_status_screen
  237. #endif
  238. );
  239. #ifdef FILAMENT_LCD_DISPLAY
  240. message_millis = millis(); // get status message to show up for a while
  241. #endif
  242. }
  243. #ifdef ULTIPANEL_FEEDMULTIPLY
  244. // Dead zone at 100% feedrate
  245. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  246. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  247. {
  248. encoderPosition = 0;
  249. feedmultiply = 100;
  250. }
  251. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  252. {
  253. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  254. encoderPosition = 0;
  255. }
  256. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  257. {
  258. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  259. encoderPosition = 0;
  260. }
  261. else if (feedmultiply != 100)
  262. {
  263. feedmultiply += int(encoderPosition);
  264. encoderPosition = 0;
  265. }
  266. #endif //ULTIPANEL_FEEDMULTIPLY
  267. if (feedmultiply < 10)
  268. feedmultiply = 10;
  269. else if (feedmultiply > 999)
  270. feedmultiply = 999;
  271. #endif //ULTIPANEL
  272. }
  273. #ifdef ULTIPANEL
  274. static void lcd_return_to_status() { lcd_goto_menu(lcd_status_screen, 0, false); }
  275. static void lcd_sdcard_pause() { card.pauseSDPrint(); }
  276. static void lcd_sdcard_resume() { card.startFileprint(); }
  277. static void lcd_sdcard_stop()
  278. {
  279. card.sdprinting = false;
  280. card.closefile();
  281. quickStop();
  282. if(SD_FINISHED_STEPPERRELEASE)
  283. {
  284. enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
  285. }
  286. autotempShutdown();
  287. cancel_heatup = true;
  288. lcd_setstatus(MSG_PRINT_ABORTED);
  289. }
  290. /* Menu implementation */
  291. static void lcd_main_menu()
  292. {
  293. START_MENU();
  294. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  295. if (movesplanned() || IS_SD_PRINTING)
  296. {
  297. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  298. }else{
  299. MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
  300. #ifdef DELTA_CALIBRATION_MENU
  301. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, lcd_delta_calibrate_menu);
  302. #endif // DELTA_CALIBRATION_MENU
  303. }
  304. MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
  305. #ifdef SDSUPPORT
  306. if (card.cardOK)
  307. {
  308. if (card.isFileOpen())
  309. {
  310. if (card.sdprinting)
  311. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  312. else
  313. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  314. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  315. }else{
  316. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  317. #if SDCARDDETECT < 1
  318. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  319. #endif
  320. }
  321. }else{
  322. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  323. #if SDCARDDETECT < 1
  324. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  325. #endif
  326. }
  327. #endif
  328. END_MENU();
  329. }
  330. #ifdef SDSUPPORT
  331. static void lcd_autostart_sd()
  332. {
  333. card.lastnr=0;
  334. card.setroot();
  335. card.checkautostart(true);
  336. }
  337. #endif
  338. void lcd_set_home_offsets()
  339. {
  340. for(int8_t i=0; i < NUM_AXIS; i++) {
  341. if (i != E_AXIS) {
  342. add_homing[i] -= current_position[i];
  343. current_position[i] = 0.0;
  344. }
  345. }
  346. plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
  347. // Audio feedback
  348. enquecommand_P(PSTR("M300 S659 P200"));
  349. enquecommand_P(PSTR("M300 S698 P200"));
  350. lcd_return_to_status();
  351. }
  352. #ifdef BABYSTEPPING
  353. static void _lcd_babystep(int axis, const char *msg) {
  354. if (encoderPosition != 0) {
  355. babystepsTodo[axis] += (int)encoderPosition;
  356. encoderPosition = 0;
  357. lcdDrawUpdate = 1;
  358. }
  359. if (lcdDrawUpdate) lcd_implementation_drawedit(msg, "");
  360. if (LCD_CLICKED) lcd_goto_menu(lcd_tune_menu);
  361. }
  362. static void lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEPPING_X)); }
  363. static void lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEPPING_Y)); }
  364. static void lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEPPING_Z)); }
  365. #endif //BABYSTEPPING
  366. static void lcd_tune_menu()
  367. {
  368. START_MENU();
  369. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  370. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);
  371. #if TEMP_SENSOR_0 != 0
  372. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  373. #endif
  374. #if TEMP_SENSOR_1 != 0
  375. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  376. #endif
  377. #if TEMP_SENSOR_2 != 0
  378. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  379. #endif
  380. #if TEMP_SENSOR_BED != 0
  381. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  382. #endif
  383. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  384. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);
  385. MENU_ITEM_EDIT(int3, MSG_FLOW0, &extruder_multiply[0], 10, 999);
  386. #if TEMP_SENSOR_1 != 0
  387. MENU_ITEM_EDIT(int3, MSG_FLOW1, &extruder_multiply[1], 10, 999);
  388. #endif
  389. #if TEMP_SENSOR_2 != 0
  390. MENU_ITEM_EDIT(int3, MSG_FLOW2, &extruder_multiply[2], 10, 999);
  391. #endif
  392. #ifdef BABYSTEPPING
  393. #ifdef BABYSTEP_XY
  394. MENU_ITEM(submenu, MSG_BABYSTEP_X, lcd_babystep_x);
  395. MENU_ITEM(submenu, MSG_BABYSTEP_Y, lcd_babystep_y);
  396. #endif //BABYSTEP_XY
  397. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  398. #endif
  399. #ifdef FILAMENTCHANGEENABLE
  400. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));
  401. #endif
  402. END_MENU();
  403. }
  404. void lcd_preheat_pla0()
  405. {
  406. setTargetHotend0(plaPreheatHotendTemp);
  407. setTargetBed(plaPreheatHPBTemp);
  408. fanSpeed = plaPreheatFanSpeed;
  409. lcd_return_to_status();
  410. setWatch(); // heater sanity check timer
  411. }
  412. void lcd_preheat_abs0()
  413. {
  414. setTargetHotend0(absPreheatHotendTemp);
  415. setTargetBed(absPreheatHPBTemp);
  416. fanSpeed = absPreheatFanSpeed;
  417. lcd_return_to_status();
  418. setWatch(); // heater sanity check timer
  419. }
  420. #if TEMP_SENSOR_1 != 0 //2nd extruder preheat
  421. void lcd_preheat_pla1()
  422. {
  423. setTargetHotend1(plaPreheatHotendTemp);
  424. setTargetBed(plaPreheatHPBTemp);
  425. fanSpeed = plaPreheatFanSpeed;
  426. lcd_return_to_status();
  427. setWatch(); // heater sanity check timer
  428. }
  429. void lcd_preheat_abs1()
  430. {
  431. setTargetHotend1(absPreheatHotendTemp);
  432. setTargetBed(absPreheatHPBTemp);
  433. fanSpeed = absPreheatFanSpeed;
  434. lcd_return_to_status();
  435. setWatch(); // heater sanity check timer
  436. }
  437. #endif //2nd extruder preheat
  438. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  439. void lcd_preheat_pla2()
  440. {
  441. setTargetHotend2(plaPreheatHotendTemp);
  442. setTargetBed(plaPreheatHPBTemp);
  443. fanSpeed = plaPreheatFanSpeed;
  444. lcd_return_to_status();
  445. setWatch(); // heater sanity check timer
  446. }
  447. void lcd_preheat_abs2()
  448. {
  449. setTargetHotend2(absPreheatHotendTemp);
  450. setTargetBed(absPreheatHPBTemp);
  451. fanSpeed = absPreheatFanSpeed;
  452. lcd_return_to_status();
  453. setWatch(); // heater sanity check timer
  454. }
  455. #endif //3 extruder preheat
  456. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 //more than one extruder present
  457. void lcd_preheat_pla012()
  458. {
  459. setTargetHotend0(plaPreheatHotendTemp);
  460. setTargetHotend1(plaPreheatHotendTemp);
  461. setTargetHotend2(plaPreheatHotendTemp);
  462. setTargetBed(plaPreheatHPBTemp);
  463. fanSpeed = plaPreheatFanSpeed;
  464. lcd_return_to_status();
  465. setWatch(); // heater sanity check timer
  466. }
  467. void lcd_preheat_abs012()
  468. {
  469. setTargetHotend0(absPreheatHotendTemp);
  470. setTargetHotend1(absPreheatHotendTemp);
  471. setTargetHotend2(absPreheatHotendTemp);
  472. setTargetBed(absPreheatHPBTemp);
  473. fanSpeed = absPreheatFanSpeed;
  474. lcd_return_to_status();
  475. setWatch(); // heater sanity check timer
  476. }
  477. #endif //more than one extruder present
  478. void lcd_preheat_pla_bedonly()
  479. {
  480. setTargetBed(plaPreheatHPBTemp);
  481. fanSpeed = plaPreheatFanSpeed;
  482. lcd_return_to_status();
  483. setWatch(); // heater sanity check timer
  484. }
  485. void lcd_preheat_abs_bedonly()
  486. {
  487. setTargetBed(absPreheatHPBTemp);
  488. fanSpeed = absPreheatFanSpeed;
  489. lcd_return_to_status();
  490. setWatch(); // heater sanity check timer
  491. }
  492. static void lcd_preheat_pla_menu()
  493. {
  494. START_MENU();
  495. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  496. MENU_ITEM(function, MSG_PREHEAT_PLA0, lcd_preheat_pla0);
  497. #if TEMP_SENSOR_1 != 0 //2 extruder preheat
  498. MENU_ITEM(function, MSG_PREHEAT_PLA1, lcd_preheat_pla1);
  499. #endif //2 extruder preheat
  500. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  501. MENU_ITEM(function, MSG_PREHEAT_PLA2, lcd_preheat_pla2);
  502. #endif //3 extruder preheat
  503. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 //all extruder preheat
  504. MENU_ITEM(function, MSG_PREHEAT_PLA012, lcd_preheat_pla012);
  505. #endif //2 extruder preheat
  506. #if TEMP_SENSOR_BED != 0
  507. MENU_ITEM(function, MSG_PREHEAT_PLA_BEDONLY, lcd_preheat_pla_bedonly);
  508. #endif
  509. END_MENU();
  510. }
  511. static void lcd_preheat_abs_menu()
  512. {
  513. START_MENU();
  514. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  515. MENU_ITEM(function, MSG_PREHEAT_ABS0, lcd_preheat_abs0);
  516. #if TEMP_SENSOR_1 != 0 //2 extruder preheat
  517. MENU_ITEM(function, MSG_PREHEAT_ABS1, lcd_preheat_abs1);
  518. #endif //2 extruder preheat
  519. #if TEMP_SENSOR_2 != 0 //3 extruder preheat
  520. MENU_ITEM(function, MSG_PREHEAT_ABS2, lcd_preheat_abs2);
  521. #endif //3 extruder preheat
  522. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 //all extruder preheat
  523. MENU_ITEM(function, MSG_PREHEAT_ABS012, lcd_preheat_abs012);
  524. #endif //2 extruder preheat
  525. #if TEMP_SENSOR_BED != 0
  526. MENU_ITEM(function, MSG_PREHEAT_ABS_BEDONLY, lcd_preheat_abs_bedonly);
  527. #endif
  528. END_MENU();
  529. }
  530. void lcd_cooldown()
  531. {
  532. setTargetHotend0(0);
  533. setTargetHotend1(0);
  534. setTargetHotend2(0);
  535. setTargetBed(0);
  536. fanSpeed = 0;
  537. lcd_return_to_status();
  538. }
  539. static void lcd_prepare_menu()
  540. {
  541. START_MENU();
  542. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  543. #ifdef SDSUPPORT
  544. #ifdef MENU_ADDAUTOSTART
  545. MENU_ITEM(function, MSG_AUTOSTART, lcd_autostart_sd);
  546. #endif
  547. #endif
  548. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  549. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  550. MENU_ITEM(function, MSG_SET_HOME_OFFSETS, lcd_set_home_offsets);
  551. //MENU_ITEM(gcode, MSG_SET_ORIGIN, PSTR("G92 X0 Y0 Z0"));
  552. #if TEMP_SENSOR_0 != 0
  553. #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_BED != 0
  554. MENU_ITEM(submenu, MSG_PREHEAT_PLA, lcd_preheat_pla_menu);
  555. MENU_ITEM(submenu, MSG_PREHEAT_ABS, lcd_preheat_abs_menu);
  556. #else
  557. MENU_ITEM(function, MSG_PREHEAT_PLA, lcd_preheat_pla0);
  558. MENU_ITEM(function, MSG_PREHEAT_ABS, lcd_preheat_abs0);
  559. #endif
  560. #endif
  561. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  562. #if PS_ON_PIN > -1
  563. if (powersupply)
  564. {
  565. MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81"));
  566. }else{
  567. MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));
  568. }
  569. #endif
  570. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
  571. END_MENU();
  572. }
  573. #ifdef DELTA_CALIBRATION_MENU
  574. static void lcd_delta_calibrate_menu()
  575. {
  576. START_MENU();
  577. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  578. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  579. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_X, PSTR("G0 F8000 X-77.94 Y-45 Z0"));
  580. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Y, PSTR("G0 F8000 X77.94 Y-45 Z0"));
  581. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_Z, PSTR("G0 F8000 X0 Y90 Z0"));
  582. MENU_ITEM(gcode, MSG_DELTA_CALIBRATE_CENTER, PSTR("G0 F8000 X0 Y0 Z0"));
  583. END_MENU();
  584. }
  585. #endif // DELTA_CALIBRATION_MENU
  586. float move_menu_scale;
  587. static void lcd_move_menu_axis();
  588. static void _lcd_move(const char *name, int axis, int min, int max) {
  589. if (encoderPosition != 0) {
  590. refresh_cmd_timeout();
  591. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  592. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  593. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  594. encoderPosition = 0;
  595. #ifdef DELTA
  596. calculate_delta(current_position);
  597. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  598. #else
  599. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
  600. #endif
  601. lcdDrawUpdate = 1;
  602. }
  603. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  604. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  605. }
  606. static void lcd_move_x() { _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS); }
  607. static void lcd_move_y() { _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS); }
  608. static void lcd_move_z() { _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS); }
  609. static void lcd_move_e()
  610. {
  611. if (encoderPosition != 0)
  612. {
  613. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  614. encoderPosition = 0;
  615. #ifdef DELTA
  616. calculate_delta(current_position);
  617. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS]/60, active_extruder);
  618. #else
  619. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS]/60, active_extruder);
  620. #endif
  621. lcdDrawUpdate = 1;
  622. }
  623. if (lcdDrawUpdate)
  624. {
  625. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  626. }
  627. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  628. }
  629. static void lcd_move_menu_axis()
  630. {
  631. START_MENU();
  632. MENU_ITEM(back, MSG_MOVE_AXIS, lcd_move_menu);
  633. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  634. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  635. if (move_menu_scale < 10.0)
  636. {
  637. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  638. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  639. }
  640. END_MENU();
  641. }
  642. static void lcd_move_menu_10mm()
  643. {
  644. move_menu_scale = 10.0;
  645. lcd_move_menu_axis();
  646. }
  647. static void lcd_move_menu_1mm()
  648. {
  649. move_menu_scale = 1.0;
  650. lcd_move_menu_axis();
  651. }
  652. static void lcd_move_menu_01mm()
  653. {
  654. move_menu_scale = 0.1;
  655. lcd_move_menu_axis();
  656. }
  657. static void lcd_move_menu()
  658. {
  659. START_MENU();
  660. MENU_ITEM(back, MSG_PREPARE, lcd_prepare_menu);
  661. MENU_ITEM(submenu, MSG_MOVE_10MM, lcd_move_menu_10mm);
  662. MENU_ITEM(submenu, MSG_MOVE_1MM, lcd_move_menu_1mm);
  663. MENU_ITEM(submenu, MSG_MOVE_01MM, lcd_move_menu_01mm);
  664. //TODO:X,Y,Z,E
  665. END_MENU();
  666. }
  667. static void lcd_control_menu()
  668. {
  669. START_MENU();
  670. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  671. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  672. MENU_ITEM(submenu, MSG_MOTION, lcd_control_motion_menu);
  673. #ifdef DOGLCD
  674. // MENU_ITEM_EDIT(int3, MSG_CONTRAST, &lcd_contrast, 0, 63);
  675. MENU_ITEM(submenu, MSG_CONTRAST, lcd_set_contrast);
  676. #endif
  677. #ifdef FWRETRACT
  678. MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
  679. #endif
  680. #ifdef EEPROM_SETTINGS
  681. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  682. MENU_ITEM(function, MSG_LOAD_EPROM, Config_RetrieveSettings);
  683. #endif
  684. MENU_ITEM(function, MSG_RESTORE_FAILSAFE, Config_ResetDefault);
  685. END_MENU();
  686. }
  687. static void lcd_control_temperature_menu()
  688. {
  689. #ifdef PIDTEMP
  690. // set up temp variables - undo the default scaling
  691. raw_Ki = unscalePID_i(Ki);
  692. raw_Kd = unscalePID_d(Kd);
  693. #endif
  694. START_MENU();
  695. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  696. #if TEMP_SENSOR_0 != 0
  697. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
  698. #endif
  699. #if TEMP_SENSOR_1 != 0
  700. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
  701. #endif
  702. #if TEMP_SENSOR_2 != 0
  703. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
  704. #endif
  705. #if TEMP_SENSOR_BED != 0
  706. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
  707. #endif
  708. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  709. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  710. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  711. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
  712. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
  713. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  714. #endif
  715. #ifdef PIDTEMP
  716. MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
  717. // i is typically a small value so allows values below 1
  718. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
  719. MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
  720. # ifdef PID_ADD_EXTRUSION_RATE
  721. MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
  722. # endif//PID_ADD_EXTRUSION_RATE
  723. #endif//PIDTEMP
  724. MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
  725. MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
  726. END_MENU();
  727. }
  728. static void lcd_control_temperature_preheat_pla_settings_menu()
  729. {
  730. START_MENU();
  731. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  732. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &plaPreheatFanSpeed, 0, 255);
  733. #if TEMP_SENSOR_0 != 0
  734. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &plaPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  735. #endif
  736. #if TEMP_SENSOR_BED != 0
  737. MENU_ITEM_EDIT(int3, MSG_BED, &plaPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  738. #endif
  739. #ifdef EEPROM_SETTINGS
  740. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  741. #endif
  742. END_MENU();
  743. }
  744. static void lcd_control_temperature_preheat_abs_settings_menu()
  745. {
  746. START_MENU();
  747. MENU_ITEM(back, MSG_TEMPERATURE, lcd_control_temperature_menu);
  748. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &absPreheatFanSpeed, 0, 255);
  749. #if TEMP_SENSOR_0 != 0
  750. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &absPreheatHotendTemp, 0, HEATER_0_MAXTEMP - 15);
  751. #endif
  752. #if TEMP_SENSOR_BED != 0
  753. MENU_ITEM_EDIT(int3, MSG_BED, &absPreheatHPBTemp, 0, BED_MAXTEMP - 15);
  754. #endif
  755. #ifdef EEPROM_SETTINGS
  756. MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
  757. #endif
  758. END_MENU();
  759. }
  760. static void lcd_control_motion_menu()
  761. {
  762. START_MENU();
  763. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  764. #ifdef ENABLE_AUTO_BED_LEVELING
  765. MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, 0.5, 50);
  766. #endif
  767. MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 500, 99000);
  768. MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
  769. MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
  770. MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
  771. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
  772. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
  773. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
  774. MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
  775. MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
  776. MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
  777. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
  778. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
  779. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 100, 99000, reset_acceleration_rates);
  780. MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
  781. MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
  782. MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
  783. MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
  784. MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
  785. MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
  786. #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
  787. MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
  788. #endif
  789. #ifdef SCARA
  790. MENU_ITEM_EDIT(float74, MSG_XSCALE, &axis_scaling[X_AXIS],0.5,2);
  791. MENU_ITEM_EDIT(float74, MSG_YSCALE, &axis_scaling[Y_AXIS],0.5,2);
  792. #endif
  793. END_MENU();
  794. }
  795. #ifdef DOGLCD
  796. static void lcd_set_contrast()
  797. {
  798. if (encoderPosition != 0)
  799. {
  800. lcd_contrast -= encoderPosition;
  801. if (lcd_contrast < 0) lcd_contrast = 0;
  802. else if (lcd_contrast > 63) lcd_contrast = 63;
  803. encoderPosition = 0;
  804. lcdDrawUpdate = 1;
  805. u8g.setContrast(lcd_contrast);
  806. }
  807. if (lcdDrawUpdate)
  808. {
  809. lcd_implementation_drawedit(PSTR(MSG_CONTRAST), itostr2(lcd_contrast));
  810. }
  811. if (LCD_CLICKED) lcd_goto_menu(lcd_control_menu);
  812. }
  813. #endif
  814. #ifdef FWRETRACT
  815. static void lcd_control_retract_menu()
  816. {
  817. START_MENU();
  818. MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  819. MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &autoretract_enabled);
  820. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &retract_length, 0, 100);
  821. #if EXTRUDERS > 1
  822. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &retract_length_swap, 0, 100);
  823. #endif
  824. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &retract_feedrate, 1, 999);
  825. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &retract_zlift, 0, 999);
  826. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &retract_recover_length, 0, 100);
  827. #if EXTRUDERS > 1
  828. MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &retract_recover_length_swap, 0, 100);
  829. #endif
  830. MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &retract_recover_feedrate, 1, 999);
  831. END_MENU();
  832. }
  833. #endif //FWRETRACT
  834. #if SDCARDDETECT == -1
  835. static void lcd_sd_refresh()
  836. {
  837. card.initsd();
  838. currentMenuViewOffset = 0;
  839. }
  840. #endif
  841. static void lcd_sd_updir()
  842. {
  843. card.updir();
  844. currentMenuViewOffset = 0;
  845. }
  846. void lcd_sdcard_menu()
  847. {
  848. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  849. return; // nothing to do (so don't thrash the SD card)
  850. uint16_t fileCnt = card.getnrfilenames();
  851. START_MENU();
  852. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  853. card.getWorkDirName();
  854. if(card.filename[0]=='/')
  855. {
  856. #if SDCARDDETECT == -1
  857. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  858. #endif
  859. }else{
  860. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  861. }
  862. for(uint16_t i=0;i<fileCnt;i++)
  863. {
  864. if (_menuItemNr == _lineNr)
  865. {
  866. #ifndef SDCARD_RATHERRECENTFIRST
  867. card.getfilename(i);
  868. #else
  869. card.getfilename(fileCnt-1-i);
  870. #endif
  871. if (card.filenameIsDir)
  872. {
  873. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  874. }else{
  875. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  876. }
  877. }else{
  878. MENU_ITEM_DUMMY();
  879. }
  880. }
  881. END_MENU();
  882. }
  883. #define menu_edit_type(_type, _name, _strFunc, scale) \
  884. void menu_edit_ ## _name () \
  885. { \
  886. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  887. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  888. if (lcdDrawUpdate) \
  889. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  890. if (LCD_CLICKED) \
  891. { \
  892. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  893. lcd_goto_menu(prevMenu, prevEncoderPosition); \
  894. } \
  895. } \
  896. void menu_edit_callback_ ## _name () { \
  897. menu_edit_ ## _name (); \
  898. if (LCD_CLICKED) (*callbackFunc)(); \
  899. } \
  900. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  901. { \
  902. prevMenu = currentMenu; \
  903. prevEncoderPosition = encoderPosition; \
  904. \
  905. lcdDrawUpdate = 2; \
  906. currentMenu = menu_edit_ ## _name; \
  907. \
  908. editLabel = pstr; \
  909. editValue = ptr; \
  910. minEditValue = minValue * scale; \
  911. maxEditValue = maxValue * scale - minEditValue; \
  912. encoderPosition = (*ptr) * scale - minEditValue; \
  913. }\
  914. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  915. { \
  916. prevMenu = currentMenu; \
  917. prevEncoderPosition = encoderPosition; \
  918. \
  919. lcdDrawUpdate = 2; \
  920. currentMenu = menu_edit_callback_ ## _name; \
  921. \
  922. editLabel = pstr; \
  923. editValue = ptr; \
  924. minEditValue = minValue * scale; \
  925. maxEditValue = maxValue * scale - minEditValue; \
  926. encoderPosition = (*ptr) * scale - minEditValue; \
  927. callbackFunc = callback;\
  928. }
  929. menu_edit_type(int, int3, itostr3, 1)
  930. menu_edit_type(float, float3, ftostr3, 1)
  931. menu_edit_type(float, float32, ftostr32, 100)
  932. menu_edit_type(float, float5, ftostr5, 0.01)
  933. menu_edit_type(float, float51, ftostr51, 10)
  934. menu_edit_type(float, float52, ftostr52, 100)
  935. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  936. #ifdef REPRAPWORLD_KEYPAD
  937. static void reprapworld_keypad_move_z_up() {
  938. encoderPosition = 1;
  939. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  940. lcd_move_z();
  941. }
  942. static void reprapworld_keypad_move_z_down() {
  943. encoderPosition = -1;
  944. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  945. lcd_move_z();
  946. }
  947. static void reprapworld_keypad_move_x_left() {
  948. encoderPosition = -1;
  949. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  950. lcd_move_x();
  951. }
  952. static void reprapworld_keypad_move_x_right() {
  953. encoderPosition = 1;
  954. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  955. lcd_move_x();
  956. }
  957. static void reprapworld_keypad_move_y_down() {
  958. encoderPosition = 1;
  959. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  960. lcd_move_y();
  961. }
  962. static void reprapworld_keypad_move_y_up() {
  963. encoderPosition = -1;
  964. move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
  965. lcd_move_y();
  966. }
  967. static void reprapworld_keypad_move_home() {
  968. enquecommand_P((PSTR("G28"))); // move all axis home
  969. }
  970. #endif
  971. /** End of menus **/
  972. static void lcd_quick_feedback()
  973. {
  974. lcdDrawUpdate = 2;
  975. blocking_enc = millis() + 500;
  976. lcd_implementation_quick_feedback();
  977. }
  978. /** Menu action functions **/
  979. static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
  980. static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
  981. static void menu_action_gcode(const char* pgcode) { enquecommand_P(pgcode); }
  982. static void menu_action_function(menuFunc_t data) { (*data)(); }
  983. static void menu_action_sdfile(const char* filename, char* longFilename)
  984. {
  985. char cmd[30];
  986. char* c;
  987. sprintf_P(cmd, PSTR("M23 %s"), filename);
  988. for(c = &cmd[4]; *c; c++)
  989. *c = tolower(*c);
  990. enquecommand(cmd);
  991. enquecommand_P(PSTR("M24"));
  992. lcd_return_to_status();
  993. }
  994. static void menu_action_sddirectory(const char* filename, char* longFilename)
  995. {
  996. card.chdir(filename);
  997. encoderPosition = 0;
  998. }
  999. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  1000. {
  1001. *ptr = !(*ptr);
  1002. }
  1003. #endif//ULTIPANEL
  1004. /** LCD API **/
  1005. void lcd_init()
  1006. {
  1007. lcd_implementation_init();
  1008. #ifdef NEWPANEL
  1009. SET_INPUT(BTN_EN1);
  1010. SET_INPUT(BTN_EN2);
  1011. WRITE(BTN_EN1,HIGH);
  1012. WRITE(BTN_EN2,HIGH);
  1013. #if BTN_ENC > 0
  1014. SET_INPUT(BTN_ENC);
  1015. WRITE(BTN_ENC,HIGH);
  1016. #endif
  1017. #ifdef REPRAPWORLD_KEYPAD
  1018. pinMode(SHIFT_CLK,OUTPUT);
  1019. pinMode(SHIFT_LD,OUTPUT);
  1020. pinMode(SHIFT_OUT,INPUT);
  1021. WRITE(SHIFT_OUT,HIGH);
  1022. WRITE(SHIFT_LD,HIGH);
  1023. #endif
  1024. #else // Not NEWPANEL
  1025. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  1026. pinMode (SR_DATA_PIN, OUTPUT);
  1027. pinMode (SR_CLK_PIN, OUTPUT);
  1028. #elif defined(SHIFT_CLK)
  1029. pinMode(SHIFT_CLK,OUTPUT);
  1030. pinMode(SHIFT_LD,OUTPUT);
  1031. pinMode(SHIFT_EN,OUTPUT);
  1032. pinMode(SHIFT_OUT,INPUT);
  1033. WRITE(SHIFT_OUT,HIGH);
  1034. WRITE(SHIFT_LD,HIGH);
  1035. WRITE(SHIFT_EN,LOW);
  1036. #else
  1037. #ifdef ULTIPANEL
  1038. #error ULTIPANEL requires an encoder
  1039. #endif
  1040. #endif // SR_LCD_2W_NL
  1041. #endif//!NEWPANEL
  1042. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  1043. pinMode(SDCARDDETECT,INPUT);
  1044. WRITE(SDCARDDETECT, HIGH);
  1045. lcd_oldcardstatus = IS_SD_INSERTED;
  1046. #endif//(SDCARDDETECT > 0)
  1047. #ifdef LCD_HAS_SLOW_BUTTONS
  1048. slow_buttons = 0;
  1049. #endif
  1050. lcd_buttons_update();
  1051. #ifdef ULTIPANEL
  1052. encoderDiff = 0;
  1053. #endif
  1054. }
  1055. void lcd_update()
  1056. {
  1057. static unsigned long timeoutToStatus = 0;
  1058. #ifdef LCD_HAS_SLOW_BUTTONS
  1059. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1060. #endif
  1061. lcd_buttons_update();
  1062. #if (SDCARDDETECT > 0)
  1063. if((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  1064. {
  1065. lcdDrawUpdate = 2;
  1066. lcd_oldcardstatus = IS_SD_INSERTED;
  1067. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1068. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1069. currentMenu == lcd_status_screen
  1070. #endif
  1071. );
  1072. if(lcd_oldcardstatus)
  1073. {
  1074. card.initsd();
  1075. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1076. }
  1077. else
  1078. {
  1079. card.release();
  1080. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1081. }
  1082. }
  1083. #endif//CARDINSERTED
  1084. if (lcd_next_update_millis < millis())
  1085. {
  1086. #ifdef ULTIPANEL
  1087. #ifdef REPRAPWORLD_KEYPAD
  1088. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  1089. reprapworld_keypad_move_z_up();
  1090. }
  1091. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  1092. reprapworld_keypad_move_z_down();
  1093. }
  1094. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  1095. reprapworld_keypad_move_x_left();
  1096. }
  1097. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  1098. reprapworld_keypad_move_x_right();
  1099. }
  1100. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  1101. reprapworld_keypad_move_y_down();
  1102. }
  1103. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  1104. reprapworld_keypad_move_y_up();
  1105. }
  1106. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  1107. reprapworld_keypad_move_home();
  1108. }
  1109. #endif
  1110. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  1111. {
  1112. lcdDrawUpdate = 1;
  1113. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  1114. encoderDiff = 0;
  1115. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1116. }
  1117. if (LCD_CLICKED)
  1118. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1119. #endif//ULTIPANEL
  1120. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  1121. blink++; // Variable for fan animation and alive dot
  1122. u8g.firstPage();
  1123. do
  1124. {
  1125. u8g.setFont(u8g_font_6x10_marlin);
  1126. u8g.setPrintPos(125,0);
  1127. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1128. u8g.drawPixel(127,63); // draw alive dot
  1129. u8g.setColorIndex(1); // black on white
  1130. (*currentMenu)();
  1131. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  1132. } while( u8g.nextPage() );
  1133. #else
  1134. (*currentMenu)();
  1135. #endif
  1136. #ifdef LCD_HAS_STATUS_INDICATORS
  1137. lcd_implementation_update_indicators();
  1138. #endif
  1139. #ifdef ULTIPANEL
  1140. if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  1141. {
  1142. lcd_return_to_status();
  1143. lcdDrawUpdate = 2;
  1144. }
  1145. #endif//ULTIPANEL
  1146. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1147. if (lcdDrawUpdate) lcdDrawUpdate--;
  1148. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  1149. }
  1150. }
  1151. void lcd_ignore_click(bool b)
  1152. {
  1153. ignore_click = b;
  1154. wait_for_unclick = false;
  1155. }
  1156. void lcd_finishstatus() {
  1157. int len = strlen(lcd_status_message);
  1158. if (len > 0) {
  1159. while (len < LCD_WIDTH) {
  1160. lcd_status_message[len++] = ' ';
  1161. }
  1162. }
  1163. lcd_status_message[LCD_WIDTH] = '\0';
  1164. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1165. #if PROGRESS_MSG_EXPIRE > 0
  1166. messageTick =
  1167. #endif
  1168. progressBarTick = millis();
  1169. #endif
  1170. lcdDrawUpdate = 2;
  1171. #ifdef FILAMENT_LCD_DISPLAY
  1172. message_millis = millis(); //get status message to show up for a while
  1173. #endif
  1174. }
  1175. void lcd_setstatus(const char* message)
  1176. {
  1177. if (lcd_status_message_level > 0)
  1178. return;
  1179. strncpy(lcd_status_message, message, LCD_WIDTH);
  1180. lcd_finishstatus();
  1181. }
  1182. void lcd_setstatuspgm(const char* message)
  1183. {
  1184. if (lcd_status_message_level > 0)
  1185. return;
  1186. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  1187. lcd_finishstatus();
  1188. }
  1189. void lcd_setalertstatuspgm(const char* message)
  1190. {
  1191. lcd_setstatuspgm(message);
  1192. lcd_status_message_level = 1;
  1193. #ifdef ULTIPANEL
  1194. lcd_return_to_status();
  1195. #endif//ULTIPANEL
  1196. }
  1197. void lcd_reset_alert_level()
  1198. {
  1199. lcd_status_message_level = 0;
  1200. }
  1201. #ifdef DOGLCD
  1202. void lcd_setcontrast(uint8_t value)
  1203. {
  1204. lcd_contrast = value & 63;
  1205. u8g.setContrast(lcd_contrast);
  1206. }
  1207. #endif
  1208. #ifdef ULTIPANEL
  1209. /* Warning: This function is called from interrupt context */
  1210. void lcd_buttons_update()
  1211. {
  1212. #ifdef NEWPANEL
  1213. uint8_t newbutton=0;
  1214. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  1215. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  1216. #if BTN_ENC > 0
  1217. if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
  1218. newbutton |= EN_C;
  1219. #endif
  1220. buttons = newbutton;
  1221. #ifdef LCD_HAS_SLOW_BUTTONS
  1222. buttons |= slow_buttons;
  1223. #endif
  1224. #ifdef REPRAPWORLD_KEYPAD
  1225. // for the reprapworld_keypad
  1226. uint8_t newbutton_reprapworld_keypad=0;
  1227. WRITE(SHIFT_LD,LOW);
  1228. WRITE(SHIFT_LD,HIGH);
  1229. for(int8_t i=0;i<8;i++) {
  1230. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad>>1;
  1231. if(READ(SHIFT_OUT))
  1232. newbutton_reprapworld_keypad|=(1<<7);
  1233. WRITE(SHIFT_CLK,HIGH);
  1234. WRITE(SHIFT_CLK,LOW);
  1235. }
  1236. buttons_reprapworld_keypad=~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1237. #endif
  1238. #else //read it from the shift register
  1239. uint8_t newbutton=0;
  1240. WRITE(SHIFT_LD,LOW);
  1241. WRITE(SHIFT_LD,HIGH);
  1242. unsigned char tmp_buttons=0;
  1243. for(int8_t i=0;i<8;i++)
  1244. {
  1245. newbutton = newbutton>>1;
  1246. if(READ(SHIFT_OUT))
  1247. newbutton|=(1<<7);
  1248. WRITE(SHIFT_CLK,HIGH);
  1249. WRITE(SHIFT_CLK,LOW);
  1250. }
  1251. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  1252. #endif//!NEWPANEL
  1253. //manage encoder rotation
  1254. uint8_t enc=0;
  1255. if (buttons & EN_A) enc |= B01;
  1256. if (buttons & EN_B) enc |= B10;
  1257. if(enc != lastEncoderBits)
  1258. {
  1259. switch(enc)
  1260. {
  1261. case encrot0:
  1262. if(lastEncoderBits==encrot3)
  1263. encoderDiff++;
  1264. else if(lastEncoderBits==encrot1)
  1265. encoderDiff--;
  1266. break;
  1267. case encrot1:
  1268. if(lastEncoderBits==encrot0)
  1269. encoderDiff++;
  1270. else if(lastEncoderBits==encrot2)
  1271. encoderDiff--;
  1272. break;
  1273. case encrot2:
  1274. if(lastEncoderBits==encrot1)
  1275. encoderDiff++;
  1276. else if(lastEncoderBits==encrot3)
  1277. encoderDiff--;
  1278. break;
  1279. case encrot3:
  1280. if(lastEncoderBits==encrot2)
  1281. encoderDiff++;
  1282. else if(lastEncoderBits==encrot0)
  1283. encoderDiff--;
  1284. break;
  1285. }
  1286. }
  1287. lastEncoderBits = enc;
  1288. }
  1289. bool lcd_detected(void)
  1290. {
  1291. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  1292. return lcd.LcdDetected() == 1;
  1293. #else
  1294. return true;
  1295. #endif
  1296. }
  1297. void lcd_buzz(long duration, uint16_t freq)
  1298. {
  1299. #ifdef LCD_USE_I2C_BUZZER
  1300. lcd.buzz(duration,freq);
  1301. #endif
  1302. }
  1303. bool lcd_clicked()
  1304. {
  1305. return LCD_CLICKED;
  1306. }
  1307. #endif//ULTIPANEL
  1308. /********************************/
  1309. /** Float conversion utilities **/
  1310. /********************************/
  1311. // convert float to string with +123.4 format
  1312. char conv[8];
  1313. char *ftostr3(const float &x)
  1314. {
  1315. return itostr3((int)x);
  1316. }
  1317. char *itostr2(const uint8_t &x)
  1318. {
  1319. //sprintf(conv,"%5.1f",x);
  1320. int xx=x;
  1321. conv[0]=(xx/10)%10+'0';
  1322. conv[1]=(xx)%10+'0';
  1323. conv[2]=0;
  1324. return conv;
  1325. }
  1326. // Convert float to string with 123.4 format, dropping sign
  1327. char *ftostr31(const float &x)
  1328. {
  1329. int xx=x*10;
  1330. conv[0]=(xx>=0)?'+':'-';
  1331. xx=abs(xx);
  1332. conv[1]=(xx/1000)%10+'0';
  1333. conv[2]=(xx/100)%10+'0';
  1334. conv[3]=(xx/10)%10+'0';
  1335. conv[4]='.';
  1336. conv[5]=(xx)%10+'0';
  1337. conv[6]=0;
  1338. return conv;
  1339. }
  1340. // Convert float to string with 123.4 format
  1341. char *ftostr31ns(const float &x)
  1342. {
  1343. int xx=x*10;
  1344. //conv[0]=(xx>=0)?'+':'-';
  1345. xx=abs(xx);
  1346. conv[0]=(xx/1000)%10+'0';
  1347. conv[1]=(xx/100)%10+'0';
  1348. conv[2]=(xx/10)%10+'0';
  1349. conv[3]='.';
  1350. conv[4]=(xx)%10+'0';
  1351. conv[5]=0;
  1352. return conv;
  1353. }
  1354. char *ftostr32(const float &x)
  1355. {
  1356. long xx=x*100;
  1357. if (xx >= 0)
  1358. conv[0]=(xx/10000)%10+'0';
  1359. else
  1360. conv[0]='-';
  1361. xx=abs(xx);
  1362. conv[1]=(xx/1000)%10+'0';
  1363. conv[2]=(xx/100)%10+'0';
  1364. conv[3]='.';
  1365. conv[4]=(xx/10)%10+'0';
  1366. conv[5]=(xx)%10+'0';
  1367. conv[6]=0;
  1368. return conv;
  1369. }
  1370. // Convert float to string with 1.23 format
  1371. char *ftostr12ns(const float &x)
  1372. {
  1373. long xx=x*100;
  1374. xx=abs(xx);
  1375. conv[0]=(xx/100)%10+'0';
  1376. conv[1]='.';
  1377. conv[2]=(xx/10)%10+'0';
  1378. conv[3]=(xx)%10+'0';
  1379. conv[4]=0;
  1380. return conv;
  1381. }
  1382. // Convert int to lj string with +123.0 format
  1383. char *itostr31(const int &xx)
  1384. {
  1385. conv[0]=(xx>=0)?'+':'-';
  1386. conv[1]=(xx/1000)%10+'0';
  1387. conv[2]=(xx/100)%10+'0';
  1388. conv[3]=(xx/10)%10+'0';
  1389. conv[4]='.';
  1390. conv[5]=(xx)%10+'0';
  1391. conv[6]=0;
  1392. return conv;
  1393. }
  1394. // Convert int to rj string with 123 or -12 format
  1395. char *itostr3(const int &x)
  1396. {
  1397. int xx = x;
  1398. if (xx < 0) {
  1399. conv[0]='-';
  1400. xx = -xx;
  1401. } else if (xx >= 100)
  1402. conv[0]=(xx/100)%10+'0';
  1403. else
  1404. conv[0]=' ';
  1405. if (xx >= 10)
  1406. conv[1]=(xx/10)%10+'0';
  1407. else
  1408. conv[1]=' ';
  1409. conv[2]=(xx)%10+'0';
  1410. conv[3]=0;
  1411. return conv;
  1412. }
  1413. // Convert int to lj string with 123 format
  1414. char *itostr3left(const int &xx)
  1415. {
  1416. if (xx >= 100)
  1417. {
  1418. conv[0]=(xx/100)%10+'0';
  1419. conv[1]=(xx/10)%10+'0';
  1420. conv[2]=(xx)%10+'0';
  1421. conv[3]=0;
  1422. }
  1423. else if (xx >= 10)
  1424. {
  1425. conv[0]=(xx/10)%10+'0';
  1426. conv[1]=(xx)%10+'0';
  1427. conv[2]=0;
  1428. }
  1429. else
  1430. {
  1431. conv[0]=(xx)%10+'0';
  1432. conv[1]=0;
  1433. }
  1434. return conv;
  1435. }
  1436. // Convert int to rj string with 1234 format
  1437. char *itostr4(const int &xx) {
  1438. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1439. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1440. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1441. conv[3] = xx % 10 + '0';
  1442. conv[4] = 0;
  1443. return conv;
  1444. }
  1445. // Convert float to rj string with 12345 format
  1446. char *ftostr5(const float &x) {
  1447. long xx = abs(x);
  1448. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  1449. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1450. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1451. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1452. conv[4] = xx % 10 + '0';
  1453. conv[5] = 0;
  1454. return conv;
  1455. }
  1456. // Convert float to string with +1234.5 format
  1457. char *ftostr51(const float &x)
  1458. {
  1459. long xx=x*10;
  1460. conv[0]=(xx>=0)?'+':'-';
  1461. xx=abs(xx);
  1462. conv[1]=(xx/10000)%10+'0';
  1463. conv[2]=(xx/1000)%10+'0';
  1464. conv[3]=(xx/100)%10+'0';
  1465. conv[4]=(xx/10)%10+'0';
  1466. conv[5]='.';
  1467. conv[6]=(xx)%10+'0';
  1468. conv[7]=0;
  1469. return conv;
  1470. }
  1471. // Convert float to string with +123.45 format
  1472. char *ftostr52(const float &x)
  1473. {
  1474. long xx=x*100;
  1475. conv[0]=(xx>=0)?'+':'-';
  1476. xx=abs(xx);
  1477. conv[1]=(xx/10000)%10+'0';
  1478. conv[2]=(xx/1000)%10+'0';
  1479. conv[3]=(xx/100)%10+'0';
  1480. conv[4]='.';
  1481. conv[5]=(xx/10)%10+'0';
  1482. conv[6]=(xx)%10+'0';
  1483. conv[7]=0;
  1484. return conv;
  1485. }
  1486. // Callback for after editing PID i value
  1487. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  1488. void copy_and_scalePID_i()
  1489. {
  1490. #ifdef PIDTEMP
  1491. Ki = scalePID_i(raw_Ki);
  1492. updatePID();
  1493. #endif
  1494. }
  1495. // Callback for after editing PID d value
  1496. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  1497. void copy_and_scalePID_d()
  1498. {
  1499. #ifdef PIDTEMP
  1500. Kd = scalePID_d(raw_Kd);
  1501. updatePID();
  1502. #endif
  1503. }
  1504. #endif //ULTRA_LCD