--- name: even-realities-g2-sdk description: Design, build, debug, and package apps and games for Even Realities G2 smart glasses using @evenrealities/even_hub_sdk. Use when the user mentions Even Realities, Even G2, Even G1, R1 ring, Even Hub, @evenrealities/even_hub_sdk, smart glasses HUD apps, 576x288 micro-LED display containers, or asks to build plugins, dashboards, or games for Even Realities glasses. --- # Even Realities G2 SDK Build production-ready web plugins, heads-up display (HUD) tools, and 8-bit games for the Even Realities G2 smart glasses and R1 control ring using `@evenrealities/even_hub_sdk`. ## When to Use - Designing or coding apps, plugins, or games for Even Realities G2 smart glasses - Working with `@evenrealities/even_hub_sdk`, `waitForEvenAppBridge`, or Even Hub CLI (`evenhub` / `eh`) - Laying out `TextContainerProperty`, `ListContainerProperty`, or `ImageContainerProperty` on the 576x288 canvas - Handling temple touchpad gestures, R1 ring inputs, IMU streams, or 4-mic array audio capture - Optimizing frame rates and render loops for real-time 8-bit games on monochrome green waveguide displays - Configuring `app.json` manifests, testing with `evenhub-simulator`, or packing `.ehpk` bundles ## Hardware and Infrastructure Foundation Understand the physical architecture before designing any UI or game loop because the code does not run on the glasses directly. - **Split Execution Model**: Your app is a standard TypeScript/JavaScript web application (typically bundled with Vite) running inside an `inappwebview` container on the user's iOS or Android phone inside the Even Realities App. The phone communicates with the glasses over Bluetooth Low Energy (BLE 5.2/5.4). - **Display Canvas**: Dual micro-LED waveguide displays (one per lens) rendering a shared **576 x 288 pixel** canvas in **4-bit monochrome green** (16 brightness levels, 0 to 15; black pixels `0` are completely transparent on the waveguide). - **Audio and Camera**: The G2 glasses have a 4-microphone array (16 kHz single-stream PCM with directional metadata) and **no camera and no speaker** by privacy design. Phone camera and album access are available through SDK bridge calls if needed. - **Input Hardware**: Dual temple-tip touchpads (`GLASSES_L`, `GLASSES_R`) and the optional **Even R1 Smart Ring** (`RING`). Both support single press, double press, swipe up, swipe down, and long press/release, plus an onboard IMU (accelerometer/gyroscope). ## Steps ### 1. Initialize Project and Bridge Connection Bootstrap a Vite + TypeScript application and always await `waitForEvenAppBridge()` before invoking any SDK method. Calling SDK methods before the bridge resolves silently fails. ```typescript import { waitForEvenAppBridge, CreateStartUpPageContainer, RebuildPageContainer, TextContainerProperty, TextContainerUpgrade, ImageContainerProperty, ImageRawDataUpdate, ListContainerProperty, OsEventTypeList, } from '@evenrealities/even_hub_sdk'; const bridge = await waitForEvenAppBridge(); ``` ### 2. Design the Container Layout (576x288 Canvas) The G2 UI is not a freeform DOM on the lens. It is a declarative container system positioned in pixel coordinates (`xPosition: 0..576`, `yPosition: 0..288`). - **Container Limits per Page**: Maximum **8 text/list containers** and maximum **4 image containers**. - **Event Capture Rule**: Exactly **one** container on the active page must set `isEventCapture: 1` to receive user input events (`CLICK_EVENT`, `DOUBLE_CLICK_EVENT`, `SCROLL_TOP_EVENT`, `SCROLL_BOTTOM_EVENT`). All other containers must set `isEventCapture: 0`. - **Class Instantiation Requirement**: Always instantiate SDK classes with `new TextContainerProperty({...})`, `new ImageContainerProperty({...})`, and `new CreateStartUpPageContainer({...})`. Do not pass plain object literals if TypeScript methods like `toJson()` are expected by the bridge. - **Z-Ordering (SDK 0.0.12+)**: Optional `zOrderIndex` controls stacking order (higher renders in front). It is all-or-nothing per page: either every container on the page specifies a unique `zOrderIndex`, or all omit it. ### 3. Manage Page Lifecycle and Updates Follow strict lifecycle call ordering so the glasses firmware initializes the page state properly: 1. **Startup**: Call `await bridge.createStartUpPageContainer(new CreateStartUpPageContainer({...}))` exactly once when the app launches. 2. **Layout Changes**: Call `await bridge.rebuildPageContainer(new RebuildPageContainer({...}))` only when adding, removing, or resizing containers (such as switching from a Title Screen to a Game Screen). 3. **Fast Text Updates**: Call `await bridge.textContainerUpgrade(new TextContainerUpgrade({ containerID, containerName, contentOffset: 0, contentLength: fullText.length, content: fullText }))` for flicker-free, low-latency text and ASCII/Unicode block-art updates. Limit content to 999 UTF-8 bytes per container. 4. **Image Updates**: `createStartUpPageContainer` and `rebuildPageContainer` only register image container placeholders. You must subsequently call `await bridge.updateImageRawData(new ImageRawDataUpdate({ containerID, containerName, imageData }))` after container creation. 5. **App Exit**: On the root page, handle `DOUBLE_CLICK_EVENT` by calling `await bridge.shutDownPageContainer(1)` to trigger the required OS exit-confirmation dialog. Never exit silently with `0` on the root view or QA will reject the app. ### 4. Route Input and Sensor Events Subscribe once via `bridge.onEvenHubEvent((event) => { ... })` and route events based on your state machine: - **Container Events (`event.textEvent` or `event.listEvent`)**: - `OsEventTypeList.CLICK_EVENT` (0) or `undefined`: Single tap on touchpad or R1 ring. Always match both `OsEventTypeList.CLICK_EVENT` and `undefined` because the SDK normalizes `0` to `undefined` in some payloads. - `OsEventTypeList.SCROLL_TOP_EVENT` (1): Swipe up. - `OsEventTypeList.SCROLL_BOTTOM_EVENT` (2): Swipe down. - `OsEventTypeList.DOUBLE_CLICK_EVENT` (3): Double tap (standard Back / Exit / Secondary action). - **System Events (`event.sysEvent`)**: - `OsEventTypeList.LONG_PRESS_EVENT` (9) and `OsEventTypeList.LONG_PRESS_RELEASE_EVENT` (10): Always arrive on `event.sysEvent` regardless of which container has `isEventCapture: 1`. In SDK 0.0.15+, `event.sysEvent.eventSource` identifies `GLASSES_R`, `GLASSES_L`, or `RING`. - `OsEventTypeList.IMU_DATA_REPORT`: Carries `event.sysEvent.imuData` (`{ x, y, z }`) after enabling `await bridge.imuControl(true, ImuReportPace.P100)`. - **Contextual Menu (`event.menuItemClickEvent`)**: Up to 10 action items attached via `menuObject` on page creation/rebuild (SDK 0.0.14+). ### 5. Architect 8-Bit Games for BLE Bandwidth Constraints Because display updates cross a BLE link between phone and glasses, choose the right rendering pipeline for your game's genre: - **Pipeline A: High-FPS Unicode/Block-Art Matrix (`textContainerUpgrade`)**: - Best for fast arcade action (10 to 15 FPS) such as Space Shooters, Snake, Pong, Breakout, Dungeon Crawlers, and Endless Runners. - Render an off-screen 2D grid buffer into Unicode block characters (`█`, `▓`, `▒`, `░`, `▀`, `▄`, `■`, `·`) or crisp retro glyphs and push updates via `textContainerUpgrade`. - Use a multi-container HUD: e.g., Container 1 (`textColor: 4`, full brightness) for the main playfield and Container 2 (`textColor: 3`) for Score, High Score, Lives, and Wave telemetry. - **Pipeline B: 4-Bit Grayscale Bitmap Canvas (`updateImageRawData`)**: - Best for turn-based games, virtual pets (Tamagotchi), puzzle boards, or localized sprite regions. - Full-screen image refreshes take ~400 to 800 ms over BLE (even with SDK 0.0.12+ automatic LZ4 compression), whereas small image containers (e.g., 200x100 px) update much faster. - Respect the **100 ms pacing floor** between `updateImageRawData` calls and guard with an `isSendingFrame` lock so BLE packets never queue up and cause input lag. - **Companion WebView Controller**: Since the app runs inside the phone's WebView, always render a synchronized retro 8-bit green-phosphor CRT canvas + touch D-pad/action buttons on the phone screen too. This lets users test in a standard browser, play via phone controls or temple/R1 gestures, and inspect live BLE telemetry. ### 6. Configure Manifest and Package with Even Hub CLI Every app requires an `app.json` manifest in the project root: ```json { "package_id": "com.developer.appname", "edition": "202601", "name": "App Name", "version": "1.0.0", "min_sdk_version": "0.0.16", "description": "Short description for Even Hub", "permissions": [] } ``` Use the workflow commands to test and ship: - Preview locally: `npx @evenrealities/evenhub-simulator http://localhost:5173` - Preview on hardware via QR: `evenhub qr --url http://:5173` - Package `.ehpk` bundle: `evenhub pack` For detailed class signatures and game engine templates, load the supplementary files `references/sdk-api-reference.md` and `references/game-rendering-guide.md`. ## Gotchas - **The `borderRdaius` Typo**: In several versions of `@evenrealities/even_hub_sdk`, the border radius property on `TextContainerProperty` and `ListContainerProperty` is misspelled `borderRdaius` in the underlying schema. Omit it if unused, or check the installed `.d.ts` version. - **`CLICK_EVENT` Normalized to `undefined`**: Single-press events often arrive with `eventType === undefined` instead of `0` (`OsEventTypeList.CLICK_EVENT`). Always check `if (eventType === OsEventTypeList.CLICK_EVENT || eventType === undefined)`. - **Mismatched `containerID` and `containerName`**: `textContainerUpgrade` and `updateImageRawData` silently fail or blank out the container if either `containerID` or `containerName` does not exactly match the values registered in `createStartUpPageContainer` or `rebuildPageContainer`. Also keep `containerName` to 16 characters or fewer. - **`textColor` is Brightness, Not Hue**: The G2 display is monochrome green. `textColor` (SDK 0.0.14+) accepts integer brightness levels `0` to `4` (default `4` is maximum brightness). Passing hex strings or values outside `0..4` throws a validation error before calling native. - **Overlapping BLE Frame Calls**: Never call `textContainerUpgrade` or `updateImageRawData` inside an unguarded `setInterval` without awaiting the previous frame promise. Always use an `isRendering` mutex flag so slow BLE frames drop gracefully rather than flooding the WebView bridge.