Skip to content
Snippets Groups Projects
Commit d3a2a1df authored by fuchsi*'s avatar fuchsi* Committed by rahix
Browse files

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
...@@ -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 writeing logfile") print("Unexpected error, stop writing logfile")
write = 0 write = 0
filebuffer = bytearray() filebuffer = bytearray()
......
...@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment