fix: small bug for PGXL fan and ultrabeam direction

This commit is contained in:
2026-06-22 17:29:29 +02:00
parent 9b0d7ce1dc
commit 60bcd2422d
2 changed files with 38 additions and 2 deletions
+23
View File
@@ -68,6 +68,13 @@ type Client struct {
running bool
seqNum byte
seqMu sync.Mutex
// Optimistic pattern direction kept until the antenna's status poll reports
// it (or it ages out) — the motors take a second or two, and a stale poll in
// between would otherwise snap the UI back to the old direction.
pendingDir int
pendingDirAt time.Time
pendingDirSet bool
}
type Status struct {
@@ -199,6 +206,14 @@ func (c *Client) pollLoop() {
}
c.statusMu.Lock()
// Keep a just-commanded direction until the antenna reports it.
if c.pendingDirSet {
if time.Since(c.pendingDirAt) > 4*time.Second || status.Direction == c.pendingDir {
c.pendingDirSet = false
} else {
status.Direction = c.pendingDir
}
}
c.lastStatus = status
c.statusMu.Unlock()
@@ -449,6 +464,14 @@ func (c *Client) SetFrequency(freqKhz int, direction int) error {
}
_, err := c.sendCommand(CMD_FREQ, data)
if err == nil {
c.statusMu.Lock()
c.pendingDir, c.pendingDirAt, c.pendingDirSet = direction, time.Now(), true
if c.lastStatus != nil {
c.lastStatus.Direction = direction // reflect immediately
}
c.statusMu.Unlock()
}
return err
}