Skip to content

Commit

Permalink
Reduce the number of golint reports
Browse files Browse the repository at this point in the history
This causes a few breaking changes in experimental code:

- hx711.TimeoutError was renamed to ErrTimeout
- unicornhd.NewUnicornhd() was stuttering and was renamed to New()
  • Loading branch information
maruel committed Dec 4, 2018
1 parent 4d03182 commit dd7e993
Showing 7 changed files with 27 additions and 25 deletions.
8 changes: 4 additions & 4 deletions experimental/cmd/mpu9250/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 4 additions & 4 deletions experimental/devices/hx711/hx711.go
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion experimental/devices/nrzled/nrzled.go
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion experimental/devices/sn3218/sn3218.go
Original file line number Diff line number Diff line change
@@ -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] {
9 changes: 5 additions & 4 deletions experimental/devices/unicornhd/unicornhd.go
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 11 additions & 11 deletions experimental/devices/unicornhd/unicornhd_test.go
Original file line number Diff line number Diff line change
@@ -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,15 +92,15 @@ 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()
}
}

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)

0 comments on commit dd7e993

Please sign in to comment.