pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AppFocusService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
    • Rocky
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

BatteryStateService

Determines when the battery state changes.

The BatteryStateService API lets you know when the battery state changes, that is, its current charge level, whether it is plugged and charging. It uses the BatteryChargeState structure to describe the current power state of Pebble.

Refer to the classio-battery-connection example, which demonstrates using the battery state service in a watchface.

Function Documentation

void battery_state_service_subscribe(BatteryStateHandler handler)

Subscribe to the battery state event service. Once subscribed, the handler gets called on every battery state change.

Parameters

handler

A callback to be executed on battery state change event

void battery_state_service_unsubscribe(void)

Unsubscribe from the battery state event service. Once unsubscribed, the previously registered handler will no longer be called.

BatteryChargeState battery_state_service_peek(void)

Peek at the last known battery state.

Returns

a BatteryChargeState containing the last known data

Data Structure Documentation

struct BatteryChargeState

Structure for retrieval of the battery charge state.

Data Fields

uint8_t charge_percent

A percentage (0-100) of how full the battery is.

bool is_charging

True if the battery is currently being charged. False if not.

bool is_plugged

True if the charger cable is connected. False if not.

Typedef Documentation

typedef void(* BatteryStateHandler)(BatteryChargeState charge)

Callback type for battery state change events.

Parameters

charge

the state of the battery BatteryChargeState

Need some help?

Functions

  • battery_state_service_subscribe
  • battery_state_service_unsubscribe
  • battery_state_service_peek

Data Structures

  • BatteryChargeState

Typedefs

  • BatteryStateHandler

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!