I've converted my Cycling Data Fields to support running activities (pace in place of speed). In case anyone else would like to do this, here is what I did. Easy. Later, in the code, just use mPACE for mSPORT = RUN or mSPEED otherwise. You could easily expand this for SWIM too if you wanted. Anyway, just trying to contribute. Cheers!
in manifest.xml (need permissions to get the sport)
<iq:permissions>
<iq:uses-permission id="UserProfile"/>
</iq:permissions>
in source code:
// GLOBALS
using Toybox.UserProfile;
enum { METRIC, US } // support imperial & metric
enum { GENERIC, RUN, BIKE, SWIM }
var Conv = { :M2MI => 0.00062137, :M2KM => 0.001, :MPS2MPH => 2.237, :MPS2KPH => 3.6, :M2FT => 3.28085 };
var mSPORT = BIKE; // default to cycling
var unitType = System.getDeviceSettings().distanceUnits; // METRIC == 0, STATUTE == 1
var mSPEED = 0.0;
var mPACE = "0:00";
// GET METRICS MODULE
var myInfo = Activity.getActivityInfo();
mSPORT = UserProfile.getProfile().getCurrentSport().toNumber();
if (mSPORT == null || mSPORT < 0 || mSPORT > 3) { mSPORT= BIKE; } // default to BIKE
mSPEED=0.0; if(myInfo has :currentSpeed) { if(myInfo.currentSpeed != null) { mSPEED = unitType == US ? myInfo.currentSpeed * Conv[:MPS2MPH] : myInfo.currentSpeed * Conv[:MPS2KPH]; } } // speed in mph or k/hr
mPACE = Utility.speed2pace(mSPEED); // pace in mm:ss
// GENERAL UTILITIES BARREL
function speed2pace(spd) {
if (spd == null || spd < 0.61) { return "0:00"; } // largest valid pace is just under 100 min/mile (2 digit minute)
var myPace = 60.0/spd;
var myMin = myPace.toNumber();
var mySec = Math.round(60.0 * (myPace - myMin));
return (myMin.format("%d") + ":" + mySec.format("%0.2d"));
}