1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-26 17:47:34 +01:00

Xiaomi-protobuf: Add HR zones progress bars

This commit is contained in:
José Rebelo 2025-01-20 20:51:31 +00:00
parent 0d8e270686
commit ff6b8e56b1
3 changed files with 69 additions and 16 deletions

View File

@ -16,6 +16,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.model;
import java.util.LinkedHashMap;
import java.util.Map;
import nodomain.freeyourgadget.gadgetbridge.R;
public class ActivitySummaryEntries {
public static final String STATUS = "status";
public static final String TYPE = "watchface_dialog_widget_type"; // TODO: change this?
@ -180,4 +185,16 @@ public class ActivitySummaryEntries {
* FIXME: We should have a cleaner way of doing this.
*/
public static final String INTERNAL_HAS_GPS = "internal_hasGps";
public static final Map<String, Integer> HR_ZONES = new LinkedHashMap<String, Integer>() {{
put(HR_ZONE_NA, 0);
put(HR_ZONE_WARM_UP, R.color.hr_zone_warm_up_color);
put(HR_ZONE_EASY, R.color.hr_zone_easy_color);
put(HR_ZONE_FAT_BURN, R.color.hr_zone_easy_color);
put(HR_ZONE_AEROBIC, R.color.hr_zone_aerobic_color);
put(HR_ZONE_ANAEROBIC, R.color.hr_zone_threshold_color);
put(HR_ZONE_THRESHOLD, R.color.hr_zone_threshold_color);
put(HR_ZONE_EXTREME, R.color.hr_zone_maximum_color);
put(HR_ZONE_MAXIMUM, R.color.hr_zone_maximum_color);
}};
}

View File

@ -364,21 +364,21 @@ public class WorkoutSummaryParser extends XiaomiActivityParser implements Activi
builder.addUnknown(24);
builder.addByte("configuredSets", UNIT_NONE);
builder.addUnknown(13);
builder.addInt("startTime2", UNIT_SECONDS);
builder.addInt("endTime2", UNIT_SECONDS);
builder.addInt("goal", UNIT_NONE); // TODO match against goalType
builder.addInt("duration2", UNIT_SECONDS);
builder.addInt("intervalTime", UNIT_SECONDS);
builder.addUnknown(56);
builder.addInt("hrZoneExtreme2", UNIT_SECONDS);
builder.addInt("hrZoneAnaerobic2", UNIT_SECONDS);
builder.addInt("hrZoneAerobic2", UNIT_SECONDS);
builder.addInt("hrZoneFatBurn2", UNIT_SECONDS);
builder.addInt("hrZoneWarmUp2", UNIT_SECONDS);
builder.addUnknown(16);
builder.addShort("vitality_gain", UNIT_NONE);
builder.addShort("training_load2", UNIT_NONE);
builder.addShort("recovery_time2", UNIT_HOURS);
//builder.addInt("startTime2", UNIT_SECONDS);
//builder.addInt("endTime2", UNIT_SECONDS);
//builder.addInt("goal", UNIT_NONE); // TODO match against goalType
//builder.addInt("duration2", UNIT_SECONDS);
//builder.addInt("intervalTime", UNIT_SECONDS);
//builder.addUnknown(56);
//builder.addInt("hrZoneExtreme2", UNIT_SECONDS);
//builder.addInt("hrZoneAnaerobic2", UNIT_SECONDS);
//builder.addInt("hrZoneAerobic2", UNIT_SECONDS);
//builder.addInt("hrZoneFatBurn2", UNIT_SECONDS);
//builder.addInt("hrZoneWarmUp2", UNIT_SECONDS);
//builder.addUnknown(16);
//builder.addShort("vitality_gain", UNIT_NONE);
//builder.addShort("training_load2", UNIT_NONE);
//builder.addShort("recovery_time2", UNIT_HOURS);
return builder.build();
}
@ -422,7 +422,7 @@ public class WorkoutSummaryParser extends XiaomiActivityParser implements Activi
builder.addInt(HR_ZONE_AEROBIC, UNIT_SECONDS);
builder.addInt(HR_ZONE_FAT_BURN, UNIT_SECONDS);
builder.addInt(HR_ZONE_WARM_UP, UNIT_SECONDS);
builder.addInt("configured_time_goal", UNIT_SECONDS);
builder.addInt("configuredTimeGoal", UNIT_SECONDS);
return builder.build();
}

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.imp
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.SWIM_STYLE;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.TIME_END;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.TIME_START;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_SECONDS;
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_UNIX_EPOCH_SECONDS;
import org.slf4j.Logger;
@ -27,11 +28,17 @@ import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryData;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class XiaomiSimpleActivityParser {
@ -55,6 +62,8 @@ public class XiaomiSimpleActivityParser {
LOG.debug("Header: {}", GB.hexdump(header));
final Map<String, Number> hrZones = new HashMap<>(5);
for (int i = 0; i < dataEntries.size(); i++) {
final XiaomiSimpleDataEntry dataEntry = dataEntries.get(i);
@ -217,11 +226,38 @@ public class XiaomiSimpleActivityParser {
default:
summary.setActivityKind(ActivityKind.UNKNOWN.getCode());
}
} else if (ActivitySummaryEntries.HR_ZONES.containsKey(dataEntry.getKey())) {
// Save the HR zones so we can add them later in order
hrZones.put(dataEntry.getKey(), value);
} else {
summaryData.add(dataEntry.getKey(), value.floatValue(), dataEntry.getUnit());
}
}
if (!hrZones.isEmpty()) {
final int totalTime = hrZones.values().stream().mapToInt(Number::intValue).sum();
if (totalTime != 0) {
for (Map.Entry<String, Integer> zone : ActivitySummaryEntries.HR_ZONES.entrySet()) {
final String zoneKey = zone.getKey();
if (!hrZones.containsKey(zoneKey)) {
continue;
}
final int zoneColor = zone.getValue();
final int zoneTime = Objects.requireNonNull(hrZones.get(zoneKey)).intValue();
summaryData.add(
zoneKey,
new ActivitySummaryProgressEntry(
zoneTime,
UNIT_SECONDS,
((100 * zoneTime) / totalTime),
zoneColor != 0 ? GBApplication.getContext().getResources().getColor(zoneColor) : 0
)
);
}
}
}
summary.setSummaryData(summaryData.toString());
}