My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ultralcd.cpp 44KB

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