Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Proyecto Smart Watch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Leonardo Martinez Hornak
Proyecto Smart Watch
Commits
2a982032
Commit
2a982032
authored
4 years ago
by
Leonardo Martinez Hornak
Browse files
Options
Downloads
Patches
Plain Diff
Chart is being updated every 500 mseconds
parent
98e8fd53
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
software/smartwatch.py
+24
-16
24 additions, 16 deletions
software/smartwatch.py
with
24 additions
and
16 deletions
software/smartwatch.py
+
24
−
16
View file @
2a982032
#Reference for Threading and GUI architecture: https://maldus512.medium.com/how-to-setup-correctly-an-application-with-python-and-tkinter-107c6bc5a45
#Reference for function animate https://towardsdatascience.com/plotting-live-data-with-matplotlib-d871fac7500b
import
queue
import
tkinter
as
tk
import
matplotlib.pyplot
as
plt
...
...
@@ -6,6 +7,7 @@ import numpy as np
from
tkinter
import
TOP
,
BOTH
,
X
,
LEFT
,
RIGHT
from
matplotlib.backends.backend_tkagg
import
FigureCanvasTkAgg
from
matplotlib.animation
import
FuncAnimation
from
types
import
SimpleNamespace
from
enum
import
Enum
from
threading
import
Thread
...
...
@@ -35,7 +37,7 @@ def refreshUI(guiRef, model, guiQueue):
pass
#Other tasks...
print
(
"
Han pasado 500 milisegundos
"
)
#
print("Han pasado 500 milisegundos")
#Class for the User Interface
...
...
@@ -46,7 +48,11 @@ class Application(tk.Frame):
#self.master.geometry('1000x1000')
self
.
master
.
title
(
'
Smart Watch
'
)
self
.
pack
(
fill
=
BOTH
,
expand
=
True
)
#Animate needs to be created here and declared self. If not, will be gargabe collected
self
.
figure
,
self
.
ax
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
6
,
5
))
self
.
create_widgets
()
self
.
animate
=
FuncAnimation
(
self
.
figure
,
self
.
refreshChart
,
interval
=
500
)
def
create_widgets
(
self
):
...
...
@@ -60,20 +66,9 @@ class Application(tk.Frame):
#FRAME 2 - GRAPH
self
.
frame_two
=
tk
.
Frame
(
self
.
master
)
self
.
frame_two
.
pack
(
fill
=
X
)
figure
=
plt
.
Figure
(
figsize
=
(
6
,
5
),
dpi
=
100
)
ax
=
figure
.
add_subplot
(
111
)
chart_type
=
FigureCanvasTkAgg
(
figure
,
self
.
frame_two
)
chart_type
=
FigureCanvasTkAgg
(
self
.
figure
,
self
.
frame_two
)
chart_type
.
get_tk_widget
().
pack
()
x
=
np
.
arange
(
10
)
y
=
2.5
*
np
.
sin
(
x
/
20
*
np
.
pi
)
ax
.
plot
(
x
,
y
,
color
=
'
tab:blue
'
)
ax
.
set_xlim
([
0
,
10
])
ax
.
set_ylim
([
-
1
,
1
])
ax
.
set_title
(
'
PPG - RED
'
)
#FRAME 3
self
.
frame_three
=
tk
.
Frame
(
self
.
master
)
self
.
frame_three
.
pack
(
fill
=
X
)
...
...
@@ -136,7 +131,6 @@ class Application(tk.Frame):
print
(
"
Alarma HR!
"
)
#Method that provides reference to the user interface. It uses a queue to communicate the UI with the exterior. It returns references to
#inner objetcs so the exterior can communicate with it. More references can be given in "SimpleNameSpace"
def
gui_reference
(
self
,
root
,
queue
):
...
...
@@ -152,6 +146,20 @@ class Application(tk.Frame):
entry_two
=
self
.
entry_heartrate_minimum
return
SimpleNamespace
(
entry
=
entry
,
entry_two
=
entry_two
)
#Function used to update the chart with external data. It is called every 500 mseconds. Data needs to be passed by reference using "gui_reference"
def
refreshChart
(
self
,
x
):
#get data
x
=
np
.
arange
(
10
)
y
=
2.5
*
np
.
sin
(
x
/
20
*
np
.
pi
)
self
.
ax
.
plot
(
x
,
y
,
color
=
'
tab:blue
'
)
print
(
"
Chart refreshed
"
)
#set limits and title
self
.
ax
.
set_xlim
([
0
,
10
])
self
.
ax
.
set_ylim
([
-
1
,
1
])
self
.
ax
.
set_title
(
'
PPG - RED
'
)
if
__name__
==
'
__main__
'
:
root
=
tk
.
Tk
()
...
...
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