ultralcd.cpp 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343
  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. #include "SdFatUtil.h"
  15. #define _STRINGIFY(s) #s
  16. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  17. extern int lcd_change_fil_state;
  18. //Function pointer to menu functions.
  19. typedef void (*menuFunc_t)();
  20. static void lcd_sd_updir();
  21. struct EditMenuParentState
  22. {
  23. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  24. menuFunc_t prevMenu;
  25. uint16_t prevEncoderPosition;
  26. //Variables used when editing values.
  27. const char* editLabel;
  28. void* editValue;
  29. int32_t minEditValue, maxEditValue;
  30. // menuFunc_t callbackFunc;
  31. };
  32. union MenuData
  33. {
  34. struct BabyStep
  35. {
  36. // 29B total
  37. int8_t status;
  38. int babystepMem[3];
  39. float babystepMemMM[3];
  40. } babyStep;
  41. struct SupportMenu
  42. {
  43. // 6B+16B=22B total
  44. int8_t status;
  45. bool is_flash_air;
  46. uint8_t ip[4];
  47. char ip_str[3*4+3+1];
  48. } supportMenu;
  49. struct AdjustBed
  50. {
  51. // 6+13+16=35B
  52. // editMenuParentState is used when an edit menu is entered, so it knows
  53. // the return menu and encoder state.
  54. struct EditMenuParentState editMenuParentState;
  55. int8_t status;
  56. int8_t left;
  57. int8_t right;
  58. int8_t front;
  59. int8_t rear;
  60. int left2;
  61. int right2;
  62. int front2;
  63. int rear2;
  64. } adjustBed;
  65. // editMenuParentState is used when an edit menu is entered, so it knows
  66. // the return menu and encoder state.
  67. struct EditMenuParentState editMenuParentState;
  68. };
  69. // State of the currently active menu.
  70. // C Union manages sharing of the static memory by all the menus.
  71. union MenuData menuData = { 0 };
  72. union Data
  73. {
  74. byte b[2];
  75. int value;
  76. };
  77. int8_t ReInitLCD = 0;
  78. int8_t SDscrool = 0;
  79. int8_t SilentModeMenu = 0;
  80. #ifdef SNMM
  81. uint8_t snmm_extruder = 0;
  82. #endif
  83. int lcd_commands_type=LCD_COMMAND_IDLE;
  84. int lcd_commands_step=0;
  85. bool isPrintPaused = false;
  86. uint8_t farm_mode = 0;
  87. int farm_no = 0;
  88. int farm_timer = 30;
  89. int farm_status = 0;
  90. unsigned long allert_timer = millis();
  91. bool printer_connected = true;
  92. unsigned long display_time; //just timer for showing pid finished message on lcd;
  93. float pid_temp = DEFAULT_PID_TEMP;
  94. bool long_press_active = false;
  95. long long_press_timer = millis();
  96. long button_blanking_time = millis();
  97. bool button_pressed = false;
  98. bool menuExiting = false;
  99. #ifdef FILAMENT_LCD_DISPLAY
  100. unsigned long message_millis = 0;
  101. #endif
  102. #ifdef ULTIPANEL
  103. static float manual_feedrate[] = MANUAL_FEEDRATE;
  104. #endif // ULTIPANEL
  105. /* !Configuration settings */
  106. uint8_t lcd_status_message_level;
  107. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  108. unsigned char firstrun = 1;
  109. #ifdef DOGLCD
  110. #include "dogm_lcd_implementation.h"
  111. #else
  112. #include "ultralcd_implementation_hitachi_HD44780.h"
  113. #endif
  114. /** forward declarations **/
  115. // void copy_and_scalePID_i();
  116. // void copy_and_scalePID_d();
  117. /* Different menus */
  118. static void lcd_status_screen();
  119. #ifdef ULTIPANEL
  120. extern bool powersupply;
  121. static void lcd_main_menu();
  122. static void lcd_tune_menu();
  123. static void lcd_prepare_menu();
  124. static void lcd_move_menu();
  125. static void lcd_settings_menu();
  126. static void lcd_calibration_menu();
  127. static void lcd_language_menu();
  128. static void lcd_control_temperature_menu();
  129. static void lcd_control_temperature_preheat_pla_settings_menu();
  130. static void lcd_control_temperature_preheat_abs_settings_menu();
  131. static void lcd_control_motion_menu();
  132. static void lcd_control_volumetric_menu();
  133. static void prusa_stat_printerstatus(int _status);
  134. static void prusa_stat_farm_number();
  135. static void prusa_stat_temperatures();
  136. static void prusa_stat_printinfo();
  137. static void lcd_farm_no();
  138. #ifdef DOGLCD
  139. static void lcd_set_contrast();
  140. #endif
  141. static void lcd_control_retract_menu();
  142. static void lcd_sdcard_menu();
  143. #ifdef DELTA_CALIBRATION_MENU
  144. static void lcd_delta_calibrate_menu();
  145. #endif // DELTA_CALIBRATION_MENU
  146. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  147. /* Different types of actions that can be used in menu items. */
  148. static void menu_action_back(menuFunc_t data);
  149. #define menu_action_back_RAM menu_action_back
  150. static void menu_action_submenu(menuFunc_t data);
  151. static void menu_action_gcode(const char* pgcode);
  152. static void menu_action_function(menuFunc_t data);
  153. static void menu_action_setlang(unsigned char lang);
  154. static void menu_action_sdfile(const char* filename, char* longFilename);
  155. static void menu_action_sddirectory(const char* filename, char* longFilename);
  156. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  157. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  158. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  159. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  160. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  161. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  162. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  163. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  164. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  165. /*
  166. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  167. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  168. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  169. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  170. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  171. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  172. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  173. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  174. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  175. */
  176. #define ENCODER_FEEDRATE_DEADZONE 10
  177. #if !defined(LCD_I2C_VIKI)
  178. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  179. #define ENCODER_STEPS_PER_MENU_ITEM 5
  180. #endif
  181. #ifndef ENCODER_PULSES_PER_STEP
  182. #define ENCODER_PULSES_PER_STEP 1
  183. #endif
  184. #else
  185. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  186. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  187. #endif
  188. #ifndef ENCODER_PULSES_PER_STEP
  189. #define ENCODER_PULSES_PER_STEP 1
  190. #endif
  191. #endif
  192. /* Helper macros for menus */
  193. #define START_MENU() do { \
  194. if (encoderPosition > 0x8000) encoderPosition = 0; \
  195. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  196. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  197. bool wasClicked = LCD_CLICKED;\
  198. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  199. _menuItemNr = 0;
  200. #define MENU_ITEM(type, label, args...) do { \
  201. if (_menuItemNr == _lineNr) { \
  202. if (lcdDrawUpdate) { \
  203. const char* _label_pstr = (label); \
  204. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  205. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  206. }else{\
  207. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  208. }\
  209. }\
  210. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  211. lcd_quick_feedback(); \
  212. menu_action_ ## type ( args ); \
  213. return;\
  214. }\
  215. }\
  216. _menuItemNr++;\
  217. } while(0)
  218. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  219. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  220. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  221. #define END_MENU() \
  222. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  223. 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; } \
  224. } } while(0)
  225. /** Used variables to keep track of the menu */
  226. #ifndef REPRAPWORLD_KEYPAD
  227. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  228. #else
  229. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  230. #endif
  231. #ifdef LCD_HAS_SLOW_BUTTONS
  232. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  233. #endif
  234. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  235. uint8_t lastEncoderBits;
  236. uint32_t encoderPosition;
  237. uint32_t savedEncoderPosition;
  238. #if (SDCARDDETECT > 0)
  239. bool lcd_oldcardstatus;
  240. #endif
  241. #endif //ULTIPANEL
  242. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  243. menuFunc_t savedMenu;
  244. uint32_t lcd_next_update_millis;
  245. uint8_t lcd_status_update_delay;
  246. bool ignore_click = false;
  247. bool wait_for_unclick;
  248. 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) */
  249. // place-holders for Ki and Kd edits
  250. #ifdef PIDTEMP
  251. // float raw_Ki, raw_Kd;
  252. #endif
  253. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true, bool reset_menu_state = true) {
  254. if (currentMenu != menu) {
  255. currentMenu = menu;
  256. encoderPosition = encoder;
  257. if (reset_menu_state) {
  258. // Resets the global shared C union.
  259. // This ensures, that the menu entered will find out, that it shall initialize itself.
  260. memset(&menuData, 0, sizeof(menuData));
  261. }
  262. if (feedback) lcd_quick_feedback();
  263. // For LCD_PROGRESS_BAR re-initialize the custom characters
  264. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  265. lcd_set_custom_characters(menu == lcd_status_screen);
  266. #endif
  267. }
  268. }
  269. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  270. // Language selection dialog not active.
  271. #define LANGSEL_OFF 0
  272. // Language selection dialog modal, entered from the info screen. This is the case on firmware boot up,
  273. // if the language index stored in the EEPROM is not valid.
  274. #define LANGSEL_MODAL 1
  275. // Language selection dialog entered from the Setup menu.
  276. #define LANGSEL_ACTIVE 2
  277. // Language selection dialog status
  278. unsigned char langsel = LANGSEL_OFF;
  279. void set_language_from_EEPROM() {
  280. unsigned char eep = eeprom_read_byte((unsigned char*)EEPROM_LANG);
  281. if (eep < LANG_NUM)
  282. {
  283. lang_selected = eep;
  284. // Language is valid, no need to enter the language selection screen.
  285. langsel = LANGSEL_OFF;
  286. }
  287. else
  288. {
  289. lang_selected = LANG_ID_DEFAULT;
  290. // Invalid language, enter the language selection screen in a modal mode.
  291. langsel = LANGSEL_MODAL;
  292. }
  293. }
  294. static void lcd_status_screen()
  295. {
  296. if (firstrun == 1)
  297. {
  298. firstrun = 0;
  299. set_language_from_EEPROM();
  300. if(lcd_status_message_level == 0){
  301. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  302. }
  303. 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)
  304. {
  305. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  306. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  307. }
  308. if (langsel) {
  309. //strncpy_P(lcd_status_message, PSTR(">>>>>>>>>>>> PRESS v"), LCD_WIDTH);
  310. // Entering the language selection screen in a modal mode.
  311. }
  312. }
  313. if (lcd_status_update_delay)
  314. lcd_status_update_delay--;
  315. else
  316. lcdDrawUpdate = 1;
  317. if (lcdDrawUpdate)
  318. {
  319. ReInitLCD++;
  320. if (ReInitLCD == 30) {
  321. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  322. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  323. currentMenu == lcd_status_screen
  324. #endif
  325. );
  326. ReInitLCD = 0 ;
  327. } else {
  328. if ((ReInitLCD % 10) == 0) {
  329. //lcd_implementation_nodisplay();
  330. lcd_implementation_init_noclear( // to maybe revive the LCD if static electricity killed it.
  331. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  332. currentMenu == lcd_status_screen
  333. #endif
  334. );
  335. }
  336. }
  337. //lcd_implementation_display();
  338. lcd_implementation_status_screen();
  339. //lcd_implementation_clear();
  340. if (farm_mode)
  341. {
  342. farm_timer--;
  343. if (farm_timer < 1)
  344. {
  345. farm_timer = 180;
  346. prusa_statistics(0);
  347. }
  348. switch (farm_timer)
  349. {
  350. case 45:
  351. prusa_statistics(21);
  352. break;
  353. case 10:
  354. if (IS_SD_PRINTING)
  355. {
  356. prusa_statistics(20);
  357. }
  358. break;
  359. }
  360. } // end of farm_mode
  361. 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 */
  362. if (lcd_commands_type != LCD_COMMAND_IDLE)
  363. {
  364. lcd_commands();
  365. }
  366. } // end of lcdDrawUpdate
  367. #ifdef ULTIPANEL
  368. bool current_click = LCD_CLICKED;
  369. if (ignore_click) {
  370. if (wait_for_unclick) {
  371. if (!current_click) {
  372. ignore_click = wait_for_unclick = false;
  373. }
  374. else {
  375. current_click = false;
  376. }
  377. }
  378. else if (current_click) {
  379. lcd_quick_feedback();
  380. wait_for_unclick = true;
  381. current_click = false;
  382. }
  383. }
  384. //if (--langsel ==0) {langsel=1;current_click=true;}
  385. if (current_click && (lcd_commands_type != LCD_COMMAND_STOP_PRINT)) //click is aborted unless stop print finishes
  386. {
  387. lcd_goto_menu(lcd_main_menu);
  388. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  389. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  390. currentMenu == lcd_status_screen
  391. #endif
  392. );
  393. #ifdef FILAMENT_LCD_DISPLAY
  394. message_millis = millis(); // get status message to show up for a while
  395. #endif
  396. }
  397. #ifdef ULTIPANEL_FEEDMULTIPLY
  398. // Dead zone at 100% feedrate
  399. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  400. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  401. {
  402. encoderPosition = 0;
  403. feedmultiply = 100;
  404. }
  405. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  406. {
  407. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  408. encoderPosition = 0;
  409. }
  410. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  411. {
  412. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  413. encoderPosition = 0;
  414. }
  415. else if (feedmultiply != 100)
  416. {
  417. feedmultiply += int(encoderPosition);
  418. encoderPosition = 0;
  419. }
  420. #endif //ULTIPANEL_FEEDMULTIPLY
  421. if (feedmultiply < 10)
  422. feedmultiply = 10;
  423. else if (feedmultiply > 999)
  424. feedmultiply = 999;
  425. #endif //ULTIPANEL
  426. if (farm_mode && !printer_connected) {
  427. lcd.setCursor(0, 3);
  428. lcd_printPGM(MSG_PRINTER_DISCONNECTED);
  429. }
  430. }
  431. #ifdef ULTIPANEL
  432. void lcd_commands()
  433. {
  434. char cmd1[25];
  435. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE)
  436. {
  437. if(lcd_commands_step == 0) {
  438. card.pauseSDPrint();
  439. lcd_setstatuspgm(MSG_FINISHING_MOVEMENTS);
  440. lcdDrawUpdate = 3;
  441. lcd_commands_step = 1;
  442. }
  443. if (lcd_commands_step == 1 && !blocks_queued()) {
  444. lcd_setstatuspgm(MSG_PRINT_PAUSED);
  445. isPrintPaused = true;
  446. long_pause();
  447. lcd_commands_type = 0;
  448. lcd_commands_step = 0;
  449. }
  450. }
  451. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE_RESUME) {
  452. char cmd1[30];
  453. if (lcd_commands_step == 0) {
  454. lcdDrawUpdate = 3;
  455. lcd_commands_step = 4;
  456. }
  457. if (lcd_commands_step == 1 && !blocks_queued()) { //recover feedmultiply
  458. sprintf_P(cmd1, PSTR("M220 S%d"), saved_feedmultiply);
  459. enquecommand(cmd1);
  460. isPrintPaused = false;
  461. pause_time += (millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  462. card.startFileprint();
  463. lcd_commands_step = 0;
  464. lcd_commands_type = 0;
  465. }
  466. if (lcd_commands_step == 2 && !blocks_queued()) { //turn on fan, move Z and unretract
  467. sprintf_P(cmd1, PSTR("M106 S%d"), fanSpeedBckp);
  468. enquecommand(cmd1);
  469. strcpy(cmd1, "G1 Z");
  470. strcat(cmd1, ftostr32(pause_lastpos[Z_AXIS]));
  471. enquecommand(cmd1);
  472. if (axis_relative_modes[3] == true) enquecommand_P(PSTR("M83")); // set extruder to relative mode.
  473. else enquecommand_P(PSTR("M82")); // set extruder to absolute mode
  474. enquecommand_P(PSTR("G1 E" STRINGIFY(PAUSE_RETRACT))); //unretract
  475. enquecommand_P(PSTR("G90")); //absolute positioning
  476. lcd_commands_step = 1;
  477. }
  478. if (lcd_commands_step == 3 && !blocks_queued()) { //wait for nozzle to reach target temp
  479. strcpy(cmd1, "M109 S");
  480. strcat(cmd1, ftostr3(HotendTempBckp));
  481. enquecommand(cmd1);
  482. lcd_commands_step = 2;
  483. }
  484. if (lcd_commands_step == 4 && !blocks_queued()) { //set temperature back and move xy
  485. strcpy(cmd1, "M104 S");
  486. strcat(cmd1, ftostr3(HotendTempBckp));
  487. enquecommand(cmd1);
  488. strcpy(cmd1, "G1 X");
  489. strcat(cmd1, ftostr32(pause_lastpos[X_AXIS]));
  490. strcat(cmd1, " Y");
  491. strcat(cmd1, ftostr32(pause_lastpos[Y_AXIS]));
  492. enquecommand(cmd1);
  493. lcd_setstatuspgm(MSG_RESUMING_PRINT);
  494. lcd_commands_step = 3;
  495. }
  496. }
  497. if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print
  498. {
  499. if (lcd_commands_step == 0)
  500. {
  501. lcd_commands_step = 6;
  502. custom_message = true;
  503. }
  504. if (lcd_commands_step == 1 && !blocks_queued())
  505. {
  506. lcd_commands_step = 0;
  507. lcd_commands_type = 0;
  508. lcd_setstatuspgm(WELCOME_MSG);
  509. custom_message_type = 0;
  510. custom_message = false;
  511. isPrintPaused = false;
  512. }
  513. if (lcd_commands_step == 2 && !blocks_queued())
  514. {
  515. setTargetBed(0);
  516. setTargetHotend(0, 0);
  517. setTargetHotend(0, 1);
  518. setTargetHotend(0, 2);
  519. manage_heater();
  520. lcd_setstatuspgm(WELCOME_MSG);
  521. cancel_heatup = false;
  522. lcd_commands_step = 1;
  523. }
  524. if (lcd_commands_step == 3 && !blocks_queued())
  525. {
  526. // M84: Disable steppers.
  527. enquecommand_P(PSTR("M84"));
  528. #ifdef SNMM
  529. enquecommand_P(PSTR("PRUSA ResF")); //resets flag at the end of the print (used for SNMM)
  530. #endif
  531. autotempShutdown();
  532. lcd_commands_step = 2;
  533. }
  534. if (lcd_commands_step == 4 && !blocks_queued())
  535. {
  536. lcd_setstatuspgm(MSG_PLEASE_WAIT);
  537. // G90: Absolute positioning.
  538. enquecommand_P(PSTR("G90"));
  539. // M83: Set extruder to relative mode.
  540. enquecommand_P(PSTR("M83"));
  541. #ifdef X_CANCEL_POS
  542. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  543. #else
  544. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  545. #endif
  546. lcd_ignore_click(false);
  547. #ifdef SNMM
  548. lcd_commands_step = 7;
  549. #else
  550. lcd_commands_step = 3;
  551. #endif
  552. }
  553. if (lcd_commands_step == 5 && !blocks_queued())
  554. {
  555. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  556. // G91: Set to relative positioning.
  557. enquecommand_P(PSTR("G91"));
  558. // Lift up.
  559. enquecommand_P(PSTR("G1 Z15 F1500"));
  560. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) lcd_commands_step = 4;
  561. else lcd_commands_step = 3;
  562. }
  563. if (lcd_commands_step == 6 && !blocks_queued())
  564. {
  565. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  566. cancel_heatup = true;
  567. setTargetBed(0);
  568. #ifndef SNMM
  569. setTargetHotend(0, 0); //to heating when changing filament for multicolor
  570. setTargetHotend(0, 1);
  571. setTargetHotend(0, 2);
  572. #endif
  573. manage_heater();
  574. custom_message = true;
  575. custom_message_type = 2;
  576. lcd_commands_step = 5;
  577. }
  578. if (lcd_commands_step == 7 && !blocks_queued()) {
  579. /*ramming();
  580. st_synchronize();
  581. change_extr(0);*/
  582. st_synchronize();
  583. enquecommand_P(PSTR("M907 E700")); //set extruder current higher
  584. enquecommand_P(PSTR("M203 E50"));
  585. st_synchronize();
  586. if (current_temperature[0] < 230) {
  587. // PLA
  588. //enquecommand_P(PSTR("G1 E-8 F2100.000000"));
  589. //enquecommand_P(PSTR("G1 E8 F2100.000000"));
  590. enquecommand_P(PSTR("G1 E5.4 F2800.000000"));
  591. enquecommand_P(PSTR("G1 E3.2 F3000.000000"));
  592. enquecommand_P(PSTR("G1 E3 F3400.000000"));
  593. enquecommand_P(PSTR("M203 E80"));
  594. st_synchronize();
  595. enquecommand_P(PSTR("G1 E-82 F9500.000000"));
  596. enquecommand_P(PSTR("M203 E50"));
  597. enquecommand_P(PSTR("G1 E-20 F1200.000000"));
  598. enquecommand_P(PSTR("G1 E5 F400.000000"));
  599. enquecommand_P(PSTR("G1 E5 F600.000000"));
  600. st_synchronize();
  601. enquecommand_P(PSTR("G1 E-10 F600.000000"));
  602. enquecommand_P(PSTR("G1 E+10 F600.000000"));
  603. enquecommand_P(PSTR("G1 E-10 F800.000000"));
  604. enquecommand_P(PSTR("G1 E+10 F800.000000"));
  605. enquecommand_P(PSTR("G1 E-10 F800.000000"));
  606. st_synchronize();
  607. }else {
  608. // ABS
  609. //enquecommand_P(PSTR("G1 E-8 F2100.000000"));
  610. //enquecommand_P(PSTR("G1 E8 F2100.000000"));
  611. enquecommand_P(PSTR("G1 E3.1 F2000.000000"));
  612. enquecommand_P(PSTR("G1 E3.1 F2500.000000"));
  613. enquecommand_P(PSTR("G1 E4 F3000.000000"));
  614. st_synchronize();
  615. enquecommand_P(PSTR("G4 P4700"));
  616. enquecommand_P(PSTR("M203 E80"));
  617. enquecommand_P(PSTR("G1 E-92 F9900.000000"));
  618. enquecommand_P(PSTR("M203 E50"));
  619. enquecommand_P(PSTR("G1 E-5 F800.000000"));
  620. enquecommand_P(PSTR("G1 E5 F400.000000"));
  621. st_synchronize();
  622. enquecommand_P(PSTR("G1 E-5 F600.000000"));
  623. enquecommand_P(PSTR("G1 E5 F600.000000"));
  624. enquecommand_P(PSTR("G1 E-5 F600.000000"));
  625. enquecommand_P(PSTR("G1 E5 F600.000000"));
  626. enquecommand_P(PSTR("G1 E5 F600.000000"));
  627. st_synchronize();
  628. }
  629. enquecommand_P(PSTR("T0"));
  630. enquecommand_P(PSTR("M907 E550")); //set extruder current to 500
  631. //digipot_init();
  632. lcd_commands_step = 3;
  633. }
  634. }
  635. if (lcd_commands_type == 3)
  636. {
  637. lcd_commands_type = 0;
  638. }
  639. if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
  640. {
  641. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  642. if (lcd_commands_step == 1 && !blocks_queued())
  643. {
  644. lcd_confirm_print();
  645. lcd_commands_step = 0;
  646. lcd_commands_type = 0;
  647. }
  648. if (lcd_commands_step == 2 && !blocks_queued())
  649. {
  650. lcd_commands_step = 1;
  651. }
  652. if (lcd_commands_step == 3 && !blocks_queued())
  653. {
  654. lcd_commands_step = 2;
  655. }
  656. if (lcd_commands_step == 4 && !blocks_queued())
  657. {
  658. enquecommand_P(PSTR("G90"));
  659. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  660. lcd_commands_step = 3;
  661. }
  662. if (lcd_commands_step == 5 && !blocks_queued())
  663. {
  664. lcd_commands_step = 4;
  665. }
  666. if (lcd_commands_step == 6 && !blocks_queued())
  667. {
  668. enquecommand_P(PSTR("G91"));
  669. enquecommand_P(PSTR("G1 Z15 F1500"));
  670. st_synchronize();
  671. #ifdef SNMM
  672. lcd_commands_step = 7;
  673. #else
  674. lcd_commands_step = 5;
  675. #endif
  676. }
  677. }
  678. if (lcd_commands_type == LCD_COMMAND_PID_EXTRUDER) {
  679. char cmd1[30];
  680. if (lcd_commands_step == 0) {
  681. custom_message_type = 3;
  682. custom_message_state = 1;
  683. custom_message = true;
  684. lcdDrawUpdate = 3;
  685. lcd_commands_step = 3;
  686. }
  687. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  688. strcpy(cmd1, "M303 E0 S");
  689. strcat(cmd1, ftostr3(pid_temp));
  690. enquecommand(cmd1);
  691. lcd_setstatuspgm(MSG_PID_RUNNING);
  692. lcd_commands_step = 2;
  693. }
  694. if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom
  695. pid_tuning_finished = false;
  696. custom_message_state = 0;
  697. lcd_setstatuspgm(MSG_PID_FINISHED);
  698. strcpy(cmd1, "M301 P");
  699. strcat(cmd1, ftostr32(_Kp));
  700. strcat(cmd1, " I");
  701. strcat(cmd1, ftostr32(_Ki));
  702. strcat(cmd1, " D");
  703. strcat(cmd1, ftostr32(_Kd));
  704. enquecommand(cmd1);
  705. enquecommand_P(PSTR("M500"));
  706. display_time = millis();
  707. lcd_commands_step = 1;
  708. }
  709. if ((lcd_commands_step == 1) && ((millis()- display_time)>2000)) { //calibration finished message
  710. lcd_setstatuspgm(WELCOME_MSG);
  711. custom_message_type = 0;
  712. custom_message = false;
  713. pid_temp = DEFAULT_PID_TEMP;
  714. lcd_commands_step = 0;
  715. lcd_commands_type = 0;
  716. }
  717. }
  718. }
  719. static void lcd_return_to_status() {
  720. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  721. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  722. currentMenu == lcd_status_screen
  723. #endif
  724. );
  725. lcd_goto_menu(lcd_status_screen, 0, false);
  726. }
  727. static void lcd_sdcard_pause() {
  728. lcd_return_to_status();
  729. lcd_commands_type = LCD_COMMAND_LONG_PAUSE;
  730. }
  731. static void lcd_sdcard_resume() {
  732. lcd_return_to_status();
  733. lcd_commands_type = LCD_COMMAND_LONG_PAUSE_RESUME;
  734. }
  735. float move_menu_scale;
  736. static void lcd_move_menu_axis();
  737. /* Menu implementation */
  738. void lcd_preheat_pla()
  739. {
  740. setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);
  741. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  742. fanSpeed = 0;
  743. lcd_return_to_status();
  744. setWatch(); // heater sanity check timer
  745. }
  746. void lcd_preheat_abs()
  747. {
  748. setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);
  749. setTargetBed(ABS_PREHEAT_HPB_TEMP);
  750. fanSpeed = 0;
  751. lcd_return_to_status();
  752. setWatch(); // heater sanity check timer
  753. }
  754. void lcd_preheat_pp()
  755. {
  756. setTargetHotend0(PP_PREHEAT_HOTEND_TEMP);
  757. setTargetBed(PP_PREHEAT_HPB_TEMP);
  758. fanSpeed = 0;
  759. lcd_return_to_status();
  760. setWatch(); // heater sanity check timer
  761. }
  762. void lcd_preheat_pet()
  763. {
  764. setTargetHotend0(PET_PREHEAT_HOTEND_TEMP);
  765. setTargetBed(PET_PREHEAT_HPB_TEMP);
  766. fanSpeed = 0;
  767. lcd_return_to_status();
  768. setWatch(); // heater sanity check timer
  769. }
  770. void lcd_preheat_hips()
  771. {
  772. setTargetHotend0(HIPS_PREHEAT_HOTEND_TEMP);
  773. setTargetBed(HIPS_PREHEAT_HPB_TEMP);
  774. fanSpeed = 0;
  775. lcd_return_to_status();
  776. setWatch(); // heater sanity check timer
  777. }
  778. void lcd_preheat_flex()
  779. {
  780. setTargetHotend0(FLEX_PREHEAT_HOTEND_TEMP);
  781. setTargetBed(FLEX_PREHEAT_HPB_TEMP);
  782. fanSpeed = 0;
  783. lcd_return_to_status();
  784. setWatch(); // heater sanity check timer
  785. }
  786. void lcd_cooldown()
  787. {
  788. setTargetHotend0(0);
  789. setTargetHotend1(0);
  790. setTargetHotend2(0);
  791. setTargetBed(0);
  792. fanSpeed = 0;
  793. lcd_return_to_status();
  794. }
  795. static void lcd_preheat_menu()
  796. {
  797. START_MENU();
  798. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  799. MENU_ITEM(function, PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  800. MENU_ITEM(function, PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  801. MENU_ITEM(function, PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  802. MENU_ITEM(function, PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  803. MENU_ITEM(function, PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  804. MENU_ITEM(function, PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  805. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  806. END_MENU();
  807. }
  808. static void lcd_support_menu()
  809. {
  810. if (menuData.supportMenu.status == 0 || lcdDrawUpdate == 2) {
  811. // Menu was entered or SD card status has changed (plugged in or removed).
  812. // Initialize its status.
  813. menuData.supportMenu.status = 1;
  814. menuData.supportMenu.is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(menuData.supportMenu.ip);
  815. if (menuData.supportMenu.is_flash_air)
  816. sprintf_P(menuData.supportMenu.ip_str, PSTR("%d.%d.%d.%d"),
  817. menuData.supportMenu.ip[0], menuData.supportMenu.ip[1],
  818. menuData.supportMenu.ip[2], menuData.supportMenu.ip[3]);
  819. } else if (menuData.supportMenu.is_flash_air &&
  820. menuData.supportMenu.ip[0] == 0 && menuData.supportMenu.ip[1] == 0 &&
  821. menuData.supportMenu.ip[2] == 0 && menuData.supportMenu.ip[3] == 0 &&
  822. ++ menuData.supportMenu.status == 16) {
  823. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  824. menuData.supportMenu.status = 0;
  825. }
  826. START_MENU();
  827. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  828. // Ideally this block would be optimized out by the compiler.
  829. const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  830. if (fw_string_len < 6) {
  831. MENU_ITEM(back, PSTR(MSG_FW_VERSION " - " FW_version), lcd_main_menu);
  832. } else {
  833. MENU_ITEM(back, PSTR("FW - " FW_version), lcd_main_menu);
  834. }
  835. MENU_ITEM(back, MSG_PRUSA3D, lcd_main_menu);
  836. MENU_ITEM(back, MSG_PRUSA3D_FORUM, lcd_main_menu);
  837. MENU_ITEM(back, MSG_PRUSA3D_HOWTO, lcd_main_menu);
  838. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  839. MENU_ITEM(back, PSTR(FILAMENT_SIZE), lcd_main_menu);
  840. MENU_ITEM(back, PSTR(ELECTRONICS),lcd_main_menu);
  841. MENU_ITEM(back, PSTR(NOZZLE_TYPE),lcd_main_menu);
  842. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  843. MENU_ITEM(back, PSTR("Date: "), lcd_main_menu);
  844. MENU_ITEM(back, PSTR(__DATE__), lcd_main_menu);
  845. // Show the FlashAir IP address, if the card is available.
  846. if (menuData.supportMenu.is_flash_air) {
  847. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  848. MENU_ITEM(back, PSTR("FlashAir IP Addr:"), lcd_main_menu);
  849. MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, lcd_main_menu);
  850. }
  851. END_MENU();
  852. }
  853. void lcd_unLoadFilament()
  854. {
  855. if (degHotend0() > EXTRUDE_MINTEMP) {
  856. enquecommand_P(PSTR("M702")); //unload filament
  857. } else {
  858. lcd_implementation_clear();
  859. lcd.setCursor(0, 0);
  860. lcd_printPGM(MSG_ERROR);
  861. lcd.setCursor(0, 2);
  862. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  863. delay(2000);
  864. lcd_implementation_clear();
  865. }
  866. lcd_return_to_status();
  867. }
  868. void lcd_change_filament() {
  869. lcd_implementation_clear();
  870. lcd.setCursor(0, 1);
  871. lcd_printPGM(MSG_CHANGING_FILAMENT);
  872. }
  873. void lcd_wait_interact() {
  874. lcd_implementation_clear();
  875. lcd.setCursor(0, 1);
  876. lcd_printPGM(MSG_INSERT_FILAMENT);
  877. lcd.setCursor(0, 2);
  878. lcd_printPGM(MSG_PRESS);
  879. }
  880. void lcd_change_success() {
  881. lcd_implementation_clear();
  882. lcd.setCursor(0, 2);
  883. lcd_printPGM(MSG_CHANGE_SUCCESS);
  884. }
  885. void lcd_loading_color() {
  886. lcd_implementation_clear();
  887. lcd.setCursor(0, 0);
  888. lcd_printPGM(MSG_LOADING_COLOR);
  889. lcd.setCursor(0, 2);
  890. lcd_printPGM(MSG_PLEASE_WAIT);
  891. for (int i = 0; i < 20; i++) {
  892. lcd.setCursor(i, 3);
  893. lcd.print(".");
  894. for (int j = 0; j < 10 ; j++) {
  895. manage_heater();
  896. manage_inactivity(true);
  897. delay(85);
  898. }
  899. }
  900. }
  901. void lcd_loading_filament() {
  902. lcd_implementation_clear();
  903. lcd.setCursor(0, 0);
  904. lcd_printPGM(MSG_LOADING_FILAMENT);
  905. lcd.setCursor(0, 2);
  906. lcd_printPGM(MSG_PLEASE_WAIT);
  907. for (int i = 0; i < 20; i++) {
  908. lcd.setCursor(i, 3);
  909. lcd.print(".");
  910. for (int j = 0; j < 10 ; j++) {
  911. manage_heater();
  912. manage_inactivity(true);
  913. delay(110);
  914. }
  915. }
  916. }
  917. void lcd_alright() {
  918. int enc_dif = 0;
  919. int cursor_pos = 1;
  920. lcd_implementation_clear();
  921. lcd.setCursor(0, 0);
  922. lcd_printPGM(MSG_CORRECTLY);
  923. lcd.setCursor(1, 1);
  924. lcd_printPGM(MSG_YES);
  925. lcd.setCursor(1, 2);
  926. lcd_printPGM(MSG_NOT_LOADED);
  927. lcd.setCursor(1, 3);
  928. lcd_printPGM(MSG_NOT_COLOR);
  929. lcd.setCursor(0, 1);
  930. lcd.print(">");
  931. enc_dif = encoderDiff;
  932. while (lcd_change_fil_state == 0) {
  933. manage_heater();
  934. manage_inactivity(true);
  935. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  936. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  937. if (enc_dif > encoderDiff ) {
  938. cursor_pos --;
  939. }
  940. if (enc_dif < encoderDiff ) {
  941. cursor_pos ++;
  942. }
  943. if (cursor_pos > 3) {
  944. cursor_pos = 3;
  945. }
  946. if (cursor_pos < 1) {
  947. cursor_pos = 1;
  948. }
  949. lcd.setCursor(0, 1);
  950. lcd.print(" ");
  951. lcd.setCursor(0, 2);
  952. lcd.print(" ");
  953. lcd.setCursor(0, 3);
  954. lcd.print(" ");
  955. lcd.setCursor(0, cursor_pos);
  956. lcd.print(">");
  957. enc_dif = encoderDiff;
  958. delay(100);
  959. }
  960. }
  961. if (lcd_clicked()) {
  962. lcd_change_fil_state = cursor_pos;
  963. delay(500);
  964. }
  965. };
  966. lcd_implementation_clear();
  967. lcd_return_to_status();
  968. }
  969. void lcd_LoadFilament()
  970. {
  971. if (degHotend0() > EXTRUDE_MINTEMP)
  972. {
  973. custom_message = true;
  974. loading_flag = true;
  975. enquecommand_P(PSTR("M701")); //load filament
  976. SERIAL_ECHOLN("Loading filament");
  977. }
  978. else
  979. {
  980. lcd_implementation_clear();
  981. lcd.setCursor(0, 0);
  982. lcd_printPGM(MSG_ERROR);
  983. lcd.setCursor(0, 2);
  984. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  985. delay(2000);
  986. lcd_implementation_clear();
  987. }
  988. lcd_return_to_status();
  989. }
  990. void lcd_menu_statistics()
  991. {
  992. if (IS_SD_PRINTING)
  993. {
  994. int _met = total_filament_used / 100000;
  995. int _cm = (total_filament_used - (_met * 100000))/10;
  996. int _t = (millis() - starttime) / 1000;
  997. int _h = _t / 3600;
  998. int _m = (_t - (_h * 3600)) / 60;
  999. int _s = _t - ((_h * 3600) + (_m * 60));
  1000. lcd.setCursor(0, 0);
  1001. lcd_printPGM(MSG_STATS_FILAMENTUSED);
  1002. lcd.setCursor(6, 1);
  1003. lcd.print(itostr3(_met));
  1004. lcd.print("m ");
  1005. lcd.print(ftostr32ns(_cm));
  1006. lcd.print("cm");
  1007. lcd.setCursor(0, 2);
  1008. lcd_printPGM(MSG_STATS_PRINTTIME);
  1009. lcd.setCursor(8, 3);
  1010. lcd.print(itostr2(_h));
  1011. lcd.print("h ");
  1012. lcd.print(itostr2(_m));
  1013. lcd.print("m ");
  1014. lcd.print(itostr2(_s));
  1015. lcd.print("s");
  1016. if (lcd_clicked())
  1017. {
  1018. lcd_quick_feedback();
  1019. lcd_return_to_status();
  1020. }
  1021. }
  1022. else
  1023. {
  1024. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  1025. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  1026. uint8_t _hours, _minutes;
  1027. uint32_t _days;
  1028. float _filament_m = (float)_filament;
  1029. int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  1030. if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  1031. _days = _time / 1440;
  1032. _hours = (_time - (_days * 1440)) / 60;
  1033. _minutes = _time - ((_days * 1440) + (_hours * 60));
  1034. lcd_implementation_clear();
  1035. lcd.setCursor(0, 0);
  1036. lcd_printPGM(MSG_STATS_TOTALFILAMENT);
  1037. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)), 1);
  1038. lcd.print(ftostr32ns(_filament_m));
  1039. if (_filament_km > 0)
  1040. {
  1041. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 3, 1);
  1042. lcd.print("km");
  1043. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 8, 1);
  1044. lcd.print(itostr4(_filament_km));
  1045. }
  1046. lcd.setCursor(18, 1);
  1047. lcd.print("m");
  1048. lcd.setCursor(0, 2);
  1049. lcd_printPGM(MSG_STATS_TOTALPRINTTIME);;
  1050. lcd.setCursor(18, 3);
  1051. lcd.print("m");
  1052. lcd.setCursor(14, 3);
  1053. lcd.print(itostr3(_minutes));
  1054. lcd.setCursor(14, 3);
  1055. lcd.print(":");
  1056. lcd.setCursor(12, 3);
  1057. lcd.print("h");
  1058. lcd.setCursor(9, 3);
  1059. lcd.print(itostr3(_hours));
  1060. lcd.setCursor(9, 3);
  1061. lcd.print(":");
  1062. lcd.setCursor(7, 3);
  1063. lcd.print("d");
  1064. lcd.setCursor(4, 3);
  1065. lcd.print(itostr3(_days));
  1066. while (!lcd_clicked())
  1067. {
  1068. manage_heater();
  1069. manage_inactivity(true);
  1070. delay(100);
  1071. }
  1072. lcd_quick_feedback();
  1073. lcd_return_to_status();
  1074. }
  1075. }
  1076. static void _lcd_move(const char *name, int axis, int min, int max) {
  1077. if (encoderPosition != 0) {
  1078. refresh_cmd_timeout();
  1079. if (! planner_queue_full()) {
  1080. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  1081. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  1082. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  1083. encoderPosition = 0;
  1084. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  1085. 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);
  1086. lcdDrawUpdate = 1;
  1087. }
  1088. }
  1089. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  1090. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis); {
  1091. }
  1092. }
  1093. static void lcd_move_e()
  1094. {
  1095. if (degHotend0() > EXTRUDE_MINTEMP) {
  1096. if (encoderPosition != 0)
  1097. {
  1098. refresh_cmd_timeout();
  1099. if (! planner_queue_full()) {
  1100. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  1101. encoderPosition = 0;
  1102. 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);
  1103. lcdDrawUpdate = 1;
  1104. }
  1105. }
  1106. if (lcdDrawUpdate)
  1107. {
  1108. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  1109. }
  1110. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  1111. }
  1112. else {
  1113. lcd_implementation_clear();
  1114. lcd.setCursor(0, 0);
  1115. lcd_printPGM(MSG_ERROR);
  1116. lcd.setCursor(0, 2);
  1117. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  1118. delay(2000);
  1119. lcd_return_to_status();
  1120. }
  1121. }
  1122. // Save a single axis babystep value.
  1123. void EEPROM_save_B(int pos, int* value)
  1124. {
  1125. union Data data;
  1126. data.value = *value;
  1127. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  1128. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  1129. }
  1130. // Read a single axis babystep value.
  1131. void EEPROM_read_B(int pos, int* value)
  1132. {
  1133. union Data data;
  1134. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  1135. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  1136. *value = data.value;
  1137. }
  1138. static void lcd_move_x() {
  1139. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  1140. }
  1141. static void lcd_move_y() {
  1142. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  1143. }
  1144. static void lcd_move_z() {
  1145. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  1146. }
  1147. static void _lcd_babystep(int axis, const char *msg)
  1148. {
  1149. if (menuData.babyStep.status == 0) {
  1150. // Menu was entered.
  1151. // Initialize its status.
  1152. menuData.babyStep.status = 1;
  1153. check_babystep();
  1154. EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]);
  1155. EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]);
  1156. EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]);
  1157. menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS];
  1158. menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  1159. menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  1160. lcdDrawUpdate = 1;
  1161. //SERIAL_ECHO("Z baby step: ");
  1162. //SERIAL_ECHO(menuData.babyStep.babystepMem[2]);
  1163. // Wait 90 seconds before closing the live adjust dialog.
  1164. lcd_timeoutToStatus = millis() + 90000;
  1165. }
  1166. if (encoderPosition != 0)
  1167. {
  1168. if (homing_flag) encoderPosition = 0;
  1169. menuData.babyStep.babystepMem[axis] += (int)encoderPosition;
  1170. if (axis == 2) {
  1171. if (menuData.babyStep.babystepMem[axis] < Z_BABYSTEP_MIN) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  1172. else if (menuData.babyStep.babystepMem[axis] > Z_BABYSTEP_MAX) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MAX; //0
  1173. else {
  1174. CRITICAL_SECTION_START
  1175. babystepsTodo[axis] += (int)encoderPosition;
  1176. CRITICAL_SECTION_END
  1177. }
  1178. }
  1179. menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[axis];
  1180. delay(50);
  1181. encoderPosition = 0;
  1182. lcdDrawUpdate = 1;
  1183. }
  1184. if (lcdDrawUpdate)
  1185. lcd_implementation_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
  1186. if (LCD_CLICKED || menuExiting) {
  1187. // Only update the EEPROM when leaving the menu.
  1188. EEPROM_save_B(
  1189. (axis == 0) ? EEPROM_BABYSTEP_X : ((axis == 1) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  1190. &menuData.babyStep.babystepMem[axis]);
  1191. }
  1192. if (LCD_CLICKED) lcd_goto_menu(lcd_main_menu);
  1193. }
  1194. static void lcd_babystep_x() {
  1195. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  1196. }
  1197. static void lcd_babystep_y() {
  1198. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  1199. }
  1200. static void lcd_babystep_z() {
  1201. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  1202. }
  1203. static void lcd_adjust_bed();
  1204. static void lcd_adjust_bed_reset()
  1205. {
  1206. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1207. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  1208. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  1209. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  1210. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  1211. lcd_goto_menu(lcd_adjust_bed, 0, false);
  1212. // Because we did not leave the menu, the menuData did not reset.
  1213. // Force refresh of the bed leveling data.
  1214. menuData.adjustBed.status = 0;
  1215. }
  1216. void adjust_bed_reset() {
  1217. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1218. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
  1219. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  1220. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  1221. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
  1222. menuData.adjustBed.left = menuData.adjustBed.left2 = 0;
  1223. menuData.adjustBed.right = menuData.adjustBed.right2 = 0;
  1224. menuData.adjustBed.front = menuData.adjustBed.front2 = 0;
  1225. menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0;
  1226. }
  1227. #define BED_ADJUSTMENT_UM_MAX 50
  1228. static void lcd_adjust_bed()
  1229. {
  1230. if (menuData.adjustBed.status == 0) {
  1231. // Menu was entered.
  1232. // Initialize its status.
  1233. menuData.adjustBed.status = 1;
  1234. bool valid = false;
  1235. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  1236. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  1237. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  1238. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  1239. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  1240. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX &&
  1241. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX &&
  1242. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX &&
  1243. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX)
  1244. valid = true;
  1245. if (! valid) {
  1246. // Reset the values: simulate an edit.
  1247. menuData.adjustBed.left2 = 0;
  1248. menuData.adjustBed.right2 = 0;
  1249. menuData.adjustBed.front2 = 0;
  1250. menuData.adjustBed.rear2 = 0;
  1251. }
  1252. lcdDrawUpdate = 1;
  1253. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1254. }
  1255. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  1256. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  1257. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  1258. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  1259. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  1260. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  1261. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  1262. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  1263. START_MENU();
  1264. MENU_ITEM(back, MSG_SETTINGS, lcd_calibration_menu);
  1265. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_LEFT, &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1266. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_RIGHT, &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1267. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_FRONT, &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1268. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_REAR, &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1269. MENU_ITEM(function, MSG_BED_CORRECTION_RESET, lcd_adjust_bed_reset);
  1270. END_MENU();
  1271. }
  1272. void pid_extruder() {
  1273. lcd_implementation_clear();
  1274. lcd.setCursor(1, 0);
  1275. lcd_printPGM(MSG_SET_TEMPERATURE);
  1276. pid_temp += int(encoderPosition);
  1277. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  1278. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  1279. encoderPosition = 0;
  1280. lcd.setCursor(1, 2);
  1281. lcd.print(ftostr3(pid_temp));
  1282. if (lcd_clicked()) {
  1283. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  1284. lcd_return_to_status();
  1285. lcd_update(2);
  1286. }
  1287. }
  1288. void lcd_adjust_z() {
  1289. int enc_dif = 0;
  1290. int cursor_pos = 1;
  1291. int fsm = 0;
  1292. lcd_implementation_clear();
  1293. lcd.setCursor(0, 0);
  1294. lcd_printPGM(MSG_ADJUSTZ);
  1295. lcd.setCursor(1, 1);
  1296. lcd_printPGM(MSG_YES);
  1297. lcd.setCursor(1, 2);
  1298. lcd_printPGM(MSG_NO);
  1299. lcd.setCursor(0, 1);
  1300. lcd.print(">");
  1301. enc_dif = encoderDiff;
  1302. while (fsm == 0) {
  1303. manage_heater();
  1304. manage_inactivity(true);
  1305. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1306. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1307. if (enc_dif > encoderDiff ) {
  1308. cursor_pos --;
  1309. }
  1310. if (enc_dif < encoderDiff ) {
  1311. cursor_pos ++;
  1312. }
  1313. if (cursor_pos > 2) {
  1314. cursor_pos = 2;
  1315. }
  1316. if (cursor_pos < 1) {
  1317. cursor_pos = 1;
  1318. }
  1319. lcd.setCursor(0, 1);
  1320. lcd.print(" ");
  1321. lcd.setCursor(0, 2);
  1322. lcd.print(" ");
  1323. lcd.setCursor(0, cursor_pos);
  1324. lcd.print(">");
  1325. enc_dif = encoderDiff;
  1326. delay(100);
  1327. }
  1328. }
  1329. if (lcd_clicked()) {
  1330. fsm = cursor_pos;
  1331. if (fsm == 1) {
  1332. int babystepLoadZ = 0;
  1333. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  1334. CRITICAL_SECTION_START
  1335. babystepsTodo[Z_AXIS] = babystepLoadZ;
  1336. CRITICAL_SECTION_END
  1337. } else {
  1338. int zero = 0;
  1339. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  1340. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  1341. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  1342. }
  1343. delay(500);
  1344. }
  1345. };
  1346. lcd_implementation_clear();
  1347. lcd_return_to_status();
  1348. }
  1349. void lcd_wait_for_cool_down() {
  1350. lcd_set_custom_characters_degree();
  1351. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  1352. lcd_display_message_fullscreen_P(MSG_WAITING_TEMP);
  1353. lcd.setCursor(0, 4);
  1354. lcd.print(LCD_STR_THERMOMETER[0]);
  1355. lcd.print(ftostr3(degHotend(0)));
  1356. lcd.print("/0");
  1357. lcd.print(LCD_STR_DEGREE);
  1358. lcd.setCursor(9, 4);
  1359. lcd.print(LCD_STR_BEDTEMP[0]);
  1360. lcd.print(ftostr3(degBed()));
  1361. lcd.print("/0");
  1362. lcd.print(LCD_STR_DEGREE);
  1363. lcd_set_custom_characters();
  1364. delay_keep_alive(1000);
  1365. }
  1366. lcd_set_custom_characters_arrows();
  1367. }
  1368. // Lets the user move the Z carriage up to the end stoppers.
  1369. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1370. // Otherwise the Z calibration is not changed and false is returned.
  1371. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  1372. {
  1373. bool clean_nozzle_asked = false;
  1374. // 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.
  1375. current_position[Z_AXIS] = 0;
  1376. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1377. // Until confirmed by the confirmation dialog.
  1378. for (;;) {
  1379. unsigned long previous_millis_cmd = millis();
  1380. const char *msg = only_z ? MSG_MOVE_CARRIAGE_TO_THE_TOP_Z : MSG_MOVE_CARRIAGE_TO_THE_TOP;
  1381. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  1382. const bool multi_screen = msg_next != NULL;
  1383. unsigned long previous_millis_msg = millis();
  1384. // Until the user finishes the z up movement.
  1385. encoderDiff = 0;
  1386. encoderPosition = 0;
  1387. for (;;) {
  1388. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1389. // goto canceled;
  1390. manage_heater();
  1391. manage_inactivity(true);
  1392. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  1393. delay(50);
  1394. previous_millis_cmd = millis();
  1395. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  1396. encoderDiff = 0;
  1397. if (! planner_queue_full()) {
  1398. // Only move up, whatever direction the user rotates the encoder.
  1399. current_position[Z_AXIS] += fabs(encoderPosition);
  1400. encoderPosition = 0;
  1401. 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);
  1402. }
  1403. }
  1404. if (lcd_clicked()) {
  1405. // Abort a move if in progress.
  1406. planner_abort_hard();
  1407. while (lcd_clicked()) ;
  1408. delay(10);
  1409. while (lcd_clicked()) ;
  1410. break;
  1411. }
  1412. if (multi_screen && millis() - previous_millis_msg > 5000) {
  1413. if (msg_next == NULL)
  1414. msg_next = msg;
  1415. msg_next = lcd_display_message_fullscreen_P(msg_next);
  1416. previous_millis_msg = millis();
  1417. }
  1418. }
  1419. if (! clean_nozzle_asked) {
  1420. lcd_show_fullscreen_message_and_wait_P(MSG_CONFIRM_NOZZLE_CLEAN);
  1421. clean_nozzle_asked = true;
  1422. }
  1423. // Let the user confirm, that the Z carriage is at the top end stoppers.
  1424. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CONFIRM_CARRIAGE_AT_THE_TOP, false);
  1425. if (result == -1)
  1426. goto canceled;
  1427. else if (result == 1)
  1428. goto calibrated;
  1429. // otherwise perform another round of the Z up dialog.
  1430. }
  1431. calibrated:
  1432. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  1433. // during the search for the induction points.
  1434. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  1435. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1436. if(only_z){
  1437. lcd_display_message_fullscreen_P(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1);
  1438. lcd_implementation_print_at(0, 3, 1);
  1439. lcd_printPGM(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2);
  1440. }else{
  1441. lcd_show_fullscreen_message_and_wait_P(MSG_PAPER);
  1442. lcd_display_message_fullscreen_P(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1);
  1443. lcd_implementation_print_at(0, 2, 1);
  1444. lcd_printPGM(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2);
  1445. }
  1446. return true;
  1447. canceled:
  1448. return false;
  1449. }
  1450. static inline bool pgm_is_whitespace(const char *c_addr)
  1451. {
  1452. const char c = pgm_read_byte(c_addr);
  1453. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  1454. }
  1455. static inline bool pgm_is_interpunction(const char *c_addr)
  1456. {
  1457. const char c = pgm_read_byte(c_addr);
  1458. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  1459. }
  1460. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  1461. {
  1462. // Disable update of the screen by the usual lcd_update() routine.
  1463. lcd_update_enable(false);
  1464. lcd_implementation_clear();
  1465. lcd.setCursor(0, 0);
  1466. const char *msgend = msg;
  1467. uint8_t row = 0;
  1468. bool multi_screen = false;
  1469. for (; row < 4; ++ row) {
  1470. while (pgm_is_whitespace(msg))
  1471. ++ msg;
  1472. if (pgm_read_byte(msg) == 0)
  1473. // End of the message.
  1474. break;
  1475. lcd.setCursor(0, row);
  1476. uint8_t linelen = min(strlen_P(msg), 20);
  1477. const char *msgend2 = msg + linelen;
  1478. msgend = msgend2;
  1479. if (row == 3 && linelen == 20) {
  1480. // Last line of the display, full line shall be displayed.
  1481. // Find out, whether this message will be split into multiple screens.
  1482. while (pgm_is_whitespace(msgend))
  1483. ++ msgend;
  1484. multi_screen = pgm_read_byte(msgend) != 0;
  1485. if (multi_screen)
  1486. msgend = (msgend2 -= 2);
  1487. }
  1488. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  1489. // Splitting a word. Find the start of the current word.
  1490. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  1491. -- msgend;
  1492. if (msgend == msg)
  1493. // Found a single long word, which cannot be split. Just cut it.
  1494. msgend = msgend2;
  1495. }
  1496. for (; msg < msgend; ++ msg) {
  1497. char c = char(pgm_read_byte(msg));
  1498. if (c == '~')
  1499. c = ' ';
  1500. lcd.print(c);
  1501. }
  1502. }
  1503. if (multi_screen) {
  1504. // Display the "next screen" indicator character.
  1505. // lcd_set_custom_characters_arrows();
  1506. lcd_set_custom_characters_nextpage();
  1507. lcd.setCursor(19, 3);
  1508. // Display the down arrow.
  1509. lcd.print(char(1));
  1510. }
  1511. nlines = row;
  1512. return multi_screen ? msgend : NULL;
  1513. }
  1514. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  1515. {
  1516. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  1517. bool multi_screen = msg_next != NULL;
  1518. // Until confirmed by a button click.
  1519. for (;;) {
  1520. // Wait for 5 seconds before displaying the next text.
  1521. for (uint8_t i = 0; i < 100; ++ i) {
  1522. delay_keep_alive(50);
  1523. if (lcd_clicked()) {
  1524. while (lcd_clicked()) ;
  1525. delay(10);
  1526. while (lcd_clicked()) ;
  1527. return;
  1528. }
  1529. }
  1530. if (multi_screen) {
  1531. if (msg_next == NULL)
  1532. msg_next = msg;
  1533. msg_next = lcd_display_message_fullscreen_P(msg_next);
  1534. }
  1535. }
  1536. }
  1537. void lcd_wait_for_click()
  1538. {
  1539. for (;;) {
  1540. manage_heater();
  1541. manage_inactivity(true);
  1542. if (lcd_clicked()) {
  1543. while (lcd_clicked()) ;
  1544. delay(10);
  1545. while (lcd_clicked()) ;
  1546. return;
  1547. }
  1548. }
  1549. }
  1550. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  1551. {
  1552. lcd_display_message_fullscreen_P(msg);
  1553. if (default_yes) {
  1554. lcd.setCursor(0, 2);
  1555. lcd_printPGM(PSTR(">"));
  1556. lcd_printPGM(MSG_YES);
  1557. lcd.setCursor(1, 3);
  1558. lcd_printPGM(MSG_NO);
  1559. }
  1560. else {
  1561. lcd.setCursor(1, 2);
  1562. lcd_printPGM(MSG_YES);
  1563. lcd.setCursor(0, 3);
  1564. lcd_printPGM(PSTR(">"));
  1565. lcd_printPGM(MSG_NO);
  1566. }
  1567. bool yes = default_yes ? true : false;
  1568. // Wait for user confirmation or a timeout.
  1569. unsigned long previous_millis_cmd = millis();
  1570. int8_t enc_dif = encoderDiff;
  1571. for (;;) {
  1572. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1573. return -1;
  1574. manage_heater();
  1575. manage_inactivity(true);
  1576. if (abs(enc_dif - encoderDiff) > 4) {
  1577. lcd.setCursor(0, 2);
  1578. if (enc_dif < encoderDiff && yes) {
  1579. lcd_printPGM((PSTR(" ")));
  1580. lcd.setCursor(0, 3);
  1581. lcd_printPGM((PSTR(">")));
  1582. yes = false;
  1583. }
  1584. else if (enc_dif > encoderDiff && !yes) {
  1585. lcd_printPGM((PSTR(">")));
  1586. lcd.setCursor(0, 3);
  1587. lcd_printPGM((PSTR(" ")));
  1588. yes = true;
  1589. }
  1590. enc_dif = encoderDiff;
  1591. }
  1592. if (lcd_clicked()) {
  1593. while (lcd_clicked());
  1594. delay(10);
  1595. while (lcd_clicked());
  1596. return yes;
  1597. }
  1598. }
  1599. }
  1600. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  1601. {
  1602. const char *msg = NULL;
  1603. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  1604. lcd_show_fullscreen_message_and_wait_P(MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND);
  1605. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  1606. if (point_too_far_mask == 0)
  1607. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1608. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1609. // Only the center point or all the three front points.
  1610. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR;
  1611. else if (point_too_far_mask & 1 == 0)
  1612. // The right and maybe the center point out of reach.
  1613. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR;
  1614. else
  1615. // The left and maybe the center point out of reach.
  1616. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR;
  1617. lcd_show_fullscreen_message_and_wait_P(msg);
  1618. } else {
  1619. if (point_too_far_mask != 0) {
  1620. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1621. // Only the center point or all the three front points.
  1622. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR;
  1623. else if (point_too_far_mask & 1 == 0)
  1624. // The right and maybe the center point out of reach.
  1625. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR;
  1626. else
  1627. // The left and maybe the center point out of reach.
  1628. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR;
  1629. lcd_show_fullscreen_message_and_wait_P(msg);
  1630. }
  1631. if (point_too_far_mask == 0 || result > 0) {
  1632. switch (result) {
  1633. default:
  1634. // should not happen
  1635. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1636. break;
  1637. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  1638. msg = MSG_BED_SKEW_OFFSET_DETECTION_PERFECT;
  1639. break;
  1640. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  1641. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD;
  1642. break;
  1643. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  1644. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
  1645. break;
  1646. }
  1647. lcd_show_fullscreen_message_and_wait_P(msg);
  1648. }
  1649. }
  1650. }
  1651. static void lcd_show_end_stops() {
  1652. lcd.setCursor(0, 0);
  1653. lcd_printPGM((PSTR("End stops diag")));
  1654. lcd.setCursor(0, 1);
  1655. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  1656. lcd.setCursor(0, 2);
  1657. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  1658. lcd.setCursor(0, 3);
  1659. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  1660. }
  1661. static void menu_show_end_stops() {
  1662. lcd_show_end_stops();
  1663. if (LCD_CLICKED) lcd_goto_menu(lcd_calibration_menu);
  1664. }
  1665. // Lets the user move the Z carriage up to the end stoppers.
  1666. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1667. // Otherwise the Z calibration is not changed and false is returned.
  1668. void lcd_diag_show_end_stops()
  1669. {
  1670. int enc_dif = encoderDiff;
  1671. lcd_implementation_clear();
  1672. for (;;) {
  1673. manage_heater();
  1674. manage_inactivity(true);
  1675. lcd_show_end_stops();
  1676. if (lcd_clicked()) {
  1677. while (lcd_clicked()) ;
  1678. delay(10);
  1679. while (lcd_clicked()) ;
  1680. break;
  1681. }
  1682. }
  1683. lcd_implementation_clear();
  1684. lcd_return_to_status();
  1685. }
  1686. void prusa_statistics(int _message) {
  1687. switch (_message)
  1688. {
  1689. case 0: // default message
  1690. if (IS_SD_PRINTING)
  1691. {
  1692. SERIAL_ECHO("{");
  1693. prusa_stat_printerstatus(4);
  1694. prusa_stat_farm_number();
  1695. prusa_stat_printinfo();
  1696. SERIAL_ECHOLN("}");
  1697. status_number = 4;
  1698. }
  1699. else
  1700. {
  1701. SERIAL_ECHO("{");
  1702. prusa_stat_printerstatus(1);
  1703. prusa_stat_farm_number();
  1704. SERIAL_ECHOLN("}");
  1705. status_number = 1;
  1706. }
  1707. break;
  1708. case 1: // 1 heating
  1709. farm_status = 2;
  1710. SERIAL_ECHO("{");
  1711. prusa_stat_printerstatus(2);
  1712. prusa_stat_farm_number();
  1713. SERIAL_ECHOLN("}");
  1714. status_number = 2;
  1715. farm_timer = 1;
  1716. break;
  1717. case 2: // heating done
  1718. farm_status = 3;
  1719. SERIAL_ECHO("{");
  1720. prusa_stat_printerstatus(3);
  1721. prusa_stat_farm_number();
  1722. SERIAL_ECHOLN("}");
  1723. status_number = 3;
  1724. farm_timer = 1;
  1725. if (IS_SD_PRINTING)
  1726. {
  1727. farm_status = 4;
  1728. SERIAL_ECHO("{");
  1729. prusa_stat_printerstatus(4);
  1730. prusa_stat_farm_number();
  1731. SERIAL_ECHOLN("}");
  1732. status_number = 4;
  1733. }
  1734. else
  1735. {
  1736. SERIAL_ECHO("{");
  1737. prusa_stat_printerstatus(3);
  1738. prusa_stat_farm_number();
  1739. SERIAL_ECHOLN("}");
  1740. status_number = 3;
  1741. }
  1742. farm_timer = 1;
  1743. break;
  1744. case 3: // filament change
  1745. break;
  1746. case 4: // print succesfull
  1747. SERIAL_ECHOLN("{[RES:1]");
  1748. prusa_stat_printerstatus(status_number);
  1749. prusa_stat_farm_number();
  1750. SERIAL_ECHOLN("}");
  1751. farm_timer = 2;
  1752. break;
  1753. case 5: // print not succesfull
  1754. SERIAL_ECHOLN("{[RES:0]");
  1755. prusa_stat_printerstatus(status_number);
  1756. prusa_stat_farm_number();
  1757. SERIAL_ECHOLN("}");
  1758. farm_timer = 2;
  1759. break;
  1760. case 6: // print done
  1761. SERIAL_ECHOLN("{[PRN:8]");
  1762. prusa_stat_farm_number();
  1763. SERIAL_ECHOLN("}");
  1764. status_number = 8;
  1765. farm_timer = 2;
  1766. break;
  1767. case 7: // print done - stopped
  1768. SERIAL_ECHOLN("{[PRN:9]");
  1769. prusa_stat_farm_number();
  1770. SERIAL_ECHOLN("}");
  1771. status_number = 9;
  1772. farm_timer = 2;
  1773. break;
  1774. case 8: // printer started
  1775. SERIAL_ECHO("{[PRN:0][PFN:");
  1776. status_number = 0;
  1777. SERIAL_ECHO(farm_no);
  1778. SERIAL_ECHOLN("]}");
  1779. farm_timer = 2;
  1780. break;
  1781. case 20: // echo farm no
  1782. SERIAL_ECHOLN("{");
  1783. prusa_stat_printerstatus(status_number);
  1784. prusa_stat_farm_number();
  1785. SERIAL_ECHOLN("}");
  1786. farm_timer = 5;
  1787. break;
  1788. case 21: // temperatures
  1789. SERIAL_ECHO("{");
  1790. prusa_stat_temperatures();
  1791. prusa_stat_farm_number();
  1792. prusa_stat_printerstatus(status_number);
  1793. SERIAL_ECHOLN("}");
  1794. break;
  1795. case 22: // waiting for filament change
  1796. SERIAL_ECHOLN("{[PRN:5]");
  1797. prusa_stat_farm_number();
  1798. SERIAL_ECHOLN("}");
  1799. status_number = 5;
  1800. break;
  1801. case 90: // Error - Thermal Runaway
  1802. SERIAL_ECHOLN("{[ERR:1]");
  1803. prusa_stat_farm_number();
  1804. SERIAL_ECHOLN("}");
  1805. break;
  1806. case 91: // Error - Thermal Runaway Preheat
  1807. SERIAL_ECHOLN("{[ERR:2]");
  1808. prusa_stat_farm_number();
  1809. SERIAL_ECHOLN("}");
  1810. break;
  1811. case 92: // Error - Min temp
  1812. SERIAL_ECHOLN("{[ERR:3]");
  1813. prusa_stat_farm_number();
  1814. SERIAL_ECHOLN("}");
  1815. break;
  1816. case 93: // Error - Max temp
  1817. SERIAL_ECHOLN("{[ERR:4]");
  1818. prusa_stat_farm_number();
  1819. SERIAL_ECHOLN("}");
  1820. break;
  1821. case 99: // heartbeat
  1822. SERIAL_ECHO("{[PRN:99]");
  1823. prusa_stat_temperatures();
  1824. SERIAL_ECHO("[PFN:");
  1825. SERIAL_ECHO(farm_no);
  1826. SERIAL_ECHO("]");
  1827. SERIAL_ECHOLN("}");
  1828. break;
  1829. }
  1830. }
  1831. static void prusa_stat_printerstatus(int _status)
  1832. {
  1833. SERIAL_ECHO("[PRN:");
  1834. SERIAL_ECHO(_status);
  1835. SERIAL_ECHO("]");
  1836. }
  1837. static void prusa_stat_farm_number() {
  1838. SERIAL_ECHO("[PFN:");
  1839. SERIAL_ECHO(farm_no);
  1840. SERIAL_ECHO("]");
  1841. }
  1842. static void prusa_stat_temperatures()
  1843. {
  1844. SERIAL_ECHO("[ST0:");
  1845. SERIAL_ECHO(target_temperature[0]);
  1846. SERIAL_ECHO("][STB:");
  1847. SERIAL_ECHO(target_temperature_bed);
  1848. SERIAL_ECHO("][AT0:");
  1849. SERIAL_ECHO(current_temperature[0]);
  1850. SERIAL_ECHO("][ATB:");
  1851. SERIAL_ECHO(current_temperature_bed);
  1852. SERIAL_ECHO("]");
  1853. }
  1854. static void prusa_stat_printinfo()
  1855. {
  1856. SERIAL_ECHO("[TFU:");
  1857. SERIAL_ECHO(total_filament_used);
  1858. SERIAL_ECHO("][PCD:");
  1859. SERIAL_ECHO(itostr3(card.percentDone()));
  1860. SERIAL_ECHO("][FEM:");
  1861. SERIAL_ECHO(itostr3(feedmultiply));
  1862. SERIAL_ECHO("][FNM:");
  1863. SERIAL_ECHO(longFilenameOLD);
  1864. SERIAL_ECHO("][TIM:");
  1865. if (starttime != 0)
  1866. {
  1867. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  1868. }
  1869. else
  1870. {
  1871. SERIAL_ECHO(0);
  1872. }
  1873. SERIAL_ECHO("][FWR:");
  1874. SERIAL_ECHO(FW_version);
  1875. SERIAL_ECHO("]");
  1876. }
  1877. void lcd_pick_babystep(){
  1878. int enc_dif = 0;
  1879. int cursor_pos = 1;
  1880. int fsm = 0;
  1881. lcd_implementation_clear();
  1882. lcd.setCursor(0, 0);
  1883. lcd_printPGM(MSG_PICK_Z);
  1884. lcd.setCursor(3, 2);
  1885. lcd.print("1");
  1886. lcd.setCursor(3, 3);
  1887. lcd.print("2");
  1888. lcd.setCursor(12, 2);
  1889. lcd.print("3");
  1890. lcd.setCursor(12, 3);
  1891. lcd.print("4");
  1892. lcd.setCursor(1, 2);
  1893. lcd.print(">");
  1894. enc_dif = encoderDiff;
  1895. while (fsm == 0) {
  1896. manage_heater();
  1897. manage_inactivity(true);
  1898. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1899. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1900. if (enc_dif > encoderDiff ) {
  1901. cursor_pos --;
  1902. }
  1903. if (enc_dif < encoderDiff ) {
  1904. cursor_pos ++;
  1905. }
  1906. if (cursor_pos > 4) {
  1907. cursor_pos = 4;
  1908. }
  1909. if (cursor_pos < 1) {
  1910. cursor_pos = 1;
  1911. }
  1912. lcd.setCursor(1, 2);
  1913. lcd.print(" ");
  1914. lcd.setCursor(1, 3);
  1915. lcd.print(" ");
  1916. lcd.setCursor(10, 2);
  1917. lcd.print(" ");
  1918. lcd.setCursor(10, 3);
  1919. lcd.print(" ");
  1920. if (cursor_pos < 3) {
  1921. lcd.setCursor(1, cursor_pos+1);
  1922. lcd.print(">");
  1923. }else{
  1924. lcd.setCursor(10, cursor_pos-1);
  1925. lcd.print(">");
  1926. }
  1927. enc_dif = encoderDiff;
  1928. delay(100);
  1929. }
  1930. }
  1931. if (lcd_clicked()) {
  1932. fsm = cursor_pos;
  1933. int babyStepZ;
  1934. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  1935. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  1936. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  1937. delay(500);
  1938. }
  1939. };
  1940. lcd_implementation_clear();
  1941. lcd_return_to_status();
  1942. }
  1943. void lcd_move_menu_axis()
  1944. {
  1945. START_MENU();
  1946. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1947. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  1948. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  1949. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1950. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1951. END_MENU();
  1952. }
  1953. static void lcd_move_menu_1mm()
  1954. {
  1955. move_menu_scale = 1.0;
  1956. lcd_move_menu_axis();
  1957. }
  1958. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  1959. {
  1960. do
  1961. {
  1962. eeprom_write_byte((unsigned char*)pos, *value);
  1963. pos++;
  1964. value++;
  1965. } while (--size);
  1966. }
  1967. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  1968. {
  1969. do
  1970. {
  1971. *value = eeprom_read_byte((unsigned char*)pos);
  1972. pos++;
  1973. value++;
  1974. } while (--size);
  1975. }
  1976. static void lcd_silent_mode_set() {
  1977. SilentModeMenu = !SilentModeMenu;
  1978. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  1979. digipot_init();
  1980. lcd_goto_menu(lcd_settings_menu, 7);
  1981. }
  1982. static void lcd_set_lang(unsigned char lang) {
  1983. lang_selected = lang;
  1984. firstrun = 1;
  1985. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  1986. /*langsel=0;*/
  1987. if (langsel == LANGSEL_MODAL)
  1988. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  1989. langsel = LANGSEL_ACTIVE;
  1990. }
  1991. void lcd_force_language_selection() {
  1992. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  1993. }
  1994. static void lcd_language_menu()
  1995. {
  1996. START_MENU();
  1997. if (langsel == LANGSEL_OFF) {
  1998. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1999. } else if (langsel == LANGSEL_ACTIVE) {
  2000. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  2001. }
  2002. for (int i=0;i<LANG_NUM;i++){
  2003. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  2004. }
  2005. END_MENU();
  2006. }
  2007. void lcd_mesh_bedleveling()
  2008. {
  2009. enquecommand_P(PSTR("G80"));
  2010. lcd_return_to_status();
  2011. }
  2012. void lcd_mesh_calibration()
  2013. {
  2014. enquecommand_P(PSTR("M45"));
  2015. lcd_return_to_status();
  2016. }
  2017. void lcd_mesh_calibration_z()
  2018. {
  2019. enquecommand_P(PSTR("M45 Z"));
  2020. lcd_return_to_status();
  2021. }
  2022. void lcd_pinda_calibration_menu()
  2023. {
  2024. START_MENU();
  2025. MENU_ITEM(back, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  2026. MENU_ITEM(submenu, MSG_CALIBRATE_PINDA, lcd_calibrate_pinda);
  2027. if (temp_cal_active == false) {
  2028. MENU_ITEM(function, MSG_TEMP_CALIBRATION_OFF, lcd_temp_calibration_set);
  2029. }
  2030. else {
  2031. MENU_ITEM(function, MSG_TEMP_CALIBRATION_ON, lcd_temp_calibration_set);
  2032. }
  2033. END_MENU();
  2034. }
  2035. void lcd_temp_calibration_set() {
  2036. temp_cal_active = !temp_cal_active;
  2037. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  2038. digipot_init();
  2039. lcd_goto_menu(lcd_pinda_calibration_menu, 2);
  2040. }
  2041. void lcd_calibrate_pinda() {
  2042. enquecommand_P(PSTR("G76"));
  2043. lcd_return_to_status();
  2044. }
  2045. #ifndef SNMM
  2046. /*void lcd_calibrate_extruder() {
  2047. if (degHotend0() > EXTRUDE_MINTEMP)
  2048. {
  2049. current_position[E_AXIS] = 0; //set initial position to zero
  2050. plan_set_e_position(current_position[E_AXIS]);
  2051. //long steps_start = st_get_position(E_AXIS);
  2052. long steps_final;
  2053. float e_steps_per_unit;
  2054. float feedrate = (180 / axis_steps_per_unit[E_AXIS]) * 1; //3 //initial automatic extrusion feedrate (depends on current value of axis_steps_per_unit to avoid too fast extrusion)
  2055. float e_shift_calibration = (axis_steps_per_unit[E_AXIS] > 180 ) ? ((180 / axis_steps_per_unit[E_AXIS]) * 70): 70; //length of initial automatic extrusion sequence
  2056. const char *msg_e_cal_knob = MSG_E_CAL_KNOB;
  2057. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  2058. const bool multi_screen = msg_next_e_cal_knob != NULL;
  2059. unsigned long msg_millis;
  2060. lcd_show_fullscreen_message_and_wait_P(MSG_MARK_FIL);
  2061. lcd_implementation_clear();
  2062. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  2063. current_position[E_AXIS] += e_shift_calibration;
  2064. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  2065. st_synchronize();
  2066. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  2067. msg_millis = millis();
  2068. while (!LCD_CLICKED) {
  2069. if (multi_screen && millis() - msg_millis > 5000) {
  2070. if (msg_next_e_cal_knob == NULL)
  2071. msg_next_e_cal_knob = msg_e_cal_knob;
  2072. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  2073. msg_millis = millis();
  2074. }
  2075. //manage_inactivity(true);
  2076. manage_heater();
  2077. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  2078. delay_keep_alive(50);
  2079. //previous_millis_cmd = millis();
  2080. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  2081. encoderDiff = 0;
  2082. if (!planner_queue_full()) {
  2083. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  2084. encoderPosition = 0;
  2085. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  2086. }
  2087. }
  2088. }
  2089. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  2090. //steps_final = st_get_position(E_AXIS);
  2091. lcdDrawUpdate = 1;
  2092. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  2093. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  2094. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  2095. lcd_implementation_clear();
  2096. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  2097. enquecommand_P(PSTR("M500")); //store settings to eeprom
  2098. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  2099. //delay_keep_alive(2000);
  2100. delay_keep_alive(500);
  2101. lcd_show_fullscreen_message_and_wait_P(MSG_CLEAN_NOZZLE_E);
  2102. lcd_update_enable(true);
  2103. lcdDrawUpdate = 2;
  2104. }
  2105. else
  2106. {
  2107. lcd_implementation_clear();
  2108. lcd.setCursor(0, 0);
  2109. lcd_printPGM(MSG_ERROR);
  2110. lcd.setCursor(0, 2);
  2111. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2112. delay(2000);
  2113. lcd_implementation_clear();
  2114. }
  2115. lcd_return_to_status();
  2116. }
  2117. void lcd_extr_cal_reset() {
  2118. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  2119. axis_steps_per_unit[E_AXIS] = tmp1[3];
  2120. //extrudemultiply = 100;
  2121. enquecommand_P(PSTR("M500"));
  2122. }*/
  2123. #endif
  2124. void lcd_toshiba_flash_air_compatibility_toggle()
  2125. {
  2126. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  2127. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  2128. }
  2129. static void lcd_settings_menu()
  2130. {
  2131. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  2132. START_MENU();
  2133. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2134. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2135. if (!homing_flag)
  2136. {
  2137. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  2138. }
  2139. if (!isPrintPaused)
  2140. {
  2141. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2142. }
  2143. if ((SilentModeMenu == 0) || (farm_mode) ) {
  2144. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  2145. } else {
  2146. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  2147. }
  2148. if (!isPrintPaused && !homing_flag)
  2149. {
  2150. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  2151. }
  2152. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  2153. if (card.ToshibaFlashAir_isEnabled()) {
  2154. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  2155. } else {
  2156. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  2157. }
  2158. if (farm_mode)
  2159. {
  2160. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  2161. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  2162. }
  2163. END_MENU();
  2164. }
  2165. static void lcd_calibration_menu()
  2166. {
  2167. START_MENU();
  2168. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2169. if (!isPrintPaused)
  2170. {
  2171. MENU_ITEM(function, MSG_SELFTEST, lcd_selftest);
  2172. #ifndef MESH_BED_LEVELING
  2173. // MK1
  2174. // "Calibrate Z"
  2175. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  2176. #else
  2177. // MK2
  2178. MENU_ITEM(function, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  2179. // "Calibrate Z" with storing the reference values to EEPROM.
  2180. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  2181. #ifndef SNMM
  2182. //MENU_ITEM(function, MSG_CALIBRATE_E, lcd_calibrate_extruder);
  2183. #endif
  2184. // "Mesh Bed Leveling"
  2185. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  2186. #endif
  2187. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  2188. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  2189. MENU_ITEM(submenu, MSG_CALIBRATION_PINDA_MENU, lcd_pinda_calibration_menu);
  2190. MENU_ITEM(submenu, MSG_PID_EXTRUDER, pid_extruder);
  2191. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  2192. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  2193. #ifndef SNMM
  2194. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  2195. #endif
  2196. }
  2197. END_MENU();
  2198. }
  2199. /*
  2200. void lcd_mylang_top(int hlaska) {
  2201. lcd.setCursor(0,0);
  2202. lcd.print(" ");
  2203. lcd.setCursor(0,0);
  2204. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  2205. }
  2206. void lcd_mylang_drawmenu(int cursor) {
  2207. int first = 0;
  2208. if (cursor>2) first = cursor-2;
  2209. if (cursor==LANG_NUM) first = LANG_NUM-3;
  2210. lcd.setCursor(0, 1);
  2211. lcd.print(" ");
  2212. lcd.setCursor(1, 1);
  2213. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  2214. lcd.setCursor(0, 2);
  2215. lcd.print(" ");
  2216. lcd.setCursor(1, 2);
  2217. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  2218. lcd.setCursor(0, 3);
  2219. lcd.print(" ");
  2220. lcd.setCursor(1, 3);
  2221. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  2222. if (cursor==1) lcd.setCursor(0, 1);
  2223. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2224. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2225. lcd.print(">");
  2226. if (cursor<LANG_NUM-1) {
  2227. lcd.setCursor(19,3);
  2228. lcd.print("\x01");
  2229. }
  2230. if (cursor>2) {
  2231. lcd.setCursor(19,1);
  2232. lcd.print("^");
  2233. }
  2234. }
  2235. */
  2236. void lcd_mylang_drawmenu(int cursor) {
  2237. int first = 0;
  2238. if (cursor>3) first = cursor-3;
  2239. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  2240. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  2241. lcd.setCursor(0, 0);
  2242. lcd.print(" ");
  2243. lcd.setCursor(1, 0);
  2244. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  2245. lcd.setCursor(0, 1);
  2246. lcd.print(" ");
  2247. lcd.setCursor(1, 1);
  2248. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  2249. lcd.setCursor(0, 2);
  2250. lcd.print(" ");
  2251. if (LANG_NUM > 2){
  2252. lcd.setCursor(1, 2);
  2253. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  2254. }
  2255. lcd.setCursor(0, 3);
  2256. lcd.print(" ");
  2257. if (LANG_NUM>3) {
  2258. lcd.setCursor(1, 3);
  2259. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  2260. }
  2261. if (cursor==1) lcd.setCursor(0, 0);
  2262. if (cursor==2) lcd.setCursor(0, 1);
  2263. if (cursor>2) lcd.setCursor(0, 2);
  2264. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  2265. lcd.print(">");
  2266. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  2267. lcd.setCursor(19,3);
  2268. lcd.print("\x01");
  2269. }
  2270. if (cursor>3 && LANG_NUM>4) {
  2271. lcd.setCursor(19,0);
  2272. lcd.print("^");
  2273. }
  2274. }
  2275. void lcd_mylang_drawcursor(int cursor) {
  2276. if (cursor==1) lcd.setCursor(0, 1);
  2277. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2278. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2279. lcd.print(">");
  2280. }
  2281. void lcd_mylang() {
  2282. int enc_dif = 0;
  2283. int cursor_pos = 1;
  2284. lang_selected=255;
  2285. int hlaska=1;
  2286. int counter=0;
  2287. lcd_set_custom_characters_arrows();
  2288. lcd_implementation_clear();
  2289. //lcd_mylang_top(hlaska);
  2290. lcd_mylang_drawmenu(cursor_pos);
  2291. enc_dif = encoderDiff;
  2292. while ( (lang_selected == 255) ) {
  2293. manage_heater();
  2294. manage_inactivity(true);
  2295. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2296. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2297. if (enc_dif > encoderDiff ) {
  2298. cursor_pos --;
  2299. }
  2300. if (enc_dif < encoderDiff ) {
  2301. cursor_pos ++;
  2302. }
  2303. if (cursor_pos > LANG_NUM) {
  2304. cursor_pos = LANG_NUM;
  2305. }
  2306. if (cursor_pos < 1) {
  2307. cursor_pos = 1;
  2308. }
  2309. lcd_mylang_drawmenu(cursor_pos);
  2310. enc_dif = encoderDiff;
  2311. delay(100);
  2312. //}
  2313. } else delay(20);
  2314. if (lcd_clicked()) {
  2315. lcd_set_lang(cursor_pos-1);
  2316. delay(500);
  2317. }
  2318. /*
  2319. if (++counter == 80) {
  2320. hlaska++;
  2321. if(hlaska>LANG_NUM) hlaska=1;
  2322. lcd_mylang_top(hlaska);
  2323. lcd_mylang_drawcursor(cursor_pos);
  2324. counter=0;
  2325. }
  2326. */
  2327. };
  2328. if(MYSERIAL.available() > 1){
  2329. lang_selected = 0;
  2330. firstrun = 0;
  2331. }
  2332. lcd_set_custom_characters_degree();
  2333. lcd_implementation_clear();
  2334. lcd_return_to_status();
  2335. }
  2336. void bowden_menu() {
  2337. int enc_dif = encoderDiff;
  2338. int cursor_pos = 0;
  2339. lcd_implementation_clear();
  2340. lcd.setCursor(0, 0);
  2341. lcd.print(">");
  2342. for (int i = 0; i < 4; i++) {
  2343. lcd.setCursor(1, i);
  2344. lcd.print("Extruder ");
  2345. lcd.print(i);
  2346. lcd.print(": ");
  2347. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  2348. lcd.print(bowden_length[i]);
  2349. }
  2350. enc_dif = encoderDiff;
  2351. while (1) {
  2352. manage_heater();
  2353. manage_inactivity(true);
  2354. lcd.setCursor(0, 0);
  2355. lcd.print(" ");
  2356. lcd.setCursor(0, 1);
  2357. lcd.print(" ");
  2358. lcd.setCursor(0, 2);
  2359. lcd.print(" ");
  2360. lcd.setCursor(0, 3);
  2361. lcd.print(" ");
  2362. lcd.setCursor(0, cursor_pos);
  2363. lcd.print(">");
  2364. if (abs((enc_dif - encoderDiff)) > 4) {
  2365. if ((abs(enc_dif - encoderDiff)) > 1) {
  2366. if (enc_dif > encoderDiff) {
  2367. bowden_length[cursor_pos]--;
  2368. lcd.setCursor(13, cursor_pos);
  2369. lcd.print(bowden_length[cursor_pos]);
  2370. enc_dif = encoderDiff;
  2371. }
  2372. if (enc_dif < encoderDiff) {
  2373. bowden_length[cursor_pos]++;
  2374. lcd.setCursor(13, cursor_pos);
  2375. lcd.print(bowden_length[cursor_pos]);
  2376. enc_dif = encoderDiff;
  2377. }
  2378. }
  2379. }
  2380. delay(100);
  2381. if (lcd_clicked()) {
  2382. while (lcd_clicked());
  2383. delay(10);
  2384. while (lcd_clicked());
  2385. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  2386. if (cursor_pos == 3) return;
  2387. else {
  2388. cursor_pos++;
  2389. }
  2390. }
  2391. }
  2392. }
  2393. char reset_menu() {
  2394. #ifdef SNMM
  2395. int items_no = 5;
  2396. #else
  2397. int items_no = 4;
  2398. #endif
  2399. static int first = 0;
  2400. int enc_dif = 0;
  2401. char cursor_pos = 0;
  2402. const char *item [items_no];
  2403. item[0] = "Language";
  2404. item[1] = "Statistics";
  2405. item[2] = "Shipping prep";
  2406. item[3] = "All Data";
  2407. #ifdef SNMM
  2408. item[4] = "Bowden length";
  2409. #endif // SNMM
  2410. enc_dif = encoderDiff;
  2411. lcd_implementation_clear();
  2412. lcd.setCursor(0, 0);
  2413. lcd.print(">");
  2414. while (1) {
  2415. for (int i = 0; i < 4; i++) {
  2416. lcd.setCursor(1, i);
  2417. lcd.print(item[first + i]);
  2418. }
  2419. manage_heater();
  2420. manage_inactivity(true);
  2421. if (abs((enc_dif - encoderDiff)) > 4) {
  2422. if ((abs(enc_dif - encoderDiff)) > 1) {
  2423. if (enc_dif > encoderDiff) {
  2424. cursor_pos--;
  2425. }
  2426. if (enc_dif < encoderDiff) {
  2427. cursor_pos++;
  2428. }
  2429. if (cursor_pos > 3) {
  2430. cursor_pos = 3;
  2431. if (first < items_no - 4) {
  2432. first++;
  2433. lcd_implementation_clear();
  2434. }
  2435. }
  2436. if (cursor_pos < 0) {
  2437. cursor_pos = 0;
  2438. if (first > 0) {
  2439. first--;
  2440. lcd_implementation_clear();
  2441. }
  2442. }
  2443. lcd.setCursor(0, 0);
  2444. lcd.print(" ");
  2445. lcd.setCursor(0, 1);
  2446. lcd.print(" ");
  2447. lcd.setCursor(0, 2);
  2448. lcd.print(" ");
  2449. lcd.setCursor(0, 3);
  2450. lcd.print(" ");
  2451. lcd.setCursor(0, cursor_pos);
  2452. lcd.print(">");
  2453. enc_dif = encoderDiff;
  2454. delay(100);
  2455. }
  2456. }
  2457. if (lcd_clicked()) {
  2458. while (lcd_clicked());
  2459. delay(10);
  2460. while (lcd_clicked());
  2461. return(cursor_pos + first);
  2462. }
  2463. }
  2464. }
  2465. static void lcd_disable_farm_mode() {
  2466. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  2467. if (disable) {
  2468. enquecommand_P(PSTR("G99"));
  2469. lcd_return_to_status();
  2470. }
  2471. else {
  2472. lcd_goto_menu(lcd_settings_menu);
  2473. }
  2474. lcd_update_enable(true);
  2475. lcdDrawUpdate = 2;
  2476. }
  2477. static void lcd_ping_allert() {
  2478. if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
  2479. allert_timer = millis();
  2480. SET_OUTPUT(BEEPER);
  2481. for (int i = 0; i < 2; i++) {
  2482. WRITE(BEEPER, HIGH);
  2483. delay(50);
  2484. WRITE(BEEPER, LOW);
  2485. delay(100);
  2486. }
  2487. }
  2488. };
  2489. #ifdef SNMM
  2490. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  2491. set_extrude_min_temp(.0);
  2492. current_position[E_AXIS] += shift;
  2493. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  2494. set_extrude_min_temp(EXTRUDE_MINTEMP);
  2495. }
  2496. void change_extr(int extr) { //switches multiplexer for extruders
  2497. st_synchronize();
  2498. delay(100);
  2499. disable_e0();
  2500. disable_e1();
  2501. disable_e2();
  2502. #ifdef SNMM
  2503. snmm_extruder = extr;
  2504. #endif
  2505. pinMode(E_MUX0_PIN, OUTPUT);
  2506. pinMode(E_MUX1_PIN, OUTPUT);
  2507. pinMode(E_MUX2_PIN, OUTPUT);
  2508. switch (extr) {
  2509. case 1:
  2510. WRITE(E_MUX0_PIN, HIGH);
  2511. WRITE(E_MUX1_PIN, LOW);
  2512. WRITE(E_MUX2_PIN, LOW);
  2513. break;
  2514. case 2:
  2515. WRITE(E_MUX0_PIN, LOW);
  2516. WRITE(E_MUX1_PIN, HIGH);
  2517. WRITE(E_MUX2_PIN, LOW);
  2518. break;
  2519. case 3:
  2520. WRITE(E_MUX0_PIN, HIGH);
  2521. WRITE(E_MUX1_PIN, HIGH);
  2522. WRITE(E_MUX2_PIN, LOW);
  2523. break;
  2524. default:
  2525. WRITE(E_MUX0_PIN, LOW);
  2526. WRITE(E_MUX1_PIN, LOW);
  2527. WRITE(E_MUX2_PIN, LOW);
  2528. break;
  2529. }
  2530. delay(100);
  2531. }
  2532. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  2533. return(4 * READ(E_MUX2_PIN) + 2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  2534. }
  2535. static void extr_adj(int extruder) //loading filament for SNMM
  2536. {
  2537. bool correct;
  2538. max_feedrate[E_AXIS] =80;
  2539. //max_feedrate[E_AXIS] = 50;
  2540. START:
  2541. lcd_implementation_clear();
  2542. lcd.setCursor(0, 0);
  2543. switch (extruder) {
  2544. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  2545. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  2546. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  2547. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  2548. }
  2549. do{
  2550. extr_mov(0.001,1000);
  2551. delay_keep_alive(2);
  2552. } while (!lcd_clicked());
  2553. //delay_keep_alive(500);
  2554. st_synchronize();
  2555. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  2556. //if (!correct) goto START;
  2557. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  2558. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  2559. extr_mov(BOWDEN_LENGTH, 500);
  2560. lcd_implementation_clear();
  2561. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  2562. st_synchronize();
  2563. max_feedrate[E_AXIS] = 50;
  2564. lcd_update_enable(true);
  2565. lcd_return_to_status();
  2566. lcdDrawUpdate = 2;
  2567. }
  2568. static void extr_unload() { //unloads filament
  2569. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  2570. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  2571. int8_t SilentMode;
  2572. if (degHotend0() > EXTRUDE_MINTEMP) {
  2573. lcd_implementation_clear();
  2574. lcd_display_message_fullscreen_P(PSTR(""));
  2575. max_feedrate[E_AXIS] = 50;
  2576. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  2577. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  2578. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  2579. current_position[E_AXIS] += 10; //extrusion
  2580. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  2581. digipot_current(2, E_MOTOR_HIGH_CURRENT);
  2582. if (current_temperature[0] < 230) { //PLA & all other filaments
  2583. current_position[E_AXIS] += 5.4;
  2584. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  2585. current_position[E_AXIS] += 3.2;
  2586. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2587. current_position[E_AXIS] += 3;
  2588. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  2589. }
  2590. else { //ABS
  2591. current_position[E_AXIS] += 3.1;
  2592. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  2593. current_position[E_AXIS] += 3.1;
  2594. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  2595. current_position[E_AXIS] += 4;
  2596. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2597. /*current_position[X_AXIS] += 23; //delay
  2598. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  2599. current_position[X_AXIS] -= 23; //delay
  2600. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  2601. delay_keep_alive(4700);
  2602. }
  2603. max_feedrate[E_AXIS] = 80;
  2604. current_position[E_AXIS] -= (BOWDEN_LENGTH + 60 + FIL_LOAD_LENGTH) / 2;
  2605. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2606. current_position[E_AXIS] -= (BOWDEN_LENGTH + 60 + FIL_LOAD_LENGTH) / 2;
  2607. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2608. st_synchronize();
  2609. //digipot_init();
  2610. if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  2611. else digipot_current(2, tmp_motor_loud[2]);
  2612. lcd_update_enable(true);
  2613. lcd_return_to_status();
  2614. max_feedrate[E_AXIS] = 50;
  2615. }
  2616. else {
  2617. lcd_implementation_clear();
  2618. lcd.setCursor(0, 0);
  2619. lcd_printPGM(MSG_ERROR);
  2620. lcd.setCursor(0, 2);
  2621. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2622. delay(2000);
  2623. lcd_implementation_clear();
  2624. }
  2625. lcd_return_to_status();
  2626. }
  2627. //wrapper functions for loading filament
  2628. static void extr_adj_0(){
  2629. change_extr(0);
  2630. extr_adj(0);
  2631. }
  2632. static void extr_adj_1() {
  2633. change_extr(1);
  2634. extr_adj(1);
  2635. }
  2636. static void extr_adj_2() {
  2637. change_extr(2);
  2638. extr_adj(2);
  2639. }
  2640. static void extr_adj_3() {
  2641. change_extr(3);
  2642. extr_adj(3);
  2643. }
  2644. //wrapper functions for changing extruders
  2645. static void extr_change_0() {
  2646. change_extr(0);
  2647. lcd_return_to_status();
  2648. }
  2649. static void extr_change_1() {
  2650. change_extr(1);
  2651. lcd_return_to_status();
  2652. }
  2653. static void extr_change_2() {
  2654. change_extr(2);
  2655. lcd_return_to_status();
  2656. }
  2657. static void extr_change_3() {
  2658. change_extr(3);
  2659. lcd_return_to_status();
  2660. }
  2661. //wrapper functions for unloading filament
  2662. static void extr_unload_all() {
  2663. if (degHotend0() > EXTRUDE_MINTEMP) {
  2664. for (int i = 0; i < 4; i++) {
  2665. change_extr(i);
  2666. extr_unload();
  2667. }
  2668. }
  2669. else {
  2670. lcd_implementation_clear();
  2671. lcd.setCursor(0, 0);
  2672. lcd_printPGM(MSG_ERROR);
  2673. lcd.setCursor(0, 2);
  2674. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2675. delay(2000);
  2676. lcd_implementation_clear();
  2677. lcd_return_to_status();
  2678. }
  2679. }
  2680. static void extr_unload_0() {
  2681. change_extr(0);
  2682. extr_unload();
  2683. }
  2684. static void extr_unload_1() {
  2685. change_extr(1);
  2686. extr_unload();
  2687. }
  2688. static void extr_unload_2() {
  2689. change_extr(2);
  2690. extr_unload();
  2691. }
  2692. static void extr_unload_3() {
  2693. change_extr(3);
  2694. extr_unload();
  2695. }
  2696. static void fil_load_menu()
  2697. {
  2698. START_MENU();
  2699. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2700. MENU_ITEM(function, MSG_LOAD_FILAMENT_1, extr_adj_0);
  2701. MENU_ITEM(function, MSG_LOAD_FILAMENT_2, extr_adj_1);
  2702. MENU_ITEM(function, MSG_LOAD_FILAMENT_3, extr_adj_2);
  2703. MENU_ITEM(function, MSG_LOAD_FILAMENT_4, extr_adj_3);
  2704. END_MENU();
  2705. }
  2706. static void fil_unload_menu()
  2707. {
  2708. START_MENU();
  2709. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2710. MENU_ITEM(function, MSG_UNLOAD_ALL, extr_unload_all);
  2711. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_1, extr_unload_0);
  2712. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_2, extr_unload_1);
  2713. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_3, extr_unload_2);
  2714. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_4, extr_unload_3);
  2715. END_MENU();
  2716. }
  2717. /*static void change_extr_menu(){
  2718. START_MENU();
  2719. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2720. MENU_ITEM(function, PSTR("Extruder 1"), extr_change_0);
  2721. MENU_ITEM(function, PSTR("Extruder 2"), extr_change_1);
  2722. MENU_ITEM(function, PSTR("Extruder 3"), extr_change_2);
  2723. MENU_ITEM(function, PSTR("Extruder 4"), extr_change_3);
  2724. END_MENU();
  2725. }*/
  2726. #endif
  2727. static void lcd_farm_no()
  2728. {
  2729. char step = 0;
  2730. int enc_dif = 0;
  2731. int _farmno = farm_no;
  2732. int _ret = 0;
  2733. lcd_implementation_clear();
  2734. lcd.setCursor(0, 0);
  2735. lcd.print("Farm no");
  2736. do
  2737. {
  2738. if (abs((enc_dif - encoderDiff)) > 2) {
  2739. if (enc_dif > encoderDiff) {
  2740. switch (step) {
  2741. case(0): if (_farmno >= 100) _farmno -= 100; break;
  2742. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  2743. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  2744. default: break;
  2745. }
  2746. }
  2747. if (enc_dif < encoderDiff) {
  2748. switch (step) {
  2749. case(0): if (_farmno < 900) _farmno += 100; break;
  2750. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  2751. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  2752. default: break;
  2753. }
  2754. }
  2755. enc_dif = 0;
  2756. encoderDiff = 0;
  2757. }
  2758. lcd.setCursor(0, 2);
  2759. if (_farmno < 100) lcd.print("0");
  2760. if (_farmno < 10) lcd.print("0");
  2761. lcd.print(_farmno);
  2762. lcd.print(" ");
  2763. lcd.setCursor(0, 3);
  2764. lcd.print(" ");
  2765. lcd.setCursor(step, 3);
  2766. lcd.print("^");
  2767. delay(100);
  2768. if (lcd_clicked())
  2769. {
  2770. delay(200);
  2771. step++;
  2772. if(step == 3) {
  2773. _ret = 1;
  2774. farm_no = _farmno;
  2775. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  2776. prusa_statistics(20);
  2777. lcd_return_to_status();
  2778. }
  2779. }
  2780. manage_heater();
  2781. } while (_ret == 0);
  2782. }
  2783. void lcd_confirm_print()
  2784. {
  2785. int enc_dif = 0;
  2786. int cursor_pos = 1;
  2787. int _ret = 0;
  2788. int _t = 0;
  2789. lcd_implementation_clear();
  2790. lcd.setCursor(0, 0);
  2791. lcd.print("Print ok ?");
  2792. do
  2793. {
  2794. if (abs((enc_dif - encoderDiff)) > 2) {
  2795. if (enc_dif > encoderDiff) {
  2796. cursor_pos--;
  2797. }
  2798. if (enc_dif < encoderDiff) {
  2799. cursor_pos++;
  2800. }
  2801. }
  2802. if (cursor_pos > 2) { cursor_pos = 2; }
  2803. if (cursor_pos < 1) { cursor_pos = 1; }
  2804. lcd.setCursor(0, 2); lcd.print(" ");
  2805. lcd.setCursor(0, 3); lcd.print(" ");
  2806. lcd.setCursor(2, 2);
  2807. lcd_printPGM(MSG_YES);
  2808. lcd.setCursor(2, 3);
  2809. lcd_printPGM(MSG_NO);
  2810. lcd.setCursor(0, 1 + cursor_pos);
  2811. lcd.print(">");
  2812. delay(100);
  2813. _t = _t + 1;
  2814. if (_t>100)
  2815. {
  2816. prusa_statistics(99);
  2817. _t = 0;
  2818. }
  2819. if (lcd_clicked())
  2820. {
  2821. if (cursor_pos == 1)
  2822. {
  2823. _ret = 1;
  2824. prusa_statistics(20);
  2825. prusa_statistics(4);
  2826. }
  2827. if (cursor_pos == 2)
  2828. {
  2829. _ret = 2;
  2830. prusa_statistics(20);
  2831. prusa_statistics(5);
  2832. }
  2833. }
  2834. manage_heater();
  2835. manage_inactivity();
  2836. } while (_ret == 0);
  2837. }
  2838. static void lcd_main_menu()
  2839. {
  2840. SDscrool = 0;
  2841. START_MENU();
  2842. // Majkl superawesome menu
  2843. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  2844. /* if (farm_mode && !IS_SD_PRINTING )
  2845. {
  2846. int tempScrool = 0;
  2847. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  2848. //delay(100);
  2849. return; // nothing to do (so don't thrash the SD card)
  2850. uint16_t fileCnt = card.getnrfilenames();
  2851. card.getWorkDirName();
  2852. if (card.filename[0] == '/')
  2853. {
  2854. #if SDCARDDETECT == -1
  2855. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  2856. #endif
  2857. } else {
  2858. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  2859. }
  2860. for (uint16_t i = 0; i < fileCnt; i++)
  2861. {
  2862. if (_menuItemNr == _lineNr)
  2863. {
  2864. #ifndef SDCARD_RATHERRECENTFIRST
  2865. card.getfilename(i);
  2866. #else
  2867. card.getfilename(fileCnt - 1 - i);
  2868. #endif
  2869. if (card.filenameIsDir)
  2870. {
  2871. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2872. } else {
  2873. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2874. }
  2875. } else {
  2876. MENU_ITEM_DUMMY();
  2877. }
  2878. }
  2879. MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen);
  2880. }*/
  2881. if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  2882. {
  2883. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  2884. }
  2885. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing )
  2886. {
  2887. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  2888. } else
  2889. {
  2890. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  2891. }
  2892. #ifdef SDSUPPORT
  2893. if (card.cardOK)
  2894. {
  2895. if (card.isFileOpen())
  2896. {
  2897. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  2898. if (card.sdprinting)
  2899. {
  2900. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  2901. }
  2902. else
  2903. {
  2904. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  2905. }
  2906. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  2907. }
  2908. }
  2909. else
  2910. {
  2911. if (!is_usb_printing)
  2912. {
  2913. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  2914. /*else*/ MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  2915. }
  2916. #if SDCARDDETECT < 1
  2917. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  2918. #endif
  2919. }
  2920. } else
  2921. {
  2922. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  2923. #if SDCARDDETECT < 1
  2924. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  2925. #endif
  2926. }
  2927. #endif
  2928. if (IS_SD_PRINTING || is_usb_printing)
  2929. {
  2930. if (farm_mode)
  2931. {
  2932. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  2933. }
  2934. }
  2935. else
  2936. {
  2937. #ifndef SNMM
  2938. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  2939. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  2940. #endif
  2941. #ifdef SNMM
  2942. MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);
  2943. MENU_ITEM(submenu, MSG_UNLOAD_FILAMENT, fil_unload_menu);
  2944. //MENU_ITEM(submenu, MSG_CHANGE_EXTR, change_extr_menu);
  2945. #endif
  2946. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  2947. if(!isPrintPaused) MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  2948. }
  2949. if (!is_usb_printing)
  2950. {
  2951. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  2952. }
  2953. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  2954. END_MENU();
  2955. }
  2956. void stack_error() {
  2957. SET_OUTPUT(BEEPER);
  2958. WRITE(BEEPER, HIGH);
  2959. delay(1000);
  2960. WRITE(BEEPER, LOW);
  2961. lcd_display_message_fullscreen_P(MSG_STACK_ERROR);
  2962. //err_triggered = 1;
  2963. while (1) delay_keep_alive(1000);
  2964. }
  2965. #ifdef SDSUPPORT
  2966. static void lcd_autostart_sd()
  2967. {
  2968. card.lastnr = 0;
  2969. card.setroot();
  2970. card.checkautostart(true);
  2971. }
  2972. #endif
  2973. static void lcd_silent_mode_set_tune() {
  2974. SilentModeMenu = !SilentModeMenu;
  2975. eeprom_update_byte((unsigned char*)EEPROM_SILENT, SilentModeMenu);
  2976. digipot_init();
  2977. lcd_goto_menu(lcd_tune_menu, 9);
  2978. }
  2979. static void lcd_tune_menu()
  2980. {
  2981. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  2982. START_MENU();
  2983. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  2984. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  2985. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  2986. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  2987. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  2988. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  2989. #ifdef FILAMENTCHANGEENABLE
  2990. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));//7
  2991. #endif
  2992. if (SilentModeMenu == 0) {
  2993. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  2994. } else {
  2995. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  2996. }
  2997. END_MENU();
  2998. }
  2999. static void lcd_move_menu_01mm()
  3000. {
  3001. move_menu_scale = 0.1;
  3002. lcd_move_menu_axis();
  3003. }
  3004. static void lcd_control_temperature_menu()
  3005. {
  3006. #ifdef PIDTEMP
  3007. // set up temp variables - undo the default scaling
  3008. // raw_Ki = unscalePID_i(Ki);
  3009. // raw_Kd = unscalePID_d(Kd);
  3010. #endif
  3011. START_MENU();
  3012. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  3013. #if TEMP_SENSOR_0 != 0
  3014. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  3015. #endif
  3016. #if TEMP_SENSOR_1 != 0
  3017. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  3018. #endif
  3019. #if TEMP_SENSOR_2 != 0
  3020. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  3021. #endif
  3022. #if TEMP_SENSOR_BED != 0
  3023. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  3024. #endif
  3025. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  3026. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  3027. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  3028. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  3029. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  3030. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  3031. #endif
  3032. END_MENU();
  3033. }
  3034. #if SDCARDDETECT == -1
  3035. static void lcd_sd_refresh()
  3036. {
  3037. card.initsd();
  3038. currentMenuViewOffset = 0;
  3039. }
  3040. #endif
  3041. static void lcd_sd_updir()
  3042. {
  3043. SDscrool = 0;
  3044. card.updir();
  3045. currentMenuViewOffset = 0;
  3046. }
  3047. void lcd_sdcard_stop()
  3048. {
  3049. lcd.setCursor(0, 0);
  3050. lcd_printPGM(MSG_STOP_PRINT);
  3051. lcd.setCursor(2, 2);
  3052. lcd_printPGM(MSG_NO);
  3053. lcd.setCursor(2, 3);
  3054. lcd_printPGM(MSG_YES);
  3055. lcd.setCursor(0, 2); lcd.print(" ");
  3056. lcd.setCursor(0, 3); lcd.print(" ");
  3057. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  3058. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  3059. lcd.setCursor(0, 1 + encoderPosition);
  3060. lcd.print(">");
  3061. if (lcd_clicked())
  3062. {
  3063. if ((int32_t)encoderPosition == 1)
  3064. {
  3065. lcd_return_to_status();
  3066. }
  3067. if ((int32_t)encoderPosition == 2)
  3068. {
  3069. cancel_heatup = true;
  3070. #ifdef MESH_BED_LEVELING
  3071. mbl.active = false;
  3072. #endif
  3073. // Stop the stoppers, update the position from the stoppers.
  3074. planner_abort_hard();
  3075. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  3076. // Z baystep is no more applied. Reset it.
  3077. babystep_reset();
  3078. // Clean the input command queue.
  3079. cmdqueue_reset();
  3080. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  3081. card.sdprinting = false;
  3082. card.closefile();
  3083. stoptime = millis();
  3084. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  3085. pause_time = 0;
  3086. save_statistics(total_filament_used, t);
  3087. lcd_return_to_status();
  3088. lcd_ignore_click(true);
  3089. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  3090. // Turn off the print fan
  3091. SET_OUTPUT(FAN_PIN);
  3092. WRITE(FAN_PIN, 0);
  3093. fanSpeed=0;
  3094. }
  3095. }
  3096. }
  3097. /*
  3098. void getFileDescription(char *name, char *description) {
  3099. // get file description, ie the REAL filenam, ie the second line
  3100. card.openFile(name, true);
  3101. int i = 0;
  3102. // skip the first line (which is the version line)
  3103. while (true) {
  3104. uint16_t readByte = card.get();
  3105. if (readByte == '\n') {
  3106. break;
  3107. }
  3108. }
  3109. // read the second line (which is the description line)
  3110. while (true) {
  3111. uint16_t readByte = card.get();
  3112. if (i == 0) {
  3113. // skip the first '^'
  3114. readByte = card.get();
  3115. }
  3116. description[i] = readByte;
  3117. i++;
  3118. if (readByte == '\n') {
  3119. break;
  3120. }
  3121. }
  3122. card.closefile();
  3123. description[i-1] = 0;
  3124. }
  3125. */
  3126. void lcd_sdcard_menu()
  3127. {
  3128. int tempScrool = 0;
  3129. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3130. //delay(100);
  3131. return; // nothing to do (so don't thrash the SD card)
  3132. uint16_t fileCnt = card.getnrfilenames();
  3133. START_MENU();
  3134. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3135. card.getWorkDirName();
  3136. if (card.filename[0] == '/')
  3137. {
  3138. #if SDCARDDETECT == -1
  3139. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3140. #endif
  3141. } else {
  3142. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3143. }
  3144. for (uint16_t i = 0; i < fileCnt; i++)
  3145. {
  3146. if (_menuItemNr == _lineNr)
  3147. {
  3148. #ifndef SDCARD_RATHERRECENTFIRST
  3149. card.getfilename(i);
  3150. #else
  3151. card.getfilename(fileCnt - 1 - i);
  3152. #endif
  3153. if (card.filenameIsDir)
  3154. {
  3155. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3156. } else {
  3157. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  3158. }
  3159. } else {
  3160. MENU_ITEM_DUMMY();
  3161. }
  3162. }
  3163. END_MENU();
  3164. }
  3165. //char description [10] [31];
  3166. /*void get_description() {
  3167. uint16_t fileCnt = card.getnrfilenames();
  3168. for (uint16_t i = 0; i < fileCnt; i++)
  3169. {
  3170. card.getfilename(fileCnt - 1 - i);
  3171. getFileDescription(card.filename, description[i]);
  3172. }
  3173. }*/
  3174. /*void lcd_farm_sdcard_menu()
  3175. {
  3176. static int i = 0;
  3177. if (i == 0) {
  3178. get_description();
  3179. i++;
  3180. }
  3181. //int j;
  3182. //char description[31];
  3183. int tempScrool = 0;
  3184. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3185. //delay(100);
  3186. return; // nothing to do (so don't thrash the SD card)
  3187. uint16_t fileCnt = card.getnrfilenames();
  3188. START_MENU();
  3189. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3190. card.getWorkDirName();
  3191. if (card.filename[0] == '/')
  3192. {
  3193. #if SDCARDDETECT == -1
  3194. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3195. #endif
  3196. }
  3197. else {
  3198. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3199. }
  3200. for (uint16_t i = 0; i < fileCnt; i++)
  3201. {
  3202. if (_menuItemNr == _lineNr)
  3203. {
  3204. #ifndef SDCARD_RATHERRECENTFIRST
  3205. card.getfilename(i);
  3206. #else
  3207. card.getfilename(fileCnt - 1 - i);
  3208. #endif
  3209. if (card.filenameIsDir)
  3210. {
  3211. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3212. }
  3213. else {
  3214. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, description[i]);
  3215. }
  3216. }
  3217. else {
  3218. MENU_ITEM_DUMMY();
  3219. }
  3220. }
  3221. END_MENU();
  3222. }*/
  3223. #define menu_edit_type(_type, _name, _strFunc, scale) \
  3224. void menu_edit_ ## _name () \
  3225. { \
  3226. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3227. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  3228. if (lcdDrawUpdate) \
  3229. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  3230. if (LCD_CLICKED) \
  3231. { \
  3232. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  3233. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  3234. } \
  3235. } \
  3236. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  3237. { \
  3238. menuData.editMenuParentState.prevMenu = currentMenu; \
  3239. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  3240. \
  3241. lcdDrawUpdate = 2; \
  3242. menuData.editMenuParentState.editLabel = pstr; \
  3243. menuData.editMenuParentState.editValue = ptr; \
  3244. menuData.editMenuParentState.minEditValue = minValue * scale; \
  3245. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  3246. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  3247. \
  3248. }\
  3249. /*
  3250. void menu_edit_callback_ ## _name () { \
  3251. menu_edit_ ## _name (); \
  3252. if (LCD_CLICKED) (*callbackFunc)(); \
  3253. } \
  3254. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  3255. { \
  3256. menuData.editMenuParentState.prevMenu = currentMenu; \
  3257. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  3258. \
  3259. lcdDrawUpdate = 2; \
  3260. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  3261. \
  3262. menuData.editMenuParentState.editLabel = pstr; \
  3263. menuData.editMenuParentState.editValue = ptr; \
  3264. menuData.editMenuParentState.minEditValue = minValue * scale; \
  3265. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  3266. callbackFunc = callback;\
  3267. }
  3268. */
  3269. menu_edit_type(int, int3, itostr3, 1)
  3270. menu_edit_type(float, float3, ftostr3, 1)
  3271. menu_edit_type(float, float32, ftostr32, 100)
  3272. menu_edit_type(float, float43, ftostr43, 1000)
  3273. menu_edit_type(float, float5, ftostr5, 0.01)
  3274. menu_edit_type(float, float51, ftostr51, 10)
  3275. menu_edit_type(float, float52, ftostr52, 100)
  3276. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  3277. static void lcd_selftest()
  3278. {
  3279. int _progress = 0;
  3280. bool _result = false;
  3281. lcd_implementation_clear();
  3282. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_START);
  3283. delay(2000);
  3284. _result = lcd_selftest_fan_dialog(1);
  3285. if (_result)
  3286. {
  3287. _result = lcd_selftest_fan_dialog(2);
  3288. }
  3289. if (_result)
  3290. {
  3291. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  3292. _result = lcd_selfcheck_endstops();
  3293. }
  3294. if (_result)
  3295. {
  3296. _progress = lcd_selftest_screen(1, _progress, 3, true, 1000);
  3297. _result = lcd_selfcheck_check_heater(false);
  3298. }
  3299. if (_result)
  3300. {
  3301. current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed
  3302. _progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  3303. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  3304. }
  3305. if (_result)
  3306. {
  3307. _progress = lcd_selftest_screen(2, _progress, 3, true, 0);
  3308. _result = lcd_selfcheck_pulleys(X_AXIS);
  3309. }
  3310. if (_result)
  3311. {
  3312. _progress = lcd_selftest_screen(3, _progress, 3, true, 1500);
  3313. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  3314. }
  3315. if (_result)
  3316. {
  3317. _progress = lcd_selftest_screen(3, _progress, 3, true, 0);
  3318. _result = lcd_selfcheck_pulleys(Y_AXIS);
  3319. }
  3320. if (_result)
  3321. {
  3322. current_position[X_AXIS] = current_position[X_AXIS] - 3;
  3323. current_position[Y_AXIS] = current_position[Y_AXIS] - 14;
  3324. _progress = lcd_selftest_screen(4, _progress, 3, true, 1500);
  3325. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  3326. enquecommand_P(PSTR("G28 W"));
  3327. enquecommand_P(PSTR("G1 Z15"));
  3328. }
  3329. if (_result)
  3330. {
  3331. _progress = lcd_selftest_screen(5, _progress, 3, true, 2000);
  3332. _result = lcd_selfcheck_check_heater(true);
  3333. }
  3334. if (_result)
  3335. {
  3336. _progress = lcd_selftest_screen(6, _progress, 3, true, 5000);
  3337. }
  3338. else
  3339. {
  3340. _progress = lcd_selftest_screen(7, _progress, 3, true, 5000);
  3341. }
  3342. lcd_reset_alert_level();
  3343. enquecommand_P(PSTR("M84"));
  3344. lcd_implementation_clear();
  3345. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  3346. if (_result)
  3347. {
  3348. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  3349. }
  3350. else
  3351. {
  3352. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  3353. }
  3354. }
  3355. static bool lcd_selfcheck_axis(int _axis, int _travel)
  3356. {
  3357. bool _stepdone = false;
  3358. bool _stepresult = false;
  3359. int _progress = 0;
  3360. int _travel_done = 0;
  3361. int _err_endstop = 0;
  3362. int _lcd_refresh = 0;
  3363. _travel = _travel + (_travel / 10);
  3364. do {
  3365. current_position[_axis] = current_position[_axis] - 1;
  3366. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3367. st_synchronize();
  3368. 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)
  3369. {
  3370. if (_axis == 0)
  3371. {
  3372. _stepresult = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3373. _err_endstop = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? 1 : 2;
  3374. }
  3375. if (_axis == 1)
  3376. {
  3377. _stepresult = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3378. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 2;
  3379. }
  3380. if (_axis == 2)
  3381. {
  3382. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3383. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 1;
  3384. /*disable_x();
  3385. disable_y();
  3386. disable_z();*/
  3387. }
  3388. _stepdone = true;
  3389. }
  3390. if (_lcd_refresh < 6)
  3391. {
  3392. _lcd_refresh++;
  3393. }
  3394. else
  3395. {
  3396. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  3397. _lcd_refresh = 0;
  3398. }
  3399. manage_heater();
  3400. manage_inactivity(true);
  3401. //delay(100);
  3402. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  3403. } while (!_stepdone);
  3404. //current_position[_axis] = current_position[_axis] + 15;
  3405. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3406. if (!_stepresult)
  3407. {
  3408. const char *_error_1;
  3409. const char *_error_2;
  3410. if (_axis == X_AXIS) _error_1 = "X";
  3411. if (_axis == Y_AXIS) _error_1 = "Y";
  3412. if (_axis == Z_AXIS) _error_1 = "Z";
  3413. if (_err_endstop == 0) _error_2 = "X";
  3414. if (_err_endstop == 1) _error_2 = "Y";
  3415. if (_err_endstop == 2) _error_2 = "Z";
  3416. if (_travel_done >= _travel)
  3417. {
  3418. lcd_selftest_error(5, _error_1, _error_2);
  3419. }
  3420. else
  3421. {
  3422. lcd_selftest_error(4, _error_1, _error_2);
  3423. }
  3424. }
  3425. return _stepresult;
  3426. }
  3427. static bool lcd_selfcheck_pulleys(int axis)
  3428. {
  3429. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  3430. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  3431. float current_position_init;
  3432. float move;
  3433. bool endstop_triggered = false;
  3434. bool result = true;
  3435. int i;
  3436. unsigned long timeout_counter;
  3437. refresh_cmd_timeout();
  3438. manage_inactivity(true);
  3439. if (axis == 0) move = 50; //X_AXIS
  3440. else move = 50; //Y_AXIS
  3441. current_position_init = current_position[axis];
  3442. current_position[axis] += 2;
  3443. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3444. for (i = 0; i < 5; i++) {
  3445. refresh_cmd_timeout();
  3446. current_position[axis] = current_position[axis] + move;
  3447. digipot_current(0, 850); //set motor current higher
  3448. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  3449. st_synchronize();
  3450. if (SilentModeMenu == 1) digipot_current(0, tmp_motor[0]); //set back to normal operation currents
  3451. else digipot_current(0, tmp_motor_loud[0]); //set motor current back
  3452. current_position[axis] = current_position[axis] - move;
  3453. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  3454. st_synchronize();
  3455. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3456. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3457. return(false);
  3458. }
  3459. }
  3460. timeout_counter = millis() + 2500;
  3461. endstop_triggered = false;
  3462. manage_inactivity(true);
  3463. while (!endstop_triggered) {
  3464. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3465. endstop_triggered = true;
  3466. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  3467. current_position[axis] += 15;
  3468. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3469. st_synchronize();
  3470. return(true);
  3471. }
  3472. else {
  3473. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3474. return(false);
  3475. }
  3476. }
  3477. else {
  3478. current_position[axis] -= 1;
  3479. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3480. st_synchronize();
  3481. if (millis() > timeout_counter) {
  3482. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3483. return(false);
  3484. }
  3485. }
  3486. }
  3487. }
  3488. static bool lcd_selfcheck_endstops()
  3489. {
  3490. bool _result = true;
  3491. 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)
  3492. {
  3493. current_position[0] = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? current_position[0] = current_position[0] + 10 : current_position[0];
  3494. current_position[1] = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? current_position[1] = current_position[1] + 10 : current_position[1];
  3495. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  3496. }
  3497. 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);
  3498. delay(500);
  3499. 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)
  3500. {
  3501. _result = false;
  3502. String _error = String((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? "X" : "") +
  3503. String((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? "Y" : "") +
  3504. String((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? "Z" : "");
  3505. lcd_selftest_error(3, _error.c_str(), "");
  3506. }
  3507. manage_heater();
  3508. manage_inactivity(true);
  3509. return _result;
  3510. }
  3511. static bool lcd_selfcheck_check_heater(bool _isbed)
  3512. {
  3513. int _counter = 0;
  3514. int _progress = 0;
  3515. bool _stepresult = false;
  3516. bool _docycle = true;
  3517. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  3518. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  3519. int _cycles = (_isbed) ? 120 : 30;
  3520. target_temperature[0] = (_isbed) ? 0 : 100;
  3521. target_temperature_bed = (_isbed) ? 100 : 0;
  3522. manage_heater();
  3523. manage_inactivity(true);
  3524. do {
  3525. _counter++;
  3526. _docycle = (_counter < _cycles) ? true : false;
  3527. manage_heater();
  3528. manage_inactivity(true);
  3529. _progress = (_isbed) ? lcd_selftest_screen(5, _progress, 2, false, 400) : lcd_selftest_screen(1, _progress, 2, false, 400);
  3530. } while (_docycle);
  3531. target_temperature[0] = 0;
  3532. target_temperature_bed = 0;
  3533. manage_heater();
  3534. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  3535. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  3536. if (_opposite_result < ((_isbed) ? 10 : 3))
  3537. {
  3538. if (_checked_result >= ((_isbed) ? 3 : 10))
  3539. {
  3540. _stepresult = true;
  3541. }
  3542. else
  3543. {
  3544. lcd_selftest_error(1, "", "");
  3545. }
  3546. }
  3547. else
  3548. {
  3549. lcd_selftest_error(2, "", "");
  3550. }
  3551. manage_heater();
  3552. manage_inactivity(true);
  3553. return _stepresult;
  3554. }
  3555. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  3556. {
  3557. lcd_implementation_quick_feedback();
  3558. target_temperature[0] = 0;
  3559. target_temperature_bed = 0;
  3560. manage_heater();
  3561. manage_inactivity();
  3562. lcd_implementation_clear();
  3563. lcd.setCursor(0, 0);
  3564. lcd_printPGM(MSG_SELFTEST_ERROR);
  3565. lcd.setCursor(0, 1);
  3566. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  3567. switch (_error_no)
  3568. {
  3569. case 1:
  3570. lcd.setCursor(0, 2);
  3571. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  3572. lcd.setCursor(0, 3);
  3573. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  3574. break;
  3575. case 2:
  3576. lcd.setCursor(0, 2);
  3577. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  3578. lcd.setCursor(0, 3);
  3579. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3580. break;
  3581. case 3:
  3582. lcd.setCursor(0, 2);
  3583. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  3584. lcd.setCursor(0, 3);
  3585. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3586. lcd.setCursor(17, 3);
  3587. lcd.print(_error_1);
  3588. break;
  3589. case 4:
  3590. lcd.setCursor(0, 2);
  3591. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3592. lcd.setCursor(18, 2);
  3593. lcd.print(_error_1);
  3594. lcd.setCursor(0, 3);
  3595. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  3596. lcd.setCursor(18, 3);
  3597. lcd.print(_error_2);
  3598. break;
  3599. case 5:
  3600. lcd.setCursor(0, 2);
  3601. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  3602. lcd.setCursor(0, 3);
  3603. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3604. lcd.setCursor(18, 3);
  3605. lcd.print(_error_1);
  3606. break;
  3607. case 6:
  3608. lcd.setCursor(0, 2);
  3609. lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  3610. lcd.setCursor(0, 3);
  3611. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3612. lcd.setCursor(18, 3);
  3613. lcd.print(_error_1);
  3614. break;
  3615. case 7:
  3616. lcd.setCursor(0, 2);
  3617. lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  3618. lcd.setCursor(0, 3);
  3619. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3620. lcd.setCursor(18, 3);
  3621. lcd.print(_error_1);
  3622. break;
  3623. case 8:
  3624. lcd.setCursor(0, 2);
  3625. lcd_printPGM(MSG_LOOSE_PULLEY);
  3626. lcd.setCursor(0, 3);
  3627. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3628. lcd.setCursor(18, 3);
  3629. lcd.print(_error_1);
  3630. break;
  3631. }
  3632. delay(1000);
  3633. lcd_implementation_quick_feedback();
  3634. do {
  3635. delay(100);
  3636. manage_heater();
  3637. manage_inactivity();
  3638. } while (!lcd_clicked());
  3639. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  3640. lcd_return_to_status();
  3641. }
  3642. static bool lcd_selftest_fan_dialog(int _fan)
  3643. {
  3644. bool _result = false;
  3645. int _errno = 0;
  3646. lcd_implementation_clear();
  3647. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_FAN);
  3648. switch (_fan)
  3649. {
  3650. case 1:
  3651. // extruder cooling fan
  3652. lcd.setCursor(0, 1); lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  3653. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  3654. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  3655. _errno = 7;
  3656. break;
  3657. case 2:
  3658. // object cooling fan
  3659. lcd.setCursor(0, 1); lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  3660. SET_OUTPUT(FAN_PIN);
  3661. analogWrite(FAN_PIN, 255);
  3662. _errno = 6;
  3663. break;
  3664. }
  3665. delay(500);
  3666. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  3667. lcd.setCursor(0, 3); lcd.print(">");
  3668. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  3669. int8_t enc_dif = 0;
  3670. do
  3671. {
  3672. switch (_fan)
  3673. {
  3674. case 1:
  3675. // extruder cooling fan
  3676. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  3677. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  3678. break;
  3679. case 2:
  3680. // object cooling fan
  3681. SET_OUTPUT(FAN_PIN);
  3682. analogWrite(FAN_PIN, 255);
  3683. break;
  3684. }
  3685. if (abs((enc_dif - encoderDiff)) > 2) {
  3686. if (enc_dif > encoderDiff) {
  3687. _result = true;
  3688. lcd.setCursor(0, 2); lcd.print(">");
  3689. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  3690. lcd.setCursor(0, 3); lcd.print(" ");
  3691. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  3692. }
  3693. if (enc_dif < encoderDiff) {
  3694. _result = false;
  3695. lcd.setCursor(0, 2); lcd.print(" ");
  3696. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  3697. lcd.setCursor(0, 3); lcd.print(">");
  3698. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  3699. }
  3700. enc_dif = 0;
  3701. encoderDiff = 0;
  3702. }
  3703. manage_heater();
  3704. delay(100);
  3705. } while (!lcd_clicked());
  3706. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  3707. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  3708. SET_OUTPUT(FAN_PIN);
  3709. analogWrite(FAN_PIN, 0);
  3710. fanSpeed = 0;
  3711. manage_heater();
  3712. if (!_result)
  3713. {
  3714. const char *_err;
  3715. lcd_selftest_error(_errno, _err, _err);
  3716. }
  3717. return _result;
  3718. }
  3719. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  3720. {
  3721. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  3722. int _step_block = 0;
  3723. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  3724. if (_clear) lcd_implementation_clear();
  3725. lcd.setCursor(0, 0);
  3726. if (_step == -1) lcd_printPGM(MSG_SELFTEST_START);
  3727. if (_step == 0) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  3728. if (_step == 1) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  3729. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  3730. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  3731. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  3732. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  3733. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  3734. if (_step == 7) lcd_printPGM(MSG_SELFTEST_FAILED);
  3735. lcd.setCursor(0, 1);
  3736. lcd.print("--------------------");
  3737. if (_step != 7)
  3738. {
  3739. _step_block = 1;
  3740. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  3741. _step_block = 2;
  3742. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  3743. _step_block = 3;
  3744. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  3745. _step_block = 4;
  3746. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  3747. _step_block = 5;
  3748. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  3749. }
  3750. if (_delay > 0) delay(_delay);
  3751. _progress++;
  3752. return (_progress > _progress_scale * 2) ? 0 : _progress;
  3753. }
  3754. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  3755. {
  3756. lcd.setCursor(_col, _row);
  3757. switch (_state)
  3758. {
  3759. case 1:
  3760. lcd.print(_name);
  3761. lcd.setCursor(_col + strlen(_name), _row);
  3762. lcd.print(":");
  3763. lcd.setCursor(_col + strlen(_name) + 1, _row);
  3764. lcd.print(_indicator);
  3765. break;
  3766. case 2:
  3767. lcd.print(_name);
  3768. lcd.setCursor(_col + strlen(_name), _row);
  3769. lcd.print(":");
  3770. lcd.setCursor(_col + strlen(_name) + 1, _row);
  3771. lcd.print("OK");
  3772. break;
  3773. default:
  3774. lcd.print(_name);
  3775. }
  3776. }
  3777. /** End of menus **/
  3778. static void lcd_quick_feedback()
  3779. {
  3780. lcdDrawUpdate = 2;
  3781. button_pressed = false;
  3782. lcd_implementation_quick_feedback();
  3783. }
  3784. /** Menu action functions **/
  3785. static void menu_action_back(menuFunc_t data) {
  3786. lcd_goto_menu(data);
  3787. }
  3788. static void menu_action_submenu(menuFunc_t data) {
  3789. lcd_goto_menu(data);
  3790. }
  3791. static void menu_action_gcode(const char* pgcode) {
  3792. enquecommand_P(pgcode);
  3793. }
  3794. static void menu_action_setlang(unsigned char lang) {
  3795. lcd_set_lang(lang);
  3796. }
  3797. static void menu_action_function(menuFunc_t data) {
  3798. (*data)();
  3799. }
  3800. static void menu_action_sdfile(const char* filename, char* longFilename)
  3801. {
  3802. loading_flag = false;
  3803. char cmd[30];
  3804. char* c;
  3805. sprintf_P(cmd, PSTR("M23 %s"), filename);
  3806. for (c = &cmd[4]; *c; c++)
  3807. *c = tolower(*c);
  3808. enquecommand(cmd);
  3809. enquecommand_P(PSTR("M24"));
  3810. lcd_return_to_status();
  3811. }
  3812. static void menu_action_sddirectory(const char* filename, char* longFilename)
  3813. {
  3814. card.chdir(filename);
  3815. encoderPosition = 0;
  3816. }
  3817. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  3818. {
  3819. *ptr = !(*ptr);
  3820. }
  3821. /*
  3822. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  3823. {
  3824. menu_action_setting_edit_bool(pstr, ptr);
  3825. (*callback)();
  3826. }
  3827. */
  3828. #endif//ULTIPANEL
  3829. /** LCD API **/
  3830. void lcd_init()
  3831. {
  3832. lcd_implementation_init();
  3833. #ifdef NEWPANEL
  3834. SET_INPUT(BTN_EN1);
  3835. SET_INPUT(BTN_EN2);
  3836. WRITE(BTN_EN1, HIGH);
  3837. WRITE(BTN_EN2, HIGH);
  3838. #if BTN_ENC > 0
  3839. SET_INPUT(BTN_ENC);
  3840. WRITE(BTN_ENC, HIGH);
  3841. #endif
  3842. #ifdef REPRAPWORLD_KEYPAD
  3843. pinMode(SHIFT_CLK, OUTPUT);
  3844. pinMode(SHIFT_LD, OUTPUT);
  3845. pinMode(SHIFT_OUT, INPUT);
  3846. WRITE(SHIFT_OUT, HIGH);
  3847. WRITE(SHIFT_LD, HIGH);
  3848. #endif
  3849. #else // Not NEWPANEL
  3850. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  3851. pinMode (SR_DATA_PIN, OUTPUT);
  3852. pinMode (SR_CLK_PIN, OUTPUT);
  3853. #elif defined(SHIFT_CLK)
  3854. pinMode(SHIFT_CLK, OUTPUT);
  3855. pinMode(SHIFT_LD, OUTPUT);
  3856. pinMode(SHIFT_EN, OUTPUT);
  3857. pinMode(SHIFT_OUT, INPUT);
  3858. WRITE(SHIFT_OUT, HIGH);
  3859. WRITE(SHIFT_LD, HIGH);
  3860. WRITE(SHIFT_EN, LOW);
  3861. #else
  3862. #ifdef ULTIPANEL
  3863. #error ULTIPANEL requires an encoder
  3864. #endif
  3865. #endif // SR_LCD_2W_NL
  3866. #endif//!NEWPANEL
  3867. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  3868. pinMode(SDCARDDETECT, INPUT);
  3869. WRITE(SDCARDDETECT, HIGH);
  3870. lcd_oldcardstatus = IS_SD_INSERTED;
  3871. #endif//(SDCARDDETECT > 0)
  3872. #ifdef LCD_HAS_SLOW_BUTTONS
  3873. slow_buttons = 0;
  3874. #endif
  3875. lcd_buttons_update();
  3876. #ifdef ULTIPANEL
  3877. encoderDiff = 0;
  3878. #endif
  3879. }
  3880. //#include <avr/pgmspace.h>
  3881. static volatile bool lcd_update_enabled = true;
  3882. unsigned long lcd_timeoutToStatus = 0;
  3883. void lcd_update_enable(bool enabled)
  3884. {
  3885. if (lcd_update_enabled != enabled) {
  3886. lcd_update_enabled = enabled;
  3887. if (enabled) {
  3888. // Reset encoder position. This is equivalent to re-entering a menu.
  3889. encoderPosition = 0;
  3890. encoderDiff = 0;
  3891. // Enabling the normal LCD update procedure.
  3892. // Reset the timeout interval.
  3893. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3894. // Force the keypad update now.
  3895. lcd_next_update_millis = millis() - 1;
  3896. // Full update.
  3897. lcd_implementation_clear();
  3898. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  3899. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  3900. #else
  3901. if (currentMenu == lcd_status_screen)
  3902. lcd_set_custom_characters_degree();
  3903. else
  3904. lcd_set_custom_characters_arrows();
  3905. #endif
  3906. lcd_update(2);
  3907. } else {
  3908. // Clear the LCD always, or let it to the caller?
  3909. }
  3910. }
  3911. }
  3912. void lcd_update(uint8_t lcdDrawUpdateOverride)
  3913. {
  3914. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  3915. lcdDrawUpdate = lcdDrawUpdateOverride;
  3916. if (!lcd_update_enabled)
  3917. return;
  3918. #ifdef LCD_HAS_SLOW_BUTTONS
  3919. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3920. #endif
  3921. lcd_buttons_update();
  3922. #if (SDCARDDETECT > 0)
  3923. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  3924. {
  3925. lcdDrawUpdate = 2;
  3926. lcd_oldcardstatus = IS_SD_INSERTED;
  3927. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3928. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  3929. currentMenu == lcd_status_screen
  3930. #endif
  3931. );
  3932. if (lcd_oldcardstatus)
  3933. {
  3934. card.initsd();
  3935. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  3936. //get_description();
  3937. }
  3938. else
  3939. {
  3940. card.release();
  3941. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  3942. }
  3943. }
  3944. #endif//CARDINSERTED
  3945. if (lcd_next_update_millis < millis())
  3946. {
  3947. #ifdef ULTIPANEL
  3948. #ifdef REPRAPWORLD_KEYPAD
  3949. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  3950. reprapworld_keypad_move_z_up();
  3951. }
  3952. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  3953. reprapworld_keypad_move_z_down();
  3954. }
  3955. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  3956. reprapworld_keypad_move_x_left();
  3957. }
  3958. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  3959. reprapworld_keypad_move_x_right();
  3960. }
  3961. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  3962. reprapworld_keypad_move_y_down();
  3963. }
  3964. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  3965. reprapworld_keypad_move_y_up();
  3966. }
  3967. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  3968. reprapworld_keypad_move_home();
  3969. }
  3970. #endif
  3971. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  3972. {
  3973. if (lcdDrawUpdate == 0)
  3974. lcdDrawUpdate = 1;
  3975. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  3976. encoderDiff = 0;
  3977. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3978. }
  3979. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3980. #endif//ULTIPANEL
  3981. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  3982. blink++; // Variable for fan animation and alive dot
  3983. u8g.firstPage();
  3984. do
  3985. {
  3986. u8g.setFont(u8g_font_6x10_marlin);
  3987. u8g.setPrintPos(125, 0);
  3988. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  3989. u8g.drawPixel(127, 63); // draw alive dot
  3990. u8g.setColorIndex(1); // black on white
  3991. (*currentMenu)();
  3992. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  3993. } while (u8g.nextPage());
  3994. #else
  3995. (*currentMenu)();
  3996. #endif
  3997. #ifdef LCD_HAS_STATUS_INDICATORS
  3998. lcd_implementation_update_indicators();
  3999. #endif
  4000. #ifdef ULTIPANEL
  4001. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  4002. {
  4003. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  4004. // to give it a chance to save its state.
  4005. // This is useful for example, when the babystep value has to be written into EEPROM.
  4006. if (currentMenu != NULL) {
  4007. menuExiting = true;
  4008. (*currentMenu)();
  4009. menuExiting = false;
  4010. }
  4011. lcd_return_to_status();
  4012. lcdDrawUpdate = 2;
  4013. }
  4014. #endif//ULTIPANEL
  4015. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  4016. if (lcdDrawUpdate) lcdDrawUpdate--;
  4017. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  4018. }
  4019. if (!SdFatUtil::test_stack_integrity()) stack_error();
  4020. lcd_ping(); //check that we have received ping command if we are in farm mode
  4021. }
  4022. void lcd_printer_connected() {
  4023. printer_connected = true;
  4024. }
  4025. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  4026. if (farm_mode) {
  4027. bool empty = is_buffer_empty();
  4028. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  4029. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  4030. //therefore longer period is used
  4031. printer_connected = false;
  4032. //lcd_ping_allert(); //acustic signals
  4033. }
  4034. else {
  4035. lcd_printer_connected();
  4036. }
  4037. }
  4038. }
  4039. void lcd_ignore_click(bool b)
  4040. {
  4041. ignore_click = b;
  4042. wait_for_unclick = false;
  4043. }
  4044. void lcd_finishstatus() {
  4045. int len = strlen(lcd_status_message);
  4046. if (len > 0) {
  4047. while (len < LCD_WIDTH) {
  4048. lcd_status_message[len++] = ' ';
  4049. }
  4050. }
  4051. lcd_status_message[LCD_WIDTH] = '\0';
  4052. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  4053. #if PROGRESS_MSG_EXPIRE > 0
  4054. messageTick =
  4055. #endif
  4056. progressBarTick = millis();
  4057. #endif
  4058. lcdDrawUpdate = 2;
  4059. #ifdef FILAMENT_LCD_DISPLAY
  4060. message_millis = millis(); //get status message to show up for a while
  4061. #endif
  4062. }
  4063. void lcd_setstatus(const char* message)
  4064. {
  4065. if (lcd_status_message_level > 0)
  4066. return;
  4067. strncpy(lcd_status_message, message, LCD_WIDTH);
  4068. lcd_finishstatus();
  4069. }
  4070. void lcd_setstatuspgm(const char* message)
  4071. {
  4072. if (lcd_status_message_level > 0)
  4073. return;
  4074. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  4075. lcd_finishstatus();
  4076. }
  4077. void lcd_setalertstatuspgm(const char* message)
  4078. {
  4079. lcd_setstatuspgm(message);
  4080. lcd_status_message_level = 1;
  4081. #ifdef ULTIPANEL
  4082. lcd_return_to_status();
  4083. #endif//ULTIPANEL
  4084. }
  4085. void lcd_reset_alert_level()
  4086. {
  4087. lcd_status_message_level = 0;
  4088. }
  4089. #ifdef DOGLCD
  4090. void lcd_setcontrast(uint8_t value)
  4091. {
  4092. lcd_contrast = value & 63;
  4093. u8g.setContrast(lcd_contrast);
  4094. }
  4095. #endif
  4096. #ifdef ULTIPANEL
  4097. /* Warning: This function is called from interrupt context */
  4098. void lcd_buttons_update()
  4099. {
  4100. #ifdef NEWPANEL
  4101. uint8_t newbutton = 0;
  4102. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  4103. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  4104. #if BTN_ENC > 0
  4105. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  4106. if (READ(BTN_ENC) == 0) { //button is pressed
  4107. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4108. if (millis() > button_blanking_time) {
  4109. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  4110. if (button_pressed == false && long_press_active == false) {
  4111. if (currentMenu != lcd_move_z) {
  4112. savedMenu = currentMenu;
  4113. savedEncoderPosition = encoderPosition;
  4114. }
  4115. long_press_timer = millis();
  4116. button_pressed = true;
  4117. }
  4118. else {
  4119. if (millis() - long_press_timer > LONG_PRESS_TIME) { //long press activated
  4120. long_press_active = true;
  4121. move_menu_scale = 1.0;
  4122. lcd_goto_menu(lcd_move_z);
  4123. }
  4124. }
  4125. }
  4126. }
  4127. else { //button not pressed
  4128. if (button_pressed) { //button was released
  4129. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  4130. if (long_press_active == false) { //button released before long press gets activated
  4131. if (currentMenu == lcd_move_z) {
  4132. //return to previously active menu and previous encoder position
  4133. lcd_goto_menu(savedMenu, savedEncoderPosition);
  4134. }
  4135. else {
  4136. newbutton |= EN_C;
  4137. }
  4138. }
  4139. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  4140. //button_pressed is set back to false via lcd_quick_feedback function
  4141. }
  4142. else {
  4143. long_press_active = false;
  4144. }
  4145. }
  4146. }
  4147. else { //we are in modal mode
  4148. if (READ(BTN_ENC) == 0)
  4149. newbutton |= EN_C;
  4150. }
  4151. #endif
  4152. buttons = newbutton;
  4153. #ifdef LCD_HAS_SLOW_BUTTONS
  4154. buttons |= slow_buttons;
  4155. #endif
  4156. #ifdef REPRAPWORLD_KEYPAD
  4157. // for the reprapworld_keypad
  4158. uint8_t newbutton_reprapworld_keypad = 0;
  4159. WRITE(SHIFT_LD, LOW);
  4160. WRITE(SHIFT_LD, HIGH);
  4161. for (int8_t i = 0; i < 8; i++) {
  4162. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  4163. if (READ(SHIFT_OUT))
  4164. newbutton_reprapworld_keypad |= (1 << 7);
  4165. WRITE(SHIFT_CLK, HIGH);
  4166. WRITE(SHIFT_CLK, LOW);
  4167. }
  4168. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  4169. #endif
  4170. #else //read it from the shift register
  4171. uint8_t newbutton = 0;
  4172. WRITE(SHIFT_LD, LOW);
  4173. WRITE(SHIFT_LD, HIGH);
  4174. unsigned char tmp_buttons = 0;
  4175. for (int8_t i = 0; i < 8; i++)
  4176. {
  4177. newbutton = newbutton >> 1;
  4178. if (READ(SHIFT_OUT))
  4179. newbutton |= (1 << 7);
  4180. WRITE(SHIFT_CLK, HIGH);
  4181. WRITE(SHIFT_CLK, LOW);
  4182. }
  4183. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  4184. #endif//!NEWPANEL
  4185. //manage encoder rotation
  4186. uint8_t enc = 0;
  4187. if (buttons & EN_A) enc |= B01;
  4188. if (buttons & EN_B) enc |= B10;
  4189. if (enc != lastEncoderBits)
  4190. {
  4191. switch (enc)
  4192. {
  4193. case encrot0:
  4194. if (lastEncoderBits == encrot3)
  4195. encoderDiff++;
  4196. else if (lastEncoderBits == encrot1)
  4197. encoderDiff--;
  4198. break;
  4199. case encrot1:
  4200. if (lastEncoderBits == encrot0)
  4201. encoderDiff++;
  4202. else if (lastEncoderBits == encrot2)
  4203. encoderDiff--;
  4204. break;
  4205. case encrot2:
  4206. if (lastEncoderBits == encrot1)
  4207. encoderDiff++;
  4208. else if (lastEncoderBits == encrot3)
  4209. encoderDiff--;
  4210. break;
  4211. case encrot3:
  4212. if (lastEncoderBits == encrot2)
  4213. encoderDiff++;
  4214. else if (lastEncoderBits == encrot0)
  4215. encoderDiff--;
  4216. break;
  4217. }
  4218. }
  4219. lastEncoderBits = enc;
  4220. }
  4221. bool lcd_detected(void)
  4222. {
  4223. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  4224. return lcd.LcdDetected() == 1;
  4225. #else
  4226. return true;
  4227. #endif
  4228. }
  4229. void lcd_buzz(long duration, uint16_t freq)
  4230. {
  4231. #ifdef LCD_USE_I2C_BUZZER
  4232. lcd.buzz(duration, freq);
  4233. #endif
  4234. }
  4235. bool lcd_clicked()
  4236. {
  4237. bool clicked = LCD_CLICKED;
  4238. if(clicked) button_pressed = false;
  4239. return clicked;
  4240. }
  4241. #endif//ULTIPANEL
  4242. /********************************/
  4243. /** Float conversion utilities **/
  4244. /********************************/
  4245. // convert float to string with +123.4 format
  4246. char conv[8];
  4247. char *ftostr3(const float &x)
  4248. {
  4249. return itostr3((int)x);
  4250. }
  4251. char *itostr2(const uint8_t &x)
  4252. {
  4253. //sprintf(conv,"%5.1f",x);
  4254. int xx = x;
  4255. conv[0] = (xx / 10) % 10 + '0';
  4256. conv[1] = (xx) % 10 + '0';
  4257. conv[2] = 0;
  4258. return conv;
  4259. }
  4260. // Convert float to string with 123.4 format, dropping sign
  4261. char *ftostr31(const float &x)
  4262. {
  4263. int xx = x * 10;
  4264. conv[0] = (xx >= 0) ? '+' : '-';
  4265. xx = abs(xx);
  4266. conv[1] = (xx / 1000) % 10 + '0';
  4267. conv[2] = (xx / 100) % 10 + '0';
  4268. conv[3] = (xx / 10) % 10 + '0';
  4269. conv[4] = '.';
  4270. conv[5] = (xx) % 10 + '0';
  4271. conv[6] = 0;
  4272. return conv;
  4273. }
  4274. // Convert float to string with 123.4 format
  4275. char *ftostr31ns(const float &x)
  4276. {
  4277. int xx = x * 10;
  4278. //conv[0]=(xx>=0)?'+':'-';
  4279. xx = abs(xx);
  4280. conv[0] = (xx / 1000) % 10 + '0';
  4281. conv[1] = (xx / 100) % 10 + '0';
  4282. conv[2] = (xx / 10) % 10 + '0';
  4283. conv[3] = '.';
  4284. conv[4] = (xx) % 10 + '0';
  4285. conv[5] = 0;
  4286. return conv;
  4287. }
  4288. char *ftostr32(const float &x)
  4289. {
  4290. long xx = x * 100;
  4291. if (xx >= 0)
  4292. conv[0] = (xx / 10000) % 10 + '0';
  4293. else
  4294. conv[0] = '-';
  4295. xx = abs(xx);
  4296. conv[1] = (xx / 1000) % 10 + '0';
  4297. conv[2] = (xx / 100) % 10 + '0';
  4298. conv[3] = '.';
  4299. conv[4] = (xx / 10) % 10 + '0';
  4300. conv[5] = (xx) % 10 + '0';
  4301. conv[6] = 0;
  4302. return conv;
  4303. }
  4304. //// Convert float to rj string with 123.45 format
  4305. char *ftostr32ns(const float &x) {
  4306. long xx = abs(x);
  4307. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  4308. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4309. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  4310. conv[3] = '.';
  4311. conv[4] = (xx / 10) % 10 + '0';
  4312. conv[5] = xx % 10 + '0';
  4313. return conv;
  4314. }
  4315. // Convert float to string with 1.234 format
  4316. char *ftostr43(const float &x)
  4317. {
  4318. long xx = x * 1000;
  4319. if (xx >= 0)
  4320. conv[0] = (xx / 1000) % 10 + '0';
  4321. else
  4322. conv[0] = '-';
  4323. xx = abs(xx);
  4324. conv[1] = '.';
  4325. conv[2] = (xx / 100) % 10 + '0';
  4326. conv[3] = (xx / 10) % 10 + '0';
  4327. conv[4] = (xx) % 10 + '0';
  4328. conv[5] = 0;
  4329. return conv;
  4330. }
  4331. //Float to string with 1.23 format
  4332. char *ftostr12ns(const float &x)
  4333. {
  4334. long xx = x * 100;
  4335. xx = abs(xx);
  4336. conv[0] = (xx / 100) % 10 + '0';
  4337. conv[1] = '.';
  4338. conv[2] = (xx / 10) % 10 + '0';
  4339. conv[3] = (xx) % 10 + '0';
  4340. conv[4] = 0;
  4341. return conv;
  4342. }
  4343. //Float to string with 1.234 format
  4344. char *ftostr13ns(const float &x)
  4345. {
  4346. long xx = x * 1000;
  4347. if (xx >= 0)
  4348. conv[0] = ' ';
  4349. else
  4350. conv[0] = '-';
  4351. xx = abs(xx);
  4352. conv[1] = (xx / 1000) % 10 + '0';
  4353. conv[2] = '.';
  4354. conv[3] = (xx / 100) % 10 + '0';
  4355. conv[4] = (xx / 10) % 10 + '0';
  4356. conv[5] = (xx) % 10 + '0';
  4357. conv[6] = 0;
  4358. return conv;
  4359. }
  4360. // convert float to space-padded string with -_23.4_ format
  4361. char *ftostr32sp(const float &x) {
  4362. long xx = abs(x * 100);
  4363. uint8_t dig;
  4364. if (x < 0) { // negative val = -_0
  4365. conv[0] = '-';
  4366. dig = (xx / 1000) % 10;
  4367. conv[1] = dig ? '0' + dig : ' ';
  4368. }
  4369. else { // positive val = __0
  4370. dig = (xx / 10000) % 10;
  4371. if (dig) {
  4372. conv[0] = '0' + dig;
  4373. conv[1] = '0' + (xx / 1000) % 10;
  4374. }
  4375. else {
  4376. conv[0] = ' ';
  4377. dig = (xx / 1000) % 10;
  4378. conv[1] = dig ? '0' + dig : ' ';
  4379. }
  4380. }
  4381. conv[2] = '0' + (xx / 100) % 10; // lsd always
  4382. dig = xx % 10;
  4383. if (dig) { // 2 decimal places
  4384. conv[5] = '0' + dig;
  4385. conv[4] = '0' + (xx / 10) % 10;
  4386. conv[3] = '.';
  4387. }
  4388. else { // 1 or 0 decimal place
  4389. dig = (xx / 10) % 10;
  4390. if (dig) {
  4391. conv[4] = '0' + dig;
  4392. conv[3] = '.';
  4393. }
  4394. else {
  4395. conv[3] = conv[4] = ' ';
  4396. }
  4397. conv[5] = ' ';
  4398. }
  4399. conv[6] = '\0';
  4400. return conv;
  4401. }
  4402. char *itostr31(const int &xx)
  4403. {
  4404. conv[0] = (xx >= 0) ? '+' : '-';
  4405. conv[1] = (xx / 1000) % 10 + '0';
  4406. conv[2] = (xx / 100) % 10 + '0';
  4407. conv[3] = (xx / 10) % 10 + '0';
  4408. conv[4] = '.';
  4409. conv[5] = (xx) % 10 + '0';
  4410. conv[6] = 0;
  4411. return conv;
  4412. }
  4413. // Convert int to rj string with 123 or -12 format
  4414. char *itostr3(const int &x)
  4415. {
  4416. int xx = x;
  4417. if (xx < 0) {
  4418. conv[0] = '-';
  4419. xx = -xx;
  4420. } else if (xx >= 100)
  4421. conv[0] = (xx / 100) % 10 + '0';
  4422. else
  4423. conv[0] = ' ';
  4424. if (xx >= 10)
  4425. conv[1] = (xx / 10) % 10 + '0';
  4426. else
  4427. conv[1] = ' ';
  4428. conv[2] = (xx) % 10 + '0';
  4429. conv[3] = 0;
  4430. return conv;
  4431. }
  4432. // Convert int to lj string with 123 format
  4433. char *itostr3left(const int &xx)
  4434. {
  4435. if (xx >= 100)
  4436. {
  4437. conv[0] = (xx / 100) % 10 + '0';
  4438. conv[1] = (xx / 10) % 10 + '0';
  4439. conv[2] = (xx) % 10 + '0';
  4440. conv[3] = 0;
  4441. }
  4442. else if (xx >= 10)
  4443. {
  4444. conv[0] = (xx / 10) % 10 + '0';
  4445. conv[1] = (xx) % 10 + '0';
  4446. conv[2] = 0;
  4447. }
  4448. else
  4449. {
  4450. conv[0] = (xx) % 10 + '0';
  4451. conv[1] = 0;
  4452. }
  4453. return conv;
  4454. }
  4455. // Convert int to rj string with 1234 format
  4456. char *itostr4(const int &xx) {
  4457. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4458. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  4459. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  4460. conv[3] = xx % 10 + '0';
  4461. conv[4] = 0;
  4462. return conv;
  4463. }
  4464. // Convert float to rj string with 12345 format
  4465. char *ftostr5(const float &x) {
  4466. long xx = abs(x);
  4467. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  4468. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4469. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  4470. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  4471. conv[4] = xx % 10 + '0';
  4472. conv[5] = 0;
  4473. return conv;
  4474. }
  4475. // Convert float to string with +1234.5 format
  4476. char *ftostr51(const float &x)
  4477. {
  4478. long xx = x * 10;
  4479. conv[0] = (xx >= 0) ? '+' : '-';
  4480. xx = abs(xx);
  4481. conv[1] = (xx / 10000) % 10 + '0';
  4482. conv[2] = (xx / 1000) % 10 + '0';
  4483. conv[3] = (xx / 100) % 10 + '0';
  4484. conv[4] = (xx / 10) % 10 + '0';
  4485. conv[5] = '.';
  4486. conv[6] = (xx) % 10 + '0';
  4487. conv[7] = 0;
  4488. return conv;
  4489. }
  4490. // Convert float to string with +123.45 format
  4491. char *ftostr52(const float &x)
  4492. {
  4493. long xx = x * 100;
  4494. conv[0] = (xx >= 0) ? '+' : '-';
  4495. xx = abs(xx);
  4496. conv[1] = (xx / 10000) % 10 + '0';
  4497. conv[2] = (xx / 1000) % 10 + '0';
  4498. conv[3] = (xx / 100) % 10 + '0';
  4499. conv[4] = '.';
  4500. conv[5] = (xx / 10) % 10 + '0';
  4501. conv[6] = (xx) % 10 + '0';
  4502. conv[7] = 0;
  4503. return conv;
  4504. }
  4505. /*
  4506. // Callback for after editing PID i value
  4507. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  4508. void copy_and_scalePID_i()
  4509. {
  4510. #ifdef PIDTEMP
  4511. Ki = scalePID_i(raw_Ki);
  4512. updatePID();
  4513. #endif
  4514. }
  4515. // Callback for after editing PID d value
  4516. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  4517. void copy_and_scalePID_d()
  4518. {
  4519. #ifdef PIDTEMP
  4520. Kd = scalePID_d(raw_Kd);
  4521. updatePID();
  4522. #endif
  4523. }
  4524. */
  4525. #endif //ULTRA_LCD