mirror of
https://github.com/ALLFATHER-BV/wadamesh.git
synced 2026-11-12 04:37:33 +00:00
Location: the web board has CAP_GPS 1. web/platform/WebLocation.* is its SensorManager + LocationProvider, fed by navigator.geolocation (page shell, only while the UI's GPS is on, the prompt deferred to a tap) or WADA_GPS on the host, so the GPS switch, status, map centring, distances and wada.sys.gps (with speed/course) work unchanged. The position reaches a connected node (CMD_SET_ADVERT_LATLON, displaced by the Location privacy radius) only while the node's advert-location setting is "share"; the demo moves its cast to the visitor's location. Map tiles: wadaHttpRequest serves the firmware's default tile server only: a synchronous emscripten_fetch from the tile_fetch pthread to the same-origin tiles/ path (serve.py proxies it; nginx location for the site), plain HTTP natively. WiFi reports connected while the browser is online. Fixes the static-init order of the host VFS (the UI's own tiles LittleFS copied an empty impl). Polish: Lua apps that need the board's own radio carry "radio": "own" in the catalog (baked under CAP_RADIO_TOOLS, greyed in the Store); mouse wheel and trackpad scrolling; Settings > Wi-Fi / Bluetooth explain the page bar (CAP_WIFI_SETUP / CAP_BT_SETUP); no Download mode (CAP_USB_FLASH); no receiver settings on Settings > GPS (CAP_GPS_RECEIVER). Tests: webtest checks the map centres on Playwright's Ghent location and shows tiles; nodetest checks the location privacy rule against the mock node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.6 KiB
C++
94 lines
3.6 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// The web board's globals and boot order: what a variants/*/target.cpp plus
|
|
// src/main.cpp's setup()/loop() are on a device. Shared by host_main.cpp (SDL2) and
|
|
// web_main.cpp (Emscripten); neither front end duplicates any of this.
|
|
#include <Arduino.h>
|
|
#include <SPIFFS.h>
|
|
#include <LittleFS.h>
|
|
#include <Wire.h>
|
|
#include <SPI.h>
|
|
#include <WiFi.h>
|
|
#include <helpers/BaseSerialInterface.h>
|
|
#include "UITask.h"
|
|
#include "WebMesh.h"
|
|
#include "WebPlatform.h"
|
|
#include "WebInput.h"
|
|
#include "BackendSelect.h"
|
|
#include "helpers/esp32/TouchPrefsStore.h"
|
|
#include "wada_host.h"
|
|
#include <time.h>
|
|
|
|
namespace {
|
|
// The mesh clock: the host's wall clock (a browser always knows the time).
|
|
class HostRTCClock : public mesh::RTCClock {
|
|
public:
|
|
uint32_t getCurrentTime() override { return (uint32_t)time(nullptr); }
|
|
void setCurrentTime(uint32_t) override {} // the OS owns the clock
|
|
};
|
|
HostRTCClock s_host_clock;
|
|
|
|
// No companion transport is served BY the web board (it is a companion's CLIENT, see
|
|
// web/mesh/CompanionBackend.cpp), so the UI's companion-link controls see a disabled, unconnected interface.
|
|
class WebSerialInterface : public BaseSerialInterface {
|
|
public:
|
|
void enable() override { _en = true; }
|
|
void disable() override { _en = false; }
|
|
bool isEnabled() const override { return _en; }
|
|
bool isConnected() const override { return false; }
|
|
bool isWriteBusy() const override { return false; }
|
|
size_t writeFrame(const uint8_t src[], size_t len) override { (void)src; return len; }
|
|
size_t checkRecvFrame(uint8_t dest[]) override { (void)dest; return 0; }
|
|
bool isTcpEnabled() const override { return false; }
|
|
private:
|
|
bool _en = false;
|
|
};
|
|
WebSerialInterface s_serial;
|
|
} // namespace
|
|
|
|
WebBoard board;
|
|
WebRadio radio_driver;
|
|
ClockFloorRTC rtc_clock(s_host_clock);
|
|
WebSensorManager sensors;
|
|
WebDisplay display;
|
|
TwoWire Wire(0), Wire1(1);
|
|
SPIClass SPI;
|
|
WiFiClass WiFi;
|
|
UITask ui_task(&board, &s_serial);
|
|
static MyMesh s_mesh(rtc_clock, &ui_task);
|
|
MyMesh& the_mesh = s_mesh;
|
|
|
|
// src/main.cpp / DataStore.cpp / MultiTransportCompanionInterface.cpp symbols the UI reads.
|
|
bool g_identity_restored_from_copy = false;
|
|
uint8_t bleLastFailReason() { return 0; } // BLE_FAIL_NONE: there is no Bluetooth stack to fail
|
|
|
|
// AutoDiscoverRTCClock (core): no I2C RTC chips on a host, the fallback clock is it.
|
|
void AutoDiscoverRTCClock::begin(TwoWire&) {}
|
|
uint32_t AutoDiscoverRTCClock::getCurrentTime() { return _fallback->getCurrentTime(); }
|
|
void AutoDiscoverRTCClock::setCurrentTime(uint32_t t) { _fallback->setCurrentTime(t); }
|
|
|
|
void WebBoard::reboot() { esp_restart(); }
|
|
void WebBoard::powerOff() { esp_restart(); }
|
|
|
|
void wadaBoardBegin(const WadaBackendChoice& choice) {
|
|
Serial.printf("[web] wadamesh %s, data dir %s\n", FIRMWARE_VERSION, wadaHostDataDir().c_str());
|
|
// Storage, then the mesh, then the UI: src/main.cpp's setup() order.
|
|
SPIFFS.begin(true);
|
|
LittleFS.begin(true);
|
|
rtc_clock.setCurrentTime((uint32_t)time(nullptr)); // the host clock is synced: a real time source
|
|
the_mesh.begin(wadaCreateBackend(choice)); // the demo, or a companion node (BackendSelect.h)
|
|
// A node is set up already: the first-run wizard (name + LoRa region) would rename
|
|
// and re-tune it. It is the demo's welcome only.
|
|
if (choice.kind != "demo" && !touchPrefsGetSetupDone()) touchPrefsSetSetupDone(true);
|
|
ui_task.begin(&display, &sensors, the_mesh.getNodePrefs());
|
|
Serial.println("[BOOT] ui ready");
|
|
}
|
|
|
|
// UI first, then the mesh (same order as src/main.cpp, same reason).
|
|
void wadaBoardStep() {
|
|
webWheelTick();
|
|
ui_task.loop();
|
|
the_mesh.loop();
|
|
}
|
|
|
|
void wadaBoardFlush() { ui_task.persistHistoryNow(); }
|