I am using the WavPlayer and I’m looking to open a directory called “count.” To do this I am modifying this line from the seed wavplayer example:
From this:
f_mount(&fsi.GetSDFileSystem(), "/", 1);
to this:
f_mount(&fsi.GetSDFileSystem(), "/count", 1);
I’ve tried a few other variants as well but none of them seem to open the sub directory but instead it keeps opening the root directory on the files system.
Any thoughts on how I can open a sub directory off of the root path?
IIRC, that path is used to specify logical drive path, not arbitrary directory on it. You should have a look at FATFS docs for explanation and examples for opening directories, reading files, etc.
I went into the libdaisy Makefile and added USE_FATFS = 1 just under the OPT flags after the sources. I ran the rebuild_all script, then went to my prject and bild it again, but no joy. I am still having issues with f_chdir not working.
@antisvin,
I will do two things today: 1) re sync the Daisy project and 2) just upload a basic sample that reproduces the problem.
I do understand the value of code, I wasn’t sure if this problem has come up for others in the past and, as such, I thought i’d check here.
The reason I have not posted all of my current system code right now simply is because the code isn’t ready to be fully posted for the world. Hopefully coming soon.
I’ll do the above two this morning (for me here) and post back if the sync fixed it or the code sample.
I went in and used Git Dektop to ensure my Daisy repro was in sync and yes, it was other than my local files.
Here is a very stripped-down version of my main CPP file:
#include "SEQ16_RevA.h"
#include "daisysp.h"
#include <string.h>
#include <stdio.h>
#include "daisy_seed.h"
#include "fatfs.h"
// Use the daisy namespace to prevent having to type
// daisy:: before all libdaisy functions
using namespace daisysp;
using namespace daisy;
// Declare a DaisySeed object called hardware
seq_16_rev_a hw;
// Setup audio descritption playback from SDCard
static SdmmcHandler sdcard;
static FatFSInterface fsi;
static WavPlayer sampler;
static FIL file;
static void AudioCallback(AudioHandle::InterleavingInputBuffer in,
AudioHandle::InterleavingOutputBuffer out,
size_t size)
{
for(size_t i = 0; i < size; i += 2)
{
out[i] = out[i + 1] = s162f(sampler.Stream()) * 0.5f;
}
}
int main(void)
{
// Configure and Initialize the Daisy Seed
// These are separate to allow reconfiguration of any of the internal
// components before initialization.
hw.Init(true);
// start up the SD Card
SdmmcHandler::Config sd_cfg;
sd_cfg.Defaults();
sdcard.Init(sd_cfg);
fsi.Init(FatFSInterface::Config::MEDIA_SD);
f_mount(&fsi.GetSDFileSystem(), "/", 1);
// f_open(&fsi, "/count", 1);
int fs_ok = f_chdir("/count");
// seupt the smapler
sampler.Init(fsi.GetSDPath());
sampler.SetLooping(true);
size_t curfile;
curfile = sampler.GetCurrentFile();
sampler.Open(curfile);
for(;;)
{
// make sure the audio is flowing from the file ssystem
sampler.Prepare();
}
}
Here is my makefile
# Project Name
TARGET = MIDILEDs
# Sources
CPP_SOURCES = OSCSqr.cpp \
MIDILEDs.cpp
# Includes FatFS source files within project.
USE_FATFS = 1
# set optimization so my code fits on the flash :)
OPT = -Os
# Library Locations
LIBDAISY_DIR = ../../libDaisy
DAISYSP_DIR = ../../DaisySP
# Core location, and generic Makefile.
SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core
include $(SYSTEM_FILES_DIR)/Makefile
# Library Locations
LIBDAISY_DIR = ../../libDaisy
DAISYSP_DIR = ../../DaisySP
Here is the error I get when compiling:
in function `main':
C:\Users\direc\Documents\GitHub\Daisy\DaisyExamples\ElectronDrift\Failure/MIDILEDs.cpp:52: undefined reference to `f_chdir'
Does that means that your problem was just that you need a function that wasn’t compiled by default or anything else? IIRC, f_chdir is one way to open the directories with FATFS, but you also have an option of using f_open and building exact paths with C strings instead.