Skip to content

Commit

Permalink
Pulsares: fix setting current (#10410)
Browse files Browse the repository at this point in the history
  • Loading branch information
premultiply authored Oct 20, 2023
1 parent 0f21f04 commit c0f5428
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions charger/pulsares.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (wb *Pulsares) heartbeat(timeout time.Duration) {

func (wb *Pulsares) setCurrent(current uint16) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(current))
binary.BigEndian.PutUint16(b, current)

_, err := wb.conn.WriteMultipleRegisters(pulsaresRegCurrent, 1, b)

Expand Down Expand Up @@ -187,9 +187,11 @@ func (wb *Pulsares) MaxCurrentMillis(current float64) error {
return fmt.Errorf("invalid current %.1f", current)
}

err := wb.setCurrent(wb.curr)
curr := uint16(current * 1e3)

err := wb.setCurrent(curr)
if err == nil {
wb.curr = uint16(current * 1e3)
wb.curr = curr
}

return err
Expand Down

0 comments on commit c0f5428

Please sign in to comment.