Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Add some status messages to statusbar
Browse files Browse the repository at this point in the history
  • Loading branch information
ijager committed Nov 21, 2019
1 parent 3f5ba0d commit e86e679
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
12 changes: 11 additions & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from comports import SerialConnection, SerialParser
from analysis import KeyPress

import status

FPS = 20


Expand Down Expand Up @@ -47,9 +49,15 @@ def __init__(self):
self.parser.newDataSet.connect(lambda i, t, p: self.mainView.resultsView.new_results(KeyPress(i, t,p)))
self.parser.newDataSet.connect(lambda i, t, p: self.mainView.textOutputView.new_results(KeyPress(i, t,p)))

status.set_status_logger(self.set_status_message)
status.set_status('Force Sensor Ready..')

def quit(self):
self.mainView.textOutputView.quit()

def set_status_message(self, msg: str):
self.window.statusBar().showMessage(msg)


class MainWindow(QtWidgets.QMainWindow):
"""
Expand Down Expand Up @@ -79,7 +87,9 @@ def _setupView(self):
self.setWindowIcon(QtGui.QIcon('assets/icon.jpeg'))
self.setGeometry(50, 50, 1600, 900)
# set_background_color(self, '#5a5d73')
set_background_color(self, 'gray')
# set_background_color(self, 'gray')

self.statusBar().showMessage('')

self._center()
self.raise_()
Expand Down
4 changes: 3 additions & 1 deletion app/comports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from serial.tools import hexlify_codec

import status

codecs.register(lambda c: hexlify_codec.getregentry() if c == 'hexlify' else None)

BAUDRATE = 57600
Expand Down Expand Up @@ -54,7 +56,6 @@ def refresh(self):
self.dropdown.clear()
self.dropdown.addItem('--- Select COM Port ---')
self.dropdown.addItems([p.device for p in self.availablePorts])
# self.newCOMPorts.emit([p.device for p in self.availablePorts])

def change_port(self, port: serial.Serial):

Expand All @@ -63,6 +64,7 @@ def change_port(self, port: serial.Serial):
self._stop_reader()
self.serial = serial.Serial(port.device, BAUDRATE, timeout=10)
print('open port: ', self.serial, self.serial.port)
status.set_status('open port: {}'.format(self.serial.port))
self._start_reader()


Expand Down
4 changes: 4 additions & 0 deletions app/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import typing
from pathlib import Path

import status

LogHandle = typing.NamedTuple('loghandle', [('file', typing.TextIO), ('writer', csv.writer)])

def start_new_session(directory, file_prefix: str, csv: bool):
Expand Down Expand Up @@ -59,6 +61,7 @@ def start_new_session(directory, file_prefix: str, csv: bool):
csvfile = open(str(fname), 'w', newline='')
writer = csv.writer(csvfile, delimiter=',') if csv else None
print('starting new logging session with file:', str(fname))
status.set_status('starting new logging session with file: {}'.format(str(fname)))
return LogHandle(file=csvfile, writer=writer)
except Exception as e:
print('error opening file: \n', e)
Expand Down Expand Up @@ -107,4 +110,5 @@ def close_session(handle: LogHandle):
"""
if handle and handle.file:
print('closing logging session for file:', handle.file.name)
status.set_status('close logging session with file: {}'.format(handle.file.name))
handle.file.close()
16 changes: 14 additions & 2 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def __init__(self):
# self.plot.update_plot(range(5))

# self.setStyleSheet("font-weight: bold; font-size: {}px".format(24))
self.forceResult = QtWidgets.QLabel('3.5 N')
self.accelResult = QtWidgets.QLabel('20 mm/s^2')
self.forceResult = QtWidgets.QLabel('- N')
self.accelResult = QtWidgets.QLabel('- mm/s^2')
self.encoder = QtWidgets.QLabel('-')
self.risetimeResult = QtWidgets.QLabel('- s')

Expand Down Expand Up @@ -165,18 +165,30 @@ def clear(self):
self.ax.clear()

def show_speed(self, k: KeyPress):

if not k:
return

self.clear()
t, speed, speed_fitted = k.speed_data()
self.plot(t, speed, speed_fitted, title='Speed vs time', xlabel='Time [ms]', ylabel='Speed [mm/s]')


def show_accel(self, k: KeyPress):

if not k:
return

self.clear()
t, accel, accel_fitted = k.accel_data()
self.plot(t, accel, accel_fitted, title='Acceleration vs time', xlabel='Time [ms]', ylabel='Speed [mm/s^2]', plot_z_average=True)


def show_position(self, k: KeyPress):

if not k:
return

self.clear()

t = k.timestamps
Expand Down

0 comments on commit e86e679

Please sign in to comment.