diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43d544d..961e80f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -93,8 +93,7 @@ jobs: run: ineffassign . - name: 'Check: staticcheck' if: always() - # TODO: Remove true if we make this check ever pass. - run: staticcheck ./... || true + run: staticcheck -checks inherit,-SA1019 ./... - name: 'Check: gosec (only G104)' run: gosec -include=G104 -fmt=golint -quiet ./... diff --git a/ads1x15/ads1x15.go b/ads1x15/ads1x15.go index d357370..3e4d955 100644 --- a/ads1x15/ads1x15.go +++ b/ads1x15/ads1x15.go @@ -370,20 +370,22 @@ const ( var ( // Mapping of gain values to config register values. gainConfig = map[int]uint16{ - 2 / 3: 0x0000, - 1: 0x0200, - 2: 0x0400, - 4: 0x0600, - 8: 0x0800, - 16: 0x0A00, + // This value should be 2/3 but cannot be expressed as an integer. + 0: 0x0000, + 1: 0x0200, + 2: 0x0400, + 4: 0x0600, + 8: 0x0800, + 16: 0x0A00, } gainVoltage = map[int]physic.ElectricPotential{ - 2 / 3: 6144 * physic.MilliVolt, - 1: 4096 * physic.MilliVolt, - 2: 2048 * physic.MilliVolt, - 4: 1024 * physic.MilliVolt, - 8: 512 * physic.MilliVolt, - 16: 256 * physic.MilliVolt, + // This value should be 2/3 but cannot be expressed as an integer. + 0: 6144 * physic.MilliVolt, + 1: 4096 * physic.MilliVolt, + 2: 2048 * physic.MilliVolt, + 4: 1024 * physic.MilliVolt, + 8: 512 * physic.MilliVolt, + 16: 256 * physic.MilliVolt, } ) diff --git a/as7262/as7262.go b/as7262/as7262.go index 7afa840..ae23403 100644 --- a/as7262/as7262.go +++ b/as7262/as7262.go @@ -153,7 +153,7 @@ func (d *Dev) Sense(ledDrive physic.ElectricCurrent, senseTime time.Duration) (S return Spectrum{}, err } - if err := d.writeVirtualRegister(ctx, controlReg, uint8(allOneShot)|uint8(d.gain)); err != nil { + if err := d.writeVirtualRegister(ctx, controlReg, allOneShot|uint8(d.gain)); err != nil { return Spectrum{}, err } @@ -509,20 +509,11 @@ func calcLed(drive physic.ElectricCurrent) (uint8, physic.ElectricCurrent) { } } -type mode uint8 - const ( - // Bank 1 consists of data from the V, G, B, Y photodiodes. - bank1 mode = 0x00 - // Bank 2 consists of data from the G, Y, O, R photodiodes. - bank2 mode = 0x04 - // AllContinuously gets data from both banks continuously, requires 2x - // the integration time. - allContinuously mode = 0x08 - // AllOneShot gets data from both banks once, and set the data ready bit in + // allOneShot gets data from both banks once, and set the data ready bit in // the status control register when complete requires 2x the integration // time. - allOneShot mode = 0x0c + allOneShot uint8 = 0x0c ) // IOError is a I/O specific error. diff --git a/ep0099/ep0099.go b/ep0099/ep0099.go index 1c278f6..e0d764a 100644 --- a/ep0099/ep0099.go +++ b/ep0099/ep0099.go @@ -10,8 +10,8 @@ import ( "periph.io/x/conn/v3/i2c" ) -var errInvalidAddress = errors.New("Invalid EP-0099 address") -var errInvalidChannel = errors.New("Invalid EP-0099 channel") +var errInvalidAddress = errors.New("invalid EP-0099 address") +var errInvalidChannel = errors.New("invalid EP-0099 channel") type State byte diff --git a/ep0099/ep0099_test.go b/ep0099/ep0099_test.go index 5f14442..2d661b5 100644 --- a/ep0099/ep0099_test.go +++ b/ep0099/ep0099_test.go @@ -108,11 +108,11 @@ func TestReturnErrorForInvalidChannel(t *testing.T) { } func TestStateToString(t *testing.T) { - if s := fmt.Sprintf("%s", StateOn); s != "on" { + if s := StateOn.String(); s != "on" { t.Fatal("StateOn as string should be 'on', got ", s) } - if s := fmt.Sprintf("%s", StateOff); s != "off" { + if s := StateOff.String(); s != "off" { t.Fatal("StateOn as string should be 'off', got ", s) } } diff --git a/ina219/ina219_test.go b/ina219/ina219_test.go index 8ca9c21..f20f6dd 100644 --- a/ina219/ina219_test.go +++ b/ina219/ina219_test.go @@ -157,11 +157,6 @@ func TestNew(t *testing.T) { func TestSense(t *testing.T) { stringErr := errors.New("use err.Error() error") - type fields struct { - currentLSB physic.ElectricCurrent - powerLSB physic.Power - } - var tests = []struct { name string args Opts @@ -291,7 +286,6 @@ func TestCalibrate(t *testing.T) { maxCurrent physic.ElectricCurrent currentLSB physic.ElectricCurrent powerLSB physic.Power - caibrated bool } tests := []struct { name string diff --git a/lepton/lepton.go b/lepton/lepton.go index 67ebb39..6a89e46 100644 --- a/lepton/lepton.go +++ b/lepton/lepton.go @@ -108,15 +108,14 @@ func New(p spi.Port, i i2c.Bus) (*Dev, error) { // Lepton. type Dev struct { *cci.Dev - s spi.Conn - w int - h int - prevImg *image14bit.Gray14 - frameA, frameB []byte - frameWidth int // in bytes - frameLines int - maxTxSize int - delay time.Duration + s spi.Conn + w int + h int + prevImg *image14bit.Gray14 + frameWidth int // in bytes + frameLines int + maxTxSize int + delay time.Duration } func (d *Dev) String() string { diff --git a/lirc/lirc.go b/lirc/lirc.go index ee0d340..ee8bcda 100644 --- a/lirc/lirc.go +++ b/lirc/lirc.go @@ -7,7 +7,6 @@ package lirc import ( "bufio" "fmt" - "io/ioutil" "log" "net" "strconv" @@ -15,7 +14,6 @@ import ( "sync" "periph.io/x/conn/v3" - "periph.io/x/conn/v3/gpio/gpioreg" "periph.io/x/conn/v3/ir" ) @@ -222,58 +220,5 @@ func read(r *bufio.Reader) (string, error) { return string(raw), nil } -// driver implements periph.Driver. -type driver struct { -} - -func (d *driver) String() string { - return "lirc" -} - -func (d *driver) Init() (bool, error) { - in, out := getPins() - if in == -1 && out == -1 { - return false, nil - } - if in != -1 { - if err := gpioreg.RegisterAlias("IR_IN", strconv.Itoa(in)); err != nil { - return true, err - } - } - if out != -1 { - if err := gpioreg.RegisterAlias("IR_OUT", strconv.Itoa(out)); err != nil { - return true, err - } - } - return true, nil -} - -// getPins queries the kernel module to determine which GPIO pins are taken by -// the driver. -// -// The return values can be converted to bcm238x.Pin. Return (-1, -1) on -// failure. -func getPins() (int, int) { - // This is configured in /boot/config.txt as: - // dtoverlay=gpio_in_pin=23,gpio_out_pin=22 - bytes, err := ioutil.ReadFile("/sys/module/lirc_rpi/parameters/gpio_in_pin") - if err != nil || len(bytes) == 0 { - return -1, -1 - } - in, err := strconv.Atoi(strings.TrimRight(string(bytes), "\n")) - if err != nil { - return -1, -1 - } - bytes, err = ioutil.ReadFile("/sys/module/lirc_rpi/parameters/gpio_out_pin") - if err != nil || len(bytes) == 0 { - return -1, -1 - } - out, err := strconv.Atoi(strings.TrimRight(string(bytes), "\n")) - if err != nil { - return -1, -1 - } - return in, out -} - var _ ir.Conn = &Conn{} var _ conn.Resource = &Conn{} diff --git a/mcp23xxx/mcp23017_test.go b/mcp23xxx/mcp23017_test.go index 048f37b..c5d97a6 100644 --- a/mcp23xxx/mcp23017_test.go +++ b/mcp23xxx/mcp23017_test.go @@ -44,7 +44,6 @@ func TestMCP23017_out(t *testing.T) { } func TestMCP23S17_out(t *testing.T) { - const address uint16 = 0x20 scenario := &spitest.Playback{ Playback: conntest.Playback{ Ops: []conntest.IO{ diff --git a/mpu9250/spi.go b/mpu9250/spi.go index 3de0fd0..59e2eb4 100644 --- a/mpu9250/spi.go +++ b/mpu9250/spi.go @@ -118,10 +118,6 @@ func (s *SpiTransport) readUint16(address ...byte) (uint16, error) { return uint16(h)<<8 | uint16(l), nil } -func (s *SpiTransport) printFunc(msg string, args ...interface{}) { - fmt.Printf("SPI: "+msg+"\n", args...) -} - func noop(string, ...interface{}) {} var _ Proto = &SpiTransport{} diff --git a/nrzled/nrzled_spi_test.go b/nrzled/nrzled_spi_test.go index 6184de1..e9eabba 100644 --- a/nrzled/nrzled_spi_test.go +++ b/nrzled/nrzled_spi_test.go @@ -420,98 +420,6 @@ func TestSPI_Draw_DstEmpty(t *testing.T) { } } -var offsetDrawWant = []byte{ - 0x00, 0x00, 0x00, 0x00, - 0xE1, 0x89, 0x79, 0x6B, - 0xE1, 0x9A, 0x88, 0x75, - 0xE1, 0xAD, 0x98, 0x82, - 0xE1, 0xC2, 0xAB, 0x92, - 0xE1, 0xDA, 0xC0, 0xA4, - 0xE1, 0xF5, 0xD9, 0xB9, - 0xE2, 0x89, 0x7A, 0x69, - 0xE2, 0x9A, 0x8A, 0x76, - 0xE2, 0xAC, 0x9B, 0x86, - 0xE2, 0xC0, 0xAE, 0x98, - 0xE2, 0xD5, 0xC3, 0xAC, - 0xE2, 0xED, 0xDA, 0xC2, - 0xE4, 0x83, 0x7A, 0x6E, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xFF, -} - -var offsetDrawTests = []struct { - name string - img image.Image - point image.Point - offset image.Rectangle - want []byte - opts Opts -}{ - { - name: "Offset Draw NRGBA", - img: func() image.Image { - im := image.NewNRGBA(image.Rect(0, 0, 16, 4)) - for x := 0; x < 16; x++ { - for y := 0; y < 4; y++ { - i := (y*16 + x) * 3 - im.Set(x, y, color.RGBA{R: uint8(i + 1), G: uint8(i + 2), B: uint8(i + 3), A: 0xFF}) - } - } - return im - }(), - point: image.Point{X: 3, Y: 2}, - offset: image.Rect(0, 0, 16, 1), - want: offsetDrawWant, - opts: Opts{ - NumPixels: 15, - Channels: 3, - Freq: 2500 * physic.KiloHertz, - }, - }, - { - name: "Both Offset Draw NRGBA", - img: func() image.Image { - im := image.NewNRGBA(image.Rect(0, 0, 16, 4)) - for x := 0; x < 16; x++ { - for y := 0; y < 4; y++ { - i := (y*16 + x) * 3 - im.Set(x, y, color.RGBA{R: uint8(i + 1), G: uint8(i + 2), B: uint8(i + 3), A: 0xFF}) - } - } - return im - }(), - point: image.Point{X: 3, Y: 2}, - offset: image.Rect(2, 0, 16, 1), - want: []byte{ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xE1, 0x89, 0x79, 0x6B, - 0xE1, 0x9A, 0x88, 0x75, - 0xE1, 0xAD, 0x98, 0x82, - 0xE1, 0xC2, 0xAB, 0x92, - 0xE1, 0xDA, 0xC0, 0xA4, - 0xE1, 0xF5, 0xD9, 0xB9, - 0xE2, 0x89, 0x7A, 0x69, - 0xE2, 0x9A, 0x8A, 0x76, - 0xE2, 0xAC, 0x9B, 0x86, - 0xE2, 0xC0, 0xAE, 0x98, - 0xE2, 0xD5, 0xC3, 0xAC, - 0xE2, 0xED, 0xDA, 0xC2, - 0xE4, 0x83, 0x7A, 0x6E, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, - }, - opts: Opts{ - NumPixels: 17, - Channels: 3, - Freq: 2500 * physic.KiloHertz, - }, - }, -} - func TestSPI_Halt(t *testing.T) { s := spitest.Playback{ Playback: conntest.Playback{ @@ -737,15 +645,3 @@ type limitLow struct { func (c *limitLow) MaxTxSize() int { return 1 } - -func equalUint16(a, b []uint16) bool { - if len(a) != len(b) { - return false - } - for i := range a { - if a[i] != b[i] { - return false - } - } - return true -} diff --git a/piblaster/piblaster.go b/piblaster/piblaster.go index 1fb03f5..fb87f39 100644 --- a/piblaster/piblaster.go +++ b/piblaster/piblaster.go @@ -64,12 +64,3 @@ func openPiblaster() error { } return nil } - -func closePiblaster() error { - if piblasterHandle != nil { - w := piblasterHandle - piblasterHandle = nil - return w.Close() - } - return nil -} diff --git a/ssd1306/ssd1306_test.go b/ssd1306/ssd1306_test.go index 98ce906..af4b671 100644 --- a/ssd1306/ssd1306_test.go +++ b/ssd1306/ssd1306_test.go @@ -669,10 +669,6 @@ func initCmdI2C() []byte { return append([]byte{0}, getInitCmd(&Opts{W: 128, H: 64, Rotated: false})...) } -var preludeI2C = []byte{ - 0x0, 0x21, 0x0, 0x7f, 0x22, 0x0, 0x7, -} - func getI2CPlayback() *i2ctest.Playback { return &i2ctest.Playback{ Ops: []i2ctest.IO{