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.

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