ultralcd.cpp 46 KB

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