Barometer service
Create or retrieve this service with page.barometer(**properties). Ruflet reuses the registered service unless you supply a different id.
Example
pressure = text(value: "Waiting for pressure data")
page.add(pressure)
page.barometer(
interval: 500,
on_reading: ->(event) { page.update(pressure, value: "Pressure: #{event.data}") },
on_error: ->(event) { page.update(pressure, value: event.data.to_s) }
)
Page accessor
page.barometer(**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:
barometer - Wire type:
barometer
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.