ThePenguinMaster
07-03-2009, 05:18 AM
Ok so there is a concept I’m trying to work out here, I’m not sure how to go about this but I want to use the fsrw object to get a listing of all of the files on an SD card. I can get the file names by using the fStore.nextfile function, but I am having trouble storing the value into an array. What I have so far:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
tvPin = 24
cardPin = 20
obj
term: "tv_text"
fStore: "fsrw"
var
byte tbuf
long fileList[20]
pub start | r, sta, bytes, i
term.start(tvPin)
' grab the file list up to 20 items for now
GetFileList
i:=0
repeat while not fileList == 0
term.str(fileList)
term.out($0D)
i++
pub GetFileList|i
fStore.mount(cardPin)
fStore.opendir
i:=0
repeat while 0 == fStore.nextfile(@tbuf)
LONG[ fileList ][ i ] := @tbuf
i++
When I run the code, I get no output. If I change “LONG[ fileList ][ i ] := @tbuf” to “fileList][ i ] := @tbuf” it will work but tbuf is rewritten every time. I made the array a set of longs although this is maybe no the right way to store a string. Tbuf is a pointer to the location that contains the file name, and I need to store that into an array and not the pointer value to the string. Is there a somewhat short way around this? Or do I need to modify the fsrw to buffer the file names and return an address to the buffer? I would much prefer to have fsrw remain unmodified and be able to take the string from the memory location it returns and store it into an array. Also, I do not know how many items may be in the array, basically, there are X amount of files. Any help would be appreciated. This is a simple core concept and I’m sure I could use the concept of storing strings into an array in a few applications. Any help would be appreciated.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
tvPin = 24
cardPin = 20
obj
term: "tv_text"
fStore: "fsrw"
var
byte tbuf
long fileList[20]
pub start | r, sta, bytes, i
term.start(tvPin)
' grab the file list up to 20 items for now
GetFileList
i:=0
repeat while not fileList == 0
term.str(fileList)
term.out($0D)
i++
pub GetFileList|i
fStore.mount(cardPin)
fStore.opendir
i:=0
repeat while 0 == fStore.nextfile(@tbuf)
LONG[ fileList ][ i ] := @tbuf
i++
When I run the code, I get no output. If I change “LONG[ fileList ][ i ] := @tbuf” to “fileList][ i ] := @tbuf” it will work but tbuf is rewritten every time. I made the array a set of longs although this is maybe no the right way to store a string. Tbuf is a pointer to the location that contains the file name, and I need to store that into an array and not the pointer value to the string. Is there a somewhat short way around this? Or do I need to modify the fsrw to buffer the file names and return an address to the buffer? I would much prefer to have fsrw remain unmodified and be able to take the string from the memory location it returns and store it into an array. Also, I do not know how many items may be in the array, basically, there are X amount of files. Any help would be appreciated. This is a simple core concept and I’m sure I could use the concept of storing strings into an array in a few applications. Any help would be appreciated.