Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfiniSleep: SleepTk Port #2170

Closed
wants to merge 0 commits into from
Closed

Conversation

cyberneel
Copy link

A SleepTk port that can help with setting a suggested wake alarm based on sleep cycle goals.

Another feature is the gradual wake feature that vibrates at intervals to slowly wake you up instead of a full-blown alarm.

Another big feature is the sleep session tracking. You can start a session once you are going to sleep and stop it once you are awake. It has information like cycle count and total sleep time to help you understand why you are tired when you wake up.

@cyberneel cyberneel changed the title InfiniSleep: SleepTkport InfiniSleep: SleepTk Port Nov 24, 2024
Copy link

github-actions bot commented Nov 24, 2024

Build checks have not completed. Possible reasons for this are:

  1. The checks need to be approved by a maintainer
  2. The branch has conflicts
  3. The firmware build has failed

@tituscmd
Copy link
Contributor

Is the sleep cycle/duration tracking done by an algorithm that calculates it via hrm and accelerometer data or is it done by simply starting and stopping the tracker and counting the time between that?

@cyberneel
Copy link
Author

For now, it is done using start-stop. I am looking into using sensor data, but looks like without a solid algorithm, this is the most accurate for this watch.

@cyberneel
Copy link
Author

@tituscmd I can't seem to figure out why the build check isn't working. Could you please help me?

@mark9064
Copy link
Member

Try building all of the targets locally - when you run make specify make all rather than just the pinetime app

@tituscmd
Copy link
Contributor

I haven't created a PR yet so unfortunately I don't actually know either 😅

@tituscmd
Copy link
Contributor

For now, it is done using start-stop. I am looking into using sensor data, but looks like without a solid algorithm, this is the most accurate for this watch.

Is there anything stopping you from using an algorithm like the Pillow app (iOS) does? You could perhaps offload the calculating of when you fall asleep and the different cycles and whatnot to InfiniLink to save storage.

@mark9064 mark9064 added new app This thread is about a new app new feature This thread is about a new feature labels Nov 24, 2024
@tituscmd
Copy link
Contributor

https://www.nature.com/articles/s41598-023-36444-2

I haven't read the entirety of it yet, partly because it's rather late, but maybe this is a step in the right direction 🙂

@cyberneel
Copy link
Author

@tituscmd I have heard that the Pillow app (iOS) is pretty accurate, do you know if the algorithm is available online? That might be a good lead for me. There isn't much stopping me other than memory constraints, so far I can guarantee data logging on the watch. Offloading to the companion app is definitely possible.

@tituscmd
Copy link
Contributor

tituscmd commented Nov 25, 2024

I'll try to find out if Pillow's sleep tracking algorithm is available online. If not, you can check out the link in my latest message.

Edit: After a bit of researching, it seems the actual algorithm is not known. The only thing I can find is that they say they use HRM and accelerometer data to estimate sleep amount and sleep cycles.

@cyberneel
Copy link
Author

@tituscmd @mark9064 Can one of you run the actions to see if it works now? Thanks!

@cyberneel
Copy link
Author

https://www.nature.com/articles/s41598-023-36444-2

I haven't read the entirety of it yet, partly because it's rather late, but maybe this is a step in the right direction 🙂

I haven't read too deeply, but seems like a ML implementation which I think is difficult to pull off on the watch.

@mark9064
Copy link
Member

At the moment you're using your main branch for this PR. You have quite a few other features on this branch like background HR, flashlight changes, local VS code config changes etc that I'm guessing you didn't mean to include (you can see a list of all the changes at https://github.com/InfiniTimeOrg/InfiniTime/pull/2170/files) - each feature needs to go in its own PR so the other features need to be removed from this branch first. It might well be easier to create a new feature branch on your repository so you're free to do whatever you like with your main branch, and then use the new branch for this PR.

If you want to use a separate branch for this feature, I believe you will need to open a new PR from that branch as AFAIK github does not let you change the source branch of an existing PR

Branch management can definitely get complex so if this doesn't make sense please say, I can try to clarify :)

@cyberneel
Copy link
Author

@mark9064 The flashlight was just an early test for me to learn the codebase and I think I merged the background HR for personal use. I'm not too versed in branch management, could you help me understand the steps to have a branch without the other changes?

@vkareh
Copy link
Contributor

vkareh commented Nov 26, 2024

I'm not too versed in branch management, could you help me understand the steps to have a branch without the other changes?

Without messing up your main too much, I would first save your changes to a separate branch:

$ git checkout main # this is to ensure you're in the right place
$ git checkout -b dev # this is a new branch that will have everything you currently have in main
$ git push # to save dev to github for safekeeping

Now that your changes are safely put away, we can blow over main to match the upstream InfiniTime code:

$ git checkout main # make sure you're in the right place
$ git fetch <upstream> # This gets the latest from InfiniTime. Here <upstream> refers to the remote name you have your InfiniTime:main, as opposed to your cyberneel:main - you find it with `git remote -v`
$ git pull <upstream> main # this merges the latest InfiniTime into your own fork
$ git push --force # caution: this will blow up any changes you have in main, but they should be safe in the new dev branch from above... Maybe there's no urgent need to do this just yet until we know it all works...

Okay, we're now in "clean slate" mode: your changes are safely saved in a dev branch and your local main matches what's on github.com/InfiniTimeOrg:main. Next is to create a new branch just for the sleep tracker:

$ git checkout main # always good to make sure you're in the right place...
$ git checkout -b sleep-tk-port # this is your new feature branch

Now the hard part: you need to cherry pick changes from your dev branch into your new sleep-tk-port branch:

$ git log dev # this will show you all the commits. Copy the hash of the first commit (which is _not_ the top one, but the bottom one of this change)
$ git cherry-pick da19c6ad6c6934483799aeda84c6d9b32fbdfb06 # this effectively cherry-picks the commit from the `dev` branch into your `sleep-tk-port` branch, commit message and all.
$ # now repeat the same `git log dev` and `git cherry-pick <hash>` on every commit in the correct order. You can also do many at the same time: `git cherry-pick <hash1> <hash2> <etc>`. The tricky thing here is to make sure you _only_ pick commits that belong in the sleep tracker, and avoid all other changes (flashlight stuff, other things merged from main, etc.)

If this works, your sleep-tk-port branch will have only the sleep tracker and nothing else. You should be able to now git push and create a new merge request.

In case you accidentally mess it up (it's very easy to mess this up), I've followed these steps myself and push them to a branch in my fork for safe-keeping: https://github.com/vkareh/InfiniTime/commits/sleep-tk-port/

In the future, a good practice is to always start with a clean up-to-date main (git checkout main && git fetch upstream && git pull upstream main && git push) and create a new feature branch for anything you're working on (git checkout -b feature-foo-bar)

@vkareh
Copy link
Contributor

vkareh commented Nov 26, 2024

Alternatively, you can just remove any commits from this branch, then create a new branch off it:

$ git rebase -i 0fe50c5d75449daa0c9c51bdc1af511a0188d206~1 # this opens an editor with all commits starting from the "upgraded flashlight app" one.

Then go through all unrelated commits and change from pick to drop. It would look something like this:
Screenshot at 2024-11-26 15-58-31

Then save and exit. You'll need to fix conflicts (I identified one for sure):

CONFLICT (content): Merge conflict in src/heartratetask/HeartRateTask.cpp
$ vi src/heartratetask/HeartRateTask.cpp # make changes as needed
$ git add src/heartratetask/HeartRateTask.cpp # add the updated file
$ git rebase --continue

Repeat if needed until all conflicts are solved, then you should have a cleaned up main branch.

Next step is create a new feature branch off it:

$ git checkout -b sleep-tk-port
$ git push

And you're done.

@cyberneel
Copy link
Author

Thanks for the info, there are actually far less changes NOT relating to the sleep tracker. So what if I made a branch which all my changes and reset the main branch like you suggested, but on the branch I just undo the changes manually and make new commits, how does that compare?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new app This thread is about a new app new feature This thread is about a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants