-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add Sleeptracking #2304
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
base: main
Are you sure you want to change the base?
Add Sleeptracking #2304
Conversation
|
Build size and comparison to main:
|
ba4bbfa to
c2085e0
Compare
|
It looks like the failing pipeline is due to infinisim main.cpp's instantiation of |
|
PR for InfiniSim is the way. It doesn't block review of the code here, so no rush in making it |
Related infinitime PR: InfiniTimeOrg/InfiniTime#2304
Related infinitime PR: InfiniTimeOrg/InfiniTime#2304
|
Just ran across this PR and I love it, the UIs simplicity is awesome! I'm not a sleep expert either, but I believe you move more during light sleep, so that could also be a metric for tracking the cycles. Something I've wanted is a way to wake my self up during light sleep to make the process of getting out of bed easier, perhaps this could be done by allowing the alarm to go off up to a half hour before the set alarm time if lots of unusual movement is detected, not sure if this would really work or be practical though. Anyways, I plan on testing out this PR on my pinetime soon, so I'll let you know if I find any bugs you haven't listed above. Great Work! |
This is just personal preference and the commit can be dropped if desired. Especially the sdk-toolchain part - that's just where I put the nRF5 SDK and gcc toolchain. CMakeUserPresets.json contains the various presets that I used, hence it's gitignored. node_modules and so on is just for the lv_font_conv dependency.
This is a reimplementation / reimagining of Sleep_TK https://github.com/thiswillbeyourgithub/SleepTk_pinetime_sleep_tracker/blob/main/sleep_tk.py Much of this was inspired by the efforts done in InfiniTimeOrg#2174 but architecturally this solution is signifigantly different. This has been tested on a sealed version of the InfiniTime over a couple of nights.
|
Thanks for your interest @JustScott (as well as any silent lurkers out there 😄 ). General Pain points:
Possible Solutions:
I am actually considering removing the alarm logic altogether, since waking you up is technically not part of the sleep tracking and you can just set an alarm in the Alarm app, or use a normal alarmclock or something. It might just make the app confusing though, since other smartwatches wake you up... So I'm not sure. |
|
I like the work here. I'm finding it quite hard to review though because we haven't actually figured out what this data is for yet right? I think we would need to have some other software that can actually use the recordings to give some useful information before we could ship it to users, otherwise the app effectively has no functionality for the end user. I completely get that knowing what to do with the data is difficult though. I had a glance at the literature recently, and it seems that commercial smartwatches still struggle with sleep zone determination. Since those generally have better hardware than the pinetime and more resources to design better software (e.g. comparing against a medical polysomnograph) I think we will struggle to design an accurate sleep zone detector that we could actually ship to users in any capacity. A sleep quality score might be a more reasonable target? But still I have no clue whether this is realistically achievable or not. I think we could give some metrics like sleep duration (probably just timed from when the user pressed start to the alarm time rather than anything fancy), and maybe average nighttime heart rate and number of minutes with motion detected / percentage of time still? I'm not sure how useful those numbers are to the user, but at least we wouldn't be making any medically dubious claims :) File space efficiencyFor 3): I think a binary format would make more sense here given the resource constraintsMaybe something like so? Header: start time (4 bytes), version (1 byte) (version is tied to the sampling period also) It's less convenient to parse, but a lot more efficient. |
|
GadgetBridge has some charts for sleep tracking so reporting data in a format it reads might be helpful? Not a dev, so can't really help more, but following that API seems like the best thing to do. |
|
I would like to see this feature added with automatic sleep detection and data exported in the format GadgetBridge expects. I am migrating to the PineTime from a Fitbit Flex 2 and even it was able to detect sleep, so imagine the processor in my PineTime is more than up to the task. |
I would love to do this. I just need to wade through GadgetBridge's documentation to figure out what that format is.
From my research, the best results are gained from executing a classifier / neural network-based algorithm on the data, which would probably be too much for the poor little MCU on the PineTime. There are other less accurate stochastic methods of detecting this which would be doable. |
|
Hi @sillydan1, First off great job on this, it seems to work pretty well, Second sorry just wanted to note that gadget-bridge doesn't really have a preferred format, as it is designed around the vendor having a preexisting output and then you just update create a library in gadget-bridge's code to take in the output of the device, I think they mention to lookup the implementation for bangle.js for inspiration or guidelines but it does mean you get it to output the data pretty much however you want and then you just have to create a library on the gadget-bridge side to receive it, That would be written in Kotlin/Java i think so if you aren't really comfortable coding or have no experience with it, then possibly try using the bangle.js implementation and then just copy and refactor the gadget bridge library code for that if you want, Hope this is helpful Some links: |
Sleeptracking 🛌 💤
This PR adds a sleeptracker with it's own isolated alarm system for wake-up functionality.
This was spurred on by the progress made in #2174 and I took a lot of inspiration from there as well as the approach taken in https://github.com/thiswillbeyourgithub/SleepTk_pinetime_sleep_tracker/blob/main/sleep_tk.py .
I've deliberately tried to keep things as simple as possible and have not implemented extra features such as automatic sleep detection, REM detection etc. I thought it'd be enough to just have the data tracked and a gentle wakeup-alarm - then post-processing can detect REM and sleep quality. I'm no sleep-scientist, I'm a software engineer so I tried to stay within my own domain.
Features
Showcase
Not tracking (setting the alarm)
Tracking
Plotting the data
I've created a
gnuplotscript for plotting the sleep data. Execute with the following command.Example session (session 3): session-3.csv
I've been using this for a couple of days (nights) now. Here are my sessions. Note that I am usually a heavy sleeper, but these past 3 days have been quite light due to pollen allergies.
Known Bugs
So far it's been quite good. But during my testing I've noticed some bugs that I can't really pin down and would like so assistance from more experienced maintainers.
The logfiles are not being cleared, only appended. This means that the app will eventually fill out the external flash.I did some attempts at alleviating this, but so far to no avail.Possible Future Improvements
General feedback
I know this is completely unwarranted, but I just wanted to give some feedback to the project, because I think it's really cool and want to see it improve.
SystemTask,DisplayAppas well asmainandCMakeLists).Alarmapp could benefit from having multiple alarms set at the same time (say max 5 or so).Please note that this PR description is not written by an AI - I am just a very wordy person.
I had a lot of fun creating this. It was a great opportunity to get more FreeRTOS familiarity and I hope it'll get merged 😄