![]() |
Forum Index : Microcontroller and PC projects : Quick library question...
Author | Message | ||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
In another thread, Geoff writes: In my library, I do DIM a couple of things needed by the library. One is a wave-table for matherp's sound Cfunction, and the other is a variable to ID the version of the library currently installed: ![]() As this would seem to be perhaps a no-no, is there any better way to do it? As you can see, SW% is needed as this is the wave-table for matherp's Cfunction, and LibVer is a string that can be called and shown on the LCD to show the version of the library in use. This is all working just fine, but I am concerned with Geoff's comment from the other thread, so any suggestions would be good to have now, rather then later if this kind of thing is likely to cause obscure bugs later on. Smoke makes things work. When the smoke gets out, it stops! |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
I believe that the post that you referred to explained it fully. Don't define your variables in MM.STARTUP but instead as normal code in the library. I bet that you also have autorun turned on. That does not reset everything like RUN does because it assumes that the processor started in a clean state. So this explains why your program works OK. BUT, if you did start your program with the RUN command it would fall over. Geoff Geoff Graham - http://geoffg.net |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
Yes, your post did suggest that rather well, didn't it?!(rhetorical) ![]() I can move the wave-table to the main code no problems. The library ID needs to be saved as part of the library, and NOT in the main code, so that it can be referred to from the main code. If I put it in the main code, the library could be updated later, and the main code would keep saying the library was version 1, if you see what I am getting at. Is there a way to do something like that in the library that does comply with library specs? Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
In the library before the sub, DIM as STRING LibVer In the sub LibVer = "Version 9" As long as it's DIMed outside the sub, the main code will see it. Jim VK7JH MMedit |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2442 |
if i am not mistaken, is it not impossible to update the library without first erasing the main code? from the start i've always seen the library as having quite limited usefulness as: 1. a means of extending the code space beyond the available ram, 2. a place to put custom functions in a 'condensed' form, 3. somewhere to hide away power-on initialization that needs to be kept safe/hidden if the user drops to the command prompt (LCD and keyboard drivers that are part of the console functionality being the main examples), 4. a way to add language extenstions for classroom situations that survive 'NEW', though are still erased with 'LIBRARY DELETE' or 'LIBRARY SAVE'. whereas, folks do seem to be using the library as a means of partitioing their code simply for the sake of it with no real added utility. if you are writing an embedded application, unless you are running out of space, moving code into the library really doesn't seem to be worthwhile, and in fact just serves to introduce unnecessary complication and opportunity for bugs. just my opinion! cheers, rob :-) |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
@ Jim - thanks - will try that. ![]() @ Rob - You are correct. To save a new library, you have to erase the main code. In my case, I am using the library to hold several Cfunctions rather then having them take up considerably more memory if listed in the main code. The version number variable is the only exception, really. It's for precisely that reason, that I need to know what is in the library - my 'Version number' string. If you do a new main code, and it does not need any new Cfunctions in the library, no problems. If you do a new code that DOES need another Cfunction, I guess you could just plop it in the main code, but compressing it in the library is a much better idea. I too think that putting general commands etc in the library is of little use. I guess at the end of the day, I don't even need the library version number, as LIBRARY LIST shows all the Cfunctions or Csub's stored within, so - meh........ ![]() Perhaps a whole lotta nuthin', my wanting a library version variable. Smoke makes things work. When the smoke gets out, it stops! |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
One problem is that your program is in an image which I cannot edit to illustrate how it should be done. So, the below is an abbreviated version as I am a slow two finger typist. If you had this in the library: DIM AS STRING LibVer = "... etc ..."
SUB MM.PROMPT etc END SUB CFUNCTION etc etc etc The variable LibVar would be visible to your running program. I believe that the issue is that you tried PRINT LibVer at the command prompt and saw nothing. The reason is that the library code is only run before the main program but not at the prompt. One way out of that would be to define LivVer in both the library code and in MM.PROMPT. For example: SetVer
etc SUB MM.PROMPT SetVer etc END SUB SUB SetVer DIM AS STRING LibVer = "... etc ..." END SUB CFUNCTION etc etc etc BTW, I do agree with Rob that the library is best used for just compressing CFunctions, etc. It is good for some other things but you can get caught up in subtle issues that are normally hidden by MMBasic. Geoff Geoff Graham - http://geoffg.net |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |