air-sensors

Air Quality Sensor library
git clone https://www.brianlane.com/git/air-sensors
Log | Files | Refs | README | LICENSE

commit 6b6a681b8704a3f31f725b6e9498016eaf2fa65f
parent 20e61875ce6f9ad044e7a034c516b8e255f546da
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Fri, 28 May 2021 15:37:21 -0700

lint: Cleanup lint complaints in the pmsa003i code

Diffstat:
Mpmsa003i/pmsa003i.go | 14++++++--------
Mpmsa003i/pmsa003i_test.go | 2+-
2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/pmsa003i/pmsa003i.go b/pmsa003i/pmsa003i.go @@ -11,10 +11,6 @@ import ( "periph.io/x/periph/conn/i2c" ) -const ( - PMSA003I_ADDR = 0x12 -) - func checksum(data []byte) bool { var cksum uint16 for i := 0; i < len(data)-2; i++ { @@ -23,6 +19,7 @@ func checksum(data []byte) bool { return word(data, 0x1e) == cksum } +// Results contains the measurements from the PMSA003i type Results struct { CfPm1 uint16 // PM1.0 in μg/m3 standard particle CfPm2_5 uint16 // PM2.5 in μg/m3 standard particle @@ -42,7 +39,7 @@ type Results struct { // New returns a PMSA003I device struct for communicating with the device // func New(i i2c.Bus) (*Dev, error) { - d := &Dev{i2c: &i2c.Dev{Bus: i, Addr: PMSA003I_ADDR}} + d := &Dev{i2c: &i2c.Dev{Bus: i, Addr: 0x12}} _, err := d.ReadSensor() if err != nil { @@ -51,9 +48,10 @@ func New(i i2c.Bus) (*Dev, error) { return d, nil } +// Dev holds the connection and error details for the device type Dev struct { - i2c conn.Conn // i2c device handle for the sgp30 - err error + i2c conn.Conn // i2c device handle for the pmsa003i + err error //nolint } // Halt implements conn.Resource. @@ -76,7 +74,7 @@ func (d *Dev) ReadSensor() (Results, error) { return Results{}, fmt.Errorf("pmsa003i: Bad checksum") } if data[0x1d] != 0x00 { - return Results{}, fmt.Errorf("pmsa0031: Error code %x", data[0x1d]) + return Results{}, fmt.Errorf("pmsa003i: Error code %x", data[0x1d]) } return Results{ diff --git a/pmsa003i/pmsa003i_test.go b/pmsa003i/pmsa003i_test.go @@ -33,7 +33,7 @@ var ( func TestWord(t *testing.T) { data := []byte{0x00, 0x01, 0x80, 0x0A, 0x55, 0xAA, 0xFF, 0x7F} result := []uint16{0x0001, 0x800A, 0x55AA, 0xFF7F} - for i := 0; i < len(result); i += 1 { + for i := 0; i < len(result); i++ { if word(data, i*2) != result[i] { t.Errorf("word error: i == %d", i) }