From 4367d0b9d0e304c6ab0520b11897496689d433cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A1=E5=8F=A3=E6=B5=AA=E4=BA=BA?= Date: Sun, 27 Sep 2026 21:14:22 +0800 Subject: [PATCH] feat: configure built-in breathing colors per alert category --- README.md | 2 +- SHA256SUMS | 8 ++++---- app/runtime.py | 2 +- app/settings.py | 7 +++++-- config/pigway-cooling-hat.conf | 10 ++++++++++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5b12db8..7d037b5 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ curl --unix-socket /run/pigway-plugins/yahboom-cooling-hat/api.sock http://local ## RGB 与已知限制 -默认 MCU 内置呼吸:CPU红、电源黄、内存紫、存储白、网络蓝、服务青;严重等级使用速度档1/2/3,可配置。速度档不是精确秒数,预置色不支持任意 RGB 或橙色呼吸。相同 effect/speed/color 不重复下发,无周期性“预热”。 +内置呼吸支持为每类告警独立选择红、绿、蓝、黄、紫、青、白,可在 Web 插件配置或 `[rgb]` 的 `<对象>_breathe_color` 中设置。默认 MCU 内置呼吸:CPU红、电源黄、内存紫、存储白、网络蓝、服务青;严重等级使用速度档1/2/3,可配置。速度档不是精确秒数,预置色不支持任意 RGB 或橙色呼吸。相同 effect/speed/color 不重复下发,无周期性“预热”。 自定义颜色常亮和闪烁仍保留。闪烁是实验性兼容路径:全选→R→全选→G→全选→B,每条间隔5ms;亮灭均完整写三个通道,灭灯写 RGB=0;实际每段至少 `custom_min_hold_ms`(最低1500ms),从指令完成后计时,不追赶延迟边沿。既往实机曾出现异色/漏执行,未证明存在完全稳定的自定义协议,不宣称这些限制能修好 MCU。 diff --git a/SHA256SUMS b/SHA256SUMS index 5bcaa7e..bd74240 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1,13 +1,13 @@ -74aaf7f7d07d49c7103dfb1dd3ca624c0d4efe5838c76073402541f81d37b42b README.md +1331f33332c6c33ecfc3e91d8734ee3ff7755ac1c2ac337fb2e5c367072c1ea7 README.md 30646b607d69dcbddbd5b41119a22f63ffb8de22929d1d0f9ff3715326a5bca6 install.sh cd6bb5137dd5922e48866f6daf4b949a16f8fad321e77addd5b4f75181bc4248 uninstall.sh 1c7836f80b0845fbc5c4b8570b12d736e2a3c442b1ceb5d35d48cdd518e4ad50 app/drivers/yahboom.py 215a62acc0a5c87303d6c52c0a2585b87dfb5cdbafbe9e9e733523d48a6a9812 app/migrate.py 72c46162c33f9587c6ccb01ad53fbaaf4ecec8cd21014b909e87e8707e253e36 app/oled_font_5x7.bin -1b8d4cf4e4668a7b1f111114e58a72fe28008190798c6e7674fb6a3e6f18dcca app/runtime.py +1803eebf7917291587204db85f74e2009e87f3a7b27a194b1aba245aa49b442b app/runtime.py e5153007a3562dc48468c6cee74de55de35844fc1e0e4d0cf00feb696991e14f app/service.py -5b16bb49bca6d4a37730ff564143f0f4d5ee73ff391bd79c983c29bc92fdcf66 app/settings.py -6440b23fb71a646ed7bb600471457147a6ed7bc850434dfff445c001c96a9480 config/pigway-cooling-hat.conf +0bd9cf86e5c8c5b36ded2dc957a38ad50ec23ccc69ba91c9968d3f76391ef1c9 app/settings.py +0e1cd04786652bb0a54589b43050937c1bdc6cf1ec6a549d611cf7229c29761a config/pigway-cooling-hat.conf c373cdde2b937bbc58d4b227f3a1d2923f0816c13f1e34548ed1f3b26c101ed5 systemd/pigway-cooling-hat.service 73b7922be93bf57169589755137dc5ec7ec7c8059c85c2bf2ee53a344e534d7e docs/HARDWARE_PLUGIN_API.md 7ca33e7a4361673d153b5e6212447d53091e223ee05ec24411083d6c052f2894 app/local_state.py diff --git a/app/runtime.py b/app/runtime.py index 75cbbdb..71c6cfe 100644 --- a/app/runtime.py +++ b/app/runtime.py @@ -200,7 +200,7 @@ class Controller: if a: group=a['category'];level=('warning','critical','emergency')[int(a['severity'])-1] label=f"{group}_{level}_{c['alert_mode']}".upper() - if c['alert_mode']=='breathe':return ('effect',1,c[level+'_speed'],COLORS[GROUPS[group]],c['write_delay_ms']),label + if c['alert_mode']=='breathe':return ('effect',1,c[level+'_speed'],COLORS[c.get(group+'_breathe_color',GROUPS[group])],c['write_delay_ms']),label mode='flash';prefix=level else: group='normal';prefix='normal';mode=c['normal_mode'];label='NORMAL_'+mode.upper() diff --git a/app/settings.py b/app/settings.py index c77260d..b28467c 100644 --- a/app/settings.py +++ b/app/settings.py @@ -31,6 +31,9 @@ for level,value in (("warning",1),("critical",2),("emergency",3)): option("rgb",f"{level}_flash_{edge}_ms",1500,f"{ {'warning':'普通','critical':'严重','emergency':'紧急'}[level]}告警{'亮灯' if edge=='on' else '灭灯'}时间",f"{level.title()} flash {edge}",minimum=50,maximum=60000,unit="ms",visible={"alert_mode":["flash"]}) for edge in ("on","off"): option("rgb",f"normal_flash_{edge}_ms",1500,"正常闪烁"+("亮灯" if edge=="on" else "灭灯")+"时间",f"Normal flash {edge}",minimum=50,maximum=60000,unit="ms",visible={"normal_mode":["flash"]}) +for group,color in GROUPS.items(): + title={"cpu":"处理器、温度与散热","power":"电源","memory":"内存","storage":"存储","network":"网络","service":"服务与进程"}[group] + option("rgb",group+"_breathe_color",color,title+"呼吸颜色",group.title()+" breathing color","enum",choices=list(COLORS),visible={"alert_mode":["breathe"]}) for group,values in DEFAULT_RGB.items(): for channel,value in zip("rgb",values): title={"cpu":"处理器","power":"电源","memory":"内存","storage":"存储","network":"网络","service":"服务","normal":"正常"}[group] @@ -87,8 +90,8 @@ def descriptor(): "fan":{"control":"levels","levels":["OFF","L1","L2","L3","L4","MAX"],"rpm":False,"autonomous":True,"owner":"plugin"}, "display":{"width":128,"height":32,"pages":True}, "rgb":{"modes":list(dict.fromkeys(["off","breathe","flash","solid",*EFFECTS])),"preset_colors":list(COLORS),"custom_flash_experimental":True}}, - "notes":[{"zh":"内置呼吸使用预置颜色:CPU红、电源黄、内存紫、存储白、网络蓝、服务青。自定义闪烁仍可能异色。", - "en":"Built-in breathing uses presets: CPU red, power yellow, memory purple, storage white, network blue, services cyan. Custom flashing may still show incorrect colors."}, + "notes":[{"zh":"内置呼吸可按告警对象选择预置颜色(红、绿、蓝、黄、紫、青、白);默认CPU红、电源黄、内存紫、存储白、网络蓝、服务青。自定义闪烁仍可能异色。", + "en":"Built-in breathing colors are configurable per alert category (red, green, blue, yellow, purple, cyan, white). Defaults: CPU red, power yellow, memory purple, storage white, network blue, services cyan. Custom flashing may still show incorrect colors."}, {"zh":"自定义闪烁的实际亮灭保持时间不低于最小保持时间。停止插件会请求风扇全速;风扇没有RPM反馈。", "en":"Custom flash phases last at least the minimum hold time. Stopping the plugin requests full fan speed; RPM feedback is unavailable."}], "schema":SCHEMA} diff --git a/config/pigway-cooling-hat.conf b/config/pigway-cooling-hat.conf index 8643947..d053f7e 100644 --- a/config/pigway-cooling-hat.conf +++ b/config/pigway-cooling-hat.conf @@ -99,3 +99,13 @@ normal_r = 0 normal_g = 0 # 正常 · B / Normal · B; 0..255 normal_b = 0 + +# 各告警对象的内置呼吸颜色 / Built-in breathing color per alert category. +# 可选 / Choices: red, green, blue, yellow, purple, cyan, white. +# 仅 alert_mode=breathe 生效;不影响自定义闪烁 RGB / Only for breathing, independent of custom flash RGB. +cpu_breathe_color = red +power_breathe_color = yellow +memory_breathe_color = purple +storage_breathe_color = white +network_breathe_color = blue +service_breathe_color = cyan