flashstream.h
Go to the documentation of this file.
#pragma once
//#ifndef _FLASHSTREAM_H_
//#define _FLASHSTREAM_H_
#include <Stream.h>
#include <Arduino.h>
#include "seekablestream.h"
//#include "config.h"
#if defined(FS_STORAGE)
#include <FS.h>
#if defined ARDUINO_ARCH_ESP32
#include <SPIFFS.h>
#endif
#endif
#define FN_CONFIG_JSON 1
#define FN_CONFIG_BIN 2
#if defined(FS_STORAGE)
class flashStream : public seekableStream
{
private:
String filename;
char openedMode;
File fs;
public:
flashStream():seekableStream(65535)
{
openedMode='\0';
filename = "";
};
virtual int open(String _filename, char mode) override;
virtual int available() override;
virtual int read() override;
virtual int peek() override;
virtual unsigned int seek (unsigned int _pos = 0) override;
virtual void close() override;
virtual void flush() override;
virtual size_t write(uint8_t ch);
using Print::write;
virtual void putEOF() override {};
virtual ~flashStream ();
};
#else
#define MAX_STREAM_SIZE 4096
class flashStream : public seekableStream
{
protected:
unsigned int pos;
unsigned int startPos;
public:
flashStream():seekableStream(MAX_STREAM_SIZE){};
void setSize(unsigned int _size);
int open(short fileNum, char mode='\0') ;
virtual int open(String _filename, char mode='\0') override;
virtual unsigned int seek(unsigned int _pos = 0);
virtual int available() override;
virtual int read() ;
virtual int peek() ;
virtual void flush();
virtual size_t write(uint8_t ch) ;
#if defined(__SAM3X8E__)
virtual size_t write(const uint8_t *buffer, size_t size) override;
#else
using Print::write;//(const uint8_t *buffer, size_t size);
#endif
#if defined(ESP8266) || defined(ESP32)
virtual void putEOF() override ;
#endif
virtual void close() override;
};
#endif
//#endif
flashStream::pos
unsigned int pos
Definition: flashstream.h:54
flashStream::flashStream
flashStream()
Definition: flashstream.h:58
flashStream::startPos
unsigned int startPos
Definition: flashstream.h:55
flashStream
Definition: flashstream.h:52
seekableStream::seekableStream
seekableStream(unsigned int size)
Definition: seekablestream.h:17
flashStream::peek
virtual int peek()
Definition: flashstream.cpp:192
seekablestream.h
seekableStream
Definition: seekablestream.h:10
flashStream::write
virtual size_t write(uint8_t ch)
Definition: flashstream.cpp:207
flashStream::flush
virtual void flush()
Definition: flashstream.cpp:199
flashStream::seek
virtual unsigned int seek(unsigned int _pos=0)
Definition: flashstream.cpp:173
MAX_STREAM_SIZE
#define MAX_STREAM_SIZE
Definition: flashstream.h:50
flashStream::read
virtual int read()
Definition: flashstream.cpp:185
flashStream::open
int open(short fileNum, char mode='\0')
Definition: flashstream.cpp:129
flashStream::available
virtual int available() override
Definition: flashstream.cpp:179
seekableStream::putEOF
virtual void putEOF()
Definition: seekablestream.h:25
flashStream::setSize
void setSize(unsigned int _size)
Definition: flashstream.cpp:128
flashStream::close
virtual void close() override
Definition: flashstream.cpp:238