Commit 71a4ce6b authored by Alisson Claudino's avatar Alisson Claudino

Transcrição do código para orientação a objeto

parent 9cc90912
......@@ -5,15 +5,9 @@ import time
import sys
from mainwindow import Ui_MainWindow
class GUI(Ui_MainWindow):
def __init__(self, dialog):
Ui_MainWindow.__init__(self)
self.setupUi(dialog)
class SerialManager(object):
def __init__(self):
self.ser = serial.Serial('/dev/ttyACM0', 115200) # Inicialização da Serial com baudrate 115200bps
self.ser = serial.Serial('/dev/ttyUSB0', 115200) # Inicialização da Serial com baudrate 115200bps
self.ser.setDTR(False) # Reset do arduino para reinicio da leitura
time.sleep(0.022)
self.ser.setDTR(True)
......@@ -29,39 +23,50 @@ class Graph(pyqtgraph.GraphicsLayout):
index=0
def __init__(self,x_range,y_range,x_size,y_size,color):
super(Graph,self).__init__()
self.x_range = x_range
self.y_range = y_range
self.x_size = x_size
self.y_size = y_size
self.p1 = self.addPlot()
self.curve1 = p1.plot(pen=color)
self.curve1 = self.p1.plot(pen=color)
self.setPreferredSize(x_size,y_size)
self.p1.setXRange(0,x_range,padding=0)
self.p1.setYRange(0, y_range, padding=0)
self.x1=[]
self.y1=[]
def updateGraph(self,value):
y1.append(value)
index += 1
if len(y1)>x_range-1:
del y1[0]
self.index = x_range
self.y1.append(value)
self.index += 1
if len(self.y1)>self.x_range-1:
del self.y1[0]
self.index = self.x_range
else:
x1.append(index)
self.x1.append(index)
self.curve1.setData(self.x1, self.y1)
self.curve1.setData(x1,y1)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QMainWindow()
ser1 = SerialManager()
uiCalibra1=Ui_MainWindow()
uiCalibra1.setupUi(dialog)
layout = Graph(0,100,0,1023,'r')
scene = QtGui.QGraphicsScene()
scene.addItem(layout)
uiCalibra1.sceneSelector(scene)
prog = GUI(dialog)
timer = QtCore.QTimer() #
timer.timeout.connect(layout.update(ser1.read())) #
timer.start(0)
dialog.show()
dialog.showMaximized()
sys.exit(app.exec_())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment