Skip to content

Commit

Permalink
adjusted to use view model
Browse files Browse the repository at this point in the history
  • Loading branch information
electr0sheep committed Feb 27, 2018
1 parent f8512e9 commit 8296819
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
22 changes: 3 additions & 19 deletions octoprint_CR10_Leveling/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
# coding=utf-8
from __future__ import absolute_import

from octoprint.settings import settings
import octoprint.plugin


class Cr10_levelingPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.StartupPlugin):

def on_after_startup(self):
s = settings()
addedControls = [{u'customClass': u'', u'layout': u'horizontal_grid', u'name': u'CR-10 Bed Leveling', u'children': [{u'width': u'11', u'commands': [u'M140 S50', u'M104 S170', u'M190 S50', u'M109 S170', u'', u'; Play tune', u'M300 S0 P66', u'M300 S987 P66', u'M300 S0 P66', u'M300 S1975 P66', u'M300 S0 P66', u'M300 S2959 P66', u'M300 S0 P66', u'M300 S2489 P66', u'M300 S0 P66', u'M300 S1975 P66', u'M300 S2959 P66', u'M300 S0 P133', u'M300 S2489 P133', u'M300 S0 P133', u'M300 S2093 P66', u'M300 S0 P66', u'M300 S4186 P66', u'M300 S0 P66', u'M300 S3135 P66', u'M300 S0 P66', u'M300 S2637 P66', u'M300 S0 P66', u'M300 S4186 P66', u'M300 S3135 P66', u'M300 S0 P133', u'M300 S2637 P133', u'M300 S0 P133', u'M300 S987 P66', u'M300 S0 P66', u'M300 S1975 P66', u'M300 S0 P66', u'M300 S2959 P66', u'M300 S0 P66', u'M300 S2489 P66', u'M300 S0 P66', u'M300 S1975 P66', u'M300 S2959 P66', u'M300 S0 P133', u'M300 S2489 P133', u'M300 S0 P133', u'M300 S2489 P66', u'M300 S2637 P66', u'M300 S2793 P66', u'M300 S0 P66', u'M300 S2793 P66', u'M300 S2959 P66', u'M300 S3135 P66', u'M300 S0 P66', u'M300 S3135 P66', u'M300 S3322 P66', u'M300 S1760 P66', u'M300 S0 P66', u'M300 S1975 P100'], u'customClass': u'btn btn-danger', u'name': u'Apply Heat', u'offset': u'2'}, {u'width': u'2', u'commands': [u'G1 Z10 F500', u'G1 X10 Y10 F3600', u'G1 Z0 F500', u'', u''], u'customClass': u'btn', u'name': u'Upper Left'}, {u'width': u'2', u'commands': [u'G1 Z10 F500', u'G1 X290 Y10 F3600', u'G1 Z0 F500', u''], u'customClass': u'btn', u'name': u'Upper Right', u'offset': u'2'}, {u'width': u'8', u'commands': [u'G1 Z10 F500', u'G1 X150 Y150 F3600', u'G1 Z0 F500', u''], u'customClass': u'btn', u'name': u'Center', u'offset': u'2'}, {u'width': u'2', u'commands': [u'G1 Z10 F500', u'G1 X10 Y290 F3600', u'G1 Z0 F500'], u'customClass': u'btn', u'name': u'Lower Left'}, {u'width': u'2', u'commands': [u'G1 Z10 F500', u'G1 X290 Y290 F3600', u'G1 Z0 F500'], u'customClass': u'btn', u'name': u'Lower Right', u'offset': u'2'}]}]

addItemsToControl = True
for item in s.get(["controls"]):
if (item['name'] == 'CR-10 Bed Leveling'):
addItemsToControl = False

if addItemsToControl:
addedControls = addedControls + s.get(["controls"])
s.set(["controls"], addedControls)
class Cr10_levelingPlugin(octoprint.plugin.AssetPlugin):

def get_assets(self):
return dict(js=["cr10leveling.js"])

def get_update_information(self):
# Define the configuration for your plugin to use with the Software Update
# Plugin here. See https://github.com/foosel/OctoPrint/wiki/Plugin:-Software-Update
# for details.
return dict(
CR10_Leveling=dict(
displayName="CR-10 Leveling Plugin",
Expand Down
50 changes: 50 additions & 0 deletions octoprint_CR10_Leveling/static/cr10leveling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$(function() {
function MyCustomViewModel (parameters) {
var self = this;

self.settings = parameters[0];

self.getAdditionalControls = function() {
return [{
'customClass': '', 'layout': 'horizontal_grid', 'name': 'CR-10 Bed Leveling', 'children':
[{'width': '11', 'commands':
['M140 S50', 'M104 S170', 'M190 S50', 'M109 S170', '', '; Play tune',
'M300 S0 P66', 'M300 S987 P66', 'M300 S0 P66', 'M300 S1975 P66',
'M300 S0 P66', 'M300 S2959 P66', 'M300 S0 P66', 'M300 S2489 P66',
'M300 S0 P66', 'M300 S1975 P66', 'M300 S2959 P66', 'M300 S0 P133',
'M300 S2489 P133', 'M300 S0 P133', 'M300 S2093 P66', 'M300 S0 P66',
'M300 S4186 P66', 'M300 S0 P66', 'M300 S3135 P66', 'M300 S0 P66',
'M300 S2637 P66', 'M300 S0 P66', 'M300 S4186 P66', 'M300 S3135 P66',
'M300 S0 P133', 'M300 S2637 P133', 'M300 S0 P133', 'M300 S987 P66',
'M300 S0 P66', 'M300 S1975 P66', 'M300 S0 P66', 'M300 S2959 P66',
'M300 S0 P66', 'M300 S2489 P66', 'M300 S0 P66', 'M300 S1975 P66',
'M300 S2959 P66', 'M300 S0 P133', 'M300 S2489 P133', 'M300 S0 P133',
'M300 S2489 P66', 'M300 S2637 P66', 'M300 S2793 P66', 'M300 S0 P66',
'M300 S2793 P66', 'M300 S2959 P66', 'M300 S3135 P66', 'M300 S0 P66',
'M300 S3135 P66', 'M300 S3322 P66', 'M300 S1760 P66', 'M300 S0 P66',
'M300 S1975 P100'],
'customClass': 'btn btn-danger', 'name': 'Apply Heat', 'offset': '2'},
{'width': '2', 'commands':
['G1 Z10 F500', 'G1 X10 Y10 F3600', 'G1 Z0 F500', '', ''],
'customClass': 'btn', 'name': 'Upper Left'},
{'width': '2', 'commands':
['G1 Z10 F500', 'G1 X290 Y10 F3600', 'G1 Z0 F500', ''],
'customClass': 'btn', 'name': 'Upper Right', 'offset': '2'},
{'width': '8', 'commands':
['G1 Z10 F500', 'G1 X150 Y150 F3600', 'G1 Z0 F500', ''],
'customClass': 'btn', 'name': 'Center', 'offset': '2'},
{'width': '2', 'commands':
['G1 Z10 F500', 'G1 X10 Y290 F3600', 'G1 Z0 F500'],
'customClass': 'btn', 'name': 'Lower Left'},
{'width': '2', 'commands':
['G1 Z10 F500', 'G1 X290 Y290 F3600', 'G1 Z0 F500'],
'customClass': 'btn', 'name': 'Lower Right', 'offset': '2'}]
}]
}
}

OCTOPRINT_VIEWMODELS.push({
construct: MyCustomViewModel,
dependencies: ["controlViewModel"]
});
})
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 = "CR-10 Leveling"

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

# 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 8296819

Please sign in to comment.