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

Union Types

Error

type Error
    = Unavailable
    | InvalidReading

Compass 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 msg

Request the current heading once.

Subscriptions

onChange

onChange : (Heading -> msg) -> Sub msg

Receive heading updates when the compass service reports changes.