Class: Toybox.AntPlus.LightNetwork

Overview

A class representing a network of bike lights

Example:

A basic example of LightNetwork and LightNetworkListener setup

using Toybox.AntPlus;
class MyLightNetworkListener extends AntPlus.LightNetworkListener {
    var mNetworkState = 0;

    function onLightNetworkStateUpdate(data) {
        mNetworkState = data;
    }
}

// In app class…
    function initialize() {
        mLightNetworkListener = new MyLightNetworkListener();
        mLightNetwork = new AntPlus.LightNetwork(mLightNetworkListener);
    }

    function onUpdate(dc) {
        // Call parent's onUpdate(dc) to redraw the layout
        View.onUpdate(dc);

        if (null != mLightNetworkListener.mNetworkState) {
            dc.drawText(
                10,
                10,
                Gfx.FONT_TINY,
                mLightNetworkListener.mNetworkState.toString(),
                Gfx.TEXT_JUSTIFY_LEFT);
        }

        if (mode < 15) {
            mode++;
        }
        else {
            mode = 0;
        }
        mLightNetwork.setHeadlightsMode(mode);
    }

Since:

API Level 2.2.0

Supported Devices:

Instance Method Summary collapse

Instance Method Details

getBikeLights() as Lang.Array<AntPlus.LightNetworkState> or Null

Get a list of lights in the network.

Returns:

Since:

API Level 2.2.0

getNetworkMode() as AntPlus.LightNetworkMode

Get the light network mode.

Returns:

Since:

API Level 2.2.0

getNetworkState() as AntPlus.LightNetworkState

Get the light network state.

Returns:

Since:

API Level 2.2.0

initialize(listener as AntPlus.LightNetworkListener or Null)

Constructor

Parameters:

  • listener(AntPlus.LightNetworkListener)

    The light network instance optionally takes an extension of the LightNetworkListener class as a parameter. null can be passed in instead if the user plans to only poll for data using the get* methods.

Since:

API Level 2.2.0

restoreHeadlightsNetworkModeControl() as Void

Bring all headlights under the control of whichever light network mode has been chosen by the user.

Since:

API Level 2.2.0

restoreTaillightsNetworkModeControl() as Void

Bring all taillights under the control of whichever light network mode has been chosen by the user.

Since:

API Level 2.2.0

setHeadlightsMode(mode as AntPlus.LightMode) as Void

Tell all headlights to enter the same mode.

You should check the capable modes of each headlight in the network before sending light modes, as lights will ignore commands to go into modes that they do not support. Lights whose modes are set here will not be controlled by the Light Network Mode until they are restored OR until the user changes the Light Network Mode outside of ConnectIQ.

Parameters:

Since:

API Level 2.2.0

setTaillightsMode(mode as AntPlus.LightMode) as Void

Tell all taillights to enter the same mode.

You should check the capable modes of each taillight in the network before sending light modes, as lights will ignore commands to go into modes that they do not support. Lights whose modes are set here will not be controlled by the Light Network Mode until they are restored OR until the user changes the Light Network Mode outside of ConnectIQ.

Parameters:

Since:

API Level 2.2.0

toggleSignalLight(left as Lang.Boolean) as Void

A signal switch for right and left signals.

  • If signal light is engaged, disengage it.

  • If signal light is disengaged, engage it.

*This will automatically disengage the opposite signal if it is currently engaged.

Parameters:

  • left(Lang.Boolean)
    • true to control left signal

    • false to control right signal

Since:

API Level 2.2.0


Generated Sep 23, 2024, 3:32:48 PM