Improve shutdown time of Controller Handler.
This commit is contained in:
parent
02137a3948
commit
1e77f337b1
1 changed files with 29 additions and 26 deletions
|
@ -68,16 +68,18 @@ class MattchBox(Controller):
|
||||||
if port:
|
if port:
|
||||||
# connect to serial port
|
# connect to serial port
|
||||||
self.ser = serial.serial_for_url(port, do_not_open=True)
|
self.ser = serial.serial_for_url(port, do_not_open=True)
|
||||||
self.ser.baudrate = 2400
|
if self.ser:
|
||||||
try:
|
self.ser.baudrate = 2400
|
||||||
self.ser.open()
|
self.ser.timeout = 0.1 # Speed up waiting for a byte.
|
||||||
self.logger.log.info("Connected to serial port {}".format(port))
|
try:
|
||||||
except (FileNotFoundError, serial.SerialException) as e:
|
self.ser.open()
|
||||||
self.logger.log.error(
|
self.logger.log.info("Connected to serial port {}".format(port))
|
||||||
"Could not open serial port {}:\n{}".format(port, e)
|
except (FileNotFoundError, serial.SerialException) as e:
|
||||||
)
|
self.logger.log.error(
|
||||||
self._disconnected()
|
"Could not open serial port {}:\n{}".format(port, e)
|
||||||
self.ser = None
|
)
|
||||||
|
self._disconnected()
|
||||||
|
self.ser = None
|
||||||
else:
|
else:
|
||||||
self.ser = None
|
self.ser = None
|
||||||
|
|
||||||
|
@ -88,22 +90,23 @@ class MattchBox(Controller):
|
||||||
self.ser and self.ser.is_open and self.port
|
self.ser and self.ser.is_open and self.port
|
||||||
): # If self.port is changing (via state_handler), we should stop.
|
): # If self.port is changing (via state_handler), we should stop.
|
||||||
try:
|
try:
|
||||||
line = int.from_bytes(
|
if self.ser.in_waiting > 0:
|
||||||
self.ser.read(1), "big"
|
line = int.from_bytes(
|
||||||
) # Endianness doesn't matter for 1 byte.
|
self.ser.read(1), "big"
|
||||||
self.logger.log.info("Received from controller: " + str(line))
|
) # Endianness doesn't matter for 1 byte.
|
||||||
if line == 255:
|
self.logger.log.info("Received from controller: " + str(line))
|
||||||
self.ser.write(b"\xff") # Send 255 back, this is a keepalive.
|
if line == 255:
|
||||||
elif line in [51, 52, 53]:
|
self.ser.write(b"\xff") # Send 255 back, this is a keepalive.
|
||||||
# We've received a status update about fader live status, fader is down.
|
elif line in [51, 52, 53]:
|
||||||
self.sendToPlayer(line - 51, "SETLIVE:False")
|
# We've received a status update about fader live status, fader is down.
|
||||||
elif line in [61, 62, 63]:
|
self.sendToPlayer(line - 51, "SETLIVE:False")
|
||||||
# We've received a status update about fader live status, fader is up.
|
elif line in [61, 62, 63]:
|
||||||
self.sendToPlayer(line - 61, "SETLIVE:True")
|
# We've received a status update about fader live status, fader is up.
|
||||||
elif line in [1, 3, 5]:
|
self.sendToPlayer(line - 61, "SETLIVE:True")
|
||||||
self.sendToPlayer(int(line / 2), "PLAYPAUSE")
|
elif line in [1, 3, 5]:
|
||||||
elif line in [2, 4, 6]:
|
self.sendToPlayer(int(line / 2), "PLAYPAUSE")
|
||||||
self.sendToPlayer(int(line / 2) - 1, "STOP")
|
elif line in [2, 4, 6]:
|
||||||
|
self.sendToPlayer(int(line / 2) - 1, "STOP")
|
||||||
except Exception:
|
except Exception:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
self.connect(self.port)
|
self.connect(self.port)
|
||||||
|
|
Loading…
Reference in a new issue