staticcheck: enforce

This does result in a few awkward cases but in general it's worth
enforcing and most importantly will make my life as a code reviewer
easier.

It's mostly deletion of dead code.
pull/18/head
Marc-Antoine Ruel 5 years ago
parent a27238ec6e
commit 823eae07fd

@ -93,8 +93,7 @@ jobs:
run: ineffassign . run: ineffassign .
- name: 'Check: staticcheck' - name: 'Check: staticcheck'
if: always() if: always()
# TODO: Remove true if we make this check ever pass. run: staticcheck -checks inherit,-SA1019 ./...
run: staticcheck ./... || true
- name: 'Check: gosec (only G104)' - name: 'Check: gosec (only G104)'
run: gosec -include=G104 -fmt=golint -quiet ./... run: gosec -include=G104 -fmt=golint -quiet ./...

@ -370,7 +370,8 @@ const (
var ( var (
// Mapping of gain values to config register values. // Mapping of gain values to config register values.
gainConfig = map[int]uint16{ gainConfig = map[int]uint16{
2 / 3: 0x0000, // This value should be 2/3 but cannot be expressed as an integer.
0: 0x0000,
1: 0x0200, 1: 0x0200,
2: 0x0400, 2: 0x0400,
4: 0x0600, 4: 0x0600,
@ -378,7 +379,8 @@ var (
16: 0x0A00, 16: 0x0A00,
} }
gainVoltage = map[int]physic.ElectricPotential{ gainVoltage = map[int]physic.ElectricPotential{
2 / 3: 6144 * physic.MilliVolt, // This value should be 2/3 but cannot be expressed as an integer.
0: 6144 * physic.MilliVolt,
1: 4096 * physic.MilliVolt, 1: 4096 * physic.MilliVolt,
2: 2048 * physic.MilliVolt, 2: 2048 * physic.MilliVolt,
4: 1024 * physic.MilliVolt, 4: 1024 * physic.MilliVolt,

@ -153,7 +153,7 @@ func (d *Dev) Sense(ledDrive physic.ElectricCurrent, senseTime time.Duration) (S
return Spectrum{}, err 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 return Spectrum{}, err
} }
@ -509,20 +509,11 @@ func calcLed(drive physic.ElectricCurrent) (uint8, physic.ElectricCurrent) {
} }
} }
type mode uint8
const ( const (
// Bank 1 consists of data from the V, G, B, Y photodiodes. // allOneShot gets data from both banks once, and set the data ready bit in
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
// the status control register when complete requires 2x the integration // the status control register when complete requires 2x the integration
// time. // time.
allOneShot mode = 0x0c allOneShot uint8 = 0x0c
) )
// IOError is a I/O specific error. // IOError is a I/O specific error.

@ -10,8 +10,8 @@ import (
"periph.io/x/conn/v3/i2c" "periph.io/x/conn/v3/i2c"
) )
var errInvalidAddress = errors.New("Invalid EP-0099 address") var errInvalidAddress = errors.New("invalid EP-0099 address")
var errInvalidChannel = errors.New("Invalid EP-0099 channel") var errInvalidChannel = errors.New("invalid EP-0099 channel")
type State byte type State byte

@ -108,11 +108,11 @@ func TestReturnErrorForInvalidChannel(t *testing.T) {
} }
func TestStateToString(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) 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) t.Fatal("StateOn as string should be 'off', got ", s)
} }
} }

@ -157,11 +157,6 @@ func TestNew(t *testing.T) {
func TestSense(t *testing.T) { func TestSense(t *testing.T) {
stringErr := errors.New("use err.Error() error") stringErr := errors.New("use err.Error() error")
type fields struct {
currentLSB physic.ElectricCurrent
powerLSB physic.Power
}
var tests = []struct { var tests = []struct {
name string name string
args Opts args Opts
@ -291,7 +286,6 @@ func TestCalibrate(t *testing.T) {
maxCurrent physic.ElectricCurrent maxCurrent physic.ElectricCurrent
currentLSB physic.ElectricCurrent currentLSB physic.ElectricCurrent
powerLSB physic.Power powerLSB physic.Power
caibrated bool
} }
tests := []struct { tests := []struct {
name string name string

@ -112,7 +112,6 @@ type Dev struct {
w int w int
h int h int
prevImg *image14bit.Gray14 prevImg *image14bit.Gray14
frameA, frameB []byte
frameWidth int // in bytes frameWidth int // in bytes
frameLines int frameLines int
maxTxSize int maxTxSize int

@ -7,7 +7,6 @@ package lirc
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"strconv" "strconv"
@ -15,7 +14,6 @@ import (
"sync" "sync"
"periph.io/x/conn/v3" "periph.io/x/conn/v3"
"periph.io/x/conn/v3/gpio/gpioreg"
"periph.io/x/conn/v3/ir" "periph.io/x/conn/v3/ir"
) )
@ -222,58 +220,5 @@ func read(r *bufio.Reader) (string, error) {
return string(raw), nil 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 _ ir.Conn = &Conn{}
var _ conn.Resource = &Conn{} var _ conn.Resource = &Conn{}

@ -44,7 +44,6 @@ func TestMCP23017_out(t *testing.T) {
} }
func TestMCP23S17_out(t *testing.T) { func TestMCP23S17_out(t *testing.T) {
const address uint16 = 0x20
scenario := &spitest.Playback{ scenario := &spitest.Playback{
Playback: conntest.Playback{ Playback: conntest.Playback{
Ops: []conntest.IO{ Ops: []conntest.IO{

@ -118,10 +118,6 @@ func (s *SpiTransport) readUint16(address ...byte) (uint16, error) {
return uint16(h)<<8 | uint16(l), nil 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{}) {} func noop(string, ...interface{}) {}
var _ Proto = &SpiTransport{} var _ Proto = &SpiTransport{}

@ -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) { func TestSPI_Halt(t *testing.T) {
s := spitest.Playback{ s := spitest.Playback{
Playback: conntest.Playback{ Playback: conntest.Playback{
@ -737,15 +645,3 @@ type limitLow struct {
func (c *limitLow) MaxTxSize() int { func (c *limitLow) MaxTxSize() int {
return 1 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
}

@ -64,12 +64,3 @@ func openPiblaster() error {
} }
return nil return nil
} }
func closePiblaster() error {
if piblasterHandle != nil {
w := piblasterHandle
piblasterHandle = nil
return w.Close()
}
return nil
}

@ -669,10 +669,6 @@ func initCmdI2C() []byte {
return append([]byte{0}, getInitCmd(&Opts{W: 128, H: 64, Rotated: false})...) 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 { func getI2CPlayback() *i2ctest.Playback {
return &i2ctest.Playback{ return &i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{

Loading…
Cancel
Save