1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 01:09:47 +01:00

Some more fixes regarding heart rate measurement #178

This commit is contained in:
cpfeiffer 2016-02-27 11:18:16 +01:00
parent 9e636d66f6
commit de6f898fef
5 changed files with 35 additions and 18 deletions

View File

@ -13,6 +13,7 @@ import android.view.View;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
@ -539,6 +540,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
// set1.setHighLightColor(Color.rgb(128, 0, 255));
// set1.setColor(Color.rgb(89, 178, 44));
set1.setValueTextColor(CHART_TEXT_COLOR);
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
return set1;
}
@ -550,13 +552,14 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
// set1.setCubicIntensity(0.2f);
// //set1.setDrawFilled(true);
// set1.setDrawCircles(false);
// set1.setLineWidth(2f);
set1.setLineWidth(2f);
// set1.setCircleSize(5f);
// set1.setFillColor(ColorTemplate.getHoloBlue());
set1.setDrawValues(false);
// set1.setHighLightColor(Color.rgb(128, 0, 255));
// set1.setColor(Color.rgb(89, 178, 44));
set1.setValueTextColor(CHART_TEXT_COLOR);
set1.setAxisDependency(YAxis.AxisDependency.RIGHT);
return set1;
}

View File

@ -79,8 +79,8 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
YAxis yAxisRight = mChart.getAxisRight();
yAxisRight.setDrawGridLines(false);
yAxisRight.setEnabled(supportsHeartrate());
yAxisRight.setDrawLabels(false);
yAxisRight.setDrawTopYLabelEntry(false);
yAxisRight.setDrawLabels(true);
yAxisRight.setDrawTopYLabelEntry(true);
yAxisRight.setTextColor(CHART_TEXT_COLOR);
// refresh immediately instead of use refreshIfVisible(), for perceived performance

View File

@ -46,8 +46,8 @@ public class MiBandService {
public static final UUID UUID_CHARACTERISTIC_PAIR = UUID.fromString(String.format(BASE_UUID, "FF0F"));
public static final UUID UUID_CHAR_HEART_RATE_CONTROL_POINT = UUID.fromString(String.format(BASE_UUID, "2A39"));
public static final UUID UUID_CHAR_HEART_RATE_MEASUREMENT = UUID.fromString(String.format(BASE_UUID, "2A37"));
public static final UUID UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT = UUID.fromString(String.format(BASE_UUID, "2A39"));
public static final UUID UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT = UUID.fromString(String.format(BASE_UUID, "2A37"));
@ -161,9 +161,9 @@ public class MiBandService {
public static final byte COMMAND_SET_REALTIME_STEP = 0x10;
// Test HR
public static final byte COMMAND_SET_HR_SLEEP = 0x0 ;
public static final byte COMMAND_SET__HR_CONTINUOUS = 0x1 ;
public static final byte COMMAND_SET_HR_MANUAL = 0x2 ;
public static final byte COMMAND_SET_HR_SLEEP = 0x0;
public static final byte COMMAND_SET__HR_CONTINUOUS = 0x1;
public static final byte COMMAND_SET_HR_MANUAL = 0x2;
/* FURTHER COMMANDS: unchecked therefore left commented
@ -243,8 +243,8 @@ public class MiBandService {
MIBAND_DEBUG.put(UUID_CHARACTERISTIC_TEST, "Test");
MIBAND_DEBUG.put(UUID_CHARACTERISTIC_SENSOR_DATA, "Sensor Data");
MIBAND_DEBUG.put(UUID_CHARACTERISTIC_PAIR, "Pair");
MIBAND_DEBUG.put(UUID_CHAR_HEART_RATE_CONTROL_POINT, "Heart Rate Control Point");
MIBAND_DEBUG.put(UUID_CHAR_HEART_RATE_MEASUREMENT, "Heart Rate Measure");
MIBAND_DEBUG.put(UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT, "Heart Rate Control Point");
MIBAND_DEBUG.put(UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT, "Heart Rate Measure");
}
public static String lookup(UUID uuid, String fallback) {

View File

@ -138,7 +138,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_SENSOR_DATA), enable);
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_SENSOR_DATA), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable);
return this;
}
@ -202,8 +203,12 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
static final byte[] reboot = new byte[]{MiBandService.COMMAND_REBOOT};
// static final byte[] HeartMode = new byte[]{MiBandService.COMMAND_SET_HR_MANUAL};
static final byte[] HeartMode = new byte[]{MiBandService.COMMAND_SET_HR_SLEEP};
static final byte[] startHeartMeasurementManual = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_MANUAL, 1};
static final byte[] stopHeartMeasurementManual = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_MANUAL, 0};
static final byte[] startHeartMeasurementContinuous = new byte[]{ 0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 1};
static final byte[] stopHeartMeasurementContinuous = new byte[]{ 0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 0};
static final byte[] startHeartMeasurementSleep = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_SLEEP, 1};
static final byte[] stopHeartMeasurementSleep = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_SLEEP, 0};
static final byte[] startRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 1};
static final byte[] stopRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 0};
@ -527,7 +532,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
public void onHearRateTest() {
try {
TransactionBuilder builder = performInitialized("HeartRateTest");
builder.write(getCharacteristic(MiBandService.UUID_CHAR_HEART_RATE_CONTROL_POINT), HeartMode);
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementManual);
builder.queue(getQueue());
} catch (IOException ex) {
LOG.error("Unable to read HearRate in MI1S", ex);
@ -654,8 +659,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
handleRealtimeSteps(characteristic.getValue());
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
handleRealtimeSteps(characteristic.getValue());
} else if (MiBandService.UUID_CHAR_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
logMessageContent(characteristic.getValue());
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
logHeartrate(characteristic.getValue());
}
else {
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
@ -675,8 +680,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
handleDeviceName(characteristic.getValue(), status);
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
handleBatteryInfo(characteristic.getValue(), status);
} else if (MiBandService.UUID_CHAR_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
logMessageContent(characteristic.getValue());
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
logHeartrate(characteristic.getValue());
} else {
LOG.info("Unhandled characteristic read: "+ characteristicUUID);
logMessageContent(characteristic.getValue());
@ -708,6 +713,14 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
}
public void logHeartrate(byte[] value) {
LOG.info("Got heartrate:");
if (value.length == 2 && value[0] == 6) {
LOG.info("Heartrate: " + (value[1] & 0xff));
} else {
logMessageContent(value);
}
}
private void handleRealtimeSteps(byte[] value) {

View File

@ -327,6 +327,7 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
steps = activityStruct.activityDataHolder[i + 2];
if (hasExtendedActivityData) {
heartrate = activityStruct.activityDataHolder[i + 3];
LOG.debug("heartrate received: " + (heartrate & 0xff));
}
samples[minutes] = new GBActivitySample(