up
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
<<<<<<< HEAD
|
||||
host string
|
||||
port int
|
||||
conn net.Conn
|
||||
@@ -23,11 +22,6 @@ type Client struct {
|
||||
statusMu sync.RWMutex
|
||||
stopChan chan struct{}
|
||||
running bool
|
||||
=======
|
||||
host string
|
||||
port int
|
||||
conn net.Conn
|
||||
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
@@ -54,18 +48,17 @@ type Status struct {
|
||||
RelayC2 int `json:"c2"`
|
||||
TuningStatus string `json:"tuning_status"`
|
||||
Connected bool `json:"connected"`
|
||||
|
||||
// Peak hold for display (internal)
|
||||
displayPower float64
|
||||
peakTime time.Time
|
||||
}
|
||||
|
||||
func New(host string, port int) *Client {
|
||||
return &Client{
|
||||
<<<<<<< HEAD
|
||||
host: host,
|
||||
port: port,
|
||||
stopChan: make(chan struct{}),
|
||||
=======
|
||||
host: host,
|
||||
port: port,
|
||||
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +103,6 @@ func (c *Client) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Try to connect, but don't fail if it doesn't work
|
||||
// The poll loop will keep trying
|
||||
_ = c.Connect()
|
||||
@@ -171,6 +163,33 @@ func (c *Client) pollLoop() {
|
||||
// Mark as connected
|
||||
status.Connected = true
|
||||
|
||||
// Peak hold logic - keep highest power for 1 second
|
||||
now := time.Now()
|
||||
if c.lastStatus != nil {
|
||||
// If new power is higher, update peak
|
||||
if status.PowerForward > c.lastStatus.displayPower {
|
||||
status.displayPower = status.PowerForward
|
||||
status.peakTime = now
|
||||
} else {
|
||||
// Check if peak has expired (1 second)
|
||||
if now.Sub(c.lastStatus.peakTime) < 1*time.Second {
|
||||
// Keep old peak
|
||||
status.displayPower = c.lastStatus.displayPower
|
||||
status.peakTime = c.lastStatus.peakTime
|
||||
} else {
|
||||
// Peak expired, use current value
|
||||
status.displayPower = status.PowerForward
|
||||
status.peakTime = now
|
||||
}
|
||||
}
|
||||
} else {
|
||||
status.displayPower = status.PowerForward
|
||||
status.peakTime = now
|
||||
}
|
||||
|
||||
// Override PowerForward with display power for frontend
|
||||
status.PowerForward = status.displayPower
|
||||
|
||||
c.statusMu.Lock()
|
||||
c.lastStatus = status
|
||||
c.statusMu.Unlock()
|
||||
@@ -221,8 +240,6 @@ func (c *Client) sendCommand(cmd string) (string, error) {
|
||||
return "", fmt.Errorf("not connected")
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> 4ab192418e21065c68d59777493ea03b76c061e7
|
||||
// Get next command ID from global counter
|
||||
cmdID := GetGlobalCommandID().GetNextID()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user