fix: small bug for PGXL fan and ultrabeam direction
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user