bug idle status PGXL

This commit is contained in:
2026-01-11 16:50:38 +01:00
parent 3d06dd44d5
commit cd93f0ea67

View File

@@ -24,6 +24,9 @@ type Client struct {
stopChan chan struct{}
running bool
// Connection health tracking
lastAliveTime time.Time
// Auto fan management
autoFanEnabled bool
lastFanMode string // Remember last manual mode
@@ -104,6 +107,9 @@ func (c *Client) Start() error {
return nil
}
// Initialize connection tracking
c.lastAliveTime = time.Now()
// Try to connect, but don't fail if it doesn't work
// The poll loop will keep trying
_ = c.Connect()
@@ -165,9 +171,17 @@ func (c *Client) pollLoop() {
status.Connected = true
// Check if device is actually alive (not just TCP connected)
// If voltage is 0 and temperature is 0, device is probably off
// If voltage is 0 and temperature is 0, device might be temporarily idle
// Use a 3-second timeout before marking as disconnected (helps with morse code pauses)
if status.Voltage == 0 && status.Temperature == 0 {
status.Connected = false
// Check if we've seen valid data recently (within 3 seconds)
if time.Since(c.lastAliveTime) > 3*time.Second {
status.Connected = false
}
// else: Keep Connected = true (device is probably just idle between morse letters)
} else {
// Valid data received, update lastAliveTime
c.lastAliveTime = time.Now()
}
// Peak hold logic - keep highest power for 1 second