-
Notifications
You must be signed in to change notification settings - Fork 0
/
Press_Mat.py
87 lines (64 loc) · 2.23 KB
/
Press_Mat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import sys
import numpy as np
from PyQt4 import QtGui
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import SerialCommunication as serial
#constants
num_rows = 10
num_cols = 5
sensor_num = num_rows*num_cols
ser = serial.sensorInit()
from functools import partial
class Press_Mat(QtGui.QWidget):
def __init__(self):
super(Press_Mat, self).__init__()
for i in range (4):
Array = serial.readSensors(ser, 28)
self.figure = plt.figure()
self.figure2 = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.grid = serial.matrixConvert(Array, num_rows, num_cols)
self.grid[0,0] = 1000
self.start()
def start(self):
self.setWindowTitle('PressMat')
gridLayout = QtGui.QGridLayout()
self.setLayout(gridLayout)
#button
restart = QtGui.QPushButton("Start")
restart.clicked.connect(self.plot)
#checkbox
self.record = QtGui.QCheckBox('Record', self)
gridLayout.addWidget(self.canvas,0,0)
gridLayout.addWidget(restart, 1,0)
gridLayout.addWidget(self.record, 2,0)
self.show()
def plot(self):
#Figure and subplot
ax = self.figure.add_subplot(111)
self.mat = ax.matshow(self.grid)
plt.axis('off')
ani = animation.FuncAnimation(self.figure, self.update, interval=3, save_count=1000)
if (self.record.checkState() != 0):
ani.save('bruh.mp4',fps=30)
self.canvas.draw()
def update(self, data):
#print('Updating')
newGrid = self.grid.copy()
Array = serial.readSensors(ser, sensor_num)
newGrid = serial.matrixConvert(Array, num_rows, num_cols)
self.mat.set_data(newGrid)
self.grid = newGrid
#simply restarts data
def restart_animation(self, ax, figure):
self.grid = np.zeros((num_rows,num_cols))
self.mat = ax.matshow(self.grid)
def main():
app = QtGui.QApplication(sys.argv)
widget = Press_Mat()
#widget can be implement in other layout
sys.exit(app.exec_())
if __name__ == "__main__":
main()