helpers
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
||||
*.egg-info
|
||||
.DS_Store
|
||||
config.yaml
|
||||
*new_stuff*
|
||||
|
||||
@@ -3,43 +3,115 @@ from __future__ import absolute_import
|
||||
|
||||
import octoprint.plugin
|
||||
import octoprint.util
|
||||
from abc import ABC
|
||||
from enum import Enum
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
|
||||
class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.SettingsPlugin,
|
||||
octoprint.plugin.AssetPlugin, octoprint.plugin.BlueprintPlugin,
|
||||
class OutputType(Enum):
|
||||
ACTION_BASED_INPUT = 0
|
||||
STATE_BASED_INPUT = 1
|
||||
|
||||
class OutputPeripheral(ABC):
|
||||
def __init__(self, id: UUID ,name:str, type:OutputType) -> None:
|
||||
super().__init__()
|
||||
|
||||
def run_action(self):
|
||||
"""
|
||||
Output peripheral can be action based when it's:
|
||||
- GCODE command
|
||||
- Shell script
|
||||
|
||||
Returns:
|
||||
Bool: Success
|
||||
"""
|
||||
pass
|
||||
|
||||
def set_state(self, state):
|
||||
"""
|
||||
Output peripheral can be state based when it's:
|
||||
- GPIO: it can be set to on / off / toggle
|
||||
- Led Strip: it can be set to a color in RGB
|
||||
- Neopixel
|
||||
- PWM
|
||||
|
||||
Returns:
|
||||
Bool: Success
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class EnclosurePlugin(octoprint.plugin.StartupPlugin,
|
||||
octoprint.plugin.TemplatePlugin,
|
||||
octoprint.plugin.SettingsPlugin,
|
||||
octoprint.plugin.AssetPlugin,
|
||||
octoprint.plugin.BlueprintPlugin,
|
||||
octoprint.plugin.EventHandlerPlugin):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._sub_plugins = dict()
|
||||
|
||||
# ~~ TemplatePlugin
|
||||
def get_template_configs(self):
|
||||
return [
|
||||
dict(type="settings", template="enclosure_settings.jinja2",
|
||||
custom_bindings=True)
|
||||
dict(
|
||||
type="settings",
|
||||
template="enclosure_settings.jinja2",
|
||||
custom_bindings=True
|
||||
)
|
||||
]
|
||||
|
||||
# ~~ AssetPlugin mixin
|
||||
def get_assets(self):
|
||||
return dict(
|
||||
js=["js/enclosure.js", "js/bootstrap-colorpicker.min.js"],
|
||||
css=["css/bootstrap-colorpicker.css", "css/enclosure.css"])
|
||||
js=["js/enclosure.js", ],
|
||||
css=["css/enclosure.css"]
|
||||
)
|
||||
|
||||
# ~~ SettingsPlugin
|
||||
def get_settings_defaults(self):
|
||||
return dict(enclosureOutputs=[], enclosureInputs=[])
|
||||
return dict()
|
||||
|
||||
# ~~ SettingsPlugin mixin
|
||||
def on_settings_save(self, data):
|
||||
enclosureOutputs = self._settings.get(["enclosureOutputs"])
|
||||
enclosureInputs = self._settings.get(["enclosureInputs"])
|
||||
print(data)
|
||||
|
||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||
|
||||
# ~~ Softwareupdate hook
|
||||
def get_update_information(self):
|
||||
return dict(enclosure=dict(displayName="Enclosure Plugin", displayVersion=self._plugin_version,
|
||||
# version check: github repository
|
||||
type="github_release", user="vitormhenrique", repo="OctoPrint-Enclosure", current=self._plugin_version,
|
||||
# update method: pip
|
||||
pip="https://github.com/vitormhenrique/OctoPrint-Enclosure/archive/{target_version}.zip"))
|
||||
return dict(
|
||||
enclosure=dict(
|
||||
displayName="Enclosure Plugin",
|
||||
displayVersion=self._plugin_version,
|
||||
type="github_release",
|
||||
user="vitormhenrique",
|
||||
repo="OctoPrint-Enclosure",
|
||||
current=self._plugin_version,
|
||||
pip="https://github.com/vitormhenrique/OctoPrint-Enclosure/archive/{target_version}.zip"
|
||||
)
|
||||
)
|
||||
|
||||
def _get_plugin_key(self, implementation):
|
||||
for k, v in self._plugin_manager.plugin_implementations.items():
|
||||
if v == implementation:
|
||||
return k
|
||||
|
||||
|
||||
def register_plugin(self, implementation):
|
||||
k = self._get_plugin_key(implementation)
|
||||
|
||||
self._logger.debug("Registering plugin - {}".format(k))
|
||||
|
||||
if k not in self._sub_plugins:
|
||||
self._logger.info("Registered plugin - {}".format(k))
|
||||
self._sub_plugins[k] = implementation
|
||||
|
||||
def output_peripheral_set_state(self):
|
||||
pass
|
||||
|
||||
def register_output_peripheral(self):
|
||||
pass
|
||||
|
||||
|
||||
__plugin_name__ = "Enclosure Plugin"
|
||||
@@ -52,6 +124,12 @@ def __plugin_load__():
|
||||
|
||||
global __plugin_hooks__
|
||||
__plugin_hooks__ = {
|
||||
# "octoprint.comm.protocol.gcode.queuing" : __plugin_implementation__.hook_gcode_queuing,
|
||||
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
|
||||
}
|
||||
|
||||
global __plugin_helpers__
|
||||
__plugin_helpers__ = dict(
|
||||
output_peripheral_set_state = __plugin_implementation__.output_peripheral_set_state,
|
||||
register_plugin = __plugin_implementation__.register_plugin,
|
||||
register_output_peripheral = __plugin_implementation__.register_output_peripheral,
|
||||
)
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
/*!
|
||||
* Bootstrap Colorpicker v2.5.1
|
||||
* https://itsjavi.com/bootstrap-colorpicker/
|
||||
*
|
||||
* Originally written by (c) 2012 Stefan Petre
|
||||
* Licensed under the Apache License v2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
*
|
||||
*/
|
||||
.colorpicker-saturation {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-image: url("../img/bootstrap-colorpicker/saturation.png");
|
||||
cursor: crosshair;
|
||||
float: left;
|
||||
}
|
||||
.colorpicker-saturation i {
|
||||
display: block;
|
||||
height: 5px;
|
||||
width: 5px;
|
||||
border: 1px solid #000;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
margin: -4px 0 0 -4px;
|
||||
}
|
||||
.colorpicker-saturation i b {
|
||||
display: block;
|
||||
height: 5px;
|
||||
width: 5px;
|
||||
border: 1px solid #fff;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.colorpicker-hue,
|
||||
.colorpicker-alpha {
|
||||
width: 15px;
|
||||
height: 100px;
|
||||
float: left;
|
||||
cursor: row-resize;
|
||||
margin-left: 4px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.colorpicker-hue i,
|
||||
.colorpicker-alpha i {
|
||||
display: block;
|
||||
height: 1px;
|
||||
background: #000;
|
||||
border-top: 1px solid #fff;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
margin-top: -1px;
|
||||
}
|
||||
.colorpicker-hue {
|
||||
background-image: url("../img/bootstrap-colorpicker/hue.png");
|
||||
}
|
||||
.colorpicker-alpha {
|
||||
background-image: url("../img/bootstrap-colorpicker/alpha.png");
|
||||
display: none;
|
||||
}
|
||||
.colorpicker-saturation,
|
||||
.colorpicker-hue,
|
||||
.colorpicker-alpha {
|
||||
background-size: contain;
|
||||
}
|
||||
.colorpicker {
|
||||
padding: 4px;
|
||||
min-width: 130px;
|
||||
margin-top: 1px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
z-index: 2500;
|
||||
}
|
||||
.colorpicker:before,
|
||||
.colorpicker:after {
|
||||
display: table;
|
||||
content: "";
|
||||
line-height: 0;
|
||||
}
|
||||
.colorpicker:after {
|
||||
clear: both;
|
||||
}
|
||||
.colorpicker:before {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
border-left: 7px solid transparent;
|
||||
border-right: 7px solid transparent;
|
||||
border-bottom: 7px solid #ccc;
|
||||
border-bottom-color: rgba(0, 0, 0, 0.2);
|
||||
position: absolute;
|
||||
top: -7px;
|
||||
left: 6px;
|
||||
}
|
||||
.colorpicker:after {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
border-left: 6px solid transparent;
|
||||
border-right: 6px solid transparent;
|
||||
border-bottom: 6px solid #ffffff;
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
left: 7px;
|
||||
}
|
||||
.colorpicker div {
|
||||
position: relative;
|
||||
}
|
||||
.colorpicker.colorpicker-with-alpha {
|
||||
min-width: 140px;
|
||||
}
|
||||
.colorpicker.colorpicker-with-alpha .colorpicker-alpha {
|
||||
display: block;
|
||||
}
|
||||
.colorpicker-color {
|
||||
height: 10px;
|
||||
margin-top: 5px;
|
||||
clear: both;
|
||||
background-image: url("../img/bootstrap-colorpicker/alpha.png");
|
||||
background-position: 0 100%;
|
||||
}
|
||||
.colorpicker-color div {
|
||||
height: 10px;
|
||||
}
|
||||
.colorpicker-selectors {
|
||||
display: none;
|
||||
height: 10px;
|
||||
margin-top: 5px;
|
||||
clear: both;
|
||||
}
|
||||
.colorpicker-selectors i {
|
||||
cursor: pointer;
|
||||
float: left;
|
||||
height: 10px;
|
||||
width: 10px;
|
||||
}
|
||||
.colorpicker-selectors i + i {
|
||||
margin-left: 3px;
|
||||
}
|
||||
.colorpicker-element .input-group-addon i,
|
||||
.colorpicker-element .add-on i {
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
height: 16px;
|
||||
vertical-align: text-top;
|
||||
width: 16px;
|
||||
}
|
||||
.colorpicker.colorpicker-inline {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
float: none;
|
||||
z-index: auto;
|
||||
}
|
||||
.colorpicker.colorpicker-horizontal {
|
||||
width: 110px;
|
||||
min-width: 110px;
|
||||
height: auto;
|
||||
}
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-saturation {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-color {
|
||||
width: 100px;
|
||||
}
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-hue,
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-alpha {
|
||||
width: 100px;
|
||||
height: 15px;
|
||||
float: left;
|
||||
cursor: col-resize;
|
||||
margin-left: 0px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-hue i,
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-alpha i {
|
||||
display: block;
|
||||
height: 15px;
|
||||
background: #ffffff;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 1px;
|
||||
border: none;
|
||||
margin-top: 0px;
|
||||
}
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-hue {
|
||||
background-image: url("../img/bootstrap-colorpicker/hue-horizontal.png");
|
||||
}
|
||||
.colorpicker.colorpicker-horizontal .colorpicker-alpha {
|
||||
background-image: url("../img/bootstrap-colorpicker/alpha-horizontal.png");
|
||||
}
|
||||
.colorpicker-right:before {
|
||||
left: auto;
|
||||
right: 6px;
|
||||
}
|
||||
.colorpicker-right:after {
|
||||
left: auto;
|
||||
right: 7px;
|
||||
}
|
||||
.colorpicker-no-arrow:before {
|
||||
border-right: 0;
|
||||
border-left: 0;
|
||||
}
|
||||
.colorpicker-no-arrow:after {
|
||||
border-right: 0;
|
||||
border-left: 0;
|
||||
}
|
||||
.colorpicker.colorpicker-visible,
|
||||
.colorpicker-alpha.colorpicker-visible,
|
||||
.colorpicker-saturation.colorpicker-visible,
|
||||
.colorpicker-hue.colorpicker-visible,
|
||||
.colorpicker-selectors.colorpicker-visible {
|
||||
display: block;
|
||||
}
|
||||
.colorpicker.colorpicker-hidden,
|
||||
.colorpicker-alpha.colorpicker-hidden,
|
||||
.colorpicker-saturation.colorpicker-hidden,
|
||||
.colorpicker-hue.colorpicker-hidden,
|
||||
.colorpicker-selectors.colorpicker-hidden {
|
||||
display: none;
|
||||
}
|
||||
.colorpicker-inline.colorpicker-visible {
|
||||
display: inline-block;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 557 B |
Binary file not shown.
|
Before Width: | Height: | Size: 488 B |
Binary file not shown.
|
Before Width: | Height: | Size: 478 B |
Binary file not shown.
|
Before Width: | Height: | Size: 504 B |
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB |
File diff suppressed because one or more lines are too long
@@ -1,426 +1,5 @@
|
||||
function isInteger(value) {
|
||||
return /^\d+$/.test(value);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
var cleanInput = function (index_id) {
|
||||
return {
|
||||
index_id: index_id,
|
||||
label: "",
|
||||
input_type: "regular_gpio",
|
||||
action_type: "output_control",
|
||||
gpio: {
|
||||
pin_name: "",
|
||||
pull_resistor: "input_pull_up",
|
||||
linked_action: "output_control",
|
||||
edge_detection: "fall",
|
||||
},
|
||||
linked_printer_action: {
|
||||
action: "filament",
|
||||
filament_sensor_enabled: false,
|
||||
filament_sensor_timeout: 120,
|
||||
},
|
||||
linked_output_action: {
|
||||
output_index_id: "",
|
||||
output_set_value: "low",
|
||||
},
|
||||
temperature_sensor: {
|
||||
type: "si7021",
|
||||
address: "",
|
||||
unit: "celsius",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var cleanOutput = function (index_id) {
|
||||
return {
|
||||
index_id: index_id,
|
||||
label: "",
|
||||
output_type: "regular_gpio",
|
||||
gpio: {
|
||||
pin_name: "",
|
||||
active_low: false,
|
||||
},
|
||||
gcode: {
|
||||
gcode: "",
|
||||
},
|
||||
neopixel: {
|
||||
count: "",
|
||||
brightness: "",
|
||||
default_color: "",
|
||||
},
|
||||
other_config: {
|
||||
hide_on_tab: false,
|
||||
show_on_navbar: false,
|
||||
},
|
||||
pwm: {
|
||||
linked_to_temperature: false,
|
||||
duty_a: "",
|
||||
temperature_a: "",
|
||||
duty_b: "",
|
||||
temperature_b: "",
|
||||
frequency: "",
|
||||
default_duty_cycle: "",
|
||||
linked_temp_sensor: "",
|
||||
},
|
||||
led_strip: {
|
||||
clock_pin: "",
|
||||
data_pin: "",
|
||||
default_color: "",
|
||||
},
|
||||
schedule: {
|
||||
toggle_timer: false,
|
||||
time_on: "",
|
||||
time_off: "",
|
||||
startup_with_server: false,
|
||||
auto_startup: false,
|
||||
startup_time_delay: "",
|
||||
auto_shutdown: false,
|
||||
shutdown_on_failed: false,
|
||||
shutdown_time_delay: "",
|
||||
},
|
||||
shell_script: {
|
||||
shell_script: "",
|
||||
},
|
||||
temperature_alarm: {
|
||||
linked_temp_sensor: "",
|
||||
set_temp: "",
|
||||
controlled_io: "",
|
||||
controlled_io_set_value: "high",
|
||||
},
|
||||
temperature_control: {
|
||||
linked_temp_sensor: "",
|
||||
control_type: "heater",
|
||||
default_value: "",
|
||||
deadband: "",
|
||||
max_temperature: "",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function EnclosureInputEditorViewModel(parameters) {
|
||||
var self = this;
|
||||
|
||||
self.isNew = ko.observable(false);
|
||||
// general info
|
||||
self.index_id = ko.observable();
|
||||
self.label = ko.observable();
|
||||
self.input_type = ko.observable();
|
||||
self.action_type = ko.observable();
|
||||
// gpio output
|
||||
self.gpio_pin = ko.observable();
|
||||
self.pull_resistor = ko.observable();
|
||||
self.linked_action = ko.observable();
|
||||
self.edge_detection = ko.observable();
|
||||
// output on linked action
|
||||
self.controlled_output = ko.observable();
|
||||
self.controlled_output_set_value = ko.observable();
|
||||
// printer action on linked action
|
||||
self.printer_action = ko.observable();
|
||||
self.filament_sensor_enabled = ko.observable();
|
||||
self.filament_sensor_timeout = ko.observable();
|
||||
// temperature sensor
|
||||
self.temperature_sensor_type = ko.observable();
|
||||
self.temperature_sensor_address = ko.observable();
|
||||
self.temperature_sensor_unit = ko.observable();
|
||||
|
||||
self.enclosureInputs = undefined;
|
||||
|
||||
self.validInput = ko.pureComputed(function () {
|
||||
|
||||
if (self.input_type() == "regular_gpio") {
|
||||
if (self.label() != "") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
});
|
||||
|
||||
self.fromInputEnclosureData = function (data) {
|
||||
|
||||
self.isNew(data === undefined);
|
||||
|
||||
if (data === undefined) {
|
||||
var arrRelaysLength = self.enclosureInputs().length;
|
||||
var nextIndex = arrRelaysLength == 0 ? 1 : self.enclosureInputs()[arrRelaysLength - 1].index_id() + 1;
|
||||
data = cleanInput(nextIndex);
|
||||
} else {
|
||||
objIndex = self.enclosureInputs().findIndex((obj => obj.index_id == data.index_id));
|
||||
data = ko.mapping.toJS(self.enclosureInputs()[objIndex]);
|
||||
}
|
||||
|
||||
// general info
|
||||
self.index_id(data.index_id);
|
||||
self.label(data.label);
|
||||
self.input_type(data.input_type);
|
||||
self.action_type(data.action_type);
|
||||
// gpio output
|
||||
self.gpio_pin(data.gpio.pin_name);
|
||||
self.pull_resistor(data.gpio.pull_resistor);
|
||||
self.linked_action(data.gpio.linked_action);
|
||||
self.edge_detection(data.gpio.edge_detection);
|
||||
// output on linked action
|
||||
self.controlled_output(data.linked_output_action.output_index_id);
|
||||
self.controlled_output_set_value(data.linked_output_action.output_set_value);
|
||||
// printer action on linked action
|
||||
self.printer_action(data.linked_printer_action.action);
|
||||
self.filament_sensor_enabled(data.linked_printer_action.filament_sensor_enabled);
|
||||
self.filament_sensor_timeout(data.linked_printer_action.filament_sensor_timeout);
|
||||
// temperature sensor
|
||||
self.temperature_sensor_type(data.type);
|
||||
self.temperature_sensor_address(data.address);
|
||||
self.temperature_sensor_unit(data.unit);
|
||||
|
||||
};
|
||||
|
||||
self.toInputEnclosureData = function (data) {
|
||||
var output_data = {
|
||||
index_id: self.index_id(),
|
||||
label: self.label(),
|
||||
input_type: self.input_type(),
|
||||
action_type: self.action_type(),
|
||||
gpio: {
|
||||
pin_name: self.gpio_pin(),
|
||||
pull_resistor: self.pull_resistor(),
|
||||
linked_action: self.linked_action(),
|
||||
edge_detection: self.edge_detection(),
|
||||
},
|
||||
linked_printer_action: {
|
||||
action: self.printer_action(),
|
||||
filament_sensor_enabled: self.filament_sensor_enabled(),
|
||||
filament_sensor_timeout: self.filament_sensor_timeout(),
|
||||
},
|
||||
linked_output_action: {
|
||||
output_index_id: self.controlled_output(),
|
||||
output_set_value: self.controlled_output_set_value(),
|
||||
},
|
||||
temperature_sensor: {
|
||||
type: self.temperature_sensor_type(),
|
||||
address: self.temperature_sensor_address(),
|
||||
unit: self.temperature_sensor_unit(),
|
||||
}
|
||||
}
|
||||
|
||||
return output_data;
|
||||
};
|
||||
|
||||
|
||||
// end of EnclosureInputEditorViewModel
|
||||
};
|
||||
|
||||
function EnclosureOutputEditorViewModel(parameters) {
|
||||
var self = this;
|
||||
|
||||
self.isNew = ko.observable(false);
|
||||
// general info
|
||||
self.index_id = ko.observable();
|
||||
self.label = ko.observable();
|
||||
self.output_type = ko.observable();
|
||||
// gpio output
|
||||
self.gpio_pin = ko.observable();
|
||||
self.active_low = ko.observable();
|
||||
// gcode output
|
||||
self.gcode = ko.observable();
|
||||
// neopixel output
|
||||
self.neopixel_count = ko.observable();
|
||||
self.neopixel_brightness = ko.observable();
|
||||
self.default_neopixel_color = ko.observable();
|
||||
// other output configurations
|
||||
self.hide_btn_ui = ko.observable();
|
||||
self.show_on_navbar = ko.observable();
|
||||
// pwm output
|
||||
self.pwm_temperature_linked = ko.observable();
|
||||
self.duty_a = ko.observable();
|
||||
self.temperature_a = ko.observable();
|
||||
self.duty_b = ko.observable();
|
||||
self.temperature_b = ko.observable();
|
||||
self.pwm_frequency = ko.observable();
|
||||
self.default_duty_cycle = ko.observable();
|
||||
self.pwm_linked_temp_sensor = ko.observable();
|
||||
// led strip output
|
||||
self.led_trip_gpio_clk = ko.observable();
|
||||
self.led_strip_gpio_data = ko.observable();
|
||||
self.default_led_strip_color = ko.observable();
|
||||
// schedule config
|
||||
self.toggle_timer = ko.observable();
|
||||
self.toggle_time_on = ko.observable();
|
||||
self.toggle_time_off = ko.observable();
|
||||
self.startup_with_server = ko.observable();
|
||||
self.auto_startup = ko.observable();
|
||||
self.startup_time_delay = ko.observable();
|
||||
self.auto_shutdown = ko.observable();
|
||||
self.shutdown_on_failed = ko.observable();
|
||||
self.shutdown_time_delay = ko.observable();
|
||||
// shell script output
|
||||
self.shell_script = ko.observable();
|
||||
// temp alarm output
|
||||
self.alarm_linked_temp_sensor = ko.observable();
|
||||
self.alarm_set_temp = ko.observable();
|
||||
self.controlled_io = ko.observable();
|
||||
self.controlled_io_set_value = ko.observable();
|
||||
// temp control output
|
||||
self.temp_ctr_linked_sensor = ko.observable();
|
||||
self.temp_ctr_type = ko.observable();
|
||||
self.temp_ctr_default_value = ko.observable();
|
||||
self.temp_ctr_deadband = ko.observable();
|
||||
self.temp_ctr_max_temp = ko.observable();
|
||||
|
||||
self.enclosureOutputs = undefined;
|
||||
|
||||
self.validOutput = ko.pureComputed(function () {
|
||||
|
||||
if (self.output_type() == "regular_gpio") {
|
||||
if (self.label() != "" && self.gpio_pin() != "" && isInteger(self.gpio_pin())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
self.fromOutputEnclosureData = function (data) {
|
||||
|
||||
self.isNew(data === undefined);
|
||||
|
||||
if (data === undefined) {
|
||||
var arrRelaysLength = self.enclosureOutputs().length;
|
||||
var nextIndex = arrRelaysLength == 0 ? 1 : self.enclosureOutputs()[arrRelaysLength - 1].index_id() + 1;
|
||||
data = cleanOutput(nextIndex);
|
||||
} else {
|
||||
objIndex = self.enclosureOutputs().findIndex((obj => obj.index_id == data.index_id));
|
||||
data = ko.mapping.toJS(self.enclosureOutputs()[objIndex]);
|
||||
}
|
||||
|
||||
// general info
|
||||
self.index_id(data.index_id);
|
||||
self.label(data.label);
|
||||
self.output_type(data.output_type);
|
||||
// gpio output
|
||||
self.gpio_pin(data.gpio.pin_name);
|
||||
self.active_low(data.gpio.active_low);
|
||||
// gcode output
|
||||
self.gcode(data.gcode.gcode);
|
||||
// neopixel output
|
||||
self.neopixel_count(data.neopixel.count);
|
||||
self.neopixel_brightness(data.neopixel.brightness);
|
||||
self.default_neopixel_color(data.neopixel.default_color);
|
||||
// other output configurations
|
||||
self.hide_btn_ui(data.other_config.hide_on_tab);
|
||||
self.show_on_navbar(data.other_config.show_on_navbar);
|
||||
// pwm output
|
||||
self.pwm_temperature_linked(data.pwm.linked_to_temperature);
|
||||
self.duty_a(data.pwm.duty_a);
|
||||
self.temperature_a(data.pwm.temperature_a);
|
||||
self.duty_b(data.pwm.duty_b);
|
||||
self.temperature_b(data.pwm.temperature_b);
|
||||
self.pwm_frequency(data.pwm.frequency);
|
||||
self.default_duty_cycle(data.pwm.default_duty_cycle);
|
||||
self.pwm_linked_temp_sensor(data.pwm.linked_temp_sensor);
|
||||
// led strip output
|
||||
self.led_trip_gpio_clk(data.led_strip.clock_pin);
|
||||
self.led_strip_gpio_data(data.led_strip.data_pin);
|
||||
self.default_led_strip_color(data.led_strip.default_color);
|
||||
// schedule config
|
||||
self.toggle_timer(data.schedule.toggle_timer);
|
||||
self.toggle_time_on(data.schedule.time_on);
|
||||
self.toggle_time_off(data.schedule.time_off);
|
||||
self.startup_with_server(data.schedule.startup_with_server);
|
||||
self.auto_startup(data.schedule.auto_startup);
|
||||
self.startup_time_delay(data.schedule.startup_time_delay);
|
||||
self.auto_shutdown(data.schedule.auto_shutdown);
|
||||
self.shutdown_on_failed(data.schedule.shutdown_on_failed);
|
||||
self.shutdown_time_delay(data.schedule.shutdown_time_delay);
|
||||
// shell script output
|
||||
self.shell_script(data.shell_script.shell_script);
|
||||
// temp alarm output
|
||||
self.alarm_linked_temp_sensor(data.temperature_alarm.linked_temp_sensor);
|
||||
self.alarm_set_temp(data.temperature_alarm.set_temp);
|
||||
self.controlled_io(data.temperature_alarm.controlled_io);
|
||||
self.controlled_io_set_value(data.temperature_alarm.controlled_io_set_value);
|
||||
// temp control output
|
||||
self.temp_ctr_linked_sensor(data.temperature_control.linked_temp_sensor);
|
||||
self.temp_ctr_type(data.temperature_control.control_type);
|
||||
self.temp_ctr_default_value(data.temperature_control.default_value);
|
||||
self.temp_ctr_deadband(data.temperature_control.deadband);
|
||||
self.temp_ctr_max_temp(data.temperature_control.max_temperature);
|
||||
};
|
||||
|
||||
self.showColorPicker = function () {
|
||||
|
||||
};
|
||||
|
||||
self.toOutputEnclosureData = function () {
|
||||
var output_data = {
|
||||
index_id: self.index_id(),
|
||||
label: self.label(),
|
||||
output_type: self.output_type(),
|
||||
gpio: {
|
||||
pin_name: self.gpio_pin(),
|
||||
active_low: self.active_low(),
|
||||
},
|
||||
gcode: {
|
||||
gcode: self.gcode(),
|
||||
},
|
||||
neopixel: {
|
||||
count: self.neopixel_count(),
|
||||
brightness: self.neopixel_brightness(),
|
||||
default_color: self.default_neopixel_color(),
|
||||
},
|
||||
other_config: {
|
||||
hide_on_tab: self.hide_btn_ui(),
|
||||
show_on_navbar: self.show_on_navbar(),
|
||||
},
|
||||
pwm: {
|
||||
linked_to_temperature: self.pwm_temperature_linked(),
|
||||
duty_a: self.duty_a(),
|
||||
temperature_a: self.temperature_a(),
|
||||
duty_b: self.duty_b(),
|
||||
temperature_b: self.temperature_b(),
|
||||
frequency: self.pwm_frequency(),
|
||||
default_duty_cycle: self.default_duty_cycle(),
|
||||
linked_temp_sensor: self.pwm_linked_temp_sensor(),
|
||||
},
|
||||
led_strip: {
|
||||
clock_pin: self.led_trip_gpio_clk(),
|
||||
data_pin: self.led_strip_gpio_data(),
|
||||
default_color: self.default_led_strip_color(),
|
||||
},
|
||||
schedule: {
|
||||
toggle_timer: self.toggle_timer(),
|
||||
time_on: self.toggle_time_on(),
|
||||
time_off: self.toggle_time_off(),
|
||||
startup_with_server: self.startup_with_server(),
|
||||
auto_startup: self.auto_startup(),
|
||||
startup_time_delay: self.startup_time_delay(),
|
||||
auto_shutdown: self.auto_shutdown(),
|
||||
shutdown_on_failed: self.shutdown_on_failed(),
|
||||
shutdown_time_delay: self.shutdown_time_delay(),
|
||||
},
|
||||
shell_script: {
|
||||
shell_script: self.shell_script(),
|
||||
},
|
||||
temperature_alarm: {
|
||||
linked_temp_sensor: self.alarm_linked_temp_sensor(),
|
||||
set_temp: self.alarm_set_temp(),
|
||||
controlled_io: self.controlled_io(),
|
||||
controlled_io_set_value: self.controlled_io_set_value(),
|
||||
},
|
||||
temperature_control: {
|
||||
linked_temp_sensor: self.temp_ctr_linked_sensor(),
|
||||
control_type: self.temp_ctr_type(),
|
||||
default_value: self.temp_ctr_default_value(),
|
||||
deadband: self.temp_ctr_deadband(),
|
||||
max_temperature: self.temp_ctr_max_temp(),
|
||||
}
|
||||
}
|
||||
return output_data
|
||||
};
|
||||
|
||||
// end of EnclosureOutputEditorViewModel
|
||||
};
|
||||
|
||||
function EnclosureViewModel(parameters) {
|
||||
var self = this;
|
||||
|
||||
@@ -434,172 +13,28 @@ $(function () {
|
||||
self.settings_unsaved = ko.observable(false);
|
||||
|
||||
self.onBeforeBinding = function () {
|
||||
self.enclosureOutputs(self.settingsViewModel.settings.plugins.enclosure.enclosureOutputs())
|
||||
self.enclosureInputs(self.settingsViewModel.settings.plugins.enclosure.enclosureInputs())
|
||||
// self.settings_unsaved(false);
|
||||
|
||||
};
|
||||
|
||||
self.onSettingsBeforeSave = function () {
|
||||
// self.enclosureOutputs(self.settingsViewModel.settings.plugins.enclosure.enclosureOutputs());
|
||||
};
|
||||
|
||||
self.onEventSettingsUpdated = function () {
|
||||
self.settingsViewModel.settings.plugins.enclosure.enclosureOutputs(self.enclosureOutputs());
|
||||
self.settingsViewModel.settings.plugins.enclosure.enclosureInputs(self.enclosureInputs());
|
||||
self.settings_unsaved(false);
|
||||
|
||||
};
|
||||
|
||||
|
||||
self.syncSettings = function () {
|
||||
// self.settingsViewModel.settings.plugins.enclosure.enclosureOutputs(self.enclosureOutputs());
|
||||
// self.settingsViewModel.settings.plugins.enclosure.enclosureInputs(self.enclosureInputs());
|
||||
// self.settings_unsaved(false);
|
||||
};
|
||||
|
||||
self.createOutputEditor = function (data) {
|
||||
var outputEditor = new EnclosureOutputEditorViewModel();
|
||||
return outputEditor;
|
||||
};
|
||||
|
||||
self.createInputEditor = function (data) {
|
||||
var inputEditor = new EnclosureInputEditorViewModel();
|
||||
return inputEditor;
|
||||
};
|
||||
|
||||
self.outputEditor = self.createOutputEditor();
|
||||
self.outputEditor.enclosureOutputs = self.enclosureOutputs;
|
||||
|
||||
self.inputEditor = self.createInputEditor();
|
||||
self.inputEditor.enclosureInputs = self.enclosureInputs;
|
||||
|
||||
|
||||
self.removeOutput = function (data) {
|
||||
self.enclosureOutputs.remove(data);
|
||||
self.settings_unsaved(true);
|
||||
};
|
||||
|
||||
self.removeInput = function(data){
|
||||
self.enclosureInputs.remove(data);
|
||||
self.settings_unsaved(true);
|
||||
}
|
||||
|
||||
self.showOutputEditorDialog = function (data) {
|
||||
|
||||
self.outputEditor.fromOutputEnclosureData(data);
|
||||
|
||||
var editDialog = $("#settings_outputs_edit_dialog");
|
||||
|
||||
$('ul.nav-pills a[data-toggle="tab"]:first', editDialog).tab("show");
|
||||
editDialog.modal({
|
||||
minHeight: function () {
|
||||
return Math.max($.fn.modal.defaults.maxHeight() - 80, 250);
|
||||
}
|
||||
}).css({
|
||||
width: 'auto',
|
||||
'margin-left': function () {
|
||||
return -($(this).width());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.showInputEditorDialog = function (data) {
|
||||
|
||||
self.inputEditor.fromInputEnclosureData(data);
|
||||
|
||||
var editDialog = $("#settings_inputs_edit_dialog");
|
||||
|
||||
$('ul.nav-pills a[data-toggle="tab"]:first', editDialog).tab("show");
|
||||
editDialog.modal({
|
||||
minHeight: function () {
|
||||
return Math.max($.fn.modal.defaults.maxHeight() - 80, 250);
|
||||
}
|
||||
}).css({
|
||||
width: 'auto',
|
||||
'margin-left': function () {
|
||||
return -($(this).width());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.confirmEditOutput = function () {
|
||||
|
||||
if (self.outputEditor.validOutput()) {
|
||||
var callback = function () {
|
||||
$("#settings_outputs_edit_dialog").modal("hide");
|
||||
};
|
||||
|
||||
self.addOutputs(callback);
|
||||
|
||||
// self.syncSettings();
|
||||
}
|
||||
};
|
||||
|
||||
self.confirmEditInput = function () {
|
||||
|
||||
if (self.inputEditor.validInput()) {
|
||||
var callback = function () {
|
||||
$("#settings_inputs_edit_dialog").modal("hide");
|
||||
};
|
||||
|
||||
self.addInputs(callback);
|
||||
|
||||
// self.syncSettings();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
self.addOutputs = function (callback) {
|
||||
var isNew = self.outputEditor.isNew();
|
||||
|
||||
self.settings_unsaved(true);
|
||||
|
||||
var output = ko.mapping.fromJS(self.outputEditor.toOutputEnclosureData());
|
||||
|
||||
if (isNew) {
|
||||
self.enclosureOutputs.push(output);
|
||||
} else {
|
||||
objIndex = self.enclosureOutputs().findIndex((obj => obj.index_id() == output.index_id()));
|
||||
var _old_output = self.enclosureOutputs()[objIndex];
|
||||
self.enclosureOutputs.replace(_old_output, output);
|
||||
}
|
||||
|
||||
if (callback !== undefined) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
self.addInputs = function (callback) {
|
||||
var isNew = self.inputEditor.isNew();
|
||||
|
||||
self.settings_unsaved(true);
|
||||
|
||||
var input = ko.mapping.fromJS(self.inputEditor.toInputEnclosureData());
|
||||
|
||||
if (isNew) {
|
||||
self.enclosureInputs.push(input);
|
||||
} else {
|
||||
objIndex = self.enclosureInputs().findIndex((obj => obj.index_id() == input.index_id()));
|
||||
var _old_input = self.enclosureInputs()[objIndex];
|
||||
self.enclosureInputs.replace(_old_input, input);
|
||||
}
|
||||
|
||||
if (callback !== undefined) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
self.print_data = function () {
|
||||
console.log(self);
|
||||
|
||||
};
|
||||
|
||||
// end of EnclosureViewModel
|
||||
};
|
||||
|
||||
|
||||
|
||||
OCTOPRINT_VIEWMODELS.push({
|
||||
construct: EnclosureViewModel,
|
||||
// ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ...
|
||||
dependencies: ["settingsViewModel", "connectionViewModel", "printerStateViewModel"],
|
||||
elements: ["#settings_plugin_enclosure"]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user