kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Splitted screenshot helper method
_capture_data splitted to remove code redundancypull/333/head
rodzic
c4c2f2c6a8
commit
ed8319a66c
|
@ -56,6 +56,9 @@ class NanoVNA(VNA):
|
|||
self.screenwidth * self.screenheight * 2)
|
||||
self.serial.timeout = timeout
|
||||
self.serial.timeout = timeout
|
||||
return image_data
|
||||
|
||||
def _convert_data(self, image_data: bytes) -> bytes:
|
||||
rgb_data = struct.unpack(
|
||||
f">{self.screenwidth * self.screenheight}H",
|
||||
image_data)
|
||||
|
@ -70,7 +73,7 @@ class NanoVNA(VNA):
|
|||
if not self.connected():
|
||||
return QtGui.QPixmap()
|
||||
try:
|
||||
rgba_array = self._capture_data()
|
||||
rgba_array = self._convert_data(self._capture_data())
|
||||
image = QtGui.QImage(
|
||||
rgba_array,
|
||||
self.screenwidth,
|
||||
|
|
|
@ -15,20 +15,6 @@ class NanoVNA_F_V2(NanoVNA):
|
|||
screenwidth = 800
|
||||
screenheight = 480
|
||||
|
||||
def _capture_data(self) -> bytes:
|
||||
timeout = self.serial.timeout
|
||||
with self.serial.lock:
|
||||
drain_serial(self.serial)
|
||||
timeout = self.serial.timeout
|
||||
self.serial.write("capture\r".encode('ascii'))
|
||||
self.serial.readline()
|
||||
self.serial.timeout = 4
|
||||
image_data = self.serial.read(
|
||||
self.screenwidth * self.screenheight * 2)
|
||||
self.serial.timeout = timeout
|
||||
self.serial.timeout = timeout
|
||||
return image_data
|
||||
|
||||
def getScreenshot(self) -> QtGui.QPixmap:
|
||||
logger.debug("Capturing screenshot...")
|
||||
if not self.connected():
|
||||
|
@ -37,10 +23,12 @@ class NanoVNA_F_V2(NanoVNA):
|
|||
rgba_array = self._capture_data()
|
||||
image = QtGui.QImage(
|
||||
rgba_array,
|
||||
self.screenwidth, self.screenheight,
|
||||
self.screenwidth,
|
||||
self.screenheight,
|
||||
QtGui.QImage.Format_RGB16)
|
||||
logger.debug("Captured screenshot")
|
||||
return QtGui.QPixmap(image)
|
||||
except serial.SerialException as exc:
|
||||
logger.exception("Exception while capturing screenshot: %s", exc)
|
||||
logger.exception(
|
||||
"Exception while capturing screenshot: %s", exc)
|
||||
return QtGui.QPixmap()
|
||||
|
|
Ładowanie…
Reference in New Issue