parent
73385bb33e
commit
0e5de107ce
@ -0,0 +1,109 @@ |
||||
# Created by .ignore support plugin (hsz.mobi) |
||||
### Python template |
||||
# Byte-compiled / optimized / DLL files |
||||
__pycache__/ |
||||
*.py[cod] |
||||
*$py.class |
||||
|
||||
.idea/ |
||||
|
||||
# C extensions |
||||
*.so |
||||
|
||||
# Distribution / packaging |
||||
.Python |
||||
build/ |
||||
develop-eggs/ |
||||
dist/ |
||||
downloads/ |
||||
eggs/ |
||||
.eggs/ |
||||
lib/ |
||||
lib64/ |
||||
parts/ |
||||
sdist/ |
||||
var/ |
||||
wheels/ |
||||
*.egg-info/ |
||||
.installed.cfg |
||||
*.egg |
||||
MANIFEST |
||||
|
||||
# PyInstaller |
||||
# Usually these files are written by a python script from a template |
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it. |
||||
*.manifest |
||||
*.spec |
||||
|
||||
# Installer logs |
||||
pip-log.txt |
||||
pip-delete-this-directory.txt |
||||
|
||||
# Unit test / coverage reports |
||||
htmlcov/ |
||||
.tox/ |
||||
.coverage |
||||
.coverage.* |
||||
.cache |
||||
nosetests.xml |
||||
coverage.xml |
||||
*.cover |
||||
.hypothesis/ |
||||
.pytest_cache/ |
||||
|
||||
# Translations |
||||
*.mo |
||||
*.pot |
||||
|
||||
# Django stuff: |
||||
*.log |
||||
local_settings.py |
||||
db.sqlite3 |
||||
|
||||
# Flask stuff: |
||||
instance/ |
||||
.webassets-cache |
||||
|
||||
# Scrapy stuff: |
||||
.scrapy |
||||
|
||||
# Sphinx documentation |
||||
docs/_build/ |
||||
|
||||
# PyBuilder |
||||
target/ |
||||
|
||||
# Jupyter Notebook |
||||
.ipynb_checkpoints |
||||
|
||||
# pyenv |
||||
.python-version |
||||
|
||||
# celery beat schedule file |
||||
celerybeat-schedule |
||||
|
||||
# SageMath parsed files |
||||
*.sage.py |
||||
|
||||
# Environments |
||||
.env |
||||
.venv |
||||
env/ |
||||
venv/ |
||||
ENV/ |
||||
env.bak/ |
||||
venv.bak/ |
||||
|
||||
# Spyder project settings |
||||
.spyderproject |
||||
.spyproject |
||||
|
||||
# Rope project settings |
||||
.ropeproject |
||||
|
||||
# mkdocs documentation |
||||
/site |
||||
|
||||
# mypy |
||||
.mypy_cache/ |
||||
|
@ -0,0 +1,70 @@ |
||||
## UNITS.INI |
||||
## GEX v0.3.1 on STM32F072-ZERO |
||||
## built May 22 2018 at 12:05:33 |
||||
|
||||
[UNITS] |
||||
# Create units by adding their names next to a type (e.g. DO=A,B), |
||||
# remove the same way. Reload to update the unit sections below. |
||||
|
||||
# Digital output |
||||
DO=trig |
||||
# Digital input with triggers |
||||
DI= |
||||
# Neopixel RGB LED strip |
||||
NPX= |
||||
# I2C master |
||||
I2C= |
||||
# SPI master |
||||
SPI= |
||||
# Serial port |
||||
USART= |
||||
# 1-Wire master |
||||
1WIRE= |
||||
# Analog/digital converter |
||||
ADC=adc |
||||
# Shift register driver (595, 4094) |
||||
SIPO= |
||||
# Frequency and pulse measurement |
||||
FCAP= |
||||
# Capacitive touch sensing |
||||
TOUCH= |
||||
# Simple PWM output |
||||
PWMDIM= |
||||
# Two-channel analog output with waveforms |
||||
DAC= |
||||
|
||||
[DO:trig@1] |
||||
# Port name |
||||
port=B |
||||
# Pins (comma separated, supports ranges) |
||||
pins=1 |
||||
# Initially high pins |
||||
initial= |
||||
# Open-drain pins |
||||
open-drain= |
||||
|
||||
[ADC:adc@2] |
||||
# Enabled channels, comma separated |
||||
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
||||
# A0 A1 A2 A3 A4 A5 A6 A7 B0 B1 C0 C1 C2 C3 C4 C5 Tsens Vref |
||||
channels=0-1 |
||||
|
||||
# Sampling time (0-7) |
||||
sample_time=2 |
||||
# Sampling frequency (Hz) |
||||
frequency=20000 |
||||
|
||||
# Sample buffer size |
||||
# - shared by all enabled channels |
||||
# - defines the maximum pre-trigger size (divide by # of channels) |
||||
# - captured data is sent in half-buffer chunks |
||||
# - buffer overrun aborts the data capture |
||||
buffer_size=500 |
||||
|
||||
# Enable continuous sampling with averaging |
||||
# Caution: This can cause DAC output glitches |
||||
averaging=N |
||||
# Exponential averaging coefficient (permil, range 0-1000 ~ 0.000-1.000) |
||||
# - used formula: y[t]=(1-k)*y[t-1]+k*u[t] |
||||
# - not available when a capture is running |
||||
avg_factor=500 |
@ -1,52 +1,124 @@ |
||||
import time |
||||
|
||||
from PyQt4 import QtCore, QtGui, Qt |
||||
from PyQt4.QtGui import QApplication, QMainWindow |
||||
import sys, math |
||||
import gex |
||||
|
||||
class MyMainScreen(QMainWindow): |
||||
def __init__(self, parent=None): |
||||
def __init__(self, client=None, parent=None): |
||||
QtGui.QMainWindow.__init__(self, parent) |
||||
self.resize(800, 600) |
||||
|
||||
self.samples = None |
||||
|
||||
self.timer = QtCore.QTimer(self) |
||||
self.timer.setInterval(100) |
||||
self.timer.timeout.connect(self.blink) |
||||
self.timer.setInterval(20) |
||||
self.timer.timeout.connect(self.measure) |
||||
self.timer.start() |
||||
|
||||
self.resize(500, 500) |
||||
self.centralwidget = QtGui.QWidget(self) |
||||
self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget) |
||||
self.timer2 = QtCore.QTimer(self) |
||||
self.timer2.setInterval(30) |
||||
self.timer2.timeout.connect(self.updatedisp) |
||||
self.timer2.start() |
||||
|
||||
self.pending = False |
||||
|
||||
# init GEX |
||||
self.client = client |
||||
self.trig = gex.DOut(client, 'trig') |
||||
self.adc = gex.ADC(client, 'adc') |
||||
|
||||
self.adc.set_sample_rate(75000) |
||||
|
||||
self.failcount = 0 |
||||
self.skipcount = 0 |
||||
self.wantredraw = False |
||||
|
||||
# self.fcap = gex.FCAP(client, 'fcap') |
||||
|
||||
def closeEvent(self,event): |
||||
self.timer.stop() |
||||
self.client.close() |
||||
self.close() |
||||
|
||||
def measure(self): |
||||
if self.pending: |
||||
self.failcount += 1 |
||||
if self.failcount > 2: |
||||
self.pending = False |
||||
self.adc.disarm() |
||||
self.skipcount = 0 |
||||
return |
||||
|
||||
self.setCentralWidget(self.centralwidget) |
||||
self.menubar = QtGui.QMenuBar(self) |
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 500, 22)) |
||||
if self.skipcount < 5: |
||||
self.skipcount += 1 |
||||
return |
||||
else: |
||||
self.skipcount = 0 |
||||
|
||||
self.setMenuBar(self.menubar) |
||||
self.pending = True |
||||
|
||||
self.statusbar = QtGui.QStatusBar(self) |
||||
self.setStatusBar(self.statusbar) |
||||
QtCore.QMetaObject.connectSlotsByName(self) |
||||
self.failcount = 0 |
||||
|
||||
self.n = 0 |
||||
self.adc.setup_trigger(1, level=1000, edge='rising', count=1000, handler=self.handle_meas) |
||||
self.adc.arm() |
||||
|
||||
def blink(self): |
||||
self.n += 0.1 |
||||
self.n = self.n % 20 |
||||
self.trig.pulse_us(10) |
||||
|
||||
def handle_meas(self, report): |
||||
self.samples = report.data[50:] |
||||
self.pending = False |
||||
self.wantredraw = True |
||||
|
||||
def updatedisp(self): |
||||
if self.wantredraw: |
||||
self.repaint() |
||||
self.wantredraw = False |
||||
|
||||
def paintEvent(self, event): |
||||
if self.samples is None: |
||||
return |
||||
|
||||
W = self.width() |
||||
H = self.height() |
||||
|
||||
painter = QtGui.QPainter(self) |
||||
painter.setRenderHint(QtGui.QPainter.Antialiasing) |
||||
painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing) |
||||
painter.setPen(QtGui.QPen(QtCore.Qt.red, 2)) |
||||
painter.fillRect(0,0, W,H, QtCore.Qt.black) |
||||
painter.setPen(QtGui.QPen(QtCore.Qt.green, 1)) |
||||
|
||||
step = round(W / len(self.samples)) |
||||
if step == 0: |
||||
step = 1 |
||||
|
||||
mult = 0.12*H/500 |
||||
n = 0 |
||||
for i in range(0, W, step): |
||||
if n == len(self.samples)-1: |
||||
break |
||||
|
||||
v = self.samples[n][0] |
||||
w = self.samples[n+1][0] |
||||
if v <= 0: v = 0.000000001 |
||||
if w <= 0: w = 0.000000001 |
||||
y0 = H - v*mult |
||||
y1 = H - w*mult |
||||
n += 1 |
||||
painter.drawLine(QtCore.QLine(i, round(y0), i+step, round(y1))) |
||||
|
||||
font = painter.font() |
||||
font.setPointSize(22) |
||||
font.setWeight(QtGui.QFont.DemiBold) |
||||
painter.setFont(font) |
||||
|
||||
step = 2 |
||||
amp = (self.height()/2)*0.8 |
||||
for i in range(0, self.width(), step): |
||||
y0 = round(self.height()/2 + amp * math.sin(2*math.pi*self.n*(i/180))) |
||||
y1 = round(self.height()/2 + amp * math.sin(2*math.pi*self.n*((i+step)/180))) |
||||
painter.drawLine(QtCore.QLine(i, y0, i+step, y1)) |
||||
# label - Raw HC-SR04 signal |
||||
painter.drawText(W-370, 50, "Surový signál přijímače") |
||||
painter.drawText(W-370, 85, "HC-SR04") |
||||
|
||||
if __name__ == "__main__": |
||||
with gex.Client(gex.TrxSerialThread()) as client: |
||||
app = QApplication(sys.argv) |
||||
mainscreen = MyMainScreen() |
||||
mainscreen = MyMainScreen(client) |
||||
mainscreen.show() |
||||
app.exec_() |
||||
|
Loading…
Reference in new issue