Skip to content

Latest commit

 

History

History
78 lines (47 loc) · 10.6 KB

design.md

File metadata and controls

78 lines (47 loc) · 10.6 KB

Product and device design

Product principles (agreed)

Simple to start. Open to explore. A child should be able to drag blocks, connect a board and upload a program without knowing a chipset, board model, runtime or wire protocol.

Program first, hardware later. The workspace and Python source exist independently of any physical device. Users may write a program before deciding which board is suitable, and adapt board-specific calls later.

Discoverability is a feature. Keep all supported boards and capabilities visible, grouped by native API and hardware capability. The toolbox is also a map of what can be programmed: discovering that an existing LEGO SPIKE hub is supported, or learning what another board can do, is a valuable experience in itself.

Unify the experience, preserve the differences. Use native APIs faithfully. Share transport, lifecycle and UI where appropriate; do not invent a lowest-common-denominator hardware API or impose board-specific editing silos.

Hardware abstraction boundaries

Native primitives, object-based components, composed applications. Keep the real hardware APIs visible instead of making every block a custom class.

  • Native hardware primitives (Pin, ADC, PWM, I2C, SPI, UART) should map directly to firmware APIs. Convenient pin-based reads and writes can coexist with native object creation.
  • Use an explicit, named object for a component when it owns a resource, retains configuration or state across operations, or has an initialization/operation/release lifecycle. Configure it once, then operate on the same instance. Avoid implicit global dictionaries keyed by pin for such components. Examples: servo, passive buzzer, ultrasonic sensor, rotary encoder, display and MQTT client.
  • Prefer simple functions or commands for one-shot operations, math, timing and convenient access to fixed board peripherals. Do not create wrapper classes merely for uniformity.
  • Let applications (robot cars, arms, irrigation) be composed by users from blocks, variables and functions. Expose capabilities without imposing a universal hardware abstraction.
  • Toolbox grouping is independent of implementation: PWM, buzzer and servo can share a category and source module. Share a component class when the physical interface is identical; label the different command interpretations explicitly rather than inventing separate drivers or software modes. A positional and continuous-rotation PWM servo use the same signal but interpret it differently.
  • Keep application policies outside device drivers: positional servo drivers set target angles; gradual motion, duration, easing and scheduling belong to ordinary math, loop and timing blocks. Expose native timing capabilities when hardware genuinely provides them; do not present synthesized behavior as native capability.
  • Prefer simple code and explicit lifecycle and timing. Distinguish commanded values from measured feedback; do not imply physical guarantees or invent native APIs.

See servo for the positional and continuous-rotation component design.

Separate concerns

  • Program: workspace, generated or manually edited Python, project libraries. May depend on board-specific APIs, but is not bound to a board identity.
  • Connected device: actual physical connection, verified protocol/runtime, observed hardware information and available device operations.
  • Deployment preferences: last explicitly chosen device and protocol-specific options, such as a SPIKE program slot. These are not a required part of the project format.
  • Firmware installation: a separate operation that chooses a compatible firmware image based on verified hardware facts and explicit choices where detection cannot resolve an ambiguity.

Compatibility diagnostics may be added later. They should inform rather than restrict editing. Device information may enrich the workspace but must not hide, disable, delete or rewrite other blocks.

Upload experience

  1. Click Upload and run. Reuse the active device when available; otherwise ask the browser for a serial port.
  2. Inspect the selected physical port and establish the appropriate protocol using verified USB identity and protocol handshakes. Do not infer the device from Python source or block types.
  3. For a confirmed ordinary MicroPython REPL, upload directly without requiring a Matrix:bit, generic ESP32 or other board-model choice. Preserve the current main.py and library deployment semantics.
  4. For a verified SPIKE Prime HubOS 3 connection, show a first-use device confirmation dialog. Identify the hub, firmware version, and known capabilities; allow choosing a program slot before any clearing, writing or starting operation. Explain that the selected slot will be overwritten. Only show slot counts, occupancy or connected peripherals if supported by verified protocol information or model documentation.
  5. Keep the confirmed connection and its deployment options for subsequent uploads. Make the active device and relevant options visible near the upload controls, with an explicit Change device action. Changing the slot is separate from changing the device.
  6. If a connection is lost, show the disconnected state. Reuse a permitted port only after revalidating its identity/protocol; never silently choose another physical device based on a matching VID/PID. Remember preferences locally as hints, not as proof of identity or authorization to write. A different hub must be confirmed independently where identity is uncertain.
  7. Unsupported or ambiguous devices receive an actionable message or an explicit protocol selection if safe. Do not fall back to sending REPL control characters to a recognized LEGO hub with unsupported firmware.

A SPIKE confirmation should be a review of a detected device, not a general board-selection wizard. Cancellation must not overwrite a program or change the confirmed active target. Slots 0–19 are supported; the selector remembers the last chosen slot locally as a default, not as an identity. The active connection is retained until disconnect or explicit change.

Firmware installation is different from uploading Python

A working MicroPython runtime already supplies a deployment protocol. Its exact retail board model need not be known to upload Python. Installing firmware, however, replaces existing programs and files, and requires a compatible image, flash configuration and memory variant. Generic ESP32 and Matrix:bit can share an image where compatibility is established; chip/flash size alone does not prove board identity or PSRAM wiring. Prefer automatic matching where safe, ask only for unresolved material differences, and keep explicit confirmation before destructive installation. Do not automatically install firmware on a port that fails the REPL handshake.

Current implementation and boundaries

The toolbox remains universal and the project format has no required target. USB selection routes known SPIKE Prime devices to the HubOS information handshake and other non-LEGO ports to the existing Raw REPL deployment path. Other LEGO USB devices are rejected rather than sent REPL control bytes. Generic serial monitoring is not proof of MicroPython compatibility; upload validates the REPL before writing. Slot occupancy, attached peripheral detection, stable physical identity across reconnects, and automatic firmware installation are not implemented. SPIKE does not support project library uploads in this path. Browser and physical-device testing of the new selection flow remains necessary.

See SPIKE Prime and Firmware installation for current behavior.

Editor layout

The universal Blocks workspace stays on the left. The right column contains Device above Code, with a vertical splitter. Device owns connection, deployment, runtime controls and console output; Code owns source display, editing, generation errors and download. Code can collapse without changing the source or upload availability. Firmware installation remains a separate top-level action. SPIKE stop targets the last successfully started slot on the current connection, not a newly chosen upload slot. Interactive serial input and soft reset are shown only for serial sessions; SPIKE has its own stop action. The editor does not infer whether an uploaded program is still running.

The Device header is a compact horizontal layout: title and small stable device identity on the left, icon toolbar on the right, vertically centered. The subtitle shows only the connection identity and selected slot, never transient messages. The console is the Device panel body; it has no additional visible title and its clear action floats at the top right of the output area. The interactive serial input retains Send beside the input. Progress, errors and acknowledgments appear in a single replaceable toast outside the panel, with no status strip or reserved height. Progress stays until replaced, errors until dismissed, and ordinary acknowledgments expire after three seconds. A start acknowledgment does not imply the program is still running.

The SPIKE slot dialog presents slots 0–19 as a five-column native radio grid, with the selected slot highlighted; occupancy is not inferred. The separator between Device and Code has a transparent background, with its drag handle still visible in both themes.

Blocks, Device and Code share the same 64px minimum header height, padding and vertical alignment. Headers may grow when controls wrap in narrow layouts; they do not shrink independently.

The SPIKE confirmation dialog presents a local Hub illustration, detected firmware and RPC versions, and six informational capability tiles in the left column, with program slots, overwrite warning and confirmation actions in the right column. At viewport widths of 760px or less, the columns stack vertically in the same reading order. External peripherals are not inferred to be connected. The native radio grid, cancel/confirm behavior and saved slot preference remain unchanged. The dialog scrolls on short viewports and follows the editor theme.

Website

The homepage and /#/editor are routes served from index.html. See website architecture and project management.

Project notifications share the fixed bottom-right toast stack with device feedback, but use an independent channel. The project header has no transient status line. Explicit saves and imports show brief acknowledgments; successful autosaves are silent.

Reuse and extensibility

Prioritize ordinary block snippet collection and a native Python source-file/import workflow as separate capabilities. Defer user-defined Blockly blocks and visual class definitions until their interfaces and reuse model are understood. See reuse design.