Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fleur
firmware
Commits
d3a2a1df
Commit
d3a2a1df
authored
5 years ago
by
fuchsi*
Committed by
rahix
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
offer the option to log the pulse in a separate file
parent
c5067970
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
preload/apps/ecg/__init__.py
+31
-4
31 additions, 4 deletions
preload/apps/ecg/__init__.py
preload/apps/ecg/settings.py
+9
-1
9 additions, 1 deletion
preload/apps/ecg/settings.py
with
40 additions
and
5 deletions
preload/apps/ecg/__init__.py
+
31
−
4
View file @
d3a2a1df
...
@@ -113,6 +113,8 @@ def detect_pulse(num_new_samples):
...
@@ -113,6 +113,8 @@ def detect_pulse(num_new_samples):
q_spike
=
-
ecg_rate
q_spike
=
-
ecg_rate
if
pulse
<
30
or
pulse
>
210
:
if
pulse
<
30
or
pulse
>
210
:
pulse
=
-
1
pulse
=
-
1
elif
write
>
0
and
"
pulse
"
in
config
.
get_option
(
"
Log
"
):
write_pulse
()
# we expect the next r-spike to be at least 60% as high as this one
# we expect the next r-spike to be at least 60% as high as this one
r_threshold
=
(
cur
*
3
)
//
5
r_threshold
=
(
cur
*
3
)
//
5
elif
samples_since_last_pulse
>
2
*
ecg_rate
:
elif
samples_since_last_pulse
>
2
*
ecg_rate
:
...
@@ -131,7 +133,7 @@ def callback_ecg(datasets):
...
@@ -131,7 +133,7 @@ def callback_ecg(datasets):
detect_pulse
(
len
(
datasets
))
detect_pulse
(
len
(
datasets
))
# buffer for writes
# buffer for writes
if
write
>
0
:
if
write
>
0
and
"
graph
"
in
config
.
get_option
(
"
Log
"
)
:
for
value
in
datasets
:
for
value
in
datasets
:
filebuffer
.
extend
(
struct
.
pack
(
"
h
"
,
value
))
filebuffer
.
extend
(
struct
.
pack
(
"
h
"
,
value
))
if
len
(
filebuffer
)
>=
FILEBUFFERBLOCK
:
if
len
(
filebuffer
)
>=
FILEBUFFERBLOCK
:
...
@@ -141,11 +143,36 @@ def callback_ecg(datasets):
...
@@ -141,11 +143,36 @@ def callback_ecg(datasets):
if
update_screen
>=
DRAW_AFTER_SAMPLES
:
if
update_screen
>=
DRAW_AFTER_SAMPLES
:
draw_histogram
()
draw_histogram
()
def
write_pulse
():
global
write
,
pause_screen
# write to file
lt
=
utime
.
localtime
(
write
)
filename
=
"
/pulse-{:04d}-{:02d}-{:02d}_{:02d}{:02d}{:02d}.log
"
.
format
(
*
lt
)
# write stuff to disk
try
:
f
=
open
(
filename
,
"
ab
"
)
print
(
utime
.
time
(),
pulse
)
f
.
write
(
struct
.
pack
(
"
h
"
,
utime
.
time
(),
pulse
))
f
.
close
()
except
OSError
as
e
:
print
(
"
Please check the file or filesystem
"
,
e
)
write
=
0
pause_screen
=
-
1
disp
.
clear
(
COLOR_BACKGROUND
)
disp
.
print
(
"
IO Error
"
,
posy
=
0
,
fg
=
COLOR_TEXT
)
disp
.
print
(
"
Please check
"
,
posy
=
20
,
fg
=
COLOR_TEXT
)
disp
.
print
(
"
your
"
,
posy
=
40
,
fg
=
COLOR_TEXT
)
disp
.
print
(
"
filesystem
"
,
posy
=
60
,
fg
=
COLOR_TEXT
)
disp
.
update
()
close_sensor
()
except
:
print
(
"
Unexpected error, stop writing logfile
"
)
write
=
0
def
write_filebuffer
():
def
write_filebuffer
():
global
write
,
filebuffer
global
write
,
filebuffer
,
pause_screen
# write to file
# write to file
chars
=
""
lt
=
utime
.
localtime
(
write
)
lt
=
utime
.
localtime
(
write
)
filename
=
"
/ecg-{:04d}-{:02d}-{:02d}_{:02d}{:02d}{:02d}.log
"
.
format
(
*
lt
)
filename
=
"
/ecg-{:04d}-{:02d}-{:02d}_{:02d}{:02d}{:02d}.log
"
.
format
(
*
lt
)
...
@@ -166,7 +193,7 @@ def write_filebuffer():
...
@@ -166,7 +193,7 @@ def write_filebuffer():
disp
.
update
()
disp
.
update
()
close_sensor
()
close_sensor
()
except
:
except
:
print
(
"
Unexpected error, stop writ
e
ing logfile
"
)
print
(
"
Unexpected error, stop writing logfile
"
)
write
=
0
write
=
0
filebuffer
=
bytearray
()
filebuffer
=
bytearray
()
...
...
This diff is collapsed.
Click to expand it.
preload/apps/ecg/settings.py
+
9
−
1
View file @
d3a2a1df
...
@@ -19,7 +19,6 @@ class Settings(simple_menu.Menu):
...
@@ -19,7 +19,6 @@ class Settings(simple_menu.Menu):
self
.
options
[
value
[
0
]]
=
next
(
value
[
1
])
self
.
options
[
value
[
0
]]
=
next
(
value
[
1
])
def
entry2name
(
self
,
value
):
def
entry2name
(
self
,
value
):
print
(
value
,
value
[
0
])
if
value
[
0
]
==
"
return
"
:
if
value
[
0
]
==
"
return
"
:
return
value
[
0
]
return
value
[
0
]
else
:
else
:
...
@@ -86,5 +85,14 @@ def ecg_settings():
...
@@ -86,5 +85,14 @@ def ecg_settings():
]
]
)
)
))
))
config
.
add_option
((
"
Log
"
,
itertools
.
cycle
(
[
(
"
full
"
,
{
"
graph
"
,
"
pulse
"
}),
(
"
graph
"
,
{
"
graph
"
}),
(
"
pulse
"
,
{
"
pulse
"
}),
]
)
))
return
config
return
config
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment