Skip to content

Commit 9f2b611

Browse files
implemented static bool for logging
1 parent 722bf6e commit 9f2b611

File tree

10 files changed

+18
-10
lines changed

10 files changed

+18
-10
lines changed

examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
2828
*/
2929

30-
3130
#include "Arduino_UnifiedStorage.h"
3231

32+
33+
3334
// Redirect Serial.print*() output to GDB instead of SerialUSB where it would conflict with ThreadDebug.
3435
// NOTE: Calls to Serial.print*() will block waiting for GDB to be connected so only useful to use this redefine
3536
// when actively debugging the program.
3637

3738

38-
3939
void printFolderContents(Folder dir, int indentation = 0) {
4040
std::vector<Folder> directories = dir.getFolders();
4141
std::vector<UFile> files = dir.getFiles();
@@ -66,8 +66,10 @@ void printFolderContents(Folder dir, int indentation = 0) {
6666
//USBStorage unifiedStorage = USBStorage() // Create an instance for interacting with USB storage
6767
InternalStorage internalStorage = InternalStorage();
6868

69+
6970
void setup() {
7071

72+
Arduino_UnifiedStorage::loggingEnabled = true;
7173

7274
Serial.begin(115200);
7375
while (!Serial);

src/Arduino_UnifiedStorage.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
#include "Arduino.h"
66
#include "Arduino_POSIXStorage.h"
77
#include "Boards.h"
8+
89
#include "Utils.h"
910
#include "Types.h"
1011
#include "Partitioning.h"
1112

1213
#include "Folder.h"
1314
#include "UFile.h"
1415

16+
1517
/**
1618
* Abstract class representing the common features of the supported storage methods
1719
*/
@@ -49,6 +51,9 @@ class Arduino_UnifiedStorage {
4951
*/
5052
virtual bool format(FileSystems fs) = 0;
5153

54+
55+
static bool loggingEnabled;
56+
5257
};
5358

5459
#if defined(HAS_USB)

src/Boards.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
#define USES_MBED_CORE
3030
#define QSPI_STORAGE_SIZE 16384
3131
#define HAS_SERIAL
32-
#endif
32+
#endif

src/Folder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "Arduino_UnifiedStorage.h"
12
#include "Folder.h"
23
#include <cstdio>
34
#include <cstring>

src/Folder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef Folder_H
22
#define Folder_H
33

4-
4+
#include "Arduino_UnifiedStorage.h"
55
#include "Utils.h"
66
#include "UFile.h"
77
#include <vector>

src/Partitioning.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11

22
#include "Arduino.h"
33
#include "Types.h"
4-
#include "Arduino_POSIXStorage.h"
4+
#include "Arduino_UnifiedStorage.h"
55
#include <vector>
66

77

8-
98
constexpr int mbrBlockSize = 4096;
109
constexpr int mbrPartitionType = 0x0B;
1110
constexpr const char * mountPointName = "mountPoint";

src/SDStorage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "Arduino_UnifiedStorage.h"
77

8-
98
/**
109
* Represents an SD card storage using the Arduino Unified Storage library.
1110
*/

src/UFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define File_H
33

44
#include <Arduino.h>
5+
#include "Arduino_UnifiedStorage.h"
56
#include <string.h>
67
#include <vector>
78
#include "Utils.h"

src/USBStorage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#define USBStorage_H
55

66
#include "Arduino_UnifiedStorage.h"
7-
87
/**
98
* USBStorage class provides an interface to access USB storage devices.
109
* It inherits from the Arduino_UnifiedStorage class and implements its pure virtual functions.

src/Utils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define PATH_MAX_LENGTH 255
44

55
#include "Arduino.h"
6+
#include "Arduino_UnifiedStorage.h"
67
#include "Arduino_POSIXStorage.h"
78
#include <iostream>
89

@@ -43,15 +44,16 @@
4344
#endif
4445

4546
[[gnu::unused]] static void debugPrint(String s){
46-
#if defined(ARDUINO_UNIFIED_STORAGE_DEBUG)
47+
48+
if (Arduino_UnifiedStorage::loggingEnabled == true){
4749
#if defined(HAS_SERIAL)
4850
if(Serial){
4951
Serial.println(s);
5052
}
5153
#elif defined(HAS_RS485) && !defined(HAS_SERIAL)
5254
debugPrintRS485(s);
5355
#endif
54-
#endif
56+
}
5557
}
5658

5759
[[gnu::unused]] static const char* createPartitionName(int number) {

0 commit comments

Comments
 (0)