Reference
API reference
Every glasses import, export and phone companion method in one place.
Glasses functions are imported from the mira WebAssembly module; phone methods live on miraCompanion. Arguments and return values are 32-bit integers unless noted.
Exports
Your module exports memory and these functions. None of them return a value.
- app_init()
- Called once when the app opens.
- app_render(elapsed_ms)
- Called repeatedly while the display is on, with the milliseconds since the previous call. If you export
app_update, the argument isforceinstead:1on the first call after the display wakes. - app_event(event)
- Called with an input event. See Input.
- app_stop()
- Called right before the app closes.
- app_update(elapsed_ms)
- Optional. Called repeatedly, even while the display is off, to advance your state.
Timing and the display
- foreground_interval_ms(ms) → i32
- How often MIRA calls your app while the display is on: 20 to 60,000 ms, or
0for no regular calls. 40 ms by default. See Timing and the display. - background_interval_ms(ms) → i32
- How often
app_updateruns while the display is off: 200 to 60,000 ms, or0for the 2,000 ms default. - display_active() → i32
- Nonzero while the display is on. Check it before drawing from
app_event.
Frames
- begin()
- Starts a new frame.
- present()
- Shows the frame. Only changed areas repaint.
- frame_checkpoint() → i32
- Saves everything drawn so far in this frame.
- frame_restore() → i32
- Restores the last checkpoint. Returns
0when there’s nothing to restore. - frame_mark() → i32
- The current drawing slot. Marks the start or end of the shapes to glide.
- glide(first, end, dx, dy, duration_ms) → i32
- Moves the shapes between two marks from an offset to where you drew them, over up to 2,000 ms. Negative durations move at a constant speed. See Animation.
- glide_state(first, end, out, capacity) → i32
- Writes the remaining x and y offset and milliseconds left. Returns
12,0for an empty or outdated range, or-1ifcapacityis under 12.
Shapes
Coordinates are pixels on the 640 × 480 canvas. gray is 0 to 15.
- line(x0, y0, x1, y1, width, gray)
- A line.
- fill_rect(x, y, w, h, gray)
- A filled rectangle.
- stroke_rect(x, y, w, h, line, gray)
- A rectangle outline.
- fill_round_rect(x, y, w, h, radius, gray)
- A filled rounded rectangle.
- stroke_round_rect(x, y, w, h, radius, line, gray)
- A rounded rectangle outline.
- fill_circle(cx, cy, radius, gray)
- A filled circle.
- stroke_circle(cx, cy, radius, line, gray)
- A circle outline.
- fill_triangle(x0, y0, x1, y1, x2, y2, gray)
- A filled triangle.
Text and images
- text(x, y, w, h, gray, font, align, line_spacing, utf8, len)
- UTF-8 text clipped to its box. Fonts
0to3are 24, 18, 32 and 40 px; align0left,1center,2right. - bitmap4(x, y, w, h, pixels, len)
- A 4-bit grayscale image. Rows are
ceil(w / 2)bytes, left pixel in the high nibble. Gray 15 is transparent. - bitmap4_rotated(x, y, w, h, pixels, len, degrees)
- The same image rotated around its center.
- bitmap1(x, y, w, h, mask, len, gray)
- A one-color mask up to 32 × 32. Rows are
ceil(w / 8)bytes, most significant bit first. - bitmap1_scaled(x, y, w, h, mask, len, scale, gray)
- A one-color mask scaled up 1 to 4 times. Uses image memory instead of the 16 mask slots.
Device
- now_ms() → i32
- A millisecond clock for timing.
- device_status(out, capacity) → i32
- Writes 10 bytes: battery, charging, audio link, phone link, clock set, hour, minute, month, day, weekday. See Device and media.
- display_brightness_get() → i32
- Brightness in percent.
- display_brightness_set(percent) → i32
- Sets brightness from 0 to 100 and returns the value applied.
- display_power_get() → i32
1while the display is awake,0while it’s asleep.- display_power_set(on)
1wakes the display or resets its idle timer;0sleeps it.- media_state(out, capacity) → i32
- Available and playing bytes, then null-terminated title and artist. Use a 164-byte buffer.
- media_command(command) → i32
0previous,1play or pause,2next,3volume up,4volume down.- audio_level(channel) → i32
- Loudness from 0 to 255. Channel
0is the microphone,1is MIRA’s spoken replies.
Head tracking
Angles are centidegrees. Reading orientation or raw motion pauses the look-up dashboard until imu_stop(), unless you share the sensor.
- imu_yaw_cdeg() → i32
- Heading. Positive turns right.
- imu_pitch_cdeg() → i32
- Tilt. Positive looks up.
- imu_roll_cdeg() → i32
- Roll.
- imu_ready() → i32
1once calibrated data has arrived. Call a getter first.- imu_threshold(above_cdeg, below_cdeg) → i32
1above,0below,-1not ready,-2full tracking is using the sensor without sharing it. Leaves the dashboard working.- imu_share_thresholds(enabled) → i32
1keeps the look-up dashboard working while you read orientation,0stops sharing. Returns0, or-1for an invalid value.- imu_raw_read(out) → i32
- Nine 32-bit floats: accelerometer, gyroscope, magnetometer. Returns
1when fresh. - imu_stop()
- Releases head tracking.
Phone requests
ble_request asks the MIRA app on the phone to do work the glasses can’t, such as live transcription. It returns a request ID right away; poll for the answer on later frames.
- ble_request(method, payload, len) → i32
- Sends a request and returns its ID. Up to 8 can be in flight, with payloads up to 384 bytes.
- ble_response_len(id) → i32
- The response size once it’s ready.
-1pending,-2unknown ID,-3timed out after 8 seconds. Phone-side errors come back as-100 - status. - ble_response_read(id, out, capacity) → i32
- Copies the response, which can be read once.
-4means the buffer is too small.
| Method | Does |
|---|---|
0x0001 | Starts live transcription. |
0x0002 | Stops live transcription. |
0x0003 | Returns the latest transcript: a state byte, a final byte, then the text as UTF-8. |
JavaScript on the glasses
Your app can run one small JavaScript context on the glasses, with up to 192 KiB of its own memory outside your module’s 64 KiB. Scripts draw through a small numeric interface that the skill file describes.
- script_create() → i32
- Creates the context.
1on success,-2if there isn’t enough memory. - script_eval(source, len) → i32
- Runs up to 48 KiB of UTF-8 source. The byte at
source[len]must be zero.1on success,-1on an error. - script_frame(elapsed_ms) → i32
- Calls the script’s global
frame(elapsed_ms). Returns a duration in ms (0 to 120,000), or-1on an error. - script_resource(name, name_len, out, capacity) → i32
- Reads a custom section of your own app.
- script_error(out, capacity) → i32
- Copies the last error.
- script_close()
- Releases the context. Stopping the app releases it too.
Rust helpers
The guide includes shared Rust modules. These are the ones most apps use.
- content::cursor(x, y, visible)
- Tells MIRA where your focused control is, for its voice feedback. See Focus.
- content::double_tap_local(claim)
- Delivers double tap to your app instead of taking the wearer out of it.
- content::holds_local(claim)
- Delivers long press, hold start and hold end to your app.
- content::overlay_visible() → bool
- True while a notification, the dashboard or one of MIRA’s answers covers your app.
- content::dashboard_open() → bool
- True while the look-up dashboard is open.
- content::context_changed() → bool
- True when what covers your app changed since you last asked.
- content::imu::stop()
- Same as
imu_stop(). - content::imu::share_thresholds(enabled)
- Same as
imu_share_thresholds. - companion::Companion::new(name)
- The ordered message bridge to your phone companion.
tick(elapsed)returns the next message once;send(json)returns false while busy. - companion::Realtime::new(name)
- The latest-value channel paired with
setLatestForApp. Calltickevery frame. - companion_bytes::Reader
- Downloads and checks an object staged with
setBytesForApp:start(id, length, hash), thentick(elapsed, buffer)every frame. See Larger data. - retained_frame::start(changed) / checkpoint()
- Keeps static drawing between frames.
- app_icon!(…)
- Defines the 32 × 32 icon your app shows on the glasses.
Phone companion
Methods on miraCompanion. Unless noted, each returns a promise.
- sendToApp(value)
- Sends an ordered JSON message to the glasses, up to 3,500 bytes.
- setSnapshotForApp(value)
- Replaces pending state the glasses page through, up to 3,500 bytes.
- setLatestForApp(value)
- Sets small realtime state, up to 380 bytes. Only the newest value is kept.
- setBytesForApp(id, bytes)
- Stages one binary object of 1 to 65,536 bytes for the glasses to download. See Larger data.
- onFromApp(handler) → unsubscribe
- Calls
handler(message)for each message from the glasses, and for voice command and dictation events. Not a promise. - storeGet(key) / storeSet(key, value) / storeRemove(key)
- Small string storage on the phone.
- getMediaState() / mediaCommand(code)
- What’s playing, and playback controls.
- getIMU() / stopIMU()
- Motion readings from the glasses, and releasing them.
- startCapture() / stopCapture()
- Starts and stops glasses microphone audio.
- onCapture(handler) → unsubscribe
- Receives audio frames. Not a promise.
- setVoiceCommands(labels, screen, descriptions)
- Registers up to 16 spoken commands for the visible screen. The last two arguments are optional. See Voice commands.
- startDictation(options) / stopDictation()
- Turns speech into text while capture runs.
stopDictationresolves with{text}. See Dictation. - bindPasteButton(button, onPaste)
- Shows the iOS Paste control over a button. Returns
{ready, dispose()}. - fetch(input, init) / WebSocket
- Standard networking, made from the phone.