ultralcd.cpp 52 KB

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