mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
boolean -> bool
This commit is contained in:
parent
3c9d1f20bb
commit
4644c3bad0
@ -21,41 +21,46 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
boolean FSClass::mount(){
|
bool FSClass::mount() {
|
||||||
if(_mounted) return true;
|
if (_mounted)
|
||||||
|
return true;
|
||||||
|
|
||||||
_mounted = spiffs_mount();
|
_mounted = spiffs_mount();
|
||||||
return _mounted;
|
return _mounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSClass::unmount(){
|
void FSClass::unmount() {
|
||||||
if(!_mounted) return;
|
if (!_mounted)
|
||||||
|
return;
|
||||||
|
|
||||||
spiffs_unmount();
|
spiffs_unmount();
|
||||||
_mounted = false;
|
_mounted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FSClass::format(){
|
bool FSClass::format() {
|
||||||
return spiffs_format();
|
return spiffs_format();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FSClass::exists(const char *filename){
|
bool FSClass::exists(const char *filename) {
|
||||||
spiffs_stat stat = {0};
|
spiffs_stat stat = {0};
|
||||||
if (SPIFFS_stat(&_filesystemStorageHandle, filename, &stat) < 0) return false;
|
if (SPIFFS_stat(&_filesystemStorageHandle, filename, &stat) < 0)
|
||||||
|
return false;
|
||||||
return stat.name[0] != '\0';
|
return stat.name[0] != '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FSClass::create(const char *filepath){
|
bool FSClass::create(const char *filepath){
|
||||||
return SPIFFS_creat(&_filesystemStorageHandle, filepath, 0) == 0;
|
return SPIFFS_creat(&_filesystemStorageHandle, filepath, 0) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FSClass::remove(const char *filepath){
|
bool FSClass::remove(const char *filepath){
|
||||||
return SPIFFS_remove(&_filesystemStorageHandle, filepath) == 0;
|
return SPIFFS_remove(&_filesystemStorageHandle, filepath) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FSClass::rename(const char *filename, const char *newname){
|
bool FSClass::rename(const char *filename, const char *newname) {
|
||||||
return SPIFFS_rename(&_filesystemStorageHandle, filename, newname) == 0;
|
return SPIFFS_rename(&_filesystemStorageHandle, filename, newname) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FSFile FSClass::open(const char *filename, uint8_t mode){
|
FSFile FSClass::open(const char *filename, uint8_t mode) {
|
||||||
int repeats = 0;
|
int repeats = 0;
|
||||||
bool notExist;
|
bool notExist;
|
||||||
bool canRecreate = (mode & SPIFFS_CREAT) == SPIFFS_CREAT;
|
bool canRecreate = (mode & SPIFFS_CREAT) == SPIFFS_CREAT;
|
||||||
@ -81,25 +86,25 @@ FSFile FSClass::open(const char *filename, uint8_t mode){
|
|||||||
|
|
||||||
FSClass FS;
|
FSClass FS;
|
||||||
|
|
||||||
FSFile::FSFile(){
|
FSFile::FSFile() {
|
||||||
_file = 0;
|
_file = 0;
|
||||||
_stats = {0};
|
_stats = {0};
|
||||||
}
|
}
|
||||||
|
|
||||||
FSFile::FSFile(file_t f){
|
FSFile::FSFile(file_t f) {
|
||||||
_file = f;
|
_file = f;
|
||||||
if(SPIFFS_fstat(&_filesystemStorageHandle, _file, &_stats) != 0){
|
if(SPIFFS_fstat(&_filesystemStorageHandle, _file, &_stats) != 0){
|
||||||
debugf("mount errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
|
debugf("mount errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSFile::close(){
|
void FSFile::close() {
|
||||||
if (! _file) return;
|
if (! _file) return;
|
||||||
SPIFFS_close(&_filesystemStorageHandle, _file);
|
SPIFFS_close(&_filesystemStorageHandle, _file);
|
||||||
_file = 0;
|
_file = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t FSFile::size(){
|
uint32_t FSFile::size() {
|
||||||
if(! _file) return 0;
|
if(! _file) return 0;
|
||||||
uint32_t pos = SPIFFS_tell(&_filesystemStorageHandle, _file);
|
uint32_t pos = SPIFFS_tell(&_filesystemStorageHandle, _file);
|
||||||
SPIFFS_lseek(&_filesystemStorageHandle, _file, 0, SPIFFS_SEEK_END);
|
SPIFFS_lseek(&_filesystemStorageHandle, _file, 0, SPIFFS_SEEK_END);
|
||||||
@ -108,31 +113,31 @@ uint32_t FSFile::size(){
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t FSFile::seek(uint32_t pos){
|
uint32_t FSFile::seek(uint32_t pos) {
|
||||||
if (! _file) return 0;
|
if (! _file) return 0;
|
||||||
return SPIFFS_lseek(&_filesystemStorageHandle, _file, pos, SPIFFS_SEEK_SET);
|
return SPIFFS_lseek(&_filesystemStorageHandle, _file, pos, SPIFFS_SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t FSFile::position(){
|
uint32_t FSFile::position() {
|
||||||
if (! _file) return 0;
|
if (! _file) return 0;
|
||||||
return SPIFFS_tell(&_filesystemStorageHandle, _file);
|
return SPIFFS_tell(&_filesystemStorageHandle, _file);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FSFile::eof(){
|
bool FSFile::eof() {
|
||||||
if (! _file) return 0;
|
if (! _file) return 0;
|
||||||
return SPIFFS_eof(&_filesystemStorageHandle, _file);
|
return SPIFFS_eof(&_filesystemStorageHandle, _file);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean FSFile::isDirectory(void){
|
bool FSFile::isDirectory(void) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FSFile::read(void *buf, uint16_t nbyte){
|
int FSFile::read(void *buf, uint16_t nbyte) {
|
||||||
if (! _file) return -1;
|
if (! _file) return -1;
|
||||||
return SPIFFS_read(&_filesystemStorageHandle, _file, buf, nbyte);
|
return SPIFFS_read(&_filesystemStorageHandle, _file, buf, nbyte);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FSFile::read(){
|
int FSFile::read() {
|
||||||
if (! _file) return -1;
|
if (! _file) return -1;
|
||||||
int val;
|
int val;
|
||||||
if(SPIFFS_read(&_filesystemStorageHandle, _file, &val, 1) != 1) return -1;
|
if(SPIFFS_read(&_filesystemStorageHandle, _file, &val, 1) != 1) return -1;
|
||||||
|
@ -29,7 +29,7 @@ class String;
|
|||||||
#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC)
|
#define FSFILE_WRITE (SPIFFS_RDONLY | SPIFFS_WRONLY | SPIFFS_CREAT | SPIFFS_APPEND | SPIFFS_TRUNC)
|
||||||
|
|
||||||
class FSFile : public Stream {
|
class FSFile : public Stream {
|
||||||
private:
|
private:
|
||||||
spiffs_stat _stats;
|
spiffs_stat _stats;
|
||||||
file_t _file;
|
file_t _file;
|
||||||
|
|
||||||
@ -47,34 +47,29 @@ public:
|
|||||||
uint32_t remove();
|
uint32_t remove();
|
||||||
uint32_t position();
|
uint32_t position();
|
||||||
uint32_t size();
|
uint32_t size();
|
||||||
boolean eof();
|
bool eof();
|
||||||
void close();
|
void close();
|
||||||
int lastError();
|
int lastError();
|
||||||
void clearError();
|
void clearError();
|
||||||
operator bool(){ return _file > 0; }
|
operator bool() { return _file > 0; }
|
||||||
char * name();
|
char * name();
|
||||||
boolean isDirectory(void);
|
bool isDirectory(void);
|
||||||
|
|
||||||
template<typename T> size_t write(T &src){
|
template<typename T> size_t write(T &src){
|
||||||
uint8_t obuf[64];
|
const size_t bufferSize = 64;
|
||||||
size_t doneLen = 0;
|
uint8_t obuf[bufferSize];
|
||||||
size_t sentLen;
|
size_t bytesWritten = 0;
|
||||||
int i;
|
while (true){
|
||||||
|
size_t available = src.available();
|
||||||
while (src.available() > 64){
|
size_t willWrite = (available < bufferSize) ? available : bufferSize;
|
||||||
src.read(obuf, 64);
|
src.read(obuf, willWrite);
|
||||||
sentLen = write(obuf, 64);
|
size_t cb = write(obuf, willWrite);
|
||||||
doneLen = doneLen + sentLen;
|
bytesWritten += cb;
|
||||||
if(sentLen != 64){
|
if (cb != willWrite) {
|
||||||
return doneLen;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return bytesWritten;
|
||||||
size_t leftLen = src.available();
|
|
||||||
src.read(obuf, leftLen);
|
|
||||||
sentLen = write(obuf, leftLen);
|
|
||||||
doneLen = doneLen + sentLen;
|
|
||||||
return doneLen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using Print::write;
|
using Print::write;
|
||||||
@ -83,16 +78,16 @@ public:
|
|||||||
class FSClass {
|
class FSClass {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boolean _mounted;
|
bool _mounted;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
boolean mount();
|
bool mount();
|
||||||
void unmount();
|
void unmount();
|
||||||
boolean format();
|
bool format();
|
||||||
boolean exists(const char *filename);
|
bool exists(const char *filename);
|
||||||
boolean create(const char *filepath);
|
bool create(const char *filepath);
|
||||||
boolean remove(const char *filepath);
|
bool remove(const char *filepath);
|
||||||
boolean rename(const char *filename, const char *newname);
|
bool rename(const char *filename, const char *newname);
|
||||||
|
|
||||||
FSFile open(const char *filename, uint8_t mode = FSFILE_READ);
|
FSFile open(const char *filename, uint8_t mode = FSFILE_READ);
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#include "c_stdio.h"
|
|
||||||
#include <user_config.h>
|
|
||||||
#include "spiffs_config.h"
|
#include "spiffs_config.h"
|
||||||
#include "flashmem.h"
|
#include "flashmem.h"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user