mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-26 20:56:37 +00:00
feat(sim): board feature parity (reset/GPS/sensors/admin/keyboard) + input fixes
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>
This commit is contained in:
@@ -7,10 +7,20 @@
|
||||
// mesh::MainBoard implementation for the native sim build -- no real
|
||||
// hardware, so battery/manufacturer/reboot are all just plausible fakes.
|
||||
class SimMainBoard : public mesh::MainBoard {
|
||||
// Real telemetry code (examples/companion_radio/MyMesh.cpp,
|
||||
// examples/simple_room_server/MyMesh.cpp) reads getBattMilliVolts()
|
||||
// directly rather than going through SensorManager -- so a JS-settable
|
||||
// battery level lives here, not on SimSensorManager. Static (not a plain
|
||||
// member) so the EMSCRIPTEN_KEEPALIVE free function below can reach it
|
||||
// without needing a reference to the one `board` global (target.cpp)
|
||||
// plumbed through, same reasoning as SimLocationProvider.h's singleton.
|
||||
static uint16_t& battMilliVoltsRef() { static uint16_t mv = 4000; return mv; }
|
||||
|
||||
public:
|
||||
void begin() { }
|
||||
|
||||
uint16_t getBattMilliVolts() override { return 4000; } // pretend full battery
|
||||
uint16_t getBattMilliVolts() override { return battMilliVoltsRef(); }
|
||||
static void setBattMilliVolts(uint16_t mv) { battMilliVoltsRef() = mv; }
|
||||
const char* getManufacturerName() const override { return "MeshCore Sim (native)"; }
|
||||
|
||||
void reboot() override {
|
||||
@@ -24,3 +34,13 @@ public:
|
||||
void onBootComplete() override { }
|
||||
void sleep(uint32_t secs) override { } // no-op: native process never actually sleeps the CPU
|
||||
};
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
// C linkage so JS's ccall('sim_battery_set_mv', ...) can find it by its
|
||||
// exact, unmangled name -- same pattern as SimLocationProvider.h's
|
||||
// sim_location_set().
|
||||
extern "C" inline EMSCRIPTEN_KEEPALIVE void sim_battery_set_mv(int mv) {
|
||||
SimMainBoard::setBattMilliVolts((uint16_t)mv);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user