mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Fix Amazfit Neo manual HR measurement.
Fix heartrate notify staying on after manual measurement. Fix "live measurement" to use "continue" packet instead of restarting measurement every second.
This commit is contained in:
parent
fb61f27768
commit
bf7446abe9
@ -301,7 +301,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
}
|
||||
};
|
||||
|
||||
private BluetoothGattCharacteristic characteristicHRControlPoint;
|
||||
protected BluetoothGattCharacteristic characteristicHRControlPoint;
|
||||
private BluetoothGattCharacteristic characteristicChunked;
|
||||
|
||||
private BluetoothGattCharacteristic characteristicChunked2021Write;
|
||||
@ -2284,7 +2284,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
logMessageContent(value);
|
||||
}
|
||||
|
||||
private void handleHeartrate(byte[] value) {
|
||||
protected void handleHeartrate(byte[] value) {
|
||||
if (value.length == 2 && value[0] == 0) {
|
||||
int hrValue = (value[1] & 0xff);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
|
@ -44,6 +44,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.Upd
|
||||
public class AmazfitNeoSupport extends MiBand5Support {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AmazfitNeoSupport.class);
|
||||
|
||||
private boolean heartRateRealtimeStarted = false;
|
||||
private boolean heartRateTestStarted = false;
|
||||
private byte heartRateRealtimeCount = 0;
|
||||
|
||||
@Override
|
||||
protected boolean notificationHasExtraHeader() {
|
||||
return false;
|
||||
@ -97,6 +101,62 @@ public class AmazfitNeoSupport extends MiBand5Support {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHeartRateTest() {
|
||||
if (characteristicHRControlPoint == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("HeartRateTest");
|
||||
enableNotifyHeartRateMeasurements(true, builder);
|
||||
builder.write(characteristicHRControlPoint, new byte[]{ 0x15, 0x01, 0x01 });
|
||||
builder.queue(getQueue());
|
||||
heartRateTestStarted = true;
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Unable to read heart rate from Huami device", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnableRealtimeHeartRateMeasurement(boolean enable) {
|
||||
heartRateTestStarted = false;
|
||||
if (characteristicHRControlPoint == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("Enable realtime heart rate measurement");
|
||||
enableNotifyHeartRateMeasurements(enable, builder);
|
||||
if (enable) {
|
||||
if (heartRateRealtimeStarted) {
|
||||
if(heartRateRealtimeCount >= 10) {
|
||||
builder.write(characteristicHRControlPoint, new byte[]{ 0x16 }); //send continue every 10 seconds
|
||||
heartRateRealtimeCount = 0;
|
||||
}
|
||||
heartRateRealtimeCount++;
|
||||
}
|
||||
else {
|
||||
builder.write(characteristicHRControlPoint, new byte[]{ 0x15, 0x01, 0x01 });
|
||||
heartRateRealtimeCount = 10; //sometimes first measurement times out, send first keep alive immediately
|
||||
}
|
||||
heartRateRealtimeStarted = true;
|
||||
} else {
|
||||
builder.write(characteristicHRControlPoint, new byte[] { 0x15, 0x01, 0x00 });
|
||||
heartRateRealtimeStarted = false;
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
enableRealtimeSamplesTimer(enable);
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Unable to enable realtime heart rate measurement", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleHeartrate(byte[] value) {
|
||||
super.handleHeartrate(value);
|
||||
if (heartRateTestStarted)
|
||||
onEnableRealtimeHeartRateMeasurement(false); //stop test after single measurement, disable HR notify
|
||||
}
|
||||
|
||||
@Override
|
||||
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
|
||||
return new AmazfitNeoFWHelper(uri, context);
|
||||
|
Loading…
Reference in New Issue
Block a user