App improvements (#105)

This commit is contained in:
Ken Van Hoeylandt
2024-12-04 23:06:03 +01:00
committed by GitHub
parent fb45790927
commit e86a11b7e2
29 changed files with 358 additions and 107 deletions
@@ -89,6 +89,11 @@ void scan();
*/
bool isScanning();
/**
* @return true the ssid name or empty string
*/
std::string getConnectionTarget();
/**
* @brief Returns the access points from the last scan (if any). It only contains public APs.
*/
@@ -116,6 +116,25 @@ WifiRadioState getRadioState() {
return state;
}
std::string getConnectionTarget() {
lock(wifi_singleton);
std::string result;
switch (wifi_singleton->radio_state) {
case WIFI_RADIO_CONNECTION_PENDING:
case WIFI_RADIO_CONNECTION_ACTIVE:
result = wifi_singleton->connection_target.ssid;
break;
case WIFI_RADIO_ON:
case WIFI_RADIO_ON_PENDING:
case WIFI_RADIO_OFF_PENDING:
case WIFI_RADIO_OFF:
result = "";
break;
}
unlock(wifi_singleton);
return result;
}
void scan() {
TT_LOG_I(TAG, "scan()");
tt_assert(wifi_singleton);
@@ -723,7 +742,6 @@ _Noreturn int32_t wifi_main(TT_UNUSED void* parameter) {
WifiMessage message;
while (true) {
TT_LOG_I(TAG, "Message queue %ld", queue.getCount());
if (queue.get(&message, 10000 / portTICK_PERIOD_MS) == TtStatusOk) {
TT_LOG_I(TAG, "Processing message of type %d", message.type);
switch (message.type) {
@@ -76,6 +76,10 @@ WifiRadioState getRadioState() {
return wifi->radio_state;
}
std::string getConnectionTarget() {
return "Home Wifi";
}
void scan() {
tt_assert(wifi);
wifi->scan_active = false; // TODO: enable and then later disable automatically
@@ -110,17 +114,17 @@ std::vector<WifiApRecord> getScanResults() {
.auth_mode = WIFI_AUTH_WPA2_PSK
});
records.push_back((WifiApRecord) {
.ssid = "Living Room",
.ssid = "No place like 127.0.0.1",
.rssi = -67,
.auth_mode = WIFI_AUTH_WPA2_PSK
});
records.push_back((WifiApRecord) {
.ssid = "No place like 127.0.0.1",
.ssid = "Pretty fly for a Wi-Fi",
.rssi = -70,
.auth_mode = WIFI_AUTH_WPA2_PSK
});
records.push_back((WifiApRecord) {
.ssid = "Public Wi-Fi",
.ssid = "An AP with a really, really long name",
.rssi = -80,
.auth_mode = WIFI_AUTH_WPA2_PSK
});
@@ -10,11 +10,11 @@ namespace tt::service::wifi::settings {
* The SSID and secret are increased by 1 byte to facilitate string null termination.
* This makes it easier to use the char array as a string in various places.
*/
typedef struct {
struct WifiApSettings {
char ssid[TT_WIFI_SSID_LIMIT + 1];
char password[TT_WIFI_CREDENTIALS_PASSWORD_LIMIT + 1];
bool auto_connect;
} WifiApSettings;
};
bool contains(const char* ssid);