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

replace 'histogram' by 'graph' as it is not a histogram

parent acb6085c
No related branches found
No related tags found
No related merge requests found
...@@ -32,8 +32,8 @@ filebuffer = bytearray() ...@@ -32,8 +32,8 @@ filebuffer = bytearray()
write = 0 write = 0
update_screen = 0 update_screen = 0
pause_screen = 0 pause_screen = 0
pause_histogram = False pause_graph = False
histogram_offset = 0 graph_offset = 0
sensor = 0 sensor = 0
disp = display.open() disp = display.open()
last_sample_count = 1 last_sample_count = 1
...@@ -127,8 +127,8 @@ def callback_ecg(datasets): ...@@ -127,8 +127,8 @@ def callback_ecg(datasets):
global update_screen, history, filebuffer, write global update_screen, history, filebuffer, write
update_screen += len(datasets) update_screen += len(datasets)
# update histogram datalist # update graph datalist
if not pause_histogram: if not pause_graph:
update_history(datasets) update_history(datasets)
detect_pulse(len(datasets)) detect_pulse(len(datasets))
...@@ -141,7 +141,7 @@ def callback_ecg(datasets): ...@@ -141,7 +141,7 @@ def callback_ecg(datasets):
# don't update on every callback # don't update on every callback
if update_screen >= DRAW_AFTER_SAMPLES: if update_screen >= DRAW_AFTER_SAMPLES:
draw_histogram() draw_graph()
def append_to_file(fileprefix, content): def append_to_file(fileprefix, content):
...@@ -221,13 +221,13 @@ def toggle_write(): ...@@ -221,13 +221,13 @@ def toggle_write():
def toggle_pause(): def toggle_pause():
global pause_histogram, histogram_offset, history, leds global pause_graph, graph_offset, history, leds
if pause_histogram: if pause_graph:
pause_histogram = False pause_graph = False
history = [] history = []
else: else:
pause_histogram = True pause_graph = True
histogram_offset = 0 graph_offset = 0
leds.clear() leds.clear()
...@@ -269,7 +269,7 @@ def draw_leds(vmin, vmax): ...@@ -269,7 +269,7 @@ def draw_leds(vmin, vmax):
leds.update() leds.update()
def draw_histogram(): def draw_graph():
global disp, history, write, pause_screen, update_screen global disp, history, write, pause_screen, update_screen
# skip rendering due to message beeing shown # skip rendering due to message beeing shown
...@@ -284,9 +284,9 @@ def draw_histogram(): ...@@ -284,9 +284,9 @@ def draw_histogram():
disp.clear(COLOR_BACKGROUND) disp.clear(COLOR_BACKGROUND)
# offset in pause_histogram mode # offset in pause_graph mode
timeWindow = config.get_option("Window") timeWindow = config.get_option("Window")
window_end = int(len(history) - histogram_offset) window_end = int(len(history) - graph_offset)
s_end = max(0, window_end) s_end = max(0, window_end)
s_start = max(0, s_end - WIDTH * timeWindow) s_start = max(0, s_end - WIDTH * timeWindow)
...@@ -294,7 +294,7 @@ def draw_histogram(): ...@@ -294,7 +294,7 @@ def draw_histogram():
value_max = max(abs(x) for x in history[s_start:s_end]) value_max = max(abs(x) for x in history[s_start:s_end])
scale = SCALE_FACTOR / (value_max if value_max > 0 else 1) scale = SCALE_FACTOR / (value_max if value_max > 0 else 1)
# draw histogram # draw graph
# values need to be inverted so high values are drawn with low pixel coordinates (at the top of the screen) # values need to be inverted so high values are drawn with low pixel coordinates (at the top of the screen)
draw_points = (int(-x * scale + OFFSET_Y) for x in history[s_start:s_end]) draw_points = (int(-x * scale + OFFSET_Y) for x in history[s_start:s_end])
...@@ -304,12 +304,12 @@ def draw_histogram(): ...@@ -304,12 +304,12 @@ def draw_histogram():
prev = value prev = value
# draw text: mode/bias/write # draw text: mode/bias/write
if pause_histogram: if pause_graph:
disp.print( disp.print(
"Pause" "Pause"
+ ( + (
" -{:0.1f}s".format(histogram_offset / config.get_option("Rate")) " -{:0.1f}s".format(graph_offset / config.get_option("Rate"))
if histogram_offset > 0 if graph_offset > 0
else "" else ""
), ),
posx=0, posx=0,
...@@ -356,7 +356,7 @@ def draw_histogram(): ...@@ -356,7 +356,7 @@ def draw_histogram():
def main(): def main():
global pause_histogram, histogram_offset, pause_screen global pause_graph, graph_offset, pause_screen
# show button layout # show button layout
disp.clear(COLOR_BACKGROUND) disp.clear(COLOR_BACKGROUND)
...@@ -404,11 +404,11 @@ def main(): ...@@ -404,11 +404,11 @@ def main():
# down # down
if button_pressed["BOTTOM_LEFT"] == 0 and v & buttons.BOTTOM_LEFT != 0: if button_pressed["BOTTOM_LEFT"] == 0 and v & buttons.BOTTOM_LEFT != 0:
button_pressed["BOTTOM_LEFT"] = 1 button_pressed["BOTTOM_LEFT"] = 1
if pause_histogram: if pause_graph:
l = len(history) l = len(history)
histogram_offset += config.get_option("Rate") / 2 graph_offset += config.get_option("Rate") / 2
if l - histogram_offset < WIDTH * config.get_option("Window"): if l - graph_offset < WIDTH * config.get_option("Window"):
histogram_offset = l - WIDTH * config.get_option("Window") graph_offset = l - WIDTH * config.get_option("Window")
else: else:
toggle_write() toggle_write()
...@@ -424,13 +424,13 @@ def main(): ...@@ -424,13 +424,13 @@ def main():
# down # down
if button_pressed["BOTTOM_RIGHT"] == 0 and v & buttons.BOTTOM_RIGHT != 0: if button_pressed["BOTTOM_RIGHT"] == 0 and v & buttons.BOTTOM_RIGHT != 0:
button_pressed["BOTTOM_RIGHT"] = 1 button_pressed["BOTTOM_RIGHT"] = 1
if pause_histogram: if pause_graph:
histogram_offset -= config.get_option("Rate") / 2 graph_offset -= config.get_option("Rate") / 2
histogram_offset -= histogram_offset % ( graph_offset -= graph_offset % (
config.get_option("Rate") / 2 config.get_option("Rate") / 2
) )
if histogram_offset < 0: if graph_offset < 0:
histogram_offset = 0 graph_offset = 0
else: else:
pause_screen = -1 # hide graph pause_screen = -1 # hide graph
leds.clear() # disable all LEDs leds.clear() # disable all LEDs
......
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