Services

Gyroscope

Gyroscope service

Create or retrieve this service with page.gyroscope(**properties). Ruflet reuses the registered service unless you supply a different id.

Example

rotation = text(value: "Rotate the device")
page.add(rotation)
page.gyroscope(
  interval: 200,
  on_reading: ->(event) { page.update(rotation, value: event.data.inspect) },
  on_error: ->(event) { page.update(rotation, value: event.data.to_s) }
)

Page accessor

  • page.gyroscope(**props)

Properties

  • cancel_on_error — Sets the cancel on error property.
  • data — Arbitrary value you can attach to the control and read back in handlers.
  • enabled — Sets the enabled property.
  • interval — Sets the interval property.
  • key — Stable identity used to preserve state across rebuilds.

Events

  • on_error — Fired when an error occurs.
  • on_reading — Fired on reading.

Result and error handling

Client calls are asynchronous. When a method accepts on_result:, handle both callback values: |result, error|. Availability and returned data can vary by platform.

Common service API

The service also supports the common Ruflet control API: attach_handler(event_name, handler), children, emit(event_name, event), has_handler?(event_name), id, merge_props(values = ...), on(event_name, &block), props, runtime_page, runtime_page=, to_patch, type, wire_id, wire_id=.

Use the named methods above for application code; common control methods mainly support event registration, updates, and runtime integration.

Wire reference

  • Service helper: gyroscope
  • Wire type: gyroscope

Protected device access

Declare motion access in services.yaml, then rebuild the native client:

services:
  - motion:
      description: Explain why your app reads motion sensor data.