ultralcd.cpp 140 KB

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