make same code into a function
This commit is contained in:
parent
525a08c20e
commit
554d78efb7
@ -11,9 +11,7 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin,
|
|||||||
octoprint.plugin.AssetPlugin):
|
octoprint.plugin.AssetPlugin):
|
||||||
|
|
||||||
def on_after_startup(self):
|
def on_after_startup(self):
|
||||||
self.fanSpeed = self._settings.get(["fanSpeed"])
|
self.get_settings_updates()
|
||||||
self.minSpeed = self._settings.get(["minSpeed"])
|
|
||||||
self.maxSpeed = self._settings.get(["maxSpeed"])
|
|
||||||
|
|
||||||
def get_settings_defaults(self):
|
def get_settings_defaults(self):
|
||||||
return dict(
|
return dict(
|
||||||
@ -24,10 +22,7 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin,
|
|||||||
|
|
||||||
def on_settings_save(self, data):
|
def on_settings_save(self, data):
|
||||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||||
|
self.get_settings_updates()
|
||||||
self.fanSpeed = self._settings.get(["fanSpeed"])
|
|
||||||
self.minSpeed = self._settings.get(["minSpeed"])
|
|
||||||
self.maxSpeed = self._settings.get(["maxSpeed"])
|
|
||||||
|
|
||||||
def get_assets(self):
|
def get_assets(self):
|
||||||
return dict(
|
return dict(
|
||||||
@ -40,12 +35,17 @@ class FanSliderPlugin(octoprint.plugin.StartupPlugin,
|
|||||||
dict(type="settings", custom_bindings=False)
|
dict(type="settings", custom_bindings=False)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_settings_updates(self):
|
||||||
|
self.fanSpeed = self._settings.get(["fanSpeed"])
|
||||||
|
self.minSpeed = self._settings.get(["minSpeed"])
|
||||||
|
self.maxSpeed = self._settings.get(["maxSpeed"])
|
||||||
|
|
||||||
|
getcontext().prec=5 #sets precision for "Decimal" not sure if this'll cause conflicts, ideas?
|
||||||
|
self.minPWM = Decimal( Decimal(self.minSpeed) * Decimal(2.55) )
|
||||||
|
self.maxPWM = Decimal( Decimal(self.maxSpeed) * Decimal(2.55) )
|
||||||
|
|
||||||
def rewrite_m106(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
|
def rewrite_m106(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
|
||||||
if gcode and gcode.startswith('M106'):
|
if gcode and gcode.startswith('M106'):
|
||||||
getcontext().prec = 5 #sets precision for "Decimal" not sure if this'll cause conflicts, ideas?
|
|
||||||
self.minPWM = Decimal( Decimal(self.minSpeed) * Decimal(255) / Decimal(100) ) #convoluted mess, could this be reduced to a function
|
|
||||||
self.maxPWM = Decimal( Decimal(self.maxSpeed) * Decimal(255) / Decimal(100) ) #so basically the same thing isn't written twice?
|
|
||||||
#Also move it out of here so it doesn't get calculated every single time the speed is rewritten
|
|
||||||
fanPwm = re.search("S(\d+.\d+)", cmd)
|
fanPwm = re.search("S(\d+.\d+)", cmd)
|
||||||
if fanPwm and fanPwm.group(1):
|
if fanPwm and fanPwm.group(1):
|
||||||
fanPwm = fanPwm.group(1)
|
fanPwm = fanPwm.group(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user