Skip to content

Commit 2c0f663

Browse files
committed
Ability to disable SD import
1 parent a5a6a1e commit 2c0f663

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

CSV_Parser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* https://github.com/michalmonday/CSV-Parser-for-Arduino */
22

33
#include "CSV_Parser.h"
4-
#include <SD.h>
4+
5+
#ifndef CSV_PARSER_DONT_IMPORT_SD
6+
#include <SD.h>
7+
#endif
58

69
//#include "mem_check.h" // COMMENT-OUT BEFORE UPLOAD
710

@@ -105,9 +108,11 @@ CSV_Parser::~CSV_Parser() {
105108
free(leftover);
106109
}
107110

111+
#ifndef CSV_PARSER_DONT_IMPORT_SD
108112
bool CSV_Parser::readSDfile(const char *f_name) {
109113
// open the file. note that only one file can be open at a time,
110114
// so you have to close this one before opening another.
115+
111116
File csv_file = SD.open(f_name);
112117
if (!csv_file)
113118
return false;
@@ -122,6 +127,7 @@ bool CSV_Parser::readSDfile(const char *f_name) {
122127
parseLeftover();
123128
return true;
124129
}
130+
#endif
125131

126132
/* It ensures that '\r\n' characters, delimiter and quote characters that are enclosed within string
127133
value itself are properly parsed. It dynamically allocates memory, creates copy of parsed string

CSV_Parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ class CSV_Parser {
116116
@param f_name - file name (provided file must have format that was supplied in CSV_Parser constructor)
117117
@return True if file could be read, false if not.
118118
It requires previously calling "SD.begin()". */
119+
120+
#ifndef CSV_PARSER_DONT_IMPORT_SD
119121
bool readSDfile(const char *f_name);
122+
#endif
120123

121124
int getColumnsCount();
122125

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [Custom delimiter](#custom-delimiter)
1212
* [Custom quote character](#custom-quote-character)
1313
* [Checking if the file was parsed correctly](#checking-if-the-file-was-parsed-correctly)
14+
* [Troubleshooting](#troubleshooting)
1415
* [Motivation](#motivation)
1516
* [Documentation](#documentation)
1617

@@ -292,6 +293,14 @@ It will display parsed header fields, their types and all the parsed values. Lik
292293
293294
**Important - cp.print() method is using "Serial" object, it assumes that "Serial.begin(baud_rate);" was previously called.**
294295
296+
## Troubleshooting
297+
298+
Platformio users reported compilation issues due to SD library import by the CSV_Parser.cpp file. Since 0.2.1 version of this library, the SD import can be disabled by placing `#define CSV_PARSER_DONT_IMPORT_SD` above (it won't work if it's below) the CSV_Parser library import like this:
299+
300+
```cpp
301+
#define CSV_PARSER_DONT_IMPORT_SD
302+
#include <CSV_Parser.h>
303+
```
295304

296305
## Motivation
297306
I wanted to parse [covid-19 csv](https://github.com/tomwhite/covid-19-uk-data) data and couldn't find any csv parser for Arduino. So instead of rushing with a quick/dirty solution, I decided to write something that could be reused in the future (possibly by other people too).

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=CSV Parser
2-
version=0.2.0
2+
version=0.2.1
33
author=Michal Borowski <michalmonday17@gmail.com>
44
maintainer=Michal Borowski <michalmonday17@gmail.com>
55
sentence=CSV Parser for Arduino.
66
paragraph=It turns CSV string into an associative array. It was written with care about speed/space efficiency.
77
category=Data Processing
88
url=https://github.com/michalmonday/CSV-Parser-for-Arduino
9-
architectures=*
9+
architectures=*

0 commit comments

Comments
 (0)