Skip to content

Commit

Permalink
Many staticcheck fixes
Browse files Browse the repository at this point in the history
It now passes when run as:
  staticcheck -checks all,-U1000,-ST1003,-SA5002,-SA1019 ./...

The disabled checks will be enabled later since they are less trivial to
enable, as this is already a non-trivial number of modifications.
  • Loading branch information
maruel committed May 24, 2020
1 parent 327cafe commit 588b1a3
Show file tree
Hide file tree
Showing 37 changed files with 60 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cmd/bmxx80/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func run(dev physic.SenseEnv, interval time.Duration) error {
if err != nil {
return err
}
chanSignal := make(chan os.Signal)
chanSignal := make(chan os.Signal, 1)
signal.Notify(chanSignal, os.Interrupt)
for {
select {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cap1xxx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func mainImpl() error {

opts := cap1xxx.DefaultOpts
if *i2cAddr != 0 {
if *i2cAddr < 0 || *i2cAddr > 65535 {
if *i2cAddr > 65535 {
return errors.New("invlaid -i2c value")
}
opts.I2CAddr = uint16(*i2cAddr)
Expand Down
2 changes: 1 addition & 1 deletion cmd/ir/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func mainImpl() error {
}
c := i.Channel()

ctrlC := make(chan os.Signal)
ctrlC := make(chan os.Signal, 1)
signal.Notify(ctrlC, os.Interrupt)

first := true
Expand Down
2 changes: 1 addition & 1 deletion conn/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ type Drawer interface {
// update.
//
// srcPts aligns the image at this offset, enabling using a subset of the
// source image. use image.ZP/image.Point{} to take the image at its origin.
// source image. use image.Point{} to take the image at its origin.
Draw(dstRect image.Rectangle, src image.Image, srcPts image.Point) error
}
4 changes: 2 additions & 2 deletions conn/display/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func ExampleDrawer() {

// Render the image. The normal use case is:
// - Use d.Bounds() as the dstRect, to cover the whole screen.
// - Use image.ZP/image.Point{} as 'srcPts' unless you want to offset inside
// - Use image.Point{} as 'srcPts' unless you want to offset inside
// the image.
if err := d.Draw(d.Bounds(), img, image.ZP); err != nil {
if err := d.Draw(d.Bounds(), img, image.Point{}); err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion conn/gpio/gpiotest/gpiotest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestLogPinIO(t *testing.T) {
}

func TestAll(t *testing.T) {
if 2 != len(gpioreg.All()) {
if len(gpioreg.All()) != 2 {
t.Fatal("expected two pins registered for test")
}
}
Expand Down
3 changes: 0 additions & 3 deletions conn/physic/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -1923,12 +1923,10 @@ func dtoi(d decimal, scale int) (int64, bool) {
switch {
case d.exp+scale < 0:
u = (u + powerOf10[mag]/2) / powerOf10[mag]
break
case mag == 0:
if u > maxInt64 {
return 0, true
}
break
default:
check := u * powerOf10[mag]
if check/powerOf10[mag] != u || check > maxInt64 {
Expand Down Expand Up @@ -2020,7 +2018,6 @@ func atod(s string) (decimal, int, error) {
return decimal{}, 0, &parseError{errNotANumber}
}
end = i
break
}
}

Expand Down
2 changes: 1 addition & 1 deletion conn/pin/pinreg/pinreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func All() map[string][][]pin.Pin {
func Position(p pin.Pin) (string, int) {
mu.Lock()
defer mu.Unlock()
pos, _ := byPin[realPin(p).Name()]
pos := byPin[realPin(p).Name()]
return pos.name, pos.number
}

Expand Down
1 change: 1 addition & 0 deletions devices/lepton/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

// Package internal contains code shared between cci and lepton.
package internal

import (
Expand Down
12 changes: 7 additions & 5 deletions devices/lepton/lepton.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ func (d *Dev) NextFrame(f *Frame) error {
if err := d.readFrame(f); err != nil {
return err
}
if f.Metadata.FFCDesired {
// TODO(maruel): Automatically trigger FFC when applicable, only do if
// the camera has a shutter.
//go d.RunFFC()
}
/*
if f.Metadata.FFCDesired {
// TODO(maruel): Automatically trigger FFC when applicable, only do if
// the camera has a shutter.
go d.RunFFC()
}
*/
// Sadly the Lepton will unconditionally send 27fps, even if the effective
// rate is 9fps.
if !equalUint16(d.prevImg.Pix, f.Gray14.Pix) {
Expand Down
7 changes: 7 additions & 0 deletions experimental/cmd/as7262/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"periph.io/x/periph/conn/i2c/i2creg"
Expand Down Expand Up @@ -46,6 +48,9 @@ func mainImpl() error {
defer sensor.Halt()

fmt.Println("ctrl+c to quit")
var halt = make(chan os.Signal, 1)
signal.Notify(halt, syscall.SIGTERM)
signal.Notify(halt, syscall.SIGINT)

senseTime := time.Millisecond * 300

Expand All @@ -57,6 +62,8 @@ func mainImpl() error {
return fmt.Errorf("sensor reading error: %v", err)
}
fmt.Println(spectrum)
case <-halt:
return nil
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion experimental/cmd/hd44780/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func mainFunc() error {
return fmt.Errorf("register select pin %s can not be found", *rsPin)
}
ePinReg := gpioreg.ByName(*ePin)
if ePin == nil {
if ePinReg == nil {
return fmt.Errorf("strobe pin %s can not be found", *ePin)
}

Expand Down
2 changes: 1 addition & 1 deletion experimental/cmd/hx711/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func mainFunc() error {
return fmt.Errorf("clock pin %s can not be found", *clkPin)
}
dataPinReg := gpioreg.ByName(*dataPin)
if dataPin == nil {
if dataPinReg == nil {
return fmt.Errorf("data pin %s can not be found", *dataPin)
}

Expand Down
2 changes: 1 addition & 1 deletion experimental/cmd/ina219/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func mainImpl() error {

// Read values from sensor every second.
everySecond := time.NewTicker(time.Second).C
var halt = make(chan os.Signal)
var halt = make(chan os.Signal, 1)
signal.Notify(halt, syscall.SIGTERM)
signal.Notify(halt, syscall.SIGINT)

Expand Down
2 changes: 1 addition & 1 deletion experimental/cmd/inky/inky.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ func mainImpl() error {
}

log.Printf("Drawing image...")
return dev.Draw(img.Bounds(), img, image.ZP)
return dev.Draw(img.Bounds(), img, image.Point{})
}
2 changes: 1 addition & 1 deletion experimental/cmd/mcp9808/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func mainImpl() error {

// Read values from sensor every second.
everySecond := time.Tick(time.Second)
var halt = make(chan os.Signal)
var halt = make(chan os.Signal, 1)
signal.Notify(halt, syscall.SIGTERM)
signal.Notify(halt, syscall.SIGINT)

Expand Down
5 changes: 1 addition & 4 deletions experimental/conn/gpio/gpioutil/debounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ func (d *debounced) Read() gpio.Level {
//
// It is the smoothed out value from the underlying gpio.PinIO.
func (d *debounced) WaitForEdge(timeout time.Duration) bool {
if !d.PinIO.WaitForEdge(timeout) {
return false
}
return true
return d.PinIO.WaitForEdge(timeout)
}

// Halt implements gpio.PinIO.
Expand Down
2 changes: 1 addition & 1 deletion experimental/conn/gpio/gpioutil/polledge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestPollEdge_Halt(t *testing.T) {
// inside WaitForEdge().
<-f.wait
if err := p.Halt(); err != nil {
t.Fatal(err)
t.Error(err)
}
}()
// p.die triggers.
Expand Down
4 changes: 2 additions & 2 deletions experimental/devices/as7262/as7262.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ func (d *Dev) Halt() error {
d.cancel()
// A receive can always proceed on a closed channel we can use that
// to signal that the running process has been canceled correctly.
_, _ = <-d.done
<-d.done
return nil
}

func (d *Dev) String() string {
return fmt.Sprintf("AMS AS7262 6 channel visible spectrum sensor")
return "AMS AS7262 6 channel visible spectrum sensor"
}

// Gain is the sensor gain for all bands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

// Package ina219smoketest tests the ina219 device.
package ina219smoketest

import (
Expand Down
2 changes: 1 addition & 1 deletion experimental/devices/inky/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Example() {
log.Fatal(err)
}

if err := dev.Draw(img.Bounds(), img, image.ZP); err != nil {
if err := dev.Draw(img.Bounds(), img, image.Point{}); err != nil {
log.Fatal(err)
}
}
6 changes: 3 additions & 3 deletions experimental/devices/inky/inky.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *Color) Set(s string) error {
case "white":
*c = White
default:
return fmt.Errorf("Unknown color %q: expected either black, red, yellow or white", s)
return fmt.Errorf("unknown color %q: expected either black, red, yellow or white", s)
}
return nil
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func (m *Model) Set(s string) error {
case "WHAT":
*m = WHAT
default:
return fmt.Errorf("Unknown model %q: expected either PHAT or WHAT", s)
return fmt.Errorf("unknown model %q: expected either PHAT or WHAT", s)
}
return nil
}
Expand Down Expand Up @@ -278,7 +278,7 @@ func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPtrs image.Point

// DrawAll redraws the whole display.
func (d *Dev) DrawAll(src image.Image) error {
return d.Draw(d.Bounds(), src, image.ZP)
return d.Draw(d.Bounds(), src, image.Point{})
}

func (d *Dev) update(border byte, black []byte, red []byte) (err error) {
Expand Down
2 changes: 1 addition & 1 deletion experimental/devices/mcp23xxx/registers.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ func (r *registerCache) getAndSetBit(bit uint8, value bool, cached bool) error {

func (r *registerCache) getBit(bit uint8, cached bool) (bool, error) {
v, err := r.readValue(cached)
return 0 != (v & (1 << bit)), err
return (v & (1 << bit)) != 0, err
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

// Package mcp9808smoketest implements a smoke test for the mcp9808.
package mcp9808smoketest

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

// Package accelerometer contains constants for the MPU9250.
package accelerometer

// Valid accelerator values.
Expand Down
1 change: 1 addition & 0 deletions experimental/devices/mpu9250/reg/reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

// Package reg defines constants for the MPU9250.
package reg

// Unsorted mix of register addresses, commands and constants.
Expand Down
2 changes: 1 addition & 1 deletion experimental/devices/pca9685/pca9685_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestPCA9685(t *testing.T) {

func TestPCA9685_invalidCh(t *testing.T) {
scenario := &i2ctest.Playback{
Ops: append(initializationSequence()),
Ops: initializationSequence(),
}

dev, err := NewI2C(scenario, I2CAddr)
Expand Down
2 changes: 1 addition & 1 deletion experimental/devices/unicornhd/unicornhd.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (device *Dev) String() string {
// 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)
return device.Draw(device.Bounds(), &image.Uniform{black}, image.Point{})
}

// ColorModel implements devices.Display. There's no surprise, it is
Expand Down
8 changes: 4 additions & 4 deletions experimental/devices/unicornhd/unicornhd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestDrawWritesBlackImageToSpi(t *testing.T) {
buf := bytes.Buffer{}
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 {
if err := dev.Draw(dev.Bounds(), &image.Uniform{black}, image.Point{}); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -219,7 +219,7 @@ func TestDrawWritesWhiteImageToSpi(t *testing.T) {
buf := bytes.Buffer{}
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 {
if err := dev.Draw(dev.Bounds(), &image.Uniform{white}, image.Point{}); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -291,7 +291,7 @@ func TestDrawWritesSequenceImageToSpi(t *testing.T) {
img.Set(x, y, clr)
}
}
if err := dev.Draw(dev.Bounds(), img, image.ZP); err != nil {
if err := dev.Draw(dev.Bounds(), img, image.Point{}); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -354,7 +354,7 @@ func TestDrawSupportsPartialUpdates(t *testing.T) {
buf := bytes.Buffer{}
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 {
if err := dev.Draw(image.Rect(0, 0, 3, 3), &image.Uniform{white}, image.Point{}); err != nil {
t.Fatal(err)
}

Expand Down
1 change: 1 addition & 0 deletions experimental/host/mt7688/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

// Package mt7688 interfaces with the MediaTek MT7688 MIPS CPU used on low cost board.
package mt7688

import (
Expand Down
2 changes: 1 addition & 1 deletion host/allwinner/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ func (d *driverGPIO) After() []string {
// for the exact processor model detected.
func (d *driverGPIO) Init() (bool, error) {
if !Present() {
return false, errors.New("Allwinner CPU not detected")
return false, errors.New("no Allwinner CPU detected")
}

// Mark the right pins as available even if the memory map fails so they can
Expand Down
2 changes: 1 addition & 1 deletion host/allwinner/gpio_pl.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (d *driverGPIOPL) After() []string {
func (d *driverGPIOPL) Init() (bool, error) {
// BUG(maruel): H3 supports group PL too.
if !IsA64() {
return false, errors.New("A64 CPU not detected")
return false, errors.New("no A64 CPU detected")
}

// Mark the right pins as available even if the memory map fails so they can
Expand Down
Loading

0 comments on commit 588b1a3

Please sign in to comment.