ultralcd.cpp 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #ifdef ULTRA_LCD
  4. #include "Marlin.h"
  5. #include "language.h"
  6. #include "cardreader.h"
  7. #include "temperature.h"
  8. #include "stepper.h"
  9. #include "ConfigurationStore.h"
  10. #include <string.h>
  11. //#include "Configuration.h"
  12. #define _STRINGIFY(s) #s
  13. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  14. extern int lcd_change_fil_state;
  15. int babystepMem[3];
  16. float babystepMemMM[3];
  17. union Data
  18. {
  19. byte b[2];
  20. int value;
  21. };
  22. int8_t ReInitLCD = 0;
  23. int8_t SDscrool = 0;
  24. int8_t SilentModeMenu = 0;
  25. int lcd_commands_type=0;
  26. int lcd_commands_step=0;
  27. bool isPrintPaused = false;
  28. bool menuExiting = false;
  29. /* Configuration settings */
  30. int plaPreheatHotendTemp;
  31. int plaPreheatHPBTemp;
  32. int plaPreheatFanSpeed;
  33. int absPreheatHotendTemp;
  34. int absPreheatHPBTemp;
  35. int absPreheatFanSpeed;
  36. int ppPreheatHotendTemp = PP_PREHEAT_HOTEND_TEMP;
  37. int ppPreheatHPBTemp = PP_PREHEAT_HPB_TEMP;
  38. int ppPreheatFanSpeed = PP_PREHEAT_FAN_SPEED;
  39. int petPreheatHotendTemp = PET_PREHEAT_HOTEND_TEMP;
  40. int petPreheatHPBTemp = PET_PREHEAT_HPB_TEMP;
  41. int petPreheatFanSpeed = PET_PREHEAT_FAN_SPEED;
  42. int hipsPreheatHotendTemp = HIPS_PREHEAT_HOTEND_TEMP;
  43. int hipsPreheatHPBTemp = HIPS_PREHEAT_HPB_TEMP;
  44. int hipsPreheatFanSpeed = HIPS_PREHEAT_FAN_SPEED;
  45. int flexPreheatHotendTemp = FLEX_PREHEAT_HOTEND_TEMP;
  46. int flexPreheatHPBTemp = FLEX_PREHEAT_HPB_TEMP;
  47. int flexPreheatFanSpeed = FLEX_PREHEAT_FAN_SPEED;
  48. #ifdef FILAMENT_LCD_DISPLAY
  49. unsigned long message_millis = 0;
  50. #endif
  51. #ifdef ULTIPANEL
  52. static float manual_feedrate[] = MANUAL_FEEDRATE;
  53. #endif // ULTIPANEL
  54. /* !Configuration settings */
  55. //Function pointer to menu functions.
  56. typedef void (*menuFunc_t)();
  57. uint8_t lcd_status_message_level;
  58. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  59. unsigned char firstrun = 1;
  60. #ifdef DOGLCD
  61. #include "dogm_lcd_implementation.h"
  62. #else
  63. #include "ultralcd_implementation_hitachi_HD44780.h"
  64. #endif
  65. /** forward declarations **/
  66. void copy_and_scalePID_i();
  67. void copy_and_scalePID_d();
  68. /* Different menus */
  69. static void lcd_status_screen();
  70. #ifdef ULTIPANEL
  71. extern bool powersupply;
  72. static void lcd_main_menu();
  73. static void lcd_tune_menu();
  74. static void lcd_prepare_menu();
  75. static void lcd_move_menu();
  76. static void lcd_control_menu();
  77. static void lcd_settings_menu();
  78. static void lcd_language_menu();
  79. static void lcd_control_temperature_menu();
  80. static void lcd_control_temperature_preheat_pla_settings_menu();
  81. static void lcd_control_temperature_preheat_abs_settings_menu();
  82. static void lcd_control_motion_menu();
  83. static void lcd_control_volumetric_menu();
  84. #ifdef DOGLCD
  85. static void lcd_set_contrast();
  86. #endif
  87. static void lcd_control_retract_menu();
  88. static void lcd_sdcard_menu();
  89. #ifdef DELTA_CALIBRATION_MENU
  90. static void lcd_delta_calibrate_menu();
  91. #endif // DELTA_CALIBRATION_MENU
  92. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  93. /* Different types of actions that can be used in menu items. */
  94. static void menu_action_back(menuFunc_t data);
  95. static void menu_action_submenu(menuFunc_t data);
  96. static void menu_action_gcode(const char* pgcode);
  97. static void menu_action_function(menuFunc_t data);
  98. static void menu_action_setlang(unsigned char lang);
  99. static void menu_action_sdfile(const char* filename, char* longFilename);
  100. static void menu_action_sddirectory(const char* filename, char* longFilename);
  101. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  102. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  103. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  104. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  105. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  106. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  107. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  108. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  109. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  110. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  111. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  112. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  113. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  114. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  115. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  116. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  117. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  118. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  119. #define ENCODER_FEEDRATE_DEADZONE 10
  120. #if !defined(LCD_I2C_VIKI)
  121. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  122. #define ENCODER_STEPS_PER_MENU_ITEM 5
  123. #endif
  124. #ifndef ENCODER_PULSES_PER_STEP
  125. #define ENCODER_PULSES_PER_STEP 1
  126. #endif
  127. #else
  128. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  129. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  130. #endif
  131. #ifndef ENCODER_PULSES_PER_STEP
  132. #define ENCODER_PULSES_PER_STEP 1
  133. #endif
  134. #endif
  135. /* Helper macros for menus */
  136. #define START_MENU() do { \
  137. if (encoderPosition > 0x8000) encoderPosition = 0; \
  138. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  139. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  140. bool wasClicked = LCD_CLICKED;\
  141. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  142. _menuItemNr = 0;
  143. #define MENU_ITEM(type, label, args...) do { \
  144. if (_menuItemNr == _lineNr) { \
  145. if (lcdDrawUpdate) { \
  146. const char* _label_pstr = (label); \
  147. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  148. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  149. }else{\
  150. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  151. }\
  152. }\
  153. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  154. lcd_quick_feedback(); \
  155. menu_action_ ## type ( args ); \
  156. return;\
  157. }\
  158. }\
  159. _menuItemNr++;\
  160. } while(0)
  161. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  162. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  163. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  164. #define END_MENU() \
  165. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  166. 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; } \
  167. } } while(0)
  168. /** Used variables to keep track of the menu */
  169. #ifndef REPRAPWORLD_KEYPAD
  170. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  171. #else
  172. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  173. #endif
  174. #ifdef LCD_HAS_SLOW_BUTTONS
  175. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  176. #endif
  177. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  178. uint32_t blocking_enc;
  179. uint8_t lastEncoderBits;
  180. uint32_t encoderPosition;
  181. #if (SDCARDDETECT > 0)
  182. bool lcd_oldcardstatus;
  183. #endif
  184. #endif //ULTIPANEL
  185. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  186. uint32_t lcd_next_update_millis;
  187. uint8_t lcd_status_update_delay;
  188. bool ignore_click = false;
  189. bool wait_for_unclick;
  190. 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) */
  191. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  192. menuFunc_t prevMenu = NULL;
  193. uint16_t prevEncoderPosition;
  194. //Variables used when editing values.
  195. const char* editLabel;
  196. void* editValue;
  197. int32_t minEditValue, maxEditValue;
  198. menuFunc_t callbackFunc;
  199. // place-holders for Ki and Kd edits
  200. float raw_Ki, raw_Kd;
  201. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true) {
  202. if (currentMenu != menu) {
  203. currentMenu = menu;
  204. encoderPosition = encoder;
  205. if (feedback) lcd_quick_feedback();
  206. // For LCD_PROGRESS_BAR re-initialize the custom characters
  207. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  208. lcd_set_custom_characters(menu == lcd_status_screen);
  209. #endif
  210. }
  211. }
  212. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  213. /*
  214. extern char langbuffer[];
  215. void lcd_printPGM(const char *s1) {
  216. strncpy_P(langbuffer,s1,LCD_WIDTH);
  217. lcd.print(langbuffer);
  218. }
  219. */
  220. unsigned char langsel;
  221. void set_language_from_EEPROM() {
  222. unsigned char eep = eeprom_read_byte((unsigned char*)EEPROM_LANG);
  223. if (eep < LANG_NUM)
  224. {
  225. lang_selected = eep;
  226. langsel = 0;
  227. }
  228. else
  229. {
  230. lang_selected = 1;
  231. langsel = 1;
  232. }
  233. }
  234. void lcd_mylang();
  235. static void lcd_status_screen()
  236. {
  237. if (firstrun == 1)
  238. {
  239. firstrun = 0;
  240. set_language_from_EEPROM();
  241. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  242. if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255)
  243. {
  244. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  245. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  246. }
  247. if (langsel) {
  248. //strncpy_P(lcd_status_message, PSTR(">>>>>>>>>>>> PRESS v"), LCD_WIDTH);
  249. lcd_mylang();
  250. }
  251. }
  252. if (lcd_status_update_delay)
  253. lcd_status_update_delay--;
  254. else
  255. lcdDrawUpdate = 1;
  256. if (lcdDrawUpdate)
  257. {
  258. ReInitLCD++;
  259. if (ReInitLCD == 30) {
  260. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  261. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  262. currentMenu == lcd_status_screen
  263. #endif
  264. );
  265. ReInitLCD = 0 ;
  266. } else {
  267. if ((ReInitLCD % 10) == 0) {
  268. //lcd_implementation_nodisplay();
  269. lcd_implementation_init_noclear( // to maybe revive the LCD if static electricity killed it.
  270. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  271. currentMenu == lcd_status_screen
  272. #endif
  273. );
  274. }
  275. }
  276. //lcd_implementation_display();
  277. lcd_implementation_status_screen();
  278. //lcd_implementation_clear();
  279. 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 */
  280. if (lcd_commands_type != 0)
  281. {
  282. lcd_commands();
  283. }
  284. }
  285. #ifdef ULTIPANEL
  286. bool current_click = LCD_CLICKED;
  287. if (ignore_click) {
  288. if (wait_for_unclick) {
  289. if (!current_click) {
  290. ignore_click = wait_for_unclick = false;
  291. }
  292. else {
  293. current_click = false;
  294. }
  295. }
  296. else if (current_click) {
  297. lcd_quick_feedback();
  298. wait_for_unclick = true;
  299. current_click = false;
  300. }
  301. }
  302. //if (--langsel ==0) {langsel=1;current_click=true;}
  303. if (current_click)
  304. {
  305. lcd_goto_menu(lcd_main_menu);
  306. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  307. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  308. currentMenu == lcd_status_screen
  309. #endif
  310. );
  311. #ifdef FILAMENT_LCD_DISPLAY
  312. message_millis = millis(); // get status message to show up for a while
  313. #endif
  314. }
  315. #ifdef ULTIPANEL_FEEDMULTIPLY
  316. // Dead zone at 100% feedrate
  317. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  318. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  319. {
  320. encoderPosition = 0;
  321. feedmultiply = 100;
  322. }
  323. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  324. {
  325. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  326. encoderPosition = 0;
  327. }
  328. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  329. {
  330. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  331. encoderPosition = 0;
  332. }
  333. else if (feedmultiply != 100)
  334. {
  335. feedmultiply += int(encoderPosition);
  336. encoderPosition = 0;
  337. }
  338. #endif //ULTIPANEL_FEEDMULTIPLY
  339. if (feedmultiply < 10)
  340. feedmultiply = 10;
  341. else if (feedmultiply > 999)
  342. feedmultiply = 999;
  343. #endif //ULTIPANEL
  344. }
  345. #ifdef ULTIPANEL
  346. void lcd_commands()
  347. {
  348. if (lcd_commands_type == 1) //// load filament sequence
  349. {
  350. if (lcd_commands_step == 0) { lcd_commands_step = 5; custom_message = true; }
  351. if (lcd_commands_step == 1 && !blocks_queued())
  352. {
  353. lcd_commands_step = 0;
  354. lcd_commands_type = 0;
  355. lcd_setstatuspgm(WELCOME_MSG);
  356. disable_z();
  357. custom_message = false;
  358. custom_message_type = 0;
  359. }
  360. if (lcd_commands_step == 2 && !blocks_queued())
  361. {
  362. lcd_setstatuspgm(MSG_LOADING_FILAMENT);
  363. enquecommand_P(PSTR(LOAD_FILAMENT_2));
  364. lcd_commands_step = 1;
  365. }
  366. if (lcd_commands_step == 3 && !blocks_queued())
  367. {
  368. enquecommand_P(PSTR(LOAD_FILAMENT_1));
  369. lcd_commands_step = 2;
  370. }
  371. if (lcd_commands_step == 4 && !blocks_queued())
  372. {
  373. lcd_setstatuspgm(MSG_INSERT_FILAMENT);
  374. enquecommand_P(PSTR(LOAD_FILAMENT_0));
  375. lcd_commands_step = 3;
  376. }
  377. if (lcd_commands_step == 5 && !blocks_queued())
  378. {
  379. lcd_setstatuspgm(MSG_PLEASE_WAIT);
  380. enable_z();
  381. custom_message = true;
  382. custom_message_type = 2;
  383. lcd_commands_step = 4;
  384. }
  385. }
  386. if (lcd_commands_type == 2) /// stop print
  387. {
  388. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  389. if (lcd_commands_step == 1 && !blocks_queued())
  390. {
  391. lcd_commands_step = 0;
  392. lcd_commands_type = 0;
  393. lcd_setstatuspgm(WELCOME_MSG);
  394. custom_message = false;
  395. }
  396. if (lcd_commands_step == 2 && !blocks_queued())
  397. {
  398. setTargetBed(0);
  399. setTargetHotend(0, 0);
  400. setTargetHotend(0, 1);
  401. setTargetHotend(0, 2);
  402. manage_heater();
  403. lcd_setstatuspgm(WELCOME_MSG);
  404. cancel_heatup = false;
  405. lcd_commands_step = 1;
  406. }
  407. if (lcd_commands_step == 3 && !blocks_queued())
  408. {
  409. enquecommand_P(PSTR("M84"));
  410. autotempShutdown();
  411. lcd_commands_step = 2;
  412. }
  413. if (lcd_commands_step == 4 && !blocks_queued())
  414. {
  415. enquecommand_P(PSTR("G90"));
  416. #ifdef X_CANCEL_POS
  417. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  418. #else
  419. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  420. #endif
  421. lcd_ignore_click(false);
  422. lcd_commands_step = 3;
  423. }
  424. if (lcd_commands_step == 5 && !blocks_queued())
  425. {
  426. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  427. enquecommand_P(PSTR("G91"));
  428. enquecommand_P(PSTR("G1 Z15 F1500"));
  429. lcd_commands_step = 4;
  430. }
  431. if (lcd_commands_step == 6 && !blocks_queued())
  432. {
  433. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  434. cancel_heatup = true;
  435. setTargetBed(0);
  436. setTargetHotend(0, 0);
  437. setTargetHotend(0, 1);
  438. setTargetHotend(0, 2);
  439. manage_heater();
  440. lcd_commands_step = 5;
  441. }
  442. }
  443. if (lcd_commands_type == 3)
  444. {
  445. lcd_commands_type = 0;
  446. }
  447. }
  448. static void lcd_return_to_status() {
  449. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  450. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  451. currentMenu == lcd_status_screen
  452. #endif
  453. );
  454. lcd_goto_menu(lcd_status_screen, 0, false);
  455. }
  456. static void lcd_sdcard_pause() {
  457. card.pauseSDPrint();
  458. isPrintPaused = true;
  459. lcdDrawUpdate = 3;
  460. }
  461. static void lcd_sdcard_resume() {
  462. card.startFileprint();
  463. isPrintPaused = false;
  464. lcdDrawUpdate = 3;
  465. }
  466. float move_menu_scale;
  467. static void lcd_move_menu_axis();
  468. /* Menu implementation */
  469. void lcd_preheat_pla()
  470. {
  471. setTargetHotend0(plaPreheatHotendTemp);
  472. setTargetBed(plaPreheatHPBTemp);
  473. fanSpeed = 0;
  474. lcd_return_to_status();
  475. setWatch(); // heater sanity check timer
  476. }
  477. void lcd_preheat_abs()
  478. {
  479. setTargetHotend0(absPreheatHotendTemp);
  480. setTargetBed(absPreheatHPBTemp);
  481. fanSpeed = 0;
  482. lcd_return_to_status();
  483. setWatch(); // heater sanity check timer
  484. }
  485. void lcd_preheat_pp()
  486. {
  487. setTargetHotend0(ppPreheatHotendTemp);
  488. setTargetBed(ppPreheatHPBTemp);
  489. fanSpeed = 0;
  490. lcd_return_to_status();
  491. setWatch(); // heater sanity check timer
  492. }
  493. void lcd_preheat_pet()
  494. {
  495. setTargetHotend0(petPreheatHotendTemp);
  496. setTargetBed(petPreheatHPBTemp);
  497. fanSpeed = 0;
  498. lcd_return_to_status();
  499. setWatch(); // heater sanity check timer
  500. }
  501. void lcd_preheat_hips()
  502. {
  503. setTargetHotend0(hipsPreheatHotendTemp);
  504. setTargetBed(hipsPreheatHPBTemp);
  505. fanSpeed = 0;
  506. lcd_return_to_status();
  507. setWatch(); // heater sanity check timer
  508. }
  509. void lcd_preheat_flex()
  510. {
  511. setTargetHotend0(flexPreheatHotendTemp);
  512. setTargetBed(flexPreheatHPBTemp);
  513. fanSpeed = 0;
  514. lcd_return_to_status();
  515. setWatch(); // heater sanity check timer
  516. }
  517. void lcd_cooldown()
  518. {
  519. setTargetHotend0(0);
  520. setTargetHotend1(0);
  521. setTargetHotend2(0);
  522. setTargetBed(0);
  523. fanSpeed = 0;
  524. lcd_return_to_status();
  525. }
  526. static void lcd_preheat_menu()
  527. {
  528. START_MENU();
  529. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  530. MENU_ITEM(function, PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  531. MENU_ITEM(function, PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  532. MENU_ITEM(function, PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  533. MENU_ITEM(function, PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  534. MENU_ITEM(function, PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  535. MENU_ITEM(function, PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  536. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  537. END_MENU();
  538. }
  539. static void lcd_support_menu()
  540. {
  541. START_MENU();
  542. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  543. MENU_ITEM(back, PSTR(MSG_FW_VERSION " - " FW_version), lcd_main_menu);
  544. MENU_ITEM(back, MSG_PRUSA3D, lcd_main_menu);
  545. MENU_ITEM(back, MSG_PRUSA3D_FORUM, lcd_main_menu);
  546. MENU_ITEM(back, MSG_PRUSA3D_HOWTO, lcd_main_menu);
  547. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  548. MENU_ITEM(back, PSTR(FILAMENT_SIZE), lcd_main_menu);
  549. MENU_ITEM(back, PSTR(ELECTRONICS),lcd_main_menu);
  550. MENU_ITEM(back, PSTR(NOZZLE_TYPE),lcd_main_menu);
  551. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  552. MENU_ITEM(back, PSTR("Date: "), lcd_main_menu);
  553. MENU_ITEM(back, PSTR(__DATE__), lcd_main_menu);
  554. END_MENU();
  555. }
  556. void lcd_unLoadFilament()
  557. {
  558. if (degHotend0() > EXTRUDE_MINTEMP) {
  559. enquecommand_P(PSTR(UNLOAD_FILAMENT_0));
  560. enquecommand_P(PSTR(UNLOAD_FILAMENT_1));
  561. } else {
  562. lcd_implementation_clear();
  563. lcd.setCursor(0, 0);
  564. lcd_printPGM(MSG_ERROR);
  565. lcd.setCursor(0, 2);
  566. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  567. delay(2000);
  568. lcd_implementation_clear();
  569. }
  570. lcd_return_to_status();
  571. }
  572. void lcd_change_filament() {
  573. lcd_implementation_clear();
  574. lcd.setCursor(0, 1);
  575. lcd_printPGM(MSG_CHANGING_FILAMENT);
  576. }
  577. void lcd_wait_interact() {
  578. lcd_implementation_clear();
  579. lcd.setCursor(0, 1);
  580. lcd_printPGM(MSG_INSERT_FILAMENT);
  581. lcd.setCursor(0, 2);
  582. lcd_printPGM(MSG_PRESS);
  583. }
  584. void lcd_change_success() {
  585. lcd_implementation_clear();
  586. lcd.setCursor(0, 2);
  587. lcd_printPGM(MSG_CHANGE_SUCCESS);
  588. }
  589. void lcd_loading_color() {
  590. lcd_implementation_clear();
  591. lcd.setCursor(0, 0);
  592. lcd_printPGM(MSG_LOADING_COLOR);
  593. lcd.setCursor(0, 2);
  594. lcd_printPGM(MSG_PLEASE_WAIT);
  595. for (int i = 0; i < 20; i++) {
  596. lcd.setCursor(i, 3);
  597. lcd.print(".");
  598. for (int j = 0; j < 10 ; j++) {
  599. manage_heater();
  600. manage_inactivity(true);
  601. delay(85);
  602. }
  603. }
  604. }
  605. void lcd_loading_filament() {
  606. lcd_implementation_clear();
  607. lcd.setCursor(0, 0);
  608. lcd_printPGM(MSG_LOADING_FILAMENT);
  609. lcd.setCursor(0, 2);
  610. lcd_printPGM(MSG_PLEASE_WAIT);
  611. for (int i = 0; i < 20; i++) {
  612. lcd.setCursor(i, 3);
  613. lcd.print(".");
  614. for (int j = 0; j < 10 ; j++) {
  615. manage_heater();
  616. manage_inactivity(true);
  617. delay(110);
  618. }
  619. }
  620. }
  621. void lcd_alright() {
  622. int enc_dif = 0;
  623. int cursor_pos = 1;
  624. lcd_implementation_clear();
  625. lcd.setCursor(0, 0);
  626. lcd_printPGM(MSG_CORRECTLY);
  627. lcd.setCursor(1, 1);
  628. lcd_printPGM(MSG_YES);
  629. lcd.setCursor(1, 2);
  630. lcd_printPGM(MSG_NOT_LOADED);
  631. lcd.setCursor(1, 3);
  632. lcd_printPGM(MSG_NOT_COLOR);
  633. lcd.setCursor(0, 1);
  634. lcd.print(">");
  635. enc_dif = encoderDiff;
  636. while (lcd_change_fil_state == 0) {
  637. manage_heater();
  638. manage_inactivity(true);
  639. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  640. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  641. if (enc_dif > encoderDiff ) {
  642. cursor_pos --;
  643. }
  644. if (enc_dif < encoderDiff ) {
  645. cursor_pos ++;
  646. }
  647. if (cursor_pos > 3) {
  648. cursor_pos = 3;
  649. }
  650. if (cursor_pos < 1) {
  651. cursor_pos = 1;
  652. }
  653. lcd.setCursor(0, 1);
  654. lcd.print(" ");
  655. lcd.setCursor(0, 2);
  656. lcd.print(" ");
  657. lcd.setCursor(0, 3);
  658. lcd.print(" ");
  659. lcd.setCursor(0, cursor_pos);
  660. lcd.print(">");
  661. enc_dif = encoderDiff;
  662. delay(100);
  663. }
  664. }
  665. if (lcd_clicked()) {
  666. lcd_change_fil_state = cursor_pos;
  667. delay(500);
  668. }
  669. };
  670. lcd_implementation_clear();
  671. lcd_return_to_status();
  672. }
  673. void lcd_LoadFilament()
  674. {
  675. if (degHotend0() > EXTRUDE_MINTEMP)
  676. {
  677. custom_message = true;
  678. lcd_commands_type = 1;
  679. SERIAL_ECHOLN("Loading filament");
  680. // commands() will handle the rest
  681. }
  682. else
  683. {
  684. lcd_implementation_clear();
  685. lcd.setCursor(0, 0);
  686. lcd_printPGM(MSG_ERROR);
  687. lcd.setCursor(0, 2);
  688. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  689. delay(2000);
  690. lcd_implementation_clear();
  691. }
  692. lcd_return_to_status();
  693. }
  694. static void lcd_menu_statistics()
  695. {
  696. if (IS_SD_PRINTING)
  697. {
  698. int _met = total_filament_used / 100000;
  699. int _cm = (total_filament_used - (_met * 100000))/10;
  700. int _t = (millis() - starttime) / 1000;
  701. int _h = _t / 3600;
  702. int _m = (_t - (_h * 60)) / 60;
  703. int _s = _t - ((_h * 3600) + (_m * 60));
  704. lcd.setCursor(0, 0);
  705. lcd_printPGM(MSG_STATS_FILAMENTUSED);
  706. lcd.setCursor(6, 1);
  707. lcd.print(itostr3(_met));
  708. lcd.print("m ");
  709. lcd.print(ftostr32ns(_cm));
  710. lcd.print("cm");
  711. lcd.setCursor(0, 2);
  712. lcd_printPGM(MSG_STATS_PRINTTIME);
  713. lcd.setCursor(8, 3);
  714. lcd.print(itostr2(_h));
  715. lcd.print("h ");
  716. lcd.print(itostr2(_m));
  717. lcd.print("m ");
  718. lcd.print(itostr2(_s));
  719. lcd.print("s");
  720. if (lcd_clicked())
  721. {
  722. lcd_quick_feedback();
  723. lcd_return_to_status();
  724. }
  725. }
  726. else
  727. {
  728. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  729. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME);
  730. uint8_t _days, _hours, _minutes;
  731. float _filament_m = (float)_filament;
  732. int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  733. if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  734. _days = _time / 1440;
  735. _hours = (_time - (_days * 1440)) / 60;
  736. _minutes = _time - ((_days * 1440) + (_hours * 60));
  737. lcd_implementation_clear();
  738. lcd.setCursor(0, 0);
  739. lcd_printPGM(MSG_STATS_TOTALFILAMENT);
  740. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)), 1);
  741. lcd.print(ftostr32ns(_filament_m));
  742. if (_filament_km > 0)
  743. {
  744. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 3, 1);
  745. lcd.print("km");
  746. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 8, 1);
  747. lcd.print(itostr4(_filament_km));
  748. }
  749. lcd.setCursor(18, 1);
  750. lcd.print("m");
  751. lcd.setCursor(0, 2);
  752. lcd_printPGM(MSG_STATS_TOTALPRINTTIME);;
  753. lcd.setCursor(18, 3);
  754. lcd.print("m");
  755. lcd.setCursor(14, 3);
  756. lcd.print(itostr3(_minutes));
  757. lcd.setCursor(14, 3);
  758. lcd.print(":");
  759. lcd.setCursor(12, 3);
  760. lcd.print("h");
  761. lcd.setCursor(9, 3);
  762. lcd.print(itostr3(_hours));
  763. lcd.setCursor(9, 3);
  764. lcd.print(":");
  765. lcd.setCursor(7, 3);
  766. lcd.print("d");
  767. lcd.setCursor(4, 3);
  768. lcd.print(itostr3(_days));
  769. while (!lcd_clicked())
  770. {
  771. manage_heater();
  772. manage_inactivity(true);
  773. delay(100);
  774. }
  775. lcd_quick_feedback();
  776. lcd_return_to_status();
  777. }
  778. }
  779. static void _lcd_move(const char *name, int axis, int min, int max) {
  780. if (encoderPosition != 0) {
  781. refresh_cmd_timeout();
  782. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  783. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  784. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  785. encoderPosition = 0;
  786. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  787. 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);
  788. lcdDrawUpdate = 1;
  789. }
  790. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  791. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  792. }
  793. static void lcd_move_e()
  794. {
  795. if (encoderPosition != 0)
  796. {
  797. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  798. encoderPosition = 0;
  799. 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);
  800. lcdDrawUpdate = 1;
  801. }
  802. if (lcdDrawUpdate)
  803. {
  804. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  805. }
  806. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  807. }
  808. // Save a single axis babystep value.
  809. void EEPROM_save_B(int pos, int* value)
  810. {
  811. union Data data;
  812. data.value = *value;
  813. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  814. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  815. }
  816. // Read a single axis babystep value.
  817. void EEPROM_read_B(int pos, int* value)
  818. {
  819. union Data data;
  820. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  821. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  822. *value = data.value;
  823. }
  824. static void lcd_move_x() {
  825. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  826. }
  827. static void lcd_move_y() {
  828. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  829. }
  830. static void lcd_move_z() {
  831. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  832. }
  833. static void _lcd_babystep(int axis, const char *msg) {
  834. if (encoderPosition != 0)
  835. {
  836. babystepsTodo[axis] += (int)encoderPosition;
  837. babystepMem[axis] += (int)encoderPosition;
  838. babystepMemMM[axis] = babystepMem[axis]/axis_steps_per_unit[Z_AXIS];
  839. delay(50);
  840. encoderPosition = 0;
  841. lcdDrawUpdate = 1;
  842. }
  843. if (lcdDrawUpdate) lcd_implementation_drawedit_2(msg, ftostr13ns(babystepMemMM[axis]));
  844. if (LCD_CLICKED || menuExiting) {
  845. // Only update the EEPROM when leaving the menu.
  846. EEPROM_save_B(
  847. (axis == 0) ? EEPROM_BABYSTEP_X : ((axis == 1) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  848. &babystepMem[axis]);
  849. }
  850. if (LCD_CLICKED) lcd_goto_menu(lcd_main_menu);
  851. }
  852. static void lcd_babystep_x() {
  853. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  854. }
  855. static void lcd_babystep_y() {
  856. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  857. }
  858. static void lcd_babystep_z() {
  859. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  860. }
  861. void lcd_adjust_z() {
  862. int enc_dif = 0;
  863. int cursor_pos = 1;
  864. int fsm = 0;
  865. lcd_implementation_clear();
  866. lcd.setCursor(0, 0);
  867. lcd_printPGM(MSG_ADJUSTZ);
  868. lcd.setCursor(1, 1);
  869. lcd_printPGM(MSG_YES);
  870. lcd.setCursor(1, 2);
  871. lcd_printPGM(MSG_NO);
  872. lcd.setCursor(0, 1);
  873. lcd.print(">");
  874. enc_dif = encoderDiff;
  875. while (fsm == 0) {
  876. manage_heater();
  877. manage_inactivity(true);
  878. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  879. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  880. if (enc_dif > encoderDiff ) {
  881. cursor_pos --;
  882. }
  883. if (enc_dif < encoderDiff ) {
  884. cursor_pos ++;
  885. }
  886. if (cursor_pos > 2) {
  887. cursor_pos = 2;
  888. }
  889. if (cursor_pos < 1) {
  890. cursor_pos = 1;
  891. }
  892. lcd.setCursor(0, 1);
  893. lcd.print(" ");
  894. lcd.setCursor(0, 2);
  895. lcd.print(" ");
  896. lcd.setCursor(0, cursor_pos);
  897. lcd.print(">");
  898. enc_dif = encoderDiff;
  899. delay(100);
  900. }
  901. }
  902. if (lcd_clicked()) {
  903. fsm = cursor_pos;
  904. if (fsm == 1) {
  905. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  906. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  907. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  908. babystepsTodo[Z_AXIS] = babystepMem[2];
  909. } else {
  910. babystepMem[0] = 0;
  911. babystepMem[1] = 0;
  912. babystepMem[2] = 0;
  913. EEPROM_save_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  914. EEPROM_save_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  915. EEPROM_save_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  916. }
  917. delay(500);
  918. }
  919. };
  920. lcd_implementation_clear();
  921. lcd_return_to_status();
  922. }
  923. // Lets the user move the Z carriage up to the end stoppers.
  924. // When done, it sets the current Z to Z_MAX_POS and returns true.
  925. // Otherwise the Z calibration is not changed and false is returned.
  926. bool lcd_calibrate_z_end_stop_manual()
  927. {
  928. bool clean_nozzle_asked = false;
  929. // Don't know where we are. Let's claim we are Z=0, so the soft end stops will not be triggered when moving up.
  930. current_position[Z_AXIS] = 0;
  931. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  932. // Until confirmed by the confirmation dialog.
  933. for (;;) {
  934. unsigned long previous_millis_cmd = millis();
  935. lcd_display_message_fullscreen_P(MSG_MOVE_CARRIAGE_TO_THE_TOP);
  936. // Until the user finishes the z up movement.
  937. encoderDiff = 0;
  938. encoderPosition = 0;
  939. for (;;) {
  940. if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  941. goto canceled;
  942. manage_heater();
  943. manage_inactivity(true);
  944. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  945. delay(50);
  946. previous_millis_cmd = millis();
  947. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  948. encoderDiff = 0;
  949. // Only move up, whatever the user does.
  950. current_position[Z_AXIS] += fabs(encoderPosition);
  951. encoderPosition = 0;
  952. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[Z_AXIS] / 60, active_extruder);
  953. // Wait for the motors to stop.
  954. st_synchronize();
  955. // Claim we are at Z=0, so the soft end stop will not trigger.
  956. current_position[Z_AXIS] = 0;
  957. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  958. }
  959. if (lcd_clicked()) {
  960. // Wait until the Z up movement is finished.
  961. st_synchronize();
  962. while (lcd_clicked()) ;
  963. delay(10);
  964. while (lcd_clicked()) ;
  965. break;
  966. }
  967. }
  968. if (! clean_nozzle_asked) {
  969. lcd_show_fullscreen_message_and_wait_P(MSG_CONFIRM_NOZZLE_CLEAN);
  970. clean_nozzle_asked = true;
  971. }
  972. // Let the user confirm, that the Z carriage is at the top end stoppers.
  973. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CONFIRM_CARRIAGE_AT_THE_TOP);
  974. if (result == -1)
  975. goto canceled;
  976. else if (result == 1)
  977. goto calibrated;
  978. // otherwise perform another round of the Z up dialog.
  979. }
  980. calibrated:
  981. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  982. // during the search for the induction points.
  983. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  984. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  985. return true;
  986. canceled:
  987. return false;
  988. }
  989. static inline bool pgm_is_whitespace(const char *c)
  990. {
  991. return pgm_read_byte(c) == ' ' || pgm_read_byte(c) == '\t' || pgm_read_byte(c) == '\r' || pgm_read_byte(c) == '\n';
  992. }
  993. void lcd_display_message_fullscreen_P(const char *msg)
  994. {
  995. // Disable update of the screen by the usual lcd_update() routine.
  996. lcd_update_enable(false);
  997. lcd_implementation_clear();
  998. lcd.setCursor(0, 0);
  999. for (int8_t row = 0; row < 4; ++ row) {
  1000. while (pgm_is_whitespace(msg))
  1001. ++ msg;
  1002. if (pgm_read_byte(msg) == 0)
  1003. // End of the message.
  1004. break;
  1005. lcd.setCursor(0, row);
  1006. const char *msgend2 = msg + min(strlen_P(msg), 20);
  1007. const char *msgend = msgend2;
  1008. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend)) {
  1009. // Splitting a word. Find the start of the current word.
  1010. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  1011. -- msgend;
  1012. if (msgend == msg)
  1013. // Found a single long word, which cannot be split. Just cut it.
  1014. msgend = msgend2;
  1015. }
  1016. for (; msg < msgend; ++ msg) {
  1017. char c = char(pgm_read_byte(msg));
  1018. if (c == '~')
  1019. c = ' ';
  1020. lcd.print(c);
  1021. }
  1022. }
  1023. }
  1024. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  1025. {
  1026. lcd_display_message_fullscreen_P(msg);
  1027. // Until confirmed by a button click.
  1028. for (;;) {
  1029. delay_keep_alive(50);
  1030. if (lcd_clicked()) {
  1031. while (lcd_clicked()) ;
  1032. delay(10);
  1033. while (lcd_clicked()) ;
  1034. break;
  1035. }
  1036. }
  1037. }
  1038. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting)
  1039. {
  1040. lcd_display_message_fullscreen_P(msg);
  1041. lcd.setCursor(1, 2);
  1042. lcd_printPGM(MSG_YES);
  1043. lcd.setCursor(0, 3);
  1044. lcd_printPGM(PSTR(">"));
  1045. lcd_printPGM(MSG_NO);
  1046. bool yes = false;
  1047. // Wait for user confirmation or a timeout.
  1048. unsigned long previous_millis_cmd = millis();
  1049. int8_t enc_dif = encoderDiff;
  1050. for (;;) {
  1051. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1052. return -1;
  1053. manage_heater();
  1054. manage_inactivity(true);
  1055. if (abs((enc_dif - encoderDiff)) > 4) {
  1056. if (abs(enc_dif - encoderDiff) > 1) {
  1057. lcd.setCursor(0, 2);
  1058. if (enc_dif > encoderDiff && yes) {
  1059. lcd_printPGM((PSTR(" ")));
  1060. lcd.setCursor(0, 3);
  1061. lcd_printPGM((PSTR(">")));
  1062. yes = false;
  1063. } else if (enc_dif < encoderDiff && ! yes) {
  1064. lcd_printPGM((PSTR(">")));
  1065. lcd.setCursor(0, 3);
  1066. lcd_printPGM((PSTR(" ")));
  1067. yes = true;
  1068. }
  1069. enc_dif = encoderDiff;
  1070. }
  1071. }
  1072. if (lcd_clicked()) {
  1073. while (lcd_clicked()) ;
  1074. delay(10);
  1075. while (lcd_clicked()) ;
  1076. return yes;
  1077. }
  1078. }
  1079. }
  1080. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  1081. {
  1082. const char *msg = NULL;
  1083. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  1084. lcd_show_fullscreen_message_and_wait_P(MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND);
  1085. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  1086. if (point_too_far_mask == 0)
  1087. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1088. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1089. // Only the center point or all the three front points.
  1090. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR;
  1091. else if (point_too_far_mask & 1 == 0)
  1092. // The right and maybe the center point out of reach.
  1093. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR;
  1094. else
  1095. // The left and maybe the center point out of reach.
  1096. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR;
  1097. lcd_show_fullscreen_message_and_wait_P(msg);
  1098. } else {
  1099. if (point_too_far_mask != 0) {
  1100. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1101. // Only the center point or all the three front points.
  1102. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR;
  1103. else if (point_too_far_mask & 1 == 0)
  1104. // The right and maybe the center point out of reach.
  1105. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR;
  1106. else
  1107. // The left and maybe the center point out of reach.
  1108. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR;
  1109. lcd_show_fullscreen_message_and_wait_P(msg);
  1110. }
  1111. if (point_too_far_mask == 0 || result > 0) {
  1112. switch (result) {
  1113. default:
  1114. // should not happen
  1115. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1116. break;
  1117. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  1118. msg = MSG_BED_SKEW_OFFSET_DETECTION_PERFECT;
  1119. break;
  1120. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  1121. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD;
  1122. break;
  1123. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  1124. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
  1125. break;
  1126. }
  1127. lcd_show_fullscreen_message_and_wait_P(msg);
  1128. }
  1129. }
  1130. }
  1131. static void lcd_show_end_stops() {
  1132. lcd.setCursor(0, 0);
  1133. lcd_printPGM((PSTR("End stops diag")));
  1134. lcd.setCursor(0, 1);
  1135. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  1136. lcd.setCursor(0, 2);
  1137. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  1138. lcd.setCursor(0, 3);
  1139. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  1140. }
  1141. static void menu_show_end_stops() {
  1142. lcd_show_end_stops();
  1143. if (LCD_CLICKED) lcd_goto_menu(lcd_settings_menu);
  1144. }
  1145. // Lets the user move the Z carriage up to the end stoppers.
  1146. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1147. // Otherwise the Z calibration is not changed and false is returned.
  1148. void lcd_diag_show_end_stops()
  1149. {
  1150. int enc_dif = encoderDiff;
  1151. lcd_implementation_clear();
  1152. for (;;) {
  1153. manage_heater();
  1154. manage_inactivity(true);
  1155. lcd_show_end_stops();
  1156. if (lcd_clicked()) {
  1157. while (lcd_clicked()) ;
  1158. delay(10);
  1159. while (lcd_clicked()) ;
  1160. break;
  1161. }
  1162. }
  1163. lcd_implementation_clear();
  1164. lcd_return_to_status();
  1165. }
  1166. void lcd_pick_babystep(){
  1167. int enc_dif = 0;
  1168. int cursor_pos = 1;
  1169. int fsm = 0;
  1170. lcd_implementation_clear();
  1171. lcd.setCursor(0, 0);
  1172. lcd_printPGM(MSG_PICK_Z);
  1173. lcd.setCursor(3, 2);
  1174. lcd.print("1");
  1175. lcd.setCursor(3, 3);
  1176. lcd.print("2");
  1177. lcd.setCursor(12, 2);
  1178. lcd.print("3");
  1179. lcd.setCursor(12, 3);
  1180. lcd.print("4");
  1181. lcd.setCursor(1, 2);
  1182. lcd.print(">");
  1183. enc_dif = encoderDiff;
  1184. while (fsm == 0) {
  1185. manage_heater();
  1186. manage_inactivity(true);
  1187. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1188. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1189. if (enc_dif > encoderDiff ) {
  1190. cursor_pos --;
  1191. }
  1192. if (enc_dif < encoderDiff ) {
  1193. cursor_pos ++;
  1194. }
  1195. if (cursor_pos > 4) {
  1196. cursor_pos = 4;
  1197. }
  1198. if (cursor_pos < 1) {
  1199. cursor_pos = 1;
  1200. }
  1201. lcd.setCursor(1, 2);
  1202. lcd.print(" ");
  1203. lcd.setCursor(1, 3);
  1204. lcd.print(" ");
  1205. lcd.setCursor(10, 2);
  1206. lcd.print(" ");
  1207. lcd.setCursor(10, 3);
  1208. lcd.print(" ");
  1209. if (cursor_pos < 3) {
  1210. lcd.setCursor(1, cursor_pos+1);
  1211. lcd.print(">");
  1212. }else{
  1213. lcd.setCursor(10, cursor_pos-1);
  1214. lcd.print(">");
  1215. }
  1216. enc_dif = encoderDiff;
  1217. delay(100);
  1218. }
  1219. }
  1220. if (lcd_clicked()) {
  1221. fsm = cursor_pos;
  1222. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babystepMem[2]);
  1223. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babystepMem[2]);
  1224. eeprom_write_byte((unsigned char*)EEPROM_BABYSTEP_Z_SET, 0x01);
  1225. delay(500);
  1226. }
  1227. };
  1228. lcd_implementation_clear();
  1229. lcd_return_to_status();
  1230. }
  1231. void lcd_move_menu_axis()
  1232. {
  1233. START_MENU();
  1234. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1235. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  1236. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  1237. if (move_menu_scale < 10.0)
  1238. {
  1239. if (!isPrintPaused)
  1240. {
  1241. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1242. }
  1243. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1244. }
  1245. END_MENU();
  1246. }
  1247. static void lcd_move_menu_1mm()
  1248. {
  1249. move_menu_scale = 1.0;
  1250. lcd_move_menu_axis();
  1251. }
  1252. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  1253. {
  1254. do
  1255. {
  1256. eeprom_write_byte((unsigned char*)pos, *value);
  1257. pos++;
  1258. value++;
  1259. } while (--size);
  1260. }
  1261. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  1262. {
  1263. do
  1264. {
  1265. *value = eeprom_read_byte((unsigned char*)pos);
  1266. pos++;
  1267. value++;
  1268. } while (--size);
  1269. }
  1270. static void lcd_silent_mode_set() {
  1271. SilentModeMenu = !SilentModeMenu;
  1272. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1273. digipot_init();
  1274. lcd_goto_menu(lcd_settings_menu, 7);
  1275. }
  1276. static void lcd_set_lang(unsigned char lang) {
  1277. lang_selected = lang;
  1278. firstrun = 1;
  1279. eeprom_write_byte((unsigned char *)EEPROM_LANG, lang);/*langsel=0;*/if (langsel == 1)langsel = 2;
  1280. }
  1281. void lcd_force_language_selection() {
  1282. eeprom_write_byte((unsigned char *)EEPROM_LANG, 255);
  1283. }
  1284. static void lcd_language_menu()
  1285. {
  1286. START_MENU();
  1287. if (!langsel) {
  1288. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1289. }
  1290. if (langsel == 2) {
  1291. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1292. }
  1293. for (int i=0;i<LANG_NUM;i++){
  1294. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  1295. }
  1296. //MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(1), 1);
  1297. END_MENU();
  1298. }
  1299. void lcd_mesh_bedleveling()
  1300. {
  1301. enquecommand_P(PSTR("G80"));
  1302. lcd_return_to_status();
  1303. }
  1304. void lcd_mesh_calibration()
  1305. {
  1306. enquecommand_P(PSTR("M45"));
  1307. lcd_return_to_status();
  1308. }
  1309. static void lcd_settings_menu()
  1310. {
  1311. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1312. START_MENU();
  1313. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1314. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1315. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  1316. if (!isPrintPaused)
  1317. {
  1318. #ifndef MESH_BED_LEVELING
  1319. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  1320. #else
  1321. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_bedleveling);
  1322. #endif
  1323. }
  1324. if (!isPrintPaused)
  1325. {
  1326. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1327. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1328. }
  1329. if (SilentModeMenu == 0) {
  1330. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  1331. } else {
  1332. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  1333. }
  1334. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  1335. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  1336. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  1337. babystepMemMM[2] = babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  1338. if (!isPrintPaused)
  1339. {
  1340. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1341. }
  1342. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  1343. if (!isPrintPaused)
  1344. {
  1345. MENU_ITEM(submenu, MSG_SELFTEST, lcd_selftest);
  1346. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  1347. MENU_ITEM(submenu, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  1348. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  1349. }
  1350. END_MENU();
  1351. }
  1352. /*
  1353. void lcd_mylang_top(int hlaska) {
  1354. lcd.setCursor(0,0);
  1355. lcd.print(" ");
  1356. lcd.setCursor(0,0);
  1357. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  1358. }
  1359. void lcd_mylang_drawmenu(int cursor) {
  1360. int first = 0;
  1361. if (cursor>2) first = cursor-2;
  1362. if (cursor==LANG_NUM) first = LANG_NUM-3;
  1363. lcd.setCursor(0, 1);
  1364. lcd.print(" ");
  1365. lcd.setCursor(1, 1);
  1366. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  1367. lcd.setCursor(0, 2);
  1368. lcd.print(" ");
  1369. lcd.setCursor(1, 2);
  1370. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  1371. lcd.setCursor(0, 3);
  1372. lcd.print(" ");
  1373. lcd.setCursor(1, 3);
  1374. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  1375. if (cursor==1) lcd.setCursor(0, 1);
  1376. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  1377. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  1378. lcd.print(">");
  1379. if (cursor<LANG_NUM-1) {
  1380. lcd.setCursor(19,3);
  1381. lcd.print("\x01");
  1382. }
  1383. if (cursor>2) {
  1384. lcd.setCursor(19,1);
  1385. lcd.print("^");
  1386. }
  1387. }
  1388. */
  1389. void lcd_mylang_drawmenu(int cursor) {
  1390. int first = 0;
  1391. if (cursor>3) first = cursor-3;
  1392. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  1393. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  1394. lcd.setCursor(0, 0);
  1395. lcd.print(" ");
  1396. lcd.setCursor(1, 0);
  1397. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  1398. lcd.setCursor(0, 1);
  1399. lcd.print(" ");
  1400. lcd.setCursor(1, 1);
  1401. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  1402. lcd.setCursor(0, 2);
  1403. lcd.print(" ");
  1404. if (LANG_NUM > 2){
  1405. lcd.setCursor(1, 2);
  1406. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  1407. }
  1408. lcd.setCursor(0, 3);
  1409. lcd.print(" ");
  1410. if (LANG_NUM>3) {
  1411. lcd.setCursor(1, 3);
  1412. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  1413. }
  1414. if (cursor==1) lcd.setCursor(0, 0);
  1415. if (cursor==2) lcd.setCursor(0, 1);
  1416. if (cursor>2) lcd.setCursor(0, 2);
  1417. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  1418. lcd.print(">");
  1419. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  1420. lcd.setCursor(19,3);
  1421. lcd.print("\x01");
  1422. }
  1423. if (cursor>3 && LANG_NUM>4) {
  1424. lcd.setCursor(19,0);
  1425. lcd.print("^");
  1426. }
  1427. }
  1428. void lcd_set_custom_characters_arrows();
  1429. void lcd_set_custom_characters_degree();
  1430. void lcd_mylang_drawcursor(int cursor) {
  1431. if (cursor==1) lcd.setCursor(0, 1);
  1432. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  1433. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  1434. lcd.print(">");
  1435. }
  1436. void lcd_mylang() {
  1437. int enc_dif = 0;
  1438. int cursor_pos = 1;
  1439. lang_selected=255;
  1440. int hlaska=1;
  1441. int counter=0;
  1442. lcd_set_custom_characters_arrows();
  1443. lcd_implementation_clear();
  1444. //lcd_mylang_top(hlaska);
  1445. lcd_mylang_drawmenu(cursor_pos);
  1446. enc_dif = encoderDiff;
  1447. while ( (lang_selected == 255) && (MYSERIAL.available() < 2) ) {
  1448. manage_heater();
  1449. manage_inactivity(true);
  1450. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1451. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1452. if (enc_dif > encoderDiff ) {
  1453. cursor_pos --;
  1454. }
  1455. if (enc_dif < encoderDiff ) {
  1456. cursor_pos ++;
  1457. }
  1458. if (cursor_pos > LANG_NUM) {
  1459. cursor_pos = LANG_NUM;
  1460. }
  1461. if (cursor_pos < 1) {
  1462. cursor_pos = 1;
  1463. }
  1464. lcd_mylang_drawmenu(cursor_pos);
  1465. enc_dif = encoderDiff;
  1466. delay(100);
  1467. //}
  1468. } else delay(20);
  1469. if (lcd_clicked()) {
  1470. lcd_set_lang(cursor_pos-1);
  1471. delay(500);
  1472. }
  1473. /*
  1474. if (++counter == 80) {
  1475. hlaska++;
  1476. if(hlaska>LANG_NUM) hlaska=1;
  1477. lcd_mylang_top(hlaska);
  1478. lcd_mylang_drawcursor(cursor_pos);
  1479. counter=0;
  1480. }
  1481. */
  1482. };
  1483. if(MYSERIAL.available() > 1){
  1484. lang_selected = 0;
  1485. firstrun = 0;
  1486. }
  1487. lcd_set_custom_characters_degree();
  1488. lcd_implementation_clear();
  1489. lcd_return_to_status();
  1490. }
  1491. static void lcd_main_menu()
  1492. {
  1493. SDscrool = 0;
  1494. /*
  1495. if (langsel == 1)
  1496. {
  1497. lcd_goto_menu(lcd_language_menu);
  1498. }
  1499. */
  1500. START_MENU();
  1501. // Majkl superawesome menu
  1502. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1503. if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < 0.5) )
  1504. {
  1505. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  1506. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  1507. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  1508. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1509. }
  1510. if ( movesplanned() || IS_SD_PRINTING || is_usb_printing )
  1511. {
  1512. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  1513. } else
  1514. {
  1515. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  1516. }
  1517. #ifdef SDSUPPORT
  1518. if (card.cardOK)
  1519. {
  1520. if (card.isFileOpen())
  1521. {
  1522. if (card.sdprinting)
  1523. {
  1524. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  1525. }
  1526. else
  1527. {
  1528. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  1529. }
  1530. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  1531. }
  1532. else
  1533. {
  1534. if (!is_usb_printing)
  1535. {
  1536. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  1537. }
  1538. #if SDCARDDETECT < 1
  1539. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  1540. #endif
  1541. }
  1542. } else
  1543. {
  1544. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  1545. #if SDCARDDETECT < 1
  1546. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  1547. #endif
  1548. }
  1549. #endif
  1550. if (IS_SD_PRINTING || is_usb_printing)
  1551. {
  1552. }
  1553. else
  1554. {
  1555. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  1556. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  1557. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  1558. }
  1559. if (!is_usb_printing)
  1560. {
  1561. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  1562. }
  1563. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  1564. END_MENU();
  1565. }
  1566. #ifdef SDSUPPORT
  1567. static void lcd_autostart_sd()
  1568. {
  1569. card.lastnr = 0;
  1570. card.setroot();
  1571. card.checkautostart(true);
  1572. }
  1573. #endif
  1574. static void lcd_silent_mode_set_tune() {
  1575. SilentModeMenu = !SilentModeMenu;
  1576. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1577. digipot_init();
  1578. lcd_goto_menu(lcd_tune_menu, 9);
  1579. }
  1580. static void lcd_tune_menu()
  1581. {
  1582. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1583. START_MENU();
  1584. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  1585. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  1586. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  1587. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  1588. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  1589. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  1590. #ifdef FILAMENTCHANGEENABLE
  1591. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));//7
  1592. #endif
  1593. if (SilentModeMenu == 0) {
  1594. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  1595. } else {
  1596. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  1597. }
  1598. END_MENU();
  1599. }
  1600. static void lcd_move_menu_01mm()
  1601. {
  1602. move_menu_scale = 0.1;
  1603. lcd_move_menu_axis();
  1604. }
  1605. static void lcd_control_temperature_menu()
  1606. {
  1607. #ifdef PIDTEMP
  1608. // set up temp variables - undo the default scaling
  1609. raw_Ki = unscalePID_i(Ki);
  1610. raw_Kd = unscalePID_d(Kd);
  1611. #endif
  1612. START_MENU();
  1613. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1614. //MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1615. #if TEMP_SENSOR_0 != 0
  1616. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  1617. #endif
  1618. #if TEMP_SENSOR_1 != 0
  1619. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  1620. #endif
  1621. #if TEMP_SENSOR_2 != 0
  1622. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  1623. #endif
  1624. #if TEMP_SENSOR_BED != 0
  1625. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  1626. #endif
  1627. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  1628. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  1629. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  1630. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  1631. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  1632. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  1633. #endif
  1634. END_MENU();
  1635. }
  1636. #if SDCARDDETECT == -1
  1637. static void lcd_sd_refresh()
  1638. {
  1639. card.initsd();
  1640. currentMenuViewOffset = 0;
  1641. }
  1642. #endif
  1643. static void lcd_sd_updir()
  1644. {
  1645. SDscrool = 0;
  1646. card.updir();
  1647. currentMenuViewOffset = 0;
  1648. }
  1649. void lcd_sdcard_stop()
  1650. {
  1651. lcd.setCursor(0, 0);
  1652. lcd_printPGM(MSG_STOP_PRINT);
  1653. lcd.setCursor(2, 2);
  1654. lcd_printPGM(MSG_NO);
  1655. lcd.setCursor(2, 3);
  1656. lcd_printPGM(MSG_YES);
  1657. lcd.setCursor(0, 2); lcd.print(" ");
  1658. lcd.setCursor(0, 3); lcd.print(" ");
  1659. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  1660. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  1661. lcd.setCursor(0, 1 + encoderPosition);
  1662. lcd.print(">");
  1663. if (lcd_clicked())
  1664. {
  1665. if ((int32_t)encoderPosition == 1)
  1666. {
  1667. lcd_return_to_status();
  1668. }
  1669. if ((int32_t)encoderPosition == 2)
  1670. {
  1671. cancel_heatup = true;
  1672. quickStop();
  1673. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  1674. card.sdprinting = false;
  1675. card.closefile();
  1676. stoptime = millis();
  1677. unsigned long t = (stoptime - starttime) / 1000;
  1678. save_statistics(total_filament_used, t);
  1679. lcd_return_to_status();
  1680. lcd_ignore_click(true);
  1681. lcd_commands_type = 2;
  1682. }
  1683. }
  1684. }
  1685. void lcd_sdcard_menu()
  1686. {
  1687. int tempScrool = 0;
  1688. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  1689. //delay(100);
  1690. return; // nothing to do (so don't thrash the SD card)
  1691. uint16_t fileCnt = card.getnrfilenames();
  1692. START_MENU();
  1693. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1694. card.getWorkDirName();
  1695. if (card.filename[0] == '/')
  1696. {
  1697. #if SDCARDDETECT == -1
  1698. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  1699. #endif
  1700. } else {
  1701. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  1702. }
  1703. for (uint16_t i = 0; i < fileCnt; i++)
  1704. {
  1705. if (_menuItemNr == _lineNr)
  1706. {
  1707. #ifndef SDCARD_RATHERRECENTFIRST
  1708. card.getfilename(i);
  1709. #else
  1710. card.getfilename(fileCnt - 1 - i);
  1711. #endif
  1712. if (card.filenameIsDir)
  1713. {
  1714. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1715. } else {
  1716. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1717. }
  1718. } else {
  1719. MENU_ITEM_DUMMY();
  1720. }
  1721. }
  1722. END_MENU();
  1723. }
  1724. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1725. void menu_edit_ ## _name () \
  1726. { \
  1727. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1728. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1729. if (lcdDrawUpdate) \
  1730. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1731. if (LCD_CLICKED) \
  1732. { \
  1733. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1734. lcd_goto_menu(prevMenu, prevEncoderPosition); \
  1735. } \
  1736. } \
  1737. void menu_edit_callback_ ## _name () { \
  1738. menu_edit_ ## _name (); \
  1739. if (LCD_CLICKED) (*callbackFunc)(); \
  1740. } \
  1741. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  1742. { \
  1743. prevMenu = currentMenu; \
  1744. prevEncoderPosition = encoderPosition; \
  1745. \
  1746. lcdDrawUpdate = 2; \
  1747. currentMenu = menu_edit_ ## _name; \
  1748. \
  1749. editLabel = pstr; \
  1750. editValue = ptr; \
  1751. minEditValue = minValue * scale; \
  1752. maxEditValue = maxValue * scale - minEditValue; \
  1753. encoderPosition = (*ptr) * scale - minEditValue; \
  1754. }\
  1755. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  1756. { \
  1757. prevMenu = currentMenu; \
  1758. prevEncoderPosition = encoderPosition; \
  1759. \
  1760. lcdDrawUpdate = 2; \
  1761. currentMenu = menu_edit_callback_ ## _name; \
  1762. \
  1763. editLabel = pstr; \
  1764. editValue = ptr; \
  1765. minEditValue = minValue * scale; \
  1766. maxEditValue = maxValue * scale - minEditValue; \
  1767. encoderPosition = (*ptr) * scale - minEditValue; \
  1768. callbackFunc = callback;\
  1769. }
  1770. menu_edit_type(int, int3, itostr3, 1)
  1771. menu_edit_type(float, float3, ftostr3, 1)
  1772. menu_edit_type(float, float32, ftostr32, 100)
  1773. menu_edit_type(float, float43, ftostr43, 1000)
  1774. menu_edit_type(float, float5, ftostr5, 0.01)
  1775. menu_edit_type(float, float51, ftostr51, 10)
  1776. menu_edit_type(float, float52, ftostr52, 100)
  1777. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1778. static void lcd_selftest()
  1779. {
  1780. int _progress = 0;
  1781. bool _result = false;
  1782. _progress = lcd_selftest_screen(-1, _progress, 4, true, 2000);
  1783. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  1784. _result = lcd_selfcheck_endstops();
  1785. if (_result)
  1786. {
  1787. _progress = lcd_selftest_screen(1, _progress, 3, true, 1000);
  1788. _result = lcd_selfcheck_check_heater(false);
  1789. }
  1790. if (_result)
  1791. {
  1792. _progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  1793. _result = lcd_selfcheck_axis(0, X_MAX_POS);
  1794. }
  1795. if (_result)
  1796. {
  1797. _progress = lcd_selftest_screen(3, _progress, 3, true, 1500);
  1798. _result = lcd_selfcheck_axis(1, Y_MAX_POS);
  1799. }
  1800. if (_result)
  1801. {
  1802. current_position[X_AXIS] = current_position[X_AXIS] - 3;
  1803. current_position[Y_AXIS] = current_position[Y_AXIS] - 14;
  1804. _progress = lcd_selftest_screen(4, _progress, 3, true, 1500);
  1805. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  1806. }
  1807. if (_result)
  1808. {
  1809. _progress = lcd_selftest_screen(5, _progress, 3, true, 2000);
  1810. _result = lcd_selfcheck_check_heater(true);
  1811. }
  1812. if (_result)
  1813. {
  1814. _progress = lcd_selftest_screen(6, _progress, 3, true, 5000);
  1815. }
  1816. else
  1817. {
  1818. _progress = lcd_selftest_screen(7, _progress, 3, true, 5000);
  1819. }
  1820. lcd_implementation_clear();
  1821. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  1822. if (_result)
  1823. {
  1824. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  1825. }
  1826. else
  1827. {
  1828. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  1829. }
  1830. }
  1831. static bool lcd_selfcheck_endstops()
  1832. {
  1833. bool _result = true;
  1834. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1 || READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1 || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  1835. {
  1836. current_position[0] = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? current_position[0] = current_position[0] + 10 : current_position[0];
  1837. current_position[1] = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? current_position[1] = current_position[1] + 10 : current_position[1];
  1838. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  1839. }
  1840. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[0] / 60, active_extruder);
  1841. delay(500);
  1842. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1 || READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1 || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  1843. {
  1844. _result = false;
  1845. String _error = String((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? "X" : "") +
  1846. String((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? "Y" : "") +
  1847. String((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? "Z" : "");
  1848. lcd_selftest_error(3, _error.c_str(), "");
  1849. }
  1850. manage_heater();
  1851. manage_inactivity();
  1852. return _result;
  1853. }
  1854. static bool lcd_selfcheck_axis(int _axis, int _travel)
  1855. {
  1856. bool _stepdone = false;
  1857. bool _stepresult = false;
  1858. int _progress = 0;
  1859. int _travel_done = 0;
  1860. int _err_endstop = 0;
  1861. int _lcd_refresh = 0;
  1862. _travel = _travel + (_travel / 10);
  1863. do {
  1864. if (_axis == 2)
  1865. {
  1866. current_position[_axis] = current_position[_axis] - 1;
  1867. }
  1868. else
  1869. {
  1870. current_position[_axis] = current_position[_axis] - 3;
  1871. }
  1872. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  1873. st_synchronize();
  1874. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1 || READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1 || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  1875. {
  1876. if (_axis == 0)
  1877. {
  1878. _stepresult = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  1879. _err_endstop = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? 1 : 2;
  1880. disable_x();
  1881. }
  1882. if (_axis == 1)
  1883. {
  1884. _stepresult = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  1885. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 2;
  1886. disable_y();
  1887. }
  1888. if (_axis == 2)
  1889. {
  1890. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  1891. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 1;
  1892. disable_z();
  1893. }
  1894. _stepdone = true;
  1895. }
  1896. if (_lcd_refresh < 6)
  1897. {
  1898. _lcd_refresh++;
  1899. }
  1900. else
  1901. {
  1902. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  1903. _lcd_refresh = 0;
  1904. }
  1905. manage_heater();
  1906. manage_inactivity();
  1907. delay(100);
  1908. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  1909. } while (!_stepdone);
  1910. current_position[_axis] = current_position[_axis] + 15;
  1911. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  1912. if (!_stepresult)
  1913. {
  1914. const char *_error_1;
  1915. const char *_error_2;
  1916. if (_axis == X_AXIS) _error_1 = "X";
  1917. if (_axis == Y_AXIS) _error_1 = "Y";
  1918. if (_axis == Z_AXIS) _error_1 = "Z";
  1919. if (_err_endstop == 0) _error_2 = "X";
  1920. if (_err_endstop == 1) _error_2 = "Y";
  1921. if (_err_endstop == 2) _error_2 = "Z";
  1922. if (_travel_done >= _travel)
  1923. {
  1924. lcd_selftest_error(5, _error_1, _error_2);
  1925. }
  1926. else
  1927. {
  1928. lcd_selftest_error(4, _error_1, _error_2);
  1929. }
  1930. }
  1931. return _stepresult;
  1932. }
  1933. static bool lcd_selfcheck_check_heater(bool _isbed)
  1934. {
  1935. int _counter = 0;
  1936. int _progress = 0;
  1937. bool _stepresult = false;
  1938. bool _docycle = true;
  1939. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  1940. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  1941. int _cycles = (_isbed) ? 120 : 30;
  1942. target_temperature[0] = (_isbed) ? 0 : 100;
  1943. target_temperature_bed = (_isbed) ? 100 : 0;
  1944. manage_heater();
  1945. manage_inactivity();
  1946. do {
  1947. _counter++;
  1948. (_counter < _cycles) ? _docycle = true : _docycle = false;
  1949. manage_heater();
  1950. manage_inactivity();
  1951. _progress = (_isbed) ? lcd_selftest_screen(5, _progress, 2, false, 400) : lcd_selftest_screen(1, _progress, 2, false, 400);
  1952. } while (_docycle);
  1953. target_temperature[0] = 0;
  1954. target_temperature_bed = 0;
  1955. manage_heater();
  1956. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  1957. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  1958. if (_opposite_result < (_isbed) ? 10 : 3)
  1959. {
  1960. if (_checked_result >= (_isbed) ? 3 : 10)
  1961. {
  1962. _stepresult = true;
  1963. }
  1964. else
  1965. {
  1966. lcd_selftest_error(1, "", "");
  1967. }
  1968. }
  1969. else
  1970. {
  1971. lcd_selftest_error(2, "", "");
  1972. }
  1973. manage_heater();
  1974. manage_inactivity();
  1975. return _stepresult;
  1976. }
  1977. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  1978. {
  1979. lcd_implementation_quick_feedback();
  1980. target_temperature[0] = 0;
  1981. target_temperature_bed = 0;
  1982. manage_heater();
  1983. manage_inactivity();
  1984. lcd_implementation_clear();
  1985. lcd.setCursor(0, 0);
  1986. lcd_printPGM(MSG_SELFTEST_ERROR);
  1987. lcd.setCursor(0, 1);
  1988. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  1989. switch (_error_no)
  1990. {
  1991. case 1:
  1992. lcd.setCursor(0, 2);
  1993. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  1994. lcd.setCursor(0, 3);
  1995. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  1996. break;
  1997. case 2:
  1998. lcd.setCursor(0, 2);
  1999. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  2000. lcd.setCursor(0, 3);
  2001. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  2002. break;
  2003. case 3:
  2004. lcd.setCursor(0, 2);
  2005. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  2006. lcd.setCursor(0, 3);
  2007. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  2008. lcd.setCursor(17, 3);
  2009. lcd.print(_error_1);
  2010. break;
  2011. case 4:
  2012. lcd.setCursor(0, 2);
  2013. lcd_printPGM(MSG_SELFTEST_MOTOR);
  2014. lcd.setCursor(18, 2);
  2015. lcd.print(_error_1);
  2016. lcd.setCursor(0, 3);
  2017. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  2018. lcd.setCursor(18, 3);
  2019. lcd.print(_error_2);
  2020. break;
  2021. case 5:
  2022. lcd.setCursor(0, 2);
  2023. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  2024. lcd.setCursor(0, 3);
  2025. lcd_printPGM(MSG_SELFTEST_MOTOR);
  2026. lcd.setCursor(18, 3);
  2027. lcd.print(_error_1);
  2028. break;
  2029. }
  2030. delay(1000);
  2031. lcd_implementation_quick_feedback();
  2032. do {
  2033. delay(100);
  2034. manage_heater();
  2035. manage_inactivity();
  2036. } while (!lcd_clicked());
  2037. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  2038. lcd_return_to_status();
  2039. }
  2040. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  2041. {
  2042. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  2043. int _step_block = 0;
  2044. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  2045. if (_clear) lcd_implementation_clear();
  2046. lcd.setCursor(0, 0);
  2047. if (_step == -1) lcd_printPGM(MSG_SELFTEST_START);
  2048. if (_step == 0) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  2049. if (_step == 1) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  2050. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  2051. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  2052. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  2053. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  2054. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  2055. if (_step == 7) lcd_printPGM(MSG_SELFTEST_FAILED);
  2056. lcd.setCursor(0, 1);
  2057. lcd.print("--------------------");
  2058. _step_block = 1;
  2059. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  2060. _step_block = 2;
  2061. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  2062. _step_block = 3;
  2063. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  2064. _step_block = 4;
  2065. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  2066. _step_block = 5;
  2067. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  2068. if (_delay > 0) delay(_delay);
  2069. _progress++;
  2070. return (_progress > _progress_scale * 2) ? 0 : _progress;
  2071. }
  2072. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  2073. {
  2074. lcd.setCursor(_col, _row);
  2075. switch (_state)
  2076. {
  2077. case 1:
  2078. lcd.print(_name);
  2079. lcd.setCursor(_col + strlen(_name), _row);
  2080. lcd.print(":");
  2081. lcd.setCursor(_col + strlen(_name) + 1, _row);
  2082. lcd.print(_indicator);
  2083. break;
  2084. case 2:
  2085. lcd.print(_name);
  2086. lcd.setCursor(_col + strlen(_name), _row);
  2087. lcd.print(":");
  2088. lcd.setCursor(_col + strlen(_name) + 1, _row);
  2089. lcd.print("OK");
  2090. break;
  2091. default:
  2092. lcd.print(_name);
  2093. }
  2094. }
  2095. /** End of menus **/
  2096. static void lcd_quick_feedback()
  2097. {
  2098. lcdDrawUpdate = 2;
  2099. blocking_enc = millis() + 500;
  2100. lcd_implementation_quick_feedback();
  2101. }
  2102. /** Menu action functions **/
  2103. static void menu_action_back(menuFunc_t data) {
  2104. lcd_goto_menu(data);
  2105. }
  2106. static void menu_action_submenu(menuFunc_t data) {
  2107. lcd_goto_menu(data);
  2108. }
  2109. static void menu_action_gcode(const char* pgcode) {
  2110. enquecommand_P(pgcode);
  2111. }
  2112. static void menu_action_setlang(unsigned char lang) {
  2113. lcd_set_lang(lang);
  2114. }
  2115. static void menu_action_function(menuFunc_t data) {
  2116. (*data)();
  2117. }
  2118. static void menu_action_sdfile(const char* filename, char* longFilename)
  2119. {
  2120. char cmd[30];
  2121. char* c;
  2122. sprintf_P(cmd, PSTR("M23 %s"), filename);
  2123. for (c = &cmd[4]; *c; c++)
  2124. *c = tolower(*c);
  2125. enquecommand(cmd);
  2126. enquecommand_P(PSTR("M24"));
  2127. lcd_return_to_status();
  2128. }
  2129. static void menu_action_sddirectory(const char* filename, char* longFilename)
  2130. {
  2131. card.chdir(filename);
  2132. encoderPosition = 0;
  2133. }
  2134. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  2135. {
  2136. *ptr = !(*ptr);
  2137. }
  2138. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  2139. {
  2140. menu_action_setting_edit_bool(pstr, ptr);
  2141. (*callback)();
  2142. }
  2143. #endif//ULTIPANEL
  2144. /** LCD API **/
  2145. void lcd_init()
  2146. {
  2147. lcd_implementation_init();
  2148. #ifdef NEWPANEL
  2149. SET_INPUT(BTN_EN1);
  2150. SET_INPUT(BTN_EN2);
  2151. WRITE(BTN_EN1, HIGH);
  2152. WRITE(BTN_EN2, HIGH);
  2153. #if BTN_ENC > 0
  2154. SET_INPUT(BTN_ENC);
  2155. WRITE(BTN_ENC, HIGH);
  2156. #endif
  2157. #ifdef REPRAPWORLD_KEYPAD
  2158. pinMode(SHIFT_CLK, OUTPUT);
  2159. pinMode(SHIFT_LD, OUTPUT);
  2160. pinMode(SHIFT_OUT, INPUT);
  2161. WRITE(SHIFT_OUT, HIGH);
  2162. WRITE(SHIFT_LD, HIGH);
  2163. #endif
  2164. #else // Not NEWPANEL
  2165. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  2166. pinMode (SR_DATA_PIN, OUTPUT);
  2167. pinMode (SR_CLK_PIN, OUTPUT);
  2168. #elif defined(SHIFT_CLK)
  2169. pinMode(SHIFT_CLK, OUTPUT);
  2170. pinMode(SHIFT_LD, OUTPUT);
  2171. pinMode(SHIFT_EN, OUTPUT);
  2172. pinMode(SHIFT_OUT, INPUT);
  2173. WRITE(SHIFT_OUT, HIGH);
  2174. WRITE(SHIFT_LD, HIGH);
  2175. WRITE(SHIFT_EN, LOW);
  2176. #else
  2177. #ifdef ULTIPANEL
  2178. #error ULTIPANEL requires an encoder
  2179. #endif
  2180. #endif // SR_LCD_2W_NL
  2181. #endif//!NEWPANEL
  2182. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  2183. pinMode(SDCARDDETECT, INPUT);
  2184. WRITE(SDCARDDETECT, HIGH);
  2185. lcd_oldcardstatus = IS_SD_INSERTED;
  2186. #endif//(SDCARDDETECT > 0)
  2187. #ifdef LCD_HAS_SLOW_BUTTONS
  2188. slow_buttons = 0;
  2189. #endif
  2190. lcd_buttons_update();
  2191. #ifdef ULTIPANEL
  2192. encoderDiff = 0;
  2193. #endif
  2194. }
  2195. //#include <avr/pgmspace.h>
  2196. static volatile bool lcd_update_enabled = true;
  2197. void lcd_update_enable(bool enabled)
  2198. {
  2199. lcd_update_enabled = enabled;
  2200. }
  2201. void lcd_update()
  2202. {
  2203. static unsigned long timeoutToStatus = 0;
  2204. if (! lcd_update_enabled)
  2205. return;
  2206. #ifdef LCD_HAS_SLOW_BUTTONS
  2207. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  2208. #endif
  2209. lcd_buttons_update();
  2210. #if (SDCARDDETECT > 0)
  2211. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  2212. {
  2213. lcdDrawUpdate = 2;
  2214. lcd_oldcardstatus = IS_SD_INSERTED;
  2215. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  2216. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  2217. currentMenu == lcd_status_screen
  2218. #endif
  2219. );
  2220. if (lcd_oldcardstatus)
  2221. {
  2222. card.initsd();
  2223. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  2224. }
  2225. else
  2226. {
  2227. card.release();
  2228. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  2229. }
  2230. }
  2231. #endif//CARDINSERTED
  2232. if (lcd_next_update_millis < millis())
  2233. {
  2234. #ifdef ULTIPANEL
  2235. #ifdef REPRAPWORLD_KEYPAD
  2236. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  2237. reprapworld_keypad_move_z_up();
  2238. }
  2239. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  2240. reprapworld_keypad_move_z_down();
  2241. }
  2242. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  2243. reprapworld_keypad_move_x_left();
  2244. }
  2245. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  2246. reprapworld_keypad_move_x_right();
  2247. }
  2248. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  2249. reprapworld_keypad_move_y_down();
  2250. }
  2251. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  2252. reprapworld_keypad_move_y_up();
  2253. }
  2254. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  2255. reprapworld_keypad_move_home();
  2256. }
  2257. #endif
  2258. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  2259. {
  2260. lcdDrawUpdate = 1;
  2261. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  2262. encoderDiff = 0;
  2263. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  2264. }
  2265. if (LCD_CLICKED)
  2266. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  2267. #endif//ULTIPANEL
  2268. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  2269. blink++; // Variable for fan animation and alive dot
  2270. u8g.firstPage();
  2271. do
  2272. {
  2273. u8g.setFont(u8g_font_6x10_marlin);
  2274. u8g.setPrintPos(125, 0);
  2275. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  2276. u8g.drawPixel(127, 63); // draw alive dot
  2277. u8g.setColorIndex(1); // black on white
  2278. (*currentMenu)();
  2279. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  2280. } while (u8g.nextPage());
  2281. #else
  2282. (*currentMenu)();
  2283. #endif
  2284. #ifdef LCD_HAS_STATUS_INDICATORS
  2285. lcd_implementation_update_indicators();
  2286. #endif
  2287. #ifdef ULTIPANEL
  2288. if (timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  2289. {
  2290. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  2291. // to give it a chance to save its state.
  2292. // This is useful for example, when the babystep value has to be written into EEPROM.
  2293. if (currentMenu != NULL) {
  2294. menuExiting = true;
  2295. (*currentMenu)();
  2296. menuExiting = false;
  2297. }
  2298. lcd_return_to_status();
  2299. lcdDrawUpdate = 2;
  2300. }
  2301. #endif//ULTIPANEL
  2302. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  2303. if (lcdDrawUpdate) lcdDrawUpdate--;
  2304. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  2305. }
  2306. }
  2307. void lcd_ignore_click(bool b)
  2308. {
  2309. ignore_click = b;
  2310. wait_for_unclick = false;
  2311. }
  2312. void lcd_finishstatus() {
  2313. int len = strlen(lcd_status_message);
  2314. if (len > 0) {
  2315. while (len < LCD_WIDTH) {
  2316. lcd_status_message[len++] = ' ';
  2317. }
  2318. }
  2319. lcd_status_message[LCD_WIDTH] = '\0';
  2320. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  2321. #if PROGRESS_MSG_EXPIRE > 0
  2322. messageTick =
  2323. #endif
  2324. progressBarTick = millis();
  2325. #endif
  2326. lcdDrawUpdate = 2;
  2327. #ifdef FILAMENT_LCD_DISPLAY
  2328. message_millis = millis(); //get status message to show up for a while
  2329. #endif
  2330. }
  2331. void lcd_setstatus(const char* message)
  2332. {
  2333. if (lcd_status_message_level > 0)
  2334. return;
  2335. strncpy(lcd_status_message, message, LCD_WIDTH);
  2336. lcd_finishstatus();
  2337. }
  2338. void lcd_setstatuspgm(const char* message)
  2339. {
  2340. if (lcd_status_message_level > 0)
  2341. return;
  2342. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  2343. lcd_finishstatus();
  2344. }
  2345. void lcd_setalertstatuspgm(const char* message)
  2346. {
  2347. lcd_setstatuspgm(message);
  2348. lcd_status_message_level = 1;
  2349. #ifdef ULTIPANEL
  2350. lcd_return_to_status();
  2351. #endif//ULTIPANEL
  2352. }
  2353. void lcd_reset_alert_level()
  2354. {
  2355. lcd_status_message_level = 0;
  2356. }
  2357. #ifdef DOGLCD
  2358. void lcd_setcontrast(uint8_t value)
  2359. {
  2360. lcd_contrast = value & 63;
  2361. u8g.setContrast(lcd_contrast);
  2362. }
  2363. #endif
  2364. #ifdef ULTIPANEL
  2365. /* Warning: This function is called from interrupt context */
  2366. void lcd_buttons_update()
  2367. {
  2368. #ifdef NEWPANEL
  2369. uint8_t newbutton = 0;
  2370. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  2371. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  2372. #if BTN_ENC > 0
  2373. if ((blocking_enc < millis()) && (READ(BTN_ENC) == 0))
  2374. newbutton |= EN_C;
  2375. #endif
  2376. buttons = newbutton;
  2377. #ifdef LCD_HAS_SLOW_BUTTONS
  2378. buttons |= slow_buttons;
  2379. #endif
  2380. #ifdef REPRAPWORLD_KEYPAD
  2381. // for the reprapworld_keypad
  2382. uint8_t newbutton_reprapworld_keypad = 0;
  2383. WRITE(SHIFT_LD, LOW);
  2384. WRITE(SHIFT_LD, HIGH);
  2385. for (int8_t i = 0; i < 8; i++) {
  2386. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  2387. if (READ(SHIFT_OUT))
  2388. newbutton_reprapworld_keypad |= (1 << 7);
  2389. WRITE(SHIFT_CLK, HIGH);
  2390. WRITE(SHIFT_CLK, LOW);
  2391. }
  2392. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  2393. #endif
  2394. #else //read it from the shift register
  2395. uint8_t newbutton = 0;
  2396. WRITE(SHIFT_LD, LOW);
  2397. WRITE(SHIFT_LD, HIGH);
  2398. unsigned char tmp_buttons = 0;
  2399. for (int8_t i = 0; i < 8; i++)
  2400. {
  2401. newbutton = newbutton >> 1;
  2402. if (READ(SHIFT_OUT))
  2403. newbutton |= (1 << 7);
  2404. WRITE(SHIFT_CLK, HIGH);
  2405. WRITE(SHIFT_CLK, LOW);
  2406. }
  2407. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  2408. #endif//!NEWPANEL
  2409. //manage encoder rotation
  2410. uint8_t enc = 0;
  2411. if (buttons & EN_A) enc |= B01;
  2412. if (buttons & EN_B) enc |= B10;
  2413. if (enc != lastEncoderBits)
  2414. {
  2415. switch (enc)
  2416. {
  2417. case encrot0:
  2418. if (lastEncoderBits == encrot3)
  2419. encoderDiff++;
  2420. else if (lastEncoderBits == encrot1)
  2421. encoderDiff--;
  2422. break;
  2423. case encrot1:
  2424. if (lastEncoderBits == encrot0)
  2425. encoderDiff++;
  2426. else if (lastEncoderBits == encrot2)
  2427. encoderDiff--;
  2428. break;
  2429. case encrot2:
  2430. if (lastEncoderBits == encrot1)
  2431. encoderDiff++;
  2432. else if (lastEncoderBits == encrot3)
  2433. encoderDiff--;
  2434. break;
  2435. case encrot3:
  2436. if (lastEncoderBits == encrot2)
  2437. encoderDiff++;
  2438. else if (lastEncoderBits == encrot0)
  2439. encoderDiff--;
  2440. break;
  2441. }
  2442. }
  2443. lastEncoderBits = enc;
  2444. }
  2445. bool lcd_detected(void)
  2446. {
  2447. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  2448. return lcd.LcdDetected() == 1;
  2449. #else
  2450. return true;
  2451. #endif
  2452. }
  2453. void lcd_buzz(long duration, uint16_t freq)
  2454. {
  2455. #ifdef LCD_USE_I2C_BUZZER
  2456. lcd.buzz(duration, freq);
  2457. #endif
  2458. }
  2459. bool lcd_clicked()
  2460. {
  2461. return LCD_CLICKED;
  2462. }
  2463. #endif//ULTIPANEL
  2464. /********************************/
  2465. /** Float conversion utilities **/
  2466. /********************************/
  2467. // convert float to string with +123.4 format
  2468. char conv[8];
  2469. char *ftostr3(const float &x)
  2470. {
  2471. return itostr3((int)x);
  2472. }
  2473. char *itostr2(const uint8_t &x)
  2474. {
  2475. //sprintf(conv,"%5.1f",x);
  2476. int xx = x;
  2477. conv[0] = (xx / 10) % 10 + '0';
  2478. conv[1] = (xx) % 10 + '0';
  2479. conv[2] = 0;
  2480. return conv;
  2481. }
  2482. // Convert float to string with 123.4 format, dropping sign
  2483. char *ftostr31(const float &x)
  2484. {
  2485. int xx = x * 10;
  2486. conv[0] = (xx >= 0) ? '+' : '-';
  2487. xx = abs(xx);
  2488. conv[1] = (xx / 1000) % 10 + '0';
  2489. conv[2] = (xx / 100) % 10 + '0';
  2490. conv[3] = (xx / 10) % 10 + '0';
  2491. conv[4] = '.';
  2492. conv[5] = (xx) % 10 + '0';
  2493. conv[6] = 0;
  2494. return conv;
  2495. }
  2496. // Convert float to string with 123.4 format
  2497. char *ftostr31ns(const float &x)
  2498. {
  2499. int xx = x * 10;
  2500. //conv[0]=(xx>=0)?'+':'-';
  2501. xx = abs(xx);
  2502. conv[0] = (xx / 1000) % 10 + '0';
  2503. conv[1] = (xx / 100) % 10 + '0';
  2504. conv[2] = (xx / 10) % 10 + '0';
  2505. conv[3] = '.';
  2506. conv[4] = (xx) % 10 + '0';
  2507. conv[5] = 0;
  2508. return conv;
  2509. }
  2510. char *ftostr32(const float &x)
  2511. {
  2512. long xx = x * 100;
  2513. if (xx >= 0)
  2514. conv[0] = (xx / 10000) % 10 + '0';
  2515. else
  2516. conv[0] = '-';
  2517. xx = abs(xx);
  2518. conv[1] = (xx / 1000) % 10 + '0';
  2519. conv[2] = (xx / 100) % 10 + '0';
  2520. conv[3] = '.';
  2521. conv[4] = (xx / 10) % 10 + '0';
  2522. conv[5] = (xx) % 10 + '0';
  2523. conv[6] = 0;
  2524. return conv;
  2525. }
  2526. //// Convert float to rj string with 123.45 format
  2527. char *ftostr32ns(const float &x) {
  2528. long xx = abs(x);
  2529. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2530. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2531. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  2532. conv[3] = '.';
  2533. conv[4] = (xx / 10) % 10 + '0';
  2534. conv[5] = xx % 10 + '0';
  2535. return conv;
  2536. }
  2537. // Convert float to string with 1.234 format
  2538. char *ftostr43(const float &x)
  2539. {
  2540. long xx = x * 1000;
  2541. if (xx >= 0)
  2542. conv[0] = (xx / 1000) % 10 + '0';
  2543. else
  2544. conv[0] = '-';
  2545. xx = abs(xx);
  2546. conv[1] = '.';
  2547. conv[2] = (xx / 100) % 10 + '0';
  2548. conv[3] = (xx / 10) % 10 + '0';
  2549. conv[4] = (xx) % 10 + '0';
  2550. conv[5] = 0;
  2551. return conv;
  2552. }
  2553. //Float to string with 1.23 format
  2554. char *ftostr12ns(const float &x)
  2555. {
  2556. long xx = x * 100;
  2557. xx = abs(xx);
  2558. conv[0] = (xx / 100) % 10 + '0';
  2559. conv[1] = '.';
  2560. conv[2] = (xx / 10) % 10 + '0';
  2561. conv[3] = (xx) % 10 + '0';
  2562. conv[4] = 0;
  2563. return conv;
  2564. }
  2565. //Float to string with 1.234 format
  2566. char *ftostr13ns(const float &x)
  2567. {
  2568. long xx = x * 1000;
  2569. if (xx >= 0)
  2570. conv[0] = ' ';
  2571. else
  2572. conv[0] = '-';
  2573. xx = abs(xx);
  2574. conv[1] = (xx / 1000) % 10 + '0';
  2575. conv[2] = '.';
  2576. conv[3] = (xx / 100) % 10 + '0';
  2577. conv[4] = (xx / 10) % 10 + '0';
  2578. conv[5] = (xx) % 10 + '0';
  2579. conv[6] = 0;
  2580. return conv;
  2581. }
  2582. // convert float to space-padded string with -_23.4_ format
  2583. char *ftostr32sp(const float &x) {
  2584. long xx = abs(x * 100);
  2585. uint8_t dig;
  2586. if (x < 0) { // negative val = -_0
  2587. conv[0] = '-';
  2588. dig = (xx / 1000) % 10;
  2589. conv[1] = dig ? '0' + dig : ' ';
  2590. }
  2591. else { // positive val = __0
  2592. dig = (xx / 10000) % 10;
  2593. if (dig) {
  2594. conv[0] = '0' + dig;
  2595. conv[1] = '0' + (xx / 1000) % 10;
  2596. }
  2597. else {
  2598. conv[0] = ' ';
  2599. dig = (xx / 1000) % 10;
  2600. conv[1] = dig ? '0' + dig : ' ';
  2601. }
  2602. }
  2603. conv[2] = '0' + (xx / 100) % 10; // lsd always
  2604. dig = xx % 10;
  2605. if (dig) { // 2 decimal places
  2606. conv[5] = '0' + dig;
  2607. conv[4] = '0' + (xx / 10) % 10;
  2608. conv[3] = '.';
  2609. }
  2610. else { // 1 or 0 decimal place
  2611. dig = (xx / 10) % 10;
  2612. if (dig) {
  2613. conv[4] = '0' + dig;
  2614. conv[3] = '.';
  2615. }
  2616. else {
  2617. conv[3] = conv[4] = ' ';
  2618. }
  2619. conv[5] = ' ';
  2620. }
  2621. conv[6] = '\0';
  2622. return conv;
  2623. }
  2624. char *itostr31(const int &xx)
  2625. {
  2626. conv[0] = (xx >= 0) ? '+' : '-';
  2627. conv[1] = (xx / 1000) % 10 + '0';
  2628. conv[2] = (xx / 100) % 10 + '0';
  2629. conv[3] = (xx / 10) % 10 + '0';
  2630. conv[4] = '.';
  2631. conv[5] = (xx) % 10 + '0';
  2632. conv[6] = 0;
  2633. return conv;
  2634. }
  2635. // Convert int to rj string with 123 or -12 format
  2636. char *itostr3(const int &x)
  2637. {
  2638. int xx = x;
  2639. if (xx < 0) {
  2640. conv[0] = '-';
  2641. xx = -xx;
  2642. } else if (xx >= 100)
  2643. conv[0] = (xx / 100) % 10 + '0';
  2644. else
  2645. conv[0] = ' ';
  2646. if (xx >= 10)
  2647. conv[1] = (xx / 10) % 10 + '0';
  2648. else
  2649. conv[1] = ' ';
  2650. conv[2] = (xx) % 10 + '0';
  2651. conv[3] = 0;
  2652. return conv;
  2653. }
  2654. // Convert int to lj string with 123 format
  2655. char *itostr3left(const int &xx)
  2656. {
  2657. if (xx >= 100)
  2658. {
  2659. conv[0] = (xx / 100) % 10 + '0';
  2660. conv[1] = (xx / 10) % 10 + '0';
  2661. conv[2] = (xx) % 10 + '0';
  2662. conv[3] = 0;
  2663. }
  2664. else if (xx >= 10)
  2665. {
  2666. conv[0] = (xx / 10) % 10 + '0';
  2667. conv[1] = (xx) % 10 + '0';
  2668. conv[2] = 0;
  2669. }
  2670. else
  2671. {
  2672. conv[0] = (xx) % 10 + '0';
  2673. conv[1] = 0;
  2674. }
  2675. return conv;
  2676. }
  2677. // Convert int to rj string with 1234 format
  2678. char *itostr4(const int &xx) {
  2679. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2680. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2681. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2682. conv[3] = xx % 10 + '0';
  2683. conv[4] = 0;
  2684. return conv;
  2685. }
  2686. // Convert float to rj string with 12345 format
  2687. char *ftostr5(const float &x) {
  2688. long xx = abs(x);
  2689. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2690. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2691. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2692. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2693. conv[4] = xx % 10 + '0';
  2694. conv[5] = 0;
  2695. return conv;
  2696. }
  2697. // Convert float to string with +1234.5 format
  2698. char *ftostr51(const float &x)
  2699. {
  2700. long xx = x * 10;
  2701. conv[0] = (xx >= 0) ? '+' : '-';
  2702. xx = abs(xx);
  2703. conv[1] = (xx / 10000) % 10 + '0';
  2704. conv[2] = (xx / 1000) % 10 + '0';
  2705. conv[3] = (xx / 100) % 10 + '0';
  2706. conv[4] = (xx / 10) % 10 + '0';
  2707. conv[5] = '.';
  2708. conv[6] = (xx) % 10 + '0';
  2709. conv[7] = 0;
  2710. return conv;
  2711. }
  2712. // Convert float to string with +123.45 format
  2713. char *ftostr52(const float &x)
  2714. {
  2715. long xx = x * 100;
  2716. conv[0] = (xx >= 0) ? '+' : '-';
  2717. xx = abs(xx);
  2718. conv[1] = (xx / 10000) % 10 + '0';
  2719. conv[2] = (xx / 1000) % 10 + '0';
  2720. conv[3] = (xx / 100) % 10 + '0';
  2721. conv[4] = '.';
  2722. conv[5] = (xx / 10) % 10 + '0';
  2723. conv[6] = (xx) % 10 + '0';
  2724. conv[7] = 0;
  2725. return conv;
  2726. }
  2727. // Callback for after editing PID i value
  2728. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  2729. void copy_and_scalePID_i()
  2730. {
  2731. #ifdef PIDTEMP
  2732. Ki = scalePID_i(raw_Ki);
  2733. updatePID();
  2734. #endif
  2735. }
  2736. // Callback for after editing PID d value
  2737. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  2738. void copy_and_scalePID_d()
  2739. {
  2740. #ifdef PIDTEMP
  2741. Kd = scalePID_d(raw_Kd);
  2742. updatePID();
  2743. #endif
  2744. }
  2745. #endif //ULTRA_LCD