Merge develop into main (#167)
- WiFi Connect app is now hidden by default, but accessible at the bottom of the WiFi Manage app when WiFi is turned on. - WiFi service now turns on WiFi when calling connect() and WiFi is not on. - Removed `blocking` option for `service::loader::startApp()`. This feature was unused and complex. - Various apps: Moved private headers into Private/ folder. - Various apps: created start() function for easy starting. - Added documentation to all TactilityC APIs - Refactored various `enum` into `class enum` - Refactor M5Stack `initBoot()` (but VBus is still 0V for some reason)
This commit is contained in:
committed by
GitHub
parent
3ca0f8cf97
commit
3ea02d912f
@@ -1,4 +1,5 @@
|
||||
#include "FileUtils.h"
|
||||
#include "app/files/FileUtils.h"
|
||||
|
||||
#include "TactilityCore.h"
|
||||
#include <cstring>
|
||||
#include <StringUtils.h>
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <dirent.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tt::app::files {
|
||||
|
||||
/** File types for `dirent`'s `d_type`. */
|
||||
enum {
|
||||
TT_DT_UNKNOWN = 0,
|
||||
#define TT_DT_UNKNOWN TT_DT_UNKNOWN // Unknown type
|
||||
TT_DT_FIFO = 1,
|
||||
#define TT_DT_FIFO TT_DT_FIFO // Named pipe or FIFO
|
||||
TT_DT_CHR = 2,
|
||||
#define TT_DT_CHR TT_DT_CHR // Character device
|
||||
TT_DT_DIR = 4,
|
||||
#define TT_DT_DIR TT_DT_DIR // Directory
|
||||
TT_DT_BLK = 6,
|
||||
#define TT_DT_BLK TT_DT_BLK // Block device
|
||||
TT_DT_REG = 8,
|
||||
#define TT_DT_REG TT_DT_REG // Regular file
|
||||
TT_DT_LNK = 10,
|
||||
#define TT_DT_LNK TT_DT_LNK // Symbolic link
|
||||
TT_DT_SOCK = 12,
|
||||
#define TT_DT_SOCK TT_DT_SOCK // Local-domain socket
|
||||
TT_DT_WHT = 14
|
||||
#define TT_DT_WHT TT_DT_WHT // Whiteout inodes
|
||||
};
|
||||
|
||||
std::string getChildPath(const std::string& basePath, const std::string& childPath);
|
||||
|
||||
typedef int (*ScandirFilter)(const struct dirent*);
|
||||
|
||||
typedef bool (*ScandirSort)(const struct dirent&, const struct dirent&);
|
||||
|
||||
bool dirent_sort_alpha_and_type(const struct dirent& left, const struct dirent& right);
|
||||
|
||||
int dirent_filter_dot_entries(const struct dirent* entry);
|
||||
|
||||
/**
|
||||
* A scandir()-like implementation that works on ESP32.
|
||||
* It does not return "." and ".." items but otherwise functions the same.
|
||||
* It returns an allocated output array with allocated dirent instances.
|
||||
* The caller is responsible for free-ing the memory of these.
|
||||
*
|
||||
* @param[in] path path the scan for files and directories
|
||||
* @param[out] outList a pointer to vector of dirent
|
||||
* @param[in] filter an optional filter to filter out specific items
|
||||
* @param[in] sort an optional sorting function
|
||||
* @return the amount of items that were stored in "output" or -1 when an error occurred
|
||||
*/
|
||||
int scandir(
|
||||
const std::string& path,
|
||||
std::vector<dirent>& outList,
|
||||
ScandirFilter _Nullable filter,
|
||||
ScandirSort _Nullable sort
|
||||
);
|
||||
|
||||
bool isSupportedExecutableFile(const std::string& filename);
|
||||
bool isSupportedImageFile(const std::string& filename);
|
||||
bool isSupportedTextFile(const std::string& filename);
|
||||
|
||||
} // namespace
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "Files.h"
|
||||
#include "app/files/FilesPrivate.h"
|
||||
|
||||
#include "app/AppContext.h"
|
||||
#include "Assets.h"
|
||||
#include "service/loader/Loader.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -37,4 +39,8 @@ extern const AppManifest manifest = {
|
||||
.onResult = onResult
|
||||
};
|
||||
|
||||
void start() {
|
||||
service::loader::startApp(manifest.id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,24 +10,6 @@
|
||||
|
||||
namespace tt::app::files {
|
||||
|
||||
class Files {
|
||||
std::unique_ptr<View> view;
|
||||
std::shared_ptr<State> state;
|
||||
|
||||
public:
|
||||
Files() {
|
||||
state = std::make_shared<State>();
|
||||
view = std::make_unique<View>(state);
|
||||
}
|
||||
|
||||
void onShow(lv_obj_t* parent) {
|
||||
view->init(parent);
|
||||
}
|
||||
|
||||
void onResult(Result result, const Bundle& bundle) {
|
||||
view->onResult(result, bundle);
|
||||
}
|
||||
};
|
||||
|
||||
void start();
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "State.h"
|
||||
#include "app/files/State.h"
|
||||
#include "app/files/FileUtils.h"
|
||||
|
||||
#include "kernel/Kernel.h"
|
||||
#include "Log.h"
|
||||
#include "FileUtils.h"
|
||||
#include "Partitions.h"
|
||||
#include "hal/SdCard.h"
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <dirent.h>
|
||||
#include "Mutex.h"
|
||||
|
||||
namespace tt::app::files {
|
||||
|
||||
class State {
|
||||
|
||||
public:
|
||||
|
||||
enum PendingAction {
|
||||
ActionNone,
|
||||
ActionDelete,
|
||||
ActionRename
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Mutex mutex = Mutex(Mutex::TypeRecursive);
|
||||
std::vector<dirent> dir_entries;
|
||||
std::string current_path;
|
||||
std::string selected_child_entry;
|
||||
PendingAction action = ActionNone;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
State();
|
||||
|
||||
void freeEntries() {
|
||||
dir_entries.clear();
|
||||
}
|
||||
|
||||
~State() {
|
||||
freeEntries();
|
||||
}
|
||||
|
||||
bool setEntriesForChildPath(const std::string& child_path);
|
||||
bool setEntriesForPath(const std::string& path);
|
||||
|
||||
const std::vector<dirent>& lockEntries() const {
|
||||
mutex.lock(TtWaitForever);
|
||||
return dir_entries;
|
||||
}
|
||||
|
||||
void unlockEntries() {
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
bool getDirent(uint32_t index, dirent& dirent);
|
||||
|
||||
void setSelectedChildEntry(const std::string& newFile) {
|
||||
selected_child_entry = newFile;
|
||||
action = ActionNone;
|
||||
}
|
||||
|
||||
std::string getSelectedChildEntry() const { return selected_child_entry; }
|
||||
std::string getCurrentPath() const { return current_path; }
|
||||
|
||||
std::string getSelectedChildPath() const;
|
||||
|
||||
PendingAction getPendingAction() const {
|
||||
return action;
|
||||
}
|
||||
|
||||
void setPendingAction(PendingAction newAction) {
|
||||
action = newAction;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
#include "app/files/FileUtils.h"
|
||||
#include "app/files/View.h"
|
||||
|
||||
#include "app/alertdialog/AlertDialog.h"
|
||||
#include "app/imageviewer/ImageViewer.h"
|
||||
#include "app/inputdialog/InputDialog.h"
|
||||
@@ -6,9 +9,7 @@
|
||||
#include "lvgl/Toolbar.h"
|
||||
#include "lvgl/LvglSync.h"
|
||||
#include "service/loader/Loader.h"
|
||||
#include "FileUtils.h"
|
||||
#include "Tactility.h"
|
||||
#include "View.h"
|
||||
#include "StringUtils.h"
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
@@ -83,18 +84,14 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
||||
app::startElfApp(processed_filepath);
|
||||
#endif
|
||||
} else if (isSupportedImageFile(filename)) {
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString(IMAGE_VIEWER_FILE_ARGUMENT, processed_filepath);
|
||||
service::loader::startApp("ImageViewer", false, bundle);
|
||||
app::imageviewer::start(processed_filepath);
|
||||
} else if (isSupportedTextFile(filename)) {
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
if (kernel::getPlatform() == kernel::PlatformEsp) {
|
||||
bundle->putString(TEXT_VIEWER_FILE_ARGUMENT, processed_filepath);
|
||||
app::textviewer::start(processed_filepath);
|
||||
} else {
|
||||
// Remove forward slash, because we need a relative path
|
||||
bundle->putString(TEXT_VIEWER_FILE_ARGUMENT, processed_filepath.substr(1));
|
||||
app::textviewer::start(processed_filepath.substr(1));
|
||||
}
|
||||
service::loader::startApp("TextViewer", false, bundle);
|
||||
} else {
|
||||
TT_LOG_W(TAG, "opening files of this type is not supported");
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "State.h"
|
||||
#include "app/AppManifest.h"
|
||||
#include <lvgl.h>
|
||||
#include <memory>
|
||||
|
||||
namespace tt::app::files {
|
||||
|
||||
class View {
|
||||
std::shared_ptr<State> state;
|
||||
|
||||
lv_obj_t* dir_entry_list = nullptr;
|
||||
lv_obj_t* action_list = nullptr;
|
||||
lv_obj_t* navigate_up_button = nullptr;
|
||||
|
||||
void showActionsForDirectory();
|
||||
void showActionsForFile();
|
||||
|
||||
void viewFile(const std::string&path, const std::string&filename);
|
||||
void createDirEntryWidget(lv_obj_t* parent, struct dirent& dir_entry);
|
||||
void onNavigate();
|
||||
|
||||
public:
|
||||
|
||||
explicit View(const std::shared_ptr<State>& state) : state(state) {}
|
||||
|
||||
void init(lv_obj_t* parent);
|
||||
void update();
|
||||
|
||||
void onNavigateUpPressed();
|
||||
void onDirEntryPressed(uint32_t index);
|
||||
void onDirEntryLongPressed(int32_t index);
|
||||
void onRenamePressed();
|
||||
void onDeletePressed();
|
||||
void onDirEntryListScrollBegin();
|
||||
void onResult(Result result, const Bundle& bundle);
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user