ultralcd.cpp 149 KB

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