GPS refactored (#262)
- Refactored GPS service and HAL: GPS is no longer part of the HAL configuration. You can now add configure new GPS devices from the GPS settings app. - T-Deck adds a boot hook to check if a GPS configuration exists and adds it when the config is empty. - Implemented the concept of ObjectFile to read/write arrays of a raw data type (e.g. struct) to disk. - Implemented more file utils (e.g. to create all directories of a path)
This commit is contained in:
committed by
GitHub
parent
81ece6f2e7
commit
d0ca3b16f8
@@ -30,6 +30,7 @@ namespace service {
|
||||
// region Default apps
|
||||
|
||||
namespace app {
|
||||
namespace addgps { extern const AppManifest manifest; }
|
||||
namespace alertdialog { extern const AppManifest manifest; }
|
||||
namespace applist { extern const AppManifest manifest; }
|
||||
namespace chat { extern const AppManifest manifest; }
|
||||
@@ -70,6 +71,7 @@ namespace app {
|
||||
// endregion
|
||||
|
||||
static void registerSystemApps() {
|
||||
addApp(app::addgps::manifest);
|
||||
addApp(app::alertdialog::manifest);
|
||||
addApp(app::applist::manifest);
|
||||
addApp(app::display::manifest);
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
#include "Tactility/StringUtils.h"
|
||||
#include "Tactility/app/AppManifest.h"
|
||||
#include "Tactility/app/alertdialog/AlertDialog.h"
|
||||
#include "Tactility/hal/gps/GpsDevice.h"
|
||||
#include "Tactility/hal/uart/Uart.h"
|
||||
#include "Tactility/lvgl/Style.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/service/gps/GpsService.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::app::addgps {
|
||||
|
||||
constexpr const char* TAG = "AddGps";
|
||||
|
||||
class AddGpsApp final : public App {
|
||||
|
||||
private:
|
||||
|
||||
lv_obj_t* uartDropdown = nullptr;
|
||||
lv_obj_t* modelDropdown = nullptr;
|
||||
lv_obj_t* baudDropdown = nullptr;
|
||||
|
||||
// Store as string instead of int, so app startup doesn't require parsing all entries.
|
||||
// We only need to parse back to int when adding the new GPS entry
|
||||
std::array<uint32_t, 6> baudRates = { 9600, 19200, 28800, 38400, 57600, 115200 };
|
||||
const char* baudRatesDropdownValues = "9600\n19200\n28800\n38400\n57600\n115200";
|
||||
|
||||
static void onAddGpsCallback(lv_event_t* event) {
|
||||
auto* app = (AddGpsApp*)lv_event_get_user_data(event);
|
||||
app->onAddGps();
|
||||
}
|
||||
|
||||
void onAddGps() {
|
||||
auto selected_baud_index = lv_dropdown_get_selected(baudDropdown);
|
||||
|
||||
auto new_configuration = hal::gps::GpsConfiguration {
|
||||
.uartName = { 0x00 },
|
||||
.baudRate = baudRates[selected_baud_index],
|
||||
// Warning: This assumes that the enum is a regularly indexed one that starts at 0
|
||||
.model = (hal::gps::GpsModel)lv_dropdown_get_selected(modelDropdown)
|
||||
};
|
||||
|
||||
lv_dropdown_get_selected_str(uartDropdown, new_configuration.uartName, sizeof(new_configuration.uartName));
|
||||
if (new_configuration.uartName[0] == 0x00) {
|
||||
alertdialog::start("Error", "You must select a bus/uart.");
|
||||
return;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Saving: uart=%s, model=%lu, baud=%lu", new_configuration.uartName, (uint32_t)new_configuration.model, new_configuration.baudRate);
|
||||
|
||||
auto service = service::gps::findGpsService();
|
||||
std::vector<tt::hal::gps::GpsConfiguration> configurations;
|
||||
if (service != nullptr) {
|
||||
service->getGpsConfigurations(configurations);
|
||||
for (auto& stored_configuration: configurations) {
|
||||
if (strcmp(stored_configuration.uartName, new_configuration.uartName) == 0) {
|
||||
auto message = std::string("Bus \"{}\" is already in use in another configuration", (const char*)new_configuration.uartName);
|
||||
app::alertdialog::start("Error", message.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!service->addGpsConfiguration(new_configuration)) {
|
||||
app::alertdialog::start("Error", "Failed to add configuration");
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) final {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
auto* main_wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_width(main_wrapper, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(main_wrapper, 1);
|
||||
lv_obj_set_flex_flow(main_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_all(main_wrapper, 0, 0);
|
||||
lv_obj_set_style_border_width(main_wrapper, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(main_wrapper);
|
||||
|
||||
// region Uart
|
||||
|
||||
auto* uart_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(uart_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_ver(uart_wrapper, 0, 0);
|
||||
lv_obj_set_style_border_width(uart_wrapper, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(uart_wrapper);
|
||||
|
||||
uartDropdown = lv_dropdown_create(uart_wrapper);
|
||||
|
||||
auto uart_names = hal::uart::getNames();
|
||||
uart_names.insert(uart_names.begin(), "");
|
||||
auto uart_options = string::join(uart_names, "\n");
|
||||
lv_dropdown_set_options(uartDropdown, uart_options.c_str());
|
||||
lv_obj_align(uartDropdown, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
lv_obj_set_width(uartDropdown, LV_PCT(50));
|
||||
|
||||
auto* uart_label = lv_label_create(uart_wrapper);
|
||||
lv_obj_align(uart_label, LV_ALIGN_TOP_LEFT, 0, 10);
|
||||
lv_label_set_text(uart_label, "Bus");
|
||||
|
||||
// region Model
|
||||
|
||||
auto* model_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(model_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_ver(model_wrapper, 0, 0);
|
||||
lv_obj_set_style_border_width(model_wrapper, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(model_wrapper);
|
||||
|
||||
modelDropdown = lv_dropdown_create(model_wrapper);
|
||||
|
||||
auto model_names = hal::gps::getModels();
|
||||
auto model_options = string::join(model_names, "\n");
|
||||
lv_dropdown_set_options(modelDropdown, model_options.c_str());
|
||||
lv_obj_align(modelDropdown, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
lv_obj_set_width(modelDropdown, LV_PCT(50));
|
||||
|
||||
auto* model_label = lv_label_create(model_wrapper);
|
||||
lv_obj_align(model_label, LV_ALIGN_TOP_LEFT, 0, 10);
|
||||
lv_label_set_text(model_label, "Model");
|
||||
|
||||
// endregion
|
||||
|
||||
// region Baud
|
||||
auto* baud_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(baud_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_ver(baud_wrapper, 0, 0);
|
||||
lv_obj_set_style_border_width(baud_wrapper, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(baud_wrapper);
|
||||
|
||||
baudDropdown = lv_dropdown_create(baud_wrapper);
|
||||
lv_dropdown_set_options(baudDropdown, baudRatesDropdownValues);
|
||||
lv_obj_align(baudDropdown, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
lv_obj_set_width(baudDropdown, LV_PCT(50));
|
||||
|
||||
auto* baud_rate_label = lv_label_create(baud_wrapper);
|
||||
lv_obj_align(baud_rate_label, LV_ALIGN_TOP_LEFT, 0, 10);
|
||||
lv_label_set_text(baud_rate_label, "Baud");
|
||||
|
||||
// endregion
|
||||
|
||||
// region Button
|
||||
|
||||
auto* button_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(button_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_ver(button_wrapper, 0, 0);
|
||||
lv_obj_set_style_border_width(button_wrapper, 0, 0);
|
||||
lvgl::obj_set_style_bg_invisible(button_wrapper);
|
||||
|
||||
auto* add_button = lv_button_create(button_wrapper);
|
||||
lv_obj_align(add_button, LV_ALIGN_TOP_MID, 0, 0);
|
||||
auto* add_label = lv_label_create(add_button);
|
||||
lv_label_set_text(add_label, "Add");
|
||||
lv_obj_add_event_cb(add_button, onAddGpsCallback, LV_EVENT_SHORT_CLICKED, this);
|
||||
|
||||
// endregion
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.id = "AddGps",
|
||||
.name = "Add GPS",
|
||||
.icon = LV_SYMBOL_GPS,
|
||||
.type = Type::Hidden,
|
||||
.createApp = create<AddGpsApp>
|
||||
};
|
||||
|
||||
void start() {
|
||||
app::start(manifest.id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -79,13 +79,13 @@ bool isSupportedImageFile(const std::string& filename) {
|
||||
bool isSupportedTextFile(const std::string& filename) {
|
||||
std::string filename_lower = string::lowercase(filename);
|
||||
return filename_lower.ends_with(".txt") ||
|
||||
filename_lower.ends_with(".ini") ||
|
||||
filename_lower.ends_with(".json") ||
|
||||
filename_lower.ends_with(".yaml") ||
|
||||
filename_lower.ends_with(".yml") ||
|
||||
filename_lower.ends_with(".lua") ||
|
||||
filename_lower.ends_with(".js") ||
|
||||
filename_lower.ends_with(".properties");
|
||||
filename_lower.ends_with(".ini") ||
|
||||
filename_lower.ends_with(".json") ||
|
||||
filename_lower.ends_with(".yaml") ||
|
||||
filename_lower.ends_with(".yml") ||
|
||||
filename_lower.ends_with(".lua") ||
|
||||
filename_lower.ends_with(".js") ||
|
||||
filename_lower.ends_with(".properties");
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace tt::app::files
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <dirent.h>
|
||||
|
||||
#define TAG "files_app"
|
||||
|
||||
@@ -48,12 +50,12 @@ bool State::setEntriesForPath(const std::string& path) {
|
||||
if (show_custom_root) {
|
||||
TT_LOG_I(TAG, "Setting custom root");
|
||||
dir_entries.clear();
|
||||
dir_entries.push_back({
|
||||
dir_entries.push_back(dirent{
|
||||
.d_ino = 0,
|
||||
.d_type = TT_DT_DIR,
|
||||
.d_name = SYSTEM_PARTITION_NAME
|
||||
});
|
||||
dir_entries.push_back({
|
||||
dir_entries.push_back(dirent{
|
||||
.d_ino = 1,
|
||||
.d_type = TT_DT_DIR,
|
||||
.d_name = DATA_PARTITION_NAME
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
#include "Tactility/TactilityHeadless.h"
|
||||
#include "Tactility/Timer.h"
|
||||
#include "Tactility/app/AppManifest.h"
|
||||
#include "Tactility/app/alertdialog/AlertDialog.h"
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/service/gps/GpsUtil.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
#include <Tactility/service/gps/Gps.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <lvgl.h>
|
||||
|
||||
#define TAG "gps_settings"
|
||||
namespace tt::app::addgps {
|
||||
extern AppManifest manifest;
|
||||
}
|
||||
|
||||
namespace tt::app::gpssettings {
|
||||
|
||||
constexpr const char* TAG = "GpsSettings";
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
class GpsSettingsApp final : public App {
|
||||
@@ -22,12 +28,16 @@ private:
|
||||
|
||||
std::unique_ptr<Timer> timer;
|
||||
std::shared_ptr<GpsSettingsApp*> appReference = std::make_shared<GpsSettingsApp*>(this);
|
||||
lv_obj_t* statusWrapper = nullptr;
|
||||
lv_obj_t* statusLabelWidget = nullptr;
|
||||
lv_obj_t* switchWidget = nullptr;
|
||||
lv_obj_t* spinnerWidget = nullptr;
|
||||
lv_obj_t* infoContainerWidget = nullptr;
|
||||
lv_obj_t* gpsConfigWrapper = nullptr;
|
||||
lv_obj_t* addGpsWrapper = nullptr;
|
||||
bool hasSetInfo = false;
|
||||
PubSub::SubscriptionHandle serviceStateSubscription = nullptr;
|
||||
std::shared_ptr<service::gps::GpsService> service;
|
||||
|
||||
static void onUpdateCallback(TT_UNUSED std::shared_ptr<void> context) {
|
||||
auto appPtr = std::static_pointer_cast<GpsSettingsApp*>(context);
|
||||
@@ -54,6 +64,15 @@ private:
|
||||
app->onGpsToggled(event);
|
||||
}
|
||||
|
||||
static void onAddGpsCallback(lv_event_t* event) {
|
||||
auto* app = (GpsSettingsApp*)lv_event_get_user_data(event);
|
||||
app->onAddGps();
|
||||
}
|
||||
|
||||
void onAddGps() {
|
||||
app::start(addgps::manifest.id);
|
||||
}
|
||||
|
||||
void startReceivingUpdates() {
|
||||
timer->start(kernel::secondsToTicks(1));
|
||||
updateViews();
|
||||
@@ -66,13 +85,83 @@ private:
|
||||
|
||||
void createInfoView(hal::gps::GpsModel model) {
|
||||
auto* label = lv_label_create(infoContainerWidget);
|
||||
lv_label_set_text_fmt(label, "Model: %s", toString(model));
|
||||
if (model == hal::gps::GpsModel::Unknown) {
|
||||
lv_label_set_text(label, "Model: auto-detect");
|
||||
} else {
|
||||
lv_label_set_text_fmt(label, "Model: %s", toString(model));
|
||||
}
|
||||
}
|
||||
|
||||
static void onDeleteConfiguration(lv_event_t* event) {
|
||||
auto* app = (GpsSettingsApp*)lv_event_get_user_data(event);
|
||||
|
||||
auto* button = lv_event_get_target_obj(event);
|
||||
auto index_as_voidptr = lv_obj_get_user_data(button); // config index
|
||||
int index;
|
||||
// TODO: Find a better way to cast void* to int, or find a different way to pass the index
|
||||
memcpy(&index, &index_as_voidptr, sizeof(int));
|
||||
|
||||
std::vector<tt::hal::gps::GpsConfiguration> configurations;
|
||||
auto gps_service = tt::service::gps::findGpsService();
|
||||
if (gps_service && gps_service->getGpsConfigurations(configurations)) {
|
||||
TT_LOG_I(TAG, "Found service and configs %d %d", index, configurations.size());
|
||||
if (index <= configurations.size()) {
|
||||
if (gps_service->removeGpsConfiguration(configurations[index])) {
|
||||
app->updateViews();
|
||||
} else {
|
||||
alertdialog::start("Error", "Failed to remove configuration");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createGpsView(const hal::gps::GpsConfiguration& configuration, int index) {
|
||||
auto* wrapper = lv_obj_create(gpsConfigWrapper);
|
||||
lv_obj_set_size(wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_style_margin_hor(wrapper, 0, 0);
|
||||
lv_obj_set_style_margin_bottom(wrapper, 8, 0);
|
||||
|
||||
// Left wrapper
|
||||
|
||||
auto* left_wrapper = lv_obj_create(wrapper);
|
||||
lv_obj_set_style_border_width(left_wrapper, 0, 0);
|
||||
lv_obj_set_style_pad_all(left_wrapper, 0, 0);
|
||||
lv_obj_set_size(left_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_grow(left_wrapper, 1);
|
||||
lv_obj_set_flex_flow(left_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
auto* uart_label = lv_label_create(left_wrapper);
|
||||
lv_label_set_text_fmt(uart_label, "UART: %s", configuration.uartName);
|
||||
|
||||
auto* baud_label = lv_label_create(left_wrapper);
|
||||
lv_label_set_text_fmt(baud_label, "Baud: %lu", configuration.baudRate);
|
||||
|
||||
auto* model_label = lv_label_create(left_wrapper);
|
||||
if (configuration.model == hal::gps::GpsModel::Unknown) {
|
||||
lv_label_set_text(model_label, "Model: auto-detect");
|
||||
} else {
|
||||
lv_label_set_text_fmt(model_label, "Model: %s", toString(configuration.model));
|
||||
}
|
||||
|
||||
// Right wrapper
|
||||
auto* right_wrapper = lv_obj_create(wrapper);
|
||||
lv_obj_set_style_border_width(right_wrapper, 0, 0);
|
||||
lv_obj_set_style_pad_all(right_wrapper, 0, 0);
|
||||
lv_obj_set_size(right_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(right_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
auto* delete_button = lv_button_create(right_wrapper);
|
||||
lv_obj_add_event_cb(delete_button, onDeleteConfiguration, LV_EVENT_SHORT_CLICKED, this);
|
||||
lv_obj_set_user_data(delete_button, reinterpret_cast<void*>(index));
|
||||
auto* delete_label = lv_label_create(delete_button);
|
||||
lv_label_set_text_fmt(delete_label, LV_SYMBOL_TRASH);
|
||||
}
|
||||
|
||||
void updateViews() {
|
||||
auto lock = lvgl::getSyncLock()->asScopedLock();
|
||||
if (lock.lock(100 / portTICK_PERIOD_MS)) {
|
||||
auto state = service::gps::getState();
|
||||
auto state = service->getState();
|
||||
|
||||
// Update toolbar
|
||||
switch (state) {
|
||||
@@ -81,24 +170,36 @@ private:
|
||||
lv_obj_remove_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_state(switchWidget, LV_STATE_CHECKED);
|
||||
lv_obj_add_state(switchWidget, LV_STATE_DISABLED);
|
||||
lv_obj_remove_flag(statusWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(gpsConfigWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
case service::gps::State::On:
|
||||
TT_LOG_D(TAG, "On");
|
||||
lv_obj_add_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_state(switchWidget, LV_STATE_CHECKED);
|
||||
lv_obj_remove_state(switchWidget, LV_STATE_DISABLED);
|
||||
lv_obj_remove_flag(statusWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(gpsConfigWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
case service::gps::State::OffPending:
|
||||
TT_LOG_D(TAG, "OffPending");
|
||||
lv_obj_remove_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_state(switchWidget, LV_STATE_CHECKED);
|
||||
lv_obj_add_state(switchWidget, LV_STATE_DISABLED);
|
||||
lv_obj_add_flag(statusWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(gpsConfigWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
case service::gps::State::Off:
|
||||
TT_LOG_D(TAG, "Off");
|
||||
lv_obj_add_flag(spinnerWidget, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_state(switchWidget, LV_STATE_CHECKED);
|
||||
lv_obj_remove_state(switchWidget, LV_STATE_DISABLED);
|
||||
lv_obj_add_flag(statusWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(gpsConfigWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(addGpsWrapper, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -113,7 +214,7 @@ private:
|
||||
}
|
||||
|
||||
minmea_sentence_rmc rmc;
|
||||
if (service::gps::getCoordinates(rmc)) {
|
||||
if (service->getCoordinates(rmc)) {
|
||||
minmea_float latitude = { rmc.latitude.value, rmc.latitude.scale };
|
||||
minmea_float longitude = { rmc.longitude.value, rmc.longitude.scale };
|
||||
auto label_text = std::format("LAT {}\nLON {}", minmea_tocoord(&latitude), minmea_tocoord(&longitude));
|
||||
@@ -130,12 +231,22 @@ private:
|
||||
|
||||
lv_obj_add_flag(statusLabelWidget, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
lv_obj_clean(gpsConfigWrapper);
|
||||
std::vector<tt::hal::gps::GpsConfiguration> configurations;
|
||||
auto gps_service = tt::service::gps::findGpsService();
|
||||
if (gps_service && gps_service->getGpsConfigurations(configurations)) {
|
||||
int index = 0;
|
||||
for (auto& configuration : configurations) {
|
||||
createGpsView(configuration, index++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @return true if the views were updated */
|
||||
bool updateTimerState() {
|
||||
bool is_on = service::gps::getState() == service::gps::State::On;
|
||||
bool is_on = service->getState() == service::gps::State::On;
|
||||
if (is_on && !timer->isRunning()) {
|
||||
startReceivingUpdates();
|
||||
return true;
|
||||
@@ -149,19 +260,19 @@ private:
|
||||
|
||||
void onGpsToggled(TT_UNUSED lv_event_t* event) {
|
||||
bool wants_on = lv_obj_has_state(switchWidget, LV_STATE_CHECKED);
|
||||
auto state = service::gps::getState();
|
||||
auto state = service->getState();
|
||||
bool is_on = (state == service::gps::State::On) || (state == service::gps::State::OnPending);
|
||||
|
||||
if (wants_on != is_on) {
|
||||
// start/stop are potentially blocking calls, so we use a dispatcher to not block the UI
|
||||
if (wants_on) {
|
||||
getMainDispatcher().dispatch([](TT_UNUSED auto _) {
|
||||
service::gps::startReceiving();
|
||||
}, nullptr);
|
||||
getMainDispatcher().dispatch([](auto service) {
|
||||
std::static_pointer_cast<service::gps::GpsService>(service)->startReceiving();
|
||||
}, service);
|
||||
} else {
|
||||
getMainDispatcher().dispatch([](TT_UNUSED auto _) {
|
||||
service::gps::stopReceiving();
|
||||
}, nullptr);
|
||||
getMainDispatcher().dispatch([](auto service) {
|
||||
std::static_pointer_cast<service::gps::GpsService>(service)->stopReceiving();
|
||||
}, service);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,6 +281,7 @@ public:
|
||||
|
||||
GpsSettingsApp() {
|
||||
timer = std::make_unique<Timer>(Timer::Type::Periodic, onUpdateCallback, appReference);
|
||||
service = service::gps::findGpsService();
|
||||
}
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) final {
|
||||
@@ -190,16 +302,16 @@ public:
|
||||
lv_obj_set_style_border_width(main_wrapper, 0, 0);
|
||||
lv_obj_set_style_pad_all(main_wrapper, 0, 0);
|
||||
|
||||
auto* top_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_width(top_wrapper, LV_PCT(100));
|
||||
lv_obj_set_height(top_wrapper, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(top_wrapper, 0, 0);
|
||||
lv_obj_set_style_border_width(top_wrapper, 0, 0);
|
||||
statusWrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_width(statusWrapper, LV_PCT(100));
|
||||
lv_obj_set_height(statusWrapper, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(statusWrapper, 0, 0);
|
||||
lv_obj_set_style_border_width(statusWrapper, 0, 0);
|
||||
|
||||
statusLabelWidget = lv_label_create(top_wrapper);
|
||||
statusLabelWidget = lv_label_create(statusWrapper);
|
||||
lv_obj_align(statusLabelWidget, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
|
||||
infoContainerWidget = lv_obj_create(top_wrapper);
|
||||
infoContainerWidget = lv_obj_create(statusWrapper);
|
||||
lv_obj_align_to(infoContainerWidget, statusLabelWidget, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 20);
|
||||
lv_obj_set_size(infoContainerWidget, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(infoContainerWidget, LV_FLEX_FLOW_COLUMN);
|
||||
@@ -207,14 +319,33 @@ public:
|
||||
lv_obj_set_style_pad_all(infoContainerWidget, 0, 0);
|
||||
hasSetInfo = false;
|
||||
|
||||
serviceStateSubscription = service->getStatePubsub()->subscribe(onServiceStateChangedCallback, this);
|
||||
|
||||
gpsConfigWrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(gpsConfigWrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_border_width(gpsConfigWrapper, 0, 0);
|
||||
lv_obj_set_style_margin_all(gpsConfigWrapper, 0, 0);
|
||||
lv_obj_set_style_pad_bottom(gpsConfigWrapper, 0, 0);
|
||||
|
||||
addGpsWrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(addGpsWrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_border_width(addGpsWrapper, 0, 0);
|
||||
lv_obj_set_style_pad_all(addGpsWrapper, 0, 0);
|
||||
lv_obj_set_style_margin_top(addGpsWrapper, 0, 0);
|
||||
lv_obj_set_style_margin_bottom(addGpsWrapper, 8, 0);
|
||||
|
||||
auto* add_gps_button = lv_button_create(addGpsWrapper);
|
||||
auto* add_gps_label = lv_label_create(add_gps_button);
|
||||
lv_label_set_text(add_gps_label, "Add GPS");
|
||||
lv_obj_add_event_cb(add_gps_button, onAddGpsCallback, LV_EVENT_SHORT_CLICKED, this);
|
||||
lv_obj_align(add_gps_button, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
updateTimerState();
|
||||
updateViews();
|
||||
|
||||
serviceStateSubscription = service::gps::getStatePubsub()->subscribe(onServiceStateChangedCallback, this);
|
||||
}
|
||||
|
||||
void onHide(AppContext& app) final {
|
||||
service::gps::getStatePubsub()->unsubscribe(serviceStateSubscription);
|
||||
service->getStatePubsub()->unsubscribe(serviceStateSubscription);
|
||||
serviceStateSubscription = nullptr;
|
||||
}
|
||||
};
|
||||
@@ -228,7 +359,7 @@ extern const AppManifest manifest = {
|
||||
};
|
||||
|
||||
void start() {
|
||||
service::loader::startApp(manifest.id);
|
||||
app::start(manifest.id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "Tactility/app/serialconsole/ConnectView.h"
|
||||
#include "Tactility/app/serialconsole/ConsoleView.h"
|
||||
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "Tactility/lvgl/Style.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
@@ -10,8 +9,6 @@
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#define TAG "text_viewer"
|
||||
|
||||
namespace tt::app::serialconsole {
|
||||
|
||||
class SerialConsoleApp final : public App {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "Tactility/hal/power/PowerDevice.h"
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
#include "Tactility/service/gps/Gps.h"
|
||||
#include "Tactility/service/gps/GpsService.h"
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/TactilityHeadless.h>
|
||||
@@ -154,7 +154,7 @@ private:
|
||||
}
|
||||
|
||||
void updateGpsIcon() {
|
||||
auto gps_state = gps::getState();
|
||||
auto gps_state = service::gps::findGpsService()->getState();
|
||||
bool show_icon = (gps_state == gps::State::OnPending) || (gps_state == gps::State::On);
|
||||
if (gps_last_state != show_icon) {
|
||||
if (show_icon) {
|
||||
|
||||
Reference in New Issue
Block a user