Module: Toybox::Attention

Overview

The Attention module provides the ability to play pre-defined sounds, methods for managing vibration, and control of the back light.

Not all devices fully support this module, so has checks are recommended. For example, the vivoactive does not have a tone generator and will trigger an error if an app attempts to play sounds.

Since:

  • 1.0.0

App Types:

  • Data Field

  • Widget

  • App

  • Audio Content Provider App

Defined Under Namespace

Classes: VibeProfile

Constant Summary

TONE_KEY = 0

Indicates that a key was pressed

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_START = 1

Indicates that an activity has started

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_STOP = 2

Indicates that an activity has stopped

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_MSG = 3

Indicates that a message is available

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_ALERT_HI = 4

An alert ending with a high note

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_ALERT_LO = 5

An alert ending with a low note

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_LOUD_BEEP = 6

A loud beep

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_INTERVAL_ALERT = 7

Indicates a change in interval

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_ALARM = 8

Indicates an alarm has triggered

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_RESET = 9

Indicates that the activity was reset

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_LAP = 10

Indicates that the user has completed a lap

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_CANARY = 11

An annoying sound to get the users attention

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_TIME_ALERT = 12

An alert that a time threshold has been met

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_DISTANCE_ALERT = 13

An alert that a distance threshold has been met

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_FAILURE = 14

Indicates that the activity was a failure

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_SUCCESS = 15

Indicates that the activity was a success

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_POWER = 16

The power on tone

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_LOW_BATTERY = 17

Indicates that the device has low battery power

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

TONE_ERROR = 18

Indicates an error occurred

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR

Instance Method Summary collapse

Instance Method Details

backlight(onOff) ⇒ Object

Turn the back light on or off.

The back light will always respect the back light timeout settings on the device. Behavior of this feature may also change depending on device settings. For example, if a device is set to activate the back light with key presses, the back light will toggle on with key presses in a Connect IQ app even if the app is written to turn off the back light with a key press.

Examples:

Turn on the back light

if (Attention has :backlight) {
    Attention.backlight(true);
}

Parameters:

Since:

  • 1.0.0

Supported Devices:

  • All devices except Edge 130


2544
2545
# File 'Monkeybrains.rb', line 2544

def backlight(onOff)
end

playTone(tone) ⇒ Object

Play a built-in tone.

Examples:

using Toybox.Attention;
if (Attention has :playTone) {
   Attention.playTone(TONE_LOUD_BEEP);
}

Parameters:

Since:

  • 1.0.0

Supported Devices:

  • All devices except Approach S60 / vivoactive / vivoactive HR


2459
2460
# File 'Monkeybrains.rb', line 2459

def playTone(tone)
end

vibrate(vibeProfiles) ⇒ Object

Note:

Forerunner devices do not support vibration patterns. Vibration may still be used, but the vibration will always run at the same duty cycle.

Engage the vibration motor.

The vibrate method takes an Array containing at least one VibeProfile object, up to a maximum of 8, and runs them in sequence.

Examples:

Vibrate in an on/off pattern

if (Attention has :vibrate) {
    vibeData =
    [
        new Attention.VibeProfile(50, 2000), // On for two seconds
        new Attention.VibeProfile(0, 2000),  // Off for two seconds
        new Attention.VibeProfile(50, 2000), // On for two seconds
        new Attention.VibeProfile(0, 2000),  // Off for two seconds
        new Attention.VibeProfile(50, 2000)  // on for two seconds
    ];
}
Attention.vibrate(vibeData);

Parameters:

See Also:

Since:

  • 1.0.0

Supported Devices:

  • All devices except Edge / Oregon / Rino


2526
2527
# File 'Monkeybrains.rb', line 2526

def vibrate(vibeProfiles)
end