This PR unifies navigation handling & adds system-wide support for continuous navigation. ## Summary Holding down a navigation button now continuously advances through items until the button is released. This removes the need for repeated press-and-release actions and makes navigation faster and smoother, especially in long menus or documents. When page-based navigation is available, it will navigate through pages. If not, it will progress through menu items or similar list-based UI elements. Additionally, this PR fixes inconsistencies in wrap-around behavior and navigation index calculations. Places where the navigation system was updated: - Home Page - Settings Pages - My Library Page - WiFi Selection Page - OPDS Browser Page - Keyboard - File Transfer Page - XTC Chapter Selector Page - EPUB Chapter Selector Page I’ve tested this on the device as much as possible and tried to match the existing behavior. Please let me know if I missed anything. Thanks 🙏  --- Following the request from @osteotek and @daveallie for system-wide support, the old PR (#379) has been closed in favor of this consolidated, system-wide implementation. --- ### AI Usage Did you use AI tools to help write this code? _**PARTIALLY**_ --------- Co-authored-by: Dave Allie <dave@daveallie.com>
110 lines
3.5 KiB
C++
110 lines
3.5 KiB
C++
#pragma once
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/semphr.h>
|
|
#include <freertos/task.h>
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "activities/ActivityWithSubactivity.h"
|
|
#include "util/ButtonNavigator.h"
|
|
|
|
// Structure to hold WiFi network information
|
|
struct WifiNetworkInfo {
|
|
std::string ssid;
|
|
int32_t rssi;
|
|
bool isEncrypted;
|
|
bool hasSavedPassword; // Whether we have saved credentials for this network
|
|
};
|
|
|
|
// WiFi selection states
|
|
enum class WifiSelectionState {
|
|
SCANNING, // Scanning for networks
|
|
NETWORK_LIST, // Displaying available networks
|
|
PASSWORD_ENTRY, // Entering password for selected network
|
|
CONNECTING, // Attempting to connect
|
|
CONNECTED, // Successfully connected
|
|
SAVE_PROMPT, // Asking user if they want to save the password
|
|
CONNECTION_FAILED, // Connection failed
|
|
FORGET_PROMPT // Asking user if they want to forget the network
|
|
};
|
|
|
|
/**
|
|
* WifiSelectionActivity is responsible for scanning WiFi APs and connecting to them.
|
|
* It will:
|
|
* - Enter scanning mode on entry
|
|
* - List available WiFi networks
|
|
* - Allow selection and launch KeyboardEntryActivity for password if needed
|
|
* - Save the password if requested
|
|
* - Call onComplete callback when connected or cancelled
|
|
*
|
|
* The onComplete callback receives true if connected successfully, false if cancelled.
|
|
*/
|
|
class WifiSelectionActivity final : public ActivityWithSubactivity {
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
|
ButtonNavigator buttonNavigator;
|
|
bool updateRequired = false;
|
|
WifiSelectionState state = WifiSelectionState::SCANNING;
|
|
int selectedNetworkIndex = 0;
|
|
std::vector<WifiNetworkInfo> networks;
|
|
const std::function<void(bool connected)> onComplete;
|
|
|
|
// Selected network for connection
|
|
std::string selectedSSID;
|
|
bool selectedRequiresPassword = false;
|
|
|
|
// Connection result
|
|
std::string connectedIP;
|
|
std::string connectionError;
|
|
|
|
// Password to potentially save (from keyboard or saved credentials)
|
|
std::string enteredPassword;
|
|
|
|
// Cached MAC address string for display
|
|
std::string cachedMacAddress;
|
|
|
|
// Whether network was connected using a saved password (skip save prompt)
|
|
bool usedSavedPassword = false;
|
|
|
|
// Save/forget prompt selection (0 = Yes, 1 = No)
|
|
int savePromptSelection = 0;
|
|
int forgetPromptSelection = 0;
|
|
|
|
// Connection timeout
|
|
static constexpr unsigned long CONNECTION_TIMEOUT_MS = 15000;
|
|
unsigned long connectionStartTime = 0;
|
|
|
|
static void taskTrampoline(void* param);
|
|
[[noreturn]] void displayTaskLoop();
|
|
void render() const;
|
|
void renderNetworkList() const;
|
|
void renderPasswordEntry() const;
|
|
void renderConnecting() const;
|
|
void renderConnected() const;
|
|
void renderSavePrompt() const;
|
|
void renderConnectionFailed() const;
|
|
void renderForgetPrompt() const;
|
|
|
|
void startWifiScan();
|
|
void processWifiScanResults();
|
|
void selectNetwork(int index);
|
|
void attemptConnection();
|
|
void checkConnectionStatus();
|
|
std::string getSignalStrengthIndicator(int32_t rssi) const;
|
|
|
|
public:
|
|
explicit WifiSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
|
const std::function<void(bool connected)>& onComplete)
|
|
: ActivityWithSubactivity("WifiSelection", renderer, mappedInput), onComplete(onComplete) {}
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
|
|
// Get the IP address after successful connection
|
|
const std::string& getConnectedIP() const { return connectedIP; }
|
|
};
|