Squashed commit of the following: commit 02c7556cdadf8de1ef3c54d2831920927cadbe30 Merge: 6bfa42e0 991003e6 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:07:54 2024 +0800 Merge commit '991003e6cbea335eca73d3783aa1837059614724' into release commit 991003e6cbea335eca73d3783aa1837059614724 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:03:34 2024 +0800 优化完整 简体中文和繁体中文的翻译 commit 1a177e90d09b9b9949bff2a1e3c6b12173420620 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 14:10:03 2024 +0800 优化排除对象的英文语法错误 commit e8d509cb6c2883b1fadb5ab9f9ca658e61849055 Author: zkk <1007518571@qq.com> Date: Fri Dec 27 16:40:52 2024 +0800 优化耗材检测显示内容 commit 1b7670485a918cb334119175777525f768e670be Author: zkk <1007518571@qq.com> Date: Fri Dec 27 14:56:25 2024 +0800 完善断料自动切头功能描述 commit ecc0c3dd16442497e56f5f8ab3a0c6be00bd180e Author: zkk <1007518571@qq.com> Date: Fri Dec 27 13:40:01 2024 +0800 实现弹窗翻译功能 commit bc6d60fa183af50b7b16fea685139ca9d5df90ea Author: zkk <1007518571@qq.com> Date: Fri Dec 27 09:53:16 2024 +0800 优化不合理名称和不合理大小写 commit 2e650926bdba1c65baa506be1b1dd09621e8d8ea Author: zkk <1007518571@qq.com> Date: Thu Dec 26 15:06:11 2024 +0800 修复10寸屏幕偏移值微调页面出界问题 commit c481b551f777a3a6cadf7be3bfcab38448b51694 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 15:28:26 2024 +0800 优化移轴设置页面没有返回按钮的问题 commit 2b3c9936bd693c8fc265d6352799f382680f4920 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 10:05:04 2024 +0800 删除移动设置页面中轴反转的选项 commit 5e37d59497c54086d3f1e215cbabc03254857a58 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 09:05:03 2024 +0800 优化选择语言标题 commit 5214c3697baac78bd0a465e33d6f4f3c1e30862e Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:57:41 2024 +0800 增加设置hostname功能 commit 3709a7465cc2e0d677ecc9979fb18144f7e0ec33 Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:43:46 2024 +0800 增加工厂设置中打包模式 commit 0c2a2618beb68d50601e433beef06122fb0ffd40 Author: zkk <1007518571@qq.com> Date: Mon Dec 23 16:25:37 2024 +0800 实现恢复出厂设置功能 commit e3a38f85613d53a4a063e835c34c701196010c6e Author: zkk <1007518571@qq.com> Date: Mon Dec 23 15:48:17 2024 +0800 一点格式化 commit 4e9e452e8bed4b53eaaae8f0a69142de8aa50611 Author: zkk <1007518571@qq.com> Date: Sat Dec 21 14:20:22 2024 +0800 优化探针偏移值校准时如果当前激活为第一个喷头时不会重复激活喷头 commit 3b85e8e8d59b0d4eae75f80d9e637fe9dc272cbe Merge: 882850db 10ec2029 Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:26:08 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit 882850dbde648598e5f91281101d0ea01fd56d56 Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:21:16 2024 +0800 补充双喷头偏移校准页面二维码图片 commit 10ec2029eb73e66874d5a0ec492c016480641110 Author: ruipeng <1041589370@qq.com> Date: Wed Dec 18 17:17:18 2024 +0800 增加自动切换喷头开关选项 commit 3d6eed9d9526b77472ba7df29014b5768c594026 Author: zkk <1007518571@qq.com> Date: Mon Dec 16 16:33:34 2024 +0800 喷头偏移值校准功能的实现 commit 40ecbb3ea4827c9bac1aa271cccc958c94c1114a Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:20:00 2024 +0800 z探针校准时指定默认激活工具头为第一个头 commit bce3caa409618ef5bc2067865940d14a1441c0f8 Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:19:19 2024 +0800 优化z探针校准时候移动过慢问题 commit 6bfa42e036a521c8ff7db1bf8ccb65500eabb6ea Merge: 1a87ced3 4f3aa9aa Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:33:58 2024 +0800 Merge commit '4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f' into release commit 4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f Merge: e3fd413d 1a69b518 Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:30:00 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit 1a69b5180de733f15550a1294a7221d6070306a0 Author: ruipeng <1041589370@qq.com> Date: Wed Dec 11 11:44:36 2024 +0800 新增D600pro2、D1000的V0版机型 commit e3fd413d6256414441e9fe653c1132b1799a5cb2 Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:34:13 2024 +0800 修复打印时没有修改z偏移值 仍提示保存z偏移的按钮的bug commit 594fb668fe94fe907c028bf65ecced43ea8660cb Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:25:04 2024 +0800 设置自适应调平选项默认为关闭状态 commit 1a87ced3f5725569a6b9a7ee5f5250044d01d852 Merge: 629416d1 6064a6e1 Author: zkk <1007518571@qq.com> Date: Fri Nov 29 10:18:32 2024 +0800 Merge branch 'develop' into release # Conflicts: # panels/advanced.py # panels/nozzle_offset.py # panels/offset_fine_tune.py # panels/zcalibrate.py
167 lines
7.7 KiB
Python
167 lines
7.7 KiB
Python
import re
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gtk, Pango
|
|
from ks_includes.screen_panel import ScreenPanel
|
|
|
|
|
|
# X and Y frequencies
|
|
XY_FREQ = [
|
|
{'name': 'X', 'config': 'shaper_freq_x', 'min': 0, 'max': 133},
|
|
{'name': 'Y', 'config': 'shaper_freq_y', 'min': 0, 'max': 133},
|
|
]
|
|
SHAPERS = ['zv', 'mzv', 'zvd', 'ei', '2hump_ei', '3hump_ei']
|
|
|
|
|
|
class Panel(ScreenPanel):
|
|
def __init__(self, screen, title):
|
|
title = title or _("Input Shaper")
|
|
super().__init__(screen, title)
|
|
self.freq_xy_adj = {}
|
|
self.freq_xy_combo = {}
|
|
self.calibrate_btn = self._gtk.Button("move", _('Finding ADXL'), "color1", lines=1)
|
|
self.calibrate_btn.connect("clicked", self.on_popover_clicked)
|
|
self.calibrate_btn.set_sensitive(False)
|
|
self.status = Gtk.Label(hexpand=True, vexpand=False, halign=Gtk.Align.START, ellipsize=Pango.EllipsizeMode.END)
|
|
self.calibrating_axis = None
|
|
self.calibrating_axis = None
|
|
|
|
auto_calibration_label = Gtk.Label(hexpand=True)
|
|
auto_calibration_label.set_markup("<big><b>{}</b></big>".format(_("Auto Calibration")))
|
|
|
|
auto_grid = Gtk.Grid()
|
|
auto_grid.attach(auto_calibration_label, 0, 0, 1, 1)
|
|
auto_grid.attach(self.calibrate_btn, 1, 0, 1, 1)
|
|
|
|
input_grid = Gtk.Grid()
|
|
|
|
for i, dim_freq in enumerate(XY_FREQ):
|
|
axis_lbl = Gtk.Label(hexpand=False, vexpand=True, halign=Gtk.Align.START, valign=Gtk.Align.CENTER,
|
|
wrap=True)
|
|
axis_lbl.set_markup(f"<b>{dim_freq['name']}</b>")
|
|
|
|
self.freq_xy_adj[dim_freq['config']] = Gtk.Adjustment(0, dim_freq['min'], dim_freq['max'], 0.1)
|
|
scale = Gtk.Scale(adjustment=self.freq_xy_adj[dim_freq['config']],
|
|
digits=1, hexpand=True, valign=Gtk.Align.END, has_origin=True)
|
|
scale.get_style_context().add_class("option_slider")
|
|
scale.connect("button-release-event", self.set_opt_value, dim_freq['config'])
|
|
|
|
shaper_slug = dim_freq['config'].replace('_freq_', '_type_')
|
|
self.freq_xy_combo[shaper_slug] = Gtk.ComboBoxText()
|
|
for shaper in SHAPERS:
|
|
self.freq_xy_combo[shaper_slug].append(shaper, shaper)
|
|
self.freq_xy_combo[shaper_slug].set_active(0)
|
|
|
|
input_grid.attach(axis_lbl, 0, i + 2, 1, 1)
|
|
input_grid.attach(scale, 1, i + 2, 1, 1)
|
|
input_grid.attach(self.freq_xy_combo[shaper_slug], 2, i + 2, 1, 1)
|
|
|
|
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
|
box.add(auto_grid)
|
|
box.add(input_grid)
|
|
box.add(self.status)
|
|
|
|
self.content.add(box)
|
|
|
|
pobox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
|
pobox.get_style_context().add_class("measure_button")
|
|
test_x = self._gtk.Button(label=_("Measure X"))
|
|
test_x.connect("clicked", self.start_calibration, "x")
|
|
pobox.pack_start(test_x, True, True, 5)
|
|
test_y = self._gtk.Button(label=_("Measure Y"))
|
|
test_y.connect("clicked", self.start_calibration, "y")
|
|
pobox.pack_start(test_y, True, True, 5)
|
|
test_both = self._gtk.Button(label=_("Measure Both"))
|
|
test_both.connect("clicked", self.start_calibration, "both")
|
|
pobox.pack_start(test_both, True, True, 5)
|
|
self.labels['popover'] = Gtk.Popover()
|
|
self.labels['popover'].add(pobox)
|
|
self.labels['popover'].set_position(Gtk.PositionType.LEFT)
|
|
|
|
def on_popover_clicked(self, widget):
|
|
self.labels['popover'].set_relative_to(widget)
|
|
self.labels['popover'].show_all()
|
|
|
|
def start_calibration(self, widget, method):
|
|
self.labels['popover'].popdown()
|
|
if self._printer.get_stat("toolhead", "homed_axes") != "xyz":
|
|
self._screen._ws.klippy.gcode_script("G28")
|
|
self.calibrating_axis = method
|
|
if method == "x":
|
|
self._screen._send_action(self.calibrate_btn, "printer.gcode.script", {"script": 'SHAPER_CALIBRATE AXIS=X'})
|
|
if method == "y":
|
|
self._screen._send_action(self.calibrate_btn, "printer.gcode.script", {"script": 'SHAPER_CALIBRATE AXIS=Y'})
|
|
if method == "both":
|
|
self._screen._send_action(self.calibrate_btn, "printer.gcode.script", {"script": 'SHAPER_CALIBRATE'})
|
|
self.calibrate_btn.set_label(_('Calibrating') + '...')
|
|
|
|
def set_opt_value(self, widget, opt, *args):
|
|
shaper_freq_x = self.freq_xy_adj['shaper_freq_x'].get_value()
|
|
shaper_freq_y = self.freq_xy_adj['shaper_freq_y'].get_value()
|
|
shaper_type_x = self.freq_xy_combo['shaper_type_x'].get_active_text()
|
|
shaper_type_y = self.freq_xy_combo['shaper_type_y'].get_active_text()
|
|
|
|
self._screen._ws.klippy.gcode_script(
|
|
f'SET_INPUT_SHAPER '
|
|
f'SHAPER_FREQ_X={shaper_freq_x} '
|
|
f'SHAPER_TYPE_X={shaper_type_x} '
|
|
f'SHAPER_FREQ_Y={shaper_freq_y} '
|
|
f'SHAPER_TYPE_Y={shaper_type_y}'
|
|
)
|
|
|
|
def save_config(self):
|
|
|
|
script = {"script": "SAVE_CONFIG"}
|
|
self._screen._confirm_send_action(
|
|
None,
|
|
_("Save configuration?") + "\n\n" + _("Klipper will reboot"),
|
|
"printer.gcode.script",
|
|
script
|
|
)
|
|
|
|
def activate(self):
|
|
# This will return the current values
|
|
self._screen._ws.klippy.gcode_script('SET_INPUT_SHAPER')
|
|
# Check for the accelerometer
|
|
self._screen._ws.klippy.gcode_script('ACCELEROMETER_QUERY')
|
|
# Send at least two commands, with my accelerometer the first command after a reboot will fail
|
|
self._screen._ws.klippy.gcode_script('MEASURE_AXES_NOISE')
|
|
|
|
def process_update(self, action, data):
|
|
if action != "notify_gcode_response":
|
|
return
|
|
self.status.set_text(f"{data.replace('shaper_', '').replace('damping_', '')}")
|
|
data = data.lower()
|
|
if 'got 0' in data:
|
|
self.calibrate_btn.set_label(_('Check ADXL Wiring'))
|
|
self.calibrate_btn.set_sensitive(False)
|
|
if 'unknown command:"accelerometer_query"' in data:
|
|
self.calibrate_btn.set_label(_('ADXL Not Configured'))
|
|
self.calibrate_btn.set_sensitive(False)
|
|
if 'adxl345 values' in data or 'axes noise' in data:
|
|
self.calibrate_btn.set_sensitive(True)
|
|
self.calibrate_btn.set_label(_('Auto-calibrate'))
|
|
# Recommended shaper_type_y = ei, shaper_freq_y = 48.4 Hz
|
|
if 'recommended shaper_type_' in data:
|
|
results = re.search(r'shaper_type_(?P<axis>[xy])\s*=\s*(?P<shaper_type>.*?), shaper_freq_.\s*=\s*('
|
|
r'?P<shaper_freq>[0-9.]+)', data)
|
|
if results:
|
|
results.groupdict()
|
|
self.freq_xy_adj['shaper_freq_' + results['axis']].set_value(float(results['shaper_freq']))
|
|
self.freq_xy_combo['shaper_type_' + results['axis']].set_active(SHAPERS.index(results['shaper_type']))
|
|
if self.calibrating_axis == results['axis'] or (self.calibrating_axis == "both" and results['axis'] == 'y'):
|
|
self.calibrate_btn.set_sensitive(True)
|
|
self.calibrate_btn.set_label(_('Calibrated'))
|
|
self.save_config()
|
|
# shaper_type_y:ei shaper_freq_y:48.400 damping_ratio_y:0.100000
|
|
if 'shaper_type_' in data:
|
|
if results := re.search(
|
|
r'shaper_type_(?P<axis>[xy]):(?P<shaper_type>.*?) shaper_freq_.:('
|
|
r'?P<shaper_freq>[0-9.]+)',
|
|
data,
|
|
):
|
|
results = results.groupdict()
|
|
self.freq_xy_adj['shaper_freq_' + results['axis']].set_value(float(results['shaper_freq']))
|
|
self.freq_xy_combo['shaper_type_' + results['axis']].set_active(SHAPERS.index(results['shaper_type']))
|