Skip to content

Commit

Permalink
Fix FIT contributor crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwarby committed Dec 13, 2024
1 parent ee49785 commit 0236ada
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ Code and ideas borrowed from [RunnersField by kpaumann](https://github.com/kopa/
## Changelog
- 1.7.0
- Add support for new devices
- Prevent crash when unable to write FIT contributions
- 1.6.1
- Fix a bug introduced by changes in 1.6.0
- 1.6.0
Expand Down
48 changes: 29 additions & 19 deletions source-memoryGTE32K/WalkerView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,30 @@ class WalkerView extends Ui.DataField {

// Create FIT contributor fields

var stepsUnits = Ui.loadResource(Rez.Strings.stepsUnits);

stepsPerKmOrMileField = createField(
deviceSettings.distanceUnits == System.UNIT_METRIC ? "stepsPerKm" : "stepsPerMile",
deviceSettings.distanceUnits == System.UNIT_METRIC ? 2 : 3, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_RECORD, :units => stepsUnits });

stepsPerHourField = createField("stepsPerHour", 4, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_RECORD, :units => stepsUnits });
try {
var stepsUnits = Ui.loadResource(Rez.Strings.stepsUnits);

stepsPerKmOrMileField = createField(
deviceSettings.distanceUnits == System.UNIT_METRIC ? "stepsPerKm" : "stepsPerMile",
deviceSettings.distanceUnits == System.UNIT_METRIC ? 2 : 3, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_RECORD, :units => stepsUnits });

stepsPerHourField = createField("stepsPerHour", 4, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_RECORD, :units => stepsUnits });

averageStepsPerKmOrMileField = createField(
deviceSettings.distanceUnits == System.UNIT_METRIC ? "avgStepsPerKm" : "avgStepsPerMile",
deviceSettings.distanceUnits == System.UNIT_METRIC ? 5 : 6, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_SESSION, :units => stepsUnits });

averageStepsPerHourField = createField("avgStepsPerHour", 7, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_SESSION, :units => stepsUnits });
averageStepsPerKmOrMileField = createField(
deviceSettings.distanceUnits == System.UNIT_METRIC ? "avgStepsPerKm" : "avgStepsPerMile",
deviceSettings.distanceUnits == System.UNIT_METRIC ? 5 : 6, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_SESSION, :units => stepsUnits });

// Set initial steps FIT contributions to zero
stepsPerKmOrMileField.setData(0);
stepsPerHourField.setData(0);
averageStepsPerKmOrMileField.setData(0);
averageStepsPerHourField.setData(0);
averageStepsPerHourField = createField("avgStepsPerHour", 7, Fit.DATA_TYPE_FLOAT, { :mesgType => Fit.MESG_TYPE_SESSION, :units => stepsUnits });

// Set initial steps FIT contributions to zero
stepsPerKmOrMileField.setData(0);
stepsPerHourField.setData(0);
averageStepsPerKmOrMileField.setData(0);
averageStepsPerHourField.setData(0);
} catch(e) {
System.println("Unable to create and initialise FIT data fields: " + e.getErrorMessage());
e.printStackTrace();
}

previousDistanceUnits = deviceSettings.distanceUnits;
}
Expand Down Expand Up @@ -275,8 +280,13 @@ class WalkerView extends Ui.DataField {
lapSteps = steps - activityStepsAtPreviousLap;

// Update step FIT contributions
stepsActivityField.setData(steps);
stepsLapField.setData(lapSteps);
try {
stepsActivityField.setData(steps);
stepsLapField.setData(lapSteps);
} catch (e) {
System.println("Unable to set FIT data with steps value " + steps + " and lap steps value " + lapSteps + ": " + e.getErrorMessage());
e.printStackTrace();
}
}
stepGoalProgress = activityMonitorInfo.stepGoal != null && activityMonitorInfo.stepGoal > 0
? daySteps > activityMonitorInfo.stepGoal
Expand Down

0 comments on commit 0236ada

Please sign in to comment.