ultralcd.cpp 140 KB

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