camera test
This commit is contained in:
parent
6d15ee208a
commit
09271c5a84
@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from PyQt5.QtCore import QThread
|
from PyQt5.QtCore import QThread, pyqtSignal
|
||||||
|
|
||||||
if "--sim-serial" in sys.argv:
|
if "--sim-serial" in sys.argv:
|
||||||
from components.dummies.serial import serial
|
from components.dummies.serial import serial
|
||||||
@ -16,9 +16,12 @@ C_UINT32_MAX = c_uint32(-1).value
|
|||||||
|
|
||||||
|
|
||||||
class NeoPixels(Component):
|
class NeoPixels(Component):
|
||||||
|
request = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self, config=None, name=None):
|
def __init__(self, config=None, name=None):
|
||||||
self.conn = None
|
self.conn = None
|
||||||
super().__init__(config=config, name=name, threaded=False)
|
super().__init__(config=config, name=name, threaded=False)
|
||||||
|
self.set_requestors({"self": self.request})
|
||||||
|
|
||||||
def config_changed(self):
|
def config_changed(self):
|
||||||
self.port = self.config[self.name]["port"]
|
self.port = self.config[self.name]["port"]
|
||||||
@ -47,10 +50,14 @@ class NeoPixels(Component):
|
|||||||
self.set_all_pixel_color("#000000")
|
self.set_all_pixel_color("#000000")
|
||||||
|
|
||||||
@Component.reconfig_on_error
|
@Component.reconfig_on_error
|
||||||
def set(self, pixel, color):
|
def _set(self, data=None):
|
||||||
if type(pixel) is not int or pixel < 0 or pixel > C_UINT32_MAX:
|
if not isinstance(data, dict):
|
||||||
|
raise ValueError(f"bad call data: {data!r}")
|
||||||
|
pixel = data.get("pixel", None)
|
||||||
|
color = data.get("color", None)
|
||||||
|
if not isinstance(pixel, int) or pixel < 0 or pixel > C_UINT32_MAX:
|
||||||
raise ValueError(f"the pixel parameter must be a int between 0 and {C_UINT32_MAX} (broadcast)")
|
raise ValueError(f"the pixel parameter must be a int between 0 and {C_UINT32_MAX} (broadcast)")
|
||||||
if not color.startswith("#") or len(color) != 7:
|
if not isinstance(color, str) or not color.startswith("#") or len(color) != 7:
|
||||||
raise ValueError("the color parameter must be in the html hex format: '#RRGGBB'")
|
raise ValueError("the color parameter must be in the html hex format: '#RRGGBB'")
|
||||||
try:
|
try:
|
||||||
self.conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
|
self.conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
|
||||||
@ -60,6 +67,9 @@ class NeoPixels(Component):
|
|||||||
except serial.serialutil.SerialException:
|
except serial.serialutil.SerialException:
|
||||||
self.log.exception(traceback.format_exc())
|
self.log.exception(traceback.format_exc())
|
||||||
|
|
||||||
|
def set(self, pixel, color):
|
||||||
|
self.request.emit({"pixel": pixel, "color": color})
|
||||||
|
|
||||||
def set_pixel_color(self, pixel, color):
|
def set_pixel_color(self, pixel, color):
|
||||||
self.set(pixel, color)
|
self.set(pixel, color)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user