Heidelberg: simplify

This commit is contained in:
andig 2022-09-16 13:48:58 +02:00
parent b862cf0e12
commit 5e6dc44ba8

View file

@ -132,22 +132,23 @@ func (wb *HeidelbergEC) Status() (api.ChargeStatus, error) {
return api.StatusE, nil
case 10:
// ensure RemoteLock is disabled after wake-up
l, err := wb.conn.ReadInputRegisters(hecRegRemoteLock, 1)
b, err := wb.conn.ReadInputRegisters(hecRegRemoteLock, 1)
if err != nil {
return api.StatusNone, err
}
if binary.BigEndian.Uint16(l) != 1 {
// unlock
err = wb.set(hecRegRemoteLock, 1)
if err != nil {
// unlock
if binary.BigEndian.Uint16(b) != 1 {
if err := wb.set(hecRegRemoteLock, 1); err != nil {
return api.StatusNone, err
}
}
// keep status B2 during wakeup
if wb.wakeup {
// keep status B2 during wakeup
return api.StatusB, nil
}
return api.StatusF, nil
default:
return api.StatusNone, fmt.Errorf("invalid status: %d", sb)
@ -286,14 +287,12 @@ var _ api.Resurrector = (*HeidelbergEC)(nil)
// WakeUp implements the api.Resurrector interface
func (wb *HeidelbergEC) WakeUp() error {
// force status F by locking
if wb.set(hecRegRemoteLock, 0) == nil {
if err := wb.set(hecRegRemoteLock, 0); err == nil {
// Takes at least ~10 sec to return to normal operation
// after locking even if unlocking immediately.
wb.wakeup = true
}
// return to normal operation by unlocking after ~10 sec
err := wb.set(hecRegRemoteLock, 1)
return err
return wb.set(hecRegRemoteLock, 1)
}