GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Background HR by mark9064 · Pull Request #2322 · InfiniTimeOrg/InfiniTime

Conversation

@mark9064

@mark9064 mark9064 commented Jun 26, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Largely based on #1718

Changes:

  • 4 state machine
  • Heart rate display avoids stale values being shown for a long time in some scenarios
    • does not cover all scenarios, but hopefully good enough and as close to the current behaviour as possible while still making sense for background measurement
  • Constant frequency HR measurements that take into account successful screen on measurements (and also long periods of unsuccessful screen on measurements)
  • Refactored a few annoying bits of the PPG code like lastBpm and the bodge to get correct not enough data messages
  • Removed the 15s mode. The sensor already takes ~6s to get a measurement in ideal conditions so it makes sense to use continuous - the sensor on time will be very similar and proper history averaging with continuous means measurement accuracy is better
  • Misc code bits such as using std::optional more where sensible. I haven't used it in the settings struct as the layout is compiler dependent AFAIK

Accuracy improvements (second commit)

  • Sampling is constant frequency instead of delay based
  • Raised the priority of the HR task to 1 so that it does not get out-competed by DisplayApp

This is still more complex than I'd like it to be

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

CivilizationUndecided and The-Nickname reacted with thumbs up emoji tr3foil reacted with heart emoji pipe01 reacted with eyes emoji
All reactions
  • 👍 2 reactions
  • ❤️ 1 reaction
  • 👀 1 reaction
@github-actions

github-actions Bot commented Jun 26, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Build size and comparison to main:

Section Size Difference
text 381180B 1112B
data 944B 0B
bss 22552B 8B

Run in InfiniEmu

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064
mark9064 force-pushed the background-hr branch from 49c4b00 to cb6462c Compare June 26, 2025 21:48
@mark9064

mark9064 commented Jun 26, 2025

Copy link
Copy Markdown
Member Author

Sim fix should be trivial, just a method rename it seems

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064 mark9064 added the enhancement Enhancement to an existing app/feature label Jun 26, 2025
@mark9064 mark9064 mentioned this pull request Jun 27, 2025
Heartrate measurements in background #1718
Closed
@mark9064 mark9064 added this to the 1.16.0 milestone Jun 30, 2025
@mark9064 mark9064 mentioned this pull request Jul 3, 2025
When HR measurement is running, steps aren't recorded #2116
Closed
1 task done
@tituscmd

tituscmd commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

Merged this onto my main device and will try it out compared to the "old"(er) system. Anything to look out for in particular?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064

mark9064 commented Jul 6, 2025

Copy link
Copy Markdown
Member Author

I'm most interested in hearing whether it feels natural in terms of how it behaves when you have screen on measurements interacting with background measurements. Also any bugs ofc :)
Thanks for testing!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tituscmd

tituscmd commented Jul 7, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Two things I can definitely say already:

  1. I'm a big fan of the feature that, after about 30 seconds with not enough data, the measurement gets set to failed. That way the amount of wrong measurements has been reduced a good bit
  2. I don't know if this is actually a causation, but I haven't had a reboot in 19hrs on a busy day like today where I usually get a reboot every few hours. This might have been fixed by a bug that was in the old version of background HR, or maybe I messed up the merge when I first merged background HR onto my device (long ago, more towards the beginning of my PineTime journey so I was definitely less experienced and the chances of me having messed up there aren't small)

I'll keep an eye out on 2. and on bugs in general of course.

PS: Now that measurements can fail, the value will be set to 0 and look awkward on the watch face. I solved it like this and I think this might be a good idea going forward (of course, again, the amount of dashes (-) is debatable)
image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tituscmd

tituscmd commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

Thinking about it, it would actually make a lot of sense if this updated background HR fixes my reboots:

Most of the reboots I have encountered have been when I am moving. I usually get a lot on the bike, and not so many just sitting at home. Sometimes when I'm sick and don't go out at all, I noticed uptimes of up to multiple days. All of this points to the idea that the reboots have something to do with me moving.
I originally thought that something was up with the accelerometer - of course I did, because the accelerometer is specifically for movement. But now that I thought about the updated background HR more today, maybe that's not the case.

The HR sensor on PineTime is notoriously not very good, if it works at all, when moving. That leads me to believe, that maybe the background HR was responsible for my reboots.
The new version of background HR (this PR) has the fail save function to mark measurements as failed when there hasn't been enough data for 30 seconds.
On the old version, I could imagine me being on the bike, a background measurement gets called and, since I'm moving so much, it can't gather enough data and gets stuck in that measurement loop and eventually crashes.

So maybe the fail save function in this PR has fixed that. Has anybody noticed similar behavior?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064

mark9064 commented Jul 7, 2025

Copy link
Copy Markdown
Member Author

PS: Now that measurements can fail, the value will be set to 0 and look awkward on the watch face. I solved it like this and I think this might be a good idea going forward (of course, again, the amount of dashes (-) is debatable)

I'd very much welcome a PR which replaces zero with - everywhere. And TBH we should also refactor it all to expect std::optional<uint8_t> rather than uint8_t so we can discard the hacky zero value altogether

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@WhyNotHugo

WhyNotHugo commented Aug 30, 2025

Copy link
Copy Markdown
Contributor

PS: Now that measurements can fail, the value will be set to 0 and look awkward on the watch face. I solved it like this and I think this might be a good idea going forward (of course, again, the amount of dashes (-) is debatable)

I'd very much welcome a PR which replaces zero with - everywhere. And TBH we should also refactor it all to expect std::optional<uint8_t> rather than uint8_t so we can discard the hacky zero value altogether

See: #2342

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JF002
JF002 approved these changes Nov 3, 2025
View reviewed changes

@JF002 JF002 left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very similar to what I POC'ed a while ago.

This is still more complex than I'd like it to be
Yeah, I also thought I could make this simpler, but... complexity increased as soon as I tried to handle all use-cases as well :-)

And I think this PR makes a great use of std::optional, which is great!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/heartratetask/HeartRateTask.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mark9064
mark9064 force-pushed the background-hr branch from cb6462c to 8017e88 Compare November 3, 2025 23:23
mark9064 and others added 2 commits November 4, 2025 00:05
@mark9064 @patgruber
Background heartrate measurement
f2b1383
Co-Authored-By: Patric Gruber <[email protected]>
@mark9064
Isochronous PPG sampling
21f9dfb
@mark9064
mark9064 force-pushed the background-hr branch from 8017e88 to 21f9dfb Compare November 4, 2025 00:06
@mark9064

mark9064 commented Nov 4, 2025

Copy link
Copy Markdown
Member Author

OK should be good to go now. Will try get InfiniSim PR up soon

JF002 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@WhyNotHugo

WhyNotHugo commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

@mark9064 InfiniTimeOrg/InfiniSim#180 might serve as a base :)

mark9064 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Koman10

Koman10 commented Nov 4, 2025

Copy link
Copy Markdown

@JF002 Hoi, ik zou graag even privé met je praten. Heb je een momentje?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064

mark9064 commented Nov 5, 2025

Copy link
Copy Markdown
Member Author

Sim PR is up InfiniTimeOrg/InfiniSim#184

Compiles locally
Merge this first, then bump the sim InfiniTime version? (@NeroBurner let me know what works best for you, I don't use the sim too often 😅 )

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NeroBurner

NeroBurner commented Nov 5, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

either make the sim work for both code versions or I'll merge the sim PR after this one is merged

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064
mark9064 merged commit fcc8073 into InfiniTimeOrg:main Nov 5, 2025
4 of 5 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mark9064 mark9064 mentioned this pull request Nov 5, 2025
Heart rate measurement is stops, when the screen is turned off #183
Closed
NeroBurner pushed a commit to InfiniTimeOrg/InfiniSim that referenced this pull request Nov 5, 2025
@mark9064
Updates for background hr (InfiniTimeOrg/InfiniTime#2322) (#184)
d5bfbb6
InfiniTime PR:  InfiniTimeOrg/InfiniTime#2322
This was referenced Nov 8, 2025
Battery Draining Extremely Fast #2340
Open
Sample heart rate proportional to variance / inverse to stable bpm? #2366
Open
@arjan-s

arjan-s commented Nov 21, 2025

Copy link
Copy Markdown

Due to this PR being merged, I built InfiniTime myself from current master (7128fc0) to test it. I enabled background HR from the settings, but I never got results in Gadgetbridge, whatever interval (even continuous) I selected.
Looking at the bottom of the watch, the green led doesn't even light up like it does during manual measurements. Do I need more PRs merged or settings changed to get this to work?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064

mark9064 commented Nov 22, 2025

Copy link
Copy Markdown
Member Author

HR needs to be turned enabled for background measurement to happen - do you have it turned on in the heart rate app?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arjan-s

arjan-s commented Nov 22, 2025

Copy link
Copy Markdown

Oh, that's it! Thanks!

It wasn't clear to me that it isn't enabled automatically when the background hr setting is enabled. Perhaps that would be a good improvement? Or at least a warning that it needs to be enabled from the hr app as well?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mark9064

mark9064 commented Nov 22, 2025

Copy link
Copy Markdown
Member Author

Glad it's working :)

Maybe a warning would be good? Supporting background measurements with no screen on feels a bit weird - how should we communicate that a heart rate value on screen is not being currently measured?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JF002 JF002 JF002 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

enhancement Enhancement to an existing app/feature

Projects

None yet

Milestone

1.16.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@mark9064 @tituscmd @WhyNotHugo @Koman10 @NeroBurner @arjan-s @JF002
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.