Skip to content

Commit b0b36c9

Browse files
authored
SW-1242 release v0.10.4 (mrbeam#1472)
2 parents c5c1b5e + faf3ad6 commit b0b36c9

File tree

16 files changed

+241
-118
lines changed

16 files changed

+241
-118
lines changed

octoprint_mrbeam/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ def initialize(self):
243243
self.led_event_listener.set_fps(self._settings.get(["leds", "fps"]))
244244
# start iobeam socket only once other handlers are already initialized so that we can handle info message
245245
self.iobeam = ioBeamHandler(self)
246-
self.temperature_manager = temperatureManager(self)
247246
self.dust_manager = dustManager(self)
248247
self.hw_malfunction_handler = hwMalfunctionHandler(self)
249248
self.laserhead_handler = laserheadHandler(self)
249+
self.temperature_manager = temperatureManager(self)
250250
self.compressor_handler = compressor_handler(self)
251251
self.wizard_config = WizardConfig(self)
252252
self.job_time_estimation = JobTimeEstimation(self)

octoprint_mrbeam/__version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.10.3"
1+
__version__ = "0.10.4"

octoprint_mrbeam/analytics/timer_handler.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# coding=utf-8
2+
import re
23

34
import netifaces
45
import requests
@@ -215,7 +216,7 @@ def _software_versions(self):
215216
it made sens when we did a filesystem checksum calculation... _software_versions_and_checksums()
216217
"""
217218
sw_versions = self._get_software_versions()
218-
self._logger.debug("_software_versions: %s", sw_versions)
219+
self._logger.debug("Software Version info: \n{}".format(sw_versions))
219220
self._plugin.analytics_handler.add_software_versions(sw_versions)
220221

221222
def _software_versions_and_checksums(self):
@@ -279,31 +280,38 @@ def _software_versions_and_checksums(self):
279280

280281
def _get_software_versions(self):
281282
result = dict()
282-
configured_checks = None
283+
software_info = None
284+
283285
try:
284-
pluginInfo = self._plugin._plugin_manager.get_plugin_info("softwareupdate")
285-
if pluginInfo is not None:
286-
impl = pluginInfo.implementation
287-
configured_checks = impl._configured_checks
288-
else:
289-
self._logger.error(
290-
"_get_software_versions() Can't get pluginInfo.implementation"
291-
)
286+
plugin_info = self._plugin._plugin_manager.get_plugin_info("softwareupdate")
287+
impl = plugin_info.implementation
288+
# using the method get_current_versions() is OK as it is threadsafe
289+
software_info, _, _ = impl.get_current_versions()
290+
self._logger.debug("Software_info: \n {}".format(software_info))
292291
except Exception as e:
293292
self._logger.exception(
294-
"Exception while reading configured_checks from softwareupdate plugin. "
293+
"Exception while reading software_info from softwareupdate plugin. Error:{} ".format(e)
295294
)
295+
return result
296296

297-
if configured_checks is None:
297+
if isinstance(software_info, dict) is False:
298298
self._logger.warn(
299-
"_get_software_versions() Can't read software version from softwareupdate plugin."
299+
"get_current_versions() Can't read software version from softwareupdate plugin."
300+
)
301+
return result
302+
303+
# Reaching this section means we are OK so far
304+
for name, info in software_info.iteritems():
305+
commit_hash = info["information"]["local"].get("name", None)
306+
if commit_hash is not None:
307+
# regex: "Commit 89nhfbffnf7f8fbfgfndhf" --> "89nhfbffnf7f8fbfgfndhf"
308+
regex_match = re.match(r"Commit (\S+)", commit_hash)
309+
if regex_match is not None:
310+
commit_hash = regex_match.group(1)
311+
result[name] = dict(
312+
version=info.get("displayVersion", None),
313+
commit_hash=commit_hash,
300314
)
301-
else:
302-
for name, config in configured_checks.iteritems():
303-
result[name] = dict(
304-
version=config.get("displayVersion", None),
305-
commit_hash=config.get("current", None),
306-
)
307315
return result
308316

309317
def _num_files(self):

octoprint_mrbeam/iobeam/iobeam_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class IoBeamValueEvents(object):
6262
FAN_FACTOR_RESPONSE = "iobeam.fan.factor.response"
6363
COMPRESSOR_STATIC = "iobeam.compressor.static"
6464
COMPRESSOR_DYNAMIC = "iobeam.compressor.dynamic"
65+
LASERHEAD_CHANGED = "iobeam.laserhead.changed"
6566

6667

6768
class IoBeamHandler(object):

octoprint_mrbeam/iobeam/laserhead_handler.py

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import re
44
from octoprint_mrbeam.mrb_logger import mrb_logger
55
from octoprint_mrbeam.mrbeam_events import MrBeamEvents
6+
from octoprint_mrbeam.iobeam.iobeam_handler import IoBeamValueEvents
7+
8+
LASERHEAD_MAX_TEMP_FALLBACK = 55.0
69

710
# singleton
811
_instance = None
@@ -30,6 +33,7 @@ def __init__(self, plugin):
3033
self._settings = plugin._settings
3134
self._event_bus = plugin._event_bus
3235
self._plugin_version = plugin.get_plugin_version()
36+
self._iobeam = None
3337

3438
self._lh_cache = {}
3539
self._last_used_lh_serial = None
@@ -74,6 +78,7 @@ def _on_mrbeam_plugin_initialized(self, event, payload):
7478
_ = event
7579
_ = payload
7680
self._analytics_handler = self._plugin.analytics_handler
81+
self._iobeam = self._plugin.iobeam
7782

7883
def _get_lh_model(self, lh_data):
7984
try:
@@ -92,19 +97,25 @@ def _get_lh_model(self, lh_data):
9297
)
9398

9499
def set_current_used_lh_data(self, lh_data):
100+
laser_head_model_changed = False
101+
95102
try:
96103
if self._valid_lh_data(lh_data):
97104
self._current_used_lh_serial = lh_data["main"]["serial"]
98105
self._current_used_lh_model_id = self._get_lh_model(lh_data)
99106
self._current_used_lh_model = self._LASERHEAD_MODEL_STRING_MAP[str(self._current_used_lh_model_id)]
100107
# fmt: off
108+
if(self._current_used_lh_model_id != self._last_used_lh_model_id) \
109+
and self._current_used_lh_model_id is not None:
110+
laser_head_model_changed = True
111+
101112
if (self._current_used_lh_serial != self._last_used_lh_serial) and self._last_used_lh_model_id is not None:
102113
# fmt: on
103114
if self._current_used_lh_model_id == 1:
104115
self._settings.set_boolean(["laserheadChanged"], True)
105116
self._settings.save()
106117
self._logger.info(
107-
"Laserhead changed: s/n:%s model:%s -> s/n:%s model:%s",
118+
"laserhead_handler: Laserhead changed: s/n:%s model:%s -> s/n:%s model:%s",
108119
self._last_used_lh_serial,
109120
self._last_used_lh_model_id,
110121
self._current_used_lh_serial,
@@ -124,6 +135,21 @@ def set_current_used_lh_data(self, lh_data):
124135
),
125136
)
126137

138+
if laser_head_model_changed:
139+
# Now all the information about the new laser head should be present Thus we can fire this event
140+
self._logger.info(
141+
"laserhead_handler: Laserhead Model changed: s/n:%s model:%s -> s/n:%s model:%s",
142+
self._last_used_lh_serial,
143+
self._last_used_lh_model_id,
144+
self._current_used_lh_serial,
145+
self._current_used_lh_model_id,
146+
)
147+
# Fire the event
148+
self._iobeam._call_callback(
149+
IoBeamValueEvents.LASERHEAD_CHANGED,
150+
"Laserhead Model changed",
151+
)
152+
127153
# BACKWARD_COMPATIBILITY: This is for detecting mrb_hw_info v0.0.20
128154
# This part of the code should never by reached, if reached then this means an update for mrb_hw_info did
129155
# fail TODO Remove this part of the code later
@@ -407,3 +433,79 @@ def _write_laser_heads_file(self, laser_heads_file=None):
407433
self._logger.info("Writing to file: {} ..is successful!".format(laser_heads_file))
408434
except IOError as e:
409435
self._logger.error("Can't open file: {} , Due to error: {}: ".format(laser_heads_file, e))
436+
437+
@property
438+
def current_laserhead_max_temperature(self):
439+
"""
440+
Return the current laser head max temperature
441+
442+
Returns:
443+
float: Laser head max temp
444+
445+
"""
446+
current_laserhead_properties = self._load_current_laserhead_properties()
447+
448+
# Handle the exceptions
449+
if((isinstance(current_laserhead_properties, dict) is False) or
450+
("max_temperature" not in current_laserhead_properties) or
451+
(isinstance(current_laserhead_properties["max_temperature"], float) is False)):
452+
# Apply fallback
453+
self._logger.debug("Current laserhead properties: {}".format(current_laserhead_properties))
454+
self._logger.exception(
455+
"Current Laserhead Max temp couldn't be retrieved, fallback to the temperature value of: {}".format(
456+
self.default_laserhead_max_temperature))
457+
return self.default_laserhead_max_temperature
458+
# Reaching here means, everything looks good
459+
self._logger.debug("Current Laserhead Max temp:{}".format(current_laserhead_properties["max_temperature"]))
460+
return current_laserhead_properties["max_temperature"]
461+
462+
@property
463+
def default_laserhead_max_temperature(self):
464+
"""
465+
Default max temperature for laser head. to be used by other modules at init time
466+
467+
Returns:
468+
float: Laser head default max temp
469+
"""
470+
471+
return LASERHEAD_MAX_TEMP_FALLBACK
472+
473+
def _load_current_laserhead_properties(self):
474+
"""
475+
Loads the current detected laser head related properties and return them
476+
477+
Returns:
478+
dict: current laser head properties, None: otherwise
479+
480+
"""
481+
# 1. get the ID of the current laser head
482+
laserhead_id = self.get_current_used_lh_model_id()
483+
484+
# 2. Load the corresponding yaml file and return it's content
485+
lh_properties_file_path = os.path.join(self._plugin._basefolder,
486+
"profiles", "laserhead", "laserhead_id_{}.yaml".format(laserhead_id))
487+
if not os.path.isfile(lh_properties_file_path):
488+
self._logger.exception(
489+
"properties file for current laser head ID: {} doesn't exist or path is invalid. Path: {}".format(
490+
laserhead_id, lh_properties_file_path))
491+
return None
492+
493+
self._logger.debug(
494+
"properties file for current laser head ID: {} exists. Path:{}".format(
495+
laserhead_id, lh_properties_file_path) )
496+
try:
497+
with open(lh_properties_file_path) as lh_properties_yaml_file:
498+
self._logger.debug(
499+
"properties file for current laser head ID: {} opened successfully".format(
500+
laserhead_id))
501+
return yaml.safe_load(lh_properties_yaml_file)
502+
except (IOError, yaml.YAMLError) as e:
503+
self._logger.exception(
504+
"Exception: {} while Opening or loading the properties file for current laser head. Path: {}".format(
505+
e, lh_properties_file_path))
506+
return None
507+
508+
509+
510+
511+

octoprint_mrbeam/iobeam/temperature_manager.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ def __init__(self, plugin):
2828
self._event_bus = plugin._event_bus
2929
self.temperature = None
3030
self.temperature_ts = 0
31-
self.temperature_max = (
32-
plugin.laserCutterProfileManager.get_current_or_default()["laser"][
33-
"max_temperature"
34-
]
35-
)
31+
self.temperature_max = plugin.laserhead_handler.current_laserhead_max_temperature
3632
self.hysteresis_temperature = (
3733
plugin.laserCutterProfileManager.get_current_or_default()["laser"][
3834
"hysteresis_temperature"
@@ -55,7 +51,7 @@ def __init__(self, plugin):
5551

5652
self.dev_mode = plugin._settings.get_boolean(["dev", "iobeam_disable_warnings"])
5753

58-
msg = "TemperatureManager initialized. temperature_max: {max}, {key}: {value}".format(
54+
msg = "TemperatureManager: initialized. temperature_max: {max}, {key}: {value}".format(
5955
max=self.temperature_max,
6056
key="cooling_duration"
6157
if self.mode_time_based
@@ -74,14 +70,16 @@ def _on_mrbeam_plugin_initialized(self, event, payload):
7470
self._iobeam = self._plugin.iobeam
7571
self._analytics_handler = self._plugin.analytics_handler
7672
self._one_button_handler = self._plugin.onebutton_handler
77-
73+
self._subscribe()
7874
self._start_temp_timer()
7975

80-
self._subscribe()
76+
8177

8278
def _subscribe(self):
8379
self._iobeam.subscribe(IoBeamValueEvents.LASER_TEMP, self.handle_temp)
8480

81+
self._iobeam.subscribe(IoBeamValueEvents.LASERHEAD_CHANGED, self.reset)
82+
8583
self._event_bus.subscribe(OctoPrintEvents.PRINT_DONE, self.onEvent)
8684
self._event_bus.subscribe(OctoPrintEvents.PRINT_FAILED, self.onEvent)
8785
self._event_bus.subscribe(OctoPrintEvents.PRINT_CANCELLED, self.onEvent)
@@ -90,12 +88,9 @@ def _subscribe(self):
9088
def shutdown(self):
9189
self._shutting_down = True
9290

93-
def reset(self):
94-
self.temperature_max = (
95-
self._plugin.laserCutterProfileManager.get_current_or_default()["laser"][
96-
"max_temperature"
97-
]
98-
)
91+
def reset(self, kwargs):
92+
self._logger.info("TemperatureManager: Reset trigger Received : {}".format(kwargs.get("event", None)))
93+
self.temperature_max = self._plugin.laserhead_handler.current_laserhead_max_temperature
9994
self.hysteresis_temperature = (
10095
self._plugin.laserCutterProfileManager.get_current_or_default()["laser"][
10196
"hysteresis_temperature"
@@ -109,15 +104,28 @@ def reset(self):
109104
self.mode_time_based = self.cooling_duration > 0
110105
self.is_cooling_since = 0
111106

107+
msg = "TemperatureManager: Reset Done. temperature_max: {max}, {key}: {value}".format(
108+
max=self.temperature_max,
109+
key="cooling_duration"
110+
if self.mode_time_based
111+
else "hysteresis_temperature",
112+
value=self.cooling_duration
113+
if self.mode_time_based
114+
else self.hysteresis_temperature,
115+
)
116+
self._logger.info(msg)
117+
112118
def onEvent(self, event, payload):
119+
self._logger.debug("TemperatureManager: Event received: {}".format(event))
113120
if event == IoBeamValueEvents.LASER_TEMP:
114121
self.handle_temp(payload)
115122
elif event in (
116123
OctoPrintEvents.PRINT_DONE,
117124
OctoPrintEvents.PRINT_FAILED,
118125
OctoPrintEvents.PRINT_CANCELLED,
119126
):
120-
self.reset()
127+
128+
self.reset({"event": event})
121129
elif event == OctoPrintEvents.SHUTDOWN:
122130
self.shutdown()
123131

octoprint_mrbeam/printing/profiles/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# if set to onebutton, MR Beam 2 One Button to start laser is activated.
1919
start_method="onebutton",
2020
laser=dict(
21-
max_temperature=55.0,
21+
max_temperature=55.0, # deprecated, moved to iobeam.laserhead_handler in SW-1077
2222
hysteresis_temperature=48.0,
2323
cooling_duration=25, # if set to positive values: enables time based cooling resuming rather that per hysteresis_temperature
2424
intensity_factor=13, # to get from 100% intesity to GCODE-intensity of 1300
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
max_temperature: 55.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
max_temperature: 59.0
33.7 KB
Loading

0 commit comments

Comments
 (0)