ultralcd.cpp 153 KB

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