From a187375c024e95b57f089d800b005008aadced4f Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 12 Mar 2022 12:19:10 +0100 Subject: [PATCH] Berry add `path.format(true)` --- .../berry/generate/be_fixed_tasmota_path.h | 9 +++++---- .../berry_tasmota/src/be_path_tasmota_lib.c | 15 +++++++++++++++ lib/libesp32/berry_tasmota/src/be_port.cpp | 10 ++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/libesp32/berry/generate/be_fixed_tasmota_path.h b/lib/libesp32/berry/generate/be_fixed_tasmota_path.h index 90ae43054..e1444209f 100644 --- a/lib/libesp32/berry/generate/be_fixed_tasmota_path.h +++ b/lib/libesp32/berry/generate/be_fixed_tasmota_path.h @@ -1,15 +1,16 @@ #include "be_constobj.h" static be_define_const_map_slots(m_libpath_map) { - { be_const_key(listdir, -1), be_const_func(m_path_listdir) }, - { be_const_key(last_modified, 2), be_const_func(m_path_last_modified) }, - { be_const_key(exists, 3), be_const_func(m_path_exists) }, + { be_const_key(listdir, 1), be_const_func(m_path_listdir) }, + { be_const_key(last_modified, -1), be_const_func(m_path_last_modified) }, + { be_const_key(format, -1), be_const_func(m_path_format) }, + { be_const_key(exists, -1), be_const_func(m_path_exists) }, { be_const_key(remove, -1), be_const_func(m_path_remove) }, }; static be_define_const_map( m_libpath_map, - 4 + 5 ); static be_define_const_module( diff --git a/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c b/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c index 0350edf12..4c60e36d8 100644 --- a/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_path_tasmota_lib.c @@ -59,12 +59,27 @@ static int m_path_remove(bvm *vm) be_return(vm); } +extern int be_format_fs(void); +static int m_path_format(bvm *vm) +{ + const char *path = NULL; + if (be_top(vm) >= 1 && be_isbool(vm, 1)) { + if (be_tobool(vm, 1)) { + be_pushbool(vm, be_format_fs()); + be_return(vm); + } + } + be_pushbool(vm, bfalse); + be_return(vm); +} + /* @const_object_info_begin module path (scope: global, file: tasmota_path) { exists, func(m_path_exists) last_modified, func(m_path_last_modified) listdir, func(m_path_listdir) remove, func(m_path_remove) + format, func(m_path_format) } @const_object_info_end */ #include "be_fixed_tasmota_path.h" diff --git a/lib/libesp32/berry_tasmota/src/be_port.cpp b/lib/libesp32/berry_tasmota/src/be_port.cpp index 4204c2171..871885252 100644 --- a/lib/libesp32/berry_tasmota/src/be_port.cpp +++ b/lib/libesp32/berry_tasmota/src/be_port.cpp @@ -18,6 +18,7 @@ // Local pointer for file managment #ifdef USE_UFILESYS #include + #include #include "ZipReadFS.h" extern FS *ffsp; FS zip_ufsp(ZipReadFSImplPtr(new ZipReadFSImpl(&ffsp))); @@ -344,6 +345,15 @@ int be_unlink(const char *filename) return 0; } +/* format file system - erase everything */ +extern "C" int be_format_fs(void) +{ +#ifdef USE_UFILESYS + return LittleFS.format(); +#endif // USE_UFILESYS + return 0; +} + #if BE_USE_FILE_SYSTEM #if defined(USE_FATFS) /* FatFs */