Fix controller to serial "None" option as None correctly.
This commit is contained in:
parent
6c80a8c192
commit
0e040d2d22
2 changed files with 15 additions and 7 deletions
|
@ -38,6 +38,7 @@ class MattchBox(Controller):
|
|||
# Allow server config changes to trigger controller reload if required.
|
||||
self.port = None
|
||||
self.next_port = self.server_state.get()["serial_port"]
|
||||
self.logger.log.info("Server config gives port as: {}".format(self.next_port))
|
||||
|
||||
self.server_from_q = server_from_q
|
||||
self.server_to_q = server_to_q
|
||||
|
@ -57,10 +58,13 @@ class MattchBox(Controller):
|
|||
self.port = None
|
||||
self.next_port = new_port
|
||||
|
||||
def connect(self, port: Optional[str]):
|
||||
# If we loose the controller, make sure to set channels live, so we tracklist.
|
||||
def _disconnected(self):
|
||||
# If we lose the controller, make sure to set channels live, so we tracklist.
|
||||
for i in range(len(self.server_from_q)):
|
||||
self.sendToPlayer(i, "SETLIVE:True")
|
||||
self.server_state.update("ser_connected", False)
|
||||
|
||||
def connect(self, port: Optional[str]):
|
||||
|
||||
if port:
|
||||
# connect to serial port
|
||||
|
@ -71,8 +75,10 @@ class MattchBox(Controller):
|
|||
self.logger.log.info("Connected to serial port {}".format(port))
|
||||
except serial.SerialException as e:
|
||||
self.logger.log.error(
|
||||
"Could not open serial port {}: {}".format(port, e)
|
||||
"Could not open serial port" + str(port),
|
||||
e
|
||||
)
|
||||
self._disconnected()
|
||||
self.ser = None
|
||||
else:
|
||||
self.ser = None
|
||||
|
@ -89,7 +95,7 @@ class MattchBox(Controller):
|
|||
) # Endianness doesn't matter for 1 byte.
|
||||
self.logger.log.info("Received from controller: " + str(line))
|
||||
if line == 255:
|
||||
self.ser.write(b"\xff") # Send 255 back
|
||||
self.ser.write(b"\xff") # Send 255 back, this is a keepalive.
|
||||
elif line in [51,52,53]:
|
||||
# We've received a status update about fader live status, fader is down.
|
||||
self.sendToPlayer(line-51, "SETLIVE:False")
|
||||
|
@ -108,7 +114,7 @@ class MattchBox(Controller):
|
|||
|
||||
elif self.port:
|
||||
# If there's still a port set, just wait a moment and see if it's been reconnected.
|
||||
self.server_state.update("ser_connected", False)
|
||||
self._disconnected()
|
||||
time.sleep(10)
|
||||
self.connect(self.port)
|
||||
|
||||
|
@ -116,7 +122,7 @@ class MattchBox(Controller):
|
|||
# We're not already connected, or a new port connection is to be made.
|
||||
if self.ser:
|
||||
self.ser.close()
|
||||
self.server_state.update("ser_connected", False)
|
||||
self._disconnected()
|
||||
|
||||
if self.next_port is not None:
|
||||
self.connect(self.next_port)
|
||||
|
|
|
@ -164,7 +164,9 @@ def ui_config_server_update(request):
|
|||
server_state.update("port", int(request.form.get("port")))
|
||||
server_state.update("num_channels", int(request.form.get("channels")))
|
||||
server_state.update("ws_port", int(request.form.get("ws_port")))
|
||||
server_state.update("serial_port", request.form.get("serial_port"))
|
||||
|
||||
serial_port = request.form.get("serial_port")
|
||||
server_state.update("serial_port", None if serial_port == "None" else serial_port)
|
||||
|
||||
# Because we're not showing the api key once it's set.
|
||||
if "myradio_api_key" in request.form and request.form.get("myradio_api_key") != "":
|
||||
|
|
Loading…
Reference in a new issue