mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Организация файлов, компилируемая версия
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"C_Cpp.clang_format_fallbackStyle": "{BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}",
|
|
||||||
"C_Cpp.formatting": "clangFormat",
|
|
||||||
"C_Cpp.default.forcedInclude": []
|
|
||||||
}
|
|
||||||
18
include/EspFileSystem.h
Normal file
18
include/EspFileSystem.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Global.h"
|
||||||
|
#include "LittleFS.h"
|
||||||
|
|
||||||
|
extern FS LittleFS;
|
||||||
|
using littlefs_impl::LittleFSConfig;
|
||||||
|
extern FS* filesystem;
|
||||||
|
#define FileFS LittleFS
|
||||||
|
#define FS_NAME "LittleFS"
|
||||||
|
|
||||||
|
extern bool fileSystemInit();
|
||||||
|
|
||||||
|
extern File seekFile(const String& filename, size_t position = 0);
|
||||||
|
extern const String writeFile(const String& filename, const String& str);
|
||||||
|
extern const String readFile(const String& filename, size_t max_size);
|
||||||
|
extern const String filepath(const String& filename);
|
||||||
|
extern bool cutFile(const String& src, const String& dst);
|
||||||
6
include/Global.h
Normal file
6
include/Global.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <FS.h>
|
||||||
|
#include <StreamUtils.h>
|
||||||
@@ -1,14 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#pragma once
|
||||||
#include <ArduinoJson.h>
|
#include "EspFileSystem.h"
|
||||||
#include <FS.h>
|
#include "Global.h"
|
||||||
#include <StreamUtils.h>
|
#include "rest.h"
|
||||||
|
|
||||||
#include "LittleFS.h"
|
|
||||||
|
|
||||||
extern FS LittleFS;
|
|
||||||
using littlefs_impl::LittleFSConfig;
|
|
||||||
extern FS* filesystem;
|
|
||||||
#define FileFS LittleFS
|
|
||||||
#define FS_NAME "LittleFS"
|
|
||||||
|
|
||||||
void setupESP();
|
void setupESP();
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
#include "main.h"
|
#pragma once
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
File seekFile(const String& filename, size_t position = 0);
|
|
||||||
const String writeFile(const String& filename, const String& str);
|
|
||||||
const String readFile(const String& filename, size_t max_size);
|
|
||||||
const String filepath(const String& filename);
|
|
||||||
bool fileSystemInit();
|
|
||||||
String prettyBytes(size_t size);
|
String prettyBytes(size_t size);
|
||||||
bool cutFile(const String& src, const String& dst);
|
|
||||||
@@ -15,7 +15,7 @@ data_dir = data_svelte
|
|||||||
|
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
lib_deps_external =
|
lib_deps_external =
|
||||||
bblanchon/ArduinoJson
|
bblanchon/ArduinoJson @6.18.0
|
||||||
|
|
||||||
[env:esp8266_4mb]
|
[env:esp8266_4mb]
|
||||||
build_flags = -Desp8266_4mb="esp8266_4mb"
|
build_flags = -Desp8266_4mb="esp8266_4mb"
|
||||||
@@ -23,6 +23,8 @@ framework = arduino
|
|||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
board_build.ldscript = eagle.flash.4m1m.ld
|
board_build.ldscript = eagle.flash.4m1m.ld
|
||||||
platform = espressif8266 @2.6.3
|
platform = espressif8266 @2.6.3
|
||||||
|
lib_deps =
|
||||||
|
${common_env_data.lib_deps_external}
|
||||||
monitor_filters = esp8266_exception_decoder
|
monitor_filters = esp8266_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|||||||
76
src/EspFileSystem.cpp
Normal file
76
src/EspFileSystem.cpp
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#include "EspFileSystem.h"
|
||||||
|
|
||||||
|
bool fileSystemInit() {
|
||||||
|
if (!FileFS.begin()) {
|
||||||
|
Serial.println("FS Init ERROR, may be FS was not flashed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Serial.println("FS Init completed");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
File seekFile(const String& filename, size_t position) {
|
||||||
|
String path = filepath(filename);
|
||||||
|
auto file = FileFS.open(path, "r");
|
||||||
|
if (!file) {
|
||||||
|
Serial.println("[E] file error");
|
||||||
|
}
|
||||||
|
file.seek(position, SeekSet);
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
const String writeFile(const String& filename, const String& str) {
|
||||||
|
String path = filepath(filename);
|
||||||
|
auto file = FileFS.open(path, "w");
|
||||||
|
if (!file) {
|
||||||
|
return "failed";
|
||||||
|
}
|
||||||
|
file.print(str);
|
||||||
|
file.close();
|
||||||
|
return "sucсess";
|
||||||
|
}
|
||||||
|
|
||||||
|
const String readFile(const String& filename, size_t max_size) {
|
||||||
|
String path = filepath(filename);
|
||||||
|
auto file = FileFS.open(path, "r");
|
||||||
|
if (!file) {
|
||||||
|
return "failed";
|
||||||
|
}
|
||||||
|
size_t size = file.size();
|
||||||
|
if (size > max_size) {
|
||||||
|
file.close();
|
||||||
|
return "large";
|
||||||
|
}
|
||||||
|
String temp = file.readString();
|
||||||
|
file.close();
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
const String filepath(const String& filename) {
|
||||||
|
return filename.startsWith("/") ? filename : "/" + filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cutFile(const String& src, const String& dst) {
|
||||||
|
String srcPath = filepath(src);
|
||||||
|
String dstPath = filepath(dst);
|
||||||
|
Serial.println("cut " + srcPath + " to " + dstPath);
|
||||||
|
if (!FileFS.exists(srcPath)) {
|
||||||
|
Serial.println("not exist: " + srcPath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (FileFS.exists(dstPath)) {
|
||||||
|
FileFS.remove(dstPath);
|
||||||
|
}
|
||||||
|
auto srcFile = FileFS.open(srcPath, "r");
|
||||||
|
auto dstFile = FileFS.open(dstPath, "w");
|
||||||
|
|
||||||
|
uint8_t buf[512];
|
||||||
|
while (srcFile.available()) {
|
||||||
|
size_t len = srcFile.read(buf, 512);
|
||||||
|
dstFile.write(buf, len);
|
||||||
|
}
|
||||||
|
srcFile.close();
|
||||||
|
dstFile.close();
|
||||||
|
FileFS.remove(srcPath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#include "main.h"
|
#include "Main.h"
|
||||||
|
|
||||||
#include "rest.h"
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|||||||
75
src/rest.cpp
75
src/rest.cpp
@@ -1,55 +1,5 @@
|
|||||||
#include "rest.h"
|
#include "rest.h"
|
||||||
|
|
||||||
File seekFile(const String& filename, size_t position) {
|
|
||||||
String path = filepath(filename);
|
|
||||||
auto file = FileFS.open(path, "r");
|
|
||||||
if (!file) {
|
|
||||||
Serial.println("[E] file error");
|
|
||||||
}
|
|
||||||
file.seek(position, SeekSet);
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
const String writeFile(const String& filename, const String& str) {
|
|
||||||
String path = filepath(filename);
|
|
||||||
auto file = FileFS.open(path, "w");
|
|
||||||
if (!file) {
|
|
||||||
return "failed";
|
|
||||||
}
|
|
||||||
file.print(str);
|
|
||||||
file.close();
|
|
||||||
return "sucсess";
|
|
||||||
}
|
|
||||||
|
|
||||||
const String readFile(const String& filename, size_t max_size) {
|
|
||||||
String path = filepath(filename);
|
|
||||||
auto file = FileFS.open(path, "r");
|
|
||||||
if (!file) {
|
|
||||||
return "failed";
|
|
||||||
}
|
|
||||||
size_t size = file.size();
|
|
||||||
if (size > max_size) {
|
|
||||||
file.close();
|
|
||||||
return "large";
|
|
||||||
}
|
|
||||||
String temp = file.readString();
|
|
||||||
file.close();
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
const String filepath(const String& filename) {
|
|
||||||
return filename.startsWith("/") ? filename : "/" + filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fileSystemInit() {
|
|
||||||
if (!FileFS.begin()) {
|
|
||||||
Serial.println("FS Init ERROR, may be FS was not flashed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Serial.println("FS Init completed");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String prettyBytes(size_t size) {
|
String prettyBytes(size_t size) {
|
||||||
if (size < 1024)
|
if (size < 1024)
|
||||||
return String(size) + "b";
|
return String(size) + "b";
|
||||||
@@ -60,28 +10,3 @@ String prettyBytes(size_t size) {
|
|||||||
else
|
else
|
||||||
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cutFile(const String& src, const String& dst) {
|
|
||||||
String srcPath = filepath(src);
|
|
||||||
String dstPath = filepath(dst);
|
|
||||||
Serial.println("cut " + srcPath + " to " + dstPath);
|
|
||||||
if (!FileFS.exists(srcPath)) {
|
|
||||||
Serial.println("not exist: " + srcPath);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (FileFS.exists(dstPath)) {
|
|
||||||
FileFS.remove(dstPath);
|
|
||||||
}
|
|
||||||
auto srcFile = FileFS.open(srcPath, "r");
|
|
||||||
auto dstFile = FileFS.open(dstPath, "w");
|
|
||||||
|
|
||||||
uint8_t buf[512];
|
|
||||||
while (srcFile.available()) {
|
|
||||||
size_t len = srcFile.read(buf, 512);
|
|
||||||
dstFile.write(buf, len);
|
|
||||||
}
|
|
||||||
srcFile.close();
|
|
||||||
dstFile.close();
|
|
||||||
FileFS.remove(srcPath);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user