BayEOS-Arduino  1.8.0_0.0.4
BayEOSBufferSD.cpp
1 #include "BayEOSBufferSD.h"
2 BayEOSBufferSD::BayEOSBufferSD(unsigned long max_length,uint8_t append,const char *f):BayEOSBuffer(){
3  strncpy(_filename,f,12);
4  _filename[12]=0;
5 #if SERIAL_DEBUG
6  Serial.println(_filename);
7  Serial.println("open file:");
8  delay(100);
9 #endif
10  _f=SD.open(_filename, O_CREAT | O_RDWR | O_APPEND);
11  _max_length=max_length;
12 #if SERIAL_DEBUG
13  Serial.println(_f.size());
14 #endif
15  if(append) set(_f.size());
16  else reset();
17 }
18 
19 
20 
21 void BayEOSBufferSD::resetStorage(void){
22  _f.close();
23  SD.remove(_filename);
24  _f=SD.open(_filename,O_CREAT | O_RDWR | O_TRUNC);
25 // Serial.println("SD reset");
26 }
27 
28 uint8_t BayEOSBufferSD::write(const uint8_t b){
29  return _f.write(b);
30 }
31 
32 uint8_t BayEOSBufferSD::write(const uint8_t *b,uint8_t length){
33 // Serial.print("SD.write:");
34 // Serial.println(_f.size());
35  return _f.write(b,length);
36 }
37 
38 uint8_t BayEOSBufferSD::seek(unsigned long pos){
39  return _f.seek(pos);
40 }
41 
42 int BayEOSBufferSD::read(void){
43  return _f.read();
44 }
45 
46 int BayEOSBufferSD::read(uint8_t *dest,int length){
47  return _f.read(dest,length);
48 }
49 
50 void BayEOSBufferSD::flush(void){
51  _f.flush();
52  // Serial.println(_f.size());
53 }
void reset(void)