Skip to content

Commit

Permalink
config readback
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenguy committed Sep 29, 2024
1 parent ac0194f commit 50ad4d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ina219/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ func (e ErrOverflow) Error() string { return "overflow" }
type ErrNotReady struct{}

func (e ErrNotReady) Error() string { return "not ready" }

type ErrConfigMismatch struct{}

func (e ErrConfigMismatch) Error() string { return "config mismatch" }
16 changes: 14 additions & 2 deletions ina219/ina219.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,22 @@ func (d *Device) Configure() (err error) {
return
}

err = d.WriteRegister(
if err = d.WriteRegister(
RegCalibration,
d.config.Calibration.RegisterValue(),
)
); err != nil {
return
}

var readConfig Config
// make sure the configuration is read back correctly
if readConfig, err = d.ReadConfig(); err != nil {
return
} else if readConfig.RegisterValue() != d.config.RegisterValue() {
err = ErrConfigMismatch{}
} else if readConfig.Calibration.RegisterValue() != d.config.Calibration.RegisterValue() {
err = ErrConfigMismatch{}
}

return
}
Expand Down

0 comments on commit 50ad4d4

Please sign in to comment.