Skip to content

Commit

Permalink
Add openCwd(), fix library.properties for Particle
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed Jan 21, 2019
1 parent 19cdd8f commit 635d3fd
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 101 deletions.
2 changes: 1 addition & 1 deletion examples/AnalogBinLogger/AnalogBinLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ void logData() {
error("Can't truncate file");
}
}
if (!binFile.rename(sd.vwd(), binName)) {
if (!binFile.rename(binName)) {
error("Can't rename file");
}
Serial.print(F("File renamed: "));
Expand Down
9 changes: 7 additions & 2 deletions examples/DirectoryFunctions/DirectoryFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const uint8_t chipSelect = SS;
// File system object.
SdFat sd;

// Directory file.
SdFile root;

// Use for file creation in folders.
SdFile file;

Expand Down Expand Up @@ -52,8 +55,10 @@ void setup() {
}

int rootFileCount = 0;
sd.vwd()->rewind();
while (file.openNext(sd.vwd(), O_RDONLY)) {
if (!root.open("/")){
error("open root failed");
}
while (file.openNext(&root, O_RDONLY)) {
if (!file.isHidden()) {
rootFileCount++;
}
Expand Down
54 changes: 27 additions & 27 deletions examples/LowLatencyLogger/LowLatencyLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void binaryToCsv() {
Serial.println();
Serial.print(F("FreeStack: "));
Serial.println(FreeStack());

// Create a new csvFile.
strcpy(csvName, binName);
strcpy(&csvName[BASE_NAME_SIZE + 3], "csv");
Expand Down Expand Up @@ -245,7 +245,7 @@ void createBinFile() {
// max number of blocks to erase per erase call
const uint32_t ERASE_SIZE = 262144L;
uint32_t bgnBlock, endBlock;

// Delete old tmp file.
if (sd.exists(TMP_FILE_NAME)) {
Serial.println(F("Deleting tmp file " TMP_FILE_NAME));
Expand Down Expand Up @@ -349,19 +349,19 @@ void recordBinFile() {
const uint8_t QUEUE_DIM = BUFFER_BLOCK_COUNT + 1;
// Index of last queue location.
const uint8_t QUEUE_LAST = QUEUE_DIM - 1;

// Allocate extra buffer space.
block_t block[BUFFER_BLOCK_COUNT - 1];

block_t* curBlock = 0;

block_t* emptyStack[BUFFER_BLOCK_COUNT];
uint8_t emptyTop;
uint8_t minTop;

block_t* fullQueue[QUEUE_DIM];
uint8_t fullHead = 0;
uint8_t fullTail = 0;
uint8_t fullTail = 0;

// Use SdFat's internal buffer.
emptyStack[0] = (block_t*)sd.vol()->cacheClear();
Expand All @@ -374,7 +374,7 @@ void recordBinFile() {
}
emptyTop = BUFFER_BLOCK_COUNT;
minTop = BUFFER_BLOCK_COUNT;

// Start a multiple block write.
if (!sd.card()->writeStart(binFile.firstBlock())) {
error("writeStart failed");
Expand All @@ -383,7 +383,7 @@ void recordBinFile() {
Serial.println(FreeStack());
Serial.println(F("Logging - type any character to stop"));
bool closeFile = false;
uint32_t bn = 0;
uint32_t bn = 0;
uint32_t maxLatency = 0;
uint32_t overrun = 0;
uint32_t overrunTotal = 0;
Expand All @@ -393,7 +393,7 @@ void recordBinFile() {
logTime += LOG_INTERVAL_USEC;
if (Serial.available()) {
closeFile = true;
}
}
if (closeFile) {
if (curBlock != 0) {
// Put buffer in full queue.
Expand All @@ -412,7 +412,7 @@ void recordBinFile() {
overrun = 0;
}
if ((int32_t)(logTime - micros()) < 0) {
error("Rate too fast");
error("Rate too fast");
}
int32_t delta;
do {
Expand All @@ -423,24 +423,24 @@ void recordBinFile() {
overrunTotal++;
if (ERROR_LED_PIN >= 0) {
digitalWrite(ERROR_LED_PIN, HIGH);
}
}
#if ABORT_ON_OVERRUN
Serial.println(F("Overrun abort"));
break;
#endif // ABORT_ON_OVERRUN
#endif // ABORT_ON_OVERRUN
} else {
#if USE_SHARED_SPI
sd.card()->spiStop();
#endif // USE_SHARED_SPI
#endif // USE_SHARED_SPI
acquireData(&curBlock->data[curBlock->count++]);
#if USE_SHARED_SPI
sd.card()->spiStart();
#endif // USE_SHARED_SPI
#endif // USE_SHARED_SPI
if (curBlock->count == DATA_DIM) {
fullQueue[fullHead] = curBlock;
fullHead = fullHead < QUEUE_LAST ? fullHead + 1 : 0;
curBlock = 0;
}
}
}
}
if (fullHead == fullTail) {
Expand Down Expand Up @@ -506,7 +506,7 @@ void recoverTmpFile() {
if (binFile.read(&count, 2) != 2) error("read");
if (count == 0 || count > DATA_DIM) {
endBlock = midBlock - 1;
} else {
} else {
bgnBlock = midBlock;
}
}
Expand All @@ -529,7 +529,7 @@ void renameBinFile() {
binName[BASE_NAME_SIZE]++;
}
}
if (!binFile.rename(sd.vwd(), binName)) {
if (!binFile.rename(binName)) {
error("Can't rename file");
}
Serial.print(F("File renamed: "));
Expand Down Expand Up @@ -563,8 +563,8 @@ void setup(void) {
pinMode(ERROR_LED_PIN, OUTPUT);
}
Serial.begin(9600);
// Wait for USB Serial

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
}
Expand All @@ -578,10 +578,10 @@ void setup(void) {
// Allow userSetup access to SPI bus.
pinMode(SD_CS_PIN, OUTPUT);
digitalWrite(SD_CS_PIN, HIGH);

// Setup sensors.
userSetup();

// Initialize at the highest speed supported by the board that is
// not over 50 MHz. Try a lower speed if SPI errors occur.
if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50))) {
Expand Down Expand Up @@ -609,11 +609,11 @@ void loop(void) {
} while (Serial.available() && Serial.read() >= 0);
Serial.println();
Serial.println(F("type:"));
Serial.println(F("b - open existing bin file"));
Serial.println(F("b - open existing bin file"));
Serial.println(F("c - convert file to csv"));
Serial.println(F("d - dump data to Serial"));
Serial.println(F("e - overrun error details"));
Serial.println(F("l - list files"));
Serial.println(F("l - list files"));
Serial.println(F("r - record data"));
Serial.println(F("t - test without logging"));
while(!Serial.available()) {
Expand All @@ -623,7 +623,7 @@ void loop(void) {
Serial.println(F("LowLatencyLogger can not run with watchdog timer"));
SysCall::halt();
#endif

char c = tolower(Serial.read());

// Discard extra Serial data.
Expand All @@ -643,12 +643,12 @@ void loop(void) {
} else if (c == 'e') {
checkOverrun();
} else if (c == 'l') {
Serial.println(F("\nls:"));
sd.ls(&Serial, LS_SIZE);
Serial.println(F("\nls:"));
sd.ls(&Serial, LS_SIZE);
} else if (c == 'r') {
logData();
} else if (c == 't') {
testSensor();
testSensor();
} else {
Serial.println(F("Invalid entry"));
}
Expand Down
Loading

0 comments on commit 635d3fd

Please sign in to comment.