From 2aa21ada27f47f94f3f39773d0bc5b2731e451a9 Mon Sep 17 00:00:00 2001
From: gemu2015
Date: Tue, 5 Jan 2021 16:36:45 +0100
Subject: [PATCH 1/5] fix esp8266 sdcard
---
tasmota/xdrv_98_filesystem.ino | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tasmota/xdrv_98_filesystem.ino b/tasmota/xdrv_98_filesystem.ino
index 1fadd6427..cbb533310 100644
--- a/tasmota/xdrv_98_filesystem.ino
+++ b/tasmota/xdrv_98_filesystem.ino
@@ -98,7 +98,7 @@ void UFSInit(void) {
if (SD.begin(cs)) {
#ifdef ESP8266
- ufsp = (FS*)&SD;
+ ufsp = &SDFS;
#endif // ESP8266
#ifdef ESP32
ufsp = &SD;
From 0af9a948eedf2b2a4aa0cf1770748ddf678e8a98 Mon Sep 17 00:00:00 2001
From: gemu2015
Date: Tue, 5 Jan 2021 16:37:22 +0100
Subject: [PATCH 2/5] update to ufilesystem
---
tasmota/xdrv_10_scripter.ino | 830 +++++++++++------------------------
1 file changed, 245 insertions(+), 585 deletions(-)
diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino
index fdcb7e0ba..7992ab555 100755
--- a/tasmota/xdrv_10_scripter.ino
+++ b/tasmota/xdrv_10_scripter.ino
@@ -36,6 +36,13 @@ no math hierarchy (costs ram and execution time, better group with brackets, an
(will probably make math hierarchy an ifdefed option)
keywords if then else endif, or, and are better readable for beginners (others may use {})
+// to doo
+remove all filesystem inititialization and gui
+adapt 3 options
+1. ufilesystem
+2. eeprom hardware and emulation
+3. compression
+
\*********************************************************************************************/
#define XDRV_10 10
@@ -70,69 +77,50 @@ keywords if then else endif, or, and are better readable for beginners (others m
//uint32_t EncodeLightId(uint8_t relay_id);
//uint32_t DecodeLightId(uint32_t hue_id);
-#ifdef USE_UNISHOX_COMPRESSION
-#define USE_SCRIPT_COMPRESSION
-#endif
+#define SPECIAL_EEPMODE_SIZE 6200
-// solve conficting defines
-// highest priority
-#ifdef USE_SCRIPT_FATFS
-#undef LITTLEFS_SCRIPT_SIZE
-#undef EEP_SCRIPT_SIZE
-#undef USE_SCRIPT_COMPRESSION
+#ifdef USE_UFILESYS
-#if USE_SCRIPT_FATFS==-1
+#undef USE_SCRIPT_FATFS
+#define USE_SCRIPT_FATFS -1
+#pragma message "universal file system used"
-#ifdef ESP32
-#pragma message "script fat file option -1 used"
-#else
-#pragma message "script fat file option -1 used"
-#endif
-
-#else
-#pragma message "script fat file SDC option used"
-#endif
-#endif // USE_SCRIPT_FATFS
-
-// lfs on esp8266 spiffs on esp32
-#ifdef LITTLEFS_SCRIPT_SIZE
-#undef EEP_SCRIPT_SIZE
-#undef USE_SCRIPT_COMPRESSION
-#pragma message "script little file system option used"
-#endif // LITTLEFS_SCRIPT_SIZE
+#else // USE_UFILESYS
// eeprom script
#ifdef EEP_SCRIPT_SIZE
-#undef USE_SCRIPT_COMPRESSION
+
+#ifdef ESP32
+#error "unsupported option for ESP32"
+#endif
+
#ifdef USE_24C256
#pragma message "script 24c256 file option used"
#else
-//#warning "EEP_SCRIPT_SIZE also needs USE_24C256"
-#if EEP_SCRIPT_SIZE==SPI_FLASH_SEC_SIZE
-#pragma message "internal eeprom script buffer used"
-#else
+
+#if EEP_SCRIPT_SIZE==SPECIAL_EEPMODE_SIZE
#pragma message "internal compressed eeprom script buffer used"
+#else
+#error "unsupported eeprom option used"
#endif
-//#define USE_24C256
-#endif
+#endif // USE_24C256
+
+#else // EEP_SCRIPT_SIZE
+
+// default
+#pragma message "script compression option used"
+
#endif // EEP_SCRIPT_SIZE
-// compression last option before default
-#ifdef USE_SCRIPT_COMPRESSION
-#pragma message "script compression option used"
-#endif // USE_UNISHOX_COMPRESSION
+#endif // USE_UFILESYS
-
-//#ifdef USE_SCRIPT_COMPRESSION
#include
-
#define SCRIPT_COMPRESS compressor.unishox_compress
#define SCRIPT_DECOMPRESS compressor.unishox_decompress
#ifndef UNISHOXRSIZE
#define UNISHOXRSIZE 2560
#endif
-//#endif // USE_SCRIPT_COMPRESSION
#ifndef STASK_PRIO
#define STASK_PRIO 1
@@ -165,22 +153,14 @@ void Script_ticker4_end(void) {
// EEPROM MACROS
// i2c eeprom
+#define EEP_WRITE(A,B,C) eeprom_writeBytes(A, B, (uint8_t*)C);
+#define EEP_READ(A,B,C) eeprom_readBytes(A, B, (uint8_t*)C);
+#define EEP_INIT(A) eeprom_init(A)
-#if defined(ALT_EEPROM) && !defined(ESP32)
-#undef EEP_WRITE
-#undef EEP_READ
-#undef EEP_INIT
-#define EEP_WRITE(A,B,C) alt_eeprom_writeBytes(A, B, (uint8_t*)C);
-#define EEP_READ(A,B,C) alt_eeprom_readBytes(A, B, (uint8_t*)C);
-#define EEP_INIT(A) alt_eeprom_init(A)
-#if EEP_SCRIPT_SIZE>6500
-#undef EEP_SCRIPT_SIZE
-#define EEP_SCRIPT_SIZE 6500
-#endif
+#if defined(EEP_SCRIPT_SIZE) && !defined(ESP32)
uint32_t eeprom_block;
-
// these support only one 4 k block below EEPROM this steals 4k of application area
uint32_t alt_eeprom_init(uint32_t size) {
//EEPROM.begin(size);
@@ -198,28 +178,30 @@ void alt_eeprom_readBytes(uint32_t adr, uint32_t len, uint8_t *buf) {
uint32_t *lwp=(uint32_t*)buf;
ESP.flashRead(eeprom_block , lwp, SPI_FLASH_SEC_SIZE);
}
-#else
-#undef EEP_WRITE
-#undef EEP_READ
-#undef EEP_INIT
-#define EEP_WRITE(A,B,C) eeprom_writeBytes(A, B, (uint8_t*)C);
-#define EEP_READ(A,B,C) eeprom_readBytes(A, B, (uint8_t*)C);
-#define EEP_INIT(A) eeprom_init(A)
-#endif // ALT_EEPROM
+#endif // EEP_SCRIPT_SIZE
+
+#include "FS.h"
+
+#define FS_FILE_WRITE "w"
+#define FS_FILE_READ "r"
+#define FS_FILE_APPEND "a"
#if USE_SCRIPT_FATFS==-1
#ifdef ESP32
-#include "FS.h"
-#include "FFat.h"
+//#include "FS.h"
+//#include "FFat.h"
#else
-#include
+//#include
#endif
-FS *fsp;
+
+#ifndef UFILESYSTEM
+//FS *ufsp;
+#endif
+
#endif // LITTLEFS_SCRIPT_SIZE
-//extern FS *ufsp;
// offsets epoch readings by 1.1.2019 00:00:00 to fit into float with second resolution
#define EPOCH_OFFSET 1546300800
@@ -230,50 +212,65 @@ enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD,SCRIPT_EVENT_HANDLED};
#ifdef USE_SCRIPT_FATFS
#if USE_SCRIPT_FATFS>=0
-#include
-#include
-#include
+//#include
+//#include
+//#include
#ifdef ESP32
-#include "FFat.h"
-FS *fsp;
+//#include "FFat.h"
+#ifndef UFILESYSTEM
+//FS *ufsp;
+#endif
#else
-SDClass *fsp;
+#ifndef UFILESYSTEM
+//SDClass *ufsp;
+#endif
#endif
#endif //USE_SCRIPT_FATFS
+#ifndef FAT_SCRIPT_SIZE
+#define FAT_SCRIPT_SIZE 4096
+#endif
+
+
#ifndef ESP32
// esp8266
#if USE_SCRIPT_FATFS>=0
// old fs
-#undef FILE_WRITE
-#define FILE_WRITE (sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT)
-#define FILE_APPEND (sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT | sdfat::O_APPEND)
+//#undef FILE_WRITE
+//#define FILE_WRITE (sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT)
+//#undef FILE_APPEND
+//#define FILE_APPEND (sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT | sdfat::O_APPEND)
#else
// new fs
-#undef FILE_WRITE
-#define FILE_WRITE "w"
-#undef FILE_READ
-#define FILE_READ "r"
-#undef FILE_APPEND
-#define FILE_APPEND "a"
+//undef FILE_WRITE
+//#define FILE_WRITE "w"
+//#undef FILE_READ
+//#define FILE_READ "r"
+//#undef FILE_APPEND
+//#define FILE_APPEND "a"
#endif
#endif // USE_SCRIPT_FATFS>=0
-#ifndef FAT_SCRIPT_SIZE
-#define FAT_SCRIPT_SIZE 4096
+extern uint8_t ufs_type;
+extern FS *ufsp;
+
+
+#ifndef UFSYS_SIZE
+#define UFSYS_SIZE 8192
#endif
+
#ifdef ESP32
#undef FAT_SCRIPT_NAME
#define FAT_SCRIPT_NAME "/script.txt"
#else
#undef FAT_SCRIPT_NAME
-#define FAT_SCRIPT_NAME "script.txt"
+#define FAT_SCRIPT_NAME "/script.txt"
#endif
//#if USE_STANDARD_SPI_LIBRARY==0
@@ -383,6 +380,20 @@ typedef union {
};
} UDP_FLAGS;
+typedef union {
+ uint8_t data;
+ struct {
+ uint8_t nutu8 : 1;
+ uint8_t nutu7 : 1;
+ uint8_t nutu6 : 1;
+ uint8_t nutu5 : 1;
+ uint8_t nutu4 : 1;
+ uint8_t nutu3 : 1;
+ bool fsys : 1;
+ bool eeprom : 1;
+ };
+} FS_FLAGS;
+
#define NUM_RES 0xfe
#define STR_RES 0xfd
@@ -425,7 +436,7 @@ struct SCRIPT_MEM {
uint8_t glob_error;
uint8_t max_ssize;
uint8_t script_loglevel;
- uint8_t flags;
+ FS_FLAGS FLAGS;
uint8_t si_num[3];
uint8_t siro_num[3];
uint8_t sind_num;
@@ -512,7 +523,7 @@ char *GetNumericArgument(char *lp,uint8_t lastop,float *fp, JsonParserObject *jo
char *GetStringArgument(char *lp,uint8_t lastop,char *cp, JsonParserObject *jo);
char *ForceStringVar(char *lp,char *dstr);
void send_download(void);
-uint8_t reject(char *name);
+uint8_t ufs_reject(char *name);
void ScriptEverySecond(void) {
@@ -965,42 +976,6 @@ char *script;
}
}
-// init file system
-//#ifndef USE_UFILESYS
-#if 1
-
-#ifdef USE_SCRIPT_FATFS
- if (!glob_script_mem.script_sd_found) {
-
-#if USE_SCRIPT_FATFS>=0
- // user sd card
- fsp = &SD;
- if (SD.begin(USE_SCRIPT_FATFS)) {
-#else
- // use flash file
-#ifdef ESP32
- // if (SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)) {
- if (FFat.begin(true)) {
-#else
- if (fsp->begin()) {
-#endif // ESP32
-
-#endif // USE_SCRIPT_FATFS>=0
-
- glob_script_mem.script_sd_found = 1;
- } else {
- glob_script_mem.script_sd_found = 0;
- }
- }
- for (uint8_t cnt = 0; cnt0
ClaimSerial();
SetSerialBaudrate(9600);
@@ -1023,63 +998,6 @@ char *script;
return err;
}
-#ifdef USE_SCRIPT_FATFS
-uint32_t get_fsinfo(uint32_t sel) {
-uint32_t result = 0;
-#ifdef ESP32
-#if USE_SCRIPT_FATFS >=0
- if (sel == 0) {
- result = SD.totalBytes()/1000;
- } else if (sel == 1) {
- result = (SD.totalBytes() - SD.usedBytes())/1000;
- }
-#else
- if (sel == 0) {
- result = FFat.totalBytes()/1000;
- } else if (sel == 1) {
- result = FFat.freeBytes()/1000;
- }
-#endif // USE_SCRIPT_FATFS>=0
-#else
- // ESP8266
- FSInfo64 fsinfo;
- fsp->info64(fsinfo);
- if (sel == 0) {
- result = fsinfo.totalBytes/1000;
- } else if (sel == 1) {
- result = (fsinfo.totalBytes - fsinfo.usedBytes)/1000;
- }
-#endif // ESP32
- return result;
-}
-
-// format number with thousand marker
-void form1000(uint32_t number, char *dp, char sc) {
- char str[32];
- sprintf(str, "%d", number);
- char *sp = str;
- uint32_t inum = strlen(sp)/3;
- uint32_t fnum = strlen(sp)%3;
- if (!fnum) inum--;
- for (uint32_t count=0; count<=inum; count++) {
- if (fnum){
- memcpy(dp,sp,fnum);
- dp+=fnum;
- sp+=fnum;
- fnum=0;
- } else {
- memcpy(dp,sp,3);
- dp+=3;
- sp+=3;
- }
- if (count!=inum) {
- *dp++=sc;
- }
- }
- *dp=0;
-}
-
-#endif //USE_SCRIPT_FATFS
#ifdef USE_SCRIPT_GLOBVARS
#define SCRIPT_UDP_BUFFER_SIZE 128
@@ -2090,7 +2008,7 @@ chknext:
#ifdef DEBUG_FS
Script_AddLog_P(LOG_LEVEL_INFO, PSTR("open file for read %d"), cnt);
#endif
- glob_script_mem.files[cnt] = fsp->open(str, FILE_READ);
+ glob_script_mem.files[cnt] = ufsp->open(str, FS_FILE_READ);
if (glob_script_mem.files[cnt].isDirectory()) {
glob_script_mem.files[cnt].rewindDirectory();
glob_script_mem.file_flags[cnt].is_dir = 1;
@@ -2100,12 +2018,12 @@ chknext:
}
else {
if (mode==1) {
- glob_script_mem.files[cnt] = fsp->open(str,FILE_WRITE);
+ glob_script_mem.files[cnt] = ufsp->open(str,FS_FILE_WRITE);
#ifdef DEBUG_FS
Script_AddLog_P(LOG_LEVEL_INFO, PSTR("open file for write %d"), cnt);
#endif
} else {
- glob_script_mem.files[cnt] = fsp->open(str,FILE_APPEND);
+ glob_script_mem.files[cnt] = ufsp->open(str,FS_FILE_APPEND);
#ifdef DEBUG_FS
Script_AddLog_P(LOG_LEVEL_INFO, PSTR("open file for append %d"), cnt);
#endif
@@ -2198,7 +2116,7 @@ chknext:
while (true) {
File entry = glob_script_mem.files[find].openNextFile();
if (entry) {
- if (!reject((char*)entry.name())) {
+ if (!ufs_reject((char*)entry.name())) {
char *ep = (char*)entry.name();
if (*ep=='/') ep++;
char *lcp = strrchr(ep,'/');
@@ -2242,7 +2160,7 @@ chknext:
if (!strncmp(vname, "fd(", 3)) {
char str[glob_script_mem.max_ssize + 1];
lp = GetStringArgument(lp + 3, OPER_EQU, str, 0);
- fsp->remove(str);
+ ufsp->remove(str);
lp++;
len = 0;
goto exit;
@@ -2280,7 +2198,7 @@ chknext:
char str[glob_script_mem.max_ssize + 1];
lp = GetStringArgument(lp + 3, OPER_EQU, str, 0);
// execute script
- File ef = fsp->open(str, FILE_READ);
+ File ef = ufsp->open(str, FS_FILE_READ);
if (ef) {
uint16_t fsiz = ef.size();
if (fsiz<2048) {
@@ -2301,7 +2219,7 @@ chknext:
if (!strncmp(vname, "fmd(", 4)) {
char str[glob_script_mem.max_ssize + 1];
lp = GetStringArgument(lp + 4, OPER_EQU, str, 0);
- fvar = fsp->mkdir(str);
+ fvar = ufsp->mkdir(str);
lp++;
len = 0;
goto exit;
@@ -2309,7 +2227,7 @@ chknext:
if (!strncmp(vname, "frd(", 4)) {
char str[glob_script_mem.max_ssize + 1];
lp = GetStringArgument(lp + 4, OPER_EQU, str, 0);
- fvar = fsp->rmdir(str);
+ fvar = ufsp->rmdir(str);
lp++;
len = 0;
goto exit;
@@ -2317,7 +2235,7 @@ chknext:
if (!strncmp(vname, "fx(", 3)) {
char str[glob_script_mem.max_ssize + 1];
lp = GetStringArgument(lp + 3, OPER_EQU, str, 0);
- if (fsp->exists(str)) fvar = 1;
+ if (ufsp->exists(str)) fvar = 1;
else fvar = 0;
lp++;
len = 0;
@@ -2326,7 +2244,7 @@ chknext:
if (!strncmp(vname, "fsi(", 4)) {
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, 0);
- fvar = get_fsinfo(fvar);
+ fvar = ufs_fsinfo(fvar);
lp++;
len = 0;
goto exit;
@@ -4852,46 +4770,13 @@ const char HTTP_SCRIPT_FORM_END[] PROGMEM =
#ifdef USE_SCRIPT_FATFS
const char HTTP_FORM_SCRIPT1c[] PROGMEM =
"";
-#ifdef SDCARD_DIR
-const char HTTP_FORM_SCRIPT1d[] PROGMEM =
- "";
-#else
+
+
const char HTTP_FORM_SCRIPT1d[] PROGMEM =
"";
-#endif
-#ifdef SDCARD_DIR
-const char S_SCRIPT_FILE_UPLOAD[] PROGMEM = D_SDCARD_DIR;
-#else
const char S_SCRIPT_FILE_UPLOAD[] PROGMEM = D_SDCARD_UPLOAD;
-#endif
-const char HTTP_FORM_FILE_UPLOAD[] PROGMEM =
-""
-"
"
-"
"
-"" D_UPLOAD_STARTED " ...
";
-
-const char HTTP_FORM_FILE_UPGc[] PROGMEM =
-"total size: %s kB - free: %s kB
";
-
-const char HTTP_FORM_SDC_DIRa[] PROGMEM =
-"";
-const char HTTP_FORM_SDC_DIRb[] PROGMEM =
- "
%s %s : %8d
";
-const char HTTP_FORM_SDC_DIRd[] PROGMEM =
-"
%s
";
-const char HTTP_FORM_SDC_DIRc[] PROGMEM =
-"
";
-const char HTTP_FORM_SDC_HREF[] PROGMEM =
-"http://%s/upl?download=%s/%s";
#endif
@@ -4968,194 +4853,16 @@ void ScriptExecuteUploadSuccess(void) {
#ifdef USE_SCRIPT_FATFS
-#if USE_LONG_FILE_NAMES>0
-#undef REJCMPL
-#define REJCMPL 6
-#else
-#undef REJCMPL
-#define REJCMPL 8
-#endif
-
-uint8_t reject(char *name) {
-
- char *lcp = strrchr(name,'/');
- if (lcp) {
- name = lcp + 1;
- }
-
- while (*name=='/') name++;
- if (*name=='_') return 1;
- if (*name=='.') return 1;
-
- if (!strncasecmp(name, "SPOTLI~1", REJCMPL)) return 1;
- if (!strncasecmp(name, "TRASHE~1", REJCMPL)) return 1;
- if (!strncasecmp(name, "FSEVEN~1", REJCMPL)) return 1;
- if (!strncasecmp(name, "SYSTEM~1", REJCMPL)) return 1;
- if (!strncasecmp(name, "System Volume", 13)) return 1;
- return 0;
-}
-
-void ListDir(char *path, uint8_t depth) {
- char name[32];
- char npath[128];
- char format[12];
- sprintf(format, "%%-%ds", 24 - depth);
-
- File dir = fsp->open(path, FILE_READ);
- if (dir) {
- dir.rewindDirectory();
- if (strlen(path)>1) {
- snprintf_P(npath, sizeof(npath), PSTR("http://%s/upl?download=%s"), WiFi.localIP().toString().c_str(),path);
- for (uint8_t cnt = strlen(npath) - 1; cnt>0; cnt--) {
- if (npath[cnt]=='/') {
- if (npath[cnt - 1]=='=') npath[cnt + 1] = 0;
- else npath[cnt] = 0;
- break;
- }
- }
- WSContentSend_P(HTTP_FORM_SDC_DIRd, npath,path, "..");
- }
- char *ep;
- while (true) {
- File entry = dir.openNextFile();
- if (!entry) {
- break;
- }
- // esp32 returns path here, shorten to filename
- ep = (char*)entry.name();
- if (*ep=='/') ep++;
- char *lcp = strrchr(ep,'/');
- if (lcp) {
- ep = lcp + 1;
- }
- //Script_AddLog_P(LOG_LEVEL_INFO, PSTR("entry: %s"),ep);
- time_t tm = entry.getLastWrite();
- char tstr[24];
- strftime(tstr, 22, "%d-%m-%Y - %H:%M:%S ", localtime(&tm));
-
- char *pp = path;
- if (!*(pp + 1)) pp++;
- char *cp = name;
- // osx formatted disks contain a lot of stuff we dont want
- if (reject((char*)ep)) goto fclose;
-
- for (uint8_t cnt = 0; cnt1) {
- strcat(path, "/");
- }
- strcat(path, ep);
- ListDir(path, depth + 4);
- path[plen] = 0;
- } else {
- snprintf_P(npath, sizeof(npath), HTTP_FORM_SDC_HREF, WiFi.localIP().toString().c_str(), pp,ep);
- WSContentSend_P(HTTP_FORM_SDC_DIRb, npath, ep, name, tstr, entry.size());
- }
- fclose:
- entry.close();
- }
- dir.close();
- }
-}
-
-char path[48];
-
-void Script_FileUploadConfiguration(void) {
- uint8_t depth = 0;
-
- strcpy(path, "/");
-
- if (!HttpCheckPriviledgedAccess()) { return; }
-
- if (Webserver->hasArg("download")) {
- String stmp = Webserver->arg("download");
- char *cp = (char*)stmp.c_str();
- if (DownloadFile(cp)) {
- // is directory
- strcpy(path, cp);
- }
- }
-
- WSContentStart_P(S_SCRIPT_FILE_UPLOAD);
- WSContentSendStyle();
- WSContentSend_P(HTTP_FORM_FILE_UPLOAD,D_SDCARD_DIR);
- WSContentSend_P(HTTP_FORM_FILE_UPG, D_SCRIPT_UPLOAD);
-#ifdef SDCARD_DIR
- char ts[16];
- char fs[16];
- form1000(get_fsinfo(0), ts, '.');
- form1000(get_fsinfo(1), fs, '.');
- WSContentSend_P(HTTP_FORM_FILE_UPGc, ts, fs);
- WSContentSend_P(HTTP_FORM_SDC_DIRa);
- if (glob_script_mem.script_sd_found) {
- ListDir(path, depth);
- }
- WSContentSend_P(HTTP_FORM_SDC_DIRc);
-#endif
- WSContentSend_P(HTTP_FORM_FILE_UPGb);
- WSContentSpaceButton(BUTTON_CONFIGURATION);
- WSContentStop();
- Web.upload_error = 0;
-}
-
-void ScriptFileUploadSuccess(void) {
- WSContentStart_P(PSTR(D_INFORMATION));
- WSContentSendStyle();
- WSContentSend_P(PSTR("" D_UPLOAD " " D_SUCCESSFUL "
"), WebColor(COL_TEXT_SUCCESS));
- WSContentSend_P(PSTR("
"));
- WSContentSend_P(PSTR(""),"/upl",D_UPL_DONE);
- //WSContentSpaceButton(BUTTON_MAIN);
- WSContentStop();
-}
-
-
-File upload_file;
-
-void script_upload(void) {
- //Script_AddLog_P(LOG_LEVEL_INFO, PSTR("HTP: file upload"));
- HTTPUpload& upload = Webserver->upload();
- if (upload.status == UPLOAD_FILE_START) {
- char npath[48];
-#if defined(ESP32) && defined(USE_SCRIPT_FATFS) && USE_SCRIPT_FATFS==-1
- //sprintf(npath,"/%s",upload.filename.c_str());
- sprintf(npath, "%s/%s", path, upload.filename.c_str());
-#else
- sprintf(npath, "%s/%s", path, upload.filename.c_str());
-#endif
- fsp->remove(npath);
- upload_file = fsp->open(npath, FILE_WRITE);
- if (!upload_file) Web.upload_error = 1;
- } else if(upload.status == UPLOAD_FILE_WRITE) {
- if (upload_file) upload_file.write(upload.buf, upload.currentSize);
- } else if(upload.status == UPLOAD_FILE_END) {
- if (upload_file) upload_file.close();
- if (Web.upload_error) {
- Script_AddLog_P(LOG_LEVEL_INFO, PSTR("HTP: upload error"));
- }
- } else {
- Web.upload_error=1;
- Webserver->send(500, "text/plain", "500: couldn't create file");
- }
-}
-
uint8_t DownloadFile(char *file) {
File download_file;
WiFiClient download_Client;
- if (!fsp->exists(file)) {
+ if (!ufsp->exists(file)) {
Script_AddLog_P(LOG_LEVEL_INFO,PSTR("file not found"));
return 0;
}
- download_file = fsp->open(file, FILE_READ);
+ download_file = ufsp->open(file, FS_FILE_READ);
if (!download_file) {
Script_AddLog_P(LOG_LEVEL_INFO,PSTR("could not open file"));
return 0;
@@ -5233,9 +4940,6 @@ void HandleScriptConfiguration(void) {
if (Webserver->hasArg("d2")) {
DownloadFile(glob_script_mem.flink[1]);
}
- if (Webserver->hasArg("upl")) {
- Script_FileUploadConfiguration();
- }
#endif
WSContentStart_P(PSTR(D_CONFIGURE_SCRIPT));
@@ -5273,30 +4977,40 @@ void HandleScriptConfiguration(void) {
void SaveScript(void) {
-#ifdef EEP_SCRIPT_SIZE
- if (glob_script_mem.flags&1) {
-#if EEP_SCRIPT_SIZE==SPI_FLASH_SEC_SIZE
- EEP_WRITE(0, EEP_SCRIPT_SIZE, glob_script_mem.script_ram);
-#else
- char *ucs;
- ucs = (char*)calloc(SPI_FLASH_SEC_SIZE + 4, 1);
- if (!script_compress(ucs,EEP_SCRIPT_SIZE-1)) {
- EEP_WRITE(0, EEP_SCRIPT_SIZE, ucs);
- }
- if (ucs) free(ucs);
-#endif
+
+#ifdef USE_UFILESYS
+ if (glob_script_mem.FLAGS.fsys == true) {
+ ufsp->remove(FAT_SCRIPT_NAME);
+ File file = ufsp->open(FAT_SCRIPT_NAME, FS_FILE_WRITE);
+ file.write((const uint8_t*)glob_script_mem.script_ram, strlen(glob_script_mem.script_ram));
+ file.close();
+ } else {
+ // fallback to compressed mode
+ script_compress(Settings.rules[0],MAX_SCRIPT_SIZE-1);
}
+#else // USE_UFILESYS
+
+#ifdef EEP_SCRIPT_SIZE
+ // here we handle EEPROM modes
+ if (glob_script_mem.FLAGS.eeprom == true) {
+ if (EEP_SCRIPT_SIZE!=SPECIAL_EEPMODE_SIZE) {
+ EEP_WRITE(0, EEP_SCRIPT_SIZE, glob_script_mem.script_ram);
+ } else {
+ uint8_t *ucs;
+ ucs = (uint8_t*)calloc(SPI_FLASH_SEC_SIZE + 4, 1);
+ if (!script_compress((char*)ucs,EEP_SCRIPT_SIZE-1)) {
+ alt_eeprom_writeBytes(0, EEP_SCRIPT_SIZE, ucs);
+ }
+ if (ucs) free(ucs);
+ }
+ }
+#else
+ // default mode is compression
+ script_compress(Settings.rules[0],MAX_SCRIPT_SIZE-1);
#endif // EEP_SCRIPT_SIZE
-#ifdef USE_SCRIPT_FATFS
- if (glob_script_mem.flags & 1) {
- fsp->remove(FAT_SCRIPT_NAME);
- File file = fsp->open(FAT_SCRIPT_NAME, FILE_WRITE);
- file.write((const uint8_t*)glob_script_mem.script_ram, FAT_SCRIPT_SIZE);
- file.close();
- }
-#endif // USE_SCRIPT_FATFS
+#endif // USE_UFILESYS
}
void ScriptSaveSettings(void) {
@@ -5307,7 +5021,6 @@ void ScriptSaveSettings(void) {
bitWrite(Settings.rule_enabled, 0, 0);
}
-
String str = Webserver->arg("t1");
if (*str.c_str()) {
@@ -5315,38 +5028,6 @@ void ScriptSaveSettings(void) {
str.replace("\r\n", "\n");
str.replace("\r", "\n");
-#ifdef xSCRIPT_STRIP_COMMENTS
- if (bitRead(Settings.rule_enabled, 1)) {
- char *sp = (char*)str.c_str();
- char *sp1 = sp;
- char *dp = sp;
- uint8_t flg = 0;
- while (*sp) {
- while (*sp==' ') sp++;
- sp1 = sp;
- sp = strchr(sp,'\n');
- if (!sp) {
- flg = 1;
- } else {
- *sp = 0;
- }
- if (*sp1!=';') {
- uint8_t slen = strlen(sp1);
- if (slen) {
- strcpy(dp, sp1);
- dp += slen;
- *dp++ = '\n';
- }
- }
- if (flg) {
- *dp = 0;
- break;
- }
- sp++;
- }
- }
-#endif //xSCRIPT_STRIP_COMMENTS
-
strlcpy(glob_script_mem.script_ram, str.c_str(), glob_script_mem.script_size);
if (glob_script_mem.script_ram[0]!='>' && glob_script_mem.script_ram[1]!='D') {
@@ -5389,10 +5070,6 @@ void SaveScriptEnd(void) {
glob_script_mem.script_mem_size = 0;
}
-#ifdef USE_SCRIPT_COMPRESSION
- script_compress(Settings.rules[0],MAX_SCRIPT_SIZE-1);
-#endif // USE_SCRIPT_COMPRESSION
-
if (bitRead(Settings.rule_enabled, 0)) {
int16_t res = Init_Scripter();
@@ -6460,7 +6137,7 @@ void ScriptGetSDCard(void) {
SendFile(cp);
return;
} else {
- if (fsp->exists(cp)) {
+ if (ufsp->exists(cp)) {
SendFile(cp);
return;
}
@@ -6543,7 +6220,7 @@ char buff[512];
}
#endif // USE_DISPLAY_DUMP
} else {
- File file = fsp->open(fname,FILE_READ);
+ File file = ufsp->open(fname,FS_FILE_READ);
uint32_t siz = file.size();
uint32_t len = sizeof(buff);
while (siz > 0) {
@@ -7645,6 +7322,8 @@ void cpy2lf(char *dst, uint32_t dstlen, char *src) {
\*********************************************************************************************/
//const esp_partition_t *esp32_part;
+
+
bool Xdrv10(uint8_t function)
{
bool result = false;
@@ -7658,13 +7337,93 @@ bool Xdrv10(uint8_t function)
//bitWrite(Settings.rule_enabled,0,0);
glob_script_mem.script_ram = Settings.rules[0];
glob_script_mem.script_size = MAX_SCRIPT_SIZE;
- glob_script_mem.flags = 0;
+ glob_script_mem.FLAGS.fsys = false;
+ glob_script_mem.FLAGS.eeprom = false;
glob_script_mem.script_pram = (uint8_t*)Settings.script_pram[0];
glob_script_mem.script_pram_size = PMEM_SIZE;
- // indicates scripter enabled (use rules[][] as single array)
- bitWrite(Settings.rule_once, 7, 1);
-#ifdef USE_SCRIPT_COMPRESSION
+#ifdef USE_UFILESYS
+ if (ufs_type) {
+ // we have a file system
+ Script_AddLog_P(LOG_LEVEL_INFO,PSTR("UFILESYSTEM OK!"));
+ char *script;
+ script = (char*)calloc(UFSYS_SIZE + 4, 1);
+ if (!script) break;
+ glob_script_mem.script_ram = script;
+ glob_script_mem.script_size = UFSYS_SIZE;
+ if (ufsp->exists(FAT_SCRIPT_NAME)) {
+ File file = ufsp->open(FAT_SCRIPT_NAME, FS_FILE_READ);
+ file.read((uint8_t*)script, UFSYS_SIZE);
+ file.close();
+ }
+ script[UFSYS_SIZE - 1] = 0;
+ // use rules storage for permanent vars
+ glob_script_mem.script_pram = (uint8_t*)Settings.rules[0];
+ glob_script_mem.script_pram_size = MAX_SCRIPT_SIZE;
+ glob_script_mem.FLAGS.fsys = true;
+ // indicates scripter use no compression
+ bitWrite(Settings.rule_once, 6, 0);
+ } else {
+ Script_AddLog_P(LOG_LEVEL_INFO,PSTR("UFILESYSTEM fail, using compression!"));
+ int32_t len_decompressed;
+ sprt = (char*)calloc(UNISHOXRSIZE + 8,1);
+ if (!sprt) { break; }
+ glob_script_mem.script_ram = sprt;
+ glob_script_mem.script_size = UNISHOXRSIZE;
+ len_decompressed = SCRIPT_DECOMPRESS(Settings.rules[0], strlen(Settings.rules[0]), glob_script_mem.script_ram, glob_script_mem.script_size);
+ if (len_decompressed>0) glob_script_mem.script_ram[len_decompressed] = 0;
+ // indicates scripter use compression
+ bitWrite(Settings.rule_once, 6, 1);
+ }
+#else // USE_UFILESYS
+
+#ifdef EEP_SCRIPT_SIZE
+
+ if (EEP_INIT(EEP_SCRIPT_SIZE)) {
+ // found 32kb eeprom,
+ char *script;
+ if (EEP_SCRIPT_SIZE!=SPECIAL_EEPMODE_SIZE) {
+ script = (char*)calloc(EEP_SCRIPT_SIZE + 4, 1);
+ if (!script) break;
+ glob_script_mem.script_ram = script;
+ glob_script_mem.script_size = EEP_SCRIPT_SIZE;
+ EEP_READ(0, EEP_SCRIPT_SIZE, script);
+ if (*script==0xff) {
+ memset(script, EEP_SCRIPT_SIZE, 0);
+ }
+ script[EEP_SCRIPT_SIZE - 1] = 0;
+ } else {
+ uint8_t *ucs;
+ ucs = (uint8_t*)calloc(SPI_FLASH_SEC_SIZE + 4, 1);
+ if (!ucs) break;
+ alt_eeprom_readBytes(0, SPI_FLASH_SEC_SIZE, ucs);
+ if (*ucs==0xff) {
+ memset(ucs, SPI_FLASH_SEC_SIZE, 0);
+ }
+ ucs[SPI_FLASH_SEC_SIZE - 1] = 0;
+
+ script = (char*)calloc(EEP_SCRIPT_SIZE + 4, 1);
+ if (!script) break;
+ glob_script_mem.script_ram = script;
+ glob_script_mem.script_size = EEP_SCRIPT_SIZE;
+
+ int32_t len_decompressed;
+ len_decompressed = SCRIPT_DECOMPRESS((char*)ucs, strlen((char*)ucs), glob_script_mem.script_ram, glob_script_mem.script_size);
+ if (len_decompressed>0) glob_script_mem.script_ram[len_decompressed] = 0;
+
+ if (ucs) free(ucs);
+
+ }
+
+ // use rules storage for permanent vars
+ glob_script_mem.script_pram = (uint8_t*)Settings.rules[0];
+ glob_script_mem.script_pram_size = MAX_SCRIPT_SIZE;
+
+ glob_script_mem.FLAGS.fsys = true;
+ }
+#else // EEP_SCRIPT_SIZE
+
+ // default mode is compression
int32_t len_decompressed;
sprt = (char*)calloc(UNISHOXRSIZE + 8,1);
if (!sprt) { break; }
@@ -7674,11 +7433,14 @@ bool Xdrv10(uint8_t function)
if (len_decompressed>0) glob_script_mem.script_ram[len_decompressed] = 0;
// indicates scripter use compression
bitWrite(Settings.rule_once, 6, 1);
- //Script_AddLog_P(LOG_LEVEL_INFO, PSTR("decompressed script len %d"),len_decompressed);
-#else // USE_SCRIPT_COMPRESSION
- // indicates scripter does not use compression
- bitWrite(Settings.rule_once, 6, 0);
-#endif // USE_SCRIPT_COMPRESSION
+
+#endif
+
+#endif // UFILESYSTEM
+
+
+// indicates scripter enabled (use rules[][] as single array)
+ bitWrite(Settings.rule_once, 7, 1);
#ifdef USE_BUTTON_EVENT
for (uint32_t cnt = 0; cnt < MAX_KEYS; cnt++) {
@@ -7686,110 +7448,13 @@ bool Xdrv10(uint8_t function)
}
#endif //USE_BUTTON_EVENT
-#ifdef EEP_SCRIPT_SIZE
- if (EEP_INIT(EEP_SCRIPT_SIZE)) {
- // found 32kb eeprom,
- char *script;
-#if EEP_SCRIPT_SIZE==SPI_FLASH_SEC_SIZE
- script = (char*)calloc(EEP_SCRIPT_SIZE + 4, 1);
- if (!script) break;
- glob_script_mem.script_ram = script;
- glob_script_mem.script_size = EEP_SCRIPT_SIZE;
- EEP_READ(0, EEP_SCRIPT_SIZE, script);
- if (*script==0xff) {
- memset(script, EEP_SCRIPT_SIZE, 0);
- }
- script[EEP_SCRIPT_SIZE - 1] = 0;
-#else
- char *ucs;
- ucs = (char*)calloc(SPI_FLASH_SEC_SIZE + 4, 1);
- if (!ucs) break;
- EEP_READ(0, SPI_FLASH_SEC_SIZE, ucs);
- if (*ucs==0xff) {
- memset(ucs, SPI_FLASH_SEC_SIZE, 0);
- }
- ucs[SPI_FLASH_SEC_SIZE - 1] = 0;
-
- script = (char*)calloc(EEP_SCRIPT_SIZE + 4, 1);
- if (!script) break;
- glob_script_mem.script_ram = script;
- glob_script_mem.script_size = EEP_SCRIPT_SIZE;
-
- int32_t len_decompressed;
- len_decompressed = SCRIPT_DECOMPRESS(ucs, strlen(ucs), glob_script_mem.script_ram, glob_script_mem.script_size);
- if (len_decompressed>0) glob_script_mem.script_ram[len_decompressed] = 0;
-
- if (ucs) free(ucs);
-
-#endif
- // use rules storage for permanent vars
- glob_script_mem.script_pram = (uint8_t*)Settings.rules[0];
- glob_script_mem.script_pram_size = MAX_SCRIPT_SIZE;
-
- glob_script_mem.flags = 1;
+ // a valid script MUST start with >D
+ if (glob_script_mem.script_ram[0]!='>' && glob_script_mem.script_ram[1]!='D') {
+ // clr all
+ memset(glob_script_mem.script_ram, 0 ,glob_script_mem.script_size);
+ strcpy_P(glob_script_mem.script_ram, PSTR(">D\nscript error must start with >D"));
+ bitWrite(Settings.rule_enabled, 0, 0);
}
-#endif // EEP_SCRIPT_SIZE
-
-
-#ifdef USE_SCRIPT_FATFS
-
-#if USE_SCRIPT_FATFS>=0
- // fs on SD card
-#ifdef ESP32
- if (PinUsed(GPIO_SPI_MOSI) && PinUsed(GPIO_SPI_MISO) && PinUsed(GPIO_SPI_CLK)) {
- SPI.begin(Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), -1);
- }
-#endif // ESP32
- fsp = &SD;
- if (SD.begin(USE_SCRIPT_FATFS)) {
-#else
- // flash file system
-#ifdef ESP32
- fsp = &FFat;
- if (FFat.begin(true)) {
-#else
- // fs on flash
- fsp = &LittleFS;
- if (fsp->begin()) {
-#endif // ESP
-
-#endif // USE_SCRIPT_FATFS>=0
-
- Script_AddLog_P(LOG_LEVEL_INFO,PSTR("FATFS mount OK!"));
-
- //fsp->dateTimeCallback(dateTime);
- glob_script_mem.script_sd_found = 1;
- char *script;
- script = (char*)calloc(FAT_SCRIPT_SIZE + 4, 1);
- if (!script) break;
- glob_script_mem.script_ram = script;
- glob_script_mem.script_size = FAT_SCRIPT_SIZE;
- if (fsp->exists(FAT_SCRIPT_NAME)) {
- File file = fsp->open(FAT_SCRIPT_NAME, FILE_READ);
- file.read((uint8_t*)script, FAT_SCRIPT_SIZE);
- file.close();
- }
- script[FAT_SCRIPT_SIZE - 1] = 0;
- // use rules storage for permanent vars
- glob_script_mem.script_pram = (uint8_t*)Settings.rules[0];
- glob_script_mem.script_pram_size = MAX_SCRIPT_SIZE;
-
- glob_script_mem.flags = 1;
-
- } else {
- Script_AddLog_P(LOG_LEVEL_INFO,PSTR("FATFS mount failed!"));
- glob_script_mem.script_sd_found = 0;
- }
-#endif // USE_SCRIPT_FATFS
-
-
- // a valid script MUST start with >D
- if (glob_script_mem.script_ram[0]!='>' && glob_script_mem.script_ram[1]!='D') {
- // clr all
- memset(glob_script_mem.script_ram, 0 ,glob_script_mem.script_size);
- strcpy_P(glob_script_mem.script_ram, PSTR(">D\nscript error must start with >D"));
- bitWrite(Settings.rule_enabled, 0, 0);
- }
// assure permanent memory is 4 byte aligned
{ uint32_t ptr = (uint32_t)glob_script_mem.script_pram;
@@ -7800,6 +7465,7 @@ bool Xdrv10(uint8_t function)
}
if (bitRead(Settings.rule_enabled, 0)) Init_Scripter();
+
// break;
//case FUNC_INIT:
if (bitRead(Settings.rule_enabled, 0)) {
@@ -7863,12 +7529,6 @@ bool Xdrv10(uint8_t function)
Webserver->on("/ta",HTTP_POST, HandleScriptTextareaConfiguration);
Webserver->on("/exs", HTTP_POST,[]() { Webserver->sendHeader("Location","/exs");Webserver->send(303);}, script_upload_start);
Webserver->on("/exs", HTTP_GET, ScriptExecuteUploadSuccess);
-
-#ifdef USE_SCRIPT_FATFS
- Webserver->on("/u13", HTTP_POST,[]() { Webserver->sendHeader("Location","/u13");Webserver->send(303);}, script_upload);
- Webserver->on("/u13", HTTP_GET, ScriptFileUploadSuccess);
- Webserver->on("/upl", HTTP_GET, Script_FileUploadConfiguration);
-#endif //USE_SCRIPT_FATFS
break;
#endif // USE_WEBSERVER
case FUNC_SAVE_BEFORE_RESTART:
From b8ce02c0ada584f769688c3a80bf8686bff153a8 Mon Sep 17 00:00:00 2001
From: gemu2015
Date: Tue, 5 Jan 2021 16:39:16 +0100
Subject: [PATCH 3/5] update to ufilesystem
---
tasmota/xdrv_13_display.ino | 20 ++++++++++----------
tasmota/xdrv_42_i2s_audio.ino | 8 +++++---
2 files changed, 15 insertions(+), 13 deletions(-)
mode change 100644 => 100755 tasmota/xdrv_13_display.ino
diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino
old mode 100644
new mode 100755
index 3a1abe6d2..6e5e7a138
--- a/tasmota/xdrv_13_display.ino
+++ b/tasmota/xdrv_13_display.ino
@@ -497,7 +497,7 @@ void DisplayText(void)
cp += var;
linebuf[fill] = 0;
break;
-#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)
+#if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(UFILESYSTEM)
case 'P':
{ char *ep=strchr(cp,':');
if (ep) {
@@ -682,7 +682,7 @@ void DisplayText(void)
RedrawGraph(temp,temp1);
break;
}
-#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)
+#if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(UFILESYSTEM)
if (*cp=='s') {
cp++;
var=atoiv(cp,&temp);
@@ -1569,8 +1569,8 @@ char get_jpeg_size(unsigned char* data, unsigned int data_size, unsigned short *
#endif // JPEG_PICTS
#endif // ESP32
-#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT) && defined(USE_DISPLAY)
-extern FS *fsp;
+#if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(UFILESYSTEM)
+extern FS *ufsp;
#define XBUFF_LEN 128
void Draw_RGB_Bitmap(char *file,uint16_t xp, uint16_t yp, bool inverted ) {
if (!renderer) return;
@@ -1586,7 +1586,7 @@ void Draw_RGB_Bitmap(char *file,uint16_t xp, uint16_t yp, bool inverted ) {
if (!strcmp(estr,"rgb")) {
// special rgb format
- fp=fsp->open(file,FILE_READ);
+ fp=ufsp->open(file,FS_FILE_READ);
if (!fp) return;
uint16_t xsize;
fp.read((uint8_t*)&xsize,2);
@@ -1621,7 +1621,7 @@ void Draw_RGB_Bitmap(char *file,uint16_t xp, uint16_t yp, bool inverted ) {
// jpeg files on ESP32 with more memory
#ifdef ESP32
#ifdef JPEG_PICTS
- fp=fsp->open(file,FILE_READ);
+ fp=ufsp->open(file,FS_FILE_READ);
if (!fp) return;
uint32_t size = fp.size();
uint8_t *mem = (uint8_t *)special_malloc(size+4);
@@ -1914,7 +1914,7 @@ void DisplayCheckGraph() {
}
-#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)
+#if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(UFILESYSTEM)
#ifdef ESP32
#include
#endif
@@ -1925,8 +1925,8 @@ void Save_graph(uint8_t num, char *path) {
struct GRAPH *gp=graph[index];
if (!gp) return;
File fp;
- fsp->remove(path);
- fp=fsp->open(path,FILE_WRITE);
+ ufsp->remove(path);
+ fp=ufsp->open(path,FS_FILE_WRITE);
if (!fp) return;
char str[32];
sprintf_P(str,PSTR("%d\t%d\t%d\t"),gp->xcnt,gp->xs,gp->ys);
@@ -1951,7 +1951,7 @@ void Restore_graph(uint8_t num, char *path) {
struct GRAPH *gp=graph[index];
if (!gp) return;
File fp;
- fp=fsp->open(path,FILE_READ);
+ fp=ufsp->open(path,FS_FILE_READ);
if (!fp) return;
char vbuff[32];
char *cp=vbuff;
diff --git a/tasmota/xdrv_42_i2s_audio.ino b/tasmota/xdrv_42_i2s_audio.ino
index 1e468593b..576ba2380 100644
--- a/tasmota/xdrv_42_i2s_audio.ino
+++ b/tasmota/xdrv_42_i2s_audio.ino
@@ -69,6 +69,8 @@ AudioGeneratorMP3 *decoder = NULL;
void *mp3ram = NULL;
+extern FS *ufsp;
+
#ifdef ESP8266
const int preallocateBufferSize = 5*1024;
const int preallocateCodecSize = 29192; // MP3 codec max mem needed
@@ -391,7 +393,7 @@ static const uint8_t wavHTemplate[] PROGMEM = { // Hardcoded simple WAV header w
0x64, 0x61, 0x74, 0x61, 0xff, 0xff, 0xff, 0xff };
bool SaveWav(char *path, uint8_t *buff, uint32_t size) {
- File fwp = fsp->open(path, FILE_WRITE);
+ File fwp = ufsp->open(path, FILE_WRITE);
uint8_t wavHeader[sizeof(wavHTemplate)];
memcpy_P(wavHeader, wavHTemplate, sizeof(wavHTemplate));
@@ -552,7 +554,7 @@ void I2S_WR_Show(void) {
#ifdef ESP32
void Play_mp3(const char *path) {
-#if defined(USE_SCRIPT) && defined(USE_SCRIPT_FATFS)
+#if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(UFILESYSTEM)
if (decoder || mp3) return;
if (!out) return;
@@ -566,7 +568,7 @@ void Play_mp3(const char *path) {
I2S_Task = false;
}
- file = new AudioFileSourceFS(*fsp,path);
+ file = new AudioFileSourceFS(*ufsp,path);
id3 = new AudioFileSourceID3(file);
if (mp3ram) {
From 35ad7cfab61d8fcf5756098d56392c9ef22a8a19 Mon Sep 17 00:00:00 2001
From: gemu2015
Date: Tue, 5 Jan 2021 16:40:50 +0100
Subject: [PATCH 4/5] ufs update
---
tasmota/sendemail.ino | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/tasmota/sendemail.ino b/tasmota/sendemail.ino
index 467646487..6d075599b 100644
--- a/tasmota/sendemail.ino
+++ b/tasmota/sendemail.ino
@@ -389,7 +389,7 @@ void xsend_message_txt(char *msg) {
#ifdef DEBUG_EMAIL_PORT
AddLog_P(LOG_LEVEL_INFO, PSTR("%s"),msg);
#endif
-#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)
+#if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(UFILESYSTEM)
if (*msg=='@') {
msg++;
attach_File(msg);
@@ -415,9 +415,9 @@ void xsend_message_txt(char *msg) {
#endif
}
-#if defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)
+#if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(UFILESYSTEM)
#include
-extern FS *fsp;
+extern FS *ufsp;
void attach_File(char *path) {
g_client->print(F("--frontier\r\n"));
@@ -425,7 +425,7 @@ void attach_File(char *path) {
char buff[64];
char *cp = path;
while (*cp=='/') cp++;
- File file = fsp->open(path, "r");
+ File file = ufsp->open(path, "r");
if (file) {
sprintf_P(buff,PSTR("Content-Disposition: attachment; filename=\"%s\"\r\n\r\n"), cp);
g_client->write(buff);
@@ -717,6 +717,8 @@ uint16_t SendMail(char *buffer) {
//Set the storage types to read the attach files (SD is default)
//smtpData.setFileStorageType(MailClientStorageType::SPIFFS);
+
+/*
#ifdef USE_SCRIPT_FATFS
#if USE_SCRIPT_FATFS<0
smtpData.setFileStorageType(MailClientStorageType::FFat);
@@ -724,6 +726,9 @@ uint16_t SendMail(char *buffer) {
smtpData.setFileStorageType(MailClientStorageType::SD);
#endif
#endif
+*/
+
+smtpData.setFileStorageType(MailClientStorageType::Univ);
//smtpData.setSendCallback(sendCallback);
From 0414ab1bf21c2823c190cbaacc37e66f643c2752 Mon Sep 17 00:00:00 2001
From: gemu2015
Date: Tue, 5 Jan 2021 16:41:41 +0100
Subject: [PATCH 5/5] ufs update
---
lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp | 8 ++++++++
lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h | 1 +
2 files changed, 9 insertions(+)
diff --git a/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp b/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp
index 687661ac9..395c43028 100755
--- a/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp
+++ b/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.cpp
@@ -3723,6 +3723,8 @@ void IMAPData::setFetchUID(const String &fetchUID)
std::string().swap(tmp);
}
+extern FS *ufsp;
+
void IMAPData::setFileStorageType(uint8_t storageType)
{
_storageType = storageType;
@@ -3736,6 +3738,9 @@ void IMAPData::setFileStorageType(uint8_t storageType)
case MailClientStorageType::FFat:
fsp = &FFat;
break;
+ case MailClientStorageType::Univ:
+ fsp = ufsp;
+ break;
}
}
@@ -4766,6 +4771,9 @@ void SMTPData::setFileStorageType(uint8_t storageType)
case MailClientStorageType::FFat:
fsp = &FFat;
break;
+ case MailClientStorageType::Univ:
+ fsp = ufsp;
+ break;
}
}
diff --git a/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h b/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h
index b6a8da775..0b1f4496c 100755
--- a/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h
+++ b/lib/libesp32/ESP32-Mail-Client/src/ESP32_MailClient.h
@@ -92,6 +92,7 @@ struct MailClientStorageType
static const uint8_t SPIFFS = 0;
static const uint8_t SD = 1;
static const uint8_t FFat = 2;
+ static const uint8_t Univ = 3;
};
static const char ESP32_MAIL_STR_1[] PROGMEM = "Content-Type: multipart/mixed; boundary=\"";