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
@@ -10,7 +10,7 @@ namespace tt::app {
|
||||
typedef std::unordered_map<std::string, const AppManifest*> AppManifestMap;
|
||||
|
||||
static AppManifestMap app_manifest_map;
|
||||
static Mutex hash_mutex(Mutex::TypeNormal);
|
||||
static Mutex hash_mutex(Mutex::Type::Normal);
|
||||
|
||||
void addApp(const AppManifest* manifest) {
|
||||
TT_LOG_I(TAG, "Registering manifest %s", manifest->id.c_str());
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace tt::app::alertdialog {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
void start(std::string title, std::string message, const std::vector<std::string>& buttonLabels) {
|
||||
void start(const std::string& title, const std::string& message, const std::vector<std::string>& buttonLabels) {
|
||||
std::string items_joined = string::join(buttonLabels, PARAMETER_ITEM_CONCATENATION_TOKEN);
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_MESSAGE, message);
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_BUTTON_LABELS, items_joined);
|
||||
service::loader::startApp(manifest.id, false, bundle);
|
||||
service::loader::startApp(manifest.id, bundle);
|
||||
}
|
||||
|
||||
int32_t getResultIndex(const Bundle& bundle) {
|
||||
|
||||
@@ -12,7 +12,13 @@
|
||||
*/
|
||||
namespace tt::app::alertdialog {
|
||||
|
||||
void start(std::string title, std::string message, const std::vector<std::string>& buttonLabels);
|
||||
/**
|
||||
* Show a dialog with the provided title, message and 0, 1 or more buttons.
|
||||
* @param[in] title the title to show in the toolbar
|
||||
* @param[in] message the message to display
|
||||
* @param[in] buttonLabels the buttons to show
|
||||
*/
|
||||
void start(const std::string& title, const std::string& message, const std::vector<std::string>& buttonLabels);
|
||||
|
||||
/**
|
||||
* Get the index of the button that the user selected.
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace tt::app::applist {
|
||||
|
||||
static void onAppPressed(lv_event_t* e) {
|
||||
const auto* manifest = static_cast<const AppManifest*>(lv_event_get_user_data(e));
|
||||
service::loader::startApp(manifest->id, false);
|
||||
service::loader::startApp(manifest->id);
|
||||
}
|
||||
|
||||
static void createAppWidget(const AppManifest* manifest, void* parent) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifdef ESP_TARGET
|
||||
|
||||
#include "app/crashdiagnostics/QrHelpers.h"
|
||||
#include "app/crashdiagnostics/QrUrl.h"
|
||||
#include "app/launcher/Launcher.h"
|
||||
#include "lvgl.h"
|
||||
#include "lvgl/Statusbar.h"
|
||||
#include "app/launcher/Launcher.h"
|
||||
#include "qrcode.h"
|
||||
#include "QrHelpers.h"
|
||||
#include "QrUrl.h"
|
||||
#include "service/loader/Loader.h"
|
||||
|
||||
#define TAG "crash_diagnostics"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "app/crashdiagnostics/QrHelpers.h"
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include "QrHelpers.h"
|
||||
|
||||
/**
|
||||
* Maps QR version (starting at a fictitious 0) to the usable byte size for L(ow) CRC checking QR.
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
bool getQrVersionForBinaryDataLength(size_t inLength, int& outVersion);
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef ESP_TARGET
|
||||
|
||||
#include "QrUrl.h"
|
||||
#include "app/crashdiagnostics/QrUrl.h"
|
||||
|
||||
#include "kernel/PanicHandler.h"
|
||||
#include "Log.h"
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string getUrlFromCrashData();
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -96,7 +96,7 @@ void Gpio::startTask(std::shared_ptr<Gpio> ptr) {
|
||||
lock();
|
||||
tt_assert(timer == nullptr);
|
||||
timer = std::make_unique<Timer>(
|
||||
Timer::TypePeriodic,
|
||||
Timer::Type::Periodic,
|
||||
&onTimer,
|
||||
ptr
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "I2cHelpers.h"
|
||||
#include "app/i2cscanner/I2cHelpers.h"
|
||||
#include "Tactility.h"
|
||||
#include "StringUtils.h"
|
||||
#include <iomanip>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace tt::app::i2cscanner {
|
||||
|
||||
std::string getAddressText(uint8_t address);
|
||||
|
||||
std::string getPortNamesForDropdown();
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "I2cScanner.h"
|
||||
#include "I2cScannerThread.h"
|
||||
#include "I2cHelpers.h"
|
||||
#include "app/i2cscanner/I2cScannerPrivate.h"
|
||||
#include "app/i2cscanner/I2cScannerThread.h"
|
||||
#include "app/i2cscanner/I2cHelpers.h"
|
||||
|
||||
#include "Assets.h"
|
||||
#include "Tactility.h"
|
||||
@@ -50,7 +50,7 @@ static void onSelectBus(lv_event_t* event) {
|
||||
TT_LOG_I(TAG, "Selected %ld", selected);
|
||||
}
|
||||
|
||||
static void onPressScan(lv_event_t* event) {
|
||||
static void onPressScan(TT_UNUSED lv_event_t* event) {
|
||||
auto data = optData();
|
||||
if (data != nullptr) {
|
||||
if (data->scanState == ScanStateScanning) {
|
||||
@@ -191,4 +191,8 @@ extern const AppManifest manifest = {
|
||||
.onHide = onHide
|
||||
};
|
||||
|
||||
void start() {
|
||||
service::loader::startApp(manifest.id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,28 +10,6 @@
|
||||
|
||||
namespace tt::app::i2cscanner {
|
||||
|
||||
#define TAG "i2cscanner"
|
||||
|
||||
enum ScanState {
|
||||
ScanStateInitial,
|
||||
ScanStateScanning,
|
||||
ScanStateStopped
|
||||
};
|
||||
|
||||
struct Data {
|
||||
// Core
|
||||
Mutex mutex = Mutex(Mutex::TypeRecursive);
|
||||
std::unique_ptr<Timer> scanTimer = nullptr;
|
||||
// State
|
||||
ScanState scanState;
|
||||
i2c_port_t port = I2C_NUM_0;
|
||||
std::vector<uint8_t> scannedAddresses;
|
||||
// Widgets
|
||||
lv_obj_t* scanButtonLabelWidget = nullptr;
|
||||
lv_obj_t* portDropdownWidget = nullptr;
|
||||
lv_obj_t* scanListWidget = nullptr;
|
||||
};
|
||||
|
||||
void onScanTimerFinished(std::shared_ptr<Data> data);
|
||||
void start();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "I2cScannerThread.h"
|
||||
#include "app/i2cscanner/I2cScannerThread.h"
|
||||
#include "lvgl.h"
|
||||
#include "service/loader/Loader.h"
|
||||
|
||||
@@ -100,7 +100,7 @@ void startScanning(std::shared_ptr<Data> data) {
|
||||
|
||||
data->scanState = ScanStateScanning;
|
||||
data->scanTimer = std::make_unique<Timer>(
|
||||
Timer::TypeOnce,
|
||||
Timer::Type::Once,
|
||||
onScanTimer,
|
||||
data
|
||||
);
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "I2cScanner.h"
|
||||
#include <memory>
|
||||
|
||||
namespace tt::app::i2cscanner {
|
||||
|
||||
bool hasScanTimer(std::shared_ptr<Data> data);
|
||||
void startScanning(std::shared_ptr<Data> data);
|
||||
void stopScanning(std::shared_ptr<Data> data);
|
||||
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
#include <TactilityCore.h>
|
||||
#include "ImageViewer.h"
|
||||
#include "lvgl.h"
|
||||
#include "lvgl/Style.h"
|
||||
#include "lvgl/Toolbar.h"
|
||||
#include "StringUtils.h"
|
||||
#include "service/loader/Loader.h"
|
||||
|
||||
namespace tt::app::imageviewer {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
#define TAG "image_viewer"
|
||||
#define IMAGE_VIEWER_FILE_ARGUMENT "file"
|
||||
|
||||
static void onShow(AppContext& app, lv_obj_t* parent) {
|
||||
auto wrapper = lv_obj_create(parent);
|
||||
@@ -57,4 +58,10 @@ extern const AppManifest manifest = {
|
||||
.onShow = onShow
|
||||
};
|
||||
|
||||
void start(const std::string& file) {
|
||||
auto parameters = std::make_shared<Bundle>();
|
||||
parameters->putString(IMAGE_VIEWER_FILE_ARGUMENT, file);
|
||||
service::loader::startApp(manifest.id, parameters);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#define IMAGE_VIEWER_FILE_ARGUMENT "file"
|
||||
namespace tt::app::imageviewer {
|
||||
|
||||
void start(const std::string& file);
|
||||
|
||||
};
|
||||
@@ -24,7 +24,7 @@ void start(const std::string& title, const std::string& message, const std::stri
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_MESSAGE, message);
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_PREFILLED, prefilled);
|
||||
service::loader::startApp(manifest.id, false, bundle);
|
||||
service::loader::startApp(manifest.id, bundle);
|
||||
}
|
||||
|
||||
std::string getResult(const Bundle& bundle) {
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
#include "Check.h"
|
||||
#include "lvgl.h"
|
||||
#include "service/loader/Loader.h"
|
||||
#include "Assets.h"
|
||||
|
||||
namespace tt::app::launcher {
|
||||
|
||||
static void onAppPressed(TT_UNUSED lv_event_t* e) {
|
||||
auto* appId = (const char*)lv_event_get_user_data(e);
|
||||
service::loader::startApp(appId, false);
|
||||
service::loader::startApp(appId);
|
||||
}
|
||||
|
||||
static lv_obj_t* createAppButton(lv_obj_t* parent, const char* title, const char* imageFile, const char* appId, int32_t buttonPaddingLeft) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <TactilityCore.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include "lvgl.h"
|
||||
@@ -13,12 +12,12 @@
|
||||
namespace tt::app::log {
|
||||
|
||||
struct LogAppData {
|
||||
LogLevel filterLevel = LogLevelInfo;
|
||||
LogLevel filterLevel = LogLevel::Info;
|
||||
lv_obj_t* labelWidget = nullptr;
|
||||
};
|
||||
|
||||
static bool shouldShowLog(LogLevel filterLevel, LogLevel logLevel) {
|
||||
if (filterLevel == LogLevelNone || logLevel == LogLevelNone) {
|
||||
if (filterLevel == LogLevel::None || logLevel == LogLevel::None) {
|
||||
return false;
|
||||
} else {
|
||||
return filterLevel >= logLevel;
|
||||
@@ -115,19 +114,19 @@ static void onResult(AppContext& app, Result result, const Bundle& bundle) {
|
||||
if (result == ResultOk) {
|
||||
switch (resultIndex) {
|
||||
case 0:
|
||||
data->filterLevel = LogLevelVerbose;
|
||||
data->filterLevel = LogLevel::Verbose;
|
||||
break;
|
||||
case 1:
|
||||
data->filterLevel = LogLevelDebug;
|
||||
data->filterLevel = LogLevel::Debug;
|
||||
break;
|
||||
case 2:
|
||||
data->filterLevel = LogLevelInfo;
|
||||
data->filterLevel = LogLevel::Info;
|
||||
break;
|
||||
case 3:
|
||||
data->filterLevel = LogLevelWarning;
|
||||
data->filterLevel = LogLevel::Warning;
|
||||
break;
|
||||
case 4:
|
||||
data->filterLevel = LogLevelError;
|
||||
data->filterLevel = LogLevel::Error;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -16,7 +16,7 @@ extern const AppManifest manifest;
|
||||
static void onTimer(TT_UNUSED std::shared_ptr<void> context);
|
||||
|
||||
struct Data {
|
||||
Timer update_timer = Timer(Timer::TypePeriodic, &onTimer, nullptr);
|
||||
Timer update_timer = Timer(Timer::Type::Periodic, &onTimer, nullptr);
|
||||
std::shared_ptr<tt::hal::Power> power = getConfiguration()->hardware->power();
|
||||
lv_obj_t* enable_label = nullptr;
|
||||
lv_obj_t* enable_switch = nullptr;
|
||||
@@ -39,7 +39,7 @@ std::shared_ptr<Data> _Nullable optData() {
|
||||
static void updateUi(std::shared_ptr<Data> data) {
|
||||
const char* charge_state;
|
||||
hal::Power::MetricData metric_data;
|
||||
if (data->power->getMetric(hal::Power::MetricType::IS_CHARGING, metric_data)) {
|
||||
if (data->power->getMetric(hal::Power::MetricType::IsCharging, metric_data)) {
|
||||
charge_state = metric_data.valueAsBool ? "yes" : "no";
|
||||
} else {
|
||||
charge_state = "N/A";
|
||||
@@ -47,7 +47,7 @@ static void updateUi(std::shared_ptr<Data> data) {
|
||||
|
||||
uint8_t charge_level;
|
||||
bool charge_level_scaled_set = false;
|
||||
if (data->power->getMetric(hal::Power::MetricType::CHARGE_LEVEL, metric_data)) {
|
||||
if (data->power->getMetric(hal::Power::MetricType::ChargeLevel, metric_data)) {
|
||||
charge_level = metric_data.valueAsUint8;
|
||||
charge_level_scaled_set = true;
|
||||
}
|
||||
@@ -57,14 +57,14 @@ static void updateUi(std::shared_ptr<Data> data) {
|
||||
|
||||
int32_t current;
|
||||
bool current_set = false;
|
||||
if (data->power->getMetric(hal::Power::MetricType::CURRENT, metric_data)) {
|
||||
if (data->power->getMetric(hal::Power::MetricType::Current, metric_data)) {
|
||||
current = metric_data.valueAsInt32;
|
||||
current_set = true;
|
||||
}
|
||||
|
||||
uint32_t battery_voltage;
|
||||
bool battery_voltage_set = false;
|
||||
if (data->power->getMetric(hal::Power::MetricType::BATTERY_VOLTAGE, metric_data)) {
|
||||
if (data->power->getMetric(hal::Power::MetricType::BatteryVoltage, metric_data)) {
|
||||
battery_voltage = metric_data.valueAsUint32;
|
||||
battery_voltage_set = true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#if TT_FEATURE_SCREENSHOT_ENABLED
|
||||
|
||||
#include "ScreenshotUi.h"
|
||||
#include "app/screenshot/ScreenshotUi.h"
|
||||
#include <memory>
|
||||
|
||||
namespace tt::app::screenshot {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#if TT_FEATURE_SCREENSHOT_ENABLED
|
||||
|
||||
#include "ScreenshotUi.h"
|
||||
#include "app/screenshot/ScreenshotUi.h"
|
||||
|
||||
#include "TactilityCore.h"
|
||||
#include "hal/SdCard.h"
|
||||
@@ -51,7 +51,7 @@ static void onTimerCallback(TT_UNUSED std::shared_ptr<void> context) {
|
||||
}
|
||||
|
||||
ScreenshotUi::ScreenshotUi() {
|
||||
updateTimer = std::make_unique<Timer>(Timer::TypePeriodic, onTimerCallback, nullptr);
|
||||
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, onTimerCallback, nullptr);
|
||||
}
|
||||
|
||||
ScreenshotUi::~ScreenshotUi() {
|
||||
@@ -146,7 +146,7 @@ void ScreenshotUi::createModeSettingWidgets(lv_obj_t* parent) {
|
||||
lv_obj_align_to(modeDropdown, mode_label, LV_ALIGN_OUT_RIGHT_MID, 8, 0);
|
||||
lv_obj_add_event_cb(modeDropdown, onModeSetCallback, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
service::screenshot::Mode mode = service->getMode();
|
||||
if (mode == service::screenshot::ScreenshotModeApps) {
|
||||
if (mode == service::screenshot::Mode::Apps) {
|
||||
lv_dropdown_set_selected(modeDropdown, 1);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ void ScreenshotUi::createFilePathWidgets(lv_obj_t* parent) {
|
||||
lv_obj_set_flex_grow(pathTextArea, 1);
|
||||
if (kernel::getPlatform() == kernel::PlatformEsp) {
|
||||
auto sdcard = tt::hal::getConfiguration()->sdcard;
|
||||
if (sdcard != nullptr && sdcard->getState() == hal::SdCard::StateMounted) {
|
||||
if (sdcard != nullptr && sdcard->getState() == hal::SdCard::State::Mounted) {
|
||||
lv_textarea_set_text(pathTextArea, "A:/sdcard");
|
||||
} else {
|
||||
lv_textarea_set_text(pathTextArea, "Error: no SD card");
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#include "Timer.h"
|
||||
#include "TactilityConfig.h"
|
||||
|
||||
#if TT_FEATURE_SCREENSHOT_ENABLED
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "app/AppContext.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
namespace tt::app::screenshot {
|
||||
|
||||
class ScreenshotUi {
|
||||
|
||||
lv_obj_t* modeDropdown = nullptr;
|
||||
lv_obj_t* pathTextArea = nullptr;
|
||||
lv_obj_t* startStopButtonLabel = nullptr;
|
||||
lv_obj_t* timerWrapper = nullptr;
|
||||
lv_obj_t* delayTextArea = nullptr;
|
||||
std::unique_ptr<Timer> updateTimer;
|
||||
|
||||
void createTimerSettingsWidgets(lv_obj_t* parent);
|
||||
void createModeSettingWidgets(lv_obj_t* parent);
|
||||
void createFilePathWidgets(lv_obj_t* parent);
|
||||
|
||||
void updateScreenshotMode();
|
||||
|
||||
public:
|
||||
|
||||
ScreenshotUi();
|
||||
~ScreenshotUi();
|
||||
|
||||
void createWidgets(const AppContext& app, lv_obj_t* parent);
|
||||
void onStartPressed();
|
||||
void onModeSet();
|
||||
void onTimerTick();
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
@@ -18,12 +18,12 @@ namespace tt::app::selectiondialog {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
void start(std::string title, const std::vector<std::string>& items) {
|
||||
void start(const std::string& title, const std::vector<std::string>& items) {
|
||||
std::string items_joined = string::join(items, PARAMETER_ITEM_CONCATENATION_TOKEN);
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
|
||||
bundle->putString(PARAMETER_BUNDLE_KEY_ITEMS, items_joined);
|
||||
service::loader::startApp(manifest.id, false, bundle);
|
||||
service::loader::startApp(manifest.id, bundle);
|
||||
}
|
||||
|
||||
int32_t getResultIndex(const Bundle& bundle) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
namespace tt::app::selectiondialog {
|
||||
|
||||
void start(std::string title, const std::vector<std::string>& items);
|
||||
void start(const std::string& title, const std::vector<std::string>& items);
|
||||
|
||||
/**
|
||||
* Get the index of the item that the user selected.
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
#include "lvgl/LabelUtils.h"
|
||||
#include "lvgl/Style.h"
|
||||
#include "lvgl/Toolbar.h"
|
||||
#include "service/loader/Loader.h"
|
||||
|
||||
#define TAG "text_viewer"
|
||||
#define TEXT_VIEWER_FILE_ARGUMENT "file"
|
||||
|
||||
namespace tt::app::textviewer {
|
||||
|
||||
@@ -45,4 +47,11 @@ extern const AppManifest manifest = {
|
||||
.onShow = onShow
|
||||
};
|
||||
|
||||
void start(const std::string& file) {
|
||||
auto parameters = std::make_shared<Bundle>();
|
||||
parameters->putString(TEXT_VIEWER_FILE_ARGUMENT, file);
|
||||
service::loader::startApp(manifest.id, parameters);
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#define TEXT_VIEWER_FILE_ARGUMENT "file"
|
||||
namespace tt::app::textviewer {
|
||||
|
||||
void start(const std::string&file);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "service/loader/Loader.h"
|
||||
#include "app/timezone/TimeZone.h"
|
||||
#include "Assets.h"
|
||||
#include "Tactility.h"
|
||||
#include "time/Time.h"
|
||||
#include "lvgl/LvglSync.h"
|
||||
|
||||
@@ -15,7 +14,7 @@ namespace tt::app::timedatesettings {
|
||||
extern const AppManifest manifest;
|
||||
|
||||
struct Data {
|
||||
Mutex mutex = Mutex(Mutex::TypeRecursive);
|
||||
Mutex mutex = Mutex(Mutex::Type::Recursive);
|
||||
lv_obj_t* regionLabelWidget = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ static void onShow(AppContext& app, lv_obj_t* parent) {
|
||||
|
||||
static void onStart(AppContext& app) {
|
||||
auto data = std::make_shared<Data>();
|
||||
data->updateTimer = std::make_unique<Timer>(Timer::TypeOnce, onUpdateTimer, data);
|
||||
data->updateTimer = std::make_unique<Timer>(Timer::Type::Once, onUpdateTimer, data);
|
||||
app.setData(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ const AppContext* _Nullable optWifiApSettingsApp() {
|
||||
void start(const std::string& ssid) {
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString("ssid", ssid);
|
||||
service::loader::startApp(manifest.id, false, bundle);
|
||||
service::loader::startApp(manifest.id, bundle);
|
||||
}
|
||||
|
||||
static void onPressForget(TT_UNUSED lv_event_t* event) {
|
||||
@@ -135,7 +135,7 @@ void onResult(TT_UNUSED AppContext& app, TT_UNUSED Result result, const Bundle&
|
||||
TT_LOG_I(TAG, "Removed SSID");
|
||||
|
||||
if (
|
||||
service::wifi::getRadioState() == service::wifi::WIFI_RADIO_CONNECTION_ACTIVE &&
|
||||
service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive &&
|
||||
service::wifi::getConnectionTarget() == ssid
|
||||
) {
|
||||
service::wifi::disconnect();
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "service/wifi/WifiSettings.h"
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
typedef void (*OnConnectSsid)(const service::wifi::settings::WifiApSettings* settings, bool store, void* context);
|
||||
|
||||
typedef struct {
|
||||
OnConnectSsid onConnectSsid;
|
||||
void* onConnectSsidContext;
|
||||
} Bindings;
|
||||
|
||||
} // namespace
|
||||
@@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define WIFI_CONNECT_PARAM_SSID "ssid" // String
|
||||
#define WIFI_CONNECT_PARAM_PASSWORD "password" // String
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "State.h"
|
||||
#include "app/wificonnect/State.h"
|
||||
#include "Check.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Mutex.h"
|
||||
#include "service/wifi/Wifi.h"
|
||||
#include "service/wifi/WifiSettings.h"
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
class State {
|
||||
Mutex lock;
|
||||
service::wifi::settings::WifiApSettings apSettings = {
|
||||
.ssid = { 0 },
|
||||
.password = { 0 },
|
||||
.auto_connect = false
|
||||
};
|
||||
bool connectionError = false;
|
||||
bool connecting = false;
|
||||
public:
|
||||
|
||||
void setConnectionError(bool error);
|
||||
bool hasConnectionError() const;
|
||||
|
||||
const service::wifi::settings::WifiApSettings& lockApSettings();
|
||||
void unlockApSettings();
|
||||
|
||||
void setApSettings(const service::wifi::settings::WifiApSettings* newSettings);
|
||||
|
||||
void setConnecting(bool isConnecting);
|
||||
bool isConnecting() const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "View.h"
|
||||
#include "State.h"
|
||||
#include "Parameters.h"
|
||||
#include "app/wificonnect/View.h"
|
||||
#include "app/wificonnect/WifiConnectPrivate.h"
|
||||
#include "WifiConnect.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
@@ -186,19 +185,19 @@ void View::init(AppContext& app, lv_obj_t* parent) {
|
||||
createBottomButtons(wrapper);
|
||||
|
||||
// Keyboard bindings
|
||||
service::gui::keyboardAddTextArea(ssid_textarea);
|
||||
service::gui::keyboardAddTextArea(password_textarea);
|
||||
service::gui::keyboardAddTextArea(ssid_textarea);
|
||||
service::gui::keyboardAddTextArea(password_textarea);
|
||||
|
||||
// Init from app parameters
|
||||
auto bundle = app.getParameters();
|
||||
if (bundle != nullptr) {
|
||||
std::string ssid;
|
||||
if (bundle->optString(WIFI_CONNECT_PARAM_SSID, ssid)) {
|
||||
if (optSsidParameter(bundle, ssid)) {
|
||||
lv_textarea_set_text(ssid_textarea, ssid.c_str());
|
||||
}
|
||||
|
||||
std::string password;
|
||||
if (bundle->optString(WIFI_CONNECT_PARAM_PASSWORD, password)) {
|
||||
if (optPasswordParameter(bundle, ssid)) {
|
||||
lv_textarea_set_text(password_textarea, password.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Bindings.h"
|
||||
#include "State.h"
|
||||
|
||||
#include "app/AppContext.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
class WifiConnect;
|
||||
|
||||
class View {
|
||||
|
||||
private:
|
||||
|
||||
Bindings* bindings;
|
||||
State* state;
|
||||
|
||||
public:
|
||||
|
||||
lv_obj_t* ssid_textarea = nullptr;
|
||||
lv_obj_t* ssid_error = nullptr;
|
||||
lv_obj_t* password_textarea = nullptr;
|
||||
lv_obj_t* password_error = nullptr;
|
||||
lv_obj_t* connect_button = nullptr;
|
||||
lv_obj_t* remember_switch = nullptr;
|
||||
lv_obj_t* connecting_spinner = nullptr;
|
||||
lv_obj_t* connection_error = nullptr;
|
||||
lv_group_t* group = nullptr;
|
||||
|
||||
View(Bindings* bindings, State* state) :
|
||||
bindings(bindings),
|
||||
state(state)
|
||||
{}
|
||||
|
||||
void init(AppContext& app, lv_obj_t* parent);
|
||||
void update();
|
||||
|
||||
void createBottomButtons(lv_obj_t* parent);
|
||||
void setLoading(bool loading);
|
||||
void resetErrors();
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "WifiConnect.h"
|
||||
#include "app/wificonnect/WifiConnectPrivate.h"
|
||||
|
||||
#include "app/AppContext.h"
|
||||
#include "TactilityCore.h"
|
||||
@@ -9,6 +9,8 @@
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
#define TAG "wifi_connect"
|
||||
#define WIFI_CONNECT_PARAM_SSID "ssid" // String
|
||||
#define WIFI_CONNECT_PARAM_PASSWORD "password" // String
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
@@ -23,18 +25,18 @@ std::shared_ptr<WifiConnect> _Nullable optWifiConnect() {
|
||||
}
|
||||
|
||||
static void eventCallback(const void* message, void* context) {
|
||||
auto* event = static_cast<const service::wifi::WifiEvent*>(message);
|
||||
auto* event = static_cast<const service::wifi::Event*>(message);
|
||||
auto* wifi = static_cast<WifiConnect*>(context);
|
||||
State& state = wifi->getState();
|
||||
switch (event->type) {
|
||||
case service::wifi::WifiEventTypeConnectionFailed:
|
||||
case service::wifi::EventType::ConnectionFailed:
|
||||
if (state.isConnecting()) {
|
||||
state.setConnecting(false);
|
||||
state.setConnectionError(true);
|
||||
wifi->requestViewUpdate();
|
||||
}
|
||||
break;
|
||||
case service::wifi::WifiEventTypeConnectionSuccess:
|
||||
case service::wifi::EventType::ConnectionSuccess:
|
||||
if (wifi->getState().isConnecting()) {
|
||||
state.setConnecting(false);
|
||||
service::loader::stopApp();
|
||||
@@ -123,10 +125,25 @@ extern const AppManifest manifest = {
|
||||
.id = "WifiConnect",
|
||||
.name = "Wi-Fi Connect",
|
||||
.icon = LV_SYMBOL_WIFI,
|
||||
.type = TypeSettings,
|
||||
.type = TypeHidden,
|
||||
.onStart = &onStart,
|
||||
.onShow = &onShow,
|
||||
.onHide = &onHide
|
||||
};
|
||||
|
||||
void start(const std::string& ssid, const std::string& password) {
|
||||
auto parameters = std::make_shared<Bundle>();
|
||||
parameters->putString(WIFI_CONNECT_PARAM_SSID, ssid);
|
||||
parameters->putString(WIFI_CONNECT_PARAM_PASSWORD, password);
|
||||
service::loader::startApp(manifest.id, parameters);
|
||||
}
|
||||
|
||||
bool optSsidParameter(const std::shared_ptr<const Bundle>& bundle, std::string& ssid) {
|
||||
return bundle->optString(WIFI_CONNECT_PARAM_SSID, ssid);
|
||||
}
|
||||
|
||||
bool optPasswordParameter(const std::shared_ptr<const Bundle>& bundle, std::string& password) {
|
||||
return bundle->optString(WIFI_CONNECT_PARAM_PASSWORD, password);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,48 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "Bindings.h"
|
||||
#include "State.h"
|
||||
#include "View.h"
|
||||
|
||||
#include "Mutex.h"
|
||||
#include "service/wifi/Wifi.h"
|
||||
#include <string>
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
class WifiConnect {
|
||||
Mutex mutex;
|
||||
State state;
|
||||
Bindings bindings = {
|
||||
.onConnectSsid = nullptr,
|
||||
.onConnectSsidContext = nullptr
|
||||
};
|
||||
View view = View(&bindings, &state);
|
||||
PubSubSubscription* wifiSubscription;
|
||||
bool view_enabled = false;
|
||||
|
||||
public:
|
||||
|
||||
WifiConnect();
|
||||
~WifiConnect();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent);
|
||||
void onHide(AppContext& app);
|
||||
|
||||
State& getState() { return state; }
|
||||
Bindings& getBindings() { return bindings; }
|
||||
View& getView() { return view; }
|
||||
|
||||
|
||||
void requestViewUpdate();
|
||||
};
|
||||
|
||||
void lock(WifiConnect* wifi);
|
||||
|
||||
void unlock(WifiConnect* wifi);
|
||||
|
||||
void view_update(WifiConnect* wifi);
|
||||
/**
|
||||
* Start the app with optional pre-filled fields.
|
||||
*/
|
||||
void start(const std::string& ssid = "", const std::string& password = "");
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace tt::app::wifimanage {
|
||||
|
||||
typedef void (*OnWifiToggled)(bool enable);
|
||||
typedef void (*OnConnectSsid)(const char* ssid);
|
||||
typedef void (*OnDisconnect)();
|
||||
typedef void (*OnShowApSettings)(const char* ssid);
|
||||
|
||||
struct Bindings{
|
||||
OnWifiToggled onWifiToggled;
|
||||
OnConnectSsid onConnectSsid;
|
||||
OnDisconnect onDisconnect;
|
||||
OnShowApSettings onShowApSettings;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <Check.h>
|
||||
#include "WifiManage.h"
|
||||
#include "app/wifimanage/WifiManagePrivate.h"
|
||||
|
||||
namespace tt::app::wifimanage {
|
||||
|
||||
@@ -10,16 +10,16 @@ void State::setScanning(bool isScanning) {
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
void State::setRadioState(service::wifi::WifiRadioState state) {
|
||||
void State::setRadioState(service::wifi::RadioState state) {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
radioState = state;
|
||||
if (radioState == service::wifi::WIFI_RADIO_OFF) {
|
||||
if (radioState == service::wifi::RadioState::Off) {
|
||||
scannedAfterRadioOn = false;
|
||||
}
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
service::wifi::WifiRadioState State::getRadioState() const {
|
||||
service::wifi::RadioState State::getRadioState() const {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
auto result = radioState;
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
@@ -33,7 +33,7 @@ bool State::isScanning() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::vector<service::wifi::WifiApRecord>& State::lockApRecords() const {
|
||||
const std::vector<service::wifi::ApRecord>& State::lockApRecords() const {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
return apRecords;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ void State::updateApRecords() {
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
void State::setConnectSsid(std::string ssid) {
|
||||
void State::setConnectSsid(const std::string& ssid) {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
connectSsid = ssid;
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "service/wifi/Wifi.h"
|
||||
#include "Mutex.h"
|
||||
|
||||
namespace tt::app::wifimanage {
|
||||
|
||||
/**
|
||||
* View's state
|
||||
*/
|
||||
class State {
|
||||
|
||||
Mutex mutex = Mutex(Mutex::TypeRecursive);
|
||||
bool scanning = false;
|
||||
bool scannedAfterRadioOn = false;
|
||||
service::wifi::WifiRadioState radioState;
|
||||
std::vector<service::wifi::WifiApRecord> apRecords;
|
||||
std::string connectSsid;
|
||||
|
||||
public:
|
||||
State() {}
|
||||
|
||||
void setScanning(bool isScanning);
|
||||
bool isScanning() const;
|
||||
|
||||
bool hasScannedAfterRadioOn() const { return scannedAfterRadioOn; }
|
||||
|
||||
void setRadioState(service::wifi::WifiRadioState state);
|
||||
service::wifi::WifiRadioState getRadioState() const;
|
||||
|
||||
void updateApRecords();
|
||||
|
||||
const std::vector<service::wifi::WifiApRecord>& lockApRecords() const;
|
||||
void unlockApRecords() const;
|
||||
|
||||
void setConnectSsid(std::string ssid);
|
||||
std::string getConnectSsid() const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "View.h"
|
||||
#include "WifiManage.h"
|
||||
#include "app/wifimanage/View.h"
|
||||
#include "app/wifimanage/WifiManagePrivate.h"
|
||||
|
||||
#include "Log.h"
|
||||
#include "service/wifi/Wifi.h"
|
||||
@@ -48,6 +48,11 @@ static void on_enable_on_boot_switch_changed(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void onConnectToHiddenClicked(lv_event_t* event) {
|
||||
auto* bindings = (Bindings*)lv_event_get_user_data(event);
|
||||
bindings->onConnectToHidden();
|
||||
}
|
||||
|
||||
// region Secondary updates
|
||||
|
||||
static void connect(lv_event_t* event) {
|
||||
@@ -73,7 +78,7 @@ static void showDetails(lv_event_t* event) {
|
||||
bindings->onShowApSettings(ssid);
|
||||
}
|
||||
|
||||
void View::createSsidListItem(const service::wifi::WifiApRecord& record, bool isConnecting) {
|
||||
void View::createSsidListItem(const service::wifi::ApRecord& record, bool isConnecting) {
|
||||
lv_obj_t* wrapper = lv_obj_create(networks_list);
|
||||
lv_obj_add_event_cb(wrapper, &connect, LV_EVENT_SHORT_CLICKED, bindings);
|
||||
lv_obj_set_user_data(wrapper, bindings);
|
||||
@@ -124,20 +129,36 @@ void View::createSsidListItem(const service::wifi::WifiApRecord& record, bool is
|
||||
}
|
||||
}
|
||||
|
||||
void View::updateConnectToHidden() {
|
||||
switch (state->getRadioState()) {
|
||||
case service::wifi::RadioState::On:
|
||||
case service::wifi::RadioState::ConnectionPending:
|
||||
case service::wifi::RadioState::ConnectionActive:
|
||||
lv_obj_remove_flag(connect_to_hidden, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
|
||||
case service::wifi::RadioState::OnPending:
|
||||
case service::wifi::RadioState::OffPending:
|
||||
case service::wifi::RadioState::Off:
|
||||
lv_obj_add_flag(connect_to_hidden, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void View::updateNetworkList() {
|
||||
lv_obj_clean(networks_list);
|
||||
|
||||
switch (state->getRadioState()) {
|
||||
case service::wifi::WIFI_RADIO_ON_PENDING:
|
||||
case service::wifi::WIFI_RADIO_ON:
|
||||
case service::wifi::WIFI_RADIO_CONNECTION_PENDING:
|
||||
case service::wifi::WIFI_RADIO_CONNECTION_ACTIVE: {
|
||||
case service::wifi::RadioState::OnPending:
|
||||
case service::wifi::RadioState::On:
|
||||
case service::wifi::RadioState::ConnectionPending:
|
||||
case service::wifi::RadioState::ConnectionActive: {
|
||||
|
||||
std::string connection_target = service::wifi::getConnectionTarget();
|
||||
auto& ap_records = state->lockApRecords();
|
||||
|
||||
bool is_connected = !connection_target.empty() &&
|
||||
state->getRadioState() == service::wifi::WIFI_RADIO_CONNECTION_ACTIVE;
|
||||
state->getRadioState() == service::wifi::RadioState::ConnectionActive;
|
||||
bool added_connected = false;
|
||||
if (is_connected) {
|
||||
if (!ap_records.empty()) {
|
||||
@@ -159,8 +180,8 @@ void View::updateNetworkList() {
|
||||
if (used_ssids.find(record.ssid) == used_ssids.end()) {
|
||||
bool connection_target_match = (record.ssid == connection_target);
|
||||
bool is_connecting = connection_target_match
|
||||
&& state->getRadioState() == service::wifi::WIFI_RADIO_CONNECTION_PENDING &&
|
||||
!connection_target.empty();
|
||||
&& state->getRadioState() == service::wifi::RadioState::ConnectionPending &&
|
||||
!connection_target.empty();
|
||||
bool skip = connection_target_match && added_connected;
|
||||
if (!skip) {
|
||||
createSsidListItem(record, is_connecting);
|
||||
@@ -180,8 +201,8 @@ void View::updateNetworkList() {
|
||||
state->unlockApRecords();
|
||||
break;
|
||||
}
|
||||
case service::wifi::WIFI_RADIO_OFF_PENDING:
|
||||
case service::wifi::WIFI_RADIO_OFF: {
|
||||
case service::wifi::RadioState::OffPending:
|
||||
case service::wifi::RadioState::Off: {
|
||||
lv_obj_add_flag(networks_list, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
}
|
||||
@@ -189,7 +210,7 @@ void View::updateNetworkList() {
|
||||
}
|
||||
|
||||
void View::updateScanning() {
|
||||
if (state->getRadioState() == service::wifi::WIFI_RADIO_ON && state->isScanning()) {
|
||||
if (state->getRadioState() == service::wifi::RadioState::On && state->isScanning()) {
|
||||
lv_obj_clear_flag(scanning_spinner, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_obj_add_flag(scanning_spinner, LV_OBJ_FLAG_HIDDEN);
|
||||
@@ -199,18 +220,18 @@ void View::updateScanning() {
|
||||
void View::updateWifiToggle() {
|
||||
lv_obj_clear_state(enable_switch, LV_STATE_ANY);
|
||||
switch (state->getRadioState()) {
|
||||
case service::wifi::WIFI_RADIO_ON:
|
||||
case service::wifi::WIFI_RADIO_CONNECTION_PENDING:
|
||||
case service::wifi::WIFI_RADIO_CONNECTION_ACTIVE:
|
||||
case service::wifi::RadioState::On:
|
||||
case service::wifi::RadioState::ConnectionPending:
|
||||
case service::wifi::RadioState::ConnectionActive:
|
||||
lv_obj_add_state(enable_switch, LV_STATE_CHECKED);
|
||||
break;
|
||||
case service::wifi::WIFI_RADIO_ON_PENDING:
|
||||
case service::wifi::RadioState::OnPending:
|
||||
lv_obj_add_state(enable_switch, LV_STATE_CHECKED | LV_STATE_DISABLED);
|
||||
break;
|
||||
case service::wifi::WIFI_RADIO_OFF:
|
||||
case service::wifi::RadioState::Off:
|
||||
lv_obj_remove_state(enable_switch, LV_STATE_CHECKED | LV_STATE_DISABLED);
|
||||
break;
|
||||
case service::wifi::WIFI_RADIO_OFF_PENDING:
|
||||
case service::wifi::RadioState::OffPending:
|
||||
lv_obj_remove_state(enable_switch, LV_STATE_CHECKED);
|
||||
lv_obj_add_state(enable_switch, LV_STATE_DISABLED);
|
||||
break;
|
||||
@@ -233,7 +254,7 @@ void View::updateEnableOnBootToggle() {
|
||||
void View::init(const AppContext& app, lv_obj_t* parent) {
|
||||
root = parent;
|
||||
|
||||
paths = std::move(app.getPaths());
|
||||
paths = app.getPaths();
|
||||
|
||||
// Toolbar
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
@@ -279,6 +300,14 @@ void View::init(const AppContext& app, lv_obj_t* parent) {
|
||||
lv_obj_set_style_pad_top(networks_list, 0, 0);
|
||||
lv_obj_set_style_pad_bottom(networks_list, 0, 0);
|
||||
lv_obj_align(networks_list, LV_ALIGN_TOP_LEFT, 0, 44);
|
||||
|
||||
connect_to_hidden = lv_button_create(secondary_flex);
|
||||
lv_obj_set_width(connect_to_hidden, LV_PCT(100));
|
||||
lv_obj_set_style_margin_bottom(connect_to_hidden, 8, 0);
|
||||
lv_obj_set_style_margin_hor(connect_to_hidden, 12, 0);
|
||||
lv_obj_add_event_cb(connect_to_hidden, onConnectToHiddenClicked, LV_EVENT_SHORT_CLICKED, bindings);
|
||||
auto* connect_to_hidden_label = lv_label_create(connect_to_hidden);
|
||||
lv_label_set_text(connect_to_hidden_label, "Connect to hidden SSID");
|
||||
}
|
||||
|
||||
void View::update() {
|
||||
@@ -286,6 +315,7 @@ void View::update() {
|
||||
updateEnableOnBootToggle();
|
||||
updateScanning();
|
||||
updateNetworkList();
|
||||
updateConnectToHidden();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/AppContext.h"
|
||||
#include "Bindings.h"
|
||||
#include "State.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
namespace tt::app::wifimanage {
|
||||
|
||||
class View {
|
||||
|
||||
private:
|
||||
|
||||
Bindings* bindings;
|
||||
State* state;
|
||||
std::unique_ptr<app::Paths> paths;
|
||||
lv_obj_t* root = nullptr;
|
||||
lv_obj_t* enable_switch = nullptr;
|
||||
lv_obj_t* enable_on_boot_switch = nullptr;
|
||||
lv_obj_t* scanning_spinner = nullptr;
|
||||
lv_obj_t* networks_list = nullptr;
|
||||
|
||||
void updateWifiToggle();
|
||||
void updateEnableOnBootToggle();
|
||||
void updateScanning();
|
||||
void updateNetworkList();
|
||||
void createSsidListItem(const service::wifi::WifiApRecord& record, bool isConnecting);
|
||||
|
||||
public:
|
||||
|
||||
View(Bindings* bindings, State* state) : bindings(bindings), state(state) {}
|
||||
|
||||
void init(const AppContext& app, lv_obj_t* parent);
|
||||
void update();
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "WifiManage.h"
|
||||
#include "View.h"
|
||||
#include "State.h"
|
||||
#include "app/wifimanage/WifiManagePrivate.h"
|
||||
#include "app/wifimanage/View.h"
|
||||
#include "app/wifimanage/State.h"
|
||||
|
||||
#include "app/AppContext.h"
|
||||
#include "app/wificonnect/Parameters.h"
|
||||
#include "app/wifiapsettings/WifiApSettings.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "service/loader/Loader.h"
|
||||
#include "service/wifi/WifiSettings.h"
|
||||
#include "lvgl/LvglSync.h"
|
||||
#include "app/wificonnect/WifiConnect.h"
|
||||
|
||||
namespace tt::app::wifimanage {
|
||||
|
||||
@@ -33,10 +33,7 @@ static void onConnect(const char* ssid) {
|
||||
service::wifi::connect(&settings, false);
|
||||
} else {
|
||||
TT_LOG_I(TAG, "Starting connection dialog");
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString(WIFI_CONNECT_PARAM_SSID, ssid);
|
||||
bundle->putString(WIFI_CONNECT_PARAM_PASSWORD, "");
|
||||
service::loader::startApp("WifiConnect", false, bundle);
|
||||
wificonnect::start(ssid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,12 +49,17 @@ static void onWifiToggled(bool enabled) {
|
||||
service::wifi::setEnabled(enabled);
|
||||
}
|
||||
|
||||
static void onConnectToHidden() {
|
||||
wificonnect::start();
|
||||
}
|
||||
|
||||
WifiManage::WifiManage() {
|
||||
bindings = (Bindings) {
|
||||
.onWifiToggled = onWifiToggled,
|
||||
.onConnectSsid = onConnect,
|
||||
.onDisconnect = onDisconnect,
|
||||
.onShowApSettings = onShowApSettings
|
||||
.onShowApSettings = onShowApSettings,
|
||||
.onConnectToHidden = onConnectToHidden
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,19 +85,20 @@ void WifiManage::requestViewUpdate() {
|
||||
}
|
||||
|
||||
static void wifiManageEventCallback(const void* message, void* context) {
|
||||
auto* event = (service::wifi::WifiEvent*)message;
|
||||
auto* event = (service::wifi::Event*)message;
|
||||
auto* wifi = (WifiManage*)context;
|
||||
TT_LOG_I(TAG, "Update with state %d", service::wifi::getRadioState());
|
||||
wifi->getState().setRadioState(service::wifi::getRadioState());
|
||||
auto radio_state = service::wifi::getRadioState();
|
||||
TT_LOG_I(TAG, "Update with state %s", service::wifi::radioStateToString(radio_state));
|
||||
wifi->getState().setRadioState(radio_state);
|
||||
switch (event->type) {
|
||||
case tt::service::wifi::WifiEventTypeScanStarted:
|
||||
case tt::service::wifi::EventType::ScanStarted:
|
||||
wifi->getState().setScanning(true);
|
||||
break;
|
||||
case tt::service::wifi::WifiEventTypeScanFinished:
|
||||
case tt::service::wifi::EventType::ScanFinished:
|
||||
wifi->getState().setScanning(false);
|
||||
wifi->getState().updateApRecords();
|
||||
break;
|
||||
case tt::service::wifi::WifiEventTypeRadioStateOn:
|
||||
case tt::service::wifi::EventType::RadioStateOn:
|
||||
if (!service::wifi::isScanning()) {
|
||||
service::wifi::scan();
|
||||
}
|
||||
@@ -124,11 +127,11 @@ void WifiManage::onShow(AppContext& app, lv_obj_t* parent) {
|
||||
view.update();
|
||||
unlock();
|
||||
|
||||
service::wifi::WifiRadioState radio_state = service::wifi::getRadioState();
|
||||
bool can_scan = radio_state == service::wifi::WIFI_RADIO_ON ||
|
||||
radio_state == service::wifi::WIFI_RADIO_CONNECTION_PENDING ||
|
||||
radio_state == service::wifi::WIFI_RADIO_CONNECTION_ACTIVE;
|
||||
TT_LOG_I(TAG, "%d %d", radio_state, service::wifi::isScanning());
|
||||
service::wifi::RadioState radio_state = service::wifi::getRadioState();
|
||||
bool can_scan = radio_state == service::wifi::RadioState::On ||
|
||||
radio_state == service::wifi::RadioState::ConnectionPending ||
|
||||
radio_state == service::wifi::RadioState::ConnectionActive;
|
||||
TT_LOG_I(TAG, "%s %d", service::wifi::radioStateToString(radio_state), (int)service::wifi::isScanning());
|
||||
if (can_scan && !service::wifi::isScanning()) {
|
||||
service::wifi::scan();
|
||||
}
|
||||
@@ -172,4 +175,8 @@ extern const AppManifest manifest = {
|
||||
.onHide = onHide
|
||||
};
|
||||
|
||||
void start() {
|
||||
service::loader::startApp(manifest.id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,35 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "Mutex.h"
|
||||
#include "View.h"
|
||||
#include "State.h"
|
||||
#include "app/wifimanage/View.h"
|
||||
#include "app/wifimanage/State.h"
|
||||
#include "service/wifi/Wifi.h"
|
||||
|
||||
namespace tt::app::wifimanage {
|
||||
|
||||
class WifiManage {
|
||||
|
||||
PubSubSubscription* wifiSubscription = nullptr;
|
||||
Mutex mutex;
|
||||
Bindings bindings = { };
|
||||
State state;
|
||||
View view = View(&bindings, &state);
|
||||
bool isViewEnabled = false;
|
||||
|
||||
public:
|
||||
|
||||
WifiManage();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent);
|
||||
void onHide(AppContext& app);
|
||||
|
||||
Bindings& getBindings() { return bindings; }
|
||||
State& getState() { return state; }
|
||||
|
||||
void requestViewUpdate();
|
||||
};
|
||||
void start();
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user