Standalone Bangle.js 2 emulator

Posted on
  • Hi all, I'd like to let you know about a standalone (i.e., not browser-based) Bangle.js 2 emulator that I've been working on: https://github.com/dzhu/banglejs-emu.

    While I really do love how Espruino provides in-browser tooling to make the barrier to entry as low as possible, and the emulator in the Espruino IDE in particular is a neat bit of tech, I find it a bit clumsy for everything to have to go through a browser (or a physical device). With this emulator, you can develop and test both firmware and apps in a way that's easier to integrate with typical coding workflows. I've already used it to help me fix a bug (https://github.com/espruino/Espruino/pul­l/2343) and do a variety of other tinkering besides. The emulator shows the screen and the console output right in the terminal window; the screen can be used for touch input, and you can connect via TCP to provide console input. Not all functionality is supported, but I think there's enough to be useful in a lot of cases.

    The emulator is written in Rust; you can either set up Rust and build it yourself or download pre-built binaries for Linux, macOS, and Windows at https://github.com/dzhu/banglejs-emu/act­ions.

  • Hi,

    Thanks! That looks like an interesting idea.

    Do you think it's possible for your code to just use the basic JS output of Bangle.js emulator? While there may be marginal performance improvements it seems like it wouldn't be much, and there's the benefit that we already keep up to date firmware builds for the Web IDE? https://github.com/espruino/EspruinoWebI­DE/tree/master/emu

  • That would be conceivable, but I don't think I would want to go in that direction from a technical perspective. Performance isn't really part of it (after all, anything running on a PC will far outstrip the real device anyway); it's more that I think WebAssembly is a better fit for this scenario -- this is basically exactly the kind of thing it was made for, by my understanding -- and asm.js has been considered pretty much made obsolete by it for a few years now, so I'd prefer not to use asm.js in a new project. And using the JS output would require writing everything in JS or embedding a JS interpreter, which didn't appeal to me personally as much. (Yes, I realize I'm saying that in the forum for a compact JS interpreter :P. I would certainly be delighted if someone did run Espruino on top of Espruino, though!)

    Actually, if anything, I was considering proposing that the web emulator switch to WebAssembly. I'll hold off from formally making that a feature request, since it would take some work while having, admittedly, not much immediate practical impact, but would you accept a PR making that change?

  • Ahh, ok - I assumed if you could run WebAssembly you basically had a JS engine already.

    I think right now, I wouldn't be up for a PR using WebAssembly - as you say I don't think it will make much practical difference, but it will break the CI checks that are done in the Espruino repo, as well as the code that's in for taking screenshots via emulator in BangleApps, and the in-progress code that's there to (hopefully) do CI checks on the apps in BangleApps. Not to mention that if there are bugs the current emulator is vaguely human-readable (you can see the real function names and step through instruction by instruction).

  • Oh, that's neat, I didn't know the JS version was used that way. I suppose that should be fixable (maybe not function names in stack traces), seeing how Node can run WebAssembly too, and I wouldn't consider the job done until such things were addressed, but I can certainly agree we're into not-worth-it territory.

    Anyway, web emulator and underlying technology aside, I hope someone will get some use out of this emulator in its own right! To expand on the benefits a bit more, I've found that the firmware for the real device takes about 40 seconds to build (even for an incremental build -- the final link step is most of it) and over 30 seconds to upload, while rebuilding for this takes 3 seconds and the emulator can be restarted instantly. Plus I don't have to squint at the rather small watch screen or wait for files to transfer over Bluetooth all the time.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Standalone Bangle.js 2 emulator

Posted by Avatar for dzhu @dzhu

Actions