ultralcd.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241
  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_move_menu_axis()
  726. {
  727. START_MENU();
  728. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  729. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  730. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  731. if (move_menu_scale < 10.0)
  732. {
  733. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  734. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  735. }
  736. END_MENU();
  737. }
  738. static void lcd_move_menu_1mm()
  739. {
  740. move_menu_scale = 1.0;
  741. lcd_move_menu_axis();
  742. }
  743. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  744. {
  745. do
  746. {
  747. eeprom_write_byte((unsigned char*)pos, *value);
  748. pos++;
  749. value++;
  750. } while (--size);
  751. }
  752. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  753. {
  754. do
  755. {
  756. *value = eeprom_read_byte((unsigned char*)pos);
  757. pos++;
  758. value++;
  759. } while (--size);
  760. }
  761. static void lcd_silent_mode_set() {
  762. SilentModeMenu = !SilentModeMenu;
  763. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  764. digipot_init();
  765. lcd_goto_menu(lcd_settings_menu, 7);
  766. }
  767. static void lcd_set_lang(unsigned char lang) {
  768. lang_selected = lang;
  769. firstrun = 1;
  770. eeprom_write_byte((unsigned char *)EEPROM_LANG, lang);/*langsel=0;*/if (langsel == 1)langsel = 2;
  771. }
  772. void lcd_force_language_selection() {
  773. eeprom_write_byte((unsigned char *)EEPROM_LANG, 255);
  774. }
  775. static void lcd_language_menu()
  776. {
  777. START_MENU();
  778. if (!langsel) {
  779. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  780. }
  781. if (langsel == 2) {
  782. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  783. }
  784. for (int i=0;i<LANG_NUM;i++){
  785. MENU_ITEM(setlang, MSG_ALL[i][LANGUAGE_NAME], i);
  786. }
  787. //MENU_ITEM(setlang, MSG_ALL[1][LANGUAGE_NAME], 1);
  788. END_MENU();
  789. }
  790. static void lcd_settings_menu()
  791. {
  792. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  793. START_MENU();
  794. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  795. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  796. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  797. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  798. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  799. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  800. if (SilentModeMenu == 0) {
  801. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  802. } else {
  803. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  804. }
  805. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  806. END_MENU();
  807. }
  808. /*
  809. void lcd_mylang_top(int hlaska) {
  810. lcd.setCursor(0,0);
  811. lcd.print(" ");
  812. lcd.setCursor(0,0);
  813. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  814. }
  815. void lcd_mylang_drawmenu(int cursor) {
  816. int first = 0;
  817. if (cursor>2) first = cursor-2;
  818. if (cursor==LANG_NUM) first = LANG_NUM-3;
  819. lcd.setCursor(0, 1);
  820. lcd.print(" ");
  821. lcd.setCursor(1, 1);
  822. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  823. lcd.setCursor(0, 2);
  824. lcd.print(" ");
  825. lcd.setCursor(1, 2);
  826. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  827. lcd.setCursor(0, 3);
  828. lcd.print(" ");
  829. lcd.setCursor(1, 3);
  830. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  831. if (cursor==1) lcd.setCursor(0, 1);
  832. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  833. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  834. lcd.print(">");
  835. if (cursor<LANG_NUM-1) {
  836. lcd.setCursor(19,3);
  837. lcd.print("\x01");
  838. }
  839. if (cursor>2) {
  840. lcd.setCursor(19,1);
  841. lcd.print("^");
  842. }
  843. }
  844. */
  845. void lcd_mylang_drawmenu(int cursor) {
  846. int first = 0;
  847. if (cursor>3) first = cursor-3;
  848. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  849. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  850. lcd.setCursor(0, 0);
  851. lcd.print(" ");
  852. lcd.setCursor(1, 0);
  853. lcd_printPGM(MSG_ALL[first+0][LANGUAGE_NAME]);
  854. lcd.setCursor(0, 1);
  855. lcd.print(" ");
  856. lcd.setCursor(1, 1);
  857. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  858. lcd.setCursor(0, 2);
  859. lcd.print(" ");
  860. if (LANG_NUM > 2){
  861. lcd.setCursor(1, 2);
  862. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  863. }
  864. lcd.setCursor(0, 3);
  865. lcd.print(" ");
  866. if (LANG_NUM>3) {
  867. lcd.setCursor(1, 3);
  868. lcd_printPGM(MSG_ALL[first+3][LANGUAGE_NAME]);
  869. }
  870. if (cursor==1) lcd.setCursor(0, 0);
  871. if (cursor==2) lcd.setCursor(0, 1);
  872. if (cursor>2) lcd.setCursor(0, 2);
  873. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  874. lcd.print(">");
  875. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  876. lcd.setCursor(19,3);
  877. lcd.print("\x01");
  878. }
  879. if (cursor>3 && LANG_NUM>4) {
  880. lcd.setCursor(19,0);
  881. lcd.print("^");
  882. }
  883. }
  884. void lcd_set_custom_characters_arrows();
  885. void lcd_set_custom_characters_degree();
  886. void lcd_mylang_drawcursor(int cursor) {
  887. if (cursor==1) lcd.setCursor(0, 1);
  888. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  889. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  890. lcd.print(">");
  891. }
  892. void lcd_mylang() {
  893. int enc_dif = 0;
  894. int cursor_pos = 1;
  895. lang_selected=255;
  896. int hlaska=1;
  897. int counter=0;
  898. lcd_set_custom_characters_arrows();
  899. lcd_implementation_clear();
  900. //lcd_mylang_top(hlaska);
  901. lcd_mylang_drawmenu(cursor_pos);
  902. enc_dif = encoderDiff;
  903. while ( (lang_selected == 255) && (MYSERIAL.available() < 2) ) {
  904. manage_heater();
  905. manage_inactivity(true);
  906. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  907. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  908. if (enc_dif > encoderDiff ) {
  909. cursor_pos --;
  910. }
  911. if (enc_dif < encoderDiff ) {
  912. cursor_pos ++;
  913. }
  914. if (cursor_pos > LANG_NUM) {
  915. cursor_pos = LANG_NUM;
  916. }
  917. if (cursor_pos < 1) {
  918. cursor_pos = 1;
  919. }
  920. lcd_mylang_drawmenu(cursor_pos);
  921. enc_dif = encoderDiff;
  922. delay(100);
  923. //}
  924. } else delay(20);
  925. if (lcd_clicked()) {
  926. lcd_set_lang(cursor_pos-1);
  927. delay(500);
  928. }
  929. /*
  930. if (++counter == 80) {
  931. hlaska++;
  932. if(hlaska>LANG_NUM) hlaska=1;
  933. lcd_mylang_top(hlaska);
  934. lcd_mylang_drawcursor(cursor_pos);
  935. counter=0;
  936. }
  937. */
  938. };
  939. if(MYSERIAL.available() > 1){
  940. lang_selected = 0;
  941. firstrun = 0;
  942. }
  943. lcd_set_custom_characters_degree();
  944. lcd_implementation_clear();
  945. lcd_return_to_status();
  946. }
  947. static void lcd_main_menu()
  948. {
  949. SDscrool = 0;
  950. /*
  951. if (langsel == 1)
  952. {
  953. lcd_goto_menu(lcd_language_menu);
  954. }
  955. */
  956. START_MENU();
  957. // Majkl superawesome menu
  958. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  959. if (IS_SD_PRINTING && (current_position[Z_AXIS] < 0.5) )
  960. {
  961. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  962. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  963. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  964. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  965. }
  966. if (movesplanned() || IS_SD_PRINTING)
  967. {
  968. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  969. } else {
  970. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  971. }
  972. #ifdef SDSUPPORT
  973. if (card.cardOK)
  974. {
  975. if (card.isFileOpen())
  976. {
  977. if (card.sdprinting)
  978. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  979. else
  980. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  981. MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
  982. } else {
  983. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  984. #if SDCARDDETECT < 1
  985. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  986. #endif
  987. }
  988. } else {
  989. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  990. #if SDCARDDETECT < 1
  991. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  992. #endif
  993. }
  994. #endif
  995. if (IS_SD_PRINTING)
  996. {
  997. } else {
  998. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  999. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  1000. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  1001. }
  1002. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  1003. END_MENU();
  1004. }
  1005. #ifdef SDSUPPORT
  1006. static void lcd_autostart_sd()
  1007. {
  1008. card.lastnr = 0;
  1009. card.setroot();
  1010. card.checkautostart(true);
  1011. }
  1012. #endif
  1013. static void lcd_silent_mode_set_tune() {
  1014. SilentModeMenu = !SilentModeMenu;
  1015. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1016. digipot_init();
  1017. lcd_goto_menu(lcd_tune_menu, 9);
  1018. }
  1019. static void lcd_tune_menu()
  1020. {
  1021. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1022. START_MENU();
  1023. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  1024. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  1025. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  1026. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  1027. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  1028. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  1029. #ifdef FILAMENTCHANGEENABLE
  1030. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));//7
  1031. #endif
  1032. if (SilentModeMenu == 0) {
  1033. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  1034. } else {
  1035. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  1036. }
  1037. END_MENU();
  1038. }
  1039. static void lcd_move_menu_01mm()
  1040. {
  1041. move_menu_scale = 0.1;
  1042. lcd_move_menu_axis();
  1043. }
  1044. static void lcd_control_temperature_menu()
  1045. {
  1046. #ifdef PIDTEMP
  1047. // set up temp variables - undo the default scaling
  1048. raw_Ki = unscalePID_i(Ki);
  1049. raw_Kd = unscalePID_d(Kd);
  1050. #endif
  1051. START_MENU();
  1052. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1053. //MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1054. #if TEMP_SENSOR_0 != 0
  1055. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  1056. #endif
  1057. #if TEMP_SENSOR_1 != 0
  1058. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  1059. #endif
  1060. #if TEMP_SENSOR_2 != 0
  1061. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  1062. #endif
  1063. #if TEMP_SENSOR_BED != 0
  1064. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  1065. #endif
  1066. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  1067. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  1068. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  1069. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  1070. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  1071. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  1072. #endif
  1073. END_MENU();
  1074. }
  1075. #if SDCARDDETECT == -1
  1076. static void lcd_sd_refresh()
  1077. {
  1078. card.initsd();
  1079. currentMenuViewOffset = 0;
  1080. }
  1081. #endif
  1082. static void lcd_sd_updir()
  1083. {
  1084. SDscrool = 0;
  1085. card.updir();
  1086. currentMenuViewOffset = 0;
  1087. }
  1088. void lcd_sdcard_menu()
  1089. {
  1090. int tempScrool = 0;
  1091. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  1092. //delay(100);
  1093. return; // nothing to do (so don't thrash the SD card)
  1094. uint16_t fileCnt = card.getnrfilenames();
  1095. START_MENU();
  1096. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1097. card.getWorkDirName();
  1098. if (card.filename[0] == '/')
  1099. {
  1100. #if SDCARDDETECT == -1
  1101. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1102. #endif
  1103. } else {
  1104. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1105. }
  1106. for (uint16_t i = 0; i < fileCnt; i++)
  1107. {
  1108. if (_menuItemNr == _lineNr)
  1109. {
  1110. #ifndef SDCARD_RATHERRECENTFIRST
  1111. card.getfilename(i);
  1112. #else
  1113. card.getfilename(fileCnt - 1 - i);
  1114. #endif
  1115. if (card.filenameIsDir)
  1116. {
  1117. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1118. } else {
  1119. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1120. }
  1121. } else {
  1122. MENU_ITEM_DUMMY();
  1123. }
  1124. }
  1125. END_MENU();
  1126. }
  1127. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1128. void menu_edit_ ## _name () \
  1129. { \
  1130. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1131. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1132. if (lcdDrawUpdate) \
  1133. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1134. if (LCD_CLICKED) \
  1135. { \
  1136. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1137. lcd_goto_menu(prevMenu, prevEncoderPosition); \
  1138. } \
  1139. } \
  1140. void menu_edit_callback_ ## _name () { \
  1141. menu_edit_ ## _name (); \
  1142. if (LCD_CLICKED) (*callbackFunc)(); \
  1143. } \
  1144. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  1145. { \
  1146. prevMenu = currentMenu; \
  1147. prevEncoderPosition = encoderPosition; \
  1148. \
  1149. lcdDrawUpdate = 2; \
  1150. currentMenu = menu_edit_ ## _name; \
  1151. \
  1152. editLabel = pstr; \
  1153. editValue = ptr; \
  1154. minEditValue = minValue * scale; \
  1155. maxEditValue = maxValue * scale - minEditValue; \
  1156. encoderPosition = (*ptr) * scale - minEditValue; \
  1157. }\
  1158. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  1159. { \
  1160. prevMenu = currentMenu; \
  1161. prevEncoderPosition = encoderPosition; \
  1162. \
  1163. lcdDrawUpdate = 2; \
  1164. currentMenu = menu_edit_callback_ ## _name; \
  1165. \
  1166. editLabel = pstr; \
  1167. editValue = ptr; \
  1168. minEditValue = minValue * scale; \
  1169. maxEditValue = maxValue * scale - minEditValue; \
  1170. encoderPosition = (*ptr) * scale - minEditValue; \
  1171. callbackFunc = callback;\
  1172. }
  1173. menu_edit_type(int, int3, itostr3, 1)
  1174. menu_edit_type(float, float3, ftostr3, 1)
  1175. menu_edit_type(float, float32, ftostr32, 100)
  1176. menu_edit_type(float, float43, ftostr43, 1000)
  1177. menu_edit_type(float, float5, ftostr5, 0.01)
  1178. menu_edit_type(float, float51, ftostr51, 10)
  1179. menu_edit_type(float, float52, ftostr52, 100)
  1180. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1181. /** End of menus **/
  1182. static void lcd_quick_feedback()
  1183. {
  1184. lcdDrawUpdate = 2;
  1185. blocking_enc = millis() + 500;
  1186. lcd_implementation_quick_feedback();
  1187. }
  1188. /** Menu action functions **/
  1189. static void menu_action_back(menuFunc_t data) {
  1190. lcd_goto_menu(data);
  1191. }
  1192. static void menu_action_submenu(menuFunc_t data) {
  1193. lcd_goto_menu(data);
  1194. }
  1195. static void menu_action_gcode(const char* pgcode) {
  1196. enquecommand_P(pgcode);
  1197. }
  1198. static void menu_action_setlang(unsigned char lang) {
  1199. lcd_set_lang(lang);
  1200. }
  1201. static void menu_action_function(menuFunc_t data) {
  1202. (*data)();
  1203. }
  1204. static void menu_action_sdfile(const char* filename, char* longFilename)
  1205. {
  1206. char cmd[30];
  1207. char* c;
  1208. sprintf_P(cmd, PSTR("M23 %s"), filename);
  1209. for (c = &cmd[4]; *c; c++)
  1210. *c = tolower(*c);
  1211. enquecommand(cmd);
  1212. enquecommand_P(PSTR("M24"));
  1213. lcd_return_to_status();
  1214. }
  1215. static void menu_action_sddirectory(const char* filename, char* longFilename)
  1216. {
  1217. card.chdir(filename);
  1218. encoderPosition = 0;
  1219. }
  1220. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  1221. {
  1222. *ptr = !(*ptr);
  1223. }
  1224. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  1225. {
  1226. menu_action_setting_edit_bool(pstr, ptr);
  1227. (*callback)();
  1228. }
  1229. #endif//ULTIPANEL
  1230. /** LCD API **/
  1231. void lcd_init()
  1232. {
  1233. lcd_implementation_init();
  1234. #ifdef NEWPANEL
  1235. SET_INPUT(BTN_EN1);
  1236. SET_INPUT(BTN_EN2);
  1237. WRITE(BTN_EN1, HIGH);
  1238. WRITE(BTN_EN2, HIGH);
  1239. #if BTN_ENC > 0
  1240. SET_INPUT(BTN_ENC);
  1241. WRITE(BTN_ENC, HIGH);
  1242. #endif
  1243. #ifdef REPRAPWORLD_KEYPAD
  1244. pinMode(SHIFT_CLK, OUTPUT);
  1245. pinMode(SHIFT_LD, OUTPUT);
  1246. pinMode(SHIFT_OUT, INPUT);
  1247. WRITE(SHIFT_OUT, HIGH);
  1248. WRITE(SHIFT_LD, HIGH);
  1249. #endif
  1250. #else // Not NEWPANEL
  1251. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  1252. pinMode (SR_DATA_PIN, OUTPUT);
  1253. pinMode (SR_CLK_PIN, OUTPUT);
  1254. #elif defined(SHIFT_CLK)
  1255. pinMode(SHIFT_CLK, OUTPUT);
  1256. pinMode(SHIFT_LD, OUTPUT);
  1257. pinMode(SHIFT_EN, OUTPUT);
  1258. pinMode(SHIFT_OUT, INPUT);
  1259. WRITE(SHIFT_OUT, HIGH);
  1260. WRITE(SHIFT_LD, HIGH);
  1261. WRITE(SHIFT_EN, LOW);
  1262. #else
  1263. #ifdef ULTIPANEL
  1264. #error ULTIPANEL requires an encoder
  1265. #endif
  1266. #endif // SR_LCD_2W_NL
  1267. #endif//!NEWPANEL
  1268. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  1269. pinMode(SDCARDDETECT, INPUT);
  1270. WRITE(SDCARDDETECT, HIGH);
  1271. lcd_oldcardstatus = IS_SD_INSERTED;
  1272. #endif//(SDCARDDETECT > 0)
  1273. #ifdef LCD_HAS_SLOW_BUTTONS
  1274. slow_buttons = 0;
  1275. #endif
  1276. lcd_buttons_update();
  1277. #ifdef ULTIPANEL
  1278. encoderDiff = 0;
  1279. #endif
  1280. }
  1281. //#include <avr/pgmspace.h>
  1282. void lcd_update()
  1283. {
  1284. static unsigned long timeoutToStatus = 0;
  1285. #ifdef LCD_HAS_SLOW_BUTTONS
  1286. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1287. #endif
  1288. lcd_buttons_update();
  1289. #if (SDCARDDETECT > 0)
  1290. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  1291. {
  1292. lcdDrawUpdate = 2;
  1293. lcd_oldcardstatus = IS_SD_INSERTED;
  1294. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1295. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1296. currentMenu == lcd_status_screen
  1297. #endif
  1298. );
  1299. if (lcd_oldcardstatus)
  1300. {
  1301. card.initsd();
  1302. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  1303. }
  1304. else
  1305. {
  1306. card.release();
  1307. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  1308. }
  1309. }
  1310. #endif//CARDINSERTED
  1311. if (lcd_next_update_millis < millis())
  1312. {
  1313. #ifdef ULTIPANEL
  1314. #ifdef REPRAPWORLD_KEYPAD
  1315. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  1316. reprapworld_keypad_move_z_up();
  1317. }
  1318. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  1319. reprapworld_keypad_move_z_down();
  1320. }
  1321. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  1322. reprapworld_keypad_move_x_left();
  1323. }
  1324. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  1325. reprapworld_keypad_move_x_right();
  1326. }
  1327. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  1328. reprapworld_keypad_move_y_down();
  1329. }
  1330. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  1331. reprapworld_keypad_move_y_up();
  1332. }
  1333. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  1334. reprapworld_keypad_move_home();
  1335. }
  1336. #endif
  1337. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  1338. {
  1339. lcdDrawUpdate = 1;
  1340. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  1341. encoderDiff = 0;
  1342. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1343. }
  1344. if (LCD_CLICKED)
  1345. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1346. #endif//ULTIPANEL
  1347. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  1348. blink++; // Variable for fan animation and alive dot
  1349. u8g.firstPage();
  1350. do
  1351. {
  1352. u8g.setFont(u8g_font_6x10_marlin);
  1353. u8g.setPrintPos(125, 0);
  1354. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  1355. u8g.drawPixel(127, 63); // draw alive dot
  1356. u8g.setColorIndex(1); // black on white
  1357. (*currentMenu)();
  1358. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  1359. } while ( u8g.nextPage() );
  1360. #else
  1361. (*currentMenu)();
  1362. #endif
  1363. #ifdef LCD_HAS_STATUS_INDICATORS
  1364. lcd_implementation_update_indicators();
  1365. #endif
  1366. #ifdef ULTIPANEL
  1367. if (timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  1368. {
  1369. lcd_return_to_status();
  1370. lcdDrawUpdate = 2;
  1371. }
  1372. #endif//ULTIPANEL
  1373. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  1374. if (lcdDrawUpdate) lcdDrawUpdate--;
  1375. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  1376. }
  1377. }
  1378. void lcd_ignore_click(bool b)
  1379. {
  1380. ignore_click = b;
  1381. wait_for_unclick = false;
  1382. }
  1383. void lcd_finishstatus() {
  1384. int len = strlen(lcd_status_message);
  1385. if (len > 0) {
  1386. while (len < LCD_WIDTH) {
  1387. lcd_status_message[len++] = ' ';
  1388. }
  1389. }
  1390. lcd_status_message[LCD_WIDTH] = '\0';
  1391. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1392. #if PROGRESS_MSG_EXPIRE > 0
  1393. messageTick =
  1394. #endif
  1395. progressBarTick = millis();
  1396. #endif
  1397. lcdDrawUpdate = 2;
  1398. #ifdef FILAMENT_LCD_DISPLAY
  1399. message_millis = millis(); //get status message to show up for a while
  1400. #endif
  1401. }
  1402. void lcd_setstatus(const char* message)
  1403. {
  1404. if (lcd_status_message_level > 0)
  1405. return;
  1406. strncpy(lcd_status_message, message, LCD_WIDTH);
  1407. lcd_finishstatus();
  1408. }
  1409. void lcd_setstatuspgm(const char* message)
  1410. {
  1411. if (lcd_status_message_level > 0)
  1412. return;
  1413. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  1414. lcd_finishstatus();
  1415. }
  1416. void lcd_setalertstatuspgm(const char* message)
  1417. {
  1418. lcd_setstatuspgm(message);
  1419. lcd_status_message_level = 1;
  1420. #ifdef ULTIPANEL
  1421. lcd_return_to_status();
  1422. #endif//ULTIPANEL
  1423. }
  1424. void lcd_reset_alert_level()
  1425. {
  1426. lcd_status_message_level = 0;
  1427. }
  1428. #ifdef DOGLCD
  1429. void lcd_setcontrast(uint8_t value)
  1430. {
  1431. lcd_contrast = value & 63;
  1432. u8g.setContrast(lcd_contrast);
  1433. }
  1434. #endif
  1435. #ifdef ULTIPANEL
  1436. /* Warning: This function is called from interrupt context */
  1437. void lcd_buttons_update()
  1438. {
  1439. #ifdef NEWPANEL
  1440. uint8_t newbutton = 0;
  1441. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  1442. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  1443. #if BTN_ENC > 0
  1444. if ((blocking_enc < millis()) && (READ(BTN_ENC) == 0))
  1445. newbutton |= EN_C;
  1446. #endif
  1447. buttons = newbutton;
  1448. #ifdef LCD_HAS_SLOW_BUTTONS
  1449. buttons |= slow_buttons;
  1450. #endif
  1451. #ifdef REPRAPWORLD_KEYPAD
  1452. // for the reprapworld_keypad
  1453. uint8_t newbutton_reprapworld_keypad = 0;
  1454. WRITE(SHIFT_LD, LOW);
  1455. WRITE(SHIFT_LD, HIGH);
  1456. for (int8_t i = 0; i < 8; i++) {
  1457. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  1458. if (READ(SHIFT_OUT))
  1459. newbutton_reprapworld_keypad |= (1 << 7);
  1460. WRITE(SHIFT_CLK, HIGH);
  1461. WRITE(SHIFT_CLK, LOW);
  1462. }
  1463. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  1464. #endif
  1465. #else //read it from the shift register
  1466. uint8_t newbutton = 0;
  1467. WRITE(SHIFT_LD, LOW);
  1468. WRITE(SHIFT_LD, HIGH);
  1469. unsigned char tmp_buttons = 0;
  1470. for (int8_t i = 0; i < 8; i++)
  1471. {
  1472. newbutton = newbutton >> 1;
  1473. if (READ(SHIFT_OUT))
  1474. newbutton |= (1 << 7);
  1475. WRITE(SHIFT_CLK, HIGH);
  1476. WRITE(SHIFT_CLK, LOW);
  1477. }
  1478. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  1479. #endif//!NEWPANEL
  1480. //manage encoder rotation
  1481. uint8_t enc = 0;
  1482. if (buttons & EN_A) enc |= B01;
  1483. if (buttons & EN_B) enc |= B10;
  1484. if (enc != lastEncoderBits)
  1485. {
  1486. switch (enc)
  1487. {
  1488. case encrot0:
  1489. if (lastEncoderBits == encrot3)
  1490. encoderDiff++;
  1491. else if (lastEncoderBits == encrot1)
  1492. encoderDiff--;
  1493. break;
  1494. case encrot1:
  1495. if (lastEncoderBits == encrot0)
  1496. encoderDiff++;
  1497. else if (lastEncoderBits == encrot2)
  1498. encoderDiff--;
  1499. break;
  1500. case encrot2:
  1501. if (lastEncoderBits == encrot1)
  1502. encoderDiff++;
  1503. else if (lastEncoderBits == encrot3)
  1504. encoderDiff--;
  1505. break;
  1506. case encrot3:
  1507. if (lastEncoderBits == encrot2)
  1508. encoderDiff++;
  1509. else if (lastEncoderBits == encrot0)
  1510. encoderDiff--;
  1511. break;
  1512. }
  1513. }
  1514. lastEncoderBits = enc;
  1515. }
  1516. bool lcd_detected(void)
  1517. {
  1518. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  1519. return lcd.LcdDetected() == 1;
  1520. #else
  1521. return true;
  1522. #endif
  1523. }
  1524. void lcd_buzz(long duration, uint16_t freq)
  1525. {
  1526. #ifdef LCD_USE_I2C_BUZZER
  1527. lcd.buzz(duration, freq);
  1528. #endif
  1529. }
  1530. bool lcd_clicked()
  1531. {
  1532. return LCD_CLICKED;
  1533. }
  1534. #endif//ULTIPANEL
  1535. /********************************/
  1536. /** Float conversion utilities **/
  1537. /********************************/
  1538. // convert float to string with +123.4 format
  1539. char conv[8];
  1540. char *ftostr3(const float &x)
  1541. {
  1542. return itostr3((int)x);
  1543. }
  1544. char *itostr2(const uint8_t &x)
  1545. {
  1546. //sprintf(conv,"%5.1f",x);
  1547. int xx = x;
  1548. conv[0] = (xx / 10) % 10 + '0';
  1549. conv[1] = (xx) % 10 + '0';
  1550. conv[2] = 0;
  1551. return conv;
  1552. }
  1553. // Convert float to string with 123.4 format, dropping sign
  1554. char *ftostr31(const float &x)
  1555. {
  1556. int xx = x * 10;
  1557. conv[0] = (xx >= 0) ? '+' : '-';
  1558. xx = abs(xx);
  1559. conv[1] = (xx / 1000) % 10 + '0';
  1560. conv[2] = (xx / 100) % 10 + '0';
  1561. conv[3] = (xx / 10) % 10 + '0';
  1562. conv[4] = '.';
  1563. conv[5] = (xx) % 10 + '0';
  1564. conv[6] = 0;
  1565. return conv;
  1566. }
  1567. // Convert float to string with 123.4 format
  1568. char *ftostr31ns(const float &x)
  1569. {
  1570. int xx = x * 10;
  1571. //conv[0]=(xx>=0)?'+':'-';
  1572. xx = abs(xx);
  1573. conv[0] = (xx / 1000) % 10 + '0';
  1574. conv[1] = (xx / 100) % 10 + '0';
  1575. conv[2] = (xx / 10) % 10 + '0';
  1576. conv[3] = '.';
  1577. conv[4] = (xx) % 10 + '0';
  1578. conv[5] = 0;
  1579. return conv;
  1580. }
  1581. char *ftostr32(const float &x)
  1582. {
  1583. long xx = x * 100;
  1584. if (xx >= 0)
  1585. conv[0] = (xx / 10000) % 10 + '0';
  1586. else
  1587. conv[0] = '-';
  1588. xx = abs(xx);
  1589. conv[1] = (xx / 1000) % 10 + '0';
  1590. conv[2] = (xx / 100) % 10 + '0';
  1591. conv[3] = '.';
  1592. conv[4] = (xx / 10) % 10 + '0';
  1593. conv[5] = (xx) % 10 + '0';
  1594. conv[6] = 0;
  1595. return conv;
  1596. }
  1597. // Convert float to string with 1.234 format
  1598. char *ftostr43(const float &x)
  1599. {
  1600. long xx = x * 1000;
  1601. if (xx >= 0)
  1602. conv[0] = (xx / 1000) % 10 + '0';
  1603. else
  1604. conv[0] = '-';
  1605. xx = abs(xx);
  1606. conv[1] = '.';
  1607. conv[2] = (xx / 100) % 10 + '0';
  1608. conv[3] = (xx / 10) % 10 + '0';
  1609. conv[4] = (xx) % 10 + '0';
  1610. conv[5] = 0;
  1611. return conv;
  1612. }
  1613. //Float to string with 1.23 format
  1614. char *ftostr12ns(const float &x)
  1615. {
  1616. long xx = x * 100;
  1617. xx = abs(xx);
  1618. conv[0] = (xx / 100) % 10 + '0';
  1619. conv[1] = '.';
  1620. conv[2] = (xx / 10) % 10 + '0';
  1621. conv[3] = (xx) % 10 + '0';
  1622. conv[4] = 0;
  1623. return conv;
  1624. }
  1625. // convert float to space-padded string with -_23.4_ format
  1626. char *ftostr32sp(const float &x) {
  1627. long xx = abs(x * 100);
  1628. uint8_t dig;
  1629. if (x < 0) { // negative val = -_0
  1630. conv[0] = '-';
  1631. dig = (xx / 1000) % 10;
  1632. conv[1] = dig ? '0' + dig : ' ';
  1633. }
  1634. else { // positive val = __0
  1635. dig = (xx / 10000) % 10;
  1636. if (dig) {
  1637. conv[0] = '0' + dig;
  1638. conv[1] = '0' + (xx / 1000) % 10;
  1639. }
  1640. else {
  1641. conv[0] = ' ';
  1642. dig = (xx / 1000) % 10;
  1643. conv[1] = dig ? '0' + dig : ' ';
  1644. }
  1645. }
  1646. conv[2] = '0' + (xx / 100) % 10; // lsd always
  1647. dig = xx % 10;
  1648. if (dig) { // 2 decimal places
  1649. conv[5] = '0' + dig;
  1650. conv[4] = '0' + (xx / 10) % 10;
  1651. conv[3] = '.';
  1652. }
  1653. else { // 1 or 0 decimal place
  1654. dig = (xx / 10) % 10;
  1655. if (dig) {
  1656. conv[4] = '0' + dig;
  1657. conv[3] = '.';
  1658. }
  1659. else {
  1660. conv[3] = conv[4] = ' ';
  1661. }
  1662. conv[5] = ' ';
  1663. }
  1664. conv[6] = '\0';
  1665. return conv;
  1666. }
  1667. char *itostr31(const int &xx)
  1668. {
  1669. conv[0] = (xx >= 0) ? '+' : '-';
  1670. conv[1] = (xx / 1000) % 10 + '0';
  1671. conv[2] = (xx / 100) % 10 + '0';
  1672. conv[3] = (xx / 10) % 10 + '0';
  1673. conv[4] = '.';
  1674. conv[5] = (xx) % 10 + '0';
  1675. conv[6] = 0;
  1676. return conv;
  1677. }
  1678. // Convert int to rj string with 123 or -12 format
  1679. char *itostr3(const int &x)
  1680. {
  1681. int xx = x;
  1682. if (xx < 0) {
  1683. conv[0] = '-';
  1684. xx = -xx;
  1685. } else if (xx >= 100)
  1686. conv[0] = (xx / 100) % 10 + '0';
  1687. else
  1688. conv[0] = ' ';
  1689. if (xx >= 10)
  1690. conv[1] = (xx / 10) % 10 + '0';
  1691. else
  1692. conv[1] = ' ';
  1693. conv[2] = (xx) % 10 + '0';
  1694. conv[3] = 0;
  1695. return conv;
  1696. }
  1697. // Convert int to lj string with 123 format
  1698. char *itostr3left(const int &xx)
  1699. {
  1700. if (xx >= 100)
  1701. {
  1702. conv[0] = (xx / 100) % 10 + '0';
  1703. conv[1] = (xx / 10) % 10 + '0';
  1704. conv[2] = (xx) % 10 + '0';
  1705. conv[3] = 0;
  1706. }
  1707. else if (xx >= 10)
  1708. {
  1709. conv[0] = (xx / 10) % 10 + '0';
  1710. conv[1] = (xx) % 10 + '0';
  1711. conv[2] = 0;
  1712. }
  1713. else
  1714. {
  1715. conv[0] = (xx) % 10 + '0';
  1716. conv[1] = 0;
  1717. }
  1718. return conv;
  1719. }
  1720. // Convert int to rj string with 1234 format
  1721. char *itostr4(const int &xx) {
  1722. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1723. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1724. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1725. conv[3] = xx % 10 + '0';
  1726. conv[4] = 0;
  1727. return conv;
  1728. }
  1729. // Convert float to rj string with 12345 format
  1730. char *ftostr5(const float &x) {
  1731. long xx = abs(x);
  1732. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  1733. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  1734. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  1735. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  1736. conv[4] = xx % 10 + '0';
  1737. conv[5] = 0;
  1738. return conv;
  1739. }
  1740. // Convert float to string with +1234.5 format
  1741. char *ftostr51(const float &x)
  1742. {
  1743. long xx = x * 10;
  1744. conv[0] = (xx >= 0) ? '+' : '-';
  1745. xx = abs(xx);
  1746. conv[1] = (xx / 10000) % 10 + '0';
  1747. conv[2] = (xx / 1000) % 10 + '0';
  1748. conv[3] = (xx / 100) % 10 + '0';
  1749. conv[4] = (xx / 10) % 10 + '0';
  1750. conv[5] = '.';
  1751. conv[6] = (xx) % 10 + '0';
  1752. conv[7] = 0;
  1753. return conv;
  1754. }
  1755. // Convert float to string with +123.45 format
  1756. char *ftostr52(const float &x)
  1757. {
  1758. long xx = x * 100;
  1759. conv[0] = (xx >= 0) ? '+' : '-';
  1760. xx = abs(xx);
  1761. conv[1] = (xx / 10000) % 10 + '0';
  1762. conv[2] = (xx / 1000) % 10 + '0';
  1763. conv[3] = (xx / 100) % 10 + '0';
  1764. conv[4] = '.';
  1765. conv[5] = (xx / 10) % 10 + '0';
  1766. conv[6] = (xx) % 10 + '0';
  1767. conv[7] = 0;
  1768. return conv;
  1769. }
  1770. // Callback for after editing PID i value
  1771. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  1772. void copy_and_scalePID_i()
  1773. {
  1774. #ifdef PIDTEMP
  1775. Ki = scalePID_i(raw_Ki);
  1776. updatePID();
  1777. #endif
  1778. }
  1779. // Callback for after editing PID d value
  1780. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  1781. void copy_and_scalePID_d()
  1782. {
  1783. #ifdef PIDTEMP
  1784. Kd = scalePID_d(raw_Kd);
  1785. updatePID();
  1786. #endif
  1787. }
  1788. #endif //ULTRA_LCD