Loading files
5e4094a64This file is pinned to the selected release. Download the original to open it in your design tool.
Files from this revision, including CAD and LFS contents. Git history is not included.
Or in GitHub Desktop, choose File → Clone repository → URL and paste this address.
Public repositories can be cloned without signing in. For pushing, use your ThingAtlas username and a Git access token as the password.
git lfs install git clone https://thingatlas.com/git/-unclaimed/stack-chan-374381865.git
Includes Git history, branches, and Git LFS files. Clones the repository’s default branch, regardless of the version shown here.
5e4094a64This file is pinned to the selected release. Download the original to open it in your design tool.
import Timer from 'timer'
const readHostButton = native('xs_stackchan_wasm_button_read')
const POLL_INTERVAL_MS = 16
class WasmButton {
#index
#lastValue
onChanged = () => {}
constructor(index) {
this.#index = index
this.#lastValue = this.read()
Timer.repeat(() => {
const value = this.read()
if (value === this.#lastValue) return
this.#lastValue = value
this.onChanged()
}, POLL_INTERVAL_MS)
}
read() {
return readHostButton(this.#index)
}
}
export function installWasmButtons() {
// Match the normalized Moddable Button contract used by real targets:
// read() is 1 while pressed and 0 while released. The native function
// crosses the XS/WebAssembly boundary and reads the browser Host.Button
// bridge. Installation is deferred until runtime because native functions
// are unavailable while xsl evaluates preloadable module code.
globalThis.button = {
a: new WasmButton(0),
b: new WasmButton(1),
c: new WasmButton(2),
}
}