diff --git a/README.md b/README.md index 90f052f..9171639 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/source-memoryGTE32K/WalkerView.mc b/source-memoryGTE32K/WalkerView.mc index 6b72fdf..c374855 100644 --- a/source-memoryGTE32K/WalkerView.mc +++ b/source-memoryGTE32K/WalkerView.mc @@ -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; } @@ -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