Squashed commit of the following: commit2676709ed5
Merge:eb1e26a7
26452c98
Author: zkk <1007518571@qq.com> Date: Mon Mar 31 11:13:17 2025 +0800 Merge commit '26452c9873d242518ae23f4db995367fbd21361d' into release commit26452c9873
Author: zkk <1007518571@qq.com> Date: Mon Mar 31 11:11:56 2025 +0800 修复非英文情况下开门状态不更新问题 commitc8048c9732
Author: zkk <1007518571@qq.com> Date: Mon Mar 31 10:51:44 2025 +0800 增加恢复出厂设置时禁用开门检测 commitd65dc6de13
Author: zkk <1007518571@qq.com> Date: Mon Mar 31 10:49:05 2025 +0800 修复选择版本没有反应的问题 commitfacebc5c8e
Author: zkk <1007518571@qq.com> Date: Sat Mar 29 17:29:22 2025 +0800 更新开门检测翻译 commit1b1322dffc
Author: zkk <1007518571@qq.com> Date: Sat Mar 29 16:50:54 2025 +0800 增加开门检测功能选项 commit58d8df6652
Author: zkk <1007518571@qq.com> Date: Sat Mar 29 15:31:20 2025 +0800 增加型号版本的选择 commitdf8ca1c547
Author: zkk <1007518571@qq.com> Date: Wed Mar 26 10:35:14 2025 +0800 优化机型显示名称 commiteb1e26a72d
Merge:d7698fd4
be25ed60
Author: zkk <1007518571@qq.com> Date: Mon Mar 17 16:44:05 2025 +0800 Merge commit 'be25ed60b5a0f89cddb8074cc9de1334d80f24aa' into release commitbe25ed60b5
Author: zkk <1007518571@qq.com> Date: Thu Mar 13 17:16:44 2025 +0800 优化首次开箱激活后没有主动关闭注册页面问题 commitd7698fd423
Merge:d6fcc79a
bc36533e
Author: zkk <1007518571@qq.com> Date: Mon Mar 10 15:13:20 2025 +0800 Merge commit 'bc36533ef7266c49c2ef8d9429fca1bc3fadf6f0' into release commitbc36533ef7
Author: zkk <1007518571@qq.com> Date: Mon Mar 10 14:23:56 2025 +0800 注册码增加测试功能 commitd6fcc79a20
Merge:69bcfa4b
7f6d43be
Author: zkk <1007518571@qq.com> Date: Tue Mar 4 16:08:21 2025 +0800 Merge commit '7f6d43be7085f8d9e5a236e684303fa2fdc7688b' into release commit7f6d43be70
Author: zkk <1007518571@qq.com> Date: Tue Mar 4 16:07:27 2025 +0800 新增图标文件,修复更改主题图标不更新的问题 commit69bcfa4bd0
Merge:2dba9f8e
964a81c3
Author: zkk <1007518571@qq.com> Date: Mon Mar 3 15:25:49 2025 +0800 Merge commit '964a81c37cd165b9f8df20db87fd915ba03d10b5' into release commit964a81c37c
Author: zkk <1007518571@qq.com> Date: Fri Feb 28 16:27:57 2025 +0800 状态栏增加网络连接图标 commit9c99cd9125
Author: zkk <1007518571@qq.com> Date: Fri Feb 28 16:20:52 2025 +0800 修复网络页面IP更新不及时的问题 commit842a616c25
Author: zkk <1007518571@qq.com> Date: Tue Feb 25 14:53:31 2025 +0800 注册码功能的实现 commit2dba9f8ee2
Merge:03cd3722
18f05cc5
Author: zkk <1007518571@qq.com> Date: Fri Feb 14 15:21:36 2025 +0800 Merge commit '18f05cc52dfb7889853a4f84aad975309ab7dbbe' into release commit18f05cc52d
Author: zkk <1007518571@qq.com> Date: Wed Feb 5 10:59:00 2025 +0800 修复连接不了未加密网络的旧问题 commit025a26209c
Author: zkk <1007518571@qq.com> Date: Fri Jan 24 15:48:52 2025 +0800 重构网络页面,解决卡顿问题 commitfdc851c4e6
Author: zkk <1007518571@qq.com> Date: Fri Jan 24 15:13:41 2025 +0800 优化菜单页面的点击效果和增加列表风格属性 commite6cfa87420
Author: zkk <1007518571@qq.com> Date: Tue Jan 21 15:11:28 2025 +0800 优化进入工厂模式的方式为10s内点击5次 commit03cd37229e
Merge:cf7cafef
adcbaa17
Author: zkk <1007518571@qq.com> Date: Fri Jan 17 14:38:18 2025 +0800 Merge commit 'adcbaa1795bffedc3000bc9e59eabba04d946dd4' into release commitadcbaa1795
Author: zkk <1007518571@qq.com> Date: Tue Jan 14 15:34:10 2025 +0800 实现探针偏移值校准保存前范围检测,避免保存错误值无法启动问题 commitcf7cafefbc
Merge:dc3478b4
8d259cea
Author: zkk <1007518571@qq.com> Date: Tue Jan 7 17:26:59 2025 +0800 Merge commit '8d259ceadd5026cecc1dc61224d91aef4f3877b4' into release commit8d259ceadd
Author: zkk <1007518571@qq.com> Date: Tue Jan 7 17:15:46 2025 +0800 实现 打印中恢复喷头温度 提示语的翻译 commitdd11c9683c
Author: zkk <1007518571@qq.com> Date: Tue Jan 7 16:52:04 2025 +0800 优化单个喷头时不显示喷头偏移菜单 commitc3ec7a81bb
Author: zkk <1007518571@qq.com> Date: Fri Jan 3 17:52:24 2025 +0800 修复屏幕耗材检测显示偶尔不准确的问题 commit413bf6fc4a
Author: zkk <1007518571@qq.com> Date: Fri Jan 3 15:00:54 2025 +0800 修复耗材检测弹窗异常问题 commitdc3478b48c
Merge:02c7556c
3bfc1aa7
Author: zkk <1007518571@qq.com> Date: Thu Jan 2 11:18:07 2025 +0800 Merge commit '3bfc1aa714e282d74b801155d830377ca58d8f59' into release commit3bfc1aa714
Author: zkk <1007518571@qq.com> Date: Thu Jan 2 11:17:15 2025 +0800 修复移轴页面移轴功能失效问题 commit02c7556cda
Merge:6bfa42e0
991003e6
Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:07:54 2024 +0800 Merge commit '991003e6cbea335eca73d3783aa1837059614724' into release commit991003e6cb
Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:03:34 2024 +0800 优化完整 简体中文和繁体中文的翻译 commit1a177e90d0
Author: zkk <1007518571@qq.com> Date: Tue Dec 31 14:10:03 2024 +0800 优化排除对象的英文语法错误 commite8d509cb6c
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 16:40:52 2024 +0800 优化耗材检测显示内容 commit1b7670485a
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 14:56:25 2024 +0800 完善断料自动切头功能描述 commitecc0c3dd16
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 13:40:01 2024 +0800 实现弹窗翻译功能 commitbc6d60fa18
Author: zkk <1007518571@qq.com> Date: Fri Dec 27 09:53:16 2024 +0800 优化不合理名称和不合理大小写 commit2e650926bd
Author: zkk <1007518571@qq.com> Date: Thu Dec 26 15:06:11 2024 +0800 修复10寸屏幕偏移值微调页面出界问题 commitc481b551f7
Author: zkk <1007518571@qq.com> Date: Wed Dec 25 15:28:26 2024 +0800 优化移轴设置页面没有返回按钮的问题 commit2b3c9936bd
Author: zkk <1007518571@qq.com> Date: Wed Dec 25 10:05:04 2024 +0800 删除移动设置页面中轴反转的选项 commit5e37d59497
Author: zkk <1007518571@qq.com> Date: Wed Dec 25 09:05:03 2024 +0800 优化选择语言标题 commit5214c3697b
Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:57:41 2024 +0800 增加设置hostname功能 commit3709a7465c
Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:43:46 2024 +0800 增加工厂设置中打包模式 commit0c2a2618be
Author: zkk <1007518571@qq.com> Date: Mon Dec 23 16:25:37 2024 +0800 实现恢复出厂设置功能 commite3a38f8561
Author: zkk <1007518571@qq.com> Date: Mon Dec 23 15:48:17 2024 +0800 一点格式化 commit4e9e452e8b
Author: zkk <1007518571@qq.com> Date: Sat Dec 21 14:20:22 2024 +0800 优化探针偏移值校准时如果当前激活为第一个喷头时不会重复激活喷头 commit3b85e8e8d5
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 commit882850dbde
Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:21:16 2024 +0800 补充双喷头偏移校准页面二维码图片 commit10ec2029eb
Author: ruipeng <1041589370@qq.com> Date: Wed Dec 18 17:17:18 2024 +0800 增加自动切换喷头开关选项 commit3d6eed9d95
Author: zkk <1007518571@qq.com> Date: Mon Dec 16 16:33:34 2024 +0800 喷头偏移值校准功能的实现 commit40ecbb3ea4
Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:20:00 2024 +0800 z探针校准时指定默认激活工具头为第一个头 commitbce3caa409
Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:19:19 2024 +0800 优化z探针校准时候移动过慢问题 commit6bfa42e036
Merge:1a87ced3
4f3aa9aa
Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:33:58 2024 +0800 Merge commit '4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f' into release commit4f3aa9aa4c
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 commit1a69b5180d
Author: ruipeng <1041589370@qq.com> Date: Wed Dec 11 11:44:36 2024 +0800 新增D600pro2、D1000的V0版机型 commite3fd413d62
Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:34:13 2024 +0800 修复打印时没有修改z偏移值 仍提示保存z偏移的按钮的bug commit594fb668fe
Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:25:04 2024 +0800 设置自适应调平选项默认为关闭状态 commit1a87ced3f5
Merge:629416d1
6064a6e1
Author: zkk <1007518571@qq.com> Date: Fri Nov 29 10:18:32 2024 +0800 Merge branch 'develop' into release # Conflicts: # config/model_menu.conf resolved by2676709ed5
version # ks_includes/KlippyFactory.py resolved by2676709ed5
version # ks_includes/ModelConfig.py resolved by2676709ed5
version # ks_includes/locales/KlipperScreen.pot resolved by2676709ed5
version # ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.mo resolved by2676709ed5
version # ks_includes/locales/zh_CN/LC_MESSAGES/KlipperScreen.po resolved by2676709ed5
version # ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.mo resolved by2676709ed5
version # ks_includes/locales/zh_TW/LC_MESSAGES/KlipperScreen.po resolved by2676709ed5
version # ks_includes/prompts_text.py resolved by2676709ed5
version # panels/advanced.py resolved by2676709ed5
version # panels/factory_settings.py resolved by2676709ed5
version
180 lines
8.1 KiB
Python
180 lines
8.1 KiB
Python
import subprocess
|
|
import os
|
|
import logging
|
|
|
|
|
|
class ModelConfig:
|
|
|
|
def __init__(self):
|
|
home = os.path.expanduser("~/")
|
|
printer_data_config = os.path.join(home, "printer_data", "config")
|
|
self.moonraker_config_path = printer_data_config + "/moonraker.conf"
|
|
self.klipperscreen_config_path = printer_data_config + "/KlipperScreen.conf"
|
|
self.printer_config_path = printer_data_config + "/printer.cfg"
|
|
|
|
def get_mac_address(self, interface):
|
|
try:
|
|
result = subprocess.run(
|
|
["ip", "link", "show", interface], capture_output=True, text=True
|
|
)
|
|
output = result.stdout
|
|
|
|
for line in output.split("\n"):
|
|
if "link/ether" in line:
|
|
mac_address = line.split()[1]
|
|
return mac_address
|
|
|
|
except Exception as e:
|
|
logging.error(f"get mac address error: {e}")
|
|
return None
|
|
|
|
def generate_machine_name(self, model):
|
|
mac_address = self.get_mac_address("eth0")
|
|
if mac_address:
|
|
mac_address = mac_address.replace(":", "")
|
|
last_four = mac_address[-4:]
|
|
machine_name = f"{model}-{last_four.upper()}"
|
|
return machine_name
|
|
else:
|
|
return None
|
|
|
|
def write_mdns_config(self, device_name):
|
|
if device_name:
|
|
try:
|
|
with open(self.moonraker_config_path, "r") as file:
|
|
lines = file.readlines()
|
|
|
|
with open(self.moonraker_config_path, "w") as file:
|
|
found_zeroconf_section = False
|
|
modified = False
|
|
|
|
for line in lines:
|
|
if line.strip().startswith("[zeroconf]"):
|
|
found_zeroconf_section = True
|
|
elif found_zeroconf_section and line.strip().startswith(
|
|
"mdns_hostname"
|
|
):
|
|
file.write(f"mdns_hostname:{device_name}\n")
|
|
found_zeroconf_section = False
|
|
modified = True
|
|
continue
|
|
elif found_zeroconf_section and line.strip().startswith(
|
|
"enable_ssdp"
|
|
):
|
|
file.write("enable_ssdp: True")
|
|
found_zeroconf_section = False
|
|
modified = True
|
|
continue
|
|
|
|
file.write(line)
|
|
|
|
if not modified:
|
|
file.write("\n[zeroconf]\n")
|
|
file.write(f"mdns_hostname:{device_name}\n")
|
|
file.write("enable_ssdp: True")
|
|
logging.info(f"Setting MDNS address to {device_name}")
|
|
except FileNotFoundError:
|
|
logging.error(
|
|
f"The configuration file {self.moonraker_config_path} not found"
|
|
)
|
|
|
|
def write_device_name_config(self, device_name):
|
|
if device_name:
|
|
try:
|
|
with open(self.klipperscreen_config_path, "r+") as file:
|
|
lines = file.readlines()
|
|
file.seek(0)
|
|
found_printer_section = False
|
|
for i, line in enumerate(lines):
|
|
if line.strip().startswith("[printer"):
|
|
lines[i] = f"[printer {device_name}]\n"
|
|
found_printer_section = True
|
|
break
|
|
if not found_printer_section:
|
|
lines.insert(0, f"[printer {device_name}]\n")
|
|
file.truncate(0)
|
|
file.writelines(lines)
|
|
logging.info(f"Setting device name to {device_name}")
|
|
except FileNotFoundError:
|
|
logging.error(
|
|
f"Configuration file {self.klipperscreen_config_path} not found."
|
|
)
|
|
|
|
def wirte_printer_config(self, device_name, version):
|
|
config_dict = {
|
|
"CreatBot_F430NX": "CreatBot_F430NX",
|
|
"CreatBot_D600Pro2HS": "CreatBot_D600Pro2",
|
|
"CreatBot_D600Pro2HS_KIT": "CreatBot_D600Pro2_V0",
|
|
"CreatBot_D1000HS": "CreatBot_D1000",
|
|
"CreatBot_D1000HS_KIT": "CreatBot_D1000_V0",
|
|
"CreatBot_P800": "CreatBot_P800",
|
|
}
|
|
if device_name:
|
|
source_path = f"{os.path.expanduser('~')}/klipper/config/{config_dict.get(device_name)}/"
|
|
target_path = f"{os.path.expanduser('~')}/printer_data/config/"
|
|
if not os.path.exists(target_path):
|
|
os.makedirs(target_path)
|
|
source_base_path = os.path.join(source_path, os.path.basename("base.cfg"))
|
|
target_base_path = os.path.join(target_path, os.path.basename("base.cfg"))
|
|
try:
|
|
if os.path.islink(target_base_path) or os.path.exists(target_base_path):
|
|
os.remove(target_base_path)
|
|
os.symlink(source_base_path, target_base_path)
|
|
logging.info(f"Created config symlink for {device_name}.")
|
|
except FileExistsError:
|
|
logging.error(f"Failed to create config symlink for {device_name}.")
|
|
except PermissionError:
|
|
logging.error(f"No permission to create symlink for {device_name}.")
|
|
except Exception as e:
|
|
logging.error(f"Error creating symlink for{device_name}:{e}")
|
|
|
|
source_module_path = os.path.join(source_path, os.path.basename(version))
|
|
target_module_path = os.path.join(target_path, os.path.basename("module"))
|
|
try:
|
|
if os.path.islink(target_module_path) or os.path.exists(target_module_path):
|
|
os.remove(target_module_path)
|
|
if version != "1.0":
|
|
os.symlink(source_module_path, target_module_path)
|
|
logging.info(f"Created config version for {device_name}-{version}.")
|
|
except FileExistsError:
|
|
logging.error(f"Failed to create version symlink for {device_name}.")
|
|
except PermissionError:
|
|
logging.error(f"No permission to create version symlink for {device_name}.")
|
|
except Exception as e:
|
|
logging.error(f"Error creating version symlink for{device_name}:{e}")
|
|
|
|
source_printer_path = os.path.join(source_path, os.path.basename("printer.cfg"))
|
|
target_printer_path = os.path.join(target_path, os.path.basename("printer.cfg"))
|
|
command = ['cp','-f', source_printer_path, target_printer_path]
|
|
try:
|
|
subprocess.run(command, check=True, text=True, capture_output=True)
|
|
logging.info(f"Configuration file copied successfully. {source_printer_path}' to '{target_printer_path}'")
|
|
except subprocess.CalledProcessError as e:
|
|
logging.error(f"Copy error config file: {e.stderr}")
|
|
except Exception as e:
|
|
logging.error(f"Copy error printer file: {e.stderr}")
|
|
|
|
def wirte_hostname(self, device_name):
|
|
|
|
try:
|
|
current_hostname = subprocess.check_output(["hostname"], text=True).strip()
|
|
logging.info(f"Current hostname: {current_hostname}")
|
|
subprocess.run(["hostnamectl", "set-hostname", device_name], check=True)
|
|
logging.info(f"Hostname has been changed to: {device_name}")
|
|
except subprocess.CalledProcessError as e:
|
|
logging.error(f"Error while executing command: {e}")
|
|
except Exception as e:
|
|
logging.error(f"An unexpected error occurred: {e}")
|
|
|
|
def generate_config(self, model, version):
|
|
model_name = model
|
|
model_name = model_name.split("_")[1]
|
|
device_name = self.generate_machine_name(model_name)
|
|
self.write_mdns_config(device_name)
|
|
self.write_device_name_config(device_name)
|
|
self.wirte_printer_config(model, version)
|
|
self.wirte_hostname(device_name)
|
|
os.system("systemctl restart klipper.service")
|
|
os.system("systemctl restart moonraker.service")
|
|
os.system("systemctl restart KlipperScreen.service")
|