From c9656885d53c3d7861fa48396fefff4dd8fed04e Mon Sep 17 00:00:00 2001 From: JayPiKay Date: Sun, 19 Jan 2020 13:31:33 +0100 Subject: [PATCH] Initial commit --- src/meter/__init__.py | 0 src/meter/um24c.py | 47 +++++++++++++++++++++ src/um24clab.py | 97 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 src/meter/__init__.py create mode 100644 src/meter/um24c.py create mode 100644 src/um24clab.py diff --git a/src/meter/__init__.py b/src/meter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/meter/um24c.py b/src/meter/um24c.py new file mode 100644 index 0000000..7598ed7 --- /dev/null +++ b/src/meter/um24c.py @@ -0,0 +1,47 @@ +import struct +from collections import namedtuple + + +PACKET_MAGIC = (b'\x09\x63', b'\xff\xf1') +DATA_FORMAT = ">2x2HI2HxB20I2HBx2IHI2x2HIxB2x" + + +UMeterStatus = namedtuple('UMeterStatus', [ + 'Voltage', + 'Current', + 'Power', + 'Temperature_Celcius', + 'Temperature_Fahrenheit', + 'Group', + 'Accumulated_Capacity0', + 'Accumulated_Energy0', + 'Accumulated_Capacity1', + 'Accumulated_Energy1', + 'Accumulated_Capacity2', + 'Accumulated_Energy2', + 'Accumulated_Capacity3', + 'Accumulated_Energy3', + 'Accumulated_Capacity4', + 'Accumulated_Energy4', + 'Accumulated_Capacity5', + 'Accumulated_Energy5', + 'Accumulated_Capacity6', + 'Accumulated_Energy6', + 'Accumulated_Capacity7', + 'Accumulated_Energy7', + 'Accumulated_Capacity8', + 'Accumulated_Energy8', + 'Accumulated_Capacity9', + 'Accumulated_Energy9', + 'D+', + 'D-', + 'Mode', + 'Recorded_Capacity', + 'Recorded_Energy', + 'Current_Trigger', + 'Recorded_Time', + 'Display_timeout', + 'Display_brightness', + 'Load_equivalent_impedance', + 'Current_screen'] +) diff --git a/src/um24clab.py b/src/um24clab.py new file mode 100644 index 0000000..51f3614 --- /dev/null +++ b/src/um24clab.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +import sys +from PyQt5.QtWidgets import ( + QApplication, QWidget, QMainWindow, QLabel, QFrame, QComboBox, QPushButton +) +import PyQt5.QtGui as QtGui +import pyqtgraph as pg + + +class UM24Lab(QMainWindow): + + def __init__(self, screen_width=1280, screen_height=1024): + super().__init__() + self.title = 'UM24C USB Meter Lab' + self.width = 800 + self.height = 600 + self.left = screen_width // 2 - self.width // 2 + self.top = screen_height // 2 - self.height // 2 + self.init_ui() + + def init_ui(self): + """ + Window Layout + +---------+-----------------------+ + |(1) |(3) | + | (1.1) | | + | | PLOTS | + | | | + +---------+ | + |(2) +------+------+---------+ + | |(4) | | | + | | (4.1)| (4.2)|(4.3) | + | | | | | + | | | |---------| + | | | |(4.4) | + | | | | | + +---------+------+------+---------+ + + """ + self.setWindowTitle(self.title) + self.setGeometry(self.left, self.top, self.width, self.height) + self.statusBar().showMessage('Idle') + + centralWidget = QWidget() + centralLayout = QtGui.QHBoxLayout() + centralWidget.setLayout(centralLayout) + + # (1) Device Control + # (1.1) Device Management + deviceWidget = QWidget() + layout = QtGui.QHBoxLayout() + deviceWidget.setLayout(layout) + self.deviceSelect = QComboBox() + layout.addWidget(self.deviceSelect) + # TODO: Populate deviceSelect + self.btnDeviceConnect = QPushButton('Connect') + layout.addWidget(self.btnDeviceConnect) + centralLayout.addWidget(deviceWidget) + + # TODO: Status current page + # TODO: Rotate Screen + # TODO: Next Page + # TODO: Screen Brightness + # TODO: Screen Timeout + + # (2) Group Memory + # TODO: List groups: Capacity (mAh) and Energy (mWh) + + # (3) Plots + plotWidget = QWidget() + layout = QtGui.QHBoxLayout() + plotWidget.setLayout(layout) + self.plotVoltage = pg.PlotWidget() + self.plotCurrent = pg.PlotWidget() + layout.addWidget(self.plotCurrent) + layout.addWidget(self.plotVoltage) + centralLayout.addWidget(plotWidget) + + # (4) Current Measurement + # TODO: (4.1) Voltage, Current, Power, Impedance + # TODO: (4.2) Recorder + # TODO: (4.3) USB D+/D-, Mode + # TODO: (4.4) Temperature (°C, °F) + + self.setCentralWidget(centralWidget) + self.show() + + def slot_connect_device(self): + self.statusBar().showMessage('Connecting...') + # TODO: connect to UM24C + + +if __name__ == '__main__': + app = QApplication(sys.argv) + screen_resolution = app.desktop().screenGeometry() + labview = UM24Lab(screen_resolution.width(), screen_resolution.height()) + sys.exit(app.exec_())