JavaScript SDK (@intarva/sdk)

The JavaScript SDK is the high-level orchestration layer for your simulation. Use it to build user interfaces, automate test sequences, or coordinate multi-board interactions.

1. Component API

Every component in the Intarva library has a corresponding JavaScript class that provides high-level methods.

Class Primary Methods & Events
Pin(id) read(), write(val), toggle(). Events: 'change'.
Button(id) isPressed(). Events: 'press', 'release'.
Servo(id) angle(deg). Sets position from 0 to 180 degrees.
NeoPixel(id, count) set(index, [r,g,b]), show(), clear().
OLED() text(str, x, y), rect(), line(), show().

2. The Event Emitter System

The SDK uses an asynchronous event-driven architecture. You can listen for hardware events without blocking the main simulation loop.

import { Button, Pin } from '@intarva/sdk';

const btn = new Button('GP14');
const led = new Pin('GP15');

// Toggle LED whenever button is pressed
btn.on('press', () => {
    led.toggle();
    console.log('Button pressed, LED toggled!');
});
            

3. Global Engine Hooks

For advanced users, the SDK provides access to the core engine’s lifecycle and safety monitoring.

  • onSafetyError(callback): Triggers when the engine detects a short circuit or over-voltage.
  • onPinStateChange(callback): Triggers for any pin change in the entire netlist.
  • setNetVoltage(netId, volts): Forces a specific voltage onto a net (simulates power injection).