ina260: Driver, initial commit for review.#64
Open
Eibborest wants to merge 2 commits intoperiph:mainfrom
Open
Conversation
Member
|
Thanks for the contribution! I left comments to help with the code but there's nothing critical. |
maruel
requested changes
Nov 11, 2023
| @@ -0,0 +1,11 @@ | |||
| // Copyright 2018 The Periph Authors. All rights reserved. | |||
|
|
||
| ) | ||
|
|
||
| type Power struct { |
Member
There was a problem hiding this comment.
Please document exported symbols.
| ) | ||
|
|
||
| const ( | ||
| INA260_CHIP_ID uint8 = 0x40 |
|
|
||
| dev := &i2c.Dev{Bus: bus, Addr: uint16(INA260_CHIP_ID)} | ||
| power := Power{ | ||
| Current: 0, |
Member
There was a problem hiding this comment.
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)} |
Member
There was a problem hiding this comment.
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, |
| Power: 0, | ||
| } | ||
|
|
||
| ina260 := &ina260{ |
Member
There was a problem hiding this comment.
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 { |
Member
There was a problem hiding this comment.
Consider using https://pkg.go.dev/periph.io/x/conn/v3@v3.7.0/mmr#Dev8
| ) | ||
|
|
||
| type Power struct { | ||
| Current float64 |
Member
There was a problem hiding this comment.
Please use types in https://pkg.go.dev/periph.io/x/conn/v3@v3.7.0/physic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First draft of driver for ina260 i2c Voltage, Current, Power monitor.
Currently Read() updates a structure with the voltage, current and power.