Compare commits

...

494 commits

Author SHA1 Message Date
0fff5cbb35 Add SleepTk into the software menu 2022-06-14 23:05:48 -04:00
e7f53f1d25 SleepTk: Adapt for mainline accel_xyz() impl 2022-06-14 22:42:50 -04:00
978b647cea Disable more apps
...and remove the disabled apps from the Software app
2022-06-14 22:41:29 -04:00
a7a20608b2 Revert "Remove more unused apps"
This reverts commit f38a9391c3.
2022-06-14 22:30:36 -04:00
c8c58f80e1 Build SleepTk 2022-06-14 22:30:29 -04:00
3571e14f81 Add 'external/SleepTk/' from commit '7ce31f74f19b943b43d1f65ad778f68b9820ef38'
git-subtree-dir: external/SleepTk
git-subtree-mainline: f38a9391c3
git-subtree-split: 7ce31f74f1
2022-06-14 22:20:31 -04:00
f38a9391c3 Remove more unused apps
...to make room for SleepTk
2022-06-14 22:19:48 -04:00
402a02e3aa Remove some unused apps
The step counter app is special-cased in wasp.py. Remove that as well.
2022-06-14 22:16:57 -04:00
thiswillbeyourgithub
7ce31f74f1 new: ramp up over 60s instead of 10 2022-06-13 21:06:11 +02:00
thiswillbeyourgithub
9ca0760a3b minor: typo 2022-06-13 20:53:51 +02:00
thiswillbeyourgithub
c2994a5fa1 docs: mention time to fall asleep 2022-06-13 20:53:45 +02:00
thiswillbeyourgithub
f5bc059cad feat: ramp up vibration to avoid waking up the gf 2022-06-13 20:51:27 +02:00
thiswillbeyourgithub
1a5c552df8 feat: automatically updates hours when minutes is updated 2022-06-07 12:42:04 +02:00
thiswillbeyourgithub
3de209fa04 new: turn off tracking by default 2022-05-28 18:07:57 +02:00
thiswillbeyourgithub
f3516cc755 minor: smaller string 2022-05-09 21:21:25 +02:00
thiswillbeyourgithub
96ab17075d fix: vibration duty cycle from 50 to 25 2022-05-08 13:55:43 +02:00
thiswillbeyourgithub
e0dde35c1b minor: renamed time_to_fall_asleep to minute_to_fall_asleep 2022-05-08 13:55:43 +02:00
thiswillbeyourgithub
c78c0b12d5 new: gradual wake by default over 10m instead of 15 2022-05-08 13:55:43 +02:00
thiswillbeyourgithub
db9350dffc fix: wrong string printed at the end of ringing 2022-05-06 18:31:37 +02:00
thiswillbeyourgithub
4201f264a9 fix: properly reload screen after stopping alarm 2022-05-06 16:59:31 +02:00
thiswillbeyourgithub
fc90854e5c new: write to file when screen has been turned on 2022-05-06 16:59:13 +02:00
thiswillbeyourgithub
3990431395 fix: don't turn screen of immediately if interacted less than 5s ago 2022-05-04 11:00:12 +02:00
thiswillbeyourgithub
b1dccb3126 fix: allow floating point gradual wake 2022-05-04 10:59:36 +02:00
thiswillbeyourgithub
5e1a7358b4 set default cycle length back to 90 2022-05-04 10:58:35 +02:00
thiswillbeyourgithub
f048c7522e fix: reset values after snoozing 2022-04-29 09:11:18 +02:00
thiswillbeyourgithub
4a7330aa6f fix: stop snoozing at stop limit 2022-04-29 09:11:07 +02:00
thiswillbeyourgithub
061ab1fe4e set default cycle length to 85 minutes for testing 2022-04-28 15:52:34 +02:00
thiswillbeyourgithub
dd46d36a40 fix: keep awake when ringing 2022-04-28 15:51:58 +02:00
thiswillbeyourgithub
b9a5ca7382 Merge branch 'main' of https://github.com/thiswillbeyourgithub/sleep_tracker_pinetime_wasp-os into main 2022-04-27 22:10:28 +02:00
thiswillbeyourgithub
45d78a48ce track HR by default every 5 minutes 2022-04-27 22:08:49 +02:00
thiswillbeyourgithub
9658416e46 track heart rate for only 10s 2022-04-27 22:08:38 +02:00
thiswillbeyourgithub
2b1b69f1b4 autoreboot when downloading files + use tqdm 2022-04-27 22:06:43 +02:00
thiswillbeyourgithub
025342dd8f add plotting instructions for heart rate 2022-04-27 22:05:44 +02:00
thiswillbeyourgithub
82d1e6ae0b disable gradual wake by default 2022-04-27 11:12:16 +02:00
thiswillbeyourgithub
8d951d6c39 fix: don't print sleep duration before user fell asleep 2022-04-27 11:12:16 +02:00
thiswillbeyourgithub
901de46037 fix: don't print sleep duration before user fell asleep 2022-04-26 12:23:57 +02:00
thiswillbeyourgithub
dbd72798f2 fix: forgot to take time to fall asleep into account 2022-04-26 12:22:44 +02:00
thiswillbeyourgithub
b62875eb5e renamed btn_al to btn_snooz 2022-04-25 15:31:12 +02:00
thiswillbeyourgithub
c72c7aec7b fix: when snoozing, disable HR tracking 2022-04-25 15:29:20 +02:00
thiswillbeyourgithub
a05739b856 todo 2022-04-25 15:24:23 +02:00
thiswillbeyourgithub
f2e5914f30 fix: reset last printed HR when starting tracking 2022-04-25 15:11:12 +02:00
thiswillbeyourgithub
78d6a6ce04 docs: warn about bluetooth being turned off and the simulator having a hard time 2022-04-25 15:06:19 +02:00
thiswillbeyourgithub
e297d37c34 docs: update readme 2022-04-25 15:05:58 +02:00
thiswillbeyourgithub
206333dc67 update which commit is important 2022-04-25 15:02:26 +02:00
thiswillbeyourgithub
911921784b fix: reduce font for smart alarm button because too large for unmodified waspos 2022-04-25 14:29:18 +02:00
thiswillbeyourgithub
ae474ea1d9 docs: mention to edit settings and implement relevant commits 2022-04-25 14:25:57 +02:00
thiswillbeyourgithub
68914d6505 new: number of sleep cycle goal is now modifiable 2022-04-25 14:21:44 +02:00
thiswillbeyourgithub
872907a257 better comment 2022-04-25 14:18:10 +02:00
thiswillbeyourgithub
d3c8f0bc12 new: default suggested wake up time is user modifiable now 2022-04-25 14:17:33 +02:00
thiswillbeyourgithub
f7dbc28df7 style: clearer comments for user settings 2022-04-25 14:17:15 +02:00
thiswillbeyourgithub
8ec294b48d renamed _offset to _track_start_time 2022-04-25 13:53:24 +02:00
thiswillbeyourgithub
6fa24dd9a5 minor: better way to reset draw 2022-04-23 19:32:16 +02:00
thiswillbeyourgithub
8fefcaa627 fix: tweaking ticks was a bad idea 2022-04-23 19:16:20 +02:00
thiswillbeyourgithub
576a0e7509 feat: auto kill bluetooth while tracking 2022-04-23 19:14:17 +02:00
thiswillbeyourgithub
5740be7e0c new: request tick on foreground but disable ticks if not needed anymore 2022-04-23 19:01:19 +02:00
thiswillbeyourgithub
767c0a9ed9 minor: call collect when sleeping 2022-04-23 19:00:59 +02:00
thiswillbeyourgithub
e252c660d0 minor: style 2022-04-23 18:36:05 +02:00
thiswillbeyourgithub
d577393aba new: enable heart rate tracking by default 2022-04-23 18:35:40 +02:00
thiswillbeyourgithub
ac336f2736 fix: try to make sure app is on when ticking 2022-04-23 17:55:31 +02:00
thiswillbeyourgithub
ef9cfe664a fix: handle case where heart rate read is None 2022-04-23 17:55:31 +02:00
thiswillbeyourgithub
30fe0c1d9f fix: remove wake() as it is not needed I think 2022-04-23 17:53:28 +02:00
thiswillbeyourgithub
158b7d95b3 minor 2022-04-23 17:28:41 +02:00
thiswillbeyourgithub
6fea95eafb fix: make HR tracking less memory hungry 2022-04-23 17:28:34 +02:00
thiswillbeyourgithub
4964197e41 fix: cancelling alarm when stopping snoozing 2022-04-23 16:59:41 +02:00
thiswillbeyourgithub
3aa6a22c83 fix: force screen to be on if user is interacting 2022-04-23 16:58:48 +02:00
thiswillbeyourgithub
2f97bfbb96 fix: snooze time was not updated to tracking page 2022-04-23 16:26:49 +02:00
thiswillbeyourgithub
576198da21 docs: mention snooze feature 2022-04-23 16:24:10 +02:00
thiswillbeyourgithub
dbda0488fa docs: reorder items 2022-04-23 16:23:59 +02:00
thiswillbeyourgithub
9ed2e9ccd0 new: save space by deleting Smart Alarm if it's not started 2022-04-23 16:22:04 +02:00
thiswillbeyourgithub
a4f2dfba88 docs: better docstring 2022-04-23 16:17:50 +02:00
thiswillbeyourgithub
28528f4f7e fix: make sure not to sleep watch at the wrong time 2022-04-23 16:17:38 +02:00
thiswillbeyourgithub
189011039d fix: potential race condition 2022-04-23 16:17:03 +02:00
thiswillbeyourgithub
f6d3c772fb fix: don't redraw if touching duration 2022-04-23 16:16:43 +02:00
thiswillbeyourgithub
46ba76aae9 fix: handle swipe gestures better 2022-04-23 16:16:29 +02:00
thiswillbeyourgithub
641d3bcb2a minor: style 2022-04-23 16:16:11 +02:00
thiswillbeyourgithub
9cb0932784 fix: make sure to turn on the screen if drawing 2022-04-23 16:16:02 +02:00
thiswillbeyourgithub
8131613a8e renamed n_swipe + make it reset between run 2022-04-23 14:03:29 +02:00
thiswillbeyourgithub
20df035559 minor fix 2022-04-23 14:00:39 +02:00
thiswillbeyourgithub
631ee530ab new: faster screen redraw 2022-04-23 14:00:39 +02:00
thiswillbeyourgithub
bbbe90bd78 feat: ability to snooze and make it harder to disable when ringing 2022-04-23 14:00:39 +02:00
thiswillbeyourgithub
19470cf07c new: add tqdm to scripts 2022-04-23 13:34:42 +02:00
thiswillbeyourgithub
7e88ff8929 new: put watch back to sleep after vibrating or tracking heart rate 2022-04-23 13:34:24 +02:00
thiswillbeyourgithub
3aad2490a1 update screenshots 2022-04-23 13:21:45 +02:00
thiswillbeyourgithub
b00ae8cb4b new: red font to reduce eye strain 2022-04-23 13:20:03 +02:00
thiswillbeyourgithub
fe7ed1f99a new: more robust handling of bpm 2022-04-22 18:48:20 +02:00
thiswillbeyourgithub
da84052a09 fix: cast last HR to str before saving 2022-04-22 18:45:30 +02:00
thiswillbeyourgithub
6e758dca11 minor: comments 2022-04-22 18:45:15 +02:00
thiswillbeyourgithub
41d557c44c minor: comments 2022-04-22 18:25:33 +02:00
thiswillbeyourgithub
1b3a0651e8 new: consider HR normal if between 30 and 100 2022-04-22 18:24:44 +02:00
thiswillbeyourgithub
eeb9eddb70 minor 2022-04-22 18:22:13 +02:00
thiswillbeyourgithub
b9a1718d9b todo 2022-04-22 18:22:07 +02:00
thiswillbeyourgithub
31681f85a3 docs: mention insomnia insights 2022-04-22 18:06:47 +02:00
thiswillbeyourgithub
17b52302c3 docs: heart tracking is not in alpha anymore 2022-04-22 18:06:34 +02:00
thiswillbeyourgithub
6e051df404 pressing button while tracking does nothing instead of returning to home 2022-04-22 18:01:18 +02:00
thiswillbeyourgithub
7c0c5550ea new: if updating HR too often averages the values instead of erasing it 2022-04-22 17:59:20 +02:00
thiswillbeyourgithub
8b4b80ae77 fix: sleeptk was returning to home for some reason 2022-04-22 17:53:47 +02:00
thiswillbeyourgithub
42b87c2925 fix: button management 2022-04-22 17:51:24 +02:00
thiswillbeyourgithub
61c7d10823 renamed a lot of var 2 2022-04-22 17:39:19 +02:00
thiswillbeyourgithub
83d59cb7b1 renamed a lot of var 2022-04-22 17:37:30 +02:00
thiswillbeyourgithub
9c05c549a7 fix: undeclared var when disabling tracking if not tracking 2022-04-22 17:28:07 +02:00
thiswillbeyourgithub
40d956a0de fix: finish heart tracking when disabling 2022-04-22 17:27:54 +02:00
thiswillbeyourgithub
e225c902ea style: reorder smart alarm and body tracking 2022-04-22 17:26:01 +02:00
thiswillbeyourgithub
e87464c28b fix: disabling tracking automatically disables smart tracking 2022-04-22 17:25:41 +02:00
thiswillbeyourgithub
4da2828d29 better way to save memory whan starting 2022-04-22 17:17:59 +02:00
thiswillbeyourgithub
02dafb63dd feat: ability to disable tracking 2022-04-22 17:17:41 +02:00
thiswillbeyourgithub
8b0be2eacc new: reset HR data in between run 2022-04-22 17:05:14 +02:00
thiswillbeyourgithub
664bf1902d minor: rename start tracking to start 2022-04-22 17:05:01 +02:00
thiswillbeyourgithub
d732a3135b minor: better position to print HR 2022-04-22 17:04:47 +02:00
thiswillbeyourgithub
98646be3eb track HR over 30s instead of 10 2022-04-22 17:01:10 +02:00
thiswillbeyourgithub
8f3e465cb5 fix: display HR 2022-04-22 16:19:55 +02:00
thiswillbeyourgithub
385d306441 new: wait less time before tracking HR 2022-04-22 16:17:13 +02:00
thiswillbeyourgithub
e9844e389b new: print last HR value when tracking 2022-04-22 16:17:00 +02:00
thiswillbeyourgithub
4041409862 fix: restart tracking heart rate if interupted 2022-04-22 16:16:40 +02:00
thiswillbeyourgithub
19f2fb4ce0 store data every 5 minutes by default 2022-04-22 15:50:16 +02:00
thiswillbeyourgithub
14b8cedd46 new: store data to file only if not currently tracking HR 2022-04-22 15:49:42 +02:00
thiswillbeyourgithub
87062e4243 better HR tracking code 2022-04-22 15:47:37 +02:00
thiswillbeyourgithub
059d198f7e new: in case of error during HR tracking, retry 2022-04-22 15:47:22 +02:00
thiswillbeyourgithub
47748c612b fix: wrong name for companion scripts 2022-04-22 13:54:30 +02:00
thiswillbeyourgithub
d723f08a61 new: add script to delete all sleep data 2022-04-22 13:53:00 +02:00
thiswillbeyourgithub
b95f0285e9 new: auto restart watch when downloading all sleep data 2022-04-22 13:52:48 +02:00
thiswillbeyourgithub
5cf1558dc9 new: don't track HR right away, wait for 60s 2022-04-22 13:30:53 +02:00
thiswillbeyourgithub
0d27e8e2d8 new: remove useless warning when alarm not set 2022-04-22 13:03:53 +02:00
thiswillbeyourgithub
2e2840a651 track heart rate every 10 minutes 2022-04-22 13:01:54 +02:00
thiswillbeyourgithub
bd88b78115 todo 2022-04-22 13:01:14 +02:00
thiswillbeyourgithub
d263124446 new: delete spinners to save memory 2022-04-22 13:00:51 +02:00
thiswillbeyourgithub
07dd718b73 new: display sleep duration while sleeping 2022-04-22 12:59:49 +02:00
thiswillbeyourgithub
1b891927b6 new: add loading screen 2022-04-22 12:44:27 +02:00
thiswillbeyourgithub
d4047ab34e new: don't exit app when sleeping 2022-04-22 12:43:35 +02:00
thiswillbeyourgithub
9e4756fda8 new: tell user when it's tracking HR 2022-04-22 12:43:21 +02:00
thiswillbeyourgithub
c63f5ebee6 fix: switch to SleepTk to receive ticks when tracking heart rate 2022-04-22 12:35:40 +02:00
thiswillbeyourgithub
2192397a3c new: keep awake during heart tracking 2022-04-22 12:22:27 +02:00
thiswillbeyourgithub
7504800bd8 fix: missing umlaut in credits 2022-04-22 12:12:28 +02:00
thiswillbeyourgithub
d657776654 minor: consider more variable to be of interest to the user 2022-04-22 12:01:16 +02:00
thiswillbeyourgithub
1527adaea9 new: delete button during tracking to save memory 2022-04-22 12:00:31 +02:00
thiswillbeyourgithub
942be77775 new: added icon and credits to plan5 2022-04-22 11:15:20 +02:00
thiswillbeyourgithub
553d1addfa fix: string warning that no alarm was set was not offset 2022-04-21 12:33:45 +02:00
thiswillbeyourgithub
3d3f82f3a8 new: removed start page that was useless 2022-04-21 12:33:25 +02:00
thiswillbeyourgithub
7e53413280 todo 2022-04-21 12:32:21 +02:00
thiswillbeyourgithub
c991af0b45 mention alpha stage of heart tracking 2022-04-19 14:45:29 +02:00
thiswillbeyourgithub
f8c0fc94cb minor: style 2022-04-19 14:44:17 +02:00
thiswillbeyourgithub
baaf78f30e minor: style 2022-04-19 14:41:37 +02:00
thiswillbeyourgithub
ab88679386 minor: draw blank scren when starting tracking 2022-04-16 10:57:59 +02:00
thiswillbeyourgithub
b66e5c3093 removed micropython decorators because it was taking too much space 2022-04-15 17:09:57 +02:00
thiswillbeyourgithub
11ab117e95 major: move smart alarm to separate class + use micropython decorators 2022-04-15 13:08:05 +02:00
thiswillbeyourgithub
6b860e6e56 fix: better way to reset spinval values between runs 2022-04-14 11:52:23 +02:00
thiswillbeyourgithub
30f2ff42a1 new: suggest wake up time at each run instead of first startup 2022-04-13 16:34:41 +02:00
thiswillbeyourgithub
ad79dc7ab0 new: auto suggest best wake up time 2022-04-13 16:34:41 +02:00
thiswillbeyourgithub
f61e5b123c todo 2022-04-13 16:34:41 +02:00
thiswillbeyourgithub
c54499f89f minor: fix losing accuracy when printing sleep duration 2022-04-13 13:49:49 +02:00
thiswillbeyourgithub
8241080c9b minor: more elegant def._read_time() 2022-04-13 13:49:25 +02:00
thiswillbeyourgithub
6bfc0e2126 new: print duration string in a separate function 2022-04-13 13:17:58 +02:00
thiswillbeyourgithub
6fc6f01c2e new: reset frequently font and color 2022-04-09 15:49:30 +02:00
thiswillbeyourgithub
a9da525e07 new: reset acclerometer at startup 2022-04-09 15:48:58 +02:00
thiswillbeyourgithub
575d161caa new: dont turn hr tracking on by default 2022-04-06 23:42:00 +02:00
thiswillbeyourgithub
514b52298f docs 2022-04-06 19:59:59 +02:00
thiswillbeyourgithub
e4cc325dfc todo 2022-04-06 18:48:52 +02:00
thiswillbeyourgithub
c385c7b4d6 feat: tracking heart rate data 2022-04-06 17:27:20 +02:00
thiswillbeyourgithub
b7492f3ee6 reactivate battery threshold 2022-03-29 15:05:51 +02:00
thiswillbeyourgithub
6f7f10fe8d add explanation on how to disable battery threshold 2022-03-29 15:05:29 +02:00
thiswillbeyourgithub
c7b542f629 more frequent data logging 2022-03-29 15:05:09 +02:00
thiswillbeyourgithub
a81b310374 minor: style 2022-03-29 15:03:33 +02:00
thiswillbeyourgithub
f3bb674de6 change default cycle length to 90 minutes 2022-03-29 15:03:24 +02:00
thiswillbeyourgithub
bc63cda21f fix: time to fall asleep was counted in seconds instead of minutes 2022-03-29 15:03:08 +02:00
thiswillbeyourgithub
6438853ef3 todo 2022-03-27 13:13:30 +02:00
thiswillbeyourgithub
c8bb5ccf6c testing: disable battery threshold 2022-03-25 11:57:40 +01:00
thiswillbeyourgithub
1ca76cbfa6 minor 2022-03-25 11:56:52 +01:00
thiswillbeyourgithub
a32875e40d change defaults gradual wake intervals and cycle length 2022-03-23 09:41:50 +01:00
thiswillbeyourgithub
753034493f added more bibliography 2022-03-22 18:53:17 +01:00
thiswillbeyourgithub
fd313b906c refactored bibliogrpahy 2022-03-22 18:33:24 +01:00
thiswillbeyourgithub
407258087d remove link to algorithm from the bibliography 2022-03-22 18:33:16 +01:00
thiswillbeyourgithub
fac9ce242e todo 2022-03-22 18:32:29 +01:00
thiswillbeyourgithub
b32040cdd8 store arm angle instead of raw atan value 2022-03-22 11:49:12 +01:00
thiswillbeyourgithub
715856618f fix: cancel tiny vibration alarm when disabling tracking 2022-03-22 11:39:13 +01:00
thiswillbeyourgithub
bd5803985c fix: reset accelerometer if invalid value + no need to check for 0 division anymore 2022-03-21 15:26:21 +01:00
thiswillbeyourgithub
5a43017bdd remove exception catcher in trackOnce 2022-03-21 15:03:28 +01:00
thiswillbeyourgithub
c2e3ebeb01 fix: avoid division by 0 2022-03-21 14:59:11 +01:00
thiswillbeyourgithub
566705f471 fix: minor 2022-03-21 13:30:39 +01:00
thiswillbeyourgithub
b5b70829b0 better exception code 2022-03-21 13:03:17 +01:00
thiswillbeyourgithub
302be10fe6 fix: error when catching exception 2022-03-21 12:50:36 +01:00
thiswillbeyourgithub
239fcf3b3e stop storing x/y/z values 2022-03-20 16:07:34 +01:00
thiswillbeyourgithub
68cb0188f6 fix: minor 2022-03-18 10:23:46 +01:00
thiswillbeyourgithub
5bdb4c5ac5 less frequent data loggin 2022-03-18 10:16:54 +01:00
thiswillbeyourgithub
b85f16ea75 todo 2022-03-18 10:16:47 +01:00
thiswillbeyourgithub
22ce8f28bd store average arm angle instead of max value etc 2022-03-18 10:16:41 +01:00
thiswillbeyourgithub
72d63cd03f new battery threshold : 25% 2022-03-18 09:44:48 +01:00
thiswillbeyourgithub
730fcf47e7 todo 2022-03-17 07:34:33 +01:00
thiswillbeyourgithub
c58199fbd2 store average instead of maxpooling 2022-03-16 16:55:33 +01:00
thiswillbeyourgithub
cf5a42589d no need to store the battery now 2022-03-16 16:55:15 +01:00
thiswillbeyourgithub
e641995d7b handle exception while pulling sleep data 2022-03-16 16:34:13 +01:00
thiswillbeyourgithub
e95b99d89d fix: initialize accel buff to minimum value 2022-03-15 20:30:03 +01:00
thiswillbeyourgithub
1547a053ba more frequent data storing 2022-03-15 20:20:07 +01:00
thiswillbeyourgithub
da47d58cfe fix: forgot to reset buff to -16000 2022-03-15 20:19:24 +01:00
thiswillbeyourgithub
383c410804 store battery level once more 2022-03-15 13:30:09 +01:00
thiswillbeyourgithub
447f7e49ae remove useless keep_awake 2022-03-15 13:25:57 +01:00
thiswillbeyourgithub
565150aedc new: catch exception and issue notification in trackOnce 2022-03-15 13:25:31 +01:00
thiswillbeyourgithub
b15fe4e6eb remove vibration when touching spinner because too slow 2022-03-15 13:16:01 +01:00
thiswillbeyourgithub
684ddf574b minor: up to date top docstring 2022-03-15 13:15:16 +01:00
thiswillbeyourgithub
43204857d1 new: notification if smart_alarm_compute is launched by mistake 2022-03-15 13:15:08 +01:00
thiswillbeyourgithub
0fe8ce9ae1 minor: style 2022-03-15 13:14:16 +01:00
thiswillbeyourgithub
41b219b4f6 warn user that cycle length currently only used for printing 2022-03-15 13:14:05 +01:00
thiswillbeyourgithub
706144b30c vibrate a tiny bit when using the spinner 2022-03-15 13:01:10 +01:00
thiswillbeyourgithub
3d19ca1153 major: refactored UI + major changes 2022-03-15 12:45:26 +01:00
thiswillbeyourgithub
ac0013b965 preliminary work to refactor UI 2022-03-15 10:21:54 +01:00
thiswillbeyourgithub
6a32d3f477 less frequent data logging 2022-03-15 10:04:35 +01:00
thiswillbeyourgithub
61a7d0aa1a minor 2022-03-15 10:04:24 +01:00
thiswillbeyourgithub
55574efd65 fix: buff has to be initialized at -16000 instead of 0 because you only keep the max 2022-03-15 10:04:02 +01:00
thiswillbeyourgithub
be7f4d72be gradual wake starts 15 minutes before alarm 2022-03-14 20:20:01 +01:00
thiswillbeyourgithub
0b16a34a90 better code to turn screen off when waking up 2022-03-14 20:19:45 +01:00
thiswillbeyourgithub
ce635863c6 set battery threshold to 10% 2022-03-14 20:17:08 +01:00
thiswillbeyourgithub
e0c024a229 auto init file by writing nothing to it 2022-03-14 17:52:07 +01:00
thiswillbeyourgithub
212b5bd2b8 reduce _FREQ to 5 seconds 2022-03-09 19:21:51 +01:00
thiswillbeyourgithub
253b33d470 replace function _add_accel_alar by two direct calls 2022-03-09 19:21:21 +01:00
thiswillbeyourgithub
314b2bef60 todo 2022-03-09 19:20:50 +01:00
thiswillbeyourgithub
92668fca48 take derivative of value + less strong outlier limitation + more smoothing 2022-03-08 15:14:05 +01:00
thiswillbeyourgithub
3581a3fee1 fix: catch error when pulling files 2022-03-08 13:27:16 +01:00
thiswillbeyourgithub
d79640707e todo 2022-03-08 13:26:19 +01:00
thiswillbeyourgithub
325d1d08a6 link to another study 2022-03-08 13:26:12 +01:00
thiswillbeyourgithub
541af81849 take more measurements 2022-03-08 13:21:10 +01:00
thiswillbeyourgithub
66d662e602 new: dont average x/y/z, instead keep only the max value 2022-03-08 13:19:08 +01:00
thiswillbeyourgithub
db4a723d8f mention other related project for the banglejs 2022-03-08 12:56:10 +01:00
thiswillbeyourgithub
0d7fd8994b no need to import time 2022-03-07 11:06:47 +01:00
thiswillbeyourgithub
39033fffe0 only import array from array 2022-03-07 11:02:36 +01:00
thiswillbeyourgithub
b036712818 set 0 and 1 to _OFF and _ON + import only const from micropython 2022-03-07 11:01:59 +01:00
thiswillbeyourgithub
2048d84849 header warns that product is not finished 2022-03-07 11:01:24 +01:00
thiswillbeyourgithub
95eae6d6ab todo 2022-03-07 10:01:10 +01:00
thiswillbeyourgithub
85cec0e696 todo 2022-03-04 13:01:34 +01:00
thiswillbeyourgithub
50751bf53c fix: was not reading last value from file when computing smart alarm 2022-03-04 12:59:41 +01:00
thiswillbeyourgithub
77b9a6006e new: stop storing absolute value of arm angle + way better way to store data 2022-03-04 12:59:25 +01:00
thiswillbeyourgithub
0ece1faa17 new: stop storing battery data 2022-03-04 12:28:36 +01:00
thiswillbeyourgithub
ab478441d9 increase data logging frequency 2022-03-04 12:10:00 +01:00
thiswillbeyourgithub
c5edca9901 todo 2022-03-04 12:09:52 +01:00
thiswillbeyourgithub
24d4a04cfa style: changed default values order 2022-03-04 12:04:23 +01:00
thiswillbeyourgithub
c1ff8bc0c3 new: don't delete buff array but just empty it 2022-03-04 12:04:11 +01:00
thiswillbeyourgithub
a79033e6d0 feat: remove partially downloaded sleep data if exception is caught 2022-03-04 09:46:24 +01:00
thiswillbeyourgithub
668c94856f new: smoothen the data only once 2022-03-04 09:45:57 +01:00
thiswillbeyourgithub
66d91a9f55 new: when using smart alarm, remove previous gentle alarm and add new one 2022-03-02 21:28:34 +01:00
thiswillbeyourgithub
81352baf20 remove gentle vibration a T-20 minutes 2022-03-02 15:47:11 +01:00
thiswillbeyourgithub
53dcb60c68 docs: mention gentle alarm clock 2022-03-02 15:46:30 +01:00
thiswillbeyourgithub
bfe38680d8 todo 2022-03-02 15:45:32 +01:00
thiswillbeyourgithub
9e8b7a23b8 todo 2022-03-02 15:20:58 +01:00
thiswillbeyourgithub
52d903d5f4 fix wrong link to screenshot 2022-03-02 15:20:07 +01:00
thiswillbeyourgithub
4279213500 style 2022-03-02 15:19:21 +01:00
thiswillbeyourgithub
58a3c4e79b update example night screenshot 2022-03-02 15:19:13 +01:00
thiswillbeyourgithub
8516651687 update screenshot 2022-03-02 15:12:05 +01:00
thiswillbeyourgithub
89b34397e8 testing, don't stop tracking when computing best wake up time 2022-03-02 15:09:28 +01:00
thiswillbeyourgithub
fe1b7bb55d fix: calling wasp instead of watch.wasp 2022-03-02 15:09:13 +01:00
thiswillbeyourgithub
254ccc24db remove useless _TRACKING2 page 2022-03-02 15:07:28 +01:00
thiswillbeyourgithub
d04b3d36f0 misc 2022-03-02 15:03:33 +01:00
thiswillbeyourgithub
2d22548e26 feat: new way better algo to find local maximas 2022-03-02 15:03:17 +01:00
thiswillbeyourgithub
9b390f9638 fix: forgot parenthesis 2022-03-02 15:02:32 +01:00
thiswillbeyourgithub
2ee7baca2f smooth 3 times only 2022-03-02 15:02:22 +01:00
thiswillbeyourgithub
7f3e6ef2f6 better docs with workflow 2 2022-03-02 15:02:01 +01:00
thiswillbeyourgithub
878de55355 center data but DONT scale it 2022-03-02 14:26:14 +01:00
thiswillbeyourgithub
b513ef5b86 remove second smoothing as it's useless 2022-03-02 13:34:18 +01:00
thiswillbeyourgithub
87beaf3c8c it's bas to clip data 2022-03-02 13:34:04 +01:00
thiswillbeyourgithub
2dc73e609a todo 2022-03-02 13:32:28 +01:00
thiswillbeyourgithub
e00551a054 better docs with workflow 2022-03-02 13:32:19 +01:00
thiswillbeyourgithub
e418f8304d better smoother function 2022-03-02 13:31:25 +01:00
thiswillbeyourgithub
3675e49a31 better outlier removal 2022-03-02 13:30:22 +01:00
thiswillbeyourgithub
f4baf4f34b docs + minor style 2022-03-01 20:01:29 +01:00
thiswillbeyourgithub
50805b3d97 docs: mention that notifications are cut at night 2022-02-28 22:06:01 +01:00
thiswillbeyourgithub
3af2bd3c0d feat: make notifications silent dring the night 2022-02-28 22:05:09 +01:00
thiswillbeyourgithub
12c95cb7d4 add gradual wake timestep 2022-02-28 21:57:24 +01:00
thiswillbeyourgithub
10b51739c1 fix: wrong import statement for time 2022-02-28 21:56:51 +01:00
thiswillbeyourgithub
0a4ca3be7c useless to use cd to use mkdir 2022-02-28 19:11:56 +01:00
thiswillbeyourgithub
469ce6181f new: import package without creating variables 2022-02-28 19:11:43 +01:00
thiswillbeyourgithub
cfed213aa1 remove import of sin 2022-02-28 18:57:03 +01:00
thiswillbeyourgithub
d6dc8d0bab avoid calling mute(True) too many times and call keep_awake once more 2022-02-28 18:54:51 +01:00
thiswillbeyourgithub
729a68de92 feat: implement gradual wakeup 2022-02-28 18:53:44 +01:00
thiswillbeyourgithub
2bd77dd5df fix: called time.time instead of rtc.time 2022-02-28 18:35:15 +01:00
thiswillbeyourgithub
53d5ce3128 todo 2022-02-28 17:48:33 +01:00
thiswillbeyourgithub
5d6e614887 fix: wrong notification text 2022-02-28 17:09:33 +01:00
thiswillbeyourgithub
6baba87b50 new: sends a bunch of keep_awake commands to keep computing the smart alarm 2022-02-28 17:09:17 +01:00
thiswillbeyourgithub
90dfcd773f minor 2022-02-28 15:45:59 +01:00
thiswillbeyourgithub
9911ba5eb0 new: wake screen but turn it off when computing best wake up time 2022-02-28 15:45:42 +01:00
thiswillbeyourgithub
b2d9899f24 new: after chatting with danielt, I should not implement sleep 2022-02-28 15:44:55 +01:00
thiswillbeyourgithub
a5282cb19a new: pressing the button goes back to home menu except if in ringing mode 2022-02-28 14:17:31 +01:00
thiswillbeyourgithub
7e66399545 minor 2022-02-28 12:52:21 +01:00
thiswillbeyourgithub
a326527691 fix: forgot parenthesis 2022-02-28 12:28:51 +01:00
thiswillbeyourgithub
b6d7983577 testing: remove code related to sinus fitting 2022-02-28 12:26:43 +01:00
thiswillbeyourgithub
735791904f untested: findind local maximas instead of using sinus fitting and least regression 2022-02-28 12:23:23 +01:00
thiswillbeyourgithub
10444e7580 default increment value for spinner 2022-02-28 11:16:21 +01:00
thiswillbeyourgithub
21bc2bc232 fix: don't allow checking hidden boxes in the settings 2022-02-27 20:27:52 +01:00
thiswillbeyourgithub
f56dd97742 write when no alarm set 2022-02-27 20:00:52 +01:00
thiswillbeyourgithub
b96032aaf9 todo 2022-02-27 19:43:06 +01:00
thiswillbeyourgithub
6ff41a143f better signal processing 2022-02-27 19:41:57 +01:00
thiswillbeyourgithub
6769f97cff fix: don't delete timer just after initiating it 2022-02-27 18:20:54 +01:00
thiswillbeyourgithub
9edb46a50c new: avoid setting first value of data to high value 2022-02-27 18:20:33 +01:00
thiswillbeyourgithub
1f49e6ccde new: move processing signal to a new function 2022-02-27 18:20:11 +01:00
thiswillbeyourgithub
c2e509435e better workflow suggestion 2022-02-27 18:19:27 +01:00
thiswillbeyourgithub
22726ae3b5 fix: store battery voltage as int 2022-02-27 15:44:31 +01:00
thiswillbeyourgithub
90f4b08f26 remove useless import atan 2022-02-27 15:33:11 +01:00
thiswillbeyourgithub
a54bdb5994 run gc.collect first 2022-02-27 15:33:02 +01:00
thiswillbeyourgithub
31ce2ddc24 new: ability to download all files + skip already present 2022-02-27 15:26:48 +01:00
thiswillbeyourgithub
0c427aedbf feat: addd script to pull automatically last night's data 2022-02-26 17:52:28 +01:00
thiswillbeyourgithub
959b879a80 todo 2022-02-26 15:20:03 +01:00
thiswillbeyourgithub
cdf3a42d9c new: set maximum digits written to file to 7 2022-02-26 15:19:01 +01:00
thiswillbeyourgithub
5e9dad82c5 changed my mind: arm angle is more accurate than summing the difference of axis 2022-02-26 15:18:36 +01:00
thiswillbeyourgithub
2132a5eb6d style: prettier hour printing 2022-02-26 15:12:45 +01:00
thiswillbeyourgithub
9d9cc462e0 todo 2022-02-26 15:06:57 +01:00
thiswillbeyourgithub
e63a8d2fd3 docs: mention flexibility as a feature 2022-02-26 15:06:48 +01:00
thiswillbeyourgithub
c6b08100f2 todo 2022-02-26 14:50:10 +01:00
thiswillbeyourgithub
6b9e37bd60 reduce accel freq to once every 30 seconds 2022-02-25 23:03:12 +01:00
thiswillbeyourgithub
d0a65e72b0 minor 2022-02-25 23:02:53 +01:00
thiswillbeyourgithub
94a2390a2a todo 2022-02-25 23:02:29 +01:00
thiswillbeyourgithub
ef2b777ee6 fusion value is now sum of diffs of each accel axis 2022-02-25 22:59:20 +01:00
thiswillbeyourgithub
cb7655bf0e notify when starting computation 2022-02-25 22:57:05 +01:00
thiswillbeyourgithub
92741ee6a8 skip useless atan import 2022-02-25 22:54:05 +01:00
thiswillbeyourgithub
1f6c8d30b3 mention features 2022-02-25 22:34:06 +01:00
thiswillbeyourgithub
aef3b04836 refactored readme 2022-02-25 22:27:28 +01:00
thiswillbeyourgithub
03a1466f0f todo 2022-02-25 20:42:46 +01:00
thiswillbeyourgithub
f00357a5d7 todo 2022-02-25 20:39:43 +01:00
thiswillbeyourgithub
0997c808f8 print best sleep cycle length in notification 2022-02-25 20:37:20 +01:00
thiswillbeyourgithub
0ee2059951 new: store diff value of x/y/z instead of raw values. Then called the result fusion instead of angl_avg 2022-02-25 20:22:50 +01:00
thiswillbeyourgithub
9dfb6fdd7b feat: add timer when computing smart alarm 2022-02-25 20:15:10 +01:00
thiswillbeyourgithub
bddd551f21 style 2022-02-25 20:13:29 +01:00
thiswillbeyourgithub
0918fa1b82 smoothen twice 5 times with averaging in between 2022-02-25 19:48:56 +01:00
thiswillbeyourgithub
55bae16aa9 add screenshot of example night data 2022-02-25 19:48:08 +01:00
thiswillbeyourgithub
c23673193a remove pandas code to test fusion def 2022-02-25 19:39:17 +01:00
thiswillbeyourgithub
c36c164442 docs: add instruction to use pandas 2022-02-25 19:38:38 +01:00
thiswillbeyourgithub
10d7099bee set first data to something high because you were awake 2022-02-25 19:37:28 +01:00
thiswillbeyourgithub
53574a30e1 comments 2022-02-25 19:37:13 +01:00
thiswillbeyourgithub
77359dd0c9 store angle average as the first column, to make it faster to read 2022-02-25 19:31:55 +01:00
thiswillbeyourgithub
9c41de6bd3 major refactor: smart alarm might just work! 2022-02-25 19:23:35 +01:00
thiswillbeyourgithub
973db51ae5 up to 40 minutes before actually 2022-02-25 19:22:32 +01:00
thiswillbeyourgithub
41f2b51a31 smart alarm: smoother and center + scale with clipping between -1 ans 1 2022-02-25 17:29:01 +01:00
thiswillbeyourgithub
0a6806d8b1 fix: read data character by character 2022-02-25 17:28:20 +01:00
thiswillbeyourgithub
86e4735788 don't waste space by writing 0 to the file 2022-02-25 17:27:48 +01:00
thiswillbeyourgithub
b3b41c0cdb minor: renamed _tracking to _is_tracking 2022-02-25 15:49:41 +01:00
thiswillbeyourgithub
024d06f136 more efficient way to write to file 2022-02-25 14:51:05 +01:00
thiswillbeyourgithub
c90ba5ff7e fix: _TIMESTAMP was added at the wrong var 2022-02-25 14:34:52 +01:00
thiswillbeyourgithub
88f63329b0 comment warning that atan is actually faster than taylor series 2022-02-25 14:30:24 +01:00
thiswillbeyourgithub
f2d3c1a5e7 don't need _DEGREE actually 2022-02-25 14:29:58 +01:00
thiswillbeyourgithub
8544d6fcee allow waking up up to 45m + comments 2022-02-25 14:29:46 +01:00
thiswillbeyourgithub
e162c49fcc allow waking up up to 45m + comments 2022-02-25 14:29:19 +01:00
thiswillbeyourgithub
7d74435c98 sqrt, pow, and degrees were awfully slow 2022-02-25 14:08:14 +01:00
thiswillbeyourgithub
3f27722814 fix: timestamp format was wrong 2022-02-25 13:20:29 +01:00
thiswillbeyourgithub
16546435f8 remove useless scrolling indicator 2022-02-25 12:17:22 +01:00
thiswillbeyourgithub
9816e111aa testing: don't enter sleep while calculating best wake up time 2022-02-25 12:13:17 +01:00
thiswillbeyourgithub
06a59a98f1 feat: scrolling indicator to access settings via swipe + disabled smart alarm by default 2022-02-25 12:07:05 +01:00
thiswillbeyourgithub
b0a44fd56f style: draw buttons before strings 2022-02-25 11:52:19 +01:00
thiswillbeyourgithub
5f2d19716d new: can turn ringing off by pressing physical button 2022-02-25 11:41:27 +01:00
thiswillbeyourgithub
65d5e9eff5 fix: missing ) 2022-02-25 11:36:51 +01:00
thiswillbeyourgithub
67d145d7d0 PRE RELEASE instead of ALPHA software 2022-02-25 11:36:45 +01:00
thiswillbeyourgithub
86ea5d5b22 more efficient and easy to read start time printing 2022-02-25 11:36:29 +01:00
thiswillbeyourgithub
e423e8501f style: renamed button STOP to WAKE UP 2022-02-25 11:35:53 +01:00
thiswillbeyourgithub
72701221a8 renamed compute_best_WU to smart_alarm_compute 2022-02-25 11:30:07 +01:00
thiswillbeyourgithub
a2c1ec6b97 new: wrappeed smart alarm in try block, write to file if exception, does NOT cut original alarm clock 2022-02-25 11:29:18 +01:00
thiswillbeyourgithub
6117b10e5d misc: added comment 2022-02-25 11:28:43 +01:00
thiswillbeyourgithub
e8dc9c04ed todo 2022-02-25 11:28:31 +01:00
thiswillbeyourgithub
3808d55e1e fix: more efficient and good looking string writing 2022-02-25 11:02:56 +01:00
thiswillbeyourgithub
5ae59ec92f docs: mention alarm is working and stable 2022-02-25 09:36:32 +01:00
thiswillbeyourgithub
f16fdcb13c fix: type error 2022-02-24 21:05:31 +01:00
thiswillbeyourgithub
711d594d2d new: store _page value as byte instead of string 2022-02-24 17:49:53 +01:00
thiswillbeyourgithub
3335d8a371 fix: can refresh tracking screen by clicking outside of buttons 2022-02-24 17:21:44 +01:00
thiswillbeyourgithub
4b3767851c notification when battery low + fix setting value of smart alarm flag 2022-02-24 17:14:52 +01:00
thiswillbeyourgithub
fb6b9a46d1 minor: style 2022-02-24 17:14:25 +01:00
thiswillbeyourgithub
b2667c1343 fix: removed unused SL_L variable + fix wrong alarm time displayed 2022-02-24 17:00:20 +01:00
thiswillbeyourgithub
a7464ed69e fix: cannot stop tracking if pressed back button in confirmation view 2022-02-24 16:59:44 +01:00
thiswillbeyourgithub
f3785f7bc0 minor: styling 2022-02-24 16:46:38 +01:00
thiswillbeyourgithub
d805186108 new: added screenshots 2022-02-24 14:40:04 +01:00
thiswillbeyourgithub
9c859ce20c docs 2022-02-24 14:33:41 +01:00
thiswillbeyourgithub
9c6097d2db new: way better gui 2022-02-24 14:30:49 +01:00
thiswillbeyourgithub
96aa9a6fae put buttons a bit lower 2022-02-24 13:54:32 +01:00
thiswillbeyourgithub
7b8dcd94e7 renameed to SleepTk 2022-02-24 13:50:20 +01:00
thiswillbeyourgithub
656799882f new: cache objet reference for better performance 2022-02-24 13:01:23 +01:00
thiswillbeyourgithub
49d8805a89 new: store values as const instead of in the class 2022-02-24 12:57:12 +01:00
thiswillbeyourgithub
66bd04ece0 remove debug flag 2022-02-24 12:48:38 +01:00
thiswillbeyourgithub
40bf395c51 fix: wrong import of gc 2022-02-24 12:48:28 +01:00
thiswillbeyourgithub
e6745617df new: re adds gc.collect everywhere 2022-02-24 12:43:21 +01:00
thiswillbeyourgithub
0789be903d style 2022-02-24 12:40:24 +01:00
thiswillbeyourgithub
5d4a8552b9 minor 2022-02-24 12:34:53 +01:00
thiswillbeyourgithub
e00621fd23 new: use binary strings whenever possible 2022-02-24 12:32:46 +01:00
thiswillbeyourgithub
795853f097 new: store offsets and average cycle length outside of RAM 2022-02-24 12:31:38 +01:00
thiswillbeyourgithub
cbf3e58897 remove call to gc.collect 2022-02-24 12:19:56 +01:00
thiswillbeyourgithub
6e0c02e9df fix: remove useless test line 2022-02-24 12:13:03 +01:00
thiswillbeyourgithub
84a1d821e2 fix: no redraw when clicking outside of buttons in settings page 2022-02-24 12:12:52 +01:00
thiswillbeyourgithub
336d672f5a minor: styling 2022-02-24 12:12:33 +01:00
thiswillbeyourgithub
e1bcb4d0c2 use more efficient string concatenation 2022-02-24 12:12:26 +01:00
thiswillbeyourgithub
e8e155c4b5 minor: style 2022-02-24 12:00:12 +01:00
thiswillbeyourgithub
cd1e29c23e new: disable tracking if battery < 20% 2022-02-24 11:59:09 +01:00
thiswillbeyourgithub
fd400489c7 todo done: confirmation view when disabling tracking 2022-02-24 11:51:58 +01:00
thiswillbeyourgithub
3215fa638d new: confirmation view when disabling tracking 2022-02-24 11:48:35 +01:00
thiswillbeyourgithub
74cecc4492 smaller STOP button 2 2022-02-24 11:36:39 +01:00
thiswillbeyourgithub
374cc649a8 smaller STOP button 2022-02-24 11:34:38 +01:00
thiswillbeyourgithub
5bd095f8e9 better docstring at the top 2022-02-24 11:25:01 +01:00
thiswillbeyourgithub
856ccca2cd minor: styling 2022-02-24 11:24:51 +01:00
thiswillbeyourgithub
dcb14a6372 use statusbar instead of clock and battery 2022-02-24 11:21:10 +01:00
thiswillbeyourgithub
54b056dd2d comment 2 testing lines 2022-02-23 19:58:12 +01:00
thiswillbeyourgithub
669c45458b major version : untested algo, added settings panel 2022-02-23 18:25:34 +01:00
thiswillbeyourgithub
f1fea9ca2d new: use a more intuitive self._page variable to keep track of app state 2022-02-23 16:39:50 +01:00
thiswillbeyourgithub
76378ea0e7 new: removed indication of file size 2022-02-23 16:22:46 +01:00
thiswillbeyourgithub
2298b1823a progress on computing optimal wake up time 2 2022-02-23 12:14:00 +01:00
thiswillbeyourgithub
f52ba0d72a show user how early the wake up was when alarm is ringing 2022-02-23 11:44:56 +01:00
thiswillbeyourgithub
4d8caf085e progress on computing optimal wake up time 2022-02-23 11:44:41 +01:00
thiswillbeyourgithub
ecbc635ee0 change the way data is stored in file 2022-02-23 11:44:19 +01:00
thiswillbeyourgithub
30d29de710 change default values 2022-02-23 11:44:04 +01:00
thiswillbeyourgithub
5942d8cce9 docs: better pandas instruction 2022-02-23 11:43:51 +01:00
thiswillbeyourgithub
0fea39a9d1 docs: add timestamp to readme 2022-02-23 11:43:41 +01:00
thiswillbeyourgithub
dd0f4ae8d0 better default values 2022-02-23 09:59:55 +01:00
thiswillbeyourgithub
565cbc0891 remove _RATIO var 2022-02-23 09:56:23 +01:00
thiswillbeyourgithub
32a1b10a96 fix: was only vibrating once 2022-02-23 09:49:55 +01:00
thiswillbeyourgithub
a56eb3a91c docs: mention pandas command 2022-02-23 09:35:01 +01:00
thiswillbeyourgithub
c9da01896f fix: debug block at the top 2022-02-21 20:26:57 +01:00
thiswillbeyourgithub
ea4cee7ffd minor 2022-02-21 20:10:25 +01:00
thiswillbeyourgithub
2627073f25 minor :changed debug values 2022-02-21 20:10:15 +01:00
thiswillbeyourgithub
d4af813cbc new: added a debugging flag to quickly change values 2022-02-21 19:17:52 +01:00
thiswillbeyourgithub
0aa6c69fda minor : remove not needed import 2022-02-21 19:12:42 +01:00
thiswillbeyourgithub
5b67be4784 fix: was not using arrays method correctly 2022-02-21 19:12:21 +01:00
thiswillbeyourgithub
10416c9539 added link to forked repo 2022-01-31 19:08:58 +01:00
thiswillbeyourgithub
dcbada0ec8 fix: buff has to contain float 2022-01-31 19:02:02 +01:00
thiswillbeyourgithub
40fa059b2f style 2022-01-31 12:45:26 +01:00
thiswillbeyourgithub
5929648993 docs 2022-01-31 12:45:14 +01:00
thiswillbeyourgithub
00a3284cf5 minor 2022-01-31 12:43:27 +01:00
thiswillbeyourgithub
5e38f5eec3 style 2022-01-31 12:43:00 +01:00
thiswillbeyourgithub
23a9c9fd25 fix: race condition 2022-01-31 12:42:45 +01:00
thiswillbeyourgithub
66f52e96f9 turn on app when motor is activated 2022-01-31 12:13:56 +01:00
thiswillbeyourgithub
0524c0eac4 testing 2022-01-31 12:13:44 +01:00
thiswillbeyourgithub
a8c0c4fb63 fix: smaller font 2022-01-31 12:13:31 +01:00
thiswillbeyourgithub
6b8a296b6a fix: race condition 2022-01-31 12:13:12 +01:00
thiswillbeyourgithub
a0901c4c41 use arrays for buffer 2022-01-31 11:55:57 +01:00
thiswillbeyourgithub
4cc4aff636 slightly more efficient code 2022-01-31 11:53:40 +01:00
thiswillbeyourgithub
d81dd749d5 use a single buffer instead of one for each axis 2022-01-31 11:53:02 +01:00
thiswillbeyourgithub
29006d1e71 refactor: much improved, implement alarm but without optimization 2022-01-28 18:01:51 +01:00
thiswillbeyourgithub
7de3b22d2b change import statements 2022-01-28 15:55:26 +01:00
thiswillbeyourgithub
a4d15f3da5 fix: _RATIO has to be an integer 2022-01-28 15:39:01 +01:00
thiswillbeyourgithub
614abf3d43 refactor: much improved, now stores the averaged value of some time 2022-01-28 15:33:52 +01:00
thiswillbeyourgithub
0ce0a79149 new: store file with timestamp as name, to make the output more compact 2022-01-28 14:19:43 +01:00
thiswillbeyourgithub
cc7c6d712d log less data 2022-01-27 18:15:51 +01:00
thiswillbeyourgithub
950187ab9f write file size 2022-01-27 18:11:51 +01:00
thiswillbeyourgithub
f828c365a6 minor 2022-01-27 15:49:56 +01:00
thiswillbeyourgithub
adc813825c better buff addition + compute angle 2022-01-27 15:31:46 +01:00
thiswillbeyourgithub
5e18e11c71 more robust mkdir 2022-01-27 15:31:31 +01:00
thiswillbeyourgithub
293eb9dba7 implement self.sleep() 2022-01-27 13:36:42 +01:00
thiswillbeyourgithub
80a0cd42a4 minor: move function down 2022-01-27 13:36:34 +01:00
thiswillbeyourgithub
ae65171c71 safer folder creation 2022-01-27 13:36:15 +01:00
thiswillbeyourgithub
7df8f2687a new: store data in logs/sleep/ 2022-01-27 13:07:28 +01:00
thiswillbeyourgithub
7fe90cd7d7 fix: minor 2022-01-27 13:07:17 +01:00
thiswillbeyourgithub
f218dfc860 changed name to ZzzTracker 2022-01-27 12:58:27 +01:00
thiswillbeyourgithub
2e36915a40 change name to smalle and understandable 2022-01-27 12:57:11 +01:00
thiswillbeyourgithub
c59fcb1dd2 UI: better, smaller, with battery and clock 2022-01-27 12:57:00 +01:00
thiswillbeyourgithub
3caa7e4552 new: store battery percent in data 2022-01-27 12:56:28 +01:00
thiswillbeyourgithub
3d98010c0c dont implement background because it's useless 2022-01-27 12:27:09 +01:00
thiswillbeyourgithub
ade3c7498b redraw the screen every press to make sure to display data 2022-01-27 12:26:39 +01:00
thiswillbeyourgithub
a77481641c style: better code to create a file 2022-01-27 12:26:17 +01:00
thiswillbeyourgithub
b094cf5666 new: _tracking is boolean, store start time elsewhere and print battery and number of datapoints 2022-01-27 12:25:53 +01:00
thiswillbeyourgithub
6aceca3726 minor: change default freq to 5 minutes 2022-01-27 12:03:17 +01:00
thiswillbeyourgithub
862b181e55 fix: proper creation of directory 2022-01-27 01:36:35 +01:00
thiswillbeyourgithub
0e32eabb83 docs: better 2022-01-27 01:36:22 +01:00
thiswillbeyourgithub
f5cd59defa todo 2022-01-27 01:14:46 +01:00
thiswillbeyourgithub
29536a0ac0 docs: added instructions 2022-01-27 01:14:37 +01:00
thiswillbeyourgithub
e2fbb70d49 docs 2022-01-27 01:14:24 +01:00
thiswillbeyourgithub
349cfebc8f minor: docstrings 2022-01-27 01:06:00 +01:00
thiswillbeyourgithub
a428f38c30 fix: mkdir crash if folder already exists 2022-01-27 00:29:00 +01:00
thiswillbeyourgithub
33815d6829 fix: using mkdir instead of os.makedirs 2022-01-27 00:06:56 +01:00
thiswillbeyourgithub
8ad3428307 docs: mention current state 2022-01-26 20:18:56 +01:00
thiswillbeyourgithub
f2b8131d51 feat: store sleep data in a directory 2022-01-26 20:14:09 +01:00
thiswillbeyourgithub
ba71456336 todo 2022-01-26 20:01:27 +01:00
thiswillbeyourgithub
5e005af4e4 minor: don't redraw UI if clicking outside buttons 2022-01-26 19:47:51 +01:00
thiswillbeyourgithub
ddc7e60f74 fix: buff not initialized at the right place 2022-01-26 19:27:50 +01:00
thiswillbeyourgithub
d52a1d62c7 force saving to file when clicking stop 2022-01-26 19:20:23 +01:00
thiswillbeyourgithub
de58a40825 added docstrings 2022-01-26 19:20:06 +01:00
thiswillbeyourgithub
67764fe8c6 minor: renamed function 2022-01-26 19:19:43 +01:00
thiswillbeyourgithub
356e468e2d new: log data on background only if running 2022-01-26 19:19:04 +01:00
thiswillbeyourgithub
7e30f5fe67 new: create one logging file per run 2022-01-26 19:18:34 +01:00
thiswillbeyourgithub
80a060133a minor: add newline after each line instead of before 2022-01-26 19:08:59 +01:00
thiswillbeyourgithub
f7146fe05e fix: remove wrong assert 2022-01-26 19:08:39 +01:00
thiswillbeyourgithub
0e4942250d minor 2022-01-26 18:59:56 +01:00
thiswillbeyourgithub
5359d439cc todo 2022-01-25 22:54:51 +01:00
thiswillbeyourgithub
38c699c6b0 better code + poll every X seconds is possible 2022-01-25 22:54:38 +01:00
thiswillbeyourgithub
cd29be0f50 minor: cleaner UI 2022-01-25 22:43:01 +01:00
thiswillbeyourgithub
2fdb751b8f fix: minor string handling 2022-01-25 22:42:48 +01:00
thiswillbeyourgithub
1ce00db2df fix: time.mktime() does the job 2022-01-25 22:42:35 +01:00
thiswillbeyourgithub
1dc5c78daf added TODO list to the to of the file 2022-01-25 18:36:52 +01:00
thiswillbeyourgithub
57b7b90dd5 shortenned SleepTracker to SleepT 2022-01-25 18:36:39 +01:00
thiswillbeyourgithub
6709be7327 fix: forgot to use time.mktime 2022-01-25 18:36:28 +01:00
thiswillbeyourgithub
6a44c80602 modified: SleepTracker.py
using set_alarm instead of ticks
still untested
2022-01-25 18:26:20 +01:00
thiswillbeyourgithub
6d567589ef added first draft of SleepTracker (only logger for now) 2022-01-25 15:59:28 +01:00
thiswillbeyourgithub
590ec28fd2 docs: added Status section 2022-01-25 15:59:00 +01:00
thiswillbeyourgithub
9fcdf60183 docs: added link to detaileed implementation 2022-01-17 23:00:14 +01:00
thiswillbeyourgithub
de4bb830cf docs: idea of OLS regression of known sinusoidal function 2022-01-16 16:59:27 +01:00
thiswillbeyourgithub
b87b8e1bcc docs: wake up after duration or at specific time 2022-01-16 16:59:08 +01:00
thiswillbeyourgithub
46071c9efe added section: related links 2022-01-09 09:22:50 +01:00
thiswillbeyourgithub
42a51a7c2c added features I'm not sure yet 2021-12-27 13:37:17 +01:00
thiswillbeyourgithub
f1f99b1b6d first step: log sleep data to calibrate algo 2021-12-27 13:37:07 +01:00
thiswillbeyourgithub
43745886cd typo 2021-12-27 13:36:44 +01:00
thiswillbeyourgithub
ebc07f1566 minor 2021-12-20 16:16:51 +01:00
thiswillbeyourgithub
90bb4af5e6 hardcode limits if heart rate is unreliable 2021-12-20 16:16:20 +01:00
thiswillbeyourgithub
6792f34343 typo 2021-12-20 16:15:44 +01:00
thiswillbeyourgithub
078028de66 targeted memory reactivation fantasy 2021-12-19 18:56:31 +01:00
thiswillbeyourgithub
e9e9e2e6ee minor 2021-12-18 15:22:24 +01:00
thiswillbeyourgithub
000a5a63b4 initial readme 2021-12-18 14:35:23 +01:00
thiswillbeyourgithub
2004f0a884 initial readme 2021-12-18 14:34:27 +01:00
thiswillbeyourgithub
e228457cf1
Initial commit 2021-12-18 13:15:38 +00:00
15 changed files with 1890 additions and 19 deletions

129
external/SleepTk/.gitignore vendored Normal file
View file

@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/

674
external/SleepTk/LICENSE vendored Normal file
View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

144
external/SleepTk/README.md vendored Normal file
View file

@ -0,0 +1,144 @@
# SleepTk : a sleep tracker and smart alarm for wasp-os
**Goal:** privacy friendly sleep tracker with smart alarm for the [pinetime smartwatch](https://pine64.com/product/pinetime-smartwatch-sealed/) by Pine64, on python, to run on [wasp-os](https://github.com/daniel-thompson/wasp-os).
## Features:
* **Sleep tracking**: logs your body movement during the night, infers your sleep cycle and write it all down in a `.csv` file.
* **Heart tracking**: tracks your heart rate throughout the night.
* **Flexible**: does not make too many assumption regarding time to fall asleep, sleep cycle duration etc. SleepTk tries various data to see what fits best for your profile. If you still want to customize things, all the hardcoded and commented settings are easily accessible at the top of the file.
* **Privacy friendly**: your data is not sent to anyone, it is stored and analyzed directly on the watch (but you can still download it if needed).
* **Completely open source**
* **Best alarm time suggestion**: suggests wake up time according to average sleep cycles length.
* **Gradual wake**: vibrates the watch a tiny bit a few times before the alarm to lift you gently back to consciousness.
* **Easy to snooze but hard to stop** You have to swipe several times to make it stop, but can snooze easily.
* **Smart alarm clock (alpha)**: adaptative alarm that wakes you at the best time of your sleep cycle (up to 40 minutes before the set time) to make sure you wake up feeling refreshed.
* **Insomnia insights**: if you turn on the screen during the night, SleepTk will tell you how long you slept and in what part of the sleep cycle you are supposed to be.
## Credits:
* Many thanks to Emanuel Löffler (https://github.com/plan5) who kindly created the logo.
## **How to install**:
*(for now you need my slightly forked wasp-os that allows to use accelerometer data)*
* download the latest [forked wasp-os](https://github.com/thiswillbeyourgithub/wasp-os), or at least implement the relevant commits (624d1c675343cd4d95caea5ac4cec32766b3119b).
* download the latest [SleepTk.py](./SleepTk.py) and put it in `wasp-os/wasp/apps/SleepTk.py`
* open `SleepTk.py` to edit the user settings (at the top of the file)
* compile `wasp-os`: `make submodules && make softdevice && make BOARD=pinetime all && echo "SUCCESS"`
* upload it to your pinetime: `./tools/ota-dfu/dfu.py -z build-pinetime/micropython.zip -a XX:XX:XX:XX:XX:XX --legacy`
* reboot the watch and enjoy `SleepTk`
* *optional: download your latest sleep data using the script `pull_sleep_data.py`*
* *optional: delete all the sleep data present in your watch using the script `rm_sleep_data.py`*
### Note to reader:
* Note that the watch assumes an average of 14 minutes to fall asleep. You have to take this into account if you feel super sleepy at the time of setting the alarm.
* If you're interested or have any kind of things to say about this, **please** open an issue and tell me all about it :)
* Status as of end of May 2022: *UI (**done**), regular alarm (**done**), heart tracking (**done** but might be a bit dodgy), smart alarm (**mostly done but untested**)*
* you can download your sleep data file using the file `pull_sleep_data`. A suggested workflow to load it into [pandas](https://pypi.org/project/pandas/) can be found at the bottom of the page.
* the notifications are set to "silent" during the tracking session and are restored to the previously used level when the alarm is ringing
* by default, the Bluetooth is turned off when tracking to save battery. Wasp OS doesn't allow to turn it back on without restarting the watch.
* it seems the simulator is having a rough time with daylight saving mode or time management. I personnaly have a 1h offset between sleep estimation on the simulator compared to the pinetime, don't worry.
# Screenshots:
![settings](./screenshots/settings_page.png)
![settings2](./screenshots/settings_page2.png)
![tracking](./screenshots/tracking_page.png)
![night example](./screenshots/example_night.png)
## TODO
**misc**
* greatly simplify the code by simply adding a large tick function every second instead of managing tons of counters.
* investigate adding a simple feature to wake you up only after a certain movement threshold was passed
* add a "nap tracking" mode that records sleep tracking with more precision
* add a "power nap" mode that wakes you as soon as there has been no movement for 5 minutes OR (like steelball) when your heart rate drops
* implement a simple Neural Network or decision tree to compute best wake up time, using one found in the scientific literature.
* implement downsampling to 15 minutes precision to compute best wake up time
* log smart alarm data to file? log user rating of how well he/she felt fresh at wake?
* ability to send in real time to Bluetooth device the current sleep stage you're probably in. For use in Targeted Memory Reactivation?
## Bibliography and related links:
* [Estimating sleep parameters using an accelerometer without sleep diary](https://www.nature.com/articles/s41598-018-31266-z)
* [Sleep stage prediction with raw acceleration and photoplethysmography heart rate data derived from a consumer wearable device](https://academic.oup.com/sleep/article/42/12/zsz180/5549536)
* [Towards Benchmarked Sleep Detection with Wrist-Worn Sensing Units](https://ieeexplore.ieee.org/document/7052479)
### to read :
* [Sleep classification from wrist-worn accelerometer data using random forests](https://pubmed.ncbi.nlm.nih.gov/33420133/)
* [Sleep Monitoring Based on a Tri-Axial Accelerometer and a Pressure Sensor](https://www.mdpi.com/1424-8220/16/5/750)
* [A Sleep Monitoring Application for u-lifecare Using Accelerometer Sensor of Smartphone](https://link.springer.com/chapter/10.1007/978-3-319-03176-7_20)
* [The Promise of Sleep: A Multi-Sensor Approach for Accurate Sleep Stage Detection Using the Oura Ring](https://www.mdpi.com/1424-8220/21/13/4302)
* [Validation of an Accelerometer Based BCG Method for Sleep Analysis](https://aaltodoc.aalto.fi/handle/123456789/21176)
* [Accelerometer-based sleep analysis](https://patents.google.com/patent/US20140364770A1/en)
* [Performance comparison between wrist and chest actigraphy in combination with heart rate variability for sleep classification](https://www.sciencedirect.com/science/article/pii/S0010482517302597)
* [Estimation of sleep stages in a healthy adult population from optical plethysmography and accelerometer signals](https://iopscience.iop.org/article/10.1088/1361-6579/aa9047/meta)
* [SleepPy: A python package for sleep analysis from accelerometer data](https://joss.theoj.org/papers/10.21105/joss.01663.pdf)
### Related project:
* another hackable smartwatch has a similar software: [sleepphasealarm](https://banglejs.com/apps/#sleepphasealarm) and [steelball](https://github.com/jabituyaben/SteelBall) for the [Banglejs](https://banglejs.com/)
## Pandas integration:
Commands the author uses to take a look a the data using pandas:
```
fname = "./logs/sleep/YOUR_TIME.csv"
import pandas as pd
import plotly.express as plt
#df = pd.read_csv(fname, names=["motion", "elapsed", "x_avg", "y_avg", "z_avg", "battery"])
df = pd.read_csv(fname, names=["motion", "elapsed", "heart_rate"])
start_time = int(fname.split("/")[-1].split(".csv")[0])
df["time"] = pd.to_datetime(df["elapsed"]+start_time, unit='s')
df["human_time"] = df["time"].dt.time
month = df.iloc[0]["time"].month_name()
dayname = str(df.iloc[0]["time"].day_name())
daynumber = str(df.iloc[0]["time"].day)
if daynumber == 1:
daynumber = str(daynumber) + "st"
elif daynumber.endswith("2"):
daynumber = str(daynumber) + "nd"
elif daynumber.endswith("3"):
daynumber = str(daynumber) + "rd"
else:
daynumber = str(daynumber) + "th"
date = f"{month} {daynumber} ({dayname})"
fig = px.line(df,
x="time",
y="motion",
labels={"motion": "Body motion", "time":"Time"},
title=f"Night starting on {date}")
fig.update_xaxes(type="date",
tickformat="%H:%M"
)
fig.show()
df_HR = df.set_index("human_time")["heart_rate"]
df_HR = df_HR[~df_HR.isna()]
df_HR.plot()
```
Now, to play around with the signal processing function:
```
import array
data = array.array("f", df["motion"])
data = data[:15] # remove the last few data points as the signal
# processor does not yet have access to them when finding best wake up time
##############################################
### PUT LATEST SIGNAL PROCESSING CODE HERE ###
##############################################
from matplotlib import pyplot as plt
plt.plot(data)
for i in x_maximas:
plt.axvline(x=i,
color="red",
linestyle="--"
)
plt.show()
```

847
external/SleepTk/SleepTk.py vendored Normal file
View file

@ -0,0 +1,847 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2021 github.com/thiswillbeyourgithub/
"""Sleep tracker
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SleepTk is an alarm clock app designed to track body movement throughout
the night to optimize sleep. Currently a WIP, more information at
https://github.com/thiswillbeyourgithub/sleep_tracker_pinetime_wasp-os
"""
import wasp
import widgets
import shell
import fonts
import math
import ppg
from array import array
from micropython import const
# 2-bit RLE, 60x60, 225 bytes, kindly designed by Emanuel Löffler (https://github.com/plan5)
icon = (
b'\x02'
b'<<'
b'?\x11\xd2*\xd2*\xd2*\xd8$\xd82\xca2\xca6'
b'\xc4\x02\xc24\xc4\x02\xc24\xc4\x04\xc40\xc4\x04\xc40'
b'\xc4\x04\xc40\xc4\x04\xc42\xc2\x04\xc8.\xc2\x04\xc8.'
b'\xc2\x04\xc8.\xc2\x04\xc8 \xc4\n\xc2\x06\xc6 \xc4\n'
b'\xc2\x06\xc6 \xc4\x08\xc6\x04\xc6 \xc4\x08\xc6\x04\xc6\x1e'
b'\xc8\x06\xc6\x04\xc6\x1e\xc8\x06\xc6\x04\xc6\x1e\xc8\x06\xc6\x04'
b'\xc6\x1e\xc8\x06\xc6\x04\xc6\x1c\xca\x06\xc6\x04\xc6\x1c\xd6\x04'
b'\xc6\x1c\xd6\x04\xc6\x1c\xd6\x04\xc6\x07\xed\x08\xc4\x03\xed\x08'
b'\xc4\x03\xed\x08\xc4\x03\xed\x08\xc4"\xc6\x04\xc4\x06\xc2&'
b'\xc6\x04\xc4\x06\xc2&\xc6\x04\xc4\x06\xc2&\xc6\x04\xc4\x06'
b'\xc2&\xc6\x04\xc6\x04\xc2&\xc6\x04\xc6\x04\xc2(\xc2\x04'
b'\xc8\x02\xc2*\xc2\x04\xc8\x02\xc2.\xce.\xce.\xce.'
b'\xce*\xd1+\xd1+\xd1+\xd1%\xd7%\xd4\x16\xe6\x16'
b'\xe6\x16\xe0\x1c\xe0\x1c\xde\x1e\xde"\xd4(\xd4\x1a'
)
# HARDCODED VARIABLES:
_ON = const(1)
_OFF = const(0)
_TRACKING = const(0)
_RINGING = const(1)
_SETTINGS1 = const(2)
_SETTINGS2 = const(3)
_FONT = fonts.sans18
_FONT_COLOR = const(0xf800) # red font to reduce eye strain at night
_TIMESTAMP = const(946684800) # unix time and time used by wasp os don't have the same reference date
## USER SETTINGS #################################
_KILL_BT = const(1)
# set to 0 to disable turning off bluetooth while tracking to save battery
# (you have to reboot the watch to reactivate BT, default: 1)
_STOP_LIMIT = const(10)
# number of times to swipe or press the button to turn off ringing (default: 10)
_SNOOZE_TIME = const(300)
# number of seconds to snooze for (default: 5 minutes)
_FREQ = const(5)
# get accelerometer data every X seconds, but process and store them only
# every _STORE_FREQ seconds (default: 5)
_HR_FREQ = const(300)
# how many seconds between heart rate data (default: 300, minimum 120)
_STORE_FREQ = const(300)
# process data and store to file every X seconds (default: 300)
_BATTERY_THRESHOLD = const(15)
# under X% of battery, stop tracking and only keep the alarm, set at -200
# or lower to disable (default: 15)
_ANTICIPATE_ALLOWED = const(2400)
# number of seconds SleepTk can wake you up before the alarm clock you set
# only relevant if smart_alarm is enabled. (default: 2400)
_GRADUAL_WAKE = array("H", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
# nb of minutes before alarm to send a tiny vibration, designed to wake
# you more gently. (default: array("H", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) )
_MINUTES_TO_FALL_ASLEEP = const(14)
# time you take to fall asleep (default: 14, according to https://sleepyti.me/)
_CYCLE_LENGTH = const(90)
# sleep cycle length in minutes. Currently used only to display best wake up
# time but not to compute smart alarm! (default: 90 or 100, according to
# https://sleepyti.me/)
_SLEEP_GOAL_CYCLE = const(5)
# number of sleep cycle you wish to sleep. With _CYCLE_LENGTH this is used
# to suggest best wake up time to user when setting the alarm. (default: 5)
##################################################
class SleepTkApp():
NAME = 'SleepTk'
ICON = icon
def __init__(self):
wasp.gc.collect()
# default button state
self._state_alarm = _ON
self._state_body_tracking = _OFF
self._state_HR_tracking = _OFF
self._state_gradual_wake = _ON
self._state_smart_alarm = _OFF
self._state_spinval_H = _OFF
self._state_spinval_M = _OFF
self._hrdata = None
self._last_HR = _OFF # if _OFF, no HR to write, if "?": error during last HR, else: heart rate
self._last_HR_printed = "?"
self._last_HR_date = _OFF
self._track_HR_once = _OFF
self._page = _SETTINGS1
self._currently_tracking = _OFF
self._conf_view = _OFF # confirmation view
self._smart_offset = _OFF # number of seconds between the alarm you set manually and the smart alarm time
self._buff = array("f", [_OFF, _OFF, _OFF]) # contains accelerometer values
self._last_touch = int(wasp.watch.rtc.time())
try:
shell.mkdir("logs/")
except: # folder already exists
pass
try:
shell.mkdir("logs/sleep")
except: # folder already exists
pass
def foreground(self):
self.stat_bar = widgets.StatusBar()
self.stat_bar.clock = True
self._conf_view = _OFF
wasp.gc.collect()
self._draw()
wasp.system.request_event(wasp.EventMask.TOUCH |
wasp.EventMask.SWIPE_LEFTRIGHT |
wasp.EventMask.SWIPE_UPDOWN |
wasp.EventMask.BUTTON)
if self._page == _TRACKING and self._track_HR_once:
wasp.system.request_tick(1000 // 8)
def sleep(self):
self._stop_trial = 0
wasp.gc.collect()
return True
def background(self):
wasp.watch.hrs.disable()
self._hrdata = None
wasp.gc.collect()
def _try_stop_alarm(self):
"""If button or swipe more than _STOP_LIMIT, then stop ringing"""
if self._stop_trial + 1 >= _STOP_LIMIT:
self._n_vibration = 0
del self._n_vibration
wasp.system.cancel_alarm(self._WU_t, self._activate_ticks_to_ring)
self._disable_tracking()
self.__init__()
self.foreground()
else:
self._stop_trial += 1
draw = wasp.watch.drawable
draw.set_color(_FONT_COLOR)
draw.string("{} to stop".format(_STOP_LIMIT - self._stop_trial), 0, 70)
def press(self, button, state):
"stop ringing alarm if pressed physical button"
if not state:
return
self._last_touch = int(wasp.watch.rtc.time())
mute = wasp.watch.display.mute
mute(False)
if self._page == _RINGING:
self._try_stop_alarm()
elif self._page == _TRACKING:
self._was_touched = 1
# disable pressing to exit, use swipe up instead
self._draw()
else:
wasp.system.navigate(wasp.EventType.HOME)
def swipe(self, event):
"navigate between settings page"
mute = wasp.watch.display.mute
mute(False)
self._last_touch = int(wasp.watch.rtc.time())
if self._page == _SETTINGS1:
if event[0] == wasp.EventType.LEFT:
self._page = _SETTINGS2
self._draw()
else:
return True
elif self._page == _SETTINGS2:
if event[0] == wasp.EventType.RIGHT:
self._page = _SETTINGS1
self._draw()
else:
return True
elif self._page == _RINGING:
self._try_stop_alarm()
else:
return True
def touch(self, event):
"""either start trackign or disable it, draw the screen in all cases"""
wasp.gc.collect()
draw = wasp.watch.drawable
mute = wasp.watch.display.mute
mute(False)
self._last_touch = int(wasp.watch.rtc.time())
if self._page == _TRACKING:
self._was_touched = 1
if self._conf_view is _OFF:
if self.btn_off.touch(event):
self._conf_view = widgets.ConfirmationView()
self._conf_view.draw("Stop tracking?")
draw.reset()
return
else:
if self._conf_view.touch(event):
if self._conf_view.value:
self._disable_tracking()
self._page = _SETTINGS1
self._conf_view = _OFF
draw.reset()
elif self._page == _RINGING:
if self.btn_snooz.touch(event):
if self._track_HR_once: # if currently tracking HR, stop
self._track_HR_once = _OFF
self._hrdata = None
wasp.watch.hrs.disable()
self._page = _TRACKING
self._WU_t = int(wasp.watch.rtc.time()) + _SNOOZE_TIME
wasp.system.set_alarm(self._WU_t, self._activate_ticks_to_ring)
wasp.system.sleep()
elif self._page == _SETTINGS1:
if self._state_alarm and (self._spin_H.touch(event) or self._spin_M.touch(event)):
if self._state_spinval_M == 0 and self._spin_M.value == 55:
self._spin_H.value -= 1
elif self._state_spinval_M == 55 and self._spin_M.value == 0:
self._spin_H.value += 1
if self._spin_H.value >= 24:
self._spin_H.value = 0
elif self._spin_H.value <= -1:
self._spin_H.value = 23
self._state_spinval_M = self._spin_M.value
self._spin_M.update()
self._state_spinval_H = self._spin_H.value
self._spin_H.update()
if self._state_alarm:
self._draw_duration(draw)
return
elif self.check_al.touch(event):
self._state_alarm = self.check_al.state
self.check_al.update()
return
elif self._page == _SETTINGS2:
if self._state_body_tracking:
if self.btn_HR.touch(event):
self.btn_HR.draw()
self._state_HR_tracking = self.btn_HR.state
return
if self._state_alarm:
if self.check_grad.touch(event):
self._state_gradual_wake = self.check_grad.state
self.check_grad.draw()
return
if self._state_body_tracking:
if self.check_smart.touch(event):
self._state_smart_alarm = self.check_smart.state
self.check_smart.draw()
return
if self.btn_sta.touch(event):
draw.fill()
draw.string("Loading", 0, 100)
self._start_tracking()
elif self.check_body_tracking.touch(event):
self._state_body_tracking = self.check_body_tracking.state
self.check_body_tracking.draw()
if not self._state_body_tracking:
self._state_smart_alarm = _OFF
self._state_HR_tracking = _OFF
self._draw()
def _draw_duration(self, draw):
draw.set_font(_FONT)
if self._page == _SETTINGS1:
duration = (self._read_time(self._state_spinval_H, self._state_spinval_M) - wasp.watch.rtc.time()) / 60 - _MINUTES_TO_FALL_ASLEEP
assert duration >= _MINUTES_TO_FALL_ASLEEP
y = 180
elif self._page == _TRACKING:
draw.set_color(_FONT_COLOR)
duration = (wasp.watch.rtc.time() - self._track_start_time) / 60 - _MINUTES_TO_FALL_ASLEEP # time slept
if duration <= 0: # don't print when not yet asleep
return
y = 130
draw.string("Total sleep {:02d}h{:02d}m".format(
int(duration // 60),
int(duration % 60)), 0, y + 20)
cycl = duration / _CYCLE_LENGTH
cycl_modulo = cycl % 1
draw.string("{} cycles ".format(str(cycl)[0:4]), 0, y)
if duration > 30 and not self._track_HR_once:
if cycl_modulo > 0.10 and cycl_modulo < 0.90:
draw.string("Not rested!", 0, y + 40)
else:
draw.string("Well rested", 0, y + 40)
def _draw(self):
"""GUI"""
mute = wasp.watch.display.mute
mute(False)
draw = wasp.watch.drawable
draw.fill(0)
self.stat_bar.draw()
draw.set_font(_FONT)
draw.set_color(_FONT_COLOR)
if self._page == _RINGING:
if self._smart_offset != 0:
msg = "WAKE UP ({}m early)".format(str(self._smart_offset//60)[0:2])
else:
msg = "WAKE UP"
draw.string(msg, 0, 50)
self.btn_snooz = widgets.Button(x=0, y=90, w=240, h=120, label="SNOOZE")
self.btn_snooz.draw()
draw.reset()
elif self._page == _TRACKING:
ti = wasp.watch.time.localtime(self._track_start_time)
draw.string('Began at {:02d}:{:02d}'.format(ti[3], ti[4]), 0, 50)
if self._state_alarm:
word = "Alarm at "
if self._state_smart_alarm:
word = "Alarm BEFORE "
ti = wasp.watch.time.localtime(self._WU_t)
draw.string("{}{:02d}:{:02d}".format(word, ti[3], ti[4]), 0, 70)
draw.string("Gradual wake: {}".format(True if self._state_gradual_wake else False), 0, 90)
else:
draw.string("No alarm set", 0, 70)
draw.string("data points: {} / {}".format(str(self._data_point_nb), str(self._data_point_nb * _FREQ // _STORE_FREQ)), 0, 110)
if self._track_HR_once:
draw.string("(ongoing)", 0, 170)
if self._state_HR_tracking:
draw.string("HR:{}".format(self._last_HR_printed), 160, 170)
self.btn_off = widgets.Button(x=0, y=200, w=240, h=40, label="Stop")
self.btn_off.update(txt=_FONT_COLOR, frame=0, bg=0)
self._draw_duration(draw)
elif self._page == _SETTINGS1:
# reset spinval values between runs
self._state_spinval_H = _OFF
self._state_spinval_M = _OFF
self.check_al = widgets.Checkbox(x=0, y=40, label="Wake me up")
self.check_al.state = self._state_alarm
self.check_al.draw()
if self._state_alarm:
if (self._state_spinval_H, self._state_spinval_M) == (_OFF, _OFF):
# suggest wake up time, on the basis of desired sleep goal + time to fall asleep
(H, M) = wasp.watch.rtc.get_localtime()[3:5]
goal_h = _SLEEP_GOAL_CYCLE * _CYCLE_LENGTH // 60
goal_m = _SLEEP_GOAL_CYCLE * _CYCLE_LENGTH % 60
M += goal_m + _MINUTES_TO_FALL_ASLEEP
while M % 5 != 0:
M += 1
self._state_spinval_H = ((H + goal_h) % 24 + (M // 60)) % 24
self._state_spinval_M = M % 60
self._spin_H = widgets.Spinner(30, 70, 0, 23, 2)
self._spin_H.value = self._state_spinval_H
self._spin_H.draw()
self._spin_M = widgets.Spinner(150, 70, 0, 59, 2, 5)
self._spin_M.value = self._state_spinval_M
self._spin_M.draw()
if self._state_alarm:
self._draw_duration(draw)
elif self._page == _SETTINGS2:
self.check_body_tracking = widgets.Checkbox(x=0, y=40, label="Movement tracking")
self.check_body_tracking.state = self._state_body_tracking
self.check_body_tracking.draw()
if self._state_body_tracking:
self.btn_HR = widgets.Checkbox(x=0, y=80, label="Heart rate tracking")
self.btn_HR.state = self._state_HR_tracking
self.btn_HR.draw()
if self._state_alarm:
self.check_grad = widgets.Checkbox(0, 120, "Gradual wake")
self.check_grad.state = self._state_gradual_wake
self.check_grad.draw()
if self._state_body_tracking:
self.check_smart = widgets.Checkbox(x=0, y=160, label="Smart alarm")
self.check_smart.state = self._state_smart_alarm
self.check_smart.draw()
self.btn_sta = widgets.Button(x=0, y=200, w=240, h=40, label="Start")
self.btn_sta.draw()
draw.reset()
def _start_tracking(self):
# save some memory
self.check_al = None
self.check_smart = None
self.check_body_tracking = None
self.check_grad = None
self.btn_sta = None
self.btn_snooz = None
self.btn_off = None
self.btn_HR = None
self._spin_H = None
self._spin_M = None
del self.check_al, self.check_smart, self.check_body_tracking, self.check_grad, self.btn_sta, self.btn_snooz, self.btn_off, self.btn_HR, self._spin_H, self._spin_M
self._currently_tracking = True
# accel data not yet written to disk:
self._data_point_nb = 0 # total number of data points so far
self._last_checkpoint = 0 # to know when to save to file
self._track_start_time = int(wasp.watch.rtc.time()) # makes output more compact
self._last_HR_printed = "?"
self._was_touched = 0
wasp.watch.accel.reset()
# create one file per recording session:
self.filep = "logs/sleep/{}.csv".format(str(self._track_start_time + _TIMESTAMP))
f = open(self.filep, "wb")
f.write(b"")
f.close()
# if enabled, add alarm to log accel data in _FREQ seconds
if self._state_body_tracking:
self.next_al = wasp.watch.rtc.time() + _FREQ
wasp.system.set_alarm(self.next_al, self._trackOnce)
else:
self.next_al = None
if self._state_gradual_wake and not self._state_alarm:
# fix incompatible settings
self._state_gradual_wake = _OFF
# setting up alarm
if self._state_alarm:
self._old_notification_level = wasp.system.notify_level
self._WU_t = self._read_time(self._state_spinval_H, self._state_spinval_M)
wasp.system.set_alarm(self._WU_t, self._activate_ticks_to_ring)
# also set alarm to vibrate a tiny bit before wake up time
# to wake up gradually
if self._state_gradual_wake:
for t in _GRADUAL_WAKE:
wasp.system.set_alarm(self._WU_t - int(t*60), self._tiny_vibration)
# wake up SleepTk 2min before earliest possible wake up
if self._state_smart_alarm:
if not SmartAlarm in locals():
raise Exception("SmartAlarm was removed in previous run to save memory. Restart the watch to use it.")
self._WU_a = self._WU_t - _ANTICIPATE_ALLOWED - 120
wasp.system.set_alarm(self._WU_a, self._smart_alarm_start)
else:
SmartAlarm = None
del SmartAlarm
# don't track heart rate right away, wait a few seconds
if self._state_HR_tracking:
self._last_HR_date = int(wasp.watch.rtc.time()) + 10
wasp.system.notify_level = 1 # silent notifications
# kill bluetooth
if _KILL_BT:
import ble
if ble.enabled():
ble.disable()
self._page = _TRACKING
self._stop_trial = 0
def _read_time(self, HH, MM):
"convert time from spinners to seconds"
(Y, Mo, d, h, m) = wasp.watch.rtc.get_localtime()[0:5]
HH = self._state_spinval_H
MM = self._state_spinval_M
if HH < h or (HH == h and MM <= m):
d += 1
return wasp.watch.time.mktime((Y, Mo, d, HH, MM, 0, 0, 0, 0))
def _disable_tracking(self, keep_main_alarm=False):
"""called by touching "STOP TRACKING" or when computing best alarm time
to wake up you disables tracking features and alarms"""
self._currently_tracking = False
if self.next_al:
wasp.system.cancel_alarm(self.next_al, self._trackOnce)
if self._state_alarm:
if keep_main_alarm is False: # to keep the alarm when stopping because of low battery
wasp.system.cancel_alarm(self._WU_t, self._activate_ticks_to_ring)
for t in _GRADUAL_WAKE:
wasp.system.cancel_alarm(self._WU_t - int(t*60), self._tiny_vibration)
if self._state_smart_alarm:
wasp.system.cancel_alarm(self._WU_a, self._smart_alarm_start)
self._state_smart_alarm = _OFF
wasp.watch.hrs.disable()
self._periodicSave()
self._state_HR_tracking = _OFF
wasp.gc.collect()
def _trackOnce(self):
"""get one data point of accelerometer every _FREQ seconds, keep
the average of each axis then store in a file every
_STORE_FREQ seconds"""
if self._currently_tracking:
buff = self._buff
xyz = wasp.watch.accel.accel_xyz()
if xyz == (0, 0, 0):
wasp.watch.accel.reset()
xyz = wasp.watch.accel.accel_xyz()
buff[0] += xyz[1]
buff[1] += xyz[0]
buff[2] -= xyz[2]
self._data_point_nb += 1
# add alarm to log accel data in _FREQ seconds
self.next_al = wasp.watch.rtc.time() + _FREQ
wasp.system.set_alarm(self.next_al, self._trackOnce)
self._periodicSave()
if wasp.watch.battery.level() <= _BATTERY_THRESHOLD:
# strop tracking if battery low
self._disable_tracking(keep_main_alarm=True)
h, m = wasp.watch.time.localtime(wasp.watch.rtc.time())[3:5]
wasp.system.notify(wasp.watch.rtc.get_uptime_ms(), {"src": "SleepTk",
"title": "Bat low",
"body": "Stopped \
tracking sleep at {}h{}m because your battery went below {}%. Alarm kept \
on.".format(h, m, _BATTERY_THRESHOLD)})
elif self._state_HR_tracking and \
wasp.watch.rtc.time() - self._last_HR_date > _HR_FREQ and \
not self._track_HR_once:
self._track_HR_once = _ON
wasp.system.wake()
if int(wasp.watch.rtc.time()) - self._last_touch > 5:
mute = wasp.watch.display.mute
mute(True)
wasp.system.switch(self)
wasp.system.request_tick(1000 // 8)
wasp.gc.collect()
def _periodicSave(self):
"""save data to csv with row order:
1. average arm angle
2. elapsed times
3/4. heart rate if present, and/or -1 if screen was woken up
by user during that time
arm angle formula from https://www.nature.com/articles/s41598-018-31266-z
note: math.atan() is faster than using a taylor serie
"""
buff = self._buff
n = self._data_point_nb - self._last_checkpoint
if n >= _STORE_FREQ // _FREQ and not self._track_HR_once:
buff[0] /= n
buff[1] /= n
buff[2] /= n
if self._last_HR != _OFF:
bpm = ",{}".format(str(self._last_HR))
self._last_HR = _OFF
else:
bpm = ""
f = open(self.filep, "ab")
f.write("{:7f},{}{}\n".format(
math.atan(buff[2] / (buff[0]**2 + buff[1]**2))*180/3.1415926535, # estimated arm angle
int(wasp.watch.rtc.time() - self._track_start_time),
bpm,
",-1" if self._was_touched else ""
).encode())
f.close()
del f
buff[0] = 0 # resets x/y/z to 0
buff[1] = 0
buff[2] = 0
self._last_checkpoint = self._data_point_nb
self._was_touched = 0
wasp.gc.collect()
def _activate_ticks_to_ring(self):
"""listen to ticks every second, telling the watch to vibrate and
completely wake the user up"""
wasp.gc.collect()
wasp.system.notify_level = self._old_notification_level # restore notification level
self._page = _RINGING
self._n_vibration = 0
if int(wasp.watch.rtc.time()) - self._last_touch > 5:
mute = wasp.watch.display.mute
mute(True)
wasp.system.wake()
wasp.system.switch(self)
self._draw()
wasp.system.request_tick(period_ms=1000)
def tick(self, ticks):
"""vibrate to wake you up OR track heart rate using code from heart.py"""
wasp.gc.collect()
wasp.system.switch(self)
if self._page == _RINGING:
wasp.system.keep_awake()
# in 60 vibrations, ramp up from subtle to strong:
wasp.watch.vibrator.pulse(duty=max(80 - 1 * self._n_vibration, 20),
ms=min(100 + 6 * self._n_vibration, 500))
self._n_vibration += 1
elif self._track_HR_once:
wasp.watch.hrs.enable()
if self._hrdata is None:
self._hrdata = ppg.PPG(wasp.watch.hrs.read_hrs())
t = wasp.machine.Timer(id=1, period=8000000)
t.start()
wasp.system.keep_awake()
if int(wasp.watch.rtc.time()) - self._last_touch > 5:
mute = wasp.watch.display.mute
mute(True)
self._subtick(1)
while t.time() < 41666:
pass
wasp.system.keep_awake()
self._subtick(1)
while t.time() < 83332:
pass
wasp.system.keep_awake()
self._subtick(1)
t.stop()
del t
wasp.system.keep_awake()
if len(self._hrdata.data) >= 240: # 10 seconds passed
bpm = self._hrdata.get_heart_rate()
bpm = int(bpm) if bpm is not None else None
if bpm is None:
# in case of invalid data, write it in the file but
# keep trying to read HR
self._last_HR = "?"
self._hrdata = None
self._last_HR_printed = self._last_HR
elif bpm < 100 and bpm > 40:
# if HR was already computed since last periodicSave,
# then average the two values
if self._last_HR != _OFF and self._last_HR != "?" and isinstance(int, self._last_HR):
self._last_HR = (self._last_HR + bpm) // 2
else:
self._last_HR = bpm
self._last_HR_printed = self._last_HR
self._last_HR_date = int(wasp.watch.rtc.time())
self._track_HR_once = _OFF
self._hrdata = None
wasp.watch.hrs.disable()
if int(wasp.watch.rtc.time()) - self._last_touch > 5:
wasp.system.sleep()
def _subtick(self, ticks):
"""track heart rate at 24Hz"""
self._hrdata.preprocess(wasp.watch.hrs.read_hrs())
def _tiny_vibration(self):
"""vibrate just a tiny bit before waking up, to gradually return
to consciousness"""
wasp.gc.collect()
if int(wasp.watch.rtc.time()) - self._last_touch > 5:
mute = wasp.watch.display.mute
mute(True)
wasp.system.wake()
wasp.system.switch(self)
wasp.watch.vibrator.pulse(duty=60, ms=100)
if not self._track_HR_once:
wasp.system.sleep()
def _smart_alarm_start(self):
SmartAlarm(self)
class SmartAlarm():
def __init__(self, sleeptk):
self.sleeptk = sleeptk
self._smart_alarm_compute()
def _smart_alarm_compute(self):
"""computes best wake up time from sleep data"""
wasp.gc.collect()
if not self.sleeptk._smart_alarm_state:
t = wasp.watch.time.localtime(wasp.watch.rtc.time())
wasp.system.notify(wasp.watch.rtc.get_uptime_ms(),
{"src": "SleepTk",
"title": "Smart alarm computation",
"body": "Started computation for the smart alarm \
BY MISTAKE at {:02d}h{:02d}m".format(t[3], t[4])})
return
mute = wasp.watch.display.mute
mute(True)
wasp.system.wake()
wasp.system.switch(self.sleeptk)
t = wasp.watch.time.localtime(wasp.watch.rtc.time())
wasp.system.notify(wasp.watch.rtc.get_uptime_ms(),
{"src": "SleepTk",
"title": "Starting smart alarm computation",
"body": "Starting computation for the smart alarm at {:02d}h{:02d}m".format(t[3], t[4])}
)
try:
start_time = wasp.watch.rtc.time()
# stop tracking to save memory, keep the alarm just in case
#self.sleeptk._disable_tracking(keep_main_alarm=True)
# read file one character at a time, to get only the 1st
# value of each row, which is the arm angle
data = array("f")
buff = b""
f = open(self.sleeptk.filep, "rb")
skip = False
while True:
char = f.read(1)
if char == b",": # start ignoring after the first col
skip = True
continue
if char == b"\n":
skip = False # stop skipping because reading a new line
data.append(float(buff))
buff = b""
continue
if char == b"": # end of file
data.append(float(buff))
break
if not skip: # digit of arm angle value
buff += char
f.close()
del f, char, buff
wasp.gc.collect()
wasp.system.keep_awake()
earlier, cycle = self.sleeptk._signal_processing(data)
WU_t = self.sleeptk._WU_t
wasp.gc.collect()
# add new alarm
wasp.system.set_alarm(max(WU_t - earlier, int(wasp.watch.rtc.time()) + 3), # not before right now, to make sure it rings
self.sleeptk._activate_ticks_to_ring)
# replace old gentle alarm by another one
if self.sleeptk._grad_alarm_state:
for t in _GRADUAL_WAKE:
wasp.system.cancel_alarm(WU_t - int(t*60), self.sleeptk._tiny_vibration)
if earlier + int(t*60) < _ANTICIPATE_ALLOWED:
wasp.system.set_alarm(WU_t - earlier - int(t*60), self.sleeptk._tiny_vibration)
self.sleeptk._earlier = earlier
self.sleeptk._page = _TRACKING
wasp.system.notify(wasp.watch.rtc.get_uptime_ms(), {"src": "SleepTk",
"title": "Finished smart alarm computation",
"body": "Finished computing best wake up time in {:2f}s. Sleep cycle: {:.2f}h".format(wasp.watch.rtc.time() - start_time, cycle)
})
if not self.sleeptk._track_HR_once:
wasp.system.sleep()
except Exception as e:
wasp.gc.collect()
h, m = wasp.watch.time.localtime(wasp.watch.rtc.time())[3:5]
msg = "Exception occured at {:02d}h{:02d}m: '{}'%".format(h, m, str(e))
f = open("smart_alarm_error_{}.txt".format(int(wasp.watch.rtc.time())), "wb")
f.write(msg.encode())
f.close()
wasp.system.notify(wasp.watch.rtc.get_uptime_ms(), {"src": "SleepTk",
"title": "Smart alarm error",
"body": msg})
wasp.gc.collect()
def _signal_processing(self, data):
"""signal processing over the data read from the local file"""
# take absolute rate of change of data
for i in range(len(data)-1):
mem = data[i+1]
data[i] = abs(mem-data[i])
del i
# remove outliers:
for x in range(len(data)):
data[x] = min(0.005, data[x])
del x
wasp.gc.collect()
wasp.system.keep_awake()
# smoothen several times
for j in range(5):
for i in range(1, len(data)-1):
data[i] += data[i-1]
data[i] /= 2
del i, j
wasp.gc.collect()
wasp.system.keep_awake()
# center data
mean = sum(data) / len(data)
for i in range(len(data)):
data[i] = data[i] - mean
del mean, i
wasp.gc.collect()
wasp.system.keep_awake()
# find local maximas
x_maximas = array("H", [0])
y_maximas = array("f", [0])
window = int(60*60/_STORE_FREQ)
skip = 1800 // _STORE_FREQ # skip first 60 minutes of data
for start_w in range(skip, len(data) - window + 1):
m = max(data[start_w:start_w + window])
for i in range(start_w, start_w + window):
if data[i] == m and m > 0:
if i not in x_maximas:
if i - x_maximas[-1] <= 2:
# too close to last maximum, keep highest
if y_maximas[-1] < data[i]:
x_maximas[-1] = i
y_maximas[-1] = data[i]
else:
x_maximas.append(i)
y_maximas.append(m)
del window, skip, start_w, i, m, x_maximas[0], y_maximas[0], data
wasp.gc.collect()
wasp.system.keep_awake()
# merge the closest peaks while there are more than N peaks
N = 3
while len(x_maximas) > N:
diffs = array("f", [x_maximas[int(x)+1] - x_maximas[int(x)] for x in range(len(x_maximas)-1)])
ex = False
for d_min_idx, d in enumerate(diffs):
if ex:
break
if d == min(diffs):
y_maximas.remove(y_maximas[d_min_idx+1])
x_maximas.remove(x_maximas[d_min_idx+1])
ex = True
del diffs, ex, d_min_idx
wasp.gc.collect()
wasp.system.keep_awake()
# sleep cycle duration is the average time distance between those N peaks
cycle = sum([x_maximas[i+1] - x_maximas[i] for i in range(len(x_maximas) -1)]) / N * _STORE_FREQ
last_peak = self.sleeptk._track_start_time + x_maximas[-1] * _STORE_FREQ
WU_t = self.sleeptk._WU_t
# check if too late, already woken up:
if last_peak + cycle > WU_t:
raise Exception("Took too long to compute!")
# if smart alarm wants to wake you up too early, limit how early
if last_peak + cycle < WU_t - _ANTICIPATE_ALLOWED:
earlier = _ANTICIPATE_ALLOWED
else: # will wake you up at computed time
earlier = last_peak - self.sleeptk._track_start_time + cycle
wasp.system.keep_awake()
return (earlier, cycle)

54
external/SleepTk/pull_sleep_data.py vendored Normal file
View file

@ -0,0 +1,54 @@
#!/usr/local/bin/python3
import time
import os
import subprocess
import shlex
import re
from tqdm import tqdm
mode = "all" # download "all" files or only "latest"
autoreboot = True # reboot between each download, to avoid memory issues
print("\n\nRunning gc.collect()...")
mem_cmd = './tools/wasptool --verbose --eval \'wasp.gc.collect()\''
subprocess.check_output(shlex.split(mem_cmd))
print("\n\nListing remote files...")
ls_cmd = './tools/wasptool --verbose --eval \'from shell import ls ; ls(\"/flash/logs/sleep/\")\''
out = subprocess.check_output(shlex.split(ls_cmd)).decode()
files = re.findall(r"\d*\.csv", out)
print(f"Found files {', '.join(files)}")
reset_cmd = './tools/wasptool --verbose --reset'
if mode == "latest":
to_dl = files[-1]
elif mode == "all":
to_dl = files
else:
raise Exception("Wrong value for 'mode'")
print("\n\n")
for fi in tqdm(to_dl):
if os.path.exists(f"./logs/sleep/{fi}"):
tqdm.write(f"Skipping file {fi}: already exists")
else:
tqdm.write(f"Downloading file '{fi}'")
pull_cmd = f'./tools/wasptool --verbose --pull logs/sleep/{fi}'
try:
out = subprocess.check_output(shlex.split(pull_cmd))
if b"Watch reported error" in out:
raise Exception("Watch reported error")
tqdm.write(f"Succesfully downloaded to './logs/sleep/{fi}'")
except Exception as e:
tqdm.write(f"Error happened while downloading {fi}, deleting local incomplete file")
os.system(f"rm ./logs/sleep/{fi}")
if mode == "all" and autoreboot:
tqdm.write("Restarting watch.")
out = subprocess.check_output(shlex.split(reset_cmd))
time.sleep(10)
print("\n\n")

39
external/SleepTk/rm_sleep_data.py vendored Normal file
View file

@ -0,0 +1,39 @@
#!/usr/local/bin/python3
import time
import subprocess
import shlex
import re
from tqdm import tqdm
print("\n\nRunning gc.collect()...")
mem_cmd = './tools/wasptool --verbose --eval \'wasp.gc.collect()\''
subprocess.check_output(shlex.split(mem_cmd))
print("\n\nListing remote files...")
ls_cmd = './tools/wasptool --verbose --eval \'from shell import ls ; ls(\"/flash/logs/sleep/\")\''
out = subprocess.check_output(shlex.split(ls_cmd)).decode()
files = re.findall(r"\d*\.csv", out)
print(f"Found files {', '.join(files)}")
reset_cmd = './tools/wasptool --verbose --reset'
to_rm = files
print("\n\n")
for fi in tqdm(to_rm):
tqdm.write(f"Removing file '{fi}'")
rm_cmd = f'./tools/wasptool --verbose --eval \'from shell import rm ; rm(\"logs/sleep/{fi}\")\''
try:
out = subprocess.check_output(shlex.split(rm_cmd))
if b"Watch reported error" in out:
raise Exception("Watch reported error")
tqdm.write(f"Succesfully removed to './logs/sleep/{fi}'")
except Exception as e:
tqdm.write(f"Error happened while removing {fi}")
tqdm.write("Restarting watch.")
out = subprocess.check_output(shlex.split(reset_cmd))
time.sleep(10)
tqdm.write("\n\n")

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

1
wasp/apps/SleepTk.py Symbolic link
View file

@ -0,0 +1 @@
../../external/SleepTk/SleepTk.py

View file

@ -28,7 +28,6 @@ class FacesApp():
choices.append(('chrono', 'Chrono'))
choices.append(('dual_clock', 'DualClock'))
choices.append(('fibonacci_clock', 'FibonacciClock'))
choices.append(('word_clock', 'WordClock'))
self.choices = choices
self.choice = 0

View file

@ -41,17 +41,14 @@ class SoftwareApp():
db = []
db.append(('alarm', factory('Alarm')))
db.append(('calc', factory('Calculator')))
db.append(('disaBLE', factory('DisaBLE')))
db.append(('faces', factory('Faces')))
db.append(('gallery', factory('Gallery')))
db.append(('musicplayer', factory('Music Player')))
db.append(('play2048', factory('Play 2048')))
db.append(('snake', factory('Snake Game')))
db.append(('sports', factory('Sports')))
db.append(('flashlight', factory('Torch')))
db.append(('testapp', factory('Test')))
db.append(('timer', factory('Timer')))
db.append(('weather', factory('Weather')))
db.append(('SleepTk', factory('SleepTk')))
# Handle user-loaded applications
try:

View file

@ -7,13 +7,10 @@ manifest = (
'apps/calc.py',
'apps/clock.py',
'apps/chrono.py',
'apps/disaBLE.py',
'apps/dual_clock.py',
'apps/faces.py',
'apps/fibonacci_clock.py',
'apps/flashlight.py',
'apps/gallery.py',
'apps/haiku.py',
'apps/heart.py',
'apps/musicplayer.py',
'apps/launcher.py',
@ -21,15 +18,12 @@ manifest = (
'apps/play2048.py',
'apps/settings.py',
'apps/software.py',
'apps/sports.py',
'apps/steps.py',
'apps/stopwatch.py',
'apps/snake.py',
'apps/testapp.py',
'apps/timer.py',
'apps/weather.py',
'apps/week_clock.py',
'apps/word_clock.py',
'apps/SleepTk.py',
'fonts/__init__.py',
'fonts/clock.py',
'fonts/clock_dual.py',

View file

@ -24,7 +24,6 @@ import widgets
from apps.launcher import LauncherApp
from apps.pager import PagerApp, CrashApp, NotificationApp
from apps.steps import StepCounterApp
RAISE_WAKE_Y_SWITCH_THRESHOLD = -1536
RAISE_WAKE_SPEED_MODIFIER = 8
@ -207,12 +206,6 @@ class Manager():
if not app:
return
# "Special case" for watches that have working step counters!
# More usefully it allows other apps to detect the presence/absence
# of a working step counter by looking at wasp.system.steps .
if isinstance(app, StepCounterApp):
self.steps = steplogger.StepLogger(self)
if watch_face:
self.quick_ring[0] = app
elif quick_ring: