Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/assets/i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@
"EARLIER": "ANTERIORES",
"ESTIMATED": "ESTIMADO",
"Each night is compared with your own previous four weeks once there are two weeks to compare with. ": "Cada noite é comparada com suas próprias quatro semanas anteriores assim que houver duas semanas para comparar. ",
"Each reading takes about two minutes. A workout you record measures continuously, whatever this is set to.": "Cada leitura leva cerca de dois minutos. Um treino que você grava mede sem parar, qualquer que seja este valor.",
"Each ring's typical gap from {0}. Lower is closer.": "A diferença típica de cada anel em relação a {0}. Menor é mais próximo.",
"Early bird": "Matutino",
"Early evening, when you're under 70% of your step goal. Off in Rest Mode.": "No início da noite, quando você estiver abaixo de 70% da sua meta de passos. Desativado no Modo Descanso.",
Expand Down
42 changes: 38 additions & 4 deletions app/src/main/java/com/pulseloop/ring/JringDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ object JringCoordinator : WearableCoordinator {
// [bitmapGatedCapabilities] when the 0x20 reply sets the bit (RingDecoder.decodeBandFunction).
)

override val bitmapGatedCapabilities: Set<WearableCapability> = setOf(WearableCapability.TEMPERATURE)
override val bitmapGatedCapabilities: Set<WearableCapability> =
setOf(WearableCapability.TEMPERATURE, WearableCapability.MEASUREMENT_INTERVAL)

override val iconSystemName = "circle.hexagongrid.circle.fill"

Expand Down Expand Up @@ -139,7 +140,7 @@ class JringSyncEngine(
// 0x19 arms the ring's continuous background sensor logging. The vendor app sends this on
// every connect; without it the ring records almost nothing, which is why users previously
// had to initialise with the vendor app first.
writer?.enqueue(encoder.makeAutomaticHeartRateCommand(enabled = true, cadenceMinutes = 30))
writer?.enqueue(automaticHeartRateCommand())
writer?.enqueue(encoder.makeBandFunctionCommand())
// History is paged rather than enqueued: [JringHistorySync] sends one day's 0x10, holds
// the rest until that day's stream goes quiet, and asks for each day's 0x16 HR itself.
Expand Down Expand Up @@ -265,14 +266,33 @@ class JringSyncEngine(
val mode = workoutSportMode ?: return stopHeartRate()
workoutSportMode = null
writer?.enqueue(encoder.makeWorkoutHeartRateStopCommand(mode))
writer?.enqueue(encoder.makeAutomaticHeartRateCommand(enabled = true, cadenceMinutes = 30))
writer?.enqueue(automaticHeartRateCommand())
}

override fun stopHeartRate() {
writer?.enqueue(encoder.makeHeartRateStopCommand())
writer?.enqueue(encoder.makeAutomaticHeartRateCommand(enabled = true, cadenceMinutes = 30))
writer?.enqueue(automaticHeartRateCommand())
}

/** The user's saved background schedule, or the vendor's default when none was saved. */
private var measurementSettings: MeasurementSettings? = null

override fun setMeasurementSettings(settings: MeasurementSettings?) {
measurementSettings = settings
}

override fun applyMeasurementSettings(settings: MeasurementSettings) {
measurementSettings = settings
writer?.enqueue(automaticHeartRateCommand())
}

/** `0x19` with the saved interval, snapped to the vendor's choices ([JringHeartRateInterval]).
* Sent on connect and again after any live stream, which the ring's schedule yields to. */
private fun automaticHeartRateCommand(): ByteArray = encoder.makeAutomaticHeartRateCommand(
enabled = measurementSettings?.hrEnabled ?: true,
cadenceMinutes = JringHeartRateInterval.snap(measurementSettings?.hrIntervalMinutes),
)

/** Spot HR using live HR streaming (0x14), same as workout HR. */
override fun measureHeartRateSpot() {
writer?.enqueue(encoder.makeHeartRateStartCommand())
Expand Down Expand Up @@ -333,3 +353,17 @@ class JringSyncEngine(
return true
}
}

/**
* The jring's background heart-rate interval (`0x19` byte 6). The vendor app offers exactly
* 15, 30, 45 and 60 minutes (`HeartrateTestActivity`) and defaults to 30 (`HEARTRATE_SNOOZE_REPEAT`);
* nothing shorter is offered there, so nothing shorter is sent here.
*/
object JringHeartRateInterval {
val CHOICES = listOf(15, 30, 45, 60)
const val DEFAULT = 30

/** A saved interval mapped onto the vendor's choices; null (never saved) is the default. */
fun snap(minutes: Int?): Int =
if (minutes == null || minutes <= 0) DEFAULT else CHOICES.minByOrNull { kotlin.math.abs(it - minutes) }!!
}
7 changes: 6 additions & 1 deletion app/src/main/java/com/pulseloop/ring/RingDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,12 @@ class RingDecoder(private val clock: JringClock? = null) {
val caps = JringBandCapabilities(bytes.copyOfRange(1, bytes.size))
// A unit that sets bit 10 has a temperature log the app can read (0x39), so it gets the
// card; the family baseline leaves TEMPERATURE out because most of these rings don't.
val reported = buildSet { if (caps.hasTemperature) add(WearableCapability.TEMPERATURE) }
val reported = buildSet {
if (caps.hasTemperature) add(WearableCapability.TEMPERATURE)
// The vendor's interval picker appears only on rings that set bit 18; the same bit
// opens Measurement frequency here (JringHeartRateInterval).
if (caps.hasAutoHeartRateInterval) add(WearableCapability.MEASUREMENT_INTERVAL)
}
return listOfNotNull(
RingDecodedEvent.BandFunction(caps),
reported.takeIf { it.isNotEmpty() }?.let { RingDecodedEvent.SupportFunctions(it) },
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/pulseloop/ring/RingProtocol.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ data class JringBandCapabilities(val bytes: ByteArray) {

val hasTemperature: Boolean get() = bit(10)

/** `FUNCTION_HEART_SHOW_AUTO_INTERVAL` (`DupMainActivity`, zArr[18]): the vendor shows its
* background heart-rate interval picker (15/30/45/60 min, `HeartrateTestActivity`) only when
* the ring sets this bit. */
val hasAutoHeartRateInterval: Boolean get() = bit(18)

/** SpO₂ uses the dedicated 0x3E command rather than the 0x23 mode selector. */
val separateBloodOxygenMode: Boolean get() = bit(65)
val hasOxygenOfflineHistory: Boolean get() = bit(81)
Expand Down
41 changes: 30 additions & 11 deletions app/src/main/java/com/pulseloop/ui/screens/SettingsSubScreens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,8 @@ fun GoalsSettingsScreen(coordinator: RingSyncCoordinator?, onBack: () -> Unit) {

/**
* Measurement Frequency detail screen: the old inline "Measurement" card (iOS #19 content).
* The hub only shows the row for rings declaring MEASUREMENT_INTERVAL (Colmi).
* The hub only shows the row for rings declaring MEASUREMENT_INTERVAL (Colmi, YCBT, LuckRing, and a jring
* whose 0x20 reply sets bit 18).
*/
@Composable
fun MeasurementSettingsScreen(coordinator: RingSyncCoordinator?, onBack: () -> Unit) {
Expand All @@ -1710,17 +1711,26 @@ fun MeasurementSettingsScreen(coordinator: RingSyncCoordinator?, onBack: () -> U
// [com.pulseloop.ring.YCBTDriver], so its ring can carry the same settings (issue #103,
// Albabit's `colmi-smarthealth` unit was capped at 5–60 until 2026-10-23).
val isYcbtProtocol = device?.deviceType in setOf(RingDeviceType.YCBT, RingDeviceType.COLMI_SMART_HEALTH)
val minimumInterval = if (isYcbtProtocol) 30 else 5
// The jring takes the vendor's four choices only (JringHeartRateInterval), and its one
// background command carries heart rate alone: no per-vital switch reaches the wire.
val isJring = device?.deviceType == RingDeviceType.JRING
val minimumInterval = when {
isJring -> com.pulseloop.ring.JringHeartRateInterval.CHOICES.first()
isYcbtProtocol -> 30
else -> 5
}
val intervalStep = if (isJring) 15 else 5
val defaultInterval = if (isJring) com.pulseloop.ring.JringHeartRateInterval.DEFAULT else minimumInterval
// 120 min is the only interval beyond the vendor app's own menu (which stops at 60) that is
// tested on hardware: the ring ACKed `01 0c 01 78` and read at 10:00 and 12:00 (issue #103,
// 2026-10-22). Nothing longer until someone tries it, and YCBT-protocol rings only — it is
// not the vendor app's behaviour, it is one ring's.
val maximumHrInterval = if (isYcbtProtocol) 120 else 60
val intervalSteps = ((maximumHrInterval - minimumInterval) / 5 - 1).coerceAtLeast(0)
val intervalSteps = ((maximumHrInterval - minimumInterval) / intervalStep - 1).coerceAtLeast(0)
// Only offered where the ring's protocol actually carries a separate blood-oxygen interval —
// elsewhere the slider moved, the value saved, and "Saved & sent to ring ✓" appeared over a
// setting nothing on the wire could express (issue #66).
val supportsSpo2Interval = device?.deviceType?.supportsSeparateSpo2Interval == true
val supportsSpo2Interval = device?.deviceType?.supportsSeparateSpo2Interval == true && !isJring
// The SpO₂ slider runs five minutes lower than the HR one (its floor is "follow heart rate"),
// so it needs its own step count: reusing the HR one put ticks 5.45 min apart, none of which
// the 5-minute snap could land on.
Expand All @@ -1730,7 +1740,7 @@ fun MeasurementSettingsScreen(coordinator: RingSyncCoordinator?, onBack: () -> U
// only), so a toggle here would be a no-op the ring never sees — the capability bit alone
// is not enough to offer it.
val supportsStressSetting = WearableCapability.STRESS in capabilities &&
!isYcbtProtocol
!isYcbtProtocol && !isJring

var cfgHrEnabled by remember { mutableStateOf(true) }
var cfgHrInterval by remember { mutableStateOf(5) }
Expand All @@ -1753,7 +1763,9 @@ fun MeasurementSettingsScreen(coordinator: RingSyncCoordinator?, onBack: () -> U
cfgLoaded = false
val config = db.deviceMeasurementConfigDao().byDevice(id)
cfgHrEnabled = config?.hrEnabled ?: true
cfgHrInterval = (config?.hrIntervalMinutes ?: minimumInterval).coerceIn(minimumInterval, maximumHrInterval)
cfgHrInterval = (config?.hrIntervalMinutes ?: defaultInterval).let {
if (isJring) com.pulseloop.ring.JringHeartRateInterval.snap(it) else it
}.coerceIn(minimumInterval, maximumHrInterval)
cfgSpo2 = (config?.spo2Enabled ?: true) && WearableCapability.SPO2 in capabilities
cfgSpo2Interval = (config?.spo2IntervalMinutes ?: 0).let {
if (it <= 0) 0 else it.coerceIn(minimumInterval, 60)
Expand Down Expand Up @@ -1807,13 +1819,20 @@ fun MeasurementSettingsScreen(coordinator: RingSyncCoordinator?, onBack: () -> U
Slider(
enabled = cfgLoaded,
value = cfgHrInterval.toFloat(),
onValueChange = { cfgHrInterval = ((it / 5).toInt() * 5).coerceIn(minimumInterval, maximumHrInterval); cfgSavedMsg = null },
onValueChange = { cfgHrInterval = (kotlin.math.round(it / intervalStep).toInt() * intervalStep).coerceIn(minimumInterval, maximumHrInterval); cfgSavedMsg = null },
valueRange = minimumInterval.toFloat()..maximumHrInterval.toFloat(),
steps = intervalSteps,
)
}
HorizontalDivider(Modifier.padding(vertical = 8.dp))
if (WearableCapability.SPO2 in capabilities) {
if (isJring) {
Text(
tr("Each reading takes about two minutes. A workout you record measures continuously, whatever this is set to."),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
if (!isJring) HorizontalDivider(Modifier.padding(vertical = 8.dp))
if (WearableCapability.SPO2 in capabilities && !isJring) {
VitalToggle(tr("Blood oxygen (SpO₂)"), cfgSpo2) { cfgSpo2 = it }
// The monitor command takes the same shape for every vital
// (`01 <key> {enable, interval}`), so blood oxygen always had an interval —
Expand Down Expand Up @@ -1891,10 +1910,10 @@ fun MeasurementSettingsScreen(coordinator: RingSyncCoordinator?, onBack: () -> U
if (supportsStressSetting) {
VitalToggle(tr("Stress"), cfgStress) { cfgStress = it }
}
if (WearableCapability.HRV in capabilities) {
if (WearableCapability.HRV in capabilities && !isJring) {
VitalToggle("HRV", cfgHrv) { cfgHrv = it }
}
if (WearableCapability.TEMPERATURE in capabilities) {
if (WearableCapability.TEMPERATURE in capabilities && !isJring) {
VitalToggle(tr("Temperature"), cfgTemp) { cfgTemp = it }
}

Expand Down
67 changes: 67 additions & 0 deletions app/src/test/java/com/pulseloop/ring/JringHeartRateIntervalTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.pulseloop.ring

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

/** The jring's background heart-rate interval: the vendor's 15/30/45/60 choices, gated on bit 18. */
class JringHeartRateIntervalTest {
private class Recorder : RingCommandWriter {
val sent = mutableListOf<ByteArray>()
override fun enqueue(command: ByteArray) { sent += command }
}

private fun settings(minutes: Int, enabled: Boolean = true) = MeasurementSettings(
hrEnabled = enabled, hrIntervalMinutes = minutes,
spo2Enabled = true, stressEnabled = true, hrvEnabled = true, temperatureEnabled = true,
)

private fun cadences(w: Recorder) = w.sent.filter { it[0] == 0x19.toByte() }.map { it[6].toInt() }

@Test fun snapsToTheVendorChoices() {
assertEquals(30, JringHeartRateInterval.snap(null))
assertEquals(15, JringHeartRateInterval.snap(5))
assertEquals(15, JringHeartRateInterval.snap(15))
assertEquals(45, JringHeartRateInterval.snap(40))
assertEquals(60, JringHeartRateInterval.snap(120))
}

@Test fun neverSavedSendsTheVendorDefault() {
val w = Recorder()
JringSyncEngine(w).runStartup()
assertEquals(listOf(30), cadences(w))
}

@Test fun theSavedIntervalGoesOutOnConnectAndOnSave() {
val w = Recorder()
val engine = JringSyncEngine(w)
engine.setMeasurementSettings(settings(15))
engine.runStartup()
engine.applyMeasurementSettings(settings(45))
assertEquals(listOf(15, 45), cadences(w))
}

@Test fun aStreamEndingRestoresTheSavedInterval() {
val w = Recorder()
val engine = JringSyncEngine(w)
engine.setMeasurementSettings(settings(15))
engine.stopHeartRate()
assertEquals(listOf(15), cadences(w))
}

@Test fun switchedOffClearsTheEnableByte() {
val w = Recorder()
val engine = JringSyncEngine(w)
engine.applyMeasurementSettings(settings(30, enabled = false))
assertEquals(0, w.sent.single { it[0] == 0x19.toByte() }[5].toInt())
}

@Test fun bit18GrantsTheSetting() {
// The owner's ring's 0x20 reply (2026-11-18): payload byte 2 = 0x07, so bit 18 is set.
val reply = "2062ec0738090abebb02001b0000000000000000".chunked(2).map { it.toInt(16).toByte() }.toByteArray()
val caps = JringBandCapabilities(reply.copyOfRange(1, reply.size))
assertTrue(caps.hasAutoHeartRateInterval)
assertFalse(JringBandCapabilities(ByteArray(19)).hasAutoHeartRateInterval)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ class JringSensorHistoryTest {
val caps = events.filterIsInstance<RingDecodedEvent.BandFunction>().single().capabilities
assertTrue(caps.hasTemperature && caps.hasOxygenOfflineHistory && caps.hasPressureHistory)
val granted = events.filterIsInstance<RingDecodedEvent.SupportFunctions>().single().capabilities
assertEquals(setOf(WearableCapability.TEMPERATURE), granted)
assertTrue(WearableCapability.TEMPERATURE in JringCoordinator.bitmapGatedCapabilities)
// Bit 18 too: this ring offers the vendor's heart-rate interval picker (JringHeartRateInterval).
assertEquals(setOf(WearableCapability.TEMPERATURE, WearableCapability.MEASUREMENT_INTERVAL), granted)
assertTrue(granted.all { it in JringCoordinator.bitmapGatedCapabilities })
}

@Test fun spotMeasurementKeepsItsHrvByte() {
Expand Down
79 changes: 79 additions & 0 deletions audits/2026-11-19-jring-hr-interval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Audit: JRing heart-rate interval

Date: 2026-11-19 · PR: see the PR linking this file · Auditor: Claude Code.
- **impeccable:** applied to the **rendered** Measurement frequency screen for a JRing. It was
drawn on the JVM with Robolectric, under the app theme with the new look on, at 1.0× and 1.3×.
The harness is local only.
- **Device check:** owed.
- **ux-user-flows, graphic-design-fundamentals, less-is-more:** applied by hand.

## Scope

The owner asked for a 15-minute option for the JRing's background heart rate. Settings → My ring →
Measurement frequency now appears for a JRing whose capability reply sets bit 18 (the vendor app's
own condition). For a JRing the screen shows:
- the All-day heart rate switch;
- a slider with the vendor's four choices, 15, 30, 45 and 60 minutes;
- one line on what a reading is.

Nothing changes for other rings.

## ux-user-flows (§13 flow review checklist)

- **Entry:** Settings → My ring → Measurement frequency. The row was absent for every JRing until
now.
- **Steps:** pick an interval, then Save. "Saved & sent to ring ✓" when connected, otherwise "Saved —
will sync on next connect" (existing states).
- **States:**
- **Never saved:** shows 30 min, the vendor default and what the app always sent.
- **Saved:** the saved value, snapped to the nearest stop.
- **Switched off:** the slider hides; the ring is told background heart rate is off.
- **A ring without bit 18:** no row; the app keeps sending 30.
- **Exits:** Back without saving changes nothing.

## impeccable

### Audit (native, on renders)

| # | Dimension | Score | Key finding |
|---|---|---|---|
| 1 | Accessibility | 4 | Standard Slider and Switch; the value is also text ("Every 30 min"). |
| 2 | Performance | 4 | No new reads. |
| 3 | Appearance & theming | 4 | Existing card and controls; one 12sp note. |
| 4 | Platform conformance | 4 | Four discrete slider stops, matching the four choices. |
| 5 | Adaptivity | 4 | At 1.3× the note wraps to three lines; nothing clips. |
| | **Total** | **20/20** | |

### Critique

| # | Heuristic | Score | Key issue |
|---|---|---|---|
| 1 | Visibility of status | 4 | Value shown above the slider; save confirmation unchanged. |
| 2 | Match real world | 4 | Minutes, as the vendor app shows them. |
| 5 | Error prevention | 4 | Only values the vendor offers can be chosen. |
| 8 | Minimalist | 4 | Switches the ring can't act on are hidden. |
| 10 | Help | 4 | One line: what a reading is, and that workouts measure continuously. |
| | **Total (of the five that apply)** | **20/20** | |

### Polish

- [P3] The 5-min Colmi steps and the 15-min JRing steps share one slider component; tick spacing
differs by ring, which is right for each ring.

No P0 or P1.

## graphic-design-fundamentals (§13 checklist)

- **Hierarchy:** title, explainer, switch, value, slider, note, Save. Unchanged order.
- **Colour:** no new colours.
- **Real size:** checked at 411dp, 1.0 and 1.3.

## less-is-more

| Element | Verdict |
|---|---|
| SpO₂ / stress / HRV / temperature switches for a JRing | Cut: the ring has no command for them |
| Intervals under 15 min | Left out: the vendor never offers them |
| The note | Kept: answers "why only every 15 min?" and "what about workouts?" |

No action gained a tap.
Loading
Loading