11
11
12
12
from octoprint_SpoolManager .DatabaseManager import DatabaseManager
13
13
# from octoprint_SpoolManager.Odometer import FilamentOdometer
14
+
14
15
from octoprint_SpoolManager .newodometer import NewFilamentOdometer
15
16
16
17
from octoprint_SpoolManager .api import Transformer
17
18
from octoprint_SpoolManager .api .SpoolManagerAPI import SpoolManagerAPI
18
19
from octoprint_SpoolManager .common import StringUtils
19
20
from octoprint_SpoolManager .common .SettingsKeys import SettingsKeys
21
+ from octoprint_SpoolManager .common .EventBusKeys import EventBusKeys
20
22
21
23
class SpoolmanagerPlugin (
22
24
SpoolManagerAPI ,
@@ -62,7 +64,6 @@ def initialize(self):
62
64
self ._logger .info ("Done initializing" )
63
65
pass
64
66
65
-
66
67
################################################################################################### public functions
67
68
68
69
def checkRemainingFilament (self , forToolIndex = None ):
@@ -134,6 +135,12 @@ def _sendMessageToClient(self, type, title, message, autoclose=False):
134
135
message = message ,
135
136
autoclose = autoclose ))
136
137
138
+ def _sendPayload2EventBus (self , eventKey , eventPayload ):
139
+
140
+ eventName = "plugin_spoolmanager_" + eventKey
141
+ self ._logger .info ("Send Event '" + eventName + "' with payload '" + str (eventPayload )+ "' to event-bus" )
142
+ self ._event_bus .fire (eventName , payload = eventPayload )
143
+
137
144
def _checkForMissingPluginInfos (self , sendToClient = False ):
138
145
139
146
pluginInfo = self ._getPluginInformation ("filamentmanager" )
@@ -275,14 +282,23 @@ def _evaluateRequiredWeight(self, selectedSpools, forToolIndex=None, warnUser=Fa
275
282
someAttributesMissing = True
276
283
else :
277
284
# Benötigtes Gewicht = gewicht(geplante länge, durchmesser, dichte)
278
- requiredWeight = int ( self ._calculateWeight (filamentLength , diameter , density ) )
285
+ requiredWeight = self ._calculateWeight (filamentLength , diameter , density )
279
286
280
287
# Vorhanden Gewicht = Gesamtgewicht - Verbrauchtes Gewicht
281
288
# TODO don't calculate here use the value from the database
282
289
remainingWeight = totalWeight - usedWeight
283
290
291
+ saftyLengthInMM = self ._settings .get_int ([SettingsKeys .SETTINGS_KEY_SAFETY_LENGTH ])
292
+ if (saftyLengthInMM != 0 ):
293
+ saftyRequiredWeight = self ._calculateWeight (saftyLengthInMM , diameter , density )
294
+ self ._logger .info ("saftyWeight '" + str (saftyRequiredWeight ) + "' from saftyLengthInMM '" + str (saftyLengthInMM ) + "' calculated" )
295
+ requiredWeight = requiredWeight + saftyRequiredWeight
296
+
297
+ self ._logger .info ("tool" + str (toolIndex ) + ", requiredWeight '" + str (requiredWeight ) + "', remainingWeight '" + str (remainingWeight ) + "'" )
298
+
284
299
notEnough = False
285
300
if remainingWeight < requiredWeight and requiredWeight > 0 :
301
+ self ._logger .info ("Filament not enough!" )
286
302
if (warnUser == True ):
287
303
self ._sendMessageToClient (
288
304
"warning" , "Filament not enough!" ,
@@ -425,6 +441,7 @@ def _on_printJobStarted(self):
425
441
action = "reloadTable"
426
442
))
427
443
# assign the current extrusion to the current selected spools
444
+
428
445
def commitOdometerData (self ):
429
446
reload = False
430
447
selectedSpools = self .loadSelectedSpools ()
@@ -465,6 +482,17 @@ def commitOdometerData(self):
465
482
self ._logger .info ("Tool %d: New spoolUsedWeight: %s" % (toolIndex , str (newUsedWeight )))
466
483
467
484
self ._databaseManager .saveSpool (spoolModel )
485
+
486
+ eventPayload = {
487
+ "toolId" : toolIndex ,
488
+ "databaseId" : spoolModel .databaseId ,
489
+ "spoolName" : spoolModel .displayName ,
490
+ "material" : spoolModel .material ,
491
+ "colorName" : spoolModel .colorName ,
492
+ "remainingWeight" : spoolModel .remainingWeight
493
+ }
494
+ self ._sendPayload2EventBus (EventBusKeys .EVENT_BUS_SPOOL_WEIGHT_UPDATED_AFTER_PRINT , eventPayload )
495
+
468
496
reload = True
469
497
470
498
self .myFilamentOdometer .reset_extruded_length ()
@@ -597,6 +625,13 @@ def on_sentGCodeHook(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **
597
625
598
626
def on_event (self , event , payload ):
599
627
628
+ # if (event != "RegisteredMessageReceived"):
629
+ # print("*** EVENT: " + event)
630
+ #
631
+ # if ("plugin_spoolmanager" in event):
632
+ # print(payload)
633
+ # pass
634
+
600
635
if (Events .CLIENT_OPENED == event ):
601
636
self ._on_clientOpened (payload )
602
637
return
@@ -714,11 +749,14 @@ def get_settings_defaults(self):
714
749
settings [SettingsKeys .SETTINGS_KEY_WARN_IF_SPOOL_NOT_SELECTED ] = True
715
750
settings [SettingsKeys .SETTINGS_KEY_WARN_IF_FILAMENT_NOT_ENOUGH ] = True
716
751
settings [SettingsKeys .SETTINGS_KEY_CURRENCY_SYMBOL ] = "€"
752
+ settings [SettingsKeys .SETTINGS_KEY_SAFETY_LENGTH ] = 0
717
753
718
754
## QR-Code
719
755
settings [SettingsKeys .SETTINGS_KEY_QR_CODE_ENABLED ] = True
720
- settings [SettingsKeys .SETTINGS_KEY_QR_CODE_FILL_COLOR ] = "darkgreen"
721
- settings [SettingsKeys .SETTINGS_KEY_QR_CODE_BACKGROUND_COLOR ] = "white"
756
+ settings [SettingsKeys .SETTINGS_KEY_QR_CODE_USE_URL_PREFIX ] = False
757
+ settings [SettingsKeys .SETTINGS_KEY_QR_CODE_URL_PREFIX ] = None
758
+ settings [SettingsKeys .SETTINGS_KEY_QR_CODE_FILL_COLOR ] = "#008000"
759
+ settings [SettingsKeys .SETTINGS_KEY_QR_CODE_BACKGROUND_COLOR ] = "#ffffff"
722
760
settings [SettingsKeys .SETTINGS_KEY_QR_CODE_WIDTH ] = "100"
723
761
settings [SettingsKeys .SETTINGS_KEY_QR_CODE_HEIGHT ] = "100"
724
762
@@ -756,6 +794,7 @@ def get_settings_defaults(self):
756
794
# "password": "illO"
757
795
# }
758
796
797
+ settings ["excludedFromTemplateCopy" ] = []
759
798
return settings
760
799
761
800
##~~ TemplatePlugin mixin
@@ -838,12 +877,13 @@ def get_update_information(self):
838
877
)
839
878
)
840
879
841
-
842
-
843
-
844
-
845
-
846
-
880
+ def register_custom_events (* args , ** kwargs ):
881
+ return [EventBusKeys .EVENT_BUS_SPOOL_WEIGHT_UPDATED_AFTER_PRINT ,
882
+ EventBusKeys .EVENT_BUS_SPOOL_SELECTED ,
883
+ EventBusKeys .EVENT_BUS_SPOOL_DESELECTED ,
884
+ EventBusKeys .EVENT_BUS_SPOOL_ADDED ,
885
+ EventBusKeys .EVENT_BUS_SPOOL_DELETED
886
+ ]
847
887
848
888
849
889
@@ -870,7 +910,8 @@ def __plugin_load__():
870
910
global __plugin_hooks__
871
911
__plugin_hooks__ = {
872
912
"octoprint.plugin.softwareupdate.check_config" : __plugin_implementation__ .get_update_information ,
873
- "octoprint.comm.protocol.gcode.sent" : __plugin_implementation__ .on_sentGCodeHook
913
+ "octoprint.comm.protocol.gcode.sent" : __plugin_implementation__ .on_sentGCodeHook ,
874
914
# "octoprint.comm.protocol.scripts": __plugin_implementation__.message_on_connect
915
+ "octoprint.events.register_custom_events" : __plugin_implementation__ .register_custom_events
875
916
}
876
917
0 commit comments