ultralcd.cpp 101 KB

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