Pebble.Compass
Read compass heading from watches with a magnetometer.
Request an initial reading in init, then subscribe for live heading updates.
import Pebble.Compass as Compass
type Msg
= GotHeading (Result Compass.Error Compass.Heading)
| HeadingChanged Compass.Heading
init _ =
( model, Compass.current GotHeading )
subscriptions _ =
Compass.onChange HeadingChanged
For a runnable example, use the watch-demo-compass project template in the IDE.
Native Pebble C API
- CompassService on developer.repebble.com
Union Types
Error
type Error
= Unavailable
| InvalidReadingCompass errors returned at the app boundary.
Type Aliases
Heading
type alias Heading =
{ degrees : Float
, isValid : Bool
}A compass heading in degrees (0–360) when valid.
Commands
current
current : (Result Error Heading -> msg) -> Cmd msgRequest the current heading once.
Subscriptions
onChange
onChange : (Heading -> msg) -> Sub msgReceive heading updates when the compass service reports changes.