ultralcd.cpp 155 KB

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