From d6869d1ec4bd24cd2c3eafa534f0849b25ec5607 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 28 Feb 2019 17:04:22 -0500 Subject: added basic code --- .../External_ListFiles/External_ListFiles.ino | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 arduino/libraries/FileSystem/examples/External_ListFiles/External_ListFiles.ino (limited to 'arduino/libraries/FileSystem/examples/External_ListFiles') diff --git a/arduino/libraries/FileSystem/examples/External_ListFiles/External_ListFiles.ino b/arduino/libraries/FileSystem/examples/External_ListFiles/External_ListFiles.ino new file mode 100755 index 0000000..76c5cda --- /dev/null +++ b/arduino/libraries/FileSystem/examples/External_ListFiles/External_ListFiles.ino @@ -0,0 +1,117 @@ +/********************************************************************* + This is an example for our nRF52 based Bluefruit LE modules + + Pick one up today in the adafruit shop! + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + MIT license, check LICENSE for more information + All text above, and the splash screen below must be included in + any redistribution +*********************************************************************/ + +#include +#include + +/* This example print out External Flash contents up to + * MAX_LEVEL level of directories (including root) + * WARNING: This example uses recursive call to print out directory tree + * be extra careful, high number of MAX_LEVEL can cause memory overflow + */ +#define MAX_LEVEL 2 + +// the setup function runs once when you press reset or power the board +void setup() +{ + Serial.begin(115200); + while ( !Serial ) delay(10); // for nrf52840 with native usb + + Serial.println("ExternalFS List Files Example"); + + // Initialize Internal File System + ExternalFS.begin(); + + // Print whole directory tree of root whose level is 0 + printTreeDir("/", 0); + + // Print prompt + Serial.println(); + Serial.println("Enter anything to print directory tree (again):"); +} + +// the loop function runs over and over again forever +void loop() +{ + if ( Serial.available() ) + { + delay(10); // delay for all input arrived + while( Serial.available() ) Serial.read(); + + printTreeDir("/", 0); + + // Print prompt + Serial.println(); + Serial.println("Enter anything to print directory tree (again):"); + } +} + +/**************************************************************************/ +/*! + @brief Print out whole directory tree of an folder + until the level reach MAX_LEVEL + + @note Recursive call +*/ +/**************************************************************************/ +void printTreeDir(const char* cwd, uint8_t level) +{ + // Open the input folder + File dir(cwd, FILE_READ, ExternalFS); + + // Print root + if (level == 0) Serial.println("root"); + + // File within folder + File item(ExternalFS); + + // Loop through the directory + while( (item = dir.openNextFile(FILE_READ)) ) + { + // Indentation according to dir level + for(int i=0; i 50 + Serial.print(' '); + + Serial.print( item.size() ); + Serial.println( " Bytes"); + } + + item.close(); + } + + dir.close(); +} -- cgit v1.2.3