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

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