My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.cpp 36KB

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