From df4430cd39d479b58f5d4853255aa4c840f3fac9 Mon Sep 17 00:00:00 2001 From: Luc Rubio Date: Tue, 26 May 2020 01:05:56 +0100 Subject: [PATCH] Number the printers following the order of IP addresses in user preferences. --- src/MPSM2NetworkedPrinterOutputDevice.py | 25 ++++++++++++------------ src/Network/DeviceManager.py | 13 +++++++++--- src/Network/PrinterHeartbeat.py | 1 - 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/MPSM2NetworkedPrinterOutputDevice.py b/src/MPSM2NetworkedPrinterOutputDevice.py index cfecea8..12b6097 100644 --- a/src/MPSM2NetworkedPrinterOutputDevice.py +++ b/src/MPSM2NetworkedPrinterOutputDevice.py @@ -63,14 +63,6 @@ def _build_printer_conf_model() -> PrinterConfigurationModel: class MPSM2NetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice): """Represents a networked OutputDevice for Monoprice Select Mini V2 printers.""" - META_NETWORK_KEY = 'mpsm2_network_key' - MPSM2_PROPERTIES = { - b'name': b'Monoprice Select Mini V2', - b'machine': b'Malyan M200', - b'manual': b'true', - b'printer_type': b'monoprice_select_mini_v2', - b'firmware_version': b'Unknown', - } MAX_TARGET_HOTEND_TEMPERATURE = 260 # celsius MAX_TARGET_BED_TEMPERATURE = 85 # celsius @@ -82,19 +74,28 @@ class MPSM2NetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice): hasTargetHotendInProgressChanged = pyqtSignal() hasTargetBedInProgressChanged = pyqtSignal() - def __init__(self, device_id: str, address: str, parent=None) -> None: + def __init__(self, device_id: str, address: str, instance_number=1, + parent=None) -> None: """Constructor Args: device_id: 'manual:' address: IP address, for example '192.168.0.70' """ - MPSM2NetworkedPrinterOutputDevice.MPSM2_PROPERTIES[b'address'] \ - = address.encode('utf-8') + device_name = 'Monoprice Select Mini V2{}'.format( + ' #{}'.format(instance_number) if instance_number > 1 else '') + mpsm2_properties = { + b'name': device_name.encode('utf-8'), + b'machine': b'Malyan M200', + b'manual': b'true', + b'printer_type': b'monoprice_select_mini_v2', + b'firmware_version': b'Unknown', + b'address': address.encode('utf-8'), + } super().__init__( device_id=device_id, address=address, - properties=MPSM2NetworkedPrinterOutputDevice.MPSM2_PROPERTIES, + properties=mpsm2_properties, connection_type=ConnectionType.NetworkConnection, parent=parent) self._printer_output_controller = MPSM2OutputController(self) diff --git a/src/Network/DeviceManager.py b/src/Network/DeviceManager.py index 25946e8..db44791 100644 --- a/src/Network/DeviceManager.py +++ b/src/Network/DeviceManager.py @@ -138,8 +138,14 @@ def _on_printer_status_response( Logger.log('d', 'Received response from printer on address %s: %s.', address, response) + self._store_manual_address(address) + instance_number = 1 + try: + instance_number = self._get_stored_manual_addresses().index(address) + 1 + except ValueError: + Logger.log('e', 'Could not find address %s in user preferences', address) device = MPSM2NetworkedPrinterOutputDevice( - DeviceManager._get_device_id(address), address) + DeviceManager._get_device_id(address), address, instance_number) device.onPrinterUpload.connect(self.onPrinterUpload) device.update_printer_status(response) discovered_printers_model = \ @@ -155,7 +161,6 @@ def _on_printer_status_response( self._discovered_devices[device.getId()] = device self.discoveredDevicesChanged.emit() self.connect_to_active_machine() - self._store_manual_address(address) if callback is not None: CuraApplication.getInstance().callLater(callback, True, address) @@ -177,7 +182,9 @@ def _create_machine(self, device_id: str) -> None: return if self._machines.get(device_id) is None: - new_machine = CuraStackBuilder.createMachine(device.name, + machine_name = device.name if len(self._machines) == 0 \ + else device.name + '#{}'.format(len(self._machines) + 1) + new_machine = CuraStackBuilder.createMachine(machine_name, device.printerType) if not new_machine: Logger.log('e', 'Failed to create a new machine.') diff --git a/src/Network/PrinterHeartbeat.py b/src/Network/PrinterHeartbeat.py index de7f4bc..85e3f78 100644 --- a/src/Network/PrinterHeartbeat.py +++ b/src/Network/PrinterHeartbeat.py @@ -2,7 +2,6 @@ Copyright 2020 Luc Rubio Plugin is licensed under the GNU Lesser General Public License v3.0. """ -import socket import time from http.client import HTTPConnection