Skip to content

Commit

Permalink
Number the printers following the order of IP addresses in user prefe…
Browse files Browse the repository at this point in the history
…rences.
  • Loading branch information
loociano committed May 26, 2020
1 parent 4c400be commit df4430c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
25 changes: 13 additions & 12 deletions src/MPSM2NetworkedPrinterOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:<ip_address>'
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)
Expand Down
13 changes: 10 additions & 3 deletions src/Network/DeviceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand All @@ -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)

Expand All @@ -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.')
Expand Down
1 change: 0 additions & 1 deletion src/Network/PrinterHeartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Copyright 2020 Luc Rubio <[email protected]>
Plugin is licensed under the GNU Lesser General Public License v3.0.
"""
import socket
import time
from http.client import HTTPConnection

Expand Down

0 comments on commit df4430c

Please sign in to comment.