particle-iot / particle-iot/docs

System.on() and System.off(); needs to be documented more completely

Open
#757 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
148
Forks
266
Avg merge
14h 41m
Merged PRs (30d)
16

Description

https://github.com/particle-iot/firmware/blob/develop/wiring/inc/spark_wiring_system.h#L219-L241

    static bool on(system_event_t events, void(*handler)(system_event_t, int,void*)) {
        return !system_subscribe_event(events, reinterpret_cast<system_event_handler_t*>(handler), nullptr);
    }

    static bool on(system_event_t events, void(*handler)(system_event_t, int)) {
        return system_subscribe_event(events, reinterpret_cast<system_event_handler_t*>(handler), NULL);
    }

    static bool on(system_event_t events, void(*handler)(system_event_t)) {
        return system_subscribe_event(events, reinterpret_cast<system_event_handler_t*>(handler), NULL);
    }

    static bool on(system_event_t events, void(*handler)()) {
        return system_subscribe_event(events, reinterpret_cast<system_event_handler_t*>(handler), NULL);
    }

    static void off(void(*handler)(system_event_t, int,void*)) {
        system_unsubscribe_event(all_events, handler, nullptr);
    }

    static void off(system_event_t events, void(*handler)(system_event_t, int,void*)) {
        system_unsubscribe_event(events, handler, nullptr);
    }

You can logically OR system events together with System.on(event1 | event2 | event3, handler);

To unregister a system handler, you can call System.off(handler) when you have previously called System.on(event1 | event2 | event3, handler); to unregister all events, or System.off(event3, handler); to unregister just event3

Note: event1,2,3 just temp names, refer to system events in docs for all available events.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the overloads in wiring/inc/spark_wiring_system.h#L219-L241 and inspect the existing System event documentation. Document combining events with bitwise OR, the available on() handler forms, and how off() removes all or selected event subscriptions. Done means the documented behavior matches these overloads and examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.