| LightHub v4.0.0 Smarthome controller firmware

flashstream.h
Go to the documentation of this file.
1 #pragma once
2 //#ifndef _FLASHSTREAM_H_
3 //#define _FLASHSTREAM_H_
4
5
6
7 #include <Stream.h>
8 #include <Arduino.h>
9 #include "seekablestream.h"
10 //#include "config.h"
11
12 #if defined(FS_STORAGE)
13 #include <FS.h>
14 #if defined ARDUINO_ARCH_ESP32
15 #include <SPIFFS.h>
16 #endif
17 #endif
18
19 #define FN_CONFIG_JSON 1
20 #define FN_CONFIG_BIN 2
21
22
23 #if defined(FS_STORAGE)
24 class flashStream : public seekableStream
25 {
26 private:
27 String filename;
28 char openedMode;
29 File fs;
30 public:
31 flashStream():seekableStream(65535)
32 {
33 openedMode='\0';
34 filename = "";
35 };
36 virtual int open(String _filename, char mode) override;
37 virtual int available() override;
38 virtual int read() override;
39 virtual int peek() override;
40 virtual unsigned int seek (unsigned int _pos = 0) override;
41 virtual void close() override;
42 virtual void flush() override;
43 virtual size_t write(uint8_t ch);
44 using Print::write;
45 virtual void putEOF() override {};
46 virtual ~flashStream ();
47 };
48
49 #else
50 #define MAX_STREAM_SIZE 4096
51 class flashStream : public seekableStream
52 {
53 protected:
54 unsigned int pos;
55 unsigned int startPos;
56
57 public:
58 flashStream():seekableStream(MAX_STREAM_SIZE){};
59 void setSize(unsigned int _size);
60 int open(short fileNum, char mode='\0') ;
61 virtual int open(String _filename, char mode='\0') override;
62 virtual unsigned int seek(unsigned int _pos = 0);
63 virtual int available() override;
64 virtual int read() ;
65 virtual int peek() ;
66 virtual void flush();
67 virtual size_t write(uint8_t ch) ;
68
69 #if defined(__SAM3X8E__)
70 virtual size_t write(const uint8_t *buffer, size_t size) override;
71 #else
72 using Print::write;//(const uint8_t *buffer, size_t size);
73 #endif
74
75 #if defined(ESP8266) || defined(ESP32)
76 virtual void putEOF() override ;
77 #endif
78
79 virtual void close() override;
80 };
81 #endif
82
83 //#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