Pebble.System
System-state commands and subscriptions sourced from Pebble event services.
Poll once in init, then subscribe to live updates for battery and phone link.
import Pebble.System as System
type Msg
= GotBattery Int
| BatteryChanged Int
| GotConnection Bool
| ConnectionChanged Bool
init _ =
( model
, Cmd.batch
[ System.batteryLevel GotBattery
, System.connectionStatus GotConnection
]
)
subscriptions _ =
Sub.batch
[ System.onBatteryChange BatteryChanged
, System.onConnectionChange ConnectionChanged
]
For a runnable example, use the watch-demo-system project template in the IDE.
Native Pebble C API
- BatteryStateService on developer.repebble.com
- ConnectionService on developer.repebble.com
Commands
batteryLevel
batteryLevel : (Int -> msg) -> Cmd msgRequest the current battery level as a percentage from 0 to 100.
connectionStatus
connectionStatus : (Bool -> msg) -> Cmd msgRequest whether the watch is connected to the phone.
Subscriptions
onBatteryChange
onBatteryChange : (Int -> msg) -> Sub msgReceive the current battery percentage when battery state changes.
onConnectionChange
onConnectionChange : (Bool -> msg) -> Sub msgReceive whether the watch is connected to the phone when connection state changes.