Reduce the number of golint comments.

Ran the following command:
    golint -min_confidence 0 ./... | grep -v ALL_CAPS | \
        grep -v underscores | grep -v 'another file'

and fixed the comments that made sense.
pull/1/head
Marc-Antoine Ruel 7 years ago
parent 6cd1bba854
commit c01d9a6384

@ -173,15 +173,15 @@ func run(i2cBus i2c.Bus, i2cAddr uint16, spiPort spi.PortCloser) (err error) {
// 1°C // 1°C
if delta.Temperature > 1000 || delta.Temperature < -1000 { if delta.Temperature > 1000 || delta.Temperature < -1000 {
return fmt.Errorf("Temperature delta higher than expected (%s): I²C got %s; SPI got %s", delta.Temperature, i2cEnv.Temperature, spiEnv.Temperature) return fmt.Errorf("temperature delta higher than expected (%s): I²C got %s; SPI got %s", delta.Temperature, i2cEnv.Temperature, spiEnv.Temperature)
} }
// 0.1kPa // 0.1kPa
if delta.Pressure > 100 || delta.Pressure < -100 { if delta.Pressure > 100 || delta.Pressure < -100 {
return fmt.Errorf("Pressure delta higher than expected (%s): I²C got %s; SPI got %s", delta.Pressure, i2cEnv.Pressure, spiEnv.Pressure) return fmt.Errorf("pressure delta higher than expected (%s): I²C got %s; SPI got %s", delta.Pressure, i2cEnv.Pressure, spiEnv.Pressure)
} }
// 4%rH // 4%rH
if delta.Humidity > 400 || delta.Humidity < -400 { if delta.Humidity > 400 || delta.Humidity < -400 {
return fmt.Errorf("Humidity delta higher than expected (%s): I²C got %s; SPI got %s", delta.Humidity, i2cEnv.Humidity, spiEnv.Humidity) return fmt.Errorf("humidity delta higher than expected (%s): I²C got %s; SPI got %s", delta.Humidity, i2cEnv.Humidity, spiEnv.Humidity)
} }
return nil return nil
} }

@ -24,6 +24,7 @@ const I2CAddr uint16 = 0x48
// a differential reading between two pins. // a differential reading between two pins.
type Channel int type Channel int
// Value channels.
const ( const (
// Absolute reading. // Absolute reading.
Channel0 Channel = 4 Channel0 Channel = 4

@ -86,7 +86,7 @@ func (d *Dev) errorCodeToError(errorCode SensorErrorID) error {
default: default:
errorText = fmt.Sprintf("Uknwown error, code: %d", errorCode) errorText = fmt.Sprintf("Uknwown error, code: %d", errorCode)
} }
return fmt.Errorf("Sensor error: %s", errorText) return fmt.Errorf("sensor error: %s", errorText)
} }
// Opts holds the configuration options. The address must be 0x5A or 0x5B. // Opts holds the configuration options. The address must be 0x5A or 0x5B.
@ -108,11 +108,11 @@ var DefaultOpts = Opts{
// New creates a new driver for CCS811 VOC sensor. // New creates a new driver for CCS811 VOC sensor.
func New(bus i2c.Bus, opts *Opts) (*Dev, error) { func New(bus i2c.Bus, opts *Opts) (*Dev, error) {
if opts.Addr != 0x5A && opts.Addr != 0x5B { if opts.Addr != 0x5A && opts.Addr != 0x5B {
return nil, fmt.Errorf("Invalid device address, only 0x5A or 0x5B are allowed") return nil, fmt.Errorf("invalid device address, only 0x5A or 0x5B are allowed")
} }
if opts.MeasurementMode > MeasurementModeConstant250 { if opts.MeasurementMode > MeasurementModeConstant250 {
return nil, fmt.Errorf("Invalid measurement mode") return nil, fmt.Errorf("invalid measurement mode")
} }
dev := &Dev{ dev := &Dev{
@ -122,14 +122,14 @@ func New(bus i2c.Bus, opts *Opts) (*Dev, error) {
// From boot mode to measurement mode. // From boot mode to measurement mode.
if err := dev.StartSensorApp(); err != nil { if err := dev.StartSensorApp(); err != nil {
return nil, fmt.Errorf("Error transitioning from boot do app mode: %v", err) return nil, fmt.Errorf("error transitioning from boot do app mode: %v", err)
} }
mmp := &MeasurementModeParams{MeasurementMode: opts.MeasurementMode, mmp := &MeasurementModeParams{MeasurementMode: opts.MeasurementMode,
GenerateInterrupt: opts.InterruptWhenReady, GenerateInterrupt: opts.InterruptWhenReady,
UseThreshold: opts.UseThreshold} UseThreshold: opts.UseThreshold}
if err := dev.SetMeasurementModeRegister(*mmp); err != nil { if err := dev.SetMeasurementModeRegister(*mmp); err != nil {
return nil, fmt.Errorf("Error setting measurement mode: %v", err) return nil, fmt.Errorf("error setting measurement mode: %v", err)
} }
return dev, nil return dev, nil
@ -197,10 +197,7 @@ func (d *Dev) GetMeasurementModeRegister() (MeasurementModeParams, error) {
// Reset sets device into the BOOT mode. // Reset sets device into the BOOT mode.
func (d *Dev) Reset() error { func (d *Dev) Reset() error {
if err := d.c.Tx([]byte{resetReg, 0x11, 0xE5, 0x72, 0x8A}, nil); err != nil { return d.c.Tx([]byte{resetReg, 0x11, 0xE5, 0x72, 0x8A}, nil)
return err
}
return nil
} }
// ReadStatus returns value of status register. // ReadStatus returns value of status register.
@ -234,10 +231,7 @@ func (d *Dev) SetEnvironmentData(temp, humidity float32) error {
byte(rawTemp >> 8), byte(rawTemp >> 8),
byte(rawTemp)} byte(rawTemp)}
if err := d.c.Tx(w, nil); err != nil { return d.c.Tx(w, nil)
return err
}
return nil
} }
// GetBaseline provides current baseline used by internal measurement algorithm. // GetBaseline provides current baseline used by internal measurement algorithm.
@ -288,10 +282,7 @@ func (d *Dev) GetBaseline() ([]byte, error) {
// 2) The baseline must be written after the conditioning period // 2) The baseline must be written after the conditioning period
func (d *Dev) SetBaseline(baseline []byte) error { func (d *Dev) SetBaseline(baseline []byte) error {
w := []byte{baselineReg, baseline[0], baseline[1]} w := []byte{baselineReg, baseline[0], baseline[1]}
if err := d.c.Tx(w, nil); err != nil { return d.c.Tx(w, nil)
return err
}
return nil
} }
// SensorValues represents data read from the sensor. // SensorValues represents data read from the sensor.

@ -40,7 +40,7 @@ func TestBasicInitialisationAndDataRead(t *testing.T) {
if data.ECO2 != 0x102 && if data.ECO2 != 0x102 &&
data.VOC != 0x203 && data.VOC != 0x203 &&
data.Status != 0xF && data.Status != 0xF &&
data.Error != fmt.Errorf("Sensor error: %s", "HEATER_FAULT: The Heater current in the CCS811 is not in range.") && data.Error != fmt.Errorf("sensor error: %s", "HEATER_FAULT: The Heater current in the CCS811 is not in range.") &&
data.RawDataCurrent != cExpected && data.RawDataCurrent != cExpected &&
data.RawDataVoltage != vExpected { data.RawDataVoltage != vExpected {
t.Fatalf("Data parsed incorrectly, got %v", data) t.Fatalf("Data parsed incorrectly, got %v", data)

@ -359,11 +359,7 @@ func (d *Dev) Init() error {
return err return err
} }
if err := d.setLut(Full); err != nil { return d.setLut(Full)
return err
}
return nil
} }
// Reset can be also used to awaken the device // Reset can be also used to awaken the device
@ -429,11 +425,7 @@ func (d *Dev) setMemoryArea(xStart, yStart, xEnd, yEnd int) error {
if err := d.sendData([]byte{byte(yEnd & 0xFF)}); err != nil { if err := d.sendData([]byte{byte(yEnd & 0xFF)}); err != nil {
return err return err
} }
if err := d.sendData([]byte{byte((yEnd >> 8) & 0xFF)}); err != nil { return d.sendData([]byte{byte((yEnd >> 8) & 0xFF)})
return err
}
return nil
} }
func (d *Dev) setLut(update PartialUpdate) error { func (d *Dev) setLut(update PartialUpdate) error {

@ -71,11 +71,7 @@ func (r *Dev) Reset() error {
return err return err
} }
if err := r.bulkSendData(initSequence, r.writeInstruction); err != nil { return r.bulkSendData(initSequence, r.writeInstruction)
return err
}
return nil
} }
func (r *Dev) String() string { func (r *Dev) String() string {
@ -95,10 +91,7 @@ func (r *Dev) Halt() error {
// line - screen line, 0-based // line - screen line, 0-based
// column - column, 0-based // column - column, 0-based
func (r *Dev) SetCursor(line uint8, column uint8) error { func (r *Dev) SetCursor(line uint8, column uint8) error {
if err := r.writeInstruction(0x80 | (line*lineTwo + column)); err != nil { return r.writeInstruction(0x80 | (line*lineTwo + column))
return err
}
return nil
} }
// Print the data string // Print the data string
@ -187,20 +180,14 @@ func (r *Dev) sendInstruction() error {
if err := r.rsPin.Out(gpio.Low); err != nil { if err := r.rsPin.Out(gpio.Low); err != nil {
return err return err
} }
if err := r.enablePin.Out(gpio.Low); err != nil { return r.enablePin.Out(gpio.Low)
return err
}
return nil
} }
func (r *Dev) sendData() error { func (r *Dev) sendData() error {
if err := r.rsPin.Out(gpio.High); err != nil { if err := r.rsPin.Out(gpio.High); err != nil {
return err return err
} }
if err := r.enablePin.Out(gpio.Low); err != nil { return r.enablePin.Out(gpio.Low)
return err
}
return nil
} }
func (r *Dev) writeInstruction(data uint8) error { func (r *Dev) writeInstruction(data uint8) error {
@ -224,10 +211,7 @@ func (r *Dev) strobe() error {
return err return err
} }
delayUs(2) delayUs(2)
if err := r.enablePin.Out(gpio.Low); err != nil { return r.enablePin.Out(gpio.Low)
return err
}
return nil
} }
func delayUs(ms uint) { func delayUs(ms uint) {

@ -71,18 +71,13 @@ func (d *Dev) init() error {
} }
// Set display to full brightness. // Set display to full brightness.
if err := d.SetBrightness(15); err != nil { return d.SetBrightness(15)
return err
}
return nil
} }
// SetBlink Blink display at specified frequency. // SetBlink Blink display at specified frequency.
func (d *Dev) SetBlink(freq BlinkFrequency) error { func (d *Dev) SetBlink(freq BlinkFrequency) error {
if _, err := d.dev.Write([]byte{displaySetup | displayOn | byte(freq)}); err != nil { _, err := d.dev.Write([]byte{displaySetup | displayOn | byte(freq)})
return err return err
}
return nil
} }
// SetBrightness of entire display to specified value. // SetBrightness of entire display to specified value.

@ -30,6 +30,7 @@ var (
// with a gain of 32. // with a gain of 32.
type InputMode int type InputMode int
// Valid InputMode.
const ( const (
CHANNEL_A_GAIN_128 InputMode = 1 CHANNEL_A_GAIN_128 InputMode = 1
CHANNEL_A_GAIN_64 InputMode = 3 CHANNEL_A_GAIN_64 InputMode = 3

@ -3,7 +3,7 @@
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
// Package inky drives an Inky pHAT E ink display. // Package inky drives an Inky pHAT E ink display.
//
// Datasheet // Datasheet
// //
// Inky lacks a true datasheet, so the code here is derived from the reference // Inky lacks a true datasheet, so the code here is derived from the reference

@ -28,11 +28,12 @@ const (
// setting the border color. // setting the border color.
type Color int type Color int
// Valid Color.
const ( const (
Black = iota Black Color = iota
Red = iota Red
Yellow = iota Yellow
White = iota White
) )
var borderColor = map[Color]byte{ var borderColor = map[Color]byte{
@ -45,6 +46,7 @@ var borderColor = map[Color]byte{
// Model lists the supported e-ink display models. // Model lists the supported e-ink display models.
type Model int type Model int
// Supported Model.
const ( const (
PHAT Model = iota PHAT Model = iota
// TODO: Add wHAT here when supported. // TODO: Add wHAT here when supported.
@ -61,10 +63,10 @@ type Opts struct {
BorderColor Color BorderColor Color
} }
// NewpHAT opens a handle to an Inky pHAT. // New opens a handle to an Inky pHAT.
func New(p spi.Port, dc gpio.PinOut, reset gpio.PinOut, busy gpio.PinIn, o *Opts) (*Dev, error) { func New(p spi.Port, dc gpio.PinOut, reset gpio.PinOut, busy gpio.PinIn, o *Opts) (*Dev, error) {
if o.ModelColor != Black && o.ModelColor != Red && o.ModelColor != Yellow { if o.ModelColor != Black && o.ModelColor != Red && o.ModelColor != Yellow {
return nil, fmt.Errorf("Unsupported color: %v", o.ModelColor) return nil, fmt.Errorf("unsupported color: %v", o.ModelColor)
} }
c, err := p.Connect(488*physic.KiloHertz, spi.Mode0, 8) c, err := p.Connect(488*physic.KiloHertz, spi.Mode0, 8)
@ -153,11 +155,11 @@ func (d *Dev) Bounds() image.Rectangle {
// Draw implements display.Drawer // Draw implements display.Drawer
func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPtrs image.Point) error { func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPtrs image.Point) error {
if dstRect != d.Bounds() { if dstRect != d.Bounds() {
return fmt.Errorf("Partial update not supported") return fmt.Errorf("partial update not supported")
} }
if src.Bounds() != d.Bounds() { if src.Bounds() != d.Bounds() {
return fmt.Errorf("Image must be the same size as bounds: %v", d.Bounds()) return fmt.Errorf("image must be the same size as bounds: %v", d.Bounds())
} }
b := src.Bounds() b := src.Bounds()
@ -331,7 +333,7 @@ func (d *Dev) sendCommand(command byte, data []byte) error {
func (d *Dev) sendData(data []byte) error { func (d *Dev) sendData(data []byte) error {
if len(data) > 4096 { if len(data) > 4096 {
return fmt.Errorf("Sending more data than chunk size: %d > 4096", len(data)) return fmt.Errorf("sending more data than chunk size: %d > 4096", len(data))
} }
if err := d.dc.Out(gpio.High); err != nil { if err := d.dc.Out(gpio.High); err != nil {
return err return err

@ -139,6 +139,7 @@ func (d *Dev) SenseContinuous(interval time.Duration) (<-chan physic.Env, error)
return env, nil return env, nil
} }
// Precision implement SenseEnv.
func (d *Dev) Precision(e *physic.Env) { func (d *Dev) Precision(e *physic.Env) {
switch d.res { switch d.res {
case Maximum: case Maximum:
@ -339,6 +340,7 @@ func (d *Dev) setLowerAlert(t physic.Temperature) error {
return nil return nil
} }
// Alert represents an alert generated by the device.
type Alert struct { type Alert struct {
AlertMode string AlertMode string
AlertLevel physic.Temperature AlertLevel physic.Temperature
@ -412,6 +414,7 @@ func alertTemperatureToBits(t physic.Temperature) (uint16, error) {
type resolution uint8 type resolution uint8
// Valid resolution values.
const ( const (
Maximum resolution = 0 Maximum resolution = 0
Low resolution = 1 Low resolution = 1

@ -96,7 +96,7 @@ func (r *LowLevel) Init() error {
return r.SetAntenna(true) return r.SetAntenna(true)
} }
// setAntenna configures the antenna state, on/off. // SetAntenna configures the antenna state, on/off.
func (r *LowLevel) SetAntenna(state bool) error { func (r *LowLevel) SetAntenna(state bool) error {
if state { if state {
current, err := r.DevRead(TxControlReg) current, err := r.DevRead(TxControlReg)

@ -35,6 +35,7 @@ type Key [6]byte
// DefaultKey provides the default bytes for card authentication for method B. // DefaultKey provides the default bytes for card authentication for method B.
var DefaultKey = Key{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} var DefaultKey = Key{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
// TODO(maruel): Move to Opts pattern. Even golint complains about this.
type config struct { type config struct {
defaultTimeout time.Duration defaultTimeout time.Duration
beforeCall func() beforeCall func()
@ -51,7 +52,7 @@ func WithTimeout(timeout time.Duration) configF {
} }
} }
// WithSyncsets the synchronization for the entire device, using internal mutex. // WithSync sets the synchronization for the entire device, using internal mutex.
func WithSync() configF { func WithSync() configF {
var mu sync.Mutex var mu sync.Mutex
return func(c *config) *config { return func(c *config) *config {

@ -1,27 +1,25 @@
package accelerometer package accelerometer
// Valid accelerator values.
const ( const (
ACCEL_FS_SEL_2G = 0 ACCEL_FS_SEL_2G = 0
ACCEL_FS_SEL_4G = 8 ACCEL_FS_SEL_4G = 8
ACCEL_FS_SEL_8G = 0x10 ACCEL_FS_SEL_8G = 0x10
ACCEL_FS_SEL_16G = 0x18 ACCEL_FS_SEL_16G = 0x18
ACCEL_FS_SENS_2G = 2.0 / 32768.0
ACCEL_FS_SENS_4G = 4.0 / 32768.0
ACCEL_FS_SENS_8G = 8.0 / 32768.0
ACCEL_FS_SENS_16G = 16.0 / 32768.0
) )
// Sensitivity returns the sensitivity as float32.
func Sensitivity(selector int) float32 { func Sensitivity(selector int) float32 {
switch selector { switch selector {
default:
fallthrough
case ACCEL_FS_SEL_2G: case ACCEL_FS_SEL_2G:
return ACCEL_FS_SENS_2G return 2.0 / 32768.0
case ACCEL_FS_SEL_4G: case ACCEL_FS_SEL_4G:
return ACCEL_FS_SENS_4G return 4.0 / 32768.0
case ACCEL_FS_SEL_8G: case ACCEL_FS_SEL_8G:
return ACCEL_FS_SENS_8G return 8.0 / 32768.0
case ACCEL_FS_SEL_16G: case ACCEL_FS_SEL_16G:
return ACCEL_FS_SENS_16G return 16.0 / 32768.0
} }
return ACCEL_FS_SENS_2G
} }

@ -82,15 +82,11 @@ func (m *MPU9250) Debug(f DebugF) {
// Init initializes the device // Init initializes the device
func (m *MPU9250) Init() error { func (m *MPU9250) Init() error {
if err := m.transferBatch(initSequence, "error initializing %d: [%x:%x] => %v"); err != nil { return m.transferBatch(initSequence, "error initializing %d: [%x:%x] => %v")
return err
}
return nil
} }
// Calibrate Calibrates the device using maximum precision for both Gyroscope and Accelerometer. // Calibrate Calibrates the device using maximum precision for both Gyroscope and Accelerometer.
func (m *MPU9250) Calibrate() error { func (m *MPU9250) Calibrate() error {
if err := m.transferBatch(calibrateSequence, "error calibrating %d: [%x:%x] => %v"); err != nil { if err := m.transferBatch(calibrateSequence, "error calibrating %d: [%x:%x] => %v"); err != nil {
return err return err
} }

@ -1,5 +1,8 @@
package reg package reg
// Unsorted mix of register addresses, commands and constants.
//
// TODO(maruel): Needs to be redone.
const ( const (
MPU9250_DEFAULT_ADDRESS = 0xD1 MPU9250_DEFAULT_ADDRESS = 0xD1
MPU9250_ALT_DEFAULT_ADDRESS = 0xD2 MPU9250_ALT_DEFAULT_ADDRESS = 0xD2

@ -49,10 +49,7 @@ func (s *SpiTransport) writeByte(address byte, value byte) error {
if err := s.device.Tx(buf[:], res[:]); err != nil { if err := s.device.Tx(buf[:], res[:]); err != nil {
return err return err
} }
if err := s.cs.Out(gpio.High); err != nil { return s.cs.Out(gpio.High)
return err
}
return nil
} }
func (s *SpiTransport) writeMagReg(address byte, value byte) error { func (s *SpiTransport) writeMagReg(address byte, value byte) error {
@ -104,7 +101,7 @@ func (s *SpiTransport) readByte(address byte) (byte, error) {
func (s *SpiTransport) readUint16(address ...byte) (uint16, error) { func (s *SpiTransport) readUint16(address ...byte) (uint16, error) {
if len(address) != 2 { if len(address) != 2 {
return 0, fmt.Errorf("Only 2 bytes per read") return 0, fmt.Errorf("only 2 bytes per read")
} }
h, err := s.readByte(address[0]) h, err := s.readByte(address[0])
if err != nil { if err != nil {

@ -42,7 +42,7 @@ type Dev struct {
// New creates a new handle to a pca9548 I²C multiplexer. // New creates a new handle to a pca9548 I²C multiplexer.
func New(bus i2c.Bus, opts *Opts) (*Dev, error) { func New(bus i2c.Bus, opts *Opts) (*Dev, error) {
if opts.Addr < 0x70 || opts.Addr > 0x77 { if opts.Addr < 0x70 || opts.Addr > 0x77 {
return nil, errors.New("Address outside valid range of 0x70-0x77") return nil, errors.New("address outside valid range of 0x70-0x77")
} }
d := &Dev{ d := &Dev{
c: bus, c: bus,

@ -176,9 +176,5 @@ func (d *Dev) Halt() error {
return err return err
} }
if err := d.buttonC.Halt(); err != nil { return d.buttonC.Halt()
return err
}
return nil
} }

Loading…
Cancel
Save