ultralcd.cpp 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376
  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. #include <string.h>
  11. //#include "Configuration.h"
  12. #define _STRINGIFY(s) #s
  13. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  14. extern int lcd_change_fil_state;
  15. int babystepMem[3];
  16. float babystepMemMM[3];
  17. union Data
  18. {
  19. byte b[2];
  20. int value;
  21. };
  22. int8_t ReInitLCD = 0;
  23. int8_t SDscrool = 0;
  24. int8_t SilentModeMenu = 0;
  25. /* Configuration settings */
  26. int plaPreheatHotendTemp;
  27. int plaPreheatHPBTemp;
  28. int plaPreheatFanSpeed;
  29. int absPreheatHotendTemp;
  30. int absPreheatHPBTemp;
  31. int absPreheatFanSpeed;
  32. int ppPreheatHotendTemp = PP_PREHEAT_HOTEND_TEMP;
  33. int ppPreheatHPBTemp = PP_PREHEAT_HPB_TEMP;
  34. int ppPreheatFanSpeed = PP_PREHEAT_FAN_SPEED;
  35. int petPreheatHotendTemp = PET_PREHEAT_HOTEND_TEMP;
  36. int petPreheatHPBTemp = PET_PREHEAT_HPB_TEMP;
  37. int petPreheatFanSpeed = PET_PREHEAT_FAN_SPEED;
  38. int hipsPreheatHotendTemp = HIPS_PREHEAT_HOTEND_TEMP;
  39. int hipsPreheatHPBTemp = HIPS_PREHEAT_HPB_TEMP;
  40. int hipsPreheatFanSpeed = HIPS_PREHEAT_FAN_SPEED;
  41. int flexPreheatHotendTemp = FLEX_PREHEAT_HOTEND_TEMP;
  42. int flexPreheatHPBTemp = FLEX_PREHEAT_HPB_TEMP;
  43. int flexPreheatFanSpeed = FLEX_PREHEAT_FAN_SPEED;
  44. #ifdef FILAMENT_LCD_DISPLAY
  45. unsigned long message_millis = 0;
  46. #endif
  47. #ifdef ULTIPANEL
  48. static float manual_feedrate[] = MANUAL_FEEDRATE;
  49. #endif // ULTIPANEL
  50. /* !Configuration settings */
  51. //Function pointer to menu functions.
  52. typedef void (*menuFunc_t)();
  53. uint8_t lcd_status_message_level;
  54. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  55. unsigned char firstrun = 1;
  56. #ifdef DOGLCD
  57. #include "dogm_lcd_implementation.h"
  58. #else
  59. #include "ultralcd_implementation_hitachi_HD44780.h"
  60. #endif
  61. /** forward declarations **/
  62. void copy_and_scalePID_i();
  63. void copy_and_scalePID_d();
  64. /* Different menus */
  65. static void lcd_status_screen();
  66. #ifdef ULTIPANEL
  67. extern bool powersupply;
  68. static void lcd_main_menu();
  69. static void lcd_tune_menu();
  70. static void lcd_prepare_menu();
  71. static void lcd_move_menu();
  72. static void lcd_control_menu();
  73. static void lcd_settings_menu();
  74. static void lcd_language_menu();
  75. static void lcd_control_temperature_menu();
  76. static void lcd_control_temperature_preheat_pla_settings_menu();
  77. static void lcd_control_temperature_preheat_abs_settings_menu();
  78. static void lcd_control_motion_menu();
  79. static void lcd_control_volumetric_menu();
  80. #ifdef DOGLCD
  81. static void lcd_set_contrast();
  82. #endif
  83. static void lcd_control_retract_menu();
  84. static void lcd_sdcard_menu();
  85. #ifdef DELTA_CALIBRATION_MENU
  86. static void lcd_delta_calibrate_menu();
  87. #endif // DELTA_CALIBRATION_MENU
  88. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  89. /* Different types of actions that can be used in menu items. */
  90. static void menu_action_back(menuFunc_t data);
  91. static void menu_action_submenu(menuFunc_t data);
  92. static void menu_action_gcode(const char* pgcode);
  93. static void menu_action_function(menuFunc_t data);
  94. static void menu_action_setlang(unsigned char lang);
  95. static void menu_action_sdfile(const char* filename, char* longFilename);
  96. static void menu_action_sddirectory(const char* filename, char* longFilename);
  97. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  98. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  99. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  100. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  101. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  102. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  103. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  104. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  105. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  106. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  107. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  108. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  109. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  110. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  111. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  112. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  113. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  114. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  115. #define ENCODER_FEEDRATE_DEADZONE 10
  116. #if !defined(LCD_I2C_VIKI)
  117. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  118. #define ENCODER_STEPS_PER_MENU_ITEM 5
  119. #endif
  120. #ifndef ENCODER_PULSES_PER_STEP
  121. #define ENCODER_PULSES_PER_STEP 1
  122. #endif
  123. #else
  124. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  125. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  126. #endif
  127. #ifndef ENCODER_PULSES_PER_STEP
  128. #define ENCODER_PULSES_PER_STEP 1
  129. #endif
  130. #endif
  131. /* Helper macros for menus */
  132. #define START_MENU() do { \
  133. if (encoderPosition > 0x8000) encoderPosition = 0; \
  134. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  135. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  136. bool wasClicked = LCD_CLICKED;\
  137. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  138. _menuItemNr = 0;
  139. #define MENU_ITEM(type, label, args...) do { \
  140. if (_menuItemNr == _lineNr) { \
  141. if (lcdDrawUpdate) { \
  142. const char* _label_pstr = (label); \
  143. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  144. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  145. }else{\
  146. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  147. }\
  148. }\
  149. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  150. lcd_quick_feedback(); \
  151. menu_action_ ## type ( args ); \
  152. return;\
  153. }\
  154. }\
  155. _menuItemNr++;\
  156. } while(0)
  157. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  158. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  159. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  160. #define END_MENU() \
  161. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  162. 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; } \
  163. } } while(0)
  164. /** Used variables to keep track of the menu */
  165. #ifndef REPRAPWORLD_KEYPAD
  166. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  167. #else
  168. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  169. #endif
  170. #ifdef LCD_HAS_SLOW_BUTTONS
  171. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  172. #endif
  173. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  174. uint32_t blocking_enc;
  175. uint8_t lastEncoderBits;
  176. uint32_t encoderPosition;
  177. #if (SDCARDDETECT > 0)
  178. bool lcd_oldcardstatus;
  179. #endif
  180. #endif //ULTIPANEL
  181. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  182. uint32_t lcd_next_update_millis;
  183. uint8_t lcd_status_update_delay;
  184. bool ignore_click = false;
  185. bool wait_for_unclick;
  186. 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) */
  187. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  188. menuFunc_t prevMenu = NULL;
  189. uint16_t prevEncoderPosition;
  190. //Variables used when editing values.
  191. const char* editLabel;
  192. void* editValue;
  193. int32_t minEditValue, maxEditValue;
  194. menuFunc_t callbackFunc;
  195. // place-holders for Ki and Kd edits
  196. float raw_Ki, raw_Kd;
  197. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true) {
  198. if (currentMenu != menu) {
  199. currentMenu = menu;
  200. encoderPosition = encoder;
  201. if (feedback) lcd_quick_feedback();
  202. // For LCD_PROGRESS_BAR re-initialize the custom characters
  203. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  204. lcd_set_custom_characters(menu == lcd_status_screen);
  205. #endif
  206. }
  207. }
  208. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  209. /*
  210. extern char langbuffer[];
  211. void lcd_printPGM(const char *s1) {
  212. strncpy_P(langbuffer,s1,LCD_WIDTH);
  213. lcd.print(langbuffer);
  214. }
  215. */
  216. unsigned char langsel;
  217. void set_language_from_EEPROM() {
  218. unsigned char eep = eeprom_read_byte((unsigned char*)EEPROM_LANG);
  219. if (eep < LANG_NUM)
  220. {
  221. lang_selected = eep;
  222. langsel = 0;
  223. }
  224. else
  225. {
  226. lang_selected = 1;
  227. langsel = 1;
  228. }
  229. }
  230. void lcd_mylang();
  231. static void lcd_status_screen()
  232. {
  233. if (firstrun == 1) {
  234. firstrun = 0;
  235. set_language_from_EEPROM();
  236. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  237. if (langsel) {
  238. //strncpy_P(lcd_status_message, PSTR(">>>>>>>>>>>> PRESS v"), LCD_WIDTH);
  239. lcd_mylang();
  240. }
  241. }
  242. if (lcd_status_update_delay)
  243. lcd_status_update_delay--;
  244. else
  245. lcdDrawUpdate = 1;
  246. if (lcdDrawUpdate)
  247. {
  248. ReInitLCD++;
  249. if (ReInitLCD == 30) {
  250. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  251. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  252. currentMenu == lcd_status_screen
  253. #endif
  254. );
  255. ReInitLCD = 0 ;
  256. } else {
  257. if ((ReInitLCD % 10) == 0) {
  258. //lcd_implementation_nodisplay();
  259. lcd_implementation_init_noclear( // to maybe revive the LCD if static electricity killed it.
  260. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  261. currentMenu == lcd_status_screen
  262. #endif
  263. );
  264. }
  265. }
  266. //lcd_implementation_display();
  267. lcd_implementation_status_screen();
  268. //lcd_implementation_clear();
  269. 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 */
  270. }
  271. #ifdef ULTIPANEL
  272. bool current_click = LCD_CLICKED;
  273. if (ignore_click) {
  274. if (wait_for_unclick) {
  275. if (!current_click) {
  276. ignore_click = wait_for_unclick = false;
  277. }
  278. else {
  279. current_click = false;
  280. }
  281. }
  282. else if (current_click) {
  283. lcd_quick_feedback();
  284. wait_for_unclick = true;
  285. current_click = false;
  286. }
  287. }
  288. //if (--langsel ==0) {langsel=1;current_click=true;}
  289. if (current_click)
  290. {
  291. lcd_goto_menu(lcd_main_menu);
  292. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  293. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  294. currentMenu == lcd_status_screen
  295. #endif
  296. );
  297. #ifdef FILAMENT_LCD_DISPLAY
  298. message_millis = millis(); // get status message to show up for a while
  299. #endif
  300. }
  301. #ifdef ULTIPANEL_FEEDMULTIPLY
  302. // Dead zone at 100% feedrate
  303. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  304. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  305. {
  306. encoderPosition = 0;
  307. feedmultiply = 100;
  308. }
  309. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  310. {
  311. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  312. encoderPosition = 0;
  313. }
  314. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  315. {
  316. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  317. encoderPosition = 0;
  318. }
  319. else if (feedmultiply != 100)
  320. {
  321. feedmultiply += int(encoderPosition);
  322. encoderPosition = 0;
  323. }
  324. #endif //ULTIPANEL_FEEDMULTIPLY
  325. if (feedmultiply < 10)
  326. feedmultiply = 10;
  327. else if (feedmultiply > 999)
  328. feedmultiply = 999;
  329. #endif //ULTIPANEL
  330. }
  331. #ifdef ULTIPANEL
  332. static void lcd_return_to_status() {
  333. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  334. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  335. currentMenu == lcd_status_screen
  336. #endif
  337. );
  338. lcd_goto_menu(lcd_status_screen, 0, false);
  339. }
  340. static void lcd_sdcard_pause() {
  341. card.pauseSDPrint();
  342. }
  343. static void lcd_sdcard_resume() {
  344. card.startFileprint();
  345. }
  346. float move_menu_scale;
  347. static void lcd_move_menu_axis();
  348. static void lcd_sdcard_stop()
  349. {
  350. card.sdprinting = false;
  351. card.closefile();
  352. quickStop();
  353. if (SD_FINISHED_STEPPERRELEASE)
  354. {
  355. enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND));
  356. }
  357. autotempShutdown();
  358. cancel_heatup = true;
  359. lcd_setstatus(MSG_PRINT_ABORTED);
  360. enquecommand_P(PSTR("M84"));
  361. }
  362. /* Menu implementation */
  363. void lcd_preheat_pla()
  364. {
  365. setTargetHotend0(plaPreheatHotendTemp);
  366. setTargetBed(plaPreheatHPBTemp);
  367. fanSpeed = 0;
  368. lcd_return_to_status();
  369. setWatch(); // heater sanity check timer
  370. }
  371. void lcd_preheat_abs()
  372. {
  373. setTargetHotend0(absPreheatHotendTemp);
  374. setTargetBed(absPreheatHPBTemp);
  375. fanSpeed = 0;
  376. lcd_return_to_status();
  377. setWatch(); // heater sanity check timer
  378. }
  379. void lcd_preheat_pp()
  380. {
  381. setTargetHotend0(ppPreheatHotendTemp);
  382. setTargetBed(ppPreheatHPBTemp);
  383. fanSpeed = 0;
  384. lcd_return_to_status();
  385. setWatch(); // heater sanity check timer
  386. }
  387. void lcd_preheat_pet()
  388. {
  389. setTargetHotend0(petPreheatHotendTemp);
  390. setTargetBed(petPreheatHPBTemp);
  391. fanSpeed = 0;
  392. lcd_return_to_status();
  393. setWatch(); // heater sanity check timer
  394. }
  395. void lcd_preheat_hips()
  396. {
  397. setTargetHotend0(hipsPreheatHotendTemp);
  398. setTargetBed(hipsPreheatHPBTemp);
  399. fanSpeed = 0;
  400. lcd_return_to_status();
  401. setWatch(); // heater sanity check timer
  402. }
  403. void lcd_preheat_flex()
  404. {
  405. setTargetHotend0(flexPreheatHotendTemp);
  406. setTargetBed(flexPreheatHPBTemp);
  407. fanSpeed = 0;
  408. lcd_return_to_status();
  409. setWatch(); // heater sanity check timer
  410. }
  411. void lcd_cooldown()
  412. {
  413. setTargetHotend0(0);
  414. setTargetHotend1(0);
  415. setTargetHotend2(0);
  416. setTargetBed(0);
  417. fanSpeed = 0;
  418. lcd_return_to_status();
  419. }
  420. static void lcd_preheat_menu()
  421. {
  422. START_MENU();
  423. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  424. MENU_ITEM(function, PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  425. MENU_ITEM(function, PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  426. MENU_ITEM(function, PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  427. MENU_ITEM(function, PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  428. MENU_ITEM(function, PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  429. MENU_ITEM(function, PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  430. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  431. END_MENU();
  432. }
  433. static void lcd_support_menu()
  434. {
  435. START_MENU();
  436. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  437. MENU_ITEM(back, PSTR(MSG_FW_VERSION " - " FW_version), lcd_main_menu);
  438. MENU_ITEM(back, MSG_PRUSA3D, lcd_main_menu);
  439. MENU_ITEM(back, MSG_PRUSA3D_FORUM, lcd_main_menu);
  440. MENU_ITEM(back, MSG_PRUSA3D_HOWTO, lcd_main_menu);
  441. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  442. MENU_ITEM(back, PSTR(FILAMENT_SIZE), lcd_main_menu);
  443. MENU_ITEM(back, PSTR(ELECTRONICS),lcd_main_menu);
  444. MENU_ITEM(back, PSTR(NOZZLE_TYPE),lcd_main_menu);
  445. END_MENU();
  446. }
  447. void lcd_unLoadFilament()
  448. {
  449. if (degHotend0() > EXTRUDE_MINTEMP) {
  450. enquecommand_P(PSTR(UNLOAD_FILAMENT_0));
  451. enquecommand_P(PSTR(UNLOAD_FILAMENT_1));
  452. } else {
  453. lcd_implementation_clear();
  454. lcd.setCursor(0, 0);
  455. lcd_printPGM(MSG_ERROR);
  456. lcd.setCursor(0, 2);
  457. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  458. delay(2000);
  459. lcd_implementation_clear();
  460. }
  461. lcd_return_to_status();
  462. }
  463. void lcd_change_filament() {
  464. lcd_implementation_clear();
  465. lcd.setCursor(0, 1);
  466. lcd_printPGM(MSG_CHANGING_FILAMENT);
  467. }
  468. void lcd_wait_interact() {
  469. lcd_implementation_clear();
  470. lcd.setCursor(0, 1);
  471. lcd_printPGM(MSG_INSERT_FILAMENT);
  472. lcd.setCursor(0, 2);
  473. lcd_printPGM(MSG_PRESS);
  474. }
  475. void lcd_change_success() {
  476. lcd_implementation_clear();
  477. lcd.setCursor(0, 2);
  478. lcd_printPGM(MSG_CHANGE_SUCCESS);
  479. }
  480. void lcd_loading_color() {
  481. lcd_implementation_clear();
  482. lcd.setCursor(0, 0);
  483. lcd_printPGM(MSG_LOADING_COLOR);
  484. lcd.setCursor(0, 2);
  485. lcd_printPGM(MSG_PLEASE_WAIT);
  486. for (int i = 0; i < 20; i++) {
  487. lcd.setCursor(i, 3);
  488. lcd.print(".");
  489. for (int j = 0; j < 10 ; j++) {
  490. manage_heater();
  491. manage_inactivity(true);
  492. delay(85);
  493. }
  494. }
  495. }
  496. void lcd_loading_filament() {
  497. lcd_implementation_clear();
  498. lcd.setCursor(0, 0);
  499. lcd_printPGM(MSG_LOADING_FILAMENT);
  500. lcd.setCursor(0, 2);
  501. lcd_printPGM(MSG_PLEASE_WAIT);
  502. for (int i = 0; i < 20; i++) {
  503. lcd.setCursor(i, 3);
  504. lcd.print(".");
  505. for (int j = 0; j < 10 ; j++) {
  506. manage_heater();
  507. manage_inactivity(true);
  508. delay(110);
  509. }
  510. }
  511. }
  512. void lcd_alright() {
  513. int enc_dif = 0;
  514. int cursor_pos = 1;
  515. lcd_implementation_clear();
  516. lcd.setCursor(0, 0);
  517. lcd_printPGM(MSG_CORRECTLY);
  518. lcd.setCursor(1, 1);
  519. lcd_printPGM(MSG_YES);
  520. lcd.setCursor(1, 2);
  521. lcd_printPGM(MSG_NOT_LOADED);
  522. lcd.setCursor(1, 3);
  523. lcd_printPGM(MSG_NOT_COLOR);
  524. lcd.setCursor(0, 1);
  525. lcd.print(">");
  526. enc_dif = encoderDiff;
  527. while (lcd_change_fil_state == 0) {
  528. manage_heater();
  529. manage_inactivity(true);
  530. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  531. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  532. if (enc_dif > encoderDiff ) {
  533. cursor_pos --;
  534. }
  535. if (enc_dif < encoderDiff ) {
  536. cursor_pos ++;
  537. }
  538. if (cursor_pos > 3) {
  539. cursor_pos = 3;
  540. }
  541. if (cursor_pos < 1) {
  542. cursor_pos = 1;
  543. }
  544. lcd.setCursor(0, 1);
  545. lcd.print(" ");
  546. lcd.setCursor(0, 2);
  547. lcd.print(" ");
  548. lcd.setCursor(0, 3);
  549. lcd.print(" ");
  550. lcd.setCursor(0, cursor_pos);
  551. lcd.print(">");
  552. enc_dif = encoderDiff;
  553. delay(100);
  554. }
  555. }
  556. if (lcd_clicked()) {
  557. lcd_change_fil_state = cursor_pos;
  558. delay(500);
  559. }
  560. };
  561. lcd_implementation_clear();
  562. lcd_return_to_status();
  563. }
  564. void lcd_LoadFilament()
  565. {
  566. if (degHotend0() > EXTRUDE_MINTEMP) {
  567. enquecommand_P(PSTR(LOAD_FILAMENT_0));
  568. enquecommand_P(PSTR(LOAD_FILAMENT_1));
  569. enquecommand_P(PSTR(LOAD_FILAMENT_2));
  570. } else {
  571. lcd_implementation_clear();
  572. lcd.setCursor(0, 0);
  573. lcd_printPGM(MSG_ERROR);
  574. lcd.setCursor(0, 2);
  575. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  576. delay(2000);
  577. lcd_implementation_clear();
  578. }
  579. lcd_return_to_status();
  580. }
  581. static void _lcd_move(const char *name, int axis, int min, int max) {
  582. if (encoderPosition != 0) {
  583. refresh_cmd_timeout();
  584. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  585. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  586. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  587. encoderPosition = 0;
  588. #ifdef DELTA
  589. calculate_delta(current_position);
  590. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis] / 60, active_extruder);
  591. #else
  592. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis] / 60, active_extruder);
  593. #endif
  594. lcdDrawUpdate = 1;
  595. }
  596. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  597. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  598. }
  599. static void lcd_move_e()
  600. {
  601. if (encoderPosition != 0)
  602. {
  603. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  604. encoderPosition = 0;
  605. #ifdef DELTA
  606. calculate_delta(current_position);
  607. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS] / 60, active_extruder);
  608. #else
  609. 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);
  610. #endif
  611. lcdDrawUpdate = 1;
  612. }
  613. if (lcdDrawUpdate)
  614. {
  615. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  616. }
  617. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  618. }
  619. void EEPROM_save_B(int pos, int* value)
  620. {
  621. union Data data;
  622. data.value = *value;
  623. eeprom_write_byte((unsigned char*)pos, data.b[0]);
  624. eeprom_write_byte((unsigned char*)pos + 1, data.b[1]);
  625. }
  626. void EEPROM_read_B(int pos, int* value)
  627. {
  628. union Data data;
  629. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  630. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  631. *value = data.value;
  632. }
  633. static void lcd_move_x() {
  634. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  635. }
  636. static void lcd_move_y() {
  637. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  638. }
  639. static void lcd_move_z() {
  640. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  641. }
  642. static void _lcd_babystep(int axis, const char *msg) {
  643. if (encoderPosition != 0) {
  644. babystepsTodo[axis] += (int)encoderPosition;
  645. babystepMem[axis] += (int)encoderPosition;
  646. babystepMemMM[axis] = babystepMem[axis]/axis_steps_per_unit[Z_AXIS];
  647. encoderPosition = 0;
  648. lcdDrawUpdate = 1;
  649. }
  650. if (lcdDrawUpdate) lcd_implementation_drawedit_2(msg, ftostr13ns(babystepMemMM[axis]));
  651. if (LCD_CLICKED) lcd_goto_menu(lcd_main_menu);
  652. EEPROM_save_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  653. EEPROM_save_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  654. EEPROM_save_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  655. }
  656. static void lcd_babystep_x() {
  657. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  658. }
  659. static void lcd_babystep_y() {
  660. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  661. }
  662. static void lcd_babystep_z() {
  663. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  664. }
  665. void lcd_adjust_z() {
  666. int enc_dif = 0;
  667. int cursor_pos = 1;
  668. int fsm = 0;
  669. lcd_implementation_clear();
  670. lcd.setCursor(0, 0);
  671. lcd_printPGM(MSG_ADJUSTZ);
  672. lcd.setCursor(1, 1);
  673. lcd_printPGM(MSG_YES);
  674. lcd.setCursor(1, 2);
  675. lcd_printPGM(MSG_NO);
  676. lcd.setCursor(0, 1);
  677. lcd.print(">");
  678. enc_dif = encoderDiff;
  679. while (fsm == 0) {
  680. manage_heater();
  681. manage_inactivity(true);
  682. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  683. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  684. if (enc_dif > encoderDiff ) {
  685. cursor_pos --;
  686. }
  687. if (enc_dif < encoderDiff ) {
  688. cursor_pos ++;
  689. }
  690. if (cursor_pos > 2) {
  691. cursor_pos = 2;
  692. }
  693. if (cursor_pos < 1) {
  694. cursor_pos = 1;
  695. }
  696. lcd.setCursor(0, 1);
  697. lcd.print(" ");
  698. lcd.setCursor(0, 2);
  699. lcd.print(" ");
  700. lcd.setCursor(0, cursor_pos);
  701. lcd.print(">");
  702. enc_dif = encoderDiff;
  703. delay(100);
  704. }
  705. }
  706. if (lcd_clicked()) {
  707. fsm = cursor_pos;
  708. if (fsm == 1) {
  709. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  710. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  711. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  712. babystepsTodo[Z_AXIS] = babystepMem[2];
  713. } else {
  714. babystepMem[0] = 0;
  715. babystepMem[1] = 0;
  716. babystepMem[2] = 0;
  717. EEPROM_save_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  718. EEPROM_save_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  719. EEPROM_save_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  720. }
  721. delay(500);
  722. }
  723. };
  724. lcd_implementation_clear();
  725. lcd_return_to_status();
  726. }
  727. void lcd_pick_babystep(){
  728. int enc_dif = 0;
  729. int cursor_pos = 1;
  730. int fsm = 0;
  731. lcd_implementation_clear();
  732. lcd.setCursor(0, 0);
  733. lcd_printPGM(MSG_PICK_Z);
  734. lcd.setCursor(3, 2);
  735. lcd.print("1");
  736. lcd.setCursor(3, 3);
  737. lcd.print("2");
  738. lcd.setCursor(12, 2);
  739. lcd.print("3");
  740. lcd.setCursor(12, 3);
  741. lcd.print("4");
  742. lcd.setCursor(1, 2);
  743. lcd.print(">");
  744. enc_dif = encoderDiff;
  745. while (fsm == 0) {
  746. manage_heater();
  747. manage_inactivity(true);
  748. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  749. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  750. if (enc_dif > encoderDiff ) {
  751. cursor_pos --;
  752. }
  753. if (enc_dif < encoderDiff ) {
  754. cursor_pos ++;
  755. }
  756. if (cursor_pos > 4) {
  757. cursor_pos = 4;
  758. }
  759. if (cursor_pos < 1) {
  760. cursor_pos = 1;
  761. }
  762. lcd.setCursor(1, 2);
  763. lcd.print(" ");
  764. lcd.setCursor(1, 3);
  765. lcd.print(" ");
  766. lcd.setCursor(10, 2);
  767. lcd.print(" ");
  768. lcd.setCursor(10, 3);
  769. lcd.print(" ");
  770. if (cursor_pos < 3) {
  771. lcd.setCursor(1, cursor_pos+1);
  772. lcd.print(">");
  773. }else{
  774. lcd.setCursor(10, cursor_pos-1);
  775. lcd.print(">");
  776. }
  777. enc_dif = encoderDiff;
  778. delay(100);
  779. }
  780. }
  781. if (lcd_clicked()) {
  782. fsm = cursor_pos;
  783. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babystepMem[2]);
  784. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babystepMem[2]);
  785. eeprom_write_byte((unsigned char*)EEPROM_BABYSTEP_Z_SET, 0x01);
  786. delay(500);
  787. }
  788. };
  789. lcd_implementation_clear();
  790. lcd_return_to_status();
  791. }
  792. void lcd_move_menu_axis()
  793. {
  794. START_MENU();
  795. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  796. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  797. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  798. if (move_menu_scale < 10.0)
  799. {
  800. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  801. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  802. }
  803. END_MENU();
  804. }
  805. static void lcd_move_menu_1mm()
  806. {
  807. move_menu_scale = 1.0;
  808. lcd_move_menu_axis();
  809. }
  810. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  811. {
  812. do
  813. {
  814. eeprom_write_byte((unsigned char*)pos, *value);
  815. pos++;
  816. value++;
  817. } while (--size);
  818. }
  819. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  820. {
  821. do
  822. {
  823. *value = eeprom_read_byte((unsigned char*)pos);
  824. pos++;
  825. value++;
  826. } while (--size);
  827. }
  828. static void lcd_silent_mode_set() {
  829. SilentModeMenu = !SilentModeMenu;
  830. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  831. digipot_init();
  832. lcd_goto_menu(lcd_settings_menu, 7);
  833. }
  834. static void lcd_set_lang(unsigned char lang) {
  835. lang_selected = lang;
  836. firstrun = 1;
  837. eeprom_write_byte((unsigned char *)EEPROM_LANG, lang);/*langsel=0;*/if (langsel == 1)langsel = 2;
  838. }
  839. void lcd_force_language_selection() {
  840. eeprom_write_byte((unsigned char *)EEPROM_LANG, 255);
  841. }
  842. static void lcd_language_menu()
  843. {
  844. START_MENU();
  845. if (!langsel) {
  846. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  847. }
  848. if (langsel == 2) {
  849. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  850. }
  851. for (int i=0;i<LANG_NUM;i++){
  852. MENU_ITEM(setlang, MSG_ALL[i][LANGUAGE_NAME], i);
  853. }
  854. //MENU_ITEM(setlang, MSG_ALL[1][LANGUAGE_NAME], 1);
  855. END_MENU();
  856. }
  857. static void lcd_settings_menu()
  858. {
  859. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  860. START_MENU();
  861. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  862. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  863. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  864. #ifndef MESH_BED_LEVELING
  865. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  866. #else
  867. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G80"));
  868. #endif
  869. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  870. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  871. if (SilentModeMenu == 0) {
  872. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  873. } else {
  874. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  875. }
  876. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  877. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  878. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  879. babystepMemMM[2] = babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  880. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  881. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  882. END_MENU();
  883. }
  884. /*
  885. void lcd_mylang_top(int hlaska) {
  886. lcd.setCursor(0,0);
  887. lcd.print(" ");
  888. lcd.setCursor(0,0);
  889. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  890. }
  891. void lcd_mylang_drawmenu(int cursor) {
  892. int first = 0;
  893. if (cursor>2) first = cursor-2;
  894. if (cursor==LANG_NUM) first = LANG_NUM-3;
  895. lcd.setCursor(0, 1);
  896. lcd.print(" ");
  897. lcd.setCursor(1, 1);
  898. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  899. lcd.setCursor(0, 2);
  900. lcd.print(" ");
  901. lcd.setCursor(1, 2);
  902. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  903. lcd.setCursor(0, 3);
  904. lcd.print(" ");
  905. lcd.setCursor(1, 3);
  906. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  907. if (cursor==1) lcd.setCursor(0, 1);
  908. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  909. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  910. lcd.print(">");
  911. if (cursor<LANG_NUM-1) {
  912. lcd.setCursor(19,3);
  913. lcd.print("\x01");
  914. }
  915. if (cursor>2) {
  916. lcd.setCursor(19,1);
  917. lcd.print("^");
  918. }
  919. }
  920. */
  921. void lcd_mylang_drawmenu(int cursor) {
  922. int first = 0;
  923. if (cursor>3) first = cursor-3;
  924. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  925. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  926. lcd.setCursor(0, 0);
  927. lcd.print(" ");
  928. lcd.setCursor(1, 0);
  929. lcd_printPGM(MSG_ALL[first+0][LANGUAGE_NAME]);
  930. lcd.setCursor(0, 1);
  931. lcd.print(" ");
  932. lcd.setCursor(1, 1);
  933. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  934. lcd.setCursor(0, 2);
  935. lcd.print(" ");
  936. if (LANG_NUM > 2){
  937. lcd.setCursor(1, 2);
  938. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  939. }
  940. lcd.setCursor(0, 3);
  941. lcd.print(" ");
  942. if (LANG_NUM>3) {
  943. lcd.setCursor(1, 3);
  944. lcd_printPGM(MSG_ALL[first+3][LANGUAGE_NAME]);
  945. }
  946. if (cursor==1) lcd.setCursor(0, 0);
  947. if (cursor==2) lcd.setCursor(0, 1);
  948. if (cursor>2) lcd.setCursor(0, 2);
  949. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  950. lcd.print(">");
  951. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  952. lcd.setCursor(19,3);
  953. lcd.print("\x01");
  954. }
  955. if (cursor>3 && LANG_NUM>4) {
  956. lcd.setCursor(19,0);
  957. lcd.print("^");
  958. }
  959. }
  960. void lcd_set_custom_characters_arrows();
  961. void lcd_set_custom_characters_degree();
  962. void lcd_mylang_drawcursor(int cursor) {
  963. if (cursor==1) lcd.setCursor(0, 1);
  964. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  965. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  966. lcd.print(">");
  967. }
  968. void lcd_mylang() {
  969. int enc_dif = 0;
  970. int cursor_pos = 1;
  971. lang_selected=255;
  972. int hlaska=1;
  973. int counter=0;
  974. lcd_set_custom_characters_arrows();
  975. lcd_implementation_clear();
  976. //lcd_mylang_top(hlaska);
  977. lcd_mylang_drawmenu(cursor_pos);
  978. enc_dif = encoderDiff;
  979. while ( (lang_selected == 255) && (MYSERIAL.available() < 2) ) {
  980. manage_heater();
  981. manage_inactivity(true);
  982. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  983. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  984. if (enc_dif > encoderDiff ) {
  985. cursor_pos --;
  986. }
  987. if (enc_dif < encoderDiff ) {
  988. cursor_pos ++;
  989. }
  990. if (cursor_pos > LANG_NUM) {
  991. cursor_pos = LANG_NUM;
  992. }
  993. if (cursor_pos < 1) {
  994. cursor_pos = 1;
  995. }
  996. lcd_mylang_drawmenu(cursor_pos);
  997. enc_dif = encoderDiff;
  998. delay(100);
  999. //}
  1000. } else delay(20);
  1001. if (lcd_clicked()) {
  1002. lcd_set_lang(cursor_pos-1);
  1003. delay(500);
  1004. }
  1005. /*
  1006. if (++counter == 80) {
  1007. hlaska++;
  1008. if(hlaska>LANG_NUM) hlaska=1;
  1009. lcd_mylang_top(hlaska);
  1010. lcd_mylang_drawcursor(cursor_pos);
  1011. counter=0;
  1012. }
  1013. */
  1014. };
  1015. if(MYSERIAL.available() > 1){
  1016. lang_selected = 0;
  1017. firstrun = 0;
  1018. }
  1019. lcd_set_custom_characters_degree();
  1020. lcd_implementation_clear();
  1021. lcd_return_to_status();
  1022. }
  1023. static void lcd_main_menu()
  1024. {
  1025. SDscrool = 0;
  1026. /*
  1027. if (langsel == 1)
  1028. {
  1029. lcd_goto_menu(lcd_language_menu);
  1030. }
  1031. */
  1032. START_MENU();
  1033. // Majkl superawesome menu
  1034. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1035. if (IS_SD_PRINTING && (current_position[Z_AXIS] < 0.5) )
  1036. {
  1037. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  1038. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  1039. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  1040. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1041. }
  1042. if (movesplanned() || IS_SD_PRINTING)
  1043. {
  1044. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  1045. } else {
  1046. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  1047. }
  1048. #ifdef SDSUPPORT
  1049. if (card.cardOK)
  1050. {
  1051. if (card.isFileOpen())
  1052. {
  1053. if (card.sdprinting)
  1054. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  1055. else
  1056. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  1057. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  1058. } else {
  1059. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  1060. #if SDCARDDETECT < 1
  1061. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  1062. #endif
  1063. }
  1064. } else {
  1065. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  1066. #if SDCARDDETECT < 1
  1067. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  1068. #endif
  1069. }
  1070. #endif
  1071. if (IS_SD_PRINTING)
  1072. {
  1073. } else {
  1074. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  1075. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  1076. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  1077. }
  1078. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  1079. END_MENU();
  1080. }
  1081. #ifdef SDSUPPORT
  1082. static void lcd_autostart_sd()
  1083. {
  1084. card.lastnr = 0;
  1085. card.setroot();
  1086. card.checkautostart(true);
  1087. }
  1088. #endif
  1089. static void lcd_silent_mode_set_tune() {
  1090. SilentModeMenu = !SilentModeMenu;
  1091. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1092. digipot_init();
  1093. lcd_goto_menu(lcd_tune_menu, 9);
  1094. }
  1095. static void lcd_tune_menu()
  1096. {
  1097. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1098. START_MENU();
  1099. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  1100. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  1101. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  1102. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  1103. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  1104. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  1105. #ifdef FILAMENTCHANGEENABLE
  1106. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));//7
  1107. #endif
  1108. if (SilentModeMenu == 0) {
  1109. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  1110. } else {
  1111. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  1112. }
  1113. END_MENU();
  1114. }
  1115. static void lcd_move_menu_01mm()
  1116. {
  1117. move_menu_scale = 0.1;
  1118. lcd_move_menu_axis();
  1119. }
  1120. static void lcd_control_temperature_menu()
  1121. {
  1122. #ifdef PIDTEMP
  1123. // set up temp variables - undo the default scaling
  1124. raw_Ki = unscalePID_i(Ki);
  1125. raw_Kd = unscalePID_d(Kd);
  1126. #endif
  1127. START_MENU();
  1128. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1129. //MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1130. #if TEMP_SENSOR_0 != 0
  1131. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  1132. #endif
  1133. #if TEMP_SENSOR_1 != 0
  1134. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  1135. #endif
  1136. #if TEMP_SENSOR_2 != 0
  1137. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  1138. #endif
  1139. #if TEMP_SENSOR_BED != 0
  1140. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  1141. #endif
  1142. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  1143. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  1144. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  1145. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  1146. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  1147. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  1148. #endif
  1149. END_MENU();
  1150. }
  1151. #if SDCARDDETECT == -1
  1152. static void lcd_sd_refresh()
  1153. {
  1154. card.initsd();
  1155. currentMenuViewOffset = 0;
  1156. }
  1157. #endif
  1158. static void lcd_sd_updir()
  1159. {
  1160. SDscrool = 0;
  1161. card.updir();
  1162. currentMenuViewOffset = 0;
  1163. }
  1164. void lcd_sdcard_menu()
  1165. {
  1166. int tempScrool = 0;
  1167. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  1168. //delay(100);
  1169. return; // nothing to do (so don't thrash the SD card)
  1170. uint16_t fileCnt = card.getnrfilenames();
  1171. START_MENU();
  1172. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1173. card.getWorkDirName();
  1174. if (card.filename[0] == '/')
  1175. {
  1176. #if SDCARDDETECT == -1
  1177. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1178. #endif
  1179. } else {
  1180. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1181. }
  1182. for (uint16_t i = 0; i < fileCnt; i++)
  1183. {
  1184. if (_menuItemNr == _lineNr)
  1185. {
  1186. #ifndef SDCARD_RATHERRECENTFIRST
  1187. card.getfilename(i);
  1188. #else
  1189. card.getfilename(fileCnt - 1 - i);
  1190. #endif
  1191. if (card.filenameIsDir)
  1192. {
  1193. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1194. } else {
  1195. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1196. }
  1197. } else {
  1198. MENU_ITEM_DUMMY();
  1199. }
  1200. }
  1201. END_MENU();
  1202. }
  1203. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1204. void menu_edit_ ## _name () \
  1205. { \
  1206. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1207. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1208. if (lcdDrawUpdate) \
  1209. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1210. if (LCD_CLICKED) \
  1211. { \
  1212. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1213. lcd_goto_menu(prevMenu, prevEncoderPosition); \
  1214. } \
  1215. } \
  1216. void menu_edit_callback_ ## _name () { \
  1217. menu_edit_ ## _name (); \
  1218. if (LCD_CLICKED) (*callbackFunc)(); \
  1219. } \
  1220. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  1221. { \
  1222. prevMenu = currentMenu; \
  1223. prevEncoderPosition = encoderPosition; \
  1224. \
  1225. lcdDrawUpdate = 2; \
  1226. currentMenu = menu_edit_ ## _name; \
  1227. \
  1228. editLabel = pstr; \
  1229. editValue = ptr; \
  1230. minEditValue = minValue * scale; \
  1231. maxEditValue = maxValue * scale - minEditValue; \
  1232. encoderPosition = (*ptr) * scale - minEditValue; \
  1233. }\
  1234. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  1235. { \
  1236. prevMenu = currentMenu; \
  1237. prevEncoderPosition = encoderPosition; \
  1238. \
  1239. lcdDrawUpdate = 2; \
  1240. currentMenu = menu_edit_callback_ ## _name; \
  1241. \
  1242. editLabel = pstr; \
  1243. editValue = ptr; \
  1244. minEditValue = minValue * scale; \
  1245. maxEditValue = maxValue * scale - minEditValue; \
  1246. encoderPosition = (*ptr) * scale - minEditValue; \
  1247. callbackFunc = callback;\
  1248. }
  1249. menu_edit_type(int, int3, itostr3, 1)
  1250. menu_edit_type(float, float3, ftostr3, 1)
  1251. menu_edit_type(float, float32, ftostr32, 100)
  1252. menu_edit_type(float, float43, ftostr43, 1000)
  1253. menu_edit_type(float, float5, ftostr5, 0.01)
  1254. menu_edit_type(float, float51, ftostr51, 10)
  1255. menu_edit_type(float, float52, ftostr52, 100)
  1256. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1257. /** End of menus **/
  1258. static void lcd_quick_feedback()
  1259. {
  1260. lcdDrawUpdate = 2;
  1261. blocking_enc = millis() + 500;
  1262. lcd_implementation_quick_feedback();
  1263. }
  1264. /** Menu action functions **/
  1265. static void menu_action_back(menuFunc_t data) {
  1266. lcd_goto_menu(data);
  1267. }
  1268. static void menu_action_submenu(menuFunc_t data) {
  1269. lcd_goto_menu(data);
  1270. }
  1271. static void menu_action_gcode(const char* pgcode) {
  1272. enquecommand_P(pgcode);
  1273. }
  1274. static void menu_action_setlang(unsigned char lang) {
  1275. lcd_set_lang(lang);
  1276. }
  1277. static void menu_action_function(menuFunc_t data) {
  1278. (*data)();
  1279. }
  1280. static void menu_action_sdfile(const char* filename, char* longFilename)
  1281. {
  1282. char cmd[30];
  1283. char* c;
  1284. sprintf_P(cmd, PSTR("M23 %s"), filename);
  1285. for (c = &cmd[4]; *c; c++)
  1286. *c = tolower(*c);
  1287. enquecommand(cmd);
  1288. enquecommand_P(PSTR("M24"));
  1289. lcd_return_to_status();
  1290. }
  1291. static void menu_action_sddirectory(const char* filename, char* longFilename)
  1292. {
  1293. card.chdir(filename);
  1294. encoderPosition = 0;
  1295. }
  1296. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  1297. {
  1298. *ptr = !(*ptr);
  1299. }
  1300. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  1301. {
  1302. menu_action_setting_edit_bool(pstr, ptr);
  1303. (*callback)();
  1304. }
  1305. #endif//ULTIPANEL
  1306. /** LCD API **/
  1307. void lcd_init()
  1308. {
  1309. lcd_implementation_init();
  1310. #ifdef NEWPANEL
  1311. SET_INPUT(BTN_EN1);
  1312. SET_INPUT(BTN_EN2);
  1313. WRITE(BTN_EN1, HIGH);
  1314. WRITE(BTN_EN2, HIGH);
  1315. #if BTN_ENC > 0
  1316. SET_INPUT(BTN_ENC);
  1317. WRITE(BTN_ENC, HIGH);
  1318. #endif
  1319. #ifdef REPRAPWORLD_KEYPAD
  1320. pinMode(SHIFT_CLK, OUTPUT);
  1321. pinMode(SHIFT_LD, OUTPUT);
  1322. pinMode(SHIFT_OUT, INPUT);
  1323. WRITE(SHIFT_OUT, HIGH);
  1324. WRITE(SHIFT_LD, HIGH);
  1325. #endif
  1326. #else // Not NEWPANEL
  1327. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  1328. pinMode (SR_DATA_PIN, OUTPUT);
  1329. pinMode (SR_CLK_PIN, OUTPUT);
  1330. #elif defined(SHIFT_CLK)
  1331. pinMode(SHIFT_CLK, OUTPUT);
  1332. pinMode(SHIFT_LD, OUTPUT);
  1333. pinMode(SHIFT_EN, OUTPUT);
  1334. pinMode(SHIFT_OUT, INPUT);
  1335. WRITE(SHIFT_OUT, HIGH);
  1336. WRITE(SHIFT_LD, HIGH);
  1337. WRITE(SHIFT_EN, LOW);
  1338. #else
  1339. #ifdef ULTIPANEL
  1340. #error ULTIPANEL requires an encoder
  1341. #endif
  1342. #endif // SR_LCD_2W_NL
  1343. #endif//!NEWPANEL
  1344. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  1345. pinMode(SDCARDDETECT, INPUT);
  1346. WRITE(SDCARDDETECT, HIGH);
  1347. lcd_oldcardstatus = IS_SD_INSERTED;
  1348. #endif//(SDCARDDETECT > 0)
  1349. #ifdef LCD_HAS_SLOW_BUTTONS
  1350. slow_buttons = 0;
  1351. #endif
  1352. lcd_buttons_update();
  1353. #ifdef ULTIPANEL
  1354. encoderDiff = 0;
  1355. #endif
  1356. }
  1357. //#include <avr/pgmspace.h>
  1358. void lcd_update()
  1359. {
  1360. static unsigned long timeoutToStatus = 0;
  1361. #ifdef LCD_HAS_SLOW_BUTTONS
  1362. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1363. #endif
  1364. lcd_buttons_update();
  1365. #if (SDCARDDETECT > 0)
  1366. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  1367. {
  1368. lcdDrawUpdate = 2;
  1369. lcd_oldcardstatus = IS_SD_INSERTED;
  1370. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1371. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1372. currentMenu == lcd_status_screen
  1373. #endif
  1374. );
  1375. if (lcd_oldcardstatus)
  1376. {
  1377. card.initsd();
  1378. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  1379. }
  1380. else
  1381. {
  1382. card.release();
  1383. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  1384. }
  1385. }
  1386. #endif//CARDINSERTED
  1387. if (lcd_next_update_millis < millis())
  1388. {
  1389. #ifdef ULTIPANEL
  1390. #ifdef REPRAPWORLD_KEYPAD
  1391. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  1392. reprapworld_keypad_move_z_up();
  1393. }
  1394. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  1395. reprapworld_keypad_move_z_down();
  1396. }
  1397. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  1398. reprapworld_keypad_move_x_left();
  1399. }
  1400. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  1401. reprapworld_keypad_move_x_right();
  1402. }
  1403. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  1404. reprapworld_keypad_move_y_down();
  1405. }
  1406. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  1407. reprapworld_keypad_move_y_up();
  1408. }
  1409. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  1410. reprapworld_keypad_move_home();
  1411. }
  1412. #endif
  1413. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  1414. {
  1415. lcdDrawUpdate = 1;
  1416. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  1417. encoderDiff = 0;
  1418. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1419. }
  1420. if (LCD_CLICKED)
  1421. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1422. #endif//ULTIPANEL
  1423. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  1424. blink++; // Variable for fan animation and alive dot
  1425. u8g.firstPage();
  1426. do
  1427. {
  1428. u8g.setFont(u8g_font_6x10_marlin);
  1429. u8g.setPrintPos(125, 0);
  1430. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1431. u8g.drawPixel(127, 63); // draw alive dot
  1432. u8g.setColorIndex(1); // black on white
  1433. (*currentMenu)();
  1434. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  1435. } while ( u8g.nextPage() );
  1436. #else
  1437. (*currentMenu)();
  1438. #endif
  1439. #ifdef LCD_HAS_STATUS_INDICATORS
  1440. lcd_implementation_update_indicators();
  1441. #endif
  1442. #ifdef ULTIPANEL
  1443. if (timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  1444. {
  1445. lcd_return_to_status();
  1446. lcdDrawUpdate = 2;
  1447. }
  1448. #endif//ULTIPANEL
  1449. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1450. if (lcdDrawUpdate) lcdDrawUpdate--;
  1451. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  1452. }
  1453. }
  1454. void lcd_ignore_click(bool b)
  1455. {
  1456. ignore_click = b;
  1457. wait_for_unclick = false;
  1458. }
  1459. void lcd_finishstatus() {
  1460. int len = strlen(lcd_status_message);
  1461. if (len > 0) {
  1462. while (len < LCD_WIDTH) {
  1463. lcd_status_message[len++] = ' ';
  1464. }
  1465. }
  1466. lcd_status_message[LCD_WIDTH] = '\0';
  1467. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1468. #if PROGRESS_MSG_EXPIRE > 0
  1469. messageTick =
  1470. #endif
  1471. progressBarTick = millis();
  1472. #endif
  1473. lcdDrawUpdate = 2;
  1474. #ifdef FILAMENT_LCD_DISPLAY
  1475. message_millis = millis(); //get status message to show up for a while
  1476. #endif
  1477. }
  1478. void lcd_setstatus(const char* message)
  1479. {
  1480. if (lcd_status_message_level > 0)
  1481. return;
  1482. strncpy(lcd_status_message, message, LCD_WIDTH);
  1483. lcd_finishstatus();
  1484. }
  1485. void lcd_setstatuspgm(const char* message)
  1486. {
  1487. if (lcd_status_message_level > 0)
  1488. return;
  1489. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  1490. lcd_finishstatus();
  1491. }
  1492. void lcd_setalertstatuspgm(const char* message)
  1493. {
  1494. lcd_setstatuspgm(message);
  1495. lcd_status_message_level = 1;
  1496. #ifdef ULTIPANEL
  1497. lcd_return_to_status();
  1498. #endif//ULTIPANEL
  1499. }
  1500. void lcd_reset_alert_level()
  1501. {
  1502. lcd_status_message_level = 0;
  1503. }
  1504. #ifdef DOGLCD
  1505. void lcd_setcontrast(uint8_t value)
  1506. {
  1507. lcd_contrast = value & 63;
  1508. u8g.setContrast(lcd_contrast);
  1509. }
  1510. #endif
  1511. #ifdef ULTIPANEL
  1512. /* Warning: This function is called from interrupt context */
  1513. void lcd_buttons_update()
  1514. {
  1515. #ifdef NEWPANEL
  1516. uint8_t newbutton = 0;
  1517. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  1518. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  1519. #if BTN_ENC > 0
  1520. if ((blocking_enc < millis()) && (READ(BTN_ENC) == 0))
  1521. newbutton |= EN_C;
  1522. #endif
  1523. buttons = newbutton;
  1524. #ifdef LCD_HAS_SLOW_BUTTONS
  1525. buttons |= slow_buttons;
  1526. #endif
  1527. #ifdef REPRAPWORLD_KEYPAD
  1528. // for the reprapworld_keypad
  1529. uint8_t newbutton_reprapworld_keypad = 0;
  1530. WRITE(SHIFT_LD, LOW);
  1531. WRITE(SHIFT_LD, HIGH);
  1532. for (int8_t i = 0; i < 8; i++) {
  1533. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  1534. if (READ(SHIFT_OUT))
  1535. newbutton_reprapworld_keypad |= (1 << 7);
  1536. WRITE(SHIFT_CLK, HIGH);
  1537. WRITE(SHIFT_CLK, LOW);
  1538. }
  1539. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1540. #endif
  1541. #else //read it from the shift register
  1542. uint8_t newbutton = 0;
  1543. WRITE(SHIFT_LD, LOW);
  1544. WRITE(SHIFT_LD, HIGH);
  1545. unsigned char tmp_buttons = 0;
  1546. for (int8_t i = 0; i < 8; i++)
  1547. {
  1548. newbutton = newbutton >> 1;
  1549. if (READ(SHIFT_OUT))
  1550. newbutton |= (1 << 7);
  1551. WRITE(SHIFT_CLK, HIGH);
  1552. WRITE(SHIFT_CLK, LOW);
  1553. }
  1554. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  1555. #endif//!NEWPANEL
  1556. //manage encoder rotation
  1557. uint8_t enc = 0;
  1558. if (buttons & EN_A) enc |= B01;
  1559. if (buttons & EN_B) enc |= B10;
  1560. if (enc != lastEncoderBits)
  1561. {
  1562. switch (enc)
  1563. {
  1564. case encrot0:
  1565. if (lastEncoderBits == encrot3)
  1566. encoderDiff++;
  1567. else if (lastEncoderBits == encrot1)
  1568. encoderDiff--;
  1569. break;
  1570. case encrot1:
  1571. if (lastEncoderBits == encrot0)
  1572. encoderDiff++;
  1573. else if (lastEncoderBits == encrot2)
  1574. encoderDiff--;
  1575. break;
  1576. case encrot2:
  1577. if (lastEncoderBits == encrot1)
  1578. encoderDiff++;
  1579. else if (lastEncoderBits == encrot3)
  1580. encoderDiff--;
  1581. break;
  1582. case encrot3:
  1583. if (lastEncoderBits == encrot2)
  1584. encoderDiff++;
  1585. else if (lastEncoderBits == encrot0)
  1586. encoderDiff--;
  1587. break;
  1588. }
  1589. }
  1590. lastEncoderBits = enc;
  1591. }
  1592. bool lcd_detected(void)
  1593. {
  1594. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  1595. return lcd.LcdDetected() == 1;
  1596. #else
  1597. return true;
  1598. #endif
  1599. }
  1600. void lcd_buzz(long duration, uint16_t freq)
  1601. {
  1602. #ifdef LCD_USE_I2C_BUZZER
  1603. lcd.buzz(duration, freq);
  1604. #endif
  1605. }
  1606. bool lcd_clicked()
  1607. {
  1608. return LCD_CLICKED;
  1609. }
  1610. #endif//ULTIPANEL
  1611. /********************************/
  1612. /** Float conversion utilities **/
  1613. /********************************/
  1614. // convert float to string with +123.4 format
  1615. char conv[8];
  1616. char *ftostr3(const float &x)
  1617. {
  1618. return itostr3((int)x);
  1619. }
  1620. char *itostr2(const uint8_t &x)
  1621. {
  1622. //sprintf(conv,"%5.1f",x);
  1623. int xx = x;
  1624. conv[0] = (xx / 10) % 10 + '0';
  1625. conv[1] = (xx) % 10 + '0';
  1626. conv[2] = 0;
  1627. return conv;
  1628. }
  1629. // Convert float to string with 123.4 format, dropping sign
  1630. char *ftostr31(const float &x)
  1631. {
  1632. int xx = x * 10;
  1633. conv[0] = (xx >= 0) ? '+' : '-';
  1634. xx = abs(xx);
  1635. conv[1] = (xx / 1000) % 10 + '0';
  1636. conv[2] = (xx / 100) % 10 + '0';
  1637. conv[3] = (xx / 10) % 10 + '0';
  1638. conv[4] = '.';
  1639. conv[5] = (xx) % 10 + '0';
  1640. conv[6] = 0;
  1641. return conv;
  1642. }
  1643. // Convert float to string with 123.4 format
  1644. char *ftostr31ns(const float &x)
  1645. {
  1646. int xx = x * 10;
  1647. //conv[0]=(xx>=0)?'+':'-';
  1648. xx = abs(xx);
  1649. conv[0] = (xx / 1000) % 10 + '0';
  1650. conv[1] = (xx / 100) % 10 + '0';
  1651. conv[2] = (xx / 10) % 10 + '0';
  1652. conv[3] = '.';
  1653. conv[4] = (xx) % 10 + '0';
  1654. conv[5] = 0;
  1655. return conv;
  1656. }
  1657. char *ftostr32(const float &x)
  1658. {
  1659. long xx = x * 100;
  1660. if (xx >= 0)
  1661. conv[0] = (xx / 10000) % 10 + '0';
  1662. else
  1663. conv[0] = '-';
  1664. xx = abs(xx);
  1665. conv[1] = (xx / 1000) % 10 + '0';
  1666. conv[2] = (xx / 100) % 10 + '0';
  1667. conv[3] = '.';
  1668. conv[4] = (xx / 10) % 10 + '0';
  1669. conv[5] = (xx) % 10 + '0';
  1670. conv[6] = 0;
  1671. return conv;
  1672. }
  1673. // Convert float to string with 1.234 format
  1674. char *ftostr43(const float &x)
  1675. {
  1676. long xx = x * 1000;
  1677. if (xx >= 0)
  1678. conv[0] = (xx / 1000) % 10 + '0';
  1679. else
  1680. conv[0] = '-';
  1681. xx = abs(xx);
  1682. conv[1] = '.';
  1683. conv[2] = (xx / 100) % 10 + '0';
  1684. conv[3] = (xx / 10) % 10 + '0';
  1685. conv[4] = (xx) % 10 + '0';
  1686. conv[5] = 0;
  1687. return conv;
  1688. }
  1689. //Float to string with 1.23 format
  1690. char *ftostr12ns(const float &x)
  1691. {
  1692. long xx = x * 100;
  1693. xx = abs(xx);
  1694. conv[0] = (xx / 100) % 10 + '0';
  1695. conv[1] = '.';
  1696. conv[2] = (xx / 10) % 10 + '0';
  1697. conv[3] = (xx) % 10 + '0';
  1698. conv[4] = 0;
  1699. return conv;
  1700. }
  1701. //Float to string with 1.234 format
  1702. char *ftostr13ns(const float &x)
  1703. {
  1704. long xx = x * 1000;
  1705. if (xx >= 0)
  1706. conv[0] = ' ';
  1707. else
  1708. conv[0] = '-';
  1709. xx = abs(xx);
  1710. conv[1] = (xx / 1000) % 10 + '0';
  1711. conv[2] = '.';
  1712. conv[3] = (xx / 100) % 10 + '0';
  1713. conv[4] = (xx / 10) % 10 + '0';
  1714. conv[5] = (xx) % 10 + '0';
  1715. conv[6] = 0;
  1716. return conv;
  1717. }
  1718. // convert float to space-padded string with -_23.4_ format
  1719. char *ftostr32sp(const float &x) {
  1720. long xx = abs(x * 100);
  1721. uint8_t dig;
  1722. if (x < 0) { // negative val = -_0
  1723. conv[0] = '-';
  1724. dig = (xx / 1000) % 10;
  1725. conv[1] = dig ? '0' + dig : ' ';
  1726. }
  1727. else { // positive val = __0
  1728. dig = (xx / 10000) % 10;
  1729. if (dig) {
  1730. conv[0] = '0' + dig;
  1731. conv[1] = '0' + (xx / 1000) % 10;
  1732. }
  1733. else {
  1734. conv[0] = ' ';
  1735. dig = (xx / 1000) % 10;
  1736. conv[1] = dig ? '0' + dig : ' ';
  1737. }
  1738. }
  1739. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1740. dig = xx % 10;
  1741. if (dig) { // 2 decimal places
  1742. conv[5] = '0' + dig;
  1743. conv[4] = '0' + (xx / 10) % 10;
  1744. conv[3] = '.';
  1745. }
  1746. else { // 1 or 0 decimal place
  1747. dig = (xx / 10) % 10;
  1748. if (dig) {
  1749. conv[4] = '0' + dig;
  1750. conv[3] = '.';
  1751. }
  1752. else {
  1753. conv[3] = conv[4] = ' ';
  1754. }
  1755. conv[5] = ' ';
  1756. }
  1757. conv[6] = '\0';
  1758. return conv;
  1759. }
  1760. char *itostr31(const int &xx)
  1761. {
  1762. conv[0] = (xx >= 0) ? '+' : '-';
  1763. conv[1] = (xx / 1000) % 10 + '0';
  1764. conv[2] = (xx / 100) % 10 + '0';
  1765. conv[3] = (xx / 10) % 10 + '0';
  1766. conv[4] = '.';
  1767. conv[5] = (xx) % 10 + '0';
  1768. conv[6] = 0;
  1769. return conv;
  1770. }
  1771. // Convert int to rj string with 123 or -12 format
  1772. char *itostr3(const int &x)
  1773. {
  1774. int xx = x;
  1775. if (xx < 0) {
  1776. conv[0] = '-';
  1777. xx = -xx;
  1778. } else if (xx >= 100)
  1779. conv[0] = (xx / 100) % 10 + '0';
  1780. else
  1781. conv[0] = ' ';
  1782. if (xx >= 10)
  1783. conv[1] = (xx / 10) % 10 + '0';
  1784. else
  1785. conv[1] = ' ';
  1786. conv[2] = (xx) % 10 + '0';
  1787. conv[3] = 0;
  1788. return conv;
  1789. }
  1790. // Convert int to lj string with 123 format
  1791. char *itostr3left(const int &xx)
  1792. {
  1793. if (xx >= 100)
  1794. {
  1795. conv[0] = (xx / 100) % 10 + '0';
  1796. conv[1] = (xx / 10) % 10 + '0';
  1797. conv[2] = (xx) % 10 + '0';
  1798. conv[3] = 0;
  1799. }
  1800. else if (xx >= 10)
  1801. {
  1802. conv[0] = (xx / 10) % 10 + '0';
  1803. conv[1] = (xx) % 10 + '0';
  1804. conv[2] = 0;
  1805. }
  1806. else
  1807. {
  1808. conv[0] = (xx) % 10 + '0';
  1809. conv[1] = 0;
  1810. }
  1811. return conv;
  1812. }
  1813. // Convert int to rj string with 1234 format
  1814. char *itostr4(const int &xx) {
  1815. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1816. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1817. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1818. conv[3] = xx % 10 + '0';
  1819. conv[4] = 0;
  1820. return conv;
  1821. }
  1822. // Convert float to rj string with 12345 format
  1823. char *ftostr5(const float &x) {
  1824. long xx = abs(x);
  1825. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  1826. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1827. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1828. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1829. conv[4] = xx % 10 + '0';
  1830. conv[5] = 0;
  1831. return conv;
  1832. }
  1833. // Convert float to string with +1234.5 format
  1834. char *ftostr51(const float &x)
  1835. {
  1836. long xx = x * 10;
  1837. conv[0] = (xx >= 0) ? '+' : '-';
  1838. xx = abs(xx);
  1839. conv[1] = (xx / 10000) % 10 + '0';
  1840. conv[2] = (xx / 1000) % 10 + '0';
  1841. conv[3] = (xx / 100) % 10 + '0';
  1842. conv[4] = (xx / 10) % 10 + '0';
  1843. conv[5] = '.';
  1844. conv[6] = (xx) % 10 + '0';
  1845. conv[7] = 0;
  1846. return conv;
  1847. }
  1848. // Convert float to string with +123.45 format
  1849. char *ftostr52(const float &x)
  1850. {
  1851. long xx = x * 100;
  1852. conv[0] = (xx >= 0) ? '+' : '-';
  1853. xx = abs(xx);
  1854. conv[1] = (xx / 10000) % 10 + '0';
  1855. conv[2] = (xx / 1000) % 10 + '0';
  1856. conv[3] = (xx / 100) % 10 + '0';
  1857. conv[4] = '.';
  1858. conv[5] = (xx / 10) % 10 + '0';
  1859. conv[6] = (xx) % 10 + '0';
  1860. conv[7] = 0;
  1861. return conv;
  1862. }
  1863. // Callback for after editing PID i value
  1864. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  1865. void copy_and_scalePID_i()
  1866. {
  1867. #ifdef PIDTEMP
  1868. Ki = scalePID_i(raw_Ki);
  1869. updatePID();
  1870. #endif
  1871. }
  1872. // Callback for after editing PID d value
  1873. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  1874. void copy_and_scalePID_d()
  1875. {
  1876. #ifdef PIDTEMP
  1877. Kd = scalePID_d(raw_Kd);
  1878. updatePID();
  1879. #endif
  1880. }
  1881. #endif //ULTRA_LCD