From dd7e993fa4ad026fe00990bc3ae2c19a2ec5e823 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ruel Date: Mon, 3 Dec 2018 19:04:10 -0500 Subject: [PATCH] Reduce the number of golint reports This causes a few breaking changes in experimental code: - hx711.TimeoutError was renamed to ErrTimeout - unicornhd.NewUnicornhd() was stuttering and was renamed to New() --- experimental/cmd/mpu9250/main.go | 8 +++---- experimental/devices/hx711/hx711.go | 8 +++---- .../ina219/ina219smoketest/ina219smoketest.go | 1 + experimental/devices/nrzled/nrzled.go | 2 +- experimental/devices/sn3218/sn3218.go | 2 +- experimental/devices/unicornhd/unicornhd.go | 9 ++++---- .../devices/unicornhd/unicornhd_test.go | 22 +++++++++---------- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/experimental/cmd/mpu9250/main.go b/experimental/cmd/mpu9250/main.go index 3926eda95..92e992465 100644 --- a/experimental/cmd/mpu9250/main.go +++ b/experimental/cmd/mpu9250/main.go @@ -96,9 +96,9 @@ func main() { if *continuous { for { - x := MustInt16(dev.GetAccelerationX()) - y := MustInt16(dev.GetAccelerationY()) - z := MustInt16(dev.GetAccelerationZ()) + x := mustInt16(dev.GetAccelerationX()) + y := mustInt16(dev.GetAccelerationY()) + z := mustInt16(dev.GetAccelerationZ()) fmt.Printf("Raw : X: %d, Y: %d, Z: %d\n", x, y, z) fmt.Printf("Calc: X: %.2f, Y: %.2f, Z: %.2f\n", float32(x)*accMulti, float32(y)*accMulti, float32(z)*accMulti) time.Sleep(time.Second) @@ -107,7 +107,7 @@ func main() { } } -func MustInt16(s int16, err error) int16 { +func mustInt16(s int16, err error) int16 { if err != nil { panic(err) } diff --git a/experimental/devices/hx711/hx711.go b/experimental/devices/hx711/hx711.go index 680933a06..480531889 100644 --- a/experimental/devices/hx711/hx711.go +++ b/experimental/devices/hx711/hx711.go @@ -20,9 +20,9 @@ import ( ) var ( - // TimeoutError is returned from Read and ReadAveraged when the ADC took too + // ErrTimeout is returned from Read and ReadAveraged when the ADC took too // long to indicate data was available. - TimeoutError = errors.New("timed out waiting for HX711 to become ready") + ErrTimeout = errors.New("timed out waiting for HX711 to become ready") ) // InputMode controls the voltage gain and the channel multiplexer on the HX711. @@ -168,14 +168,14 @@ func (d *Dev) IsReady() bool { // // It blocks until the ADC indicates there is data ready for retrieval. If the // ADC doesn't pull its Data pin low to indicate there is data ready before the -// timeout is reached, TimeoutError is returned. +// timeout is reached, ErrTimeout is returned. func (d *Dev) ReadTimeout(timeout time.Duration) (int32, error) { // Wait for the falling edge that indicates the ADC has data. d.mu.Lock() defer d.mu.Unlock() if !d.IsReady() { if !d.data.WaitForEdge(timeout) { - return 0, TimeoutError + return 0, ErrTimeout } } return d.readRaw() diff --git a/experimental/devices/ina219/ina219smoketest/ina219smoketest.go b/experimental/devices/ina219/ina219smoketest/ina219smoketest.go index 6e945e5b8..c3100c9ca 100644 --- a/experimental/devices/ina219/ina219smoketest/ina219smoketest.go +++ b/experimental/devices/ina219/ina219smoketest/ina219smoketest.go @@ -29,6 +29,7 @@ func (s *SmokeTest) Description() string { return "Tests INA219 over I²C" } +// Run implements the SmokeTest interface. func (s *SmokeTest) Run(f *flag.FlagSet, args []string) (err error) { i2cID := f.String("i2c", "", "I²C bus to use") i2cAddr := f.Int("ia", 0x40, "I²C bus address use: 0x40 to 0x4f") diff --git a/experimental/devices/nrzled/nrzled.go b/experimental/devices/nrzled/nrzled.go index bca99032f..9e06adbcb 100644 --- a/experimental/devices/nrzled/nrzled.go +++ b/experimental/devices/nrzled/nrzled.go @@ -39,7 +39,7 @@ type Opts struct { Freq physic.Frequency } -// New opens a handle to a compatible LED strip. +// NewStream opens a handle to a compatible LED strip. func NewStream(p gpiostream.PinOut, opts *Opts) (*Dev, error) { // Allow a wider range in case there's new devices with higher supported // frequency. diff --git a/experimental/devices/sn3218/sn3218.go b/experimental/devices/sn3218/sn3218.go index 1621e2699..d4db1118d 100644 --- a/experimental/devices/sn3218/sn3218.go +++ b/experimental/devices/sn3218/sn3218.go @@ -106,7 +106,7 @@ func (d *Dev) reset() error { } func (d *Dev) stateArrayToInt() uint { - var result uint = 0 + var result uint for i := uint(0); i < uint(18); i++ { state := uint(1) if !d.on[i] { diff --git a/experimental/devices/unicornhd/unicornhd.go b/experimental/devices/unicornhd/unicornhd.go index 1f8f651c3..6aa220502 100644 --- a/experimental/devices/unicornhd/unicornhd.go +++ b/experimental/devices/unicornhd/unicornhd.go @@ -37,7 +37,7 @@ type Dev struct { // // The SPI port speed must be 9MHz and the SPI mode, 0, as in the // python example library. -func NewUnicornhd(port spi.Port) (*Dev, error) { +func New(port spi.Port) (*Dev, error) { connector, err := port.Connect(speed, spi.Mode0, bits) if err != nil { return nil, err @@ -49,14 +49,15 @@ func NewUnicornhd(port spi.Port) (*Dev, error) { }, nil } -// Implement display.Drawer +// String implements display.Drawer // -// Returns a string with the driver name and the width and height of the display. +// Returns a string with the driver name and the width and height of the +// display. func (device *Dev) String() string { return fmt.Sprintf("UnicornHD{%d, %d}", width, height) } -// Halting the unicorn HD sets all the pixels to black. Error is always nil. +// Halt sets all the pixels to black. Error is always nil. func (device *Dev) Halt() error { black := color.RGBA{0, 0, 0, 0} return device.Draw(device.Bounds(), &image.Uniform{black}, image.ZP) diff --git a/experimental/devices/unicornhd/unicornhd_test.go b/experimental/devices/unicornhd/unicornhd_test.go index d09be8f59..ea21a6738 100644 --- a/experimental/devices/unicornhd/unicornhd_test.go +++ b/experimental/devices/unicornhd/unicornhd_test.go @@ -17,20 +17,20 @@ import ( ) func TestNewFailsWhenConnectionToSpiFails(t *testing.T) { - if dev, err := NewUnicornhd(&spiFail{}); dev != nil || err == nil { + if dev, err := New(&spiFail{}); dev != nil || err == nil { t.Fatal() } } func TestNewReturnsDriverWithGoodSpi(t *testing.T) { - if dev, err := NewUnicornhd(spitest.NewRecordRaw(nil)); dev == nil || err != nil { + if dev, err := New(spitest.NewRecordRaw(nil)); dev == nil || err != nil { t.Fatal() } } func TestStringIsDriverNameWidthHeight(t *testing.T) { expectedString := "UnicornHD{16, 16}" - dev, _ := NewUnicornhd(spitest.NewRecordRaw(nil)) + dev, _ := New(spitest.NewRecordRaw(nil)) devString := dev.String() if devString != expectedString { t.Fatalf("expected: '%s', actual: '%s'", expectedString, devString) @@ -81,7 +81,7 @@ func TestHalt(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } buf := bytes.Buffer{} - dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) + dev, _ := New(spitest.NewRecordRaw(&buf)) if err := dev.Halt(); err != nil { t.Fatal(err) } @@ -92,7 +92,7 @@ func TestHalt(t *testing.T) { } func TestColorModeIsNRGBA(t *testing.T) { - dev, _ := NewUnicornhd(spitest.NewRecordRaw(nil)) + dev, _ := New(spitest.NewRecordRaw(nil)) if dev.ColorModel() != color.NRGBAModel { t.Fatal() @@ -100,7 +100,7 @@ func TestColorModeIsNRGBA(t *testing.T) { } func TestBoundsMatchDeviceSize(t *testing.T) { - dev, _ := NewUnicornhd(spitest.NewRecordRaw(nil)) + dev, _ := New(spitest.NewRecordRaw(nil)) bounds := dev.Bounds() @@ -162,7 +162,7 @@ func TestDrawWritesBlackImageToSpi(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } buf := bytes.Buffer{} - dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) + dev, _ := New(spitest.NewRecordRaw(&buf)) black := color.RGBA{0, 0, 0, 0} if err := dev.Draw(dev.Bounds(), &image.Uniform{black}, image.ZP); err != nil { t.Fatal(err) @@ -217,7 +217,7 @@ func TestDrawWritesWhiteImageToSpi(t *testing.T) { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, } buf := bytes.Buffer{} - dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) + dev, _ := New(spitest.NewRecordRaw(&buf)) white := color.RGBA{255, 255, 255, 255} if err := dev.Draw(dev.Bounds(), &image.Uniform{white}, image.ZP); err != nil { t.Fatal(err) @@ -265,10 +265,10 @@ func TestDrawWritesSequenceImageToSpi(t *testing.T) { 0xe8, 0xea, 0xe9, 0xeb, 0xed, 0xec, 0xee, 0xf0, 0xef, 0xf1, 0xf3, 0xf2, 0xf4, 0xf6, 0xf5, 0xf7, 0xf9, 0xf8, 0xfa, 0xfc, 0xfb, 0xfd, 0xff, 0xfe, } buf := bytes.Buffer{} - dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) + dev, _ := New(spitest.NewRecordRaw(&buf)) img := image.NewNRGBA(image.Rect(0, 0, width, height)) - var c uint8 = 0 + var c uint8 for y := 0; y < height; y++ { for x := 0; x < width; x++ { r := c @@ -352,7 +352,7 @@ func TestDrawSupportsPartialUpdates(t *testing.T) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } buf := bytes.Buffer{} - dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) + dev, _ := New(spitest.NewRecordRaw(&buf)) white := color.RGBA{0xFF, 0xFF, 0xFF, 0xFF} if err := dev.Draw(image.Rect(0, 0, 3, 3), &image.Uniform{white}, image.ZP); err != nil { t.Fatal(err)