Clearing my code: Accessing variables between cogs
jmspaggi
Posts: 629
Hi all,
In my main program, I have some variables declaration:
I have a cog which have to handle the SD card and will update/read those variables, so I call it that way:
On the cog side, here is the way I'm ready/updating those variables:
... No comments! I'm sure there is an easier and cleaner way to do that.. Because each time I have to update one of those variables, I have to copy this LONG statement
Is there another way to do what I'm doing here?
Thanks,
JM
In my main program, I have some variables declaration:
VAR long lfNumber ' How many files do we have in the current directory long lfBuffer [c#bufferedFilesName * c#maxLenghtFileName / 4] ' Buffer for file names to display long lfCurrent ' Which file, in the buffer, we are pointing at. long lfFirst ' Which file is the first in the buffer. IE, if lfFirst = 10, then buffer contain files from 12 to 12+bufferedFilesName long lfChangeDirectory ' $FFFF= Do nothing. $FFFE= One directory up. everything else: Move to the x directory in the current folder. long lfPlayFile ' $FFFF= Do nothing. else: Play the file x.
I have a cog which have to handle the SD card and will update/read those variables, so I call it that way:
sd.start (@lfNumber)
On the cog side, here is the way I'm ready/updating those variables:
if LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)] < c#bufferedFilesName LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)]++ '' lfCurrent++ else LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)+4]++ LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName+4+4+4)] := LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName+4)] + LONG[lf_number_addr+constant(4+c#bufferedFilesName*c#maxLenghtFileName)] - 1 ''lfPlayFile := lfFirst + lfCurrent - 1
... No comments! I'm sure there is an easier and cleaner way to do that.. Because each time I have to update one of those variables, I have to copy this LONG statement
Is there another way to do what I'm doing here?
Thanks,
JM
Comments
Alternatively, you could just pass @lfNumber and then compute the other addresses at the beginning of sd.start:
Then you could write something like this:
Btw, there's a typo in c#maxLenghtFileName.
CON
bFN = c#bufferedFilesName
mLFN = c#maxLengthFileName
plus = bFN + mLFN
I understand for the CON section. I can also rename maxLengthFileName mLFN directly in c. But I like verbose things
Regarding adding the variables lf_buffer_addr, lf_current_addr and lf_first_addr to the VAR section, that will add 4 bytes per variables And I would like to avoid that. Is there a way to reference it directly?
Since I have only one instance of this object, is there something like the "#" but for the variables and not only the constrantes?
Thanks,
JM