Skip to content

Commit fcefa6b

Browse files
committed
experiment(luckring): drop the HRV byte's top bit (#112, not for merge)
Test build for the reporter of #112, who suspects the top bit of the HRV byte is a flag. Built on #118 so the steps fix stays. Compare these values with what LuckRing shows for the same readings.
1 parent 384a07b commit fcefa6b

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎app/src/main/java/com/pulseloop/ring/LuckRingDecoder.kt‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ object LuckRingDecoder {
4747
LuckRingDataType.REAL_BP -> decodeBP(p).ifEmpty { listOf(RingDecodedEvent.CommandAck(LuckRingDataType.REAL_BP)) }
4848
LuckRingDataType.HISTORY_BP -> decodeBP(p)
4949

50+
// EXPERIMENT (issue #112), not for merge: the reporter suspects the HRV byte's top bit is a
51+
// flag. This build drops it so the values can be compared against what LuckRing shows.
5052
LuckRingDataType.REAL_HRV ->
51-
decodeLive(p, now) { value, ts -> RingDecodedEvent.HrvSample(value.toInt(), ts) }
52-
LuckRingDataType.HISTORY_HRV -> decodeHistory(p, MeasurementKind.HRV)
53+
decodeLive(p, now) { value, ts -> RingDecodedEvent.HrvSample(value.toInt() and 0x7F, ts) }
54+
LuckRingDataType.HISTORY_HRV -> decodeHistory(p, MeasurementKind.HRV).map { e ->
55+
if (e is RingDecodedEvent.HistoryMeasurement) e.copy(value = (e.value.toInt() and 0x7F).toDouble()) else e
56+
}
5357

5458
LuckRingDataType.REAL_TEMP -> decodeTemperature(p, history = false)
5559
LuckRingDataType.HISTORY_TEMP -> decodeTemperature(p, history = true)

‎app/src/test/java/com/pulseloop/ring/LuckRingDecoderTest.kt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ class LuckRingDecoderTest {
123123
assertTrue(kinds.contains(MeasurementKind.BLOOD_PRESSURE_DIASTOLIC to 76.0))
124124
}
125125

126+
/** EXPERIMENT (issue #112): the HRV byte's top bit is dropped — 0xA8 from the reporter's ring reads 40. */
127+
@Test
128+
fun `history HRV drops the top bit in the experiment build`() {
129+
val payload = envelope(2, listOf(LuckRingBytes.le32(base) + listOf<UByte>(0xA8u), LuckRingBytes.le32(base + 60) + listOf<UByte>(107u)))
130+
val values = LuckRingDecoder.decode(frame(42u, payload))
131+
.mapNotNull { (it as? RingDecodedEvent.HistoryMeasurement)?.value }
132+
assertEquals(listOf(40.0, 107.0), values)
133+
}
134+
126135
// MARK: Sport
127136

128137
@Test

0 commit comments

Comments
 (0)