-
Notifications
You must be signed in to change notification settings - Fork 46
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
ina260: Driver, initial commit for review. #64
base: main
Are you sure you want to change the base?
Conversation
Thanks for the contribution! I left comments to help with the code but there's nothing critical. |
@@ -0,0 +1,11 @@ | |||
// Copyright 2018 The Periph Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update.
|
||
) | ||
|
||
type Power struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document exported symbols.
) | ||
|
||
const ( | ||
INA260_CHIP_ID uint8 = 0x40 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not export these.
|
||
dev := &i2c.Dev{Bus: bus, Addr: uint16(INA260_CHIP_ID)} | ||
power := Power{ | ||
Current: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary. Memory allocation in Go is zero-initialized.
|
||
func New(bus i2c.Bus) *ina260 { | ||
|
||
dev := &i2c.Dev{Bus: bus, Addr: uint16(INA260_CHIP_ID)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an ID, this is an address. I'd put 0x40 directly as is there and would remove the constant.
|
||
ina260 := &ina260{ | ||
Conn: dev, | ||
Power: power, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary.
Power: 0, | ||
} | ||
|
||
ina260 := &ina260{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can return this without using a named variable.
|
||
reg := []byte{byte(INA260_CURRENT)} | ||
currentBytes := make([]byte, 2) | ||
if err := i.Conn.Tx(reg, currentBytes); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) | ||
|
||
type Power struct { | ||
Current float64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use types in https://pkg.go.dev/periph.io/x/conn/[email protected]/physic
First draft of driver for ina260 i2c Voltage, Current, Power monitor.
Currently Read() updates a structure with the voltage, current and power.