wwatson
Well-known member
This one has me stumped.
Here is the code:
The ouput from the above code is:
This is good.
Now if I comment out the green line and un-comment the the first red line I get This:
This is wrong.
If I un-comment the second red line that is the delay I get this:
This is also correct but why would I need the delay
I have been hammering on this for almost a whole day. Any ideas what I am missing?
Here is the code:
Code:
#include "Arduino.h"
#define CNT_PARITIONS 24
// ----------------------------------------------------------------------------
// Find a device and return the logical drive index number for that device and
// the path spec with volume label stripped off of the path spec.
// param in: full path.
// param out: device index number. Path name stripped of volume label.
// ----------------------------------------------------------------------------
int getLogicalDeviceNumber(const char **path) {
const char *tempPath;
char tempChar, ldNumber[256];
const char *strPtr;
char pathChar;
int i = 0, volume = -1;
uint8_t cntDigits = 0;
tempPath = *path;
if (!tempPath) return volume; // Invalid path name?
// Check if using logical device number ("0:" etc...).
sprintf(ldNumber,"%s",*path);
// Look for a colon in the path spec. Terminate on end of string
// or if colon found.
do {
tempChar = ldNumber[cntDigits];
cntDigits++; // Inc digit count for atoi().
} while ((uint8_t)tempChar != '\0' && tempChar != ':');
if (tempChar == ':') { // Is this a volume number?
cntDigits--; // Backup to ':' position.
[COLOR="#00FF00"] ldNumber[cntDigits] = '/'; // Change ':' to '/'.[/COLOR]
i = atoi(ldNumber); // numeric value of number string.
if (i < CNT_PARITIONS) { // Don't overrun array.
volume = i; // Drive number
[COLOR="#FF0000"]// ldNumber[cntDigits] = '/'; // Change ':' to '/'.[/COLOR]
[COLOR="#FF0000"]// delay(1);[/COLOR]
*path = ldNumber+cntDigits; // Snip off the drive number.
}
return volume;
}
// Look for logical device name (/volume name/).
/*
if (*tempPath == '/') { // Look for first '/'
do {
strPtr = drvIdx[i].name; // Volume label.
tempPath = *path; // Path to search.
// Compare the volume label with path name.
do {
// Get a character to compare (with inc).
pathChar = *strPtr++; tempChar = *(++tempPath);
if (ifLower(pathChar)) pathChar -= 0x20; // Make upper case.
if (ifLower(tempChar)) tempChar -= 0x20; // Ditto.
} while (pathChar && (char)pathChar == tempChar);
// Repeat for each label until there is a pattern match.
} while ((pathChar || (tempChar != '/')) && ++i <= CNT_PARITIONS);
// If a volume label is found, get the drive number and strip label from path.
if (i <= CNT_PARITIONS) {
volume = i; // Volume number.
*path = tempPath; // Strip off the logical drive name (leave last '/').
return volume;
}
}
if(*tempPath == '/')
return volume; // Return error (-1).
return currDrv;
*/
return volume;
}
// Change '32GSDFAT32' to a volume name of your drives.
//const char *device = "/TEENSY8GSD/test1.txt";
const char *device = "16:test1.txt";
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial);
int ldn = getLogicalDeviceNumber(&device);
Serial.printf("ldn = %d, device = %s\n",ldn, device);
}
void loop() {
}
The ouput from the above code is:
Code:
ldn = 16, device = [COLOR="#00FF00"]/[/COLOR]test1.txt
Now if I comment out the green line and un-comment the the first red line I get This:
Code:
ldn = 16, device = [COLOR="#FF0000"]:[/COLOR]test1.txt
If I un-comment the second red line that is the delay I get this:
Code:
ldn = 16, device = [COLOR="#00FF00"]/[/COLOR]test1.txt
I have been hammering on this for almost a whole day. Any ideas what I am missing?
Last edited: