You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.2 KiB
124 lines
3.2 KiB
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, client=None, parent=None):
|
|
QtGui.QMainWindow.__init__(self, parent)
|
|
self.resize(800, 600)
|
|
|
|
self.samples = None
|
|
|
|
self.timer = QtCore.QTimer(self)
|
|
self.timer.setInterval(20)
|
|
self.timer.timeout.connect(self.measure)
|
|
self.timer.start()
|
|
|
|
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(80000)
|
|
|
|
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
|
|
|
|
if self.skipcount < 5:
|
|
self.skipcount += 1
|
|
return
|
|
else:
|
|
self.skipcount = 0
|
|
|
|
self.pending = True
|
|
|
|
self.failcount = 0
|
|
|
|
self.adc.setup_trigger(1, level=1000, edge='rising', count=1366, handler=self.handle_meas)
|
|
self.adc.arm()
|
|
|
|
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.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)
|
|
|
|
# label - Raw HC-SR04 signal
|
|
painter.drawText(W-370, 50, "Surový signál přijímače")
|
|
painter.drawText(W-370, 85, "HC-SR04")
|
|
|
|
with gex.Client(gex.TrxSerialThread()) as client:
|
|
app = QApplication(sys.argv)
|
|
mainscreen = MyMainScreen(client)
|
|
mainscreen.showFullScreen()
|
|
app.exec_()
|
|
|