Update Fan panel to include all configured fans.
This commit is contained in:
parent
407d8ad000
commit
d540c038a4
@ -87,19 +87,18 @@ class Printer:
|
||||
'virtual_sdcard',
|
||||
'webhooks'
|
||||
]
|
||||
for x in keys:
|
||||
if x in data:
|
||||
if x not in self.data:
|
||||
self.data[x] = {}
|
||||
|
||||
for y in data[x]:
|
||||
self.data[x][y] = data[x][y]
|
||||
|
||||
for x in (self.get_tools() + self.get_heaters()):
|
||||
if x in data:
|
||||
d = data[x]
|
||||
for i in d:
|
||||
self.set_dev_stat(x, i, d[i])
|
||||
for i in data[x]:
|
||||
self.set_dev_stat(x, i, data[x][i])
|
||||
|
||||
for x in data:
|
||||
if x == "configfile":
|
||||
continue
|
||||
if x not in self.data:
|
||||
self.data[x] = {}
|
||||
self.data[x].update(data[x])
|
||||
|
||||
if "webhooks" in data or "idle_timeout" in data or "print_stats" in data:
|
||||
self.evaluate_state()
|
||||
@ -177,6 +176,14 @@ class Printer:
|
||||
def get_data(self):
|
||||
return self.data
|
||||
|
||||
def get_fans(self):
|
||||
fans = ["fan"] if len(self.get_config_section_list("fan")) > 0 else []
|
||||
fan_types = ["controller_fan", "fan_generic", "heater_fan", "temperature_fan"]
|
||||
for type in fan_types:
|
||||
for f in self.get_config_section_list("%s " % type):
|
||||
fans.append(f)
|
||||
return fans
|
||||
|
||||
def get_gcode_macros(self):
|
||||
return self.get_config_section_list("gcode_macro ")
|
||||
|
||||
|
183
panels/fan.py
183
panels/fan.py
@ -2,7 +2,7 @@ import gi
|
||||
import logging
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, Gdk, GLib
|
||||
from gi.repository import Gtk, Gdk, GLib, Pango
|
||||
|
||||
from ks_includes.KlippyGcodes import KlippyGcodes
|
||||
from ks_includes.screen_panel import ScreenPanel
|
||||
@ -10,84 +10,143 @@ from ks_includes.screen_panel import ScreenPanel
|
||||
def create_panel(*args):
|
||||
return FanPanel(*args)
|
||||
|
||||
CHANGEABLE_FANS = ["fan","fan_generic"]
|
||||
|
||||
class FanPanel(ScreenPanel):
|
||||
fan_speed = 0
|
||||
fan_speed = {}
|
||||
user_selecting = False
|
||||
|
||||
def initialize(self, panel_name):
|
||||
_ = self.lang.gettext
|
||||
self.devices = {}
|
||||
|
||||
grid = self._gtk.HomogeneousGrid()
|
||||
scroll = Gtk.ScrolledWindow()
|
||||
scroll.set_property("overlay-scrolling", False)
|
||||
scroll.set_vexpand(True)
|
||||
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
box.set_hexpand(True)
|
||||
# Create a grid for all devices
|
||||
self.labels['devices'] = Gtk.Grid()
|
||||
scroll.add(self.labels['devices'])
|
||||
|
||||
adj = Gtk.Adjustment(0, 0, 100, 1, 5, 0)
|
||||
self.labels["scale"] = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=adj)
|
||||
self.labels["scale"].set_value(0)
|
||||
self.labels["scale"].set_hexpand(True)
|
||||
self.labels["scale"].connect("value-changed", self.select_fan_speed)
|
||||
self.labels["scale"].get_style_context().add_class("fan_slider")
|
||||
box.add(self.labels["scale"])
|
||||
# Create a box to contain all of the above
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
|
||||
box.set_vexpand(True)
|
||||
box.pack_start(scroll, True, True, 0)
|
||||
|
||||
self.labels["fanoff"] = self._gtk.ButtonImage("fan", _("Fan Off"))
|
||||
self.labels["fanoff"].get_style_context().add_class("color1")
|
||||
self.labels["fanoff"].connect("clicked", self.set_fan_on, False)
|
||||
self.labels["fanon"] = self._gtk.ButtonImage("fan-on", _("Fan On"))
|
||||
self.labels["fanon"].get_style_context().add_class("color3")
|
||||
self.labels["fanon"].connect("clicked", self.set_fan_on, True)
|
||||
self.load_fans()
|
||||
|
||||
self.labels["apply"] = self._gtk.ButtonImage("complete", _("Set Speed"))
|
||||
self.labels["apply"].get_style_context().add_class("color4")
|
||||
self.labels["apply"].connect("clicked", self.set_fan_speed)
|
||||
self.labels["cancel"] = self._gtk.ButtonImage("cancel", _("Cancel"))
|
||||
self.labels["cancel"].get_style_context().add_class("color2")
|
||||
self.labels["cancel"].connect("clicked", self.cancel_select_fan_speed)
|
||||
self.labels["cancel"].hide()
|
||||
self.content.add(box)
|
||||
|
||||
grid.attach(Gtk.Label(), 0, 0, 1, 1)
|
||||
grid.attach(box, 0, 1, 4, 1)
|
||||
grid.attach(self.labels["fanoff"], 0, 2, 1, 1)
|
||||
grid.attach(self.labels["fanon"], 3, 2, 1, 1)
|
||||
|
||||
self.grid = grid
|
||||
self.content.add(grid)
|
||||
self._screen.add_subscription(panel_name)
|
||||
|
||||
def process_update(self, action, data):
|
||||
if (action == "notify_status_update" and "fan" in data and "speed" in data["fan"] and
|
||||
self.user_selecting == False):
|
||||
self.fan_speed = float(int(float(data["fan"]["speed"]) * 100))
|
||||
self.labels["scale"].disconnect_by_func(self.select_fan_speed)
|
||||
self.labels["scale"].set_value(self.fan_speed)
|
||||
self.labels["scale"].connect("value-changed", self.select_fan_speed)
|
||||
|
||||
|
||||
def select_fan_speed(self, widget):
|
||||
if self.user_selecting == True:
|
||||
if (action != "notify_status_update"):
|
||||
return
|
||||
|
||||
self.user_selecting = True
|
||||
self.grid.attach(self.labels["apply"], 3, 0, 1, 1)
|
||||
self.grid.attach(self.labels["cancel"], 0, 0, 1, 1)
|
||||
self._screen.show_all()
|
||||
for fan in self.devices:
|
||||
if fan in data and "speed" in data[fan]:
|
||||
self.update_fan_speed(fan, data[fan]["speed"])
|
||||
|
||||
def cancel_select_fan_speed(self, widget):
|
||||
self.labels["scale"].set_value(self.fan_speed)
|
||||
self.user_selecting = False
|
||||
self.grid.remove(self.labels["apply"])
|
||||
self.grid.remove(self.labels["cancel"])
|
||||
def update_fan_speed(self, fan, speed):
|
||||
if fan not in self.devices:
|
||||
return
|
||||
if self.devices[fan]['changeable'] == True:
|
||||
if self.devices[fan]['scale'].has_grab():
|
||||
return
|
||||
self.fan_speed[fan] = round(float(speed) * 100)
|
||||
self.devices[fan]['scale'].disconnect_by_func(self.set_fan_speed)
|
||||
self.devices[fan]['scale'].set_value(self.fan_speed[fan])
|
||||
self.devices[fan]['scale'].connect("value-changed", self.set_fan_speed, fan)
|
||||
else:
|
||||
self.fan_speed[fan] = float(speed)
|
||||
self.devices[fan]['scale'].set_fraction(self.fan_speed[fan])
|
||||
|
||||
def add_fan(self, fan):
|
||||
logging.info("Adding fan: %s" % fan)
|
||||
changeable = False
|
||||
for x in CHANGEABLE_FANS:
|
||||
if fan.startswith(x) or fan == x:
|
||||
changeable = True
|
||||
break
|
||||
|
||||
def set_fan_speed(self, widget):
|
||||
self._screen._ws.klippy.gcode_script(KlippyGcodes.set_fan_speed(self.labels['scale'].get_value()))
|
||||
self.cancel_select_fan_speed(widget)
|
||||
frame = Gtk.Frame()
|
||||
frame.set_property("shadow-type",Gtk.ShadowType.NONE)
|
||||
frame.get_style_context().add_class("frame-item")
|
||||
|
||||
def set_fan_on(self, widget, fanon):
|
||||
speed = 100 if fanon == True else 0
|
||||
self._screen._ws.klippy.gcode_script(KlippyGcodes.set_fan_speed(speed))
|
||||
self.fan_speed = float(speed)
|
||||
self.labels["scale"].disconnect_by_func(self.select_fan_speed)
|
||||
self.labels["scale"].set_value(self.fan_speed)
|
||||
self.labels["scale"].connect("value-changed", self.select_fan_speed)
|
||||
self.cancel_select_fan_speed(widget)
|
||||
try:
|
||||
self.fan_speed[fan] = float(self._printer.get_data()[fan]["speed"])
|
||||
except Exception:
|
||||
self.fan_speed[fan] = 0
|
||||
|
||||
name = Gtk.Label()
|
||||
if fan == "fan":
|
||||
fan_name = "Part Fan"
|
||||
else:
|
||||
fan_name = " ".join(fan.split(" ")[1:])
|
||||
name.set_markup("<big><b>%s</b></big>" % (fan_name))
|
||||
name.set_hexpand(True)
|
||||
name.set_vexpand(True)
|
||||
name.set_halign(Gtk.Align.START)
|
||||
name.set_valign(Gtk.Align.CENTER)
|
||||
name.set_line_wrap(True)
|
||||
name.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
||||
|
||||
adj = Gtk.Adjustment(0, 0, 100, 1, 5, 0)
|
||||
if changeable == True:
|
||||
self.fan_speed[fan] = round(self.fan_speed[fan] * 100)
|
||||
scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=adj)
|
||||
scale.set_value(self.fan_speed[fan])
|
||||
scale.set_digits(0)
|
||||
scale.set_hexpand(True)
|
||||
scale.set_has_origin(True)
|
||||
scale.get_style_context().add_class("fan_slider")
|
||||
scale.connect("value-changed", self.set_fan_speed, fan)
|
||||
else:
|
||||
scale = Gtk.ProgressBar()
|
||||
scale.set_fraction(self.fan_speed[fan])
|
||||
scale.set_show_text(True)
|
||||
scale.set_hexpand(True)
|
||||
#scale.get_style_context().add_class("fan_slider")
|
||||
|
||||
labels = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
labels.add(name)
|
||||
labels.add(scale)
|
||||
|
||||
dev = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
|
||||
dev.set_hexpand(True)
|
||||
dev.set_vexpand(False)
|
||||
dev.add(labels)
|
||||
frame.add(dev)
|
||||
|
||||
self.devices[fan] = {
|
||||
"changeable": changeable,
|
||||
"row": frame,
|
||||
"scale": scale,
|
||||
}
|
||||
|
||||
devices = sorted(self.devices)
|
||||
if fan == "fan":
|
||||
pos = 0
|
||||
elif "fan" in devices:
|
||||
devices.pop(devices.index("fan"))
|
||||
pos = devices.index(fan) + 1
|
||||
else:
|
||||
pos = devices.index(fan)
|
||||
|
||||
self.labels['devices'].insert_row(pos)
|
||||
self.labels['devices'].attach(self.devices[fan]['row'], 0, pos, 1, 1)
|
||||
self.labels['devices'].show_all()
|
||||
|
||||
def load_fans(self):
|
||||
fans = self._printer.get_fans()
|
||||
for fan in fans:
|
||||
self.add_fan(fan)
|
||||
|
||||
def set_fan_speed(self, widget, fan):
|
||||
value = self.devices[fan]['scale'].get_value()
|
||||
|
||||
if fan == "fan":
|
||||
self._screen._ws.klippy.gcode_script(KlippyGcodes.set_fan_speed(value))
|
||||
else:
|
||||
f = " ".join(fan.split(" ")[1:])
|
||||
self._screen._ws.klippy.gcode_script("SET_FAN_SPEED FAN=%s SPEED=%s" % (f, float(value)/100))
|
||||
|
37
screen.py
37
screen.py
@ -41,17 +41,17 @@ import matplotlib.pyplot
|
||||
|
||||
PRINTER_BASE_STATUS_OBJECTS = [
|
||||
'bed_mesh',
|
||||
'idle_timeout',
|
||||
'configfile',
|
||||
'display_status',
|
||||
'gcode_move',
|
||||
'extruder',
|
||||
'fan',
|
||||
'gcode_move',
|
||||
'heater_bed',
|
||||
'idle_timeout',
|
||||
'pause_resume',
|
||||
'print_stats',
|
||||
'toolhead',
|
||||
'virtual_sdcard',
|
||||
'print_stats',
|
||||
'heater_bed',
|
||||
'extruder',
|
||||
'pause_resume',
|
||||
'webhooks'
|
||||
]
|
||||
|
||||
@ -259,6 +259,8 @@ class KlipperScreen(Gtk.Window):
|
||||
requested_updates['objects'][extruder] = ["target","temperature","pressure_advance","smooth_time"]
|
||||
for h in self.printer.get_heaters():
|
||||
requested_updates['objects'][h] = ["target","temperature"]
|
||||
for f in self.printer.get_fans():
|
||||
requested_updates['objects'][f] = ["speed"]
|
||||
|
||||
self._ws.klippy.object_subscription(requested_updates)
|
||||
|
||||
@ -775,9 +777,30 @@ class KlipperScreen(Gtk.Window):
|
||||
powerdevs = self.apiclient.send_request("machine/device_power/devices")
|
||||
data = data['result']['status']
|
||||
|
||||
config = self.apiclient.send_request("printer/objects/query?configfile")
|
||||
if config == False:
|
||||
logging.info("Error getting printer config data")
|
||||
return False
|
||||
|
||||
# Reinitialize printer, in case the printer was shut down and anything has changed.
|
||||
self.printer.reinit(printer_info['result'], data)
|
||||
self.printer.reinit(printer_info['result'], config['result']['status'])
|
||||
|
||||
self.ws_subscribe()
|
||||
extra_items = []
|
||||
for extruder in self.printer.get_tools():
|
||||
extra_items.append(extruder)
|
||||
for h in self.printer.get_heaters():
|
||||
extra_items.append(h)
|
||||
for f in self.printer.get_fans():
|
||||
extra_items.append(f)
|
||||
|
||||
data = self.apiclient.send_request("printer/objects/query?" + "&".join(PRINTER_BASE_STATUS_OBJECTS +
|
||||
extra_items))
|
||||
if data == False:
|
||||
logging.info("Error getting printer object data")
|
||||
return False
|
||||
logging.info("Startup data: %s" % data['result']['status'])
|
||||
self.printer.process_update(data['result']['status'])
|
||||
|
||||
self.files.initialize()
|
||||
self.files.refresh_files()
|
||||
|
@ -83,15 +83,22 @@ menuitem {
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
progress, trough {
|
||||
trough {
|
||||
min-height: 2em;
|
||||
background-color: #586e75; /*base01*/
|
||||
color: #fdf6e3; /*base3*/
|
||||
border: 1px solid #002b36; /*base03*/
|
||||
}
|
||||
|
||||
progress {
|
||||
trough highlight, trough progress {
|
||||
min-height: 2em;
|
||||
background-color: #b58900; /*solarazed-yellow*/
|
||||
color: #fdf6e3; /*base3*/
|
||||
border: 1px solid #002b36; /*base03*/
|
||||
}
|
||||
|
||||
trough progress.left {
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
scale mark {
|
||||
|
@ -84,15 +84,22 @@ menuitem {
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
progress, trough {
|
||||
trough {
|
||||
min-height: 2em;
|
||||
background-color: #404E57;
|
||||
color: white;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
progress {
|
||||
background-color: #d47b00;
|
||||
trough highlight, trough progress {
|
||||
min-height: 2em;
|
||||
background-color: #3584e4;
|
||||
color: white;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
trough progress.left {
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
scale mark {
|
||||
|
Loading…
x
Reference in New Issue
Block a user