ultralcd.cpp 153 KB

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