ultralcd.cpp 55 KB

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