diff --git a/.gitignore b/.gitignore index 564ea90..3f311b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode *.pyc -*.egg-info* +*.egg-info +.DS_Store diff --git a/octoprint_enclosure/old_stuff/SI7021.py b/octoprint_enclosure/old_stuff/SI7021.py index 6b352f1..3e1eb60 100644 --- a/octoprint_enclosure/old_stuff/SI7021.py +++ b/octoprint_enclosure/old_stuff/SI7021.py @@ -3,14 +3,18 @@ import time import sys -if len(sys.argv) == 2: +if len(sys.argv) == 2 or len(sys.argv) == 3: address = int(sys.argv[1],16) + if len(sys.argv) == 3: + busNum = int(sys.argv[2],16) + else: + busNum = 1 else: print('-1 | -1') sys.exit(1) # Get I2C bus -bus = smbus.SMBus(1) +bus = smbus.SMBus(busNum) # SI7021 address, 0x40(64) # 0xF5(245) Select Relative Humidity NO HOLD master mode diff --git a/octoprint_enclosure/old_stuff/__init__.py b/octoprint_enclosure/old_stuff/__init__.py index d66a07b..473321c 100644 --- a/octoprint_enclosure/old_stuff/__init__.py +++ b/octoprint_enclosure/old_stuff/__init__.py @@ -23,6 +23,35 @@ import json import copy +#Function that returns Boolean output state of the GPIO inputs / outputs +def PinState_Boolean(pin, ActiveLow) : + try: + state = GPIO.input(pin) + if ActiveLow and not state: return True + if not ActiveLow and state: return True + return False + except: + return "ERROR: Unable to read pin" + +#Function that returns human-readable output state of the GPIO inputs / outputs +def PinState_Human(pin, ActiveLow): + PinState = PinState_Boolean(pin, ActiveLow) + if PinState == True : + return " ON " + elif PinState == False: + return " OFF " + else: + return PinState + +#Translates the Pull-Up/Pull-Down GPIO resistor setting to ActiveLow/ActiveHigh boolean +def CheckInputActiveLow(Input_Pull_Resistor): + #input_pull_up + #input_pull_down + if Input_Pull_Resistor == "input_pull_up": + return True + else: + return False + class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.SettingsPlugin, octoprint.plugin.AssetPlugin, octoprint.plugin.BlueprintPlugin, octoprint.plugin.EventHandlerPlugin): @@ -52,10 +81,8 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP @staticmethod def to_float(value): """Converts value to flow - Arguments: value {any} -- value to be - Returns: float -- value converted """ @@ -100,7 +127,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP for command in command_string.split(' '): index = command.upper().find(gcode.upper()) if not index == -1: - return command.replace(gcode, '').upper() + return command.replace(gcode, '') return -1 # ~~ StartupPlugin mixin @@ -144,6 +171,40 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP self._settings.set(["rpi_inputs"], []) self.rpi_inputs = self._settings.get(["rpi_inputs"]) + #Scan all configured inputs and outputs and return the pin value + @octoprint.plugin.BlueprintPlugin.route("/ReadPin/", methods=["GET"]) + def ReadSinglePin(self, identifier): + Resp = [] + MatchFound = False + for rpi_input in self.rpi_inputs: + if identifier == self.to_int(rpi_input['gpio_pin']): + MatchFound = True + ConfiguredAs = "Input" + ActiveLow = CheckInputActiveLow(rpi_input['input_pull_resistor']) + pin = self.to_int(rpi_input['gpio_pin']) + val = PinState_Human(pin,ActiveLow) + label = rpi_input['label'] + Resp.append(dict(Configured_As=ConfiguredAs, label=label, GPIO_Pin=pin, Active_Low=ActiveLow, State=val)) + for rpi_output in self.rpi_outputs: + if identifier == self.to_int(rpi_output['gpio_pin']): + MatchFound = True + ConfiguredAs = "Output" + ActiveLow = CheckInputActiveLow(rpi_output['active_low']) + pin = self.to_int(rpi_output['gpio_pin']) + val = PinState_Human(pin,ActiveLow) + label = rpi_output['label'] + Resp.append(dict(Configured_As=ConfiguredAs, label=label, GPIO_Pin=pin, Active_Low=ActiveLow, State=val)) + if MatchFound == False: + pin = int(identifier) + ConfiguredAs = "Unknown" + ActiveLow = "Unknown" + try: + val = GPIO.input(pin) + except: + val = "GPIO pin not initialized." + Resp.append(dict(Configured_As=ConfiguredAs, GPIO_Pin=pin, Active_Low=ActiveLow, State=val)) + return Response(json.dumps(Resp), mimetype='application/json') + # ~~ Blueprintplugin mixin @octoprint.plugin.BlueprintPlugin.route("/inputs", methods=["GET"]) def get_inputs(self): @@ -151,10 +212,12 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP for rpi_input in self.rpi_inputs: index = self.to_int(rpi_input['index_id']) label = rpi_input['label'] - inputs.append(dict(index_id=index, label=label)) + ActiveLow = CheckInputActiveLow(rpi_input['input_pull_resistor']) + pin = self.to_int(rpi_input['gpio_pin']) + val = PinState_Human(pin,ActiveLow) + inputs.append(dict(index_id=index, label=label, GPIO_Pin=pin, State=val)) return Response(json.dumps(inputs), mimetype='application/json') - @octoprint.plugin.BlueprintPlugin.route("/inputs/", methods=["GET"]) def get_input_status(self, identifier): for rpi_input in self.rpi_inputs: @@ -207,7 +270,6 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP self._settings.set(["rpi_inputs"], self.rpi_inputs) return make_response('', 204) - @octoprint.plugin.BlueprintPlugin.route("/outputs", methods=["GET"]) def get_outputs(self): outputs = [] @@ -215,7 +277,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP if rpi_output['output_type'] == 'regular': index = self.to_int(rpi_output['index_id']) label = rpi_output['label'] - outputs.append(dict(index_id=index, label=label)) + pin = self.to_int(rpi_output['gpio_pin']) + ActiveLow = rpi_output['active_low'] + val = PinState_Human(pin,ActiveLow) + outputs.append(dict(index_id=index, label=label, GPIO_Pin=pin, State=val)) return Response(json.dumps(outputs), mimetype='application/json') @@ -225,7 +290,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP if identifier == self.to_int(rpi_output['index_id']): out = copy.deepcopy(rpi_output) pin = self.to_int(rpi_output['gpio_pin']) - out['current_value'] = GPIO.input(pin) if not rpi_output['active_low'] else (not GPIO.input(pin)) + out['current_value'] = PinState_Boolean(pin, rpi_output['active_low'] ) return Response(json.dumps(out), mimetype='application/json') return make_response('', 404) @@ -454,9 +519,11 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP for rpi_output in self.rpi_outputs: if rpi_output['output_type'] == 'regular': pin = self.to_int(rpi_output['gpio_pin']) - val = GPIO.input(pin) if not rpi_output['active_low'] else (not GPIO.input(pin)) + ActiveLow = rpi_output['active_low'] + val = PinState_Boolean(pin, ActiveLow) + val2 = PinState_Human(pin, ActiveLow) index = self.to_int(rpi_output['index_id']) - gpio_status.append(dict(index_id=index, status=val)) + gpio_status.append(dict(index_id=index, status=val, State=val2)) return Response(json.dumps(gpio_status), mimetype='application/json') @octoprint.plugin.BlueprintPlugin.route("/setIO", methods=["GET"]) @@ -581,7 +648,6 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP def send_neopixel_command(self, led_pin, led_count, led_brightness, red, green, blue, address, neopixel_dirrect, index_id, queue_id=None): """Send neopixel command - Arguments: led_pin {int} -- GPIO number ledCount {int} -- number of LEDS @@ -800,7 +866,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP elif sensor['temp_sensor_type'] == "am2320": temp, hum = self.read_am2320_temp() # sensor has fixed address elif sensor['temp_sensor_type'] == "si7021": - temp, hum = self.read_si7021_temp(sensor['temp_sensor_address']) + temp, hum = self.read_si7021_temp(sensor['temp_sensor_address'], sensor['temp_sensor_i2cbus']) elif sensor['temp_sensor_type'] == "tmp102": temp = self.read_tmp102_temp(sensor['temp_sensor_address']) hum = 0 @@ -835,7 +901,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP for rpi_controlled_output in self.rpi_outputs: if self.to_int(temperature_alarm['controlled_io']) == self.to_int( rpi_controlled_output['index_id']): - val = GPIO.LOW if rpi_controlled_output['active_low'] else GPIO.HIGH + val = GPIO.LOW if temperature_alarm['controlled_io_set_value'] == 'low' else GPIO.HIGH self.write_gpio(self.to_int(rpi_controlled_output['gpio_pin']), val) for notification in self.notifications: if notification['temperatureAction']: @@ -864,7 +930,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout, _ = proc.communicate() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("MCP9808 result: %s", stdout) - return self.to_float(stdout.strip()) + return self.to_float(stdout.decode("utf-8").strip()) except Exception as ex: self._logger.info("Failed to execute python scripts, try disabling use SUDO on advanced section.") self.log_error(ex) @@ -883,7 +949,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("Dht result: %s", stdout) - temp, hum = stdout.split("|") + temp, hum = stdout.decode("utf-8").split("|") return (self.to_float(temp.strip()), self.to_float(hum.strip())) except Exception as ex: self._logger.info( @@ -904,7 +970,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("BME280 result: %s", stdout) - temp, hum = stdout.split("|") + temp, hum = stdout.decode("utf-8").split("|") return (self.to_float(temp.strip()), self.to_float(hum.strip())) except Exception as ex: self._logger.info( @@ -925,7 +991,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("AM2320 result: %s", stdout) - temp, hum = stdout.split("|") + temp, hum = stdout.decode("utf-8").split("|") return (self.to_float(temp.strip()), self.to_float(hum.strip())) except Exception as ex: self._logger.info( @@ -933,20 +999,20 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP self.log_error(ex) return (0, 0) - def read_si7021_temp(self, address): + def read_si7021_temp(self, address, i2cbus): try: script = os.path.dirname(os.path.realpath(__file__)) + "/SI7021.py " if self._settings.get(["use_sudo"]): sudo_str = "sudo " else: sudo_str = "" - cmd = sudo_str + "python " + script + str(address) + cmd = sudo_str + "python " + script + str(address) + " " + str(i2cbus) if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("Temperature SI7021 cmd: %s", cmd) stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("SI7021 result: %s", stdout) - temp, hum = stdout.split("|") + temp, hum = stdout.decode("utf-8").split("|") return (self.to_float(temp.strip()), self.to_float(hum.strip())) except Exception as ex: self._logger.info( @@ -990,7 +1056,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout, _ = proc.communicate() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("TMP102 result: %s", stdout) - return self.to_float(stdout.strip()) + return self.to_float(stdout.decode("utf-8").strip()) except Exception as ex: self._logger.info("Failed to execute python scripts, try disabling use SUDO on advanced section.") self.log_error(ex) @@ -1006,7 +1072,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout, _ = proc.communicate() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("MAX31855 result: %s", stdout) - return self.to_float(stdout.strip()) + return self.to_float(stdout.decode("utf-8").strip()) except Exception as ex: self._logger.info("Failed to execute python scripts, try disabling use SUDO on advanced section.") self.log_error(ex) @@ -1261,8 +1327,8 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP item['time'] = time_now for line in self._settings.get(["filament_sensor_gcode"]).split('\n'): if line: - self._printer.commands(line.strip().upper()) - self._logger.info("Sending GCODE command: %s", line.strip().upper()) + self._printer.commands(line.strip()) + self._logger.info("Sending GCODE command: %s", line.strip()) time.sleep(0.2) for notification in self.notifications: if notification['filamentChange']: @@ -1378,8 +1444,8 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP def send_gcode_command(self, command): for line in command.split('\n'): if line: - self._printer.commands(line.strip().upper()) - self._logger.info("Sending GCODE command: %s", line.strip().upper()) + self._printer.commands(line.strip()) + self._logger.info("Sending GCODE command: %s", line.strip()) time.sleep(0.2) def handle_printer_action(self, channel): @@ -1880,7 +1946,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP __plugin_name__ = "Enclosure Plugin" -__plugin_pythoncompat__ = ">=3,<4" +__plugin_pythoncompat__ = ">=2.7,<4" def __plugin_load__(): @@ -1891,4 +1957,4 @@ def __plugin_load__(): __plugin_hooks__ = { "octoprint.comm.protocol.gcode.queuing" : __plugin_implementation__.hook_gcode_queuing, "octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information - } \ No newline at end of file + } diff --git a/octoprint_enclosure/old_stuff/neopixel_direct.py b/octoprint_enclosure/old_stuff/neopixel_direct.py index 3af63f9..6259377 100644 --- a/octoprint_enclosure/old_stuff/neopixel_direct.py +++ b/octoprint_enclosure/old_stuff/neopixel_direct.py @@ -17,7 +17,7 @@ else: print("fail") sys.exit(1) -strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT) +strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS) strip.begin() color = Color(red, green, blue) diff --git a/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css b/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css index 0dfa89c..26cb0de 100644 --- a/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css +++ b/octoprint_enclosure/old_stuff/static/css/bootstrap-colorpicker.css @@ -226,4 +226,5 @@ } .colorpicker-inline.colorpicker-visible { display: inline-block; -} \ No newline at end of file +} +/*# sourceMappingURL=bootstrap-colorpicker.css.map */ \ No newline at end of file diff --git a/octoprint_enclosure/old_stuff/static/js/enclosure.js b/octoprint_enclosure/old_stuff/static/js/enclosure.js index b7a96e5..e9c4847 100644 --- a/octoprint_enclosure/old_stuff/static/js/enclosure.js +++ b/octoprint_enclosure/old_stuff/static/js/enclosure.js @@ -455,7 +455,8 @@ $(function () { printer_action: ko.observable("filament"), temp_sensor_navbar: ko.observable(true), filament_sensor_timeout: ko.observable(120), - filament_sensor_enabled: ko.observable(true) + filament_sensor_enabled: ko.observable(true), + temp_sensor_i2cbus: ko.observable(1) }); }; @@ -706,4 +707,4 @@ $(function () { elements: ["#tab_plugin_enclosure", "#settings_plugin_enclosure", "#navbar_plugin_enclosure_1", "#navbar_plugin_enclosure_2"] }); -}); \ No newline at end of file +}); diff --git a/octoprint_enclosure/old_stuff/templates/enclosure_settings.jinja2 b/octoprint_enclosure/old_stuff/templates/enclosure_settings.jinja2 index 5195bbe..a30ca69 100644 --- a/octoprint_enclosure/old_stuff/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/old_stuff/templates/enclosure_settings.jinja2 @@ -11,7 +11,7 @@ - + - + - + - +
@@ -98,8 +98,8 @@ GPIO number that will be controlled. - /ko - ko if: ($data.output_type() == "neopixel_indirect") + + Attention Neopixel requires a microcontroller (ex: arduino) connected to I2C bus. This is the pin on the @@ -328,22 +328,22 @@
- + - +
@@ -387,7 +387,7 @@
- +
@@ -413,7 +413,7 @@
- + - +
@@ -582,6 +582,14 @@ i2cdetect -y 1 on your Raspberry Pi
+
+ +
+ + This value should remain 1 unless you've used dtoverlay=i2c-gpio. + +
+
@@ -901,4 +909,4 @@
- \ No newline at end of file + diff --git a/octoprint_enclosure/templates/input_folder/general_info.jinja2 b/octoprint_enclosure/templates/input_folder/general_info.jinja2 new file mode 100644 index 0000000..da6de71 --- /dev/null +++ b/octoprint_enclosure/templates/input_folder/general_info.jinja2 @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file diff --git a/octoprint_enclosure/templates/input_folder/io_output.jinja2 b/octoprint_enclosure/templates/input_folder/io_output.jinja2 new file mode 100644 index 0000000..da6de71 --- /dev/null +++ b/octoprint_enclosure/templates/input_folder/io_output.jinja2 @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file diff --git a/octoprint_enclosure/templates/input_folder/main_screen.jinja2 b/octoprint_enclosure/templates/input_folder/main_screen.jinja2 new file mode 100644 index 0000000..4cf6b04 --- /dev/null +++ b/octoprint_enclosure/templates/input_folder/main_screen.jinja2 @@ -0,0 +1,59 @@ + \ No newline at end of file diff --git a/octoprint_enclosure/templates/input_folder/output_action.jinja2 b/octoprint_enclosure/templates/input_folder/output_action.jinja2 new file mode 100644 index 0000000..da6de71 --- /dev/null +++ b/octoprint_enclosure/templates/input_folder/output_action.jinja2 @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file diff --git a/octoprint_enclosure/templates/input_folder/printer_action.jinja2 b/octoprint_enclosure/templates/input_folder/printer_action.jinja2 new file mode 100644 index 0000000..da6de71 --- /dev/null +++ b/octoprint_enclosure/templates/input_folder/printer_action.jinja2 @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file diff --git a/octoprint_enclosure/templates/input_folder/temperature_sensor.jinja2 b/octoprint_enclosure/templates/input_folder/temperature_sensor.jinja2 new file mode 100644 index 0000000..da6de71 --- /dev/null +++ b/octoprint_enclosure/templates/input_folder/temperature_sensor.jinja2 @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file diff --git a/octoprint_enclosure/templates/input_table.jinja2 b/octoprint_enclosure/templates/input_table.jinja2 new file mode 100644 index 0000000..e69de29