Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webasto Next: fix register usage #4150

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions charger/webasto-next.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type WebastoNext struct {
log *util.Logger
conn *modbus.Connection
current uint16
enabled bool
}

const (
Expand Down Expand Up @@ -127,18 +128,6 @@ func (wb *WebastoNext) Status() (api.ChargeStatus, error) {
}
}

// Enabled implements the api.Charger interface
func (wb *WebastoNext) Enabled() (bool, error) {
b, err := wb.conn.ReadHoldingRegisters(tqRegChargeCurrent, 1)
if err != nil {
return false, err
}

cur := binary.BigEndian.Uint16(b)

return cur != 0, nil
}

// Enable implements the api.Charger interface
func (wb *WebastoNext) Enable(enable bool) error {
b := make([]byte, 2)
Expand All @@ -147,10 +136,18 @@ func (wb *WebastoNext) Enable(enable bool) error {
}

_, err := wb.conn.WriteMultipleRegisters(tqRegChargeCurrent, 1, b)
if err == nil {
wb.enabled = enable
}

return err
}

// Enabled implements the api.Charger interface
func (wb *WebastoNext) Enabled() (bool, error) {
return wb.enabled, nil
}

// MaxCurrent implements the api.Charger interface
func (wb *WebastoNext) MaxCurrent(current int64) error {
if current < 6 {
Expand Down Expand Up @@ -208,14 +205,14 @@ var _ api.MeterCurrent = (*WebastoNext)(nil)

// Currents implements the api.MeterCurrent interface
func (wb *WebastoNext) Currents() (float64, float64, float64, error) {
b, err := wb.conn.ReadHoldingRegisters(tqRegCurrents, 3)
if err != nil {
return 0, 0, 0, err
}

var curr [3]float64
for l := 0; l < 3; l++ {
curr[l] = float64(binary.BigEndian.Uint16(b[2*l:2*(l+1)])) / 1e3
for l := uint16(0); l < 3; l++ {
b, err := wb.conn.ReadInputRegisters(tqRegCurrents+2*l, 1)
if err != nil {
return 0, 0, 0, err
}

curr[l] = float64(binary.BigEndian.Uint16(b)) / 1e3
}

return curr[0], curr[1], curr[2], nil
Expand Down