-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSDuFAT.h
150 lines (116 loc) · 4.8 KB
/
SDuFAT.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* SDuFAT.h - Use of SD Cards
*
* Copyright (C) 2008 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* However, D.J. Cuartielles has to credit the following people, since
* this library is just a wrapper on code written by others, who deserve
* all the credit for their effort making this possible:
*
* ** sd2iec - SD/MMC to Commodore serial bus interface/controller
* Copyright (C) 2007,2008 Ingo Korb <ingo@akana.de>
*
* ** Inspiration and low-level SD/MMC access based on code from MMC2IEC
* by Lars Pontoppidan, Aske Olsson, Pascal Dufour, DTU, Denmark
*
* Created February 14th, 2009 by David Cuartielles -aka BlushingBoy-
*/
#include "mmc.h"
#include "microfat.h"
#include <WProgram.h>
#ifndef SDuFAT_h
#define SDuFAT_h
/// DEFINES /////////////////////////////////////////////////////////////////////////////
// define command codes
#define LS 0
#define DEL 1
#define CAT 2
#define PRINT 3
#define WRITE 4
#define APPEND 5
#define SUCCESS 6
#define ERROR 7
#define WARNING 8
// define command help
#define LSm "file info"
#define DELm "deting file"
#define CATm "file content"
#define PRINTm "add string"
#define WRITEm "init file, type text"
#define APPENDm "add text"
#define SUCCESSm "..done\n"
#define ERRORm "..error!\n"
#define WARNINGm "..warning!\n"
// maximum size of the string to be sent to the card at once
// (you will have a hard time getting it to work for bigger values)
// if needed, reduce to the minimum your use of Serial.print and other strings
#define DATABUFFERSIZE 32
// define verbose modes
#define ON 1
#define OFF 0
// define the end of file and end of line characters
#define EOL '.' // used to end the package to write to the board
#define EOF 0x03 // used to mark end of file, 0x03 is end of text, for many editors 0x0A marks end of file, but can be confused with EOL
class SDuFAT
{
private:
public:
/// CONSTRUCTORS ////////////////////////////////////////////////////////////////////////
SDuFAT(void);
/// FUNCTIONS ///////////////////////////////////////////////////////////////////////////
//////TESTED FUNCTIONS //////////////////////////////////////////////////////////////////
// printEvent - displays what is happening
void printEvent(int event, const char* filename);
// usedBytes - returns how many bytes are used in the file
long usedBytes(const char* filename);
// startSector - returns the sector wher the file starts
long startSector(const char* filename);
// del - erases the file given as parameter for real it just writes the first character of
// the file's blocks with EOF, the rest will be kept in the card. It could be used
// to recover data the old-school way
int del(const char* filename);
// ls - prints info about the file to the screen
int ls(const char* filename);
// cat - prints the contents of the file
int cat(const char* filename);
// write - writes data interactively to the file
// after initializing it
int write(const char* filename);
// println - print a string adding EOL
int println(const char* filename, char* data);
int println(const char* filename, byte* data);
// print - append a string at the end of the card
int print(const char* filename, byte* data);
int print(const char* filename, char* data);
// append - append data interactively
int append(const char* filename);
// verbose - change verbose mode
void verbose(byte mode);
//////END TESTED FUNCTIONS //////////////////////////////////////////////////////////////
//////EXPERIMENTAL FUNCTIONS ////////////////////////////////////////////////////////////
// UNDER CONSTRUCTION, WILL COME SOON ///////////////////////////////////////////////////
/*
* - append(filename1, filename2): appends filename2 at the end of filename1
* - indexOf(filename, string): looks for a string in a file answering the position
* - indexOfLine(filename, int): gets the offset in the file to the line determined by the parameter
*/
//////END EXPERIMENTAL FUNCTIONS ////////////////////////////////////////////////////////
/// END FUNCTIONS ///////////////////////////////////////////////////////////////////////
};
extern SDuFAT SD;
#endif