npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pebble-events

v1.2.0

Published

A library to fix the Pebble SDK's event services.

Downloads

26

Readme

pebble-events

pebble-events fixes the Pebble SDK's event system, supporting multiple independent subscriptions to a single event, and providing a context parameter to those that didn't already have one.

Everyone should use it!

Note: This library depends on Pebble SDK 3.14 or greater for the PBL_API_EXISTS macro.

Installation

pebble package install pebble-events

You must be using a new-style project; install the latest pebble tool and SDK and run pebble convert-project on your app if you aren't.

Usage

Usage mirrors the Pebble SDK, but with events_ prefixing all the function names. Subscription functions have the same signature as the SDK functions of the same name, except that they return an EventHandle that can be passed to the corresponding unsubscribe function.

To support usage where some data needs to be passed to the callback (for instance, a layer component that needs to subscribe to the tick service might need to pass a pointer to itself to that callback), you can use the _context variants. These have a signature similar to the non-context versions, but with a final void *context argument at the end.

App Focus Service

Wrapping the SDK AppFocusService, with the same behaviour.

EventHandle events_app_focus_service_subscribe_handlers(AppFocusHandlers handlers);
EventHandle events_app_focus_service_subscribe_handlers_context(EventFocusHandlers handlers, void *context);
EventHandle events_app_focus_service_subscribe(AppFocusHandler handler);
EventHandle events_app_focus_service_subscribe_context(EventFocusHandler handler, void *context);
void events_app_focus_service_unsubscribe(EventHandle handle);

Battery State Service

Wrapping the SDK BatteryStateService, with the same behaviour.

EventHandle events_battery_state_service_subscribe(BatteryStateHandler handler);
EventHandle events_battery_state_service_subscribe_context(EventBatteryStateHandler handler, void *context);
void events_battery_state_service_unsubscribe(EventHandle handle);

Connection Service

Wrapping the SDK ConnectionService, with the same behaviour. Note that the deprecated BluetoothConnectionService is not implemented.

EventHandle events_connection_service_subscribe(ConnectionHandlers conn_handlers);
EventHandle events_connection_service_subscribe_context(EventConnectionHandlers conn_handlers, void *context);
void events_connection_service_unsubscribe(EventHandle handle);

Health Service

Wrapping the SDK HealthService, with the same behaviour. Note that no _context variant is provided because the native version already has a context parameter.

EventHandle events_health_service_events_subscribe(HealthEventHandler handler, void *context);
bool events_health_service_events_unsubscribe(EventHandle handle);

Tick Timer Service

Wrapping the SDK TickTimerService, with similar behaviour. Unlike the TickTimerService, however, we will not necessarily call your handler immediately after subscription. We also may spuriously call your handler as a result of internal subscription management. However, in most cases we will call your handlers only on the requested time units. We will subscribe to the lowest-resolution time unit that permits this.

EventHandle events_tick_timer_service_subscribe(TimeUnits units, TickHandler handler);
EventHandle events_tick_timer_service_subscribe_context(TimeUnits units, EventTickHandler handler, void *context);
void events_tick_timer_service_unsubscribe(EventHandle handle);

Appmessage Service

The appmessage service is more complex than other services because once we open appmessage, we cannot change the inbox size. Therefore, to use the appmessage service, you must call events_app_message_request_inbox_size with your desired inbox size and events_app_message_request_outbox_size with your desired outbox size (if you don't send messages in one direction you don't need) to call it in that direction. The consumer app, and only the app, should call events_app_message_open once all libraries have been initialised. After this point, the two request functions will no longer work. If you are building a library, this may require you to add a library_prepare() method or similar to be called at app initialisation.

To subscribe to more than one appmessage callback at once, you can use events_app_message_subscribe_handlers. Otherwise, analogues to the SDK's standard appmessage functions are also available.

Keep in mind that you will receive all appmessages, even if you did not expect them. Check for a key that your code sends to ensure it is intended for you. If you could have multiple instances that should not all process a given message, include some means of determining which instance should handle it (e.g. if it's a request/response, a pointer cast to a uint32 could work).

typedef struct EventAppMessageHandlers {
	AppMessageOutboxSent sent;
	AppMessageOutboxFailed failed;
	AppMessageInboxReceived received;
	AppMessageInboxDropped dropped;
} EventAppMessageHandlers;
void events_app_message_request_inbox_size(uint32_t size);
void events_app_message_request_outbox_size(uint32_t size);
AppMessageResult events_app_message_open(void);
EventHandle events_app_message_subscribe_handlers(EventAppMessageHandlers handlers, void *context);
void events_app_message_unsubscribe(EventHandle handle);

// For consistency with the SDK.
EventHandle events_app_message_register_outbox_sent(AppMessageOutboxSent sent_callback, void *context);
EventHandle events_app_message_register_outbox_failed(AppMessageOutboxFailed failed_callback, void *context);
EventHandle events_app_message_register_inbox_received(AppMessageInboxReceived received_callback, void *context);
EventHandle events_app_message_register_inbox_dropped(AppMessageInboxDropped dropped_callback, void *context);

Accelerometer Tap Service

Wrapping the Tap part of the SDK AccelerometerService, with the same behaviour.

EventHandle events_accel_tap_service_subscribe(AccelTapHandler handler);
EventHandle events_accel_tap_service_subscribe_context(EventAccelTapHandler handler, void *context);
void events_accel_tap_service_unsubscribe(EventHandle handle);

Unobstructed Area Service

Wrapping the SDK UnobstructedAreaService, with the same behaviour. Note that no _context variant is provided because the native version already has a context parameter.

EventHandle events_unobstructed_area_service_subscribe(UnobstructedAreaHandlers handlers, void *context);
void events_unobstructed_area_service_unsubscribe(EventHandle handle);