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,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