matrix_test: minor codestyle
parent
aa59202b5a
commit
8d56cdb191
|
|
@ -1,6 +1,7 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
from PyQt5.QtWidgets import QVBoxLayout, QPushButton
|
from PyQt5.QtWidgets import QVBoxLayout, QPushButton
|
||||||
from PyQt5.QtCore import Qt, QTimer
|
from PyQt5.QtCore import Qt, QTimer
|
||||||
import struct
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
from basic_editor import BasicEditor
|
from basic_editor import BasicEditor
|
||||||
|
|
@ -8,6 +9,7 @@ from keyboard_widget import KeyboardWidget
|
||||||
from vial_device import VialKeyboard
|
from vial_device import VialKeyboard
|
||||||
from unlocker import Unlocker
|
from unlocker import Unlocker
|
||||||
|
|
||||||
|
|
||||||
class MatrixTest(BasicEditor):
|
class MatrixTest(BasicEditor):
|
||||||
def __init__(self, layout_editor):
|
def __init__(self, layout_editor):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -35,7 +37,7 @@ class MatrixTest(BasicEditor):
|
||||||
self.timer = QTimer()
|
self.timer = QTimer()
|
||||||
self.timer.timeout.connect(self.matrix_poller)
|
self.timer.timeout.connect(self.matrix_poller)
|
||||||
|
|
||||||
self.startButtonWidget.clicked.connect(self.start_poller)
|
self.startButtonWidget.clicked.connect(self.toggle)
|
||||||
self.resetButtonWidget.clicked.connect(self.reset_keyboard_widget)
|
self.resetButtonWidget.clicked.connect(self.reset_keyboard_widget)
|
||||||
|
|
||||||
def rebuild(self, device):
|
def rebuild(self, device):
|
||||||
|
|
@ -64,14 +66,14 @@ class MatrixTest(BasicEditor):
|
||||||
rows = self.keyboard.rows
|
rows = self.keyboard.rows
|
||||||
cols = self.keyboard.cols
|
cols = self.keyboard.cols
|
||||||
# Generate 2d array of matrix
|
# Generate 2d array of matrix
|
||||||
matrix = [ [None for y in range(cols)] for x in range(rows) ]
|
matrix = [[None] * cols for x in range(rows)]
|
||||||
|
|
||||||
# Get matrix data from keyboard
|
# Get matrix data from keyboard
|
||||||
data = self.keyboard.matrix_poll()
|
data = self.keyboard.matrix_poll()
|
||||||
# Calculate the amount of bytes belong to 1 row, each bit is 1 key, so per 8 keys in a row, a byte is needed for the row.
|
# Calculate the amount of bytes belong to 1 row, each bit is 1 key, so per 8 keys in a row,
|
||||||
|
# a byte is needed for the row.
|
||||||
row_size = math.ceil(cols / 8)
|
row_size = math.ceil(cols / 8)
|
||||||
|
|
||||||
|
|
||||||
for row in range(rows):
|
for row in range(rows):
|
||||||
# Make slice of bytes for the row (skip first 2 bytes, they're for VIAL)
|
# Make slice of bytes for the row (skip first 2 bytes, they're for VIAL)
|
||||||
row_data_start = 2 + (row * row_size)
|
row_data_start = 2 + (row * row_size)
|
||||||
|
|
@ -102,15 +104,20 @@ class MatrixTest(BasicEditor):
|
||||||
self.keyboardWidget.update()
|
self.keyboardWidget.update()
|
||||||
self.keyboardWidget.updateGeometry()
|
self.keyboardWidget.updateGeometry()
|
||||||
|
|
||||||
def start_poller(self):
|
def start(self):
|
||||||
if not self.polling:
|
|
||||||
Unlocker.unlock(self.keyboard)
|
Unlocker.unlock(self.keyboard)
|
||||||
self.startButtonWidget.setText("Stop testing")
|
self.startButtonWidget.setText("Stop testing")
|
||||||
self.timer.start(20)
|
self.timer.start(20)
|
||||||
self.polling = True
|
self.polling = True
|
||||||
else:
|
|
||||||
|
def stop(self):
|
||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
self.keyboard.lock()
|
self.keyboard.lock()
|
||||||
self.startButtonWidget.setText("Start testing")
|
self.startButtonWidget.setText("Start testing")
|
||||||
self.polling = False
|
self.polling = False
|
||||||
|
|
||||||
|
def toggle(self):
|
||||||
|
if not self.polling:
|
||||||
|
self.start()
|
||||||
|
else:
|
||||||
|
self.stop()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue