mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-14 15:16:40 +00:00
Rounds out the browser sim harness with the rest of the physical board's interactions: a reset button (JS-driven, since board.reboot() is inert under -sEXIT_RUNTIME=0), GPS input wired into a real LocationProvider via new SimSensorManager, JS-settable battery/environment telemetry, an admin/repeater-login test hook (sendRoomLogin against the default "password"), and full physical-keyboard text entry (printable ASCII passthrough into the existing KeyboardWidget, Tab->KEY_KB_ENTER submit). Also fixes three real bugs found while exercising all of this in a real browser: - UITask.cpp's native-only stdin poll branch had no __EMSCRIPTEN__ exclusion, so it also compiled into the wasm build and called a real, blocking window.prompt() on nearly every frame -- the actual cause of the reported time/controls jumping. Now gated to native only. - 'n'/'p' were mapped as Next/Prev keyboard shortcuts, colliding with typing those literal letters. Removed the shortcuts; added explicit Next/Prev buttons to mesh.html (previously relied solely on them). - Buttons grabbed native browser keyboard focus on click, so a later stray Enter/Space could silently re-trigger a previously-clicked button (e.g. Reset). mousedown now calls preventDefault() on all buttons. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
81 lines
3.5 KiB
C++
81 lines
3.5 KiB
C++
#pragma once
|
|
|
|
#include <helpers/sensors/LocationProvider.h>
|
|
#include <helpers/SensorManager.h>
|
|
#include <ctime>
|
|
|
|
// LocationProvider stub for the sim build. Phase 1/2: no real GPS, always
|
|
// reports "no fix" (default-constructed state below reproduces that
|
|
// exactly). Phase 3: JS-settable per instance via sim_location_set(),
|
|
// declared at the bottom of this file.
|
|
//
|
|
// Note on how this actually reaches the advertised location: companion_radio
|
|
// itself never calls a LocationProvider through this class -- it reads
|
|
// `sensors.node_lat`/`node_lon` directly (see e.g.
|
|
// examples/companion_radio/MyMesh.cpp's createSelfAdvert() call sites), and
|
|
// `sensors` (declared in target.h) is a plain base `SensorManager`, not a
|
|
// subclass wired to any LocationProvider -- there was never a real GPS
|
|
// object plugged in here to begin with (see SensorManager.h: "modify
|
|
// node_lat/node_lon directly, if you want to affect Advert location"). So
|
|
// sim_location_set() below writes BOTH this class's own state (satisfying
|
|
// the LocationProvider interface faithfully, in case future sim code wants
|
|
// a real one) AND `sensors.node_lat/node_lon` directly (the field
|
|
// companion_radio's advert path actually reads) -- belt and suspenders,
|
|
// same underlying values either way.
|
|
class SimLocationProvider : public LocationProvider {
|
|
long _lat_e6 = 0, _lon_e6 = 0, _alt_mm = 0;
|
|
bool _valid = false;
|
|
|
|
public:
|
|
long getLatitude() override { return _lat_e6; }
|
|
long getLongitude() override { return _lon_e6; }
|
|
long getAltitude() override { return _alt_mm; }
|
|
long satellitesCount() override { return _valid ? 8 : 0; }
|
|
bool isValid() override { return _valid; }
|
|
long getTimestamp() override { return _valid ? (long)time(NULL) : 0; }
|
|
void reset() override { _valid = false; }
|
|
void begin() override { }
|
|
void stop() override { }
|
|
void loop() override { }
|
|
bool isEnabled() override { return _valid; }
|
|
void sendSentence(const char* sentence) override { }
|
|
|
|
void set(float lat_deg, float lon_deg, float alt_m = 0.0f) {
|
|
_lat_e6 = (long)(lat_deg * 1000000.0f);
|
|
_lon_e6 = (long)(lon_deg * 1000000.0f);
|
|
_alt_mm = (long)(alt_m * 1000.0f);
|
|
_valid = true;
|
|
}
|
|
};
|
|
|
|
// Single instance, mirroring the pattern of every other Sim* global
|
|
// (board/radio_driver/rtc_clock/sensors) declared in target.h/target.cpp.
|
|
// Typed as SimSensorManager, not the SensorManager base, because C++
|
|
// requires every declaration of the same global variable to agree on its
|
|
// exact type -- target.cpp's actual `SimSensorManager sensors;` definition
|
|
// would otherwise conflict with a base-typed extern here. This only
|
|
// compiles because target.h includes SimSensorManager.h (which declares
|
|
// the class) before this file -- see target.h's own comment on that
|
|
// ordering.
|
|
extern SimSensorManager sensors; // defined in variants/sim/target.cpp
|
|
inline SimLocationProvider& sim_location_provider() {
|
|
static SimLocationProvider instance;
|
|
return instance;
|
|
}
|
|
|
|
inline void sim_location_apply(float lat_deg, float lon_deg, float alt_m = 0.0f) {
|
|
sim_location_provider().set(lat_deg, lon_deg, alt_m);
|
|
sensors.node_lat = lat_deg;
|
|
sensors.node_lon = lon_deg;
|
|
sensors.node_altitude = alt_m;
|
|
}
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
#include <emscripten.h>
|
|
// C linkage (no default args, unlike sim_location_apply() above) so JS's
|
|
// ccall('sim_location_set', ...) can find it by its exact, unmangled name.
|
|
extern "C" inline EMSCRIPTEN_KEEPALIVE void sim_location_set(float lat_deg, float lon_deg, float alt_m) {
|
|
sim_location_apply(lat_deg, lon_deg, alt_m);
|
|
}
|
|
#endif
|