-
Notifications
You must be signed in to change notification settings - Fork 3
Interested in porting to InfiniTime #13
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
Comments
Great to hear! Thanks a lot! |
I've looked into it a little further. I think I should be able to finish this by the end of the week. |
That's awesome! Can't wait to test it out. |
I'm so looking forward to this! |
Likewise. @lxrst , do NOT hesitate to ask me anything about a feature or aspect you have trouble to implement. I am sure choices will have to be made to cram as much feature as possible into the infinitime code but I would absolutely hate to waste some of your time if you made a call on your own that turned out to be questionable in the eyes of long time users. SleepTk is pretty simple in some aspect but quite advanced in others! I used it for literal years and have not changed the code for the last few, not ouf of laziness but because it was feature complete. Also I'm sure some parts of the code might be weird and I would gladly explain them. As I'm writing this, the bounty is at $100 from me + up to $76 CAD from @Koloss0 Also, despite the name, the wakeup features are way more important than the tracking:
I'm so excited :) |
Is SleepTK able to detect the different sleep phases? Or is it purely duration? |
Hi, So initially the plan was indeed to track the actual sleep cycle. But then I stumbled upon one paper that I think I linked in the bibliography. And the conclusion was that the main predictor of accuracy of a sleep tracker was actually just biasing with a clock. If I recall correctly, it was far better than any fusion of combination of sensors you could put on a watch. So I decided to remove this part of the code which had the benefit of greatly reducing the complexity as I was computing autocorrelations with reference signusoidal functions at some point for example. But in the end I became aware that it was actually not needed at all because the average sleep cycle is roughly 90 minutes. And the biological tolerance for waking up refreshed is in the order of maybe 30 minutes. So if you have a very rough approximation of the current sleep cycle you're in then if you put slight vibrations to gently wake the user, it works. What I mean is that I became confident that there was no way I could get a high confidence on estimating the sleep cycle and it became not important when wakeup features were stable. Also something important to understand is that if the sleep cycle was disrupted during the night, then you are very quickly out of the envelope of the usual algorithms by other watches anyway. The TLDR is that waking up with appropriate vibrations patterns is way more important than computing the sleep cycle. If the objective is to wake up feeling refreshed, that is. But if you're just interested in tracking your health, then you shouldn't rely on most consumer product algorithm at all nor mine I'd say. |
That makes a lot of sense. I don't necessarily need any of the sleep phases, sleep duration would be sufficient if we want to maximize efficiency and whatnot. |
What is important though is that the user gets to know:
|
Is there a feature to wake you up a set amount of hours (in a fitting sleep stage) after falling asleep? |
Initially there was, but I removed that part too because I noticed that it was actually quite constant so it was better to leave that handled by the user to decide its own offset. And in the case where the person takes really too long to get to sleep, then it makes sense to yourself think about setting the alarm again just like a regular alarm clock. It's better than over engineering a python app with so little ram. Additionally, the natural wake feature can solve potential issues around this because you can set it to only wake you up if you are in a good part of the cycle by doing tiny vibrations every 30s etc |
Hypothetically, let's say I go to bed at around 8pm and have to get up at 5:30am. If I start the sleep tracker at 8pm, will it accurately track my sleep duration even if it takes me, say, 1h to actually fall asleep? |
Tracking can be disabled, or track motion or motion + heart rate. It's not telling you when you were asleep specifically. You'll just have the raw motion + hr data and can post process it however you like. I did try and you might find some old commits that overengineered everything to try to infer sleep etc but concluded that it made no sense as a feature as it added a lot of noise and lines and above all a false sense of trust from the user to the algorithm which can't beat established companies algl that are themselves not satisfying compared to polysomnography (the current gold standard) I plan on buying a colmi smart ring someday and use it to store my raw sleep data to gadgetbridge. But it can't vibrate obviously so it might be a nice setup to have both. |
Also, keep in mind that the average sleeper sleeps at best 5 cycles per night. Each cycle get shorter and shorter as the night progresses. The cycle length decreaes with age. The hr drops samples and is not fully reliable on waspos. Alcohol, coffee, exercise, deeply impact some aspects of the cycles. External temperature too. Having a mosquito bite that makes your hand reach to scratch counts as motion. Having your significant other pull the sheets etc. There's at lot of factors at play and with 5 datapoint per night I firmly concluded that it was over engineered and couldn't reasonnably expect a reliable accuracy, especially on out of distribution nights where it matters the most arguably (sleeping in a hotel?). Wake up features on the other hand are an absolute gamechanger and with @lxrst 's work there's a chance it can be used by more than a few lone waspos geeks :) |
I might just not understand correctly, and if so please tell me, but if it isn't telling me when I was asleep specifically, then what part of it is actually the sleep tracking part? Or is the entire thing mostly just an advanced wake up feature? |
I concede that the name is at this point confusing. It started as what you imagine. But I removed the advanced stuff that tried to infer sleep quality and cycles, left raw data tracking (motion and hr), kept the advanced wakeup features. So is it tracking your sleep ? Kinda. It can be tracking your body throughout sleep, which is what all other sleep trackers do. Arguably they just lie about telling you you had I am curious about your feelings about all this. I thought I was being quite explicit about all that in my messages and docs no? |
Tldr: i thought tracking my sleep was what I needed to wake up well and recover efficiently but actually I was looking for advanced wakeup features all along. Maybe so are you! |
I understand that and looking at the docs, it makes sense. But the naming of "sleep tracker" implies things like sleep duration and tracking of sleep stages imo. Since I have fixed wake up times because of school, advanced wake up features would not be in my interest most days. I would rather wake up and know "Oh nice, I've actually slept 8hrs 18min this night, that's cool". I was thinking that would be trackable via drop of BPM and motion, and when your BPM falls under a certain threshold thats x BPM lower than before for x minutes, then you've most probably fallen asleep. But because of my limited knowledge and experience in these programming languages, I don't actually know how feasible that is. |
I'm getting slightly off-topic here, but it goes to use-case, your honour! 😅 AIUI the purpose of the smart wake features (certainly in SleepAsAndroid and I'm fairly confident SleepTk as well) is that if you have a fixed wake time there's no guarantee of which sleep phase you'll be in at that fixed time, and being woken during deep sleep leaves you feeling groggy and unrefreshed. So the idea is to wake you "at or before" that fixed time, by choosing a point where your sleep stage is conducive to feeling refreshed when awoken. SleepAsAndroid does this by trying to detect when you are in a light sleep phase by tracking movement etc, and my impression is that SleepTk aims to do this by using the subtle "wrist-tap" alarm so that it wouldn't disturb deep sleep but will rouse you from light sleep (apologies if I am mis-characterising SleepTk, I am not yet a user). So it's folk who have a "fixed wake commitment time" that stand to benefit most from smart-wake times because they don't have the luxury of just sleeping until they wake "naturally". I've had DSPD (delayed sleep phase disorder) since I was a baby (and lots of folk have it temporarily from early teens to mid-late twenties), and it makes waking up to a morning alarm hell on earth. Apps like SaA or SleepTk would have been pretty handy in those first forty years for me, but alas, all I could do was set up ever-more impactful alarms, taking the nuclear arms race option for battling waking. My natural wake time was around 2pm. Schooling (and work!) was pretty rough. Sorry - didn't mean to turn that into a pity party! Just that I wanted to point out where smart-wake can fit in with a fixed waking commitment, and also do a little awareness-building about DSPS/DSPD and circadian disorders, because GPs and many sleep specialists are still completely unaware of many of them, and sometimes hearing an "oh, that me" story is what it takes to get some answers. |
As a student finishing medical school my opinion is that you overestimate the usefulness of such a noisy metric. The errors bars are tremendous and likely only plausibly informative on very controlled nights. Lying in bed thinking already is a dip in the HR. You can have spikes because of dreams etc. Personnaly I just set SleepTk at the last few minute before falling asleep and turn it off at wake so I treat the time of sleep as a maximum estimate and mentally adjust by just knowing if it took me more or less time than usual to fall asleep. Also waspos has a bug with HR that infinitime does not. So using hr as a primary sensors was not an option. Regarding the name, I considered changing it but it feels also off to not call it tracking because it is tracking sleep just not cycles. I am absolutely open to suggestions. BetterWaker? |
So SAA does that. Sleeptk wanted intially to do that but it ended up a bad idea because waking up gradually achieves the same purpose in a better overall setup as I explained above in more depth.
Close! This is only the NaturalWake feature. I use it when I want to sleep as long as I can while feeling refreshed on wake. The other alarm type is a vibration pattern gradually increasing in strength and decreasing in intervibration delay. With all that customizable as a top level variable.
For those nights I use the "not natural" wakeup mode I just described. Otherwise yeah spot on.
I'm sorry to hear that. I'm optimistic it could help you, and opine that regular algorithms of sleep tracking would be out of their spec envelope for regular hours for the same reason tracking the sleep of someone without DSPD in the afternoon would be out of distribution.
Apologies not accepted, your clarifications were useful I think so thank you :) |
Thanks, this might be relevant to sleeptk's infinitime version as the HR will be accurate there. If I recall correctly, the gadget bridge Android app supports a specifying specific sleep metadata through their api |
I'd be very glad if the automatic equivalent of what I do with the graphs would be implemented into the sleep tracker. Don't hesitate to contact me if you need any HRM data like that again. |
Thanks but as there is no way to send data to GB from waspos it's out of my hands, and into the eventual porter's. |
Hi @lxrst are there any news on your side? As a reminder and IRC there's at least $174 waiting for you if you pull this off :) |
That's really good timing because I've been using it every night since it worked so it's less of a rush :) thanks again. (Also I didn't mention the HR tracking and motion tracking code I think, it's not part of my bounty but part of @Koloss0 ) |
@thiswillbeyourgithub planning to look k to HR and motion once the wake feature get polished. Is there anything else for your bounty? |
To keep track I created another issue there #15 Do you agree with what's in it? I can totally have made a mistake so please be honest! Also you can totally disagree so tell me so we can clear things up |
@thiswillbeyourgithub I think it looks right, but I thought the extra 10% was for adding the random button movement to make stopping harder? |
No, I offered $10 for that feature, the 10% is, and I quote:
|
@thiswillbeyourgithub Ohh, thanks so much! |
Just a point about the rebooting thing, "validate firmware" is a required step after each flashing of infinitime. If you don't do it, the next time the watch reboots it will boot up the previous flash image. This means that if you haven't validated, that reboot will put you back to the previous version of infinitime (and infiniSleep) so you'll be testing the older version again. This doesn't explain why your watch is rebooting, but might explain why it only reboots once. |
@thiswillbeyourgithub Here is a release with Natural wake and pushes to stop added to settings. |
Oh wow TIL thanks a lot.
Thanks, will test the next night |
I'm not sure if I properly validated the firmware you sent me so I might be using the wrong one. Could you send me the latest firmware to be sure? |
@thiswillbeyourgithub have you had a chance to test it? At this point, I think I have all the features implemented. I'm looking at way to optimize code for the PR that's open. |
Unfortunately the first night sort of worked but I had forgotten to validate the firmware so it rebooted etc. On the second night it seems to have NOT rang at all so there might be some stability issue, I will try again tonight. I was wondering, is that complicated to add a third option "both" to use gradual wake AND natural wake ? That's what I was doing for sleeptk and think it's probably better. You see if you have only a vibration every 30s (natural wake) your brain can end up totally ignoring it because it's fully predictable. That's part of why the gradual wake is ramping up in strength and is more and more often: it's harder to ignore while remaining somewhat gentle. In my mind it seems reasonnably easy to add and I think fits in the bounty but we can talk if you disagree. Also what would you think about renaming "gradual wake" to "prewake"? That might be clearer no? I'll try the next few nights for natural wake but I'm guessing that by friday at the very latest I'll have sent the money. |
@thiswillbeyourgithub I think the renaming and the both option is good, I'll see if I can add it later today and send that. |
@thiswillbeyourgithub can you explain a little more what you mean about the natural wake, you want it to ramp up like the normal alarm but keep that 30 secs trigger? |
@thiswillbeyourgithub Here is the new release with the "both" option and the gradual wake renamed to PreWake. I also added the ramping up effect the normal alarm had to the natural wake alarm, let me know what you feel about the way it works. |
2nd try: unfortunately it still failed, meaning I set the alarm to 7am and woke up because of my phone alarm. When looking at the app the timer was set to 7:33 and the start/stop button was saying "start". No prewake happened, no wake either. Yesterday it was in mode natural wake and today in gradual wake.
Hm the "both" means have the prewake closer and closer before 7am, then at 7am instead of doing the ramping up stronger and stronger every 1s or so use the 1 vibration every 30s which wakes you up only if you're in a light sleep. Is that clearer?
I'm sorry this was a mistake: the prewake only gets closer ane closer in time and we settled on not ramping up the strength iirc.
So this was not what I had in mind I'm sorry for being imprecise, but it might actually be a better idea to ramp up the natural wake like so. Thanks a lot! Let's keep it your way. I'll flash the new release and try again tonight, but so far it seems to have been broken for a few days. |
Also, and NOT a criteria of the bounty, can the start and stop time be stored and sent to gadgetbridge as a way to record the total sleep? That would be terrific. I'll add $10 if you're interested. This can all be much later than the current bounty if you want. |
@thiswillbeyourgithub the session data is currently stored in a file, I'm not sure how gedgetbridge does things but the data is there to pull. Also about the alarm not ringing, it sounds like it crashed at some point then. I've been using the firmware and natural wake have been working find last two nights. Since it's difficult for me to find the crash reason right now, I'll see if I can add a way to recover from a crash, like ringing immediately if it's past time. |
Btw I have a colmi r10 (?) smart ring. Every morning on gadgetbridge when I pull to refresh the data I get sleep data. I'm thinking it might be straightforward to add the missing pieces? |
@thiswillbeyourgithub It is open source so I think it is simple but there is more stuff happening most likely. I would need to add checks to make sure it's new data and stuff. I'll look into it later. |
Alright so I'll add the 10 extra dollars in advance for you to try. If it ends up being too complicated, if you could at least document why in the infinitime PR (or anywhere else you deem fit) to make it easier for others that would be great, in all other situations count it as a small tip. I won't rollback my decision to give the bounty but I noticed some more things re the app:
|
@thiswillbeyourgithub Thanks for the great feedback! For the turning off, do you mean the tracker? I didn't do anything about it because there is an OS wide setting for sleep mode that ignores motion wake and tap to wake. You have to swipe to the right from the clock screen and tap the notification icon until it is the moon icon. About the reboot, I've been trying to find out more about it, but I've only ever had it reboot 1/5 mornings for me roughly so far on the version I was testing. It could be an OS issue which is why I will mention it in the PR I opened so someone with w dev kit can debug it more efficiently. Initially, I thought it could be a part of my code that runs outside of the app screen, but after checking, none of it runs in a way that causes that. |
Alright thanks! |
This morning again when I woke up the alarm was disabled. I'm thinking I missclicked during the night at about 3am. Is there a more recent release I could flash? Lots of code seems to have happened since I flashed. |
@thiswillbeyourgithub Im not not what I added since you last flash, one big thing was brightness, I made the app set brightness to low and only restore brightness when leaving app AND tracker is off. Also about misclicking, have you tried the OS's sleep mode I was talking about. In that mode raise to wake and tap to wake are disabled which makes misclicks harder. |
I'll put the release up later. |
oh i thought it was enabled automatically during sleeptk's operation. Is it not ? |
@thiswillbeyourgithub no it's not, since it's a system setting I didn't want to edit it. |
It seems to have worked, thanks a lot! |
Sorry, I'd forgotten about this. I haven't put much work into it yet, but I'm able to start working on this now. I'll post updates as soon as I have something.
The text was updated successfully, but these errors were encountered: