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.

Examples:

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=>ActivityRecording.SPORT_GENERIC,       // set sport type
                 :subSport=>ActivityRecording.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
}

See Also:

Since:

  • 1.0.0

App Types:

  • App

  • Glance Support

  • Background Services

Requires Permission:

  • Fit

Defined Under Namespace

Classes: Session

Constant Summary

SPORT_GENERIC = 0

Sport used for sports not on the list

Since:

  • 1.0.0

SPORT_RUNNING = 1

Sport used for running

Since:

  • 1.0.0

SPORT_CYCLING = 2

Sport used for multi-sport transitions

Since:

  • 1.0.0

SPORT_TRANSITION = 3

Since:

  • 1.0.0

SPORT_FITNESS_EQUIPMENT = 4

Sport used for ANT enabled exercise equipment

Since:

  • 1.0.0

SPORT_SWIMMING = 5

Sport used for swimming

Since:

  • 1.0.0

SPORT_BASKETBALL = 6

Sport used for basketball

Since:

  • 1.0.0

SPORT_SOCCER = 7

Sport used for soccer

Since:

  • 1.0.0

SPORT_TENNIS = 8

Sport used for Tennis

Since:

  • 1.0.0

SPORT_AMERICAN_FOOTBALL = 9

Sport used for American football

Since:

  • 1.0.0

SPORT_TRAINING = 10

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

Since:

  • 1.0.0

SPORT_WALKING = 11

Sport used for walking

Since:

  • 1.0.0

SPORT_CROSS_COUNTRY_SKIING = 12

Sport used for cross-country skiing

Since:

  • 1.0.0

SPORT_ALPINE_SKIING = 13

Sport used for alpine skiing

Since:

  • 1.0.0

SPORT_SNOWBOARDING = 14

Sport used for snowboarding

Since:

  • 1.0.0

SPORT_ROWING = 15

Sport used for rowing

Since:

  • 1.0.0

SPORT_MOUNTAINEERING = 16

Sport used for mountaineering

Since:

  • 1.0.0

SPORT_HIKING = 17

Sport used for hiking

Since:

  • 1.0.0

SPORT_MULTISPORT = 18

Sport used for multi-sport events

Since:

  • 1.0.0

SPORT_PADDLING = 19

Sport used for paddling

Since:

  • 1.0.0

SPORT_FLYING = 20

Sport used for flying

Since:

  • 3.0.10

SPORT_E_BIKING = 21

Sport used for riding an e-bike

Since:

  • 3.0.10

SPORT_MOTORCYCLING = 22

Sport used for motorcycling

Since:

  • 3.0.10

SPORT_BOATING = 23

Sport used for boating

Since:

  • 3.0.10

SPORT_DRIVING = 24

Sport used for driving

Since:

  • 3.0.10

SPORT_GOLF = 25

Sport used for golfing

Since:

  • 3.0.10

SPORT_HANG_GLIDING = 26

Sport used for hang gliding

Since:

  • 3.0.10

SPORT_HORSEBACK_RIDING = 27

Sport used for horseback riding

Since:

  • 3.0.10

SPORT_HUNTING = 28

Sport used for hunting

Since:

  • 3.0.10

SPORT_FISHING = 29

Sport used for fishing

Since:

  • 3.0.10

SPORT_INLINE_SKATING = 30

Sport used for inline skating

Since:

  • 3.0.10

SPORT_ROCK_CLIMBING = 31

Sport used for rock climbing

Since:

  • 3.0.10

SPORT_SAILING = 32

Sport used for sailing

Since:

  • 3.0.10

SPORT_ICE_SKATING = 33

Sport used for ice skating

Since:

  • 3.0.10

SPORT_SKY_DIVING = 34

Sport used for sky diving

Since:

  • 3.0.10

SPORT_SNOWSHOEING = 35

Sport used for showshoeing

Since:

  • 3.0.10

SPORT_SNOWMOBILING = 36

Sport used for snowmobiling

Since:

  • 3.0.10

SPORT_STAND_UP_PADDLEBOARDING = 37

Sport used for paddle boarding

Since:

  • 3.0.10

SPORT_SURFING = 38

Sport used for surfing

Since:

  • 3.0.10

SPORT_WAKEBOARDING = 39

Sport used for wakeboarding

Since:

  • 3.0.10

SPORT_WATER_SKIING = 40

Sport used for water skiing

Since:

  • 3.0.10

SPORT_KAYAKING = 41

Sport used for kayaking

Since:

  • 3.0.10

SPORT_RAFTING = 42

Sport used for rafting

Since:

  • 3.0.10

SPORT_WINDSURFING = 43

Sport used for windsurfing

Since:

  • 3.0.10

SPORT_KITESURFING = 44

Sport used for kite surfing

Since:

  • 3.0.10

SPORT_TACTICAL = 45

Sport used for tactical

Since:

  • 3.0.10

SPORT_JUMPMASTER = 46

Sport used for jumpmaster

Since:

  • 3.0.10

SPORT_BOXING = 47

Sport used for boxing

Since:

  • 3.0.10

SPORT_FLOOR_CLIMBING = 48

Sport used for climbing

Since:

  • 3.0.10

SPORT_BASEBALL = 49

Sport used for baseball

Since:

  • 3.0.10

SPORT_SOFTBALL_FAST_PITCH = 50

Sport used for fast pitch softball

Since:

  • 3.0.10

SPORT_SOFTBALL_SLOW_PITCH = 51

Sport used for slow pitch softball

Since:

  • 3.0.10

SPORT_SHOOTING = 56

Sport used for shooting

Since:

  • 3.0.10

SPORT_AUTO_RACING = 57

Sport used for auto racing

Since:

  • 3.0.10

SUB_SPORT_GENERIC = 0

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

Since:

  • 1.0.0

SUB_SPORT_TREADMILL = 1

Sub-sport for Running and Fitness Equipment

Since:

  • 1.0.0

SUB_SPORT_STREET = 2

Sub-sport for Running

Since:

  • 1.0.0

SUB_SPORT_TRAIL = 3

Sub-sport for Running

Since:

  • 1.0.0

SUB_SPORT_TRACK = 4

Sub-sport for Running

Since:

  • 1.0.0

SUB_SPORT_SPIN = 5

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_INDOOR_CYCLING = 6

Sub-sport for Cycling and Fitness Equipment

Since:

  • 1.0.0

SUB_SPORT_ROAD = 7

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_MOUNTAIN = 8

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_DOWNHILL = 9

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_RECUMBENT = 10

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_CYCLOCROSS = 11

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_HAND_CYCLING = 12

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_TRACK_CYCLING = 13

Sub-sport for Cycling

Since:

  • 1.0.0

SUB_SPORT_INDOOR_ROWING = 14

Sub-sport for Rowing and Fitness Equipment

Since:

  • 1.0.0

SUB_SPORT_ELLIPTICAL = 15

Sub-sport for Fitness Equipment

Since:

  • 1.0.0

SUB_SPORT_STAIR_CLIMBING = 16

Sub-sport for Fitness Equipment

Since:

  • 1.0.0

SUB_SPORT_LAP_SWIMMING = 17

Sub-sport for Swimming

Since:

  • 1.0.0

SUB_SPORT_OPEN_WATER = 18

Sub-sport for Swimming

Since:

  • 1.0.0

SUB_SPORT_FLEXIBILITY_TRAINING = 19

Sub-sport for Training

Since:

  • 1.0.0

SUB_SPORT_STRENGTH_TRAINING = 20

Sub-sport for Training

Since:

  • 1.0.0

SUB_SPORT_WARM_UP = 21

Sub-sport for Activity Warm-up

Since:

  • 1.0.0

SUB_SPORT_MATCH = 22

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

Since:

  • 1.0.0

SUB_SPORT_EXERCISE = 23

Sub-sport for Exercise

Since:

  • 1.0.0

SUB_SPORT_CHALLENGE = 24

Sub-sport for a Sport Challenge

Since:

  • 1.0.0

SUB_SPORT_INDOOR_SKIING = 25

Sub-sport for Fitness Equipment

Since:

  • 1.0.0

SUB_SPORT_CARDIO_TRAINING = 26

Sub-sport for Training

Since:

  • 1.0.0

TIMER_EVENT_START = 0

Timer start event

Since:

  • 3.0.10

TIMER_EVENT_STOP = 1

Timer stop event

Since:

  • 3.0.10

TIMER_EVENT_PAUSE = 2

Timer pause event

Since:

  • 3.0.10

TIMER_EVENT_RESUME = 3

Timer resume event

Since:

  • 3.0.10

TIMER_EVENT_LAP = 4

Timer lap event

Since:

  • 3.0.10

TIMER_EVENT_RESET = 5

Timer reset

Since:

  • 3.0.10

TIMER_EVENT_WORKOUT_STEP_COMPLETE = 6

Workout step complete

Since:

  • 3.0.10

TIMER_EVENT_NEXT_MULTISPORT_LEG = 7

Multisport leg started

Since:

  • 3.0.10

Instance Method Summary collapse

Instance Method Details

createSession(options) ⇒ Toybox::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.

Examples:

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=>ActivityRecording.SPORT_GENERIC,        // set sport type
        :subSport=>ActivityRecording.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;
}

Parameters:

Options Hash (options):

  • :sport (Toybox::Lang::Number)

    The primary sport being recorded (SPORT_GENERIC by default).

  • :subSport (Toybox::Lang::Number)

    The sport subcategory being recorded (SUB_SPORT_GENERIC by default).

  • :name (Toybox::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 (Toybox::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 (Toybox::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 (Toybox::SensorLogging::SensorLogger)

    The SensorLogger to use to record this session.

Returns:

Since:

  • 1.0.0


5316
5317
# File 'Monkeybrains.rb', line 5316

def createSession(options)
end