Skip to content

Commit

Permalink
Create packages with numbers more efficiently as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Dec 11, 2024
1 parent 4af9834 commit d4751d8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 0 additions & 2 deletions remote/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"net"
)

const commandFormat = "-%s.%s\r"

// Control implements remote IP control of supported Hegel amplifiers.
type Control struct {
conn io.ReadWriteCloser
Expand Down
9 changes: 6 additions & 3 deletions remote/reset.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package remote

import (
"fmt"
"strconv"
)

// SetResetDelay sets a timeout, in minutes, for when to reset.
func (c *Control) SetResetDelay(delay uint8) error {
number := strconv.FormatUint(uint64(delay), 10)
_, err := fmt.Fprintf(c.conn, commandFormat, "r", number)
packet := make([]byte, 0, 7)
packet = append(packet, "-r."...)
packet = strconv.AppendUint(packet, uint64(delay), 10)
packet = append(packet, '\r')

_, err := c.conn.Write(packet)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions remote/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package remote

import (
"errors"
"fmt"
"strconv"

"github.com/Jacalz/hegelmote/device"
Expand All @@ -29,8 +28,12 @@ func (c *Control) SetSourceNumber(number uint) error {
return errSorceInputIsZero
}

parameter := strconv.FormatUint(uint64(number), 10)
_, err := fmt.Fprintf(c.conn, commandFormat, "i", parameter)
packet := make([]byte, 0, 7)
packet = append(packet, "-i."...)
packet = strconv.AppendUint(packet, uint64(number), 10)
packet = append(packet, '\r')

_, err := c.conn.Write(packet)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions remote/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package remote

import (
"errors"
"fmt"
"strconv"
)

Expand All @@ -14,8 +13,12 @@ func (c *Control) SetVolume(percentage uint8) error {
return errInvalidPercentage
}

value := strconv.FormatUint(uint64(percentage), 10)
_, err := fmt.Fprintf(c.conn, commandFormat, "v", value)
packet := make([]byte, 0, 7)
packet = append(packet, "-v."...)
packet = strconv.AppendUint(packet, uint64(percentage), 10)
packet = append(packet, '\r')

_, err := c.conn.Write(packet)
if err != nil {
return err
}
Expand Down

0 comments on commit d4751d8

Please sign in to comment.