Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uScope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
BSS_development
Neuro
uScope
Commits
fc5f8b68
Commit
fc5f8b68
authored
4 years ago
by
Roberto-R
Browse files
Options
Downloads
Patches
Plain Diff
Improved typing and documentation
parent
897e4bec
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
plot_decoder/plot_decoder.py
+6
-8
6 additions, 8 deletions
plot_decoder/plot_decoder.py
ui/combo_box.py
+2
-2
2 additions, 2 deletions
ui/combo_box.py
ui/main_window.py
+14
-13
14 additions, 13 deletions
ui/main_window.py
with
22 additions
and
23 deletions
plot_decoder/plot_decoder.py
+
6
−
8
View file @
fc5f8b68
...
...
@@ -10,8 +10,7 @@ class Mode(Enum):
class
PlotDecoder
:
"""
Class to decode the BioRobotics plot protocol
"""
Class to decode the BioRobotics plot protocol.
The serial protocol is as follows:
...
...
@@ -22,7 +21,7 @@ class PlotDecoder:
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
"""
Constructor
"""
"""
Constructor
.
"""
self
.
header_bytes
=
[
b
'
\x7f
'
,
b
'
\xff
'
,
b
'
\xbf
'
]
self
.
buffer
=
bytearray
()
# Store bytes while receiving
...
...
@@ -33,8 +32,8 @@ class PlotDecoder:
self
.
time
=
0
# Read microtime
self
.
data
=
[]
# Received floats
def
set_state
(
self
,
new_mode
):
"""
Simple wrapper to change mode
"""
def
set_state
(
self
,
new_mode
:
Mode
):
"""
Simple wrapper to change mode
.
"""
self
.
mode
=
new_mode
self
.
bytes_count
=
0
...
...
@@ -43,9 +42,8 @@ class PlotDecoder:
if
new_mode
==
Mode
.
DATA
:
self
.
data
=
[]
def
receive_byte
(
self
,
byte
):
"""
Precess new incoming byte
def
receive_byte
(
self
,
byte
:
bytearray
)
->
bool
:
"""
Precess new incoming byte.
Return true when a complete package was received
"""
...
...
This diff is collapsed.
Click to expand it.
ui/combo_box.py
+
2
−
2
View file @
fc5f8b68
...
...
@@ -3,11 +3,11 @@ from PyQt5.QtCore import pyqtSignal
class
ComboBox
(
QComboBox
):
"""
Extend QComboBox widget to handle click event
"""
"""
Extend QComboBox widget to handle click event
.
"""
popupAboutToBeShown
=
pyqtSignal
()
def
showPopup
(
self
):
"""
Fire event first, then call parent popup method
"""
"""
Fire event first, then call parent popup method
.
"""
self
.
popupAboutToBeShown
.
emit
()
super
().
showPopup
()
This diff is collapsed.
Click to expand it.
ui/main_window.py
+
14
−
13
View file @
fc5f8b68
from
PyQt5.QtWidgets
import
QWidget
,
QMainWindow
,
QLabel
,
QCheckBox
,
\
QLineEdit
,
QPushButton
,
QMenu
,
QAction
,
QMessageBox
,
QFileDialog
,
\
QVBoxLayout
,
QHBoxLayout
,
QFormLayout
from
PyQt5.QtGui
import
QIntValidator
,
QDoubleValidator
,
QIcon
from
PyQt5.QtGui
import
QIntValidator
,
QDoubleValidator
,
QIcon
,
QCloseEvent
from
PyQt5.QtCore
import
pyqtSlot
from
PyQt5.QtSerialPort
import
QSerialPort
,
QSerialPortInfo
import
pyqtgraph
as
pg
...
...
@@ -9,6 +9,7 @@ import numpy as np
import
json
import
os
import
time
from
typing
import
Optional
,
List
from
plot_decoder.plot_decoder
import
PlotDecoder
from
ui.combo_box
import
ComboBox
...
...
@@ -45,8 +46,8 @@ class MainWindow(QMainWindow):
# Prepare data structure
self
.
channels
=
0
# Wait for serial data, resize on the fly
self
.
data
=
None
# Received data, each row is a channel
self
.
time
=
None
# Timestamps of each data column
self
.
data
:
Optional
[
np
.
array
]
=
None
# Received data, each row is a channel
self
.
time
:
Optional
[
np
.
array
]
=
None
# Timestamps of each data column
self
.
data_points
=
0
# Number of points recorded
self
.
data_size
=
200
# Number of points in history
self
.
time_offset
=
None
# Time offset in microseconds
...
...
@@ -56,7 +57,7 @@ class MainWindow(QMainWindow):
self
.
y_scale
=
[
-
10.0
,
10.0
]
# Y-scale values when not automatic
# The system time of the last frame update - Used to limit framerate
self
.
last_update
=
0
self
.
last_update
=
0
.0
# Create property stubs
self
.
input_port
=
ComboBox
()
...
...
@@ -72,8 +73,8 @@ class MainWindow(QMainWindow):
self
.
layout_plots
=
pg
.
GraphicsLayoutWidget
()
self
.
button_save
=
QPushButton
(
'
Save
'
)
self
.
plots
=
[]
# Start with empty plots
self
.
curves
=
[]
self
.
plots
:
List
[
pg
.
PlotItem
]
=
[]
# Start with empty plots
self
.
curves
:
List
[
pg
.
PlotDataItem
]
=
[]
self
.
build_ui_elements
()
# Put actual GUI together
...
...
@@ -158,7 +159,7 @@ class MainWindow(QMainWindow):
self
.
setCentralWidget
(
main_widget
)
@pyqtSlot
(
bool
)
def
on_connect_toggle
(
self
,
checked
):
def
on_connect_toggle
(
self
,
checked
:
bool
):
"""
When the serial `connect` button is pressed
"""
self
.
button_port
.
setText
(
'
Disconnect
'
if
checked
else
'
Connect
'
)
...
...
@@ -189,7 +190,7 @@ class MainWindow(QMainWindow):
self
.
input_autoscale
.
setDisabled
(
False
)
@pyqtSlot
(
bool
)
def
on_autoscale_toggle
(
self
,
checked
):
def
on_autoscale_toggle
(
self
,
checked
:
bool
):
"""
Callback for the autoscale checkbox
"""
# Enable/disable manual scales
...
...
@@ -213,10 +214,10 @@ class MainWindow(QMainWindow):
self
.
decoder
.
data
)
@pyqtSlot
(
QAction
)
def
on_save
(
self
,
action
):
def
on_save
(
self
,
action
:
QAction
):
self
.
save_data
(
action
.
text
())
def
save_data
(
self
,
file_format
):
def
save_data
(
self
,
file_format
:
str
):
"""
Save data, file_format is either `csv` or `numpy`
"""
file_format
=
file_format
.
lower
()
...
...
@@ -288,7 +289,7 @@ class MainWindow(QMainWindow):
with
open
(
'
settings.json
'
,
'
w
'
)
as
file
:
file
.
write
(
json
.
dumps
(
settings
))
def
closeEvent
(
self
,
event
):
def
closeEvent
(
self
,
event
:
QCloseEvent
):
"""
When main window is closed
"""
self
.
serial
.
close
()
self
.
save_settings
()
...
...
@@ -322,7 +323,7 @@ class MainWindow(QMainWindow):
self
.
serial
.
clear
()
# Get rid of data in buffer
def
update_data
(
self
,
channels
,
micros
,
new_data
):
def
update_data
(
self
,
channels
:
int
,
micros
:
int
,
new_data
:
list
):
"""
Called when new row was received
"""
if
self
.
channels
!=
channels
:
...
...
@@ -359,7 +360,7 @@ class MainWindow(QMainWindow):
for
i
,
curve
in
enumerate
(
self
.
curves
):
curve
.
setData
(
x
=
data_x
[
0
,
:],
y
=
data_y
[
i
,
:])
def
set_channels
(
self
,
channels
):
def
set_channels
(
self
,
channels
:
int
):
"""
Resize number of channels
...
...
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