-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFileIO.h
76 lines (72 loc) · 1.31 KB
/
FileIO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "FS.h"
#include "FFat.h"
// This file should be compiled with 'Partition Scheme' (in Tools menu)
// set to 'Default with ffat' if you have a 4MB ESP32 dev module or
// set to '16M Fat' if you have a 16MB ESP32 dev module.
// You only need to format FFat the first time you run a test
#define FORMAT_FFAT true
const char* SETTINGS_FILE = "settings.cfg";
const char* PATTERNS_FILE = "patterns.dat";
const char* TUNINGS_FILE = "tunings.dat";
const char* PATCHES_FILE = "patches.dat";
File file;
void initFileIO(char* msg)
{
if(!FFat.begin())
{
sprintf(msg,"FILEIO INIT ERR");
}
else
{
sprintf(msg, "FILEIO OK");
}
}
void formatFat()
{
FFat.format();
}
bool openFile(const char* filename)
{
file = FFat.open(filename);
return file?true:false;
}
bool openFileForWriting(const char* filename)
{
file = FFat.open(filename,FILE_WRITE);
return (file>0)?true:false;
}
bool readLine(char* buf, int maxchars)
{
int i = 0;
while(file.available() && i<maxchars)
{
char c = file.read();
if(c=='\n')
{
buf[i]=0;
return true;
}
buf[i] = c;
i++;
}
if(i>0)
{
return true;
}
return false;
}
bool writeLine(char* msg)
{
if(file.print(msg) && file.print("\n"))
{
return true;
}
else
{
return false;
}
}
void closeFile()
{
file.close();
}