gcode partial implementation
This commit is contained in:
@@ -161,6 +161,13 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
|
||||
rpi_output['gpio_pin']), self.to_int(pwm_val))
|
||||
return flask.jsonify(success=True)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/sendGcodeCommand", methods=["GET"])
|
||||
def requested_gcode_command(self):
|
||||
gpio_index = self.to_int(flask.request.values["index_id"])
|
||||
rpi_output = [r_out for r_out in self.rpi_outputs if self.to_int(r_out['index_id']) == gpio_index].pop()
|
||||
self.send_gcode_command(rpi_output['gcode'])
|
||||
return flask.jsonify(success=True)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/setNeopixel", methods=["GET"])
|
||||
def set_neopixel(self):
|
||||
""" set_neopixel method get request from octoprint and send the comand to arduino or neopixel"""
|
||||
@@ -647,7 +654,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
|
||||
gpio_pin = self.to_int(rpi_input['gpio_pin'])
|
||||
GPIO.setup(gpio_pin, GPIO.IN, pullResistor)
|
||||
edge = GPIO.RISING if rpi_input['edge'] == 'rise' else GPIO.FALLING
|
||||
if rpi_input['action_type'] == 'gpio_control':
|
||||
if rpi_input['action_type'] == 'output_control':
|
||||
self._logger.info(
|
||||
"Adding GPIO event detect on pin %s with edge: %s", gpio_pin, edge)
|
||||
GPIO.add_event_detect(gpio_pin, edge, callback=self.handle_gpio_control, bouncetime=200)
|
||||
@@ -748,19 +755,25 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
|
||||
controlled_io = self.to_int(rpi_input['controlled_io'])
|
||||
if ((rpi_input['edge'] == 'fall') ^ GPIO.input(gpio_pin)):
|
||||
rpi_output = [r_out for r_out in self.rpi_outputs if self.to_int(r_out['index_id']) == controlled_io].pop()
|
||||
|
||||
if rpi_input['controlled_io_set_value'] == 'toggle':
|
||||
val = GPIO.LOW if GPIO.input(self.to_int(
|
||||
rpi_output['gpio_pin'])) == GPIO.HIGH else GPIO.HIGH
|
||||
else:
|
||||
val = GPIO.LOW if rpi_input['controlled_io_set_value'] == 'low' else GPIO.HIGH
|
||||
self.write_gpio(self.to_int(
|
||||
rpi_output['gpio_pin']), val)
|
||||
for notification in self.notifications:
|
||||
if notification['gpioAction']:
|
||||
msg = "GPIO control action caused by input " + str(rpi_input['label']) + ". Setting GPIO" + str(
|
||||
rpi_input['controlled_io']) + " to: " + str(rpi_input['controlled_io_set_value'])
|
||||
self.send_notification(msg)
|
||||
if rpi_output['output_type'] == 'regular':
|
||||
if rpi_input['controlled_io_set_value'] == 'toggle':
|
||||
val = GPIO.LOW if GPIO.input(self.to_int(
|
||||
rpi_output['gpio_pin'])) == GPIO.HIGH else GPIO.HIGH
|
||||
else:
|
||||
val = GPIO.LOW if rpi_input['controlled_io_set_value'] == 'low' else GPIO.HIGH
|
||||
self.write_gpio(self.to_int(
|
||||
rpi_output['gpio_pin']), val)
|
||||
for notification in self.notifications:
|
||||
if notification['gpioAction']:
|
||||
msg = "GPIO control action caused by input " + str(rpi_input['label']) + ". Setting GPIO" + str(
|
||||
rpi_input['controlled_io']) + " to: " + str(rpi_input['controlled_io_set_value'])
|
||||
self.send_notification(msg)
|
||||
if rpi_output['output_type'] == 'gcode_output':
|
||||
self.send_gcode_command(rpi_output['gcode'])
|
||||
for notification in self.notifications:
|
||||
if notification['gpioAction']:
|
||||
msg = "GPIO control action caused by input " + str(rpi_input['label']) + ". Sending GCODE command"
|
||||
self.send_notification(msg)
|
||||
except Exception as ex:
|
||||
template = "An exception of type {0} occurred on {1}. Arguments:\n{2!r}"
|
||||
message = template.format(
|
||||
@@ -768,6 +781,14 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
|
||||
self._logger.warn(message)
|
||||
pass
|
||||
|
||||
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())
|
||||
time.sleep(0.2)
|
||||
|
||||
def handle_printer_action(self, channel):
|
||||
try:
|
||||
for rpi_input in self.rpi_inputs:
|
||||
|
||||
@@ -17,6 +17,12 @@ $(function () {
|
||||
});
|
||||
});
|
||||
|
||||
self.rpi_possible_outputs = ko.pureComputed(function () {
|
||||
return ko.utils.arrayFilter(self.rpi_outputs(), function (item) {
|
||||
return (item.output_type() === "regular" || item.output_type() === "gcode_output");
|
||||
});
|
||||
});
|
||||
|
||||
self.rpi_outputs_pwm = ko.pureComputed(function () {
|
||||
return ko.utils.arrayFilter(self.rpi_outputs(), function (item) {
|
||||
return (item.output_type() === "pwm");
|
||||
@@ -280,6 +286,7 @@ $(function () {
|
||||
output_type: ko.observable("regular"),
|
||||
gpio_pin: ko.observable(0),
|
||||
gpio_status: ko.observable(false),
|
||||
hide_btn_ui: ko.observable(false),
|
||||
active_low: ko.observable(true),
|
||||
auto_startup: ko.observable(false),
|
||||
controlled_io: ko.observable(0),
|
||||
@@ -334,7 +341,7 @@ $(function () {
|
||||
temp_sensor_humidity: ko.observable(""),
|
||||
ds18b20_serial: ko.observable(""),
|
||||
use_fahrenheit: ko.observable(false),
|
||||
action_type: ko.observable("gpio_control"),
|
||||
action_type: ko.observable("output_control"),
|
||||
controlled_io: ko.observable(""),
|
||||
controlled_io_set_value: ko.observable("low"),
|
||||
edge: ko.observable("fall"),
|
||||
|
||||
@@ -87,6 +87,20 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
|
||||
|
||||
<!-- ko if: ($data.output_type() == "regular" || $data.output_type() == "gcode_output" ) -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: hide_btn_ui"> {{ _('Hide UI Button') }}
|
||||
</label>
|
||||
<span class="help-inline">If you plan to use a physical button (INPUT) and want to hide the button from enclosure tab check this.</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
|
||||
|
||||
<!-- ko ifnot: ($data.output_type() == "gcode_output" || $data.output_type() == "temperature_alarm" ) -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
@@ -411,7 +425,7 @@
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Action Type') }}</label>
|
||||
<div class="controls">
|
||||
<input type="radio" value="gpio_control" data-bind="checked: action_type, attr: {name: 'actionType_' + $index() }"> {{ _('GPIO Control') }}
|
||||
<input type="radio" value="output_control" data-bind="checked: action_type, attr: {name: 'actionType_' + $index() }"> {{ _('Output Control') }}
|
||||
</div>
|
||||
<div class="controls">
|
||||
<input type="radio" value="printer_control" data-bind="checked: action_type, attr: {name: 'actionType_' + $index() }"> {{ _('Printer') }}
|
||||
@@ -426,7 +440,7 @@
|
||||
sensor conects to ground when detects the end of the filament, you should choose PULL UP resistors and detect
|
||||
the event on the falling edge.</span>
|
||||
<!-- /ko -->
|
||||
<!-- ko if: ($data.action_type() == "gpio_control") -->
|
||||
<!-- ko if: ($data.action_type() == "output_control") -->
|
||||
<span class="help-inline">
|
||||
<span class="label label-info">Info:</span> Action will control GPIO outputs when a condition is met, for example detect a press of a button.
|
||||
You can use this to control any previous configured OUTPUTS, basically beeing able to control your lights / fan
|
||||
@@ -471,14 +485,14 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ko if: ($data.action_type() == "gpio_control") -->
|
||||
<!-- ko if: ($data.action_type() == "output_control") -->
|
||||
<div class="control-group">
|
||||
<label class="control-label"> Controlled IO</label>
|
||||
<div class="controls">
|
||||
<select data-bind="options: $root.rpi_outputs_regular, optionsText: 'label',
|
||||
<select data-bind="options: $root.rpi_possible_outputs, optionsText: 'label',
|
||||
optionsValue: 'index_id', value: $data.controlled_io">
|
||||
</select>
|
||||
<span class="help-inline">When the event happen, you want control which IO?</span>
|
||||
<span class="help-inline">When the event happen, you want control which OUTPUT?</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko foreach: $root.rpi_outputs() -->
|
||||
<!-- ko if: ($data.output_type() == "regular") -->
|
||||
<!-- ko if: ($data.output_type() == "regular" || (!data.hide_btn_ui())) -->
|
||||
|
||||
<h4>
|
||||
<span data-bind="html: label"> </span>
|
||||
|
||||
Reference in New Issue
Block a user