1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-26 20:06:52 +01:00

Huawei: Add non-P2P HR zones configuration

This commit is contained in:
Martin.JM 2024-11-12 14:59:07 +01:00 committed by José Rebelo
parent 5f91715c89
commit 39e7bd8c62
4 changed files with 133 additions and 0 deletions

View File

@ -453,6 +453,14 @@ public class HuaweiCoordinator {
return supportsHeartRate() || getForceOption(gbDevice, PREF_FORCE_ENABLE_HEARTRATE_SUPPORT);
}
public boolean supportsHeartRateZones() {
return supportsCommandForService(0x07, 0x13);
}
public boolean supportsExtendedHeartRateZones() {
return supportsCommandForService(0x07, 0x21);
}
public boolean supportsFitnessRestHeartRate() {
return supportsCommandForService(0x07, 0x23);
}

View File

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HeartRateZonesConfig;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiReportThreshold;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiTLV;
@ -597,6 +598,71 @@ public class FitnessData {
}
}
public static class HeartRateZoneConfigPacket {
// It can use two IDs with basically the same format.
public static final byte id_simple = 0x13;
public static final byte id_extended = 0x21;
public static class Request extends HuaweiPacket {
private Request(
ParamsProvider paramsProvider,
byte id,
HeartRateZonesConfig heartRateZonesConfig
) {
super(paramsProvider);
this.serviceId = FitnessData.id;
this.commandId = id;
HuaweiTLV subTlv = new HuaweiTLV().
put(0x08, heartRateZonesConfig.getWarningEnable());
if (
heartRateZonesConfig.hasValidMHRData() &&
heartRateZonesConfig.getWarningHRLimit() > 0 &&
heartRateZonesConfig.getMaxHRThreshold() > 0
) {
subTlv
.put(0x09, (byte) heartRateZonesConfig.getWarningHRLimit())
.put(0x02, (byte) heartRateZonesConfig.getMHRWarmUp())
.put(0x03, (byte) heartRateZonesConfig.getMHRFatBurning())
.put(0x04, (byte) heartRateZonesConfig.getMHRAerobic())
.put(0x05, (byte) heartRateZonesConfig.getMHRAnaerobic())
.put(0x06, (byte) heartRateZonesConfig.getMHRExtreme())
.put(0x07, (byte) heartRateZonesConfig.getMaxHRThreshold())
.put(0x0b, (byte) heartRateZonesConfig.getMaxHRThreshold());
}
if (id == id_extended && heartRateZonesConfig.hasValidHRRData()) {
subTlv
.put(0x0d, (byte) heartRateZonesConfig.getHRRBasicAerobic())
.put(0x0e, (byte) heartRateZonesConfig.getHRRAdvancedAerobic())
.put(0x0f, (byte) heartRateZonesConfig.getHRRLactate())
.put(0x10, (byte) heartRateZonesConfig.getHRRBasicAnaerobic())
.put(0x11, (byte) heartRateZonesConfig.getHRRAdvancedAnaerobic());
}
if (id == id_extended && heartRateZonesConfig.getRestHeartRate() > 0) {
subTlv
.put(0x0a, (byte) heartRateZonesConfig.getCalculateMethod())
.put(0x0c, (byte) heartRateZonesConfig.getRestHeartRate());
}
this.tlv = new HuaweiTLV().put(0x81, subTlv);
this.complete = true;
}
public static Request requestSimple(ParamsProvider paramsProvider, HeartRateZonesConfig heartRateZonesConfig) {
return new Request(paramsProvider, id_simple, heartRateZonesConfig);
}
public static Request requestExtended(ParamsProvider paramsProvider, HeartRateZonesConfig heartRateZonesConfig) {
return new Request(paramsProvider, id_extended, heartRateZonesConfig);
}
}
}
public static class TruSleep {
public static final byte id = 0x16;

View File

@ -125,6 +125,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.Send
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendFitnessUserInfoRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendGpsDataRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendFileUploadInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendHeartRateZonesConfig;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendRunPaceConfigRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendSetContactsRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendNotifyHeartRateCapabilityRequest;
@ -834,6 +835,7 @@ public class HuaweiSupportProvider {
initRequestQueue.add(new SendFitnessUserInfoRequest(this));
initRequestQueue.add(new SendRunPaceConfigRequest(this));
initRequestQueue.add(new SendDeviceReportThreshold(this));
initRequestQueue.add(new SendHeartRateZonesConfig(this));
initRequestQueue.add(new SetMediumToStrengthThresholdRequest(this));
initRequestQueue.add(new SendFitnessGoalRequest(this));
initRequestQueue.add(new GetNotificationCapabilitiesRequest(this));

View File

@ -0,0 +1,57 @@
/* Copyright (C) 2024 Martin.JM
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HeartRateZonesConfig;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.FitnessData;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
public class SendHeartRateZonesConfig extends Request {
public SendHeartRateZonesConfig(HuaweiSupportProvider support) {
super(support);
this.serviceId = FitnessData.id;
this.commandId = supportProvider.getHuaweiCoordinator().supportsExtendedHeartRateZones() ?
FitnessData.HeartRateZoneConfigPacket.id_extended :
FitnessData.HeartRateZoneConfigPacket.id_simple;
}
@Override
protected boolean requestSupported() {
return
!supportProvider.getHuaweiCoordinator().supportsTrack() && // In this case it uses P2P
supportProvider.getHuaweiCoordinator().supportsHeartRateZones();
}
@Override
protected List<byte[]> createRequest() throws RequestCreationException {
try {
HeartRateZonesConfig heartRateZonesConfig = new HeartRateZonesConfig(HeartRateZonesConfig.TYPE_UPRIGHT, new ActivityUser().getAge());
if (supportProvider.getHuaweiCoordinator().supportsExtendedHeartRateZones()) {
return FitnessData.HeartRateZoneConfigPacket.Request.requestExtended(paramsProvider, heartRateZonesConfig).serialize();
} else {
return FitnessData.HeartRateZoneConfigPacket.Request.requestSimple(paramsProvider, heartRateZonesConfig).serialize();
}
} catch (HuaweiPacket.CryptoException e) {
throw new RequestCreationException(e);
}
}
}