Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HEV - High Energy Ventilator
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Projects
HEV - High Energy Ventilator
Commits
e52631ae
Commit
e52631ae
authored
4 years ago
by
Karol Hennessy
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://gitlab.cern.ch:8443/hev-sw/hev-sw
parents
1a39409a
a51387dc
Branches
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
raspberry-backend/app.py
+45
-0
45 additions, 0 deletions
raspberry-backend/app.py
raspberry-backend/static/js/Chart-display.js
+1
-3
1 addition, 3 deletions
raspberry-backend/static/js/Chart-display.js
raspberry-backend/templates/base.html
+34
-31
34 additions, 31 deletions
raspberry-backend/templates/base.html
with
80 additions
and
34 deletions
raspberry-backend/app.py
+
45
−
0
View file @
e52631ae
...
...
@@ -23,6 +23,30 @@ import sqlite3
from
datetime
import
datetime
import
threading
readBattery
=
True
pin_bat
=
5
pin_ok
=
6
pin_alarm
=
12
pin_rdy2buf
=
13
pin_bat85
=
19
try
:
import
RPi.GPIO
as
gpio
gpio
.
setmode
(
gpio
.
BCM
)
gpio
.
setup
(
pin_bat
,
gpio
.
IN
)
gpio
.
setup
(
pin_ok
,
gpio
.
IN
)
gpio
.
setup
(
pin_alarm
,
gpio
.
IN
)
gpio
.
setup
(
pin_rdy2buf
,
gpio
.
IN
)
gpio
.
setup
(
pin_bat85
,
gpio
.
IN
)
except
ImportError
:
print
(
"
No Raspberry Pi GPIO Module, battery information won
'
t be reliable
"
)
readBattery
=
False
#SQLITE_FILE = 'database/HEV_monitoringDB.sqlite' # name of the sqlite database file
#SQLITE_FILE = 'hev::memory:?cache=shared'
SQLITE_FILE
=
'
file:hev?mode=memory&cache=shared
'
...
...
@@ -276,6 +300,27 @@ def live_data():
response
.
content_type
=
'
application/json
'
return
response
@WEBAPP.route
(
'
/battery
'
,
methods
=
[
'
GET
'
])
def
live_battery
():
"""
Get battery info
Output in json format
"""
battery
=
{
'
bat
'
:
0
,
'
ok
'
:
0
,
'
alarm
'
:
0
,
'
rdy2buf
'
:
0
,
'
bat85
'
:
0
}
if
readBattery
:
battery
=
{
'
bat
'
:
gpio
.
input
(
pin_bat
)
,
'
ok
'
:
gpio
.
input
(
pin_ok
)
,
'
alarm
'
:
gpio
.
input
(
pin_alarm
)
,
'
rdy2buf
'
:
gpio
.
input
(
pin_rdy2buf
)
,
'
bat85
'
:
gpio
.
input
(
pin_bat85
)
}
response
=
make_response
(
json
.
dumps
(
battery
).
encode
(
'
utf-8
'
)
)
response
.
content_type
=
'
application/json
'
return
response
@WEBAPP.route
(
'
/last-data
'
,
methods
=
[
'
GET
'
])
def
last_data
():
"""
...
...
This diff is collapsed.
Click to expand it.
raspberry-backend/static/js/Chart-display.js
+
1
−
3
View file @
e52631ae
...
...
@@ -35,9 +35,7 @@ function init_results(){
var
initial_yaxis_flow
=
[];
var
initial_yaxis_pressure
=
[];
var
initial_yaxis_volume
=
[];
console
.
log
(
"
Getting initial results
"
);
for
(
let
i
=
Math
.
min
(
data
.
length
,
1000
)
-
1
;
i
>=
0
;
i
--
)
{
console
.
log
(
i
,
data
[
i
][
"
timestamp
"
]);
var
seconds
=
data
[
i
][
"
timestamp
"
]
/
1000
;
if
(
seconds
==
""
)
continue
;
if
(
seconds
<=
timestamp
)
continue
;
...
...
@@ -447,7 +445,7 @@ function create_gauge_chart(var_name) {
},
options
:
{
maintainAspectRatio
:
tru
e
,
maintainAspectRatio
:
fals
e
,
events
:
[]
}
});
...
...
This diff is collapsed.
Click to expand it.
raspberry-backend/templates/base.html
+
34
−
31
View file @
e52631ae
...
...
@@ -18,7 +18,6 @@
<script
src=
"{{ url_for('static', filename='js/easy-numpad.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/pickout.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/notifications.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/scripts.js') }}"
></script>
<link
rel=
"apple-touch-icon"
sizes=
"180x180"
href=
"{{ url_for('static', filename='img/apple-touch-icon.png') }}"
>
<link
rel=
"icon"
type=
"image/png"
sizes=
"32x32"
href=
"{{ url_for('static', filename='img/favicon-32x32.png') }}"
>
<link
rel=
"icon"
type=
"image/png"
sizes=
"16x16"
href=
"{{ url_for('static', filename='img/favicon-16x16.png') }}"
>
...
...
@@ -128,7 +127,7 @@
<script
src=
"{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/dataTables.bootstrap4.min.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/scripts.js') }}"
></script>
{% block body_scripts %}
{% endblock %}
<script>
...
...
@@ -140,8 +139,8 @@
var
idleTimer
;
var
unlocked
=
Boolean
(
false
);
if
(
sessionStorage
.
getItem
(
"
unlocked
"
)
!=
null
){
if
(
sessionStorage
.
getItem
(
"
unlocked
"
)
==
true
){
console
.
log
(
"
storage item has unlocked = true
"
);
unlocked
=
Boolean
(
true
);}
else
{
unlocked
=
Boolean
(
false
);
console
.
log
(
"
storage item has unlocked is false
"
);
}
if
(
sessionStorage
.
getItem
(
"
unlocked
"
)
==
true
){
unlocked
=
Boolean
(
true
);}
else
{
unlocked
=
Boolean
(
false
);}
}
//our default is locked, but if we load and the unlock is set, unlock page
...
...
@@ -302,34 +301,38 @@
});
var
battery
=
200
;
function
update_battery
()
{
// set all transparent
var
powered
=
document
.
getElementById
(
"
powered
"
);
powered
.
classList
.
add
(
"
transparent
"
);
var
full
=
document
.
getElementById
(
"
battery-full
"
);
full
.
classList
.
add
(
"
transparent
"
);
three_qtr
=
document
.
getElementById
(
"
battery-three-quarter
"
);
three_qtr
.
classList
.
add
(
"
transparent
"
);
var
half
=
document
.
getElementById
(
"
battery-half
"
);
half
.
classList
.
add
(
"
transparent
"
);
var
one_qtr
=
document
.
getElementById
(
"
battery-one-quarter
"
);
one_qtr
.
classList
.
add
(
"
transparent
"
);
var
empty
=
document
.
getElementById
(
"
battery-empty
"
);
empty
.
classList
.
add
(
"
transparent
"
);
function
update_battery
()
{
$
.
ajax
({
url
:
'
/battery
'
,
success
:
function
(
point
)
{
// set all transparent
var
powered
=
document
.
getElementById
(
"
powered
"
);
powered
.
classList
.
add
(
"
transparent
"
);
var
full
=
document
.
getElementById
(
"
battery-full
"
);
full
.
classList
.
add
(
"
transparent
"
);
three_qtr
=
document
.
getElementById
(
"
battery-three-quarter
"
);
three_qtr
.
classList
.
add
(
"
transparent
"
);
var
half
=
document
.
getElementById
(
"
battery-half
"
);
half
.
classList
.
add
(
"
transparent
"
);
var
one_qtr
=
document
.
getElementById
(
"
battery-one-quarter
"
);
one_qtr
.
classList
.
add
(
"
transparent
"
);
var
empty
=
document
.
getElementById
(
"
battery-empty
"
);
empty
.
classList
.
add
(
"
transparent
"
);
// find the one to show
if
(
battery
>
100.0
)
{
powered
.
classList
.
remove
(
"
transparent
"
);
}
else
if
(
battery
>=
87.5
&&
battery
<=
100.0
)
{
full
.
classList
.
remove
(
"
transparent
"
);}
else
if
(
battery
>=
67.5
&&
battery
<
87.5
)
{
three_qtr
.
classList
.
remove
(
"
transparent
"
);
}
else
if
(
battery
>=
37.5
&&
battery
<
67.5
)
{
half
.
classList
.
remove
(
"
transparent
"
);
}
else
if
(
battery
>=
7.5
&&
battery
<
37.5
)
{
one_qtr
.
classList
.
remove
(
"
transparent
"
);
}
else
{
empty
.
classList
.
remove
(
"
transparent
"
);
}
battery
=
battery
-
1
;
if
(
battery
<=
0
)
battery
=
200
;
}
var
batteryInterval
=
setInterval
(
'
update_battery()
'
,
1000
);
var
prev_val
;
// find the one to show
if
(
point
[
'
ok
'
])
{
powered
.
classList
.
remove
(
"
transparent
"
);
}
else
if
(
point
[
"
bat
"
]
&&
point
[
"
bat85
"
]
)
{
full
.
classList
.
remove
(
"
transparent
"
);}
else
if
(
point
[
"
bat
"
]
)
{
three_qtr
.
classList
.
remove
(
"
transparent
"
);
}
//else if (battery >= 37.5 && battery
<
67.5
)
{
half
.
classList
.
remove
(
"
transparent
"
);
}
//else if (battery >= 7.5 && battery
<
37.5
)
{
one_qtr
.
classList
.
remove
(
"
transparent
"
);
}
else
{
empty
.
classList
.
remove
(
"
transparent
"
);
}
}
})
}
update_battery
();
var
batteryInterval
=
setInterval
(
'
update_battery()
'
,
1000
);
var
prev_val
;
$
(
'
.input-editable
'
).
focus
(
function
()
{
prev_val
=
$
(
this
).
val
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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