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()
pull/1/head
Marc-Antoine Ruel 8 years ago
parent e17c8b885b
commit 71c7a218dd

@ -20,9 +20,9 @@ import (
) )
var ( 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. // 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. // 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 // 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 // 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) { func (d *Dev) ReadTimeout(timeout time.Duration) (int32, error) {
// Wait for the falling edge that indicates the ADC has data. // Wait for the falling edge that indicates the ADC has data.
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
if !d.IsReady() { if !d.IsReady() {
if !d.data.WaitForEdge(timeout) { if !d.data.WaitForEdge(timeout) {
return 0, TimeoutError return 0, ErrTimeout
} }
} }
return d.readRaw() return d.readRaw()

@ -29,6 +29,7 @@ func (s *SmokeTest) Description() string {
return "Tests INA219 over I²C" return "Tests INA219 over I²C"
} }
// Run implements the SmokeTest interface.
func (s *SmokeTest) Run(f *flag.FlagSet, args []string) (err error) { func (s *SmokeTest) Run(f *flag.FlagSet, args []string) (err error) {
i2cID := f.String("i2c", "", "I²C bus to use") i2cID := f.String("i2c", "", "I²C bus to use")
i2cAddr := f.Int("ia", 0x40, "I²C bus address use: 0x40 to 0x4f") i2cAddr := f.Int("ia", 0x40, "I²C bus address use: 0x40 to 0x4f")

@ -39,7 +39,7 @@ type Opts struct {
Freq physic.Frequency 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) { func NewStream(p gpiostream.PinOut, opts *Opts) (*Dev, error) {
// Allow a wider range in case there's new devices with higher supported // Allow a wider range in case there's new devices with higher supported
// frequency. // frequency.

@ -106,7 +106,7 @@ func (d *Dev) reset() error {
} }
func (d *Dev) stateArrayToInt() uint { func (d *Dev) stateArrayToInt() uint {
var result uint = 0 var result uint
for i := uint(0); i < uint(18); i++ { for i := uint(0); i < uint(18); i++ {
state := uint(1) state := uint(1)
if !d.on[i] { if !d.on[i] {

@ -37,7 +37,7 @@ type Dev struct {
// //
// The SPI port speed must be 9MHz and the SPI mode, 0, as in the // The SPI port speed must be 9MHz and the SPI mode, 0, as in the
// python example library. // 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) connector, err := port.Connect(speed, spi.Mode0, bits)
if err != nil { if err != nil {
return nil, err return nil, err
@ -49,14 +49,15 @@ func NewUnicornhd(port spi.Port) (*Dev, error) {
}, nil }, 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 { func (device *Dev) String() string {
return fmt.Sprintf("UnicornHD{%d, %d}", width, height) 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 { func (device *Dev) Halt() error {
black := color.RGBA{0, 0, 0, 0} black := color.RGBA{0, 0, 0, 0}
return device.Draw(device.Bounds(), &image.Uniform{black}, image.ZP) return device.Draw(device.Bounds(), &image.Uniform{black}, image.ZP)

@ -17,20 +17,20 @@ import (
) )
func TestNewFailsWhenConnectionToSpiFails(t *testing.T) { 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() t.Fatal()
} }
} }
func TestNewReturnsDriverWithGoodSpi(t *testing.T) { 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() t.Fatal()
} }
} }
func TestStringIsDriverNameWidthHeight(t *testing.T) { func TestStringIsDriverNameWidthHeight(t *testing.T) {
expectedString := "UnicornHD{16, 16}" expectedString := "UnicornHD{16, 16}"
dev, _ := NewUnicornhd(spitest.NewRecordRaw(nil)) dev, _ := New(spitest.NewRecordRaw(nil))
devString := dev.String() devString := dev.String()
if devString != expectedString { if devString != expectedString {
t.Fatalf("expected: '%s', actual: '%s'", expectedString, devString) 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, 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{} buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) dev, _ := New(spitest.NewRecordRaw(&buf))
if err := dev.Halt(); err != nil { if err := dev.Halt(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -92,7 +92,7 @@ func TestHalt(t *testing.T) {
} }
func TestColorModeIsNRGBA(t *testing.T) { func TestColorModeIsNRGBA(t *testing.T) {
dev, _ := NewUnicornhd(spitest.NewRecordRaw(nil)) dev, _ := New(spitest.NewRecordRaw(nil))
if dev.ColorModel() != color.NRGBAModel { if dev.ColorModel() != color.NRGBAModel {
t.Fatal() t.Fatal()
@ -100,7 +100,7 @@ func TestColorModeIsNRGBA(t *testing.T) {
} }
func TestBoundsMatchDeviceSize(t *testing.T) { func TestBoundsMatchDeviceSize(t *testing.T) {
dev, _ := NewUnicornhd(spitest.NewRecordRaw(nil)) dev, _ := New(spitest.NewRecordRaw(nil))
bounds := dev.Bounds() 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, 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{} buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) dev, _ := New(spitest.NewRecordRaw(&buf))
black := color.RGBA{0, 0, 0, 0} black := color.RGBA{0, 0, 0, 0}
if err := dev.Draw(dev.Bounds(), &image.Uniform{black}, image.ZP); err != nil { if err := dev.Draw(dev.Bounds(), &image.Uniform{black}, image.ZP); err != nil {
t.Fatal(err) 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, 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{} buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) dev, _ := New(spitest.NewRecordRaw(&buf))
white := color.RGBA{255, 255, 255, 255} white := color.RGBA{255, 255, 255, 255}
if err := dev.Draw(dev.Bounds(), &image.Uniform{white}, image.ZP); err != nil { if err := dev.Draw(dev.Bounds(), &image.Uniform{white}, image.ZP); err != nil {
t.Fatal(err) 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, 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{} buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) dev, _ := New(spitest.NewRecordRaw(&buf))
img := image.NewNRGBA(image.Rect(0, 0, width, height)) img := image.NewNRGBA(image.Rect(0, 0, width, height))
var c uint8 = 0 var c uint8
for y := 0; y < height; y++ { for y := 0; y < height; y++ {
for x := 0; x < width; x++ { for x := 0; x < width; x++ {
r := c 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, 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{} buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf)) dev, _ := New(spitest.NewRecordRaw(&buf))
white := color.RGBA{0xFF, 0xFF, 0xFF, 0xFF} white := color.RGBA{0xFF, 0xFF, 0xFF, 0xFF}
if err := dev.Draw(image.Rect(0, 0, 3, 3), &image.Uniform{white}, image.ZP); err != nil { if err := dev.Draw(image.Rect(0, 0, 3, 3), &image.Uniform{white}, image.ZP); err != nil {
t.Fatal(err) t.Fatal(err)

Loading…
Cancel
Save