Skip to content

Conversation

func main() {
bus := machine.I2C0
err := bus.Configure(machine.I2CConfig{
Frequency: 10_000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10kHz is an unusually low frequency, is this intentional? (Many chips don't even support such low frequencies).

buf [4]byte
}

func NewDevI2C(bus drivers.I2C, addr uint8, outMin, outMax uint16, pMin, pMax int32) *DevI2C {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some I2C devices have 16-bit addresses, although I don't think we have any support for them at the moment. Perhaps it would be a good idea to use uint16 anyway?

Suggested change
func NewDevI2C(bus drivers.I2C, addr uint8, outMin, outMax uint16, pMin, pMax int32) *DevI2C {
func NewDevI2C(bus drivers.I2C, addr uint16, outMin, outMax uint16, pMin, pMax int32) *DevI2C {

Also, can you add some doc comments?

return h
}

func (d *DevI2C) Update(which drivers.Measurement) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, please add documentation to this method (especially since it is exported).

buf := &d.buf
const reg = 0
value := (d.addr << 1) | 1
err := d.bus.Tx(uint16(d.addr), []byte{reg, value}, buf[:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the []byte{reg, value} will likely cause a heap allocation depending on the I2C implementation.

buf [4]byte
}

func NewDevSPI(conn drivers.SPI, cs pinout, outMin, outMax uint16, pMin, pMax int32) (*DevSPI, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this should get some explanation. At least clarifying with parameters like outMin mean.

return h, nil
}

// Update implements the sensor interface.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's technically correct, but not super helpful to users.
What about something like

Update reads the sensor values from the device. The values are stored in the driver object, and can be read with the Pressure and Temperature methods.

}

// Temperature returns temperature in milliKelvin [mK].
func (d *dev) Temperature() int32 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By far most drivers use milli-degrees Celsius. See for example:

drivers/bma42x/bma42x.go

Lines 277 to 279 in 228e57c

// Temperature returns the last read temperature in celsius milli degrees (1°C
// is 1000).
func (d *Device) Temperature() int32 {

And:

drivers/bme280/bme280.go

Lines 180 to 181 in 228e57c

// ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
func (d *Device) ReadTemperature() (int32, error) {

I would like to keep that as a convention.

Also see #332 which I still think is a good idea. It's somewhat out of scope for this PR though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants