Skip to content

Commit

Permalink
add M118 E1 TASMOTA_M150 support for better real-time LED handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed May 18, 2021
1 parent b745da4 commit 127de45
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
69 changes: 38 additions & 31 deletions octoprint_tasmota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,42 @@ def gcode_led(self, plugip, led_data):
except Exception as e:
self._logger.debug("Error: {}".format(e))

def process_echo(self, comm, line, *args, **kwargs):
if not line.startswith("TASMOTA_M150"):
return line

plugip = None
workleds = dict(LEDRed=0, LEDBlue=0, LEDGreen=0, LEDWhite=0, LEDBrightness=-1)
workval = line.upper().split()
for i in workval:
firstchar = str(i[0].upper())
leddata = str(i[1:].strip())
if not leddata.isdigit() and firstchar not in ["I", "T"]:
self._tasmota_logger.debug(leddata)
return line

if firstchar == 'T':
continue
elif firstchar == "I":
plugip = leddata
elif firstchar == 'R':
workleds['LEDRed'] = int(leddata)
elif firstchar == 'G' or firstchar == 'U':
workleds['LEDGreen'] = int(leddata)
elif firstchar == 'B':
workleds['LEDBlue'] = int(leddata)
elif firstchar == "W":
workleds['LEDWhite'] = int(float(leddata) / 255 * 100)
elif firstchar == "P":
workleds['LEDBrightness'] = int(float(leddata) / 255 * 100)
else:
self._tasmota_logger.debug(leddata)

if plugip is not None:
t = threading.Timer(0, self.gcode_led, [plugip, workleds])
t.daemon = True
t.start()

def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
if gcode:
if gcode in ["M80", "M81"] and cmd.count(" ") >= 2:
Expand All @@ -721,37 +757,7 @@ def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwar
else:
return
elif gcode == "M150":
plugip = None
workleds = dict(LEDRed=0, LEDBlue=0, LEDGreen=0, LEDWhite=0, LEDBrightness=-1)
workval = cmd.upper().split()
for i in workval:
firstchar = str(i[0].upper())
leddata = str(i[1:].strip())
if not leddata.isdigit() and firstchar != 'I':
self._tasmota_logger.debug(leddata)
return

if firstchar == 'M':
continue
elif firstchar == "I":
plugip = leddata
elif firstchar == 'R':
workleds['LEDRed'] = int(leddata)
elif firstchar == 'G' or firstchar == 'U':
workleds['LEDGreen'] = int(leddata)
elif firstchar == 'B':
workleds['LEDBlue'] = int(leddata)
elif firstchar == "W":
workleds['LEDWhite'] = int(float(leddata)/255*100)
elif firstchar == "P":
workleds['LEDBrightness'] = int(float(leddata)/255*100)
else:
self._tasmota_logger.debug(leddata)

if plugip is not None:
t = threading.Timer(0, self.gcode_led, [plugip, workleds])
t.daemon = True
t.start()
self.process_echo(comm_instance, "TASMOTA_{}".format(cmd), *args, **kwargs)
elif self.powerOffWhenIdle and not (gcode in self._idleIgnoreCommandsArray):
self._waitForHeaters = False
self._reset_idle_timer()
Expand Down Expand Up @@ -1031,6 +1037,7 @@ def __plugin_load__():
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.processGCODE,
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.process_echo,
"octoprint.comm.protocol.temperatures.received": __plugin_implementation__.monitor_temperatures,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-Tasmota"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.0.4rc3"
plugin_version = "1.0.4rc4"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 127de45

Please sign in to comment.