fix: isolate fan writes from active RGB frames
This commit is contained in:
@@ -98,6 +98,9 @@ def bus_write(method,*args):
|
||||
raise
|
||||
|
||||
fan_level=0
|
||||
fan_initialized=False
|
||||
pending_fan=None
|
||||
pending_fan_lock=threading.Lock()
|
||||
prev_cpu=None
|
||||
page=0; page_since=time.monotonic()
|
||||
cpu_hi=mem_hi=0
|
||||
@@ -180,13 +183,32 @@ def fan_target(t):
|
||||
if t<FAN_T[4]: return 4
|
||||
return 5
|
||||
def update_fan(t):
|
||||
global fan_level
|
||||
want=fan_target(t); old=fan_level
|
||||
global fan_level,fan_initialized,pending_fan
|
||||
want=fan_target(t); old=fan_level if fan_initialized else None
|
||||
if want>fan_level: fan_level=want
|
||||
elif want<fan_level:
|
||||
boundary = FAN_T[max(0,fan_level-1)] - FAN_HYST
|
||||
if t < boundary: fan_level-=1
|
||||
if old!=fan_level: mcu(0x08,FAN_REG[fan_level])
|
||||
if not fan_initialized or old!=fan_level:
|
||||
with pending_fan_lock:
|
||||
pending_fan=(old,fan_level,float(t))
|
||||
fan_initialized=True
|
||||
|
||||
def apply_pending_fan():
|
||||
global pending_fan
|
||||
with pending_fan_lock:
|
||||
command=pending_fan
|
||||
pending_fan=None
|
||||
if command is None: return
|
||||
old,new,temp=command
|
||||
try:
|
||||
mcu(0x08,FAN_REG[new])
|
||||
except Exception:
|
||||
with pending_fan_lock:
|
||||
if pending_fan is None: pending_fan=command
|
||||
raise
|
||||
log("INFO","FAN_LEVEL",old=FAN_NAME[old] if old is not None else "UNKNOWN",
|
||||
new=FAN_NAME[new],temp_c=f"{temp:.1f}",register=f"0x{FAN_REG[new]:02x}")
|
||||
|
||||
def cpu_pct():
|
||||
global prev_cpu
|
||||
@@ -756,6 +778,11 @@ class DisplayController:
|
||||
rgb_static(NORMAL_COLOR,"normal_flash_on") if on else rgb_off()
|
||||
else: rgb_flash(applied_mode,on)
|
||||
flash_on=on
|
||||
# Fan and RGB share the same MCU. During an alert flash, send
|
||||
# fan changes only while RGB is already dark so MCU-internal
|
||||
# register handling cannot expose a transient unrelated color.
|
||||
if not applied_flash or flash_on is False:
|
||||
with bus_lock: apply_pending_fan()
|
||||
if previous_error is not None: log("INFO","RGB_RECOVERED")
|
||||
previous_error=None
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user