Module: Toybox.ActivityRecording

Overview

The Activity Recording module will allow Apps to access the FIT file recording capabilities of the device.

Apps can use this module to allow the user to start and stop recordings, create laps, and save recorded data. SPORT_* and SUB_SPORT_* constants are provided as enums.

The SPORT_* defines the type of activity, but is not guaranteed to change device behavior. This may cause different algorithms to be applied to the sensor data. For example, a device that does not natively support SPORT_MULTISPORT recording will not gain SPORT_MULTISPORT transition features. However, the FIT file can be defined as SPORT_MULTISPORT and MULTI_SPORT algorithms may be applied to the sensor data.

SUB_SPORT_* allows for clarification of sport when recording.

See Also:

Example:

using Toybox.ActivityRecording;
using Toybox.WatchUi
var session = null;                                             // set up session variable

// use the select Start/Stop or touch for recording
function onSelect() {
   if (Toybox has :ActivityRecording) {                         // check device for activity recording
       if ((session == null) || (session.isRecording() == false)) {
           session = ActivityRecording.createSession({          // set up recording session
                 :name=>"Generic",                              // set session name
                 :sport=>Activity.SPORT_GENERIC,                // set sport type
                 :subSport=>Activity.SUB_SPORT_GENERIC          // set sub sport type
           });
           session.start();                                     // call start session
       }
       else if ((session != null) && session.isRecording()) {
           session.stop();                                      // stop the session
           session.save();                                      // save the session
           session = null;                                      // set session control variable to null
       }
   }
   return true;                                                 // return true for onSelect function
}

Since:

API Level 1.0.0

App Types:

  • Watch App

  • Background

Supported Devices:

Requires Permission:

  • Fit

Classes Under Namespace

Classes: Session

Constant Summary

Sport1

This has been deprecated

This enum may be removed after System 8.

Since:

API Level 1.0.0

See Also:

Name Value Since Description See Also
SPORT_GENERIC 0

API Level 1.0.0

Sport used for sports not on the list

SPORT_RUNNING 1

API Level 1.0.0

Sport used for running

SPORT_CYCLING 2

API Level 1.0.0

Sport used for multi-sport transitions

SPORT_TRANSITION 3

API Level 1.0.0

SPORT_FITNESS_EQUIPMENT 4

API Level 1.0.0

Sport used for ANT enabled exercise equipment

SPORT_SWIMMING 5

API Level 1.0.0

Sport used for swimming

SPORT_BASKETBALL 6

API Level 1.0.0

Sport used for basketball

SPORT_SOCCER 7

API Level 1.0.0

Sport used for soccer

SPORT_TENNIS 8

API Level 1.0.0

Sport used for Tennis

SPORT_AMERICAN_FOOTBALL 9

API Level 1.0.0

Sport used for American football

SPORT_TRAINING 10

API Level 1.0.0

Sport used for activities such as strength training, cardio, etc

SPORT_WALKING 11

API Level 1.0.0

Sport used for walking

SPORT_CROSS_COUNTRY_SKIING 12

API Level 1.0.0

Sport used for cross-country skiing

SPORT_ALPINE_SKIING 13

API Level 1.0.0

Sport used for alpine skiing

SPORT_SNOWBOARDING 14

API Level 1.0.0

Sport used for snowboarding

SPORT_ROWING 15

API Level 1.0.0

Sport used for rowing

SPORT_MOUNTAINEERING 16

API Level 1.0.0

Sport used for mountaineering

SPORT_HIKING 17

API Level 1.0.0

Sport used for hiking

SPORT_MULTISPORT 18

API Level 1.0.0

Sport used for multi-sport events

SPORT_PADDLING 19

API Level 1.0.0

Sport used for paddling

Sport2

This has been deprecated

This enum may be removed after System 8.

Since:

API Level 1.0.0

See Also:

Name Value Since Description See Also
SPORT_FLYING 20

API Level 3.0.10

Sport used for flying

SPORT_E_BIKING 21

API Level 3.0.10

Sport used for riding an e-bike

SPORT_MOTORCYCLING 22

API Level 3.0.10

Sport used for motorcycling

SPORT_BOATING 23

API Level 3.0.10

Sport used for boating

SPORT_DRIVING 24

API Level 3.0.10

Sport used for driving

SPORT_GOLF 25

API Level 3.0.10

Sport used for golfing

SPORT_HANG_GLIDING 26

API Level 3.0.10

Sport used for hang gliding

SPORT_HORSEBACK_RIDING 27

API Level 3.0.10

Sport used for horseback riding

SPORT_HUNTING 28

API Level 3.0.10

Sport used for hunting

SPORT_FISHING 29

API Level 3.0.10

Sport used for fishing

SPORT_INLINE_SKATING 30

API Level 3.0.10

Sport used for inline skating

SPORT_ROCK_CLIMBING 31

API Level 3.0.10

Sport used for rock climbing

SPORT_SAILING 32

API Level 3.0.10

Sport used for sailing

SPORT_ICE_SKATING 33

API Level 3.0.10

Sport used for ice skating

SPORT_SKY_DIVING 34

API Level 3.0.10

Sport used for sky diving

SPORT_SNOWSHOEING 35

API Level 3.0.10

Sport used for showshoeing

SPORT_SNOWMOBILING 36

API Level 3.0.10

Sport used for snowmobiling

SPORT_STAND_UP_PADDLEBOARDING 37

API Level 3.0.10

Sport used for paddle boarding

SPORT_SURFING 38

API Level 3.0.10

Sport used for surfing

SPORT_WAKEBOARDING 39

API Level 3.0.10

Sport used for wakeboarding

SPORT_WATER_SKIING 40

API Level 3.0.10

Sport used for water skiing

SPORT_KAYAKING 41

API Level 3.0.10

Sport used for kayaking

SPORT_RAFTING 42

API Level 3.0.10

Sport used for rafting

SPORT_WINDSURFING 43

API Level 3.0.10

Sport used for windsurfing

SPORT_KITESURFING 44

API Level 3.0.10

Sport used for kite surfing

SPORT_TACTICAL 45

API Level 3.0.10

Sport used for tactical

SPORT_JUMPMASTER 46

API Level 3.0.10

Sport used for jumpmaster

SPORT_BOXING 47

API Level 3.0.10

Sport used for boxing

SPORT_FLOOR_CLIMBING 48

API Level 3.0.10

Sport used for climbing

SPORT_BASEBALL 49

API Level 3.0.10

Sport used for baseball

SPORT_SOFTBALL_FAST_PITCH 50

API Level 3.0.10

Sport used for fast pitch softball

SPORT_SOFTBALL_SLOW_PITCH 51

API Level 3.0.10

Sport used for slow pitch softball

SPORT_SHOOTING 56

API Level 3.0.10

Sport used for shooting

SPORT_AUTO_RACING 57

API Level 3.0.10

Sport used for auto racing

SubSport

This has been deprecated

This enum may be removed after System 8.

Since:

API Level 1.0.0

Name Value Since Description See Also
SUB_SPORT_GENERIC 0

API Level 1.0.0

Sub-sport used if no other sub-sport is applicable

SUB_SPORT_TREADMILL 1

API Level 1.0.0

Sub-sport for Running and Fitness Equipment

SUB_SPORT_STREET 2

API Level 1.0.0

Sub-sport for Running

SUB_SPORT_TRAIL 3

API Level 1.0.0

Sub-sport for Running

SUB_SPORT_TRACK 4

API Level 1.0.0

Sub-sport for Running

SUB_SPORT_SPIN 5

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_INDOOR_CYCLING 6

API Level 1.0.0

Sub-sport for Cycling and Fitness Equipment

SUB_SPORT_ROAD 7

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_MOUNTAIN 8

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_DOWNHILL 9

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_RECUMBENT 10

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_CYCLOCROSS 11

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_HAND_CYCLING 12

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_TRACK_CYCLING 13

API Level 1.0.0

Sub-sport for Cycling

SUB_SPORT_INDOOR_ROWING 14

API Level 1.0.0

Sub-sport for Rowing and Fitness Equipment

SUB_SPORT_ELLIPTICAL 15

API Level 1.0.0

Sub-sport for Fitness Equipment

SUB_SPORT_STAIR_CLIMBING 16

API Level 1.0.0

Sub-sport for Fitness Equipment

SUB_SPORT_LAP_SWIMMING 17

API Level 1.0.0

Sub-sport for Swimming

SUB_SPORT_OPEN_WATER 18

API Level 1.0.0

Sub-sport for Swimming

SUB_SPORT_FLEXIBILITY_TRAINING 19

API Level 1.0.0

Sub-sport for Training

SUB_SPORT_STRENGTH_TRAINING 20

API Level 1.0.0

Sub-sport for Training

SUB_SPORT_WARM_UP 21

API Level 1.0.0

Sub-sport for Activity Warm-up

SUB_SPORT_MATCH 22

API Level 1.0.0

Sub-sport for Sports with Matches (e.g. Tennis)

SUB_SPORT_EXERCISE 23

API Level 1.0.0

Sub-sport for Exercise

SUB_SPORT_CHALLENGE 24

API Level 1.0.0

Sub-sport for a Sport Challenge

SUB_SPORT_INDOOR_SKIING 25

API Level 1.0.0

Sub-sport for Fitness Equipment

SUB_SPORT_CARDIO_TRAINING 26

API Level 1.0.0

Sub-sport for Training

TimerEventType

Since:

API Level 1.0.0

Name Value Since Description See Also
TIMER_EVENT_START 0

API Level 3.0.10

Timer start event

TIMER_EVENT_STOP 1

API Level 3.0.10

Timer stop event

TIMER_EVENT_PAUSE 2

API Level 3.0.10

Timer pause event

TIMER_EVENT_RESUME 3

API Level 3.0.10

Timer resume event

TIMER_EVENT_LAP 4

API Level 3.0.10

Timer lap event

TIMER_EVENT_RESET 5

API Level 3.0.10

Timer reset

TIMER_EVENT_WORKOUT_STEP_COMPLETE 6

API Level 3.0.10

Workout step complete

TIMER_EVENT_NEXT_MULTISPORT_LEG 7

API Level 3.0.10

Multisport leg started

Typedef Summary collapse

Instance Method Summary collapse

Instance Method Details

createSession(options as { :sport as ActivityRecording.Sport or Activity.Sport, :subSport as ActivityRecording.SubSport or Activity.SubSport, :name as Lang.String, :poolLength as Lang.Float, :sensorLogger as SensorLogging.SensorLogger, :autoLap as { :type as Lang.Symbol, :entry as [ Position.Location, Position.Location ], :exit as [ Position.Location, Position.Location ] } }) as ActivityRecording.Session

Create a Session object with options determined by the caller.

Only one Session object is allowed to exist at a time. If there is an existing object that has not been closed using the save() or discard() methods, this method will return that object instead of creating a new one. On some products running the 1.x virtual machine, creating a Session object requires a large memory allocation. To free this memory, the Session must first be successfully saved or discarded, and then app references to the Session object should be set to null.

Parameters:

  • options(Lang.Dictionary)

    A Dictionary containing session creation options.

    • :sport(Lang.Number)

      The primary sport being recorded (SPORT_GENERIC by default).

    • :subSport(Lang.Number)

      The sport subcategory being recorded (SUB_SPORT_GENERIC by default).

    • :name(Lang.String)

      Required. This is the name that will be associated with the sport being recorded. The suggested maximum length of the name is 15 characters (some devices support longer names).

    • :poolLength(Lang.Float)

      This is the length of the pool in meters for this activity. If this session object is configured with :sport=>SPORT_SWIMMING and :subSport=>SUB_SPORT_LAP_SWIMMING, this option is required to configure the system in this mode. If it is not provided, activity data may have undefined behavior. For all other sport modes, this option is ignored.

    • :autoLap(Lang.Dictionary)

      A dictionary containing auto-lap detection options. If present, this dictionary must have a :type key; If the value of :type is :lines, the :entry and :exit keys are required. The values associated with :entry and :exit describe the endpoints of the auto lap entry and exit line segments, each being defined as an Array of two Location objects. (added in 3.0.10)

    • :sensorLogger(SensorLogging.SensorLogger)

      The SensorLogger to use to record this session.

Example:

Create a Session with auto lap detection using entry/exit lines

using Toybox.ActivityRecording;
function createSession() {
    var session = ActivityRecording.createSession({  // set up recording session
        :name=>"Race",                               // set session name
        :sport=>Activity.SPORT_GENERIC,              // set sport type
        :subSport=>Activity.SUB_SPORT_GENERIC,       // set sub sport type
        :autoLap=>{                                  // auto lap configuration
            :type=>:lines,                           // auto lap using entry/exit lines
            :exit=>[loc1, loc2],                     // set exit of auto lap staging box (typically the finish line)
            :entry=>[loc3, loc4],                    // set entrance of auto lap staging box (typically before the finish line)
            :autoStart=>true                         // auto start using the entry/exit lines
        }
    });
    return session;
}

Returns:

  • ActivityRecording.Session

    A new Session object, or the existing Session object if a Session is active and has not been saved or discarded.

Since:

API Level 1.0.0

Throws:


Generated Apr 17, 2024 9:40:37 AM