Files
wadamesh/web/platform/board.cpp
T
Kaj SchittecatandClaude Opus 5.5 91fc03fdc0 web: one board boot (board.cpp) for two front ends; panel dirty rectangle
board.cpp owns the board globals and src/main.cpp's setup()/loop() order;
host_main.cpp keeps only the SDL window, event pump and scripted tour, so the
browser front end reuses the boot unchanged. WebDisplay tracks the changed
rectangle for the canvas upload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 12:55:59 +02:00

89 lines
3.3 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 "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 the companion's client in
// phase 3), 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);
SensorManager 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() {
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
sensors.node_lat = 52.3728; // the demo node's position (scripts/doc/web-demo/demo.py)
sensors.node_lon = 4.8934;
the_mesh.begin(wadaCreateDemoBackend());
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() {
ui_task.loop();
the_mesh.loop();
}
void wadaBoardFlush() { ui_task.persistHistoryNow(); }